• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

Screen.h

Go to the documentation of this file.
00001 /*
00002     This file is part of Konsole, KDE's terminal.
00003 
00004     Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
00005     Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00020     02110-1301  USA.
00021 */
00022 
00023 #ifndef SCREEN_H
00024 #define SCREEN_H
00025 
00026 // Qt
00027 #include <QtCore/QRect>
00028 #include <QtCore/QTextStream>
00029 #include <QtCore/QVarLengthArray>
00030 
00031 // Konsole
00032 #include "Character.h"
00033 #include "History.h"
00034 
00035 #define MODE_Origin    0
00036 #define MODE_Wrap      1
00037 #define MODE_Insert    2
00038 #define MODE_Screen    3
00039 #define MODE_Cursor    4
00040 #define MODE_NewLine   5
00041 #define MODES_SCREEN   6
00042 
00043 namespace Konsole
00044 {
00045 
00046 class TerminalCharacterDecoder;
00047 
00071 class Screen
00072 {
00073 public:
00075     Screen(int lines, int columns);
00076     ~Screen();
00077 
00078     // VT100/2 Operations 
00079     // Cursor Movement
00080     
00085     void cursorUp(int n);
00090     void cursorDown(int n);
00095     void cursorLeft(int n);
00100     void cursorRight(int n);
00102     void setCursorY(int y);
00104     void setCursorX(int x);
00106     void setCursorYX(int y, int x);
00113     void setMargins(int topLine , int bottomLine);
00115     int topMargin() const;
00117     int bottomMargin() const;
00118 
00123     void setDefaultMargins();
00124     
00133     void newLine();
00138     void nextLine();
00139 
00145     void index();
00151     void reverseIndex();
00152     
00158     void scrollUp(int n);
00164     void scrollDown(int n);
00169     void toStartOfLine();
00174     void backspace();
00176     void tab(int n = 1);
00178     void backtab(int n);
00179     
00180     // Editing
00181     
00188     void eraseChars(int n);
00193     void deleteChars(int n);
00199     void insertChars(int n);
00205     void deleteLines(int n);
00211     void insertLines(int n);
00213     void clearTabStops();
00215     void changeTabStop(bool set);
00216    
00218     void resetMode(int mode);
00220     void setMode(int mode);
00225     void saveMode(int mode);
00227     void restoreMode(int mode);
00229     bool getMode(int mode) const;
00230    
00235     void saveCursor();
00237     void restoreCursor();
00238    
00240     void clearEntireScreen();
00245     void clearToEndOfScreen();
00250     void clearToBeginOfScreen();
00252     void clearEntireLine();
00254     void clearToEndOfLine();
00256     void clearToBeginOfLine();
00257     
00259     void helpAlign();
00260        
00267     void setRendition(int rendition);
00274     void resetRendition(int rendition);
00275     
00284     void setForeColor(int space, int color);
00293     void setBackColor(int space, int color);
00298     void setDefaultRendition();
00299     
00301     int  getCursorX() const;
00303     int  getCursorY() const;
00304    
00308     void clear();
00313     void home();
00331     void reset(bool clearScreen = true);
00332    
00344     void displayCharacter(unsigned short c);
00345     
00346     // Do composition with last shown character FIXME: Not implemented yet for KDE 4
00347     void compose(const QString& compose);
00348     
00359     void resizeImage(int new_lines, int new_columns);
00360     
00371     void getImage( Character* dest , int size , int startLine , int endLine ) const;
00372 
00379     QVector<LineProperty> getLineProperties( int startLine , int endLine ) const;
00380     
00381 
00383     int getLines() const   
00384     { return lines; }
00386     int getColumns() const 
00387     { return columns; }
00389     int getHistLines() const;
00395     void setScroll(const HistoryType& , bool copyPreviousScroll = true);
00397     const HistoryType& getScroll() const;
00402     bool hasScroll() const;
00403 
00411     void setSelectionStart(const int column, const int line, const bool blockSelectionMode);
00412     
00419     void setSelectionEnd(const int column, const int line);
00420    
00425     void getSelectionStart(int& column , int& line) const;
00426     
00431     void getSelectionEnd(int& column , int& line) const;
00432 
00434     void clearSelection();
00435 
00440     bool isSelected(const int column,const int line) const;
00441 
00447     QString selectedText(bool preserveLineBreaks) const;
00448         
00456     void writeLinesToStream(TerminalCharacterDecoder* decoder, int fromLine, int toLine) const;
00457 
00468     void writeSelectionToStream(TerminalCharacterDecoder* decoder , bool
00469                                 preserveLineBreaks = true) const;
00470 
00472     void checkSelection(int from, int to);
00473 
00491     void setLineProperty(LineProperty property , bool enable);
00492 
00500     int scrolledLines() const;
00501 
00508     QRect lastScrolledRegion() const;
00509 
00514     void resetScrolledLines();
00515 
00525     int droppedLines() const;
00526 
00531     void resetDroppedLines();
00532 
00537     static void fillWithDefaultChar(Character* dest, int count);
00538 
00539 private: 
00540 
00541     //copies a line of text from the screen or history into a stream using a 
00542     //specified character decoder.  Returns the number of lines actually copied,
00543     //which may be less than 'count' if (start+count) is more than the number of characters on
00544     //the line 
00545     //
00546     //line - the line number to copy, from 0 (the earliest line in the history) up to 
00547     //         history->getLines() + lines - 1
00548     //start - the first column on the line to copy
00549     //count - the number of characters on the line to copy
00550     //decoder - a decoder which coverts terminal characters (an Character array) into text
00551     //appendNewLine - if true a new line character (\n) is appended to the end of the line
00552     int  copyLineToStream(int line, 
00553                           int start, 
00554                           int count, 
00555                           TerminalCharacterDecoder* decoder,
00556                           bool appendNewLine,
00557                           bool preserveLineBreaks) const;
00558     
00559     //fills a section of the screen image with the character 'c'
00560     //the parameters are specified as offsets from the start of the screen image.
00561     //the loc(x,y) macro can be used to generate these values from a column,line pair.
00562     void clearImage(int loca, int loce, char c);
00563 
00564     //move screen image between 'sourceBegin' and 'sourceEnd' to 'dest'.
00565     //the parameters are specified as offsets from the start of the screen image.
00566     //the loc(x,y) macro can be used to generate these values from a column,line pair.
00567     //
00568     //NOTE: moveImage() can only move whole lines
00569     void moveImage(int dest, int sourceBegin, int sourceEnd);
00570     // scroll up 'i' lines in current region, clearing the bottom 'i' lines 
00571     void scrollUp(int from, int i);
00572     // scroll down 'i' lines in current region, clearing the top 'i' lines
00573     void scrollDown(int from, int i);
00574 
00575     void addHistLine();
00576 
00577     void initTabStops();
00578 
00579     void updateEffectiveRendition();
00580     void reverseRendition(Character& p) const;
00581 
00582     bool isSelectionValid() const;
00583     // copies text from 'startIndex' to 'endIndex' to a stream
00584     // startIndex and endIndex are positions generated using the loc(x,y) macro
00585     void writeToStream(TerminalCharacterDecoder* decoder, int startIndex, 
00586                        int endIndex, bool preserveLineBreaks = true) const;
00587     // copies 'count' lines from the screen buffer into 'dest',
00588     // starting from 'startLine', where 0 is the first line in the screen buffer
00589     void copyFromScreen(Character* dest, int startLine, int count) const;
00590     // copies 'count' lines from the history buffer into 'dest',
00591     // starting from 'startLine', where 0 is the first line in the history
00592     void copyFromHistory(Character* dest, int startLine, int count) const;
00593 
00594 
00595     // screen image ----------------
00596     int lines;
00597     int columns;
00598 
00599     typedef QVector<Character> ImageLine;      // [0..columns]
00600     ImageLine*          screenLines;    // [lines]
00601 
00602     int _scrolledLines;
00603     QRect _lastScrolledRegion;
00604 
00605     int _droppedLines;
00606 
00607     QVarLengthArray<LineProperty,64> lineProperties;    
00608     
00609     // history buffer ---------------
00610     HistoryScroll* history;
00611     
00612     // cursor location
00613     int cuX;
00614     int cuY;
00615 
00616     // cursor color and rendition info
00617     CharacterColor currentForeground;
00618     CharacterColor currentBackground;
00619     quint8 currentRendition; 
00620 
00621     // margins ----------------
00622     int _topMargin;
00623     int _bottomMargin;
00624 
00625     // states ----------------
00626     int currentModes[MODES_SCREEN];
00627     int savedModes[MODES_SCREEN];
00628 
00629     // ----------------------------
00630 
00631     QBitArray tabStops;
00632 
00633     // selection -------------------
00634     int selBegin; // The first location selected.
00635     int selTopLeft;    // TopLeft Location.
00636     int selBottomRight;    // Bottom Right Location.
00637     bool blockSelectionMode;  // Column selection mode
00638 
00639     // effective colors and rendition ------------
00640     CharacterColor effectiveForeground; // These are derived from
00641     CharacterColor effectiveBackground; // the cu_* variables above
00642     quint8 effectiveRendition;          // to speed up operation
00643 
00644     class SavedState  
00645     {
00646     public:
00647         SavedState()
00648         : cursorColumn(0),cursorLine(0),rendition(0) {}
00649 
00650         int cursorColumn;
00651         int cursorLine;
00652         quint8 rendition;
00653         CharacterColor foreground;
00654         CharacterColor background;
00655     };
00656     SavedState savedState;
00657         
00658     // last position where we added a character
00659     int lastPos;
00660 
00661     static Character defaultChar;
00662 };
00663 
00664 }
00665 
00666 #endif // SCREEN_H

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal