35 #include <QtCore/QTextStream>
36 #include <QtCore/QDate>
44 #define BS_CLEARS false
56 #define loc(X,Y) ((Y)*columns+(X))
76 tmargin(0), bmargin(0),
78 sel_begin(0), sel_TL(0), sel_BR(0),
87 for (
int i=0;i<
lines+1;i++)
183 if (top == 0) top = 1;
184 if (bot == 0) bot =
lines;
187 if ( !( 0 <= top && top < bot && bot <
lines ) )
188 { qDebug()<<
" setRegion("<<top<<
","<<bot<<
") : bad range.";
382 if ((new_lines==
lines) && (new_columns==
columns))
return;
384 if (
cuY > new_lines-1)
387 for (
int i = 0; i <
cuY-(new_lines-1); i++)
396 for (
int i=0; i < qMin(
lines-1,new_lines+1) ;i++)
398 for (
int i=
lines;(i > 0) && (i<new_lines+1);i++)
399 newScreenLines[i].resize( new_columns );
402 for (
int i=
lines;(i > 0) && (i<new_lines+1);i++)
514 Q_ASSERT( startLine >= 0 && count > 0 && startLine + count <= hist->
getLines() );
516 for (
int line = startLine;
line < startLine + count;
line++)
519 const int destLineOffset = (
line-startLine)*
columns;
523 for (
int column = length; column <
columns; column++)
529 for (
int column = 0; column <
columns; column++)
542 Q_ASSERT( startLine >= 0 && count > 0 && startLine + count <=
lines );
544 for (
int line = startLine;
line < (startLine+count) ;
line++)
547 int destLineStartIndex = (
line-startLine)*columns;
549 for (
int column = 0; column <
columns; column++)
551 int srcIndex = srcLineStartIndex + column;
552 int destIndex = destLineStartIndex + column;
566 Q_ASSERT( startLine >= 0 );
567 Q_ASSERT( endLine >= startLine && endLine < hist->
getLines() +
lines );
569 const int mergedLines = endLine - startLine + 1;
571 Q_ASSERT( size >= mergedLines *
columns );
574 const int linesInHistoryBuffer = qBound(0,
hist->
getLines()-startLine,mergedLines);
575 const int linesInScreenBuffer = mergedLines - linesInHistoryBuffer;
578 if (linesInHistoryBuffer > 0) {
583 if (linesInScreenBuffer > 0) {
586 linesInScreenBuffer);
592 for (
int i = 0; i < mergedLines*
columns; i++)
597 int cursorIndex =
loc(
cuX,
cuY + linesInHistoryBuffer);
604 Q_ASSERT( startLine >= 0 );
605 Q_ASSERT( endLine >= startLine && endLine < hist->
getLines() +
lines );
607 const int mergedLines = endLine-startLine+1;
608 const int linesInHistory = qBound(0,
hist->
getLines()-startLine,mergedLines);
609 const int linesInScreen = mergedLines - linesInHistory;
611 QVector<LineProperty> result(mergedLines);
615 for (
int line = startLine;
line < startLine + linesInHistory;
line++)
626 const int firstScreenLine = startLine + linesInHistory -
hist->
getLines();
627 for (
int line = firstScreenLine;
line < firstScreenLine+linesInScreen;
line++)
694 while((n > 0) && (
cuX > 0))
746 if ( (
sel_BR > (from+scr_TL) )&&(
sel_TL < (to+scr_TL)) )
775 if (size == 0 &&
cuY > 0)
802 int newCursorX =
cuX + w--;
874 if (n <= 0 || from + n >
bmargin)
return;
974 if ( (
sel_BR > (loca+scr_TL) )&&(
sel_TL < (loce+scr_TL)) )
986 bool isDefaultCh = (clearCh ==
Character());
988 for (
int y=topLine;y<=bottomLine;y++)
993 int startCol = ( y == topLine ) ? loca%
columns : 0;
997 if ( isDefaultCh && endCol ==
columns-1 )
999 line.resize(startCol);
1003 if (line.size() < endCol + 1)
1004 line.resize(endCol+1);
1007 for (
int i=startCol;i<=endCol;i++)
1031 Q_ASSERT( sourceBegin <= sourceEnd );
1040 if (dest < sourceBegin)
1042 for (
int i=0;i<=
lines;i++)
1050 for (
int i=lines;i>=0;i--)
1059 int diff = dest - sourceBegin;
1069 int diff = dest - sourceBegin;
1071 int srca = sourceBegin+scr_TL;
1072 int srce = sourceEnd+scr_TL;
1073 int desta = srca+diff;
1074 int deste = srce+diff;
1116 for (
int i = 0; i < (
lines-1); i++)
1264 int sel_Left,sel_Right;
1270 return ( x >= sel_Left % columns ) && ( x <= sel_Right %
columns ) &&
1284 QTextStream stream(&result, QIODevice::ReadWrite);
1287 decoder.
begin(&stream);
1300 bool preserveLineBreaks)
1312 Q_ASSERT( top >= 0 && left >= 0 && bottom >= 0 && right >= 0 );
1317 for (
int y=top;y<=bottom;y++)
1323 if ( y == bottom ||
columnmode ) count = right - start + 1;
1325 const bool appendNewLine = ( y != bottom );
1331 preserveLineBreaks );
1341 bool preserveLineBreaks)
1347 static const int MAX_CHARS = 1024;
1348 static Character characterBuffer[MAX_CHARS];
1350 assert( count < MAX_CHARS );
1360 start = qMin(start,qMax(0,lineLength-1));
1365 count = lineLength-start;
1369 count = qMin(start+count,lineLength)-start;
1373 assert( start >= 0 );
1374 assert( count >= 0 );
1387 assert( count >= 0 );
1395 for (
int i=start;i < qMin(start+count,length);i++)
1397 characterBuffer[i-start] = data[i];
1401 count = qBound(0,count,length-start);
1408 for (
int i=count-1 ; i >= 0; i--)
1409 if (QChar(characterBuffer[i].character).isSpace())
1415 const bool omitLineBreak = (currentLineProperties &
LINE_WRAPPED) ||
1416 !preserveLineBreaks;
1418 if ( !omitLineBreak && appendNewLine && (count+1 < MAX_CHARS) )
1420 characterBuffer[count] =
'\n';
1426 count, currentLineProperties );
1479 if ( newHistLines == oldHistLines )
1483 if (newHistLines > oldHistLines)
1495 int top_BR =
loc(0, 1+newHistLines);
1531 if ( copyPreviousScroll )
1564 for (
int i=0;i<count;i++)