diff options
author | nyamatongwe <unknown> | 2001-12-19 07:42:43 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2001-12-19 07:42:43 +0000 |
commit | a3e9b9fcf48df51d55fb1e5c2c696d73dc72c151 (patch) | |
tree | 2b7025f7018ab826f0c5da3e14cc6299430bd783 /src | |
parent | f3801f3ee91582dbe10abec295840c794da1858e (diff) | |
download | scintilla-mirror-a3e9b9fcf48df51d55fb1e5c2c696d73dc72c151.tar.gz |
Wrapping supported.
Diffstat (limited to 'src')
-rw-r--r-- | src/ContractionState.cxx | 90 |
1 files changed, 75 insertions, 15 deletions
diff --git a/src/ContractionState.cxx b/src/ContractionState.cxx index 1f1469665..362dc1ed8 100644 --- a/src/ContractionState.cxx +++ b/src/ContractionState.cxx @@ -11,8 +11,9 @@ OneLine::OneLine() { displayLine = 0; - docLine = 0; + //docLine = 0; visible = true; + height = 1; expanded = true; } @@ -22,6 +23,8 @@ ContractionState::ContractionState() { linesInDoc = 1; linesInDisplay = 1; valid = false; + docLines = 0; + sizeDocLines = 0; } ContractionState::~ContractionState() { @@ -30,14 +33,32 @@ ContractionState::~ContractionState() { void ContractionState::MakeValid() const { if (!valid) { - // Could be cleverer by keeping the index of the last still valid entry + // Could be cleverer by keeping the index of the last still valid entry // rather than invalidating all. - int lineDisplay = 0; + linesInDisplay = 0; + for (int lineInDoc=0; lineInDoc<linesInDoc; lineInDoc++) { + lines[lineInDoc].displayLine = linesInDisplay; + if (lines[lineInDoc].visible) { + linesInDisplay += lines[lineInDoc].height; + } + } + if (sizeDocLines < linesInDisplay) { + delete []docLines; + docLines = new int[linesInDisplay + growSize]; + if (docLines) { + sizeDocLines = linesInDisplay + growSize; + } else { + return; + } + } + + int lineInDisplay=0; for (int line=0; line<linesInDoc; line++) { - lines[line].displayLine = lineDisplay; if (lines[line].visible) { - lines[lineDisplay].docLine = line; - lineDisplay++; + for (int linePiece=0; linePiece<lines[line].height; linePiece++) { + docLines[lineInDisplay] = line; + lineInDisplay++; + } } } valid = true; @@ -50,6 +71,9 @@ void ContractionState::Clear() { size = 0; linesInDoc = 1; linesInDisplay = 1; + delete []docLines; + docLines = 0; + sizeDocLines = 0; } int ContractionState::LinesInDoc() const { @@ -57,6 +81,9 @@ int ContractionState::LinesInDoc() const { } int ContractionState::LinesDisplayed() const { + if (size != 0) { + MakeValid(); + } return linesInDisplay; } @@ -79,7 +106,11 @@ int ContractionState::DocFromDisplay(int lineDisplay) const { if (size == 0) return lineDisplay; MakeValid(); - return lines[lineDisplay].docLine; + if (docLines) { // Valid allocation + return docLines[lineDisplay]; + } else { + return 0; + } } void ContractionState::Grow(int sizeNew) { @@ -113,13 +144,15 @@ void ContractionState::InsertLines(int lineDoc, int lineCount) { Grow(linesInDoc + lineCount + growSize); } linesInDoc += lineCount; - linesInDisplay += lineCount; for (int i = linesInDoc; i >= lineDoc + lineCount; i--) { lines[i].visible = lines[i - lineCount].visible; + lines[i].height = lines[i - lineCount].height; + linesInDisplay += lines[i].height; lines[i].expanded = lines[i - lineCount].expanded; } for (int d=0;d<lineCount;d++) { lines[lineDoc+d].visible = true; // Should inherit visibility from context ? + lines[lineDoc+d].height = 1; lines[lineDoc+d].expanded = true; } valid = false; @@ -134,7 +167,7 @@ void ContractionState::DeleteLines(int lineDoc, int lineCount) { int deltaDisplayed = 0; for (int d=0;d<lineCount;d++) { if (lines[lineDoc+d].visible) - deltaDisplayed--; + deltaDisplayed -= lines[lineDoc+d].height; } for (int i = lineDoc; i < linesInDoc-lineCount; i++) { if (i != 0) // Line zero is always visible @@ -157,10 +190,10 @@ bool ContractionState::GetVisible(int lineDoc) const { } bool ContractionState::SetVisible(int lineDocStart, int lineDocEnd, bool visible) { - if (lineDocStart == 0) - lineDocStart++; - if (lineDocStart > lineDocEnd) - return false; + if (lineDocStart == 0) + lineDocStart++; + if (lineDocStart > lineDocEnd) + return false; if (size == 0) { Grow(linesInDoc + growSize); } @@ -170,7 +203,7 @@ bool ContractionState::SetVisible(int lineDocStart, int lineDocEnd, bool visible if ((lineDocStart <= lineDocEnd) && (lineDocStart >= 0) && (lineDocEnd < linesInDoc)) { for (int line=lineDocStart; line <= lineDocEnd; line++) { if (lines[line].visible != visible) { - delta += visible ? 1 : -1; + delta += visible ? lines[line].height : -lines[line].height; lines[line].visible = visible; } } @@ -181,7 +214,7 @@ bool ContractionState::SetVisible(int lineDocStart, int lineDocEnd, bool visible } bool ContractionState::GetExpanded(int lineDoc) const { - if (size == 0) + if (size == 0) return true; if ((lineDoc >= 0) && (lineDoc < linesInDoc)) { return lines[lineDoc].expanded; @@ -203,6 +236,33 @@ bool ContractionState::SetExpanded(int lineDoc, bool expanded) { return false; } +int ContractionState::GetHeight(int lineDoc) const { + if (size == 0) + return 1; + if ((lineDoc >= 0) && (lineDoc < linesInDoc)) { + return lines[lineDoc].height; + } else { + return 1; + } +} + +// Set the number of display lines needed for this line. +// Return true if this is a change. +bool ContractionState::SetHeight(int lineDoc, int height) { + if (lineDoc > linesInDoc) + return false; + if (size == 0) { + Grow(linesInDoc + growSize); + } + if (lines[lineDoc].height != height) { + lines[lineDoc].height = height; + valid = false; + return true; + } else { + return false; + } +} + void ContractionState::ShowAll() { delete []lines; lines = 0; |