diff --git a/src/Screen.cpp b/src/Screen.cpp index 4093ef634..4c7db5635 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -1559,3 +1559,8 @@ void Screen::setLineProperty(LineProperty property , bool enable) lineProperties[cuY] = (LineProperty)(lineProperties[cuY] & ~property); } } +void Screen::fillWithDefaultChar(Character* dest, int count) +{ + for (int i=0;i getLineProperties( int startLine , int endLine ) const; @@ -430,13 +430,16 @@ public: void setBusySelecting(bool busy) { sel_busy = busy; } - /** Returns true if the character at (@p column, @p line) is part of the current selection. */ + /** + * Returns true if the character at (@p column, @p line) is part of the + * current selection. + */ bool isSelected(const int column,const int line) const; /** * Convenience method. Returns the currently selected text. - * @param preserveLineBreaks Specifies whether new line characters should be inserted into - * the returned text at the end of each terminal line. + * @param preserveLineBreaks Specifies whether new line characters should + * be inserted into the returned text at the end of each terminal line. */ QString selectedText(bool preserveLineBreaks); @@ -459,11 +462,11 @@ public: * Copies the selected characters, set using @see setSelBeginXY and @see setSelExtentXY * into a stream. * - * @param decoder A decoder which converts terminal characters into text. PlainTextDecoder - * is the most commonly used decoder which coverts characters into plain - * text with no formatting. - * @param preserveLineBreaks Specifies whether new line characters should be inserted into - * the returned text at the end of each terminal line. + * @param decoder A decoder which converts terminal characters into text. + * PlainTextDecoder is the most commonly used decoder which coverts characters + * into plain text with no formatting. + * @param preserveLineBreaks Specifies whether new line characters should + * be inserted into the returned text at the end of each terminal line. */ void writeSelectionToStream(TerminalCharacterDecoder* decoder , bool preserveLineBreaks = true); @@ -528,9 +531,16 @@ public: */ void resetDroppedLines(); + /** + * Fills the buffer @p dest with @p count instances of the default (ie. blank) + * Character style. + */ + static void fillWithDefaultChar(Character* dest, int count); + private: - //copies a line of text from the screen or history into a stream using a specified character decoder + //copies a line of text from the screen or history into a stream using a + //specified character decoder //line - the line number to copy, from 0 (the earliest line in the history) up to // hist->getLines() + lines - 1 //start - the first column on the line to copy @@ -573,22 +583,11 @@ private: // starting from 'startLine', where 0 is the first line in the history void copyFromHistory(Character* dest, int startLine, int count) const; - /* - The state of the screen is more complex as one would - expect first. The screem does really do part of the - emulation providing state information in form of modes, - margins, tabulators, cursor etc. - - Even more unexpected are variables to save and restore - parts of the state. - */ // screen image ---------------- - int lines; int columns; - typedef QVector ImageLine; // [0..columns] ImageLine* screenLines; // [lines] @@ -600,27 +599,22 @@ private: QVarLengthArray lineProperties; // history buffer --------------- - HistoryScroll *hist; // cursor location - int cuX; int cuY; // cursor color and rendition info - CharacterColor cu_fg; // foreground CharacterColor cu_bg; // background quint8 cu_re; // rendition // margins ---------------- - int tmargin; // top margin int bmargin; // bottom margin // states ---------------- - ScreenParm currParm; // ---------------------------- @@ -628,7 +622,6 @@ private: bool* tabstops; // selection ------------------- - int sel_begin; // The first location selected. int sel_TL; // TopLeft Location. int sel_BR; // Bottom Right Location. @@ -636,7 +629,6 @@ private: bool columnmode; // Column selection mode // effective colors and rendition ------------ - CharacterColor ef_fg; // These are derived from CharacterColor ef_bg; // the cu_* variables above quint8 ef_re; // to speed up operation @@ -646,12 +638,10 @@ private: // // cursor location - int sa_cuX; int sa_cuY; // rendition info - quint8 sa_cu_re; CharacterColor sa_cu_fg; CharacterColor sa_cu_bg; @@ -660,7 +650,6 @@ private: int lastPos; // modes - ScreenParm saveParm; static Character defaultChar; diff --git a/src/ScreenWindow.cpp b/src/ScreenWindow.cpp index df55098fa..1cb6b82fa 100644 --- a/src/ScreenWindow.cpp +++ b/src/ScreenWindow.cpp @@ -72,17 +72,39 @@ Character* ScreenWindow::getImage() _screen->getImage(_windowBuffer,size, _currentLine,endWindowLine()); - _bufferNeedsUpdate = false; + // this window may look beyond the end of the screen, in which + // case there will be an unused area which needs to be filled + // with blank characters + fillUnusedArea(); + + _bufferNeedsUpdate = false; return _windowBuffer; } +void ScreenWindow::fillUnusedArea() +{ + int screenEndLine = _screen->getHistLines() + _screen->getLines() - 1; + int windowEndLine = _currentLine + windowLines() - 1; + + int unusedLines = windowEndLine - screenEndLine; + int charsToFill = unusedLines * windowColumns(); + + Screen::fillWithDefaultChar(_windowBuffer + _windowBufferSize - charsToFill,charsToFill); +} + +// return the index of the line at the end of this window, or if this window +// goes beyond the end of the screen, the index of the line at the end +// of the screen. +// +// when passing a line number to a Screen method, the line number should +// never be more than endWindowLine() +// int ScreenWindow::endWindowLine() const { return qMin(_currentLine + windowLines() - 1, _screen->getHistLines() + _screen->getLines() - 1); } - QVector ScreenWindow::getLineProperties() { QVector result = _screen->getLineProperties(_currentLine,endWindowLine()); @@ -112,7 +134,7 @@ void ScreenWindow::setSelectionStart( int column , int line , bool columnMode ) { #warning "FIXME: The columnMode parameter is handled correctly when visually selecting an area, but copy/select and paste produces the wrong results." - _screen->setSelectionStart( column , line + _currentLine , columnMode); + _screen->setSelectionStart( column , qMin(line + _currentLine,endWindowLine()) , columnMode); _bufferNeedsUpdate = true; emit selectionChanged(); @@ -120,7 +142,7 @@ void ScreenWindow::setSelectionStart( int column , int line , bool columnMode ) void ScreenWindow::setSelectionEnd( int column , int line ) { - _screen->setSelectionEnd( column , line + _currentLine ); + _screen->setSelectionEnd( column , qMin(line + _currentLine,endWindowLine()) ); _bufferNeedsUpdate = true; emit selectionChanged(); @@ -128,7 +150,7 @@ void ScreenWindow::setSelectionEnd( int column , int line ) bool ScreenWindow::isSelected( int column , int line ) { - return _screen->isSelected( column , line + _currentLine ); + return _screen->isSelected( column , qMin(line + _currentLine,endWindowLine()) ); } void ScreenWindow::clearSelection() @@ -259,7 +281,7 @@ void ScreenWindow::notifyOutputChanged() if ( _trackOutput ) { _scrollCount -= _screen->scrolledLines(); - _currentLine = _screen->getHistLines(); + _currentLine = _screen->getHistLines() - (windowLines()-_screen->getLines()); } else { diff --git a/src/ScreenWindow.h b/src/ScreenWindow.h index ebb86cc73..9cfc49d05 100644 --- a/src/ScreenWindow.h +++ b/src/ScreenWindow.h @@ -236,6 +236,7 @@ signals: private: int endWindowLine() const; + void fillUnusedArea(); Screen* _screen; // see setScreen() , screen() Character* _windowBuffer;