]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/ContractionState.cxx
816d06aae708f19c45eb88153873701397b7515c
1 // Scintilla source code edit control
2 // ContractionState.cxx - manages visibility of lines for folding
3 // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
8 #include "ContractionState.h"
17 ContractionState::ContractionState() {
25 ContractionState::~ContractionState() {
29 void ContractionState::MakeValid() const {
31 // Could be cleverer by keeping the index of the last still valid entry
32 // rather than invalidating all.
35 for (int line
=0; line
<linesInDoc
; line
++) {
36 lines
[line
].displayLine
= lineDisplay
;
37 if (lines
[line
].visible
) {
38 lines
[lineDisplay
].docLine
= line
;
46 void ContractionState::Clear() {
54 int ContractionState::LinesInDoc() const {
58 int ContractionState::LinesDisplayed() const {
59 return linesInDisplay
;
62 int ContractionState::DisplayFromDoc(int lineDoc
) const {
67 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
68 return lines
[lineDoc
].displayLine
;
73 int ContractionState::DocFromDisplay(int lineDisplay
) const {
76 if (lineDisplay
>= linesInDisplay
)
81 return lines
[lineDisplay
].docLine
;
84 void ContractionState::Grow(int sizeNew
) {
85 OneLine
*linesNew
= new OneLine
[sizeNew
];
88 for (; i
< size
; i
++) {
89 linesNew
[i
] = lines
[i
];
91 for (; i
< sizeNew
; i
++) {
92 linesNew
[i
].displayLine
= i
;
99 Platform::DebugPrintf("No memory available\n");
104 void ContractionState::InsertLines(int lineDoc
, int lineCount
) {
106 linesInDoc
+= lineCount
;
107 linesInDisplay
+= lineCount
;
110 //Platform::DebugPrintf("InsertLine[%d] = %d\n", lineDoc);
111 if ((linesInDoc
+ lineCount
+ 2) >= size
) {
112 Grow(linesInDoc
+ lineCount
+ growSize
);
114 linesInDoc
+= lineCount
;
115 linesInDisplay
+= lineCount
;
116 for (int i
= linesInDoc
+ 1; i
>= lineDoc
+ lineCount
; i
--) {
117 lines
[i
].visible
= lines
[i
- lineCount
].visible
;
118 lines
[i
].expanded
= lines
[i
- lineCount
].expanded
;
120 for (int d
=0;d
<lineCount
;d
++) {
121 lines
[lineDoc
+d
].visible
= true; // Should inherit visibility from context ?
122 lines
[lineDoc
+d
].expanded
= true;
127 void ContractionState::DeleteLines(int lineDoc
, int lineCount
) {
129 linesInDoc
-= lineCount
;
130 linesInDisplay
-= lineCount
;
134 for (int d
=0;d
<lineCount
;d
++)
135 if (lines
[lineDoc
+d
].visible
)
137 for (int i
= lineDoc
; i
< linesInDoc
-lineCount
; i
++) {
138 lines
[i
].visible
= lines
[i
+ lineCount
].visible
;
139 lines
[i
].expanded
= lines
[i
+ lineCount
].expanded
;
141 linesInDoc
-= lineCount
;
142 linesInDisplay
+= delta
;
146 bool ContractionState::GetVisible(int lineDoc
) const {
149 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
150 return lines
[lineDoc
].visible
;
156 bool ContractionState::SetVisible(int lineDocStart
, int lineDocEnd
, bool visible
) {
158 Grow(linesInDoc
+ growSize
);
160 // TODO: modify docLine members to mirror displayLine
163 if ((lineDocStart
<= lineDocEnd
) && (lineDocStart
>= 0) && (lineDocEnd
< linesInDoc
)) {
164 for (int line
=lineDocStart
; line
<= lineDocEnd
; line
++) {
165 if (lines
[line
].visible
!= visible
) {
166 delta
+= visible
? 1 : -1;
167 lines
[line
].visible
= visible
;
169 lines
[line
].displayLine
+= delta
;
172 for (int line
=lineDocEnd
+1; line
<= linesInDoc
; line
++) {
173 lines
[line
].displayLine
+= delta
;
177 linesInDisplay
+= delta
;
182 bool ContractionState::GetExpanded(int lineDoc
) const {
185 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
186 return lines
[lineDoc
].expanded
;
192 bool ContractionState::SetExpanded(int lineDoc
, bool expanded
) {
194 Grow(linesInDoc
+ growSize
);
196 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
197 if (lines
[lineDoc
].expanded
!= expanded
) {
198 lines
[lineDoc
].expanded
= expanded
;