]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/ContractionState.cxx
1 // Scintilla source code edit control
2 /** @file ContractionState.cxx
3 ** Manages visibility of lines for folding.
5 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
10 #include "ContractionState.h"
19 ContractionState::ContractionState() {
27 ContractionState::~ContractionState() {
31 void ContractionState::MakeValid() const {
33 // Could be cleverer by keeping the index of the last still valid entry
34 // rather than invalidating all.
36 for (int line
=0; line
<linesInDoc
; line
++) {
37 lines
[line
].displayLine
= lineDisplay
;
38 if (lines
[line
].visible
) {
39 lines
[lineDisplay
].docLine
= line
;
47 void ContractionState::Clear() {
55 int ContractionState::LinesInDoc() const {
59 int ContractionState::LinesDisplayed() const {
60 return linesInDisplay
;
63 int ContractionState::DisplayFromDoc(int lineDoc
) const {
68 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
69 return lines
[lineDoc
].displayLine
;
74 int ContractionState::DocFromDisplay(int lineDisplay
) const {
77 if (lineDisplay
>= linesInDisplay
)
82 return lines
[lineDisplay
].docLine
;
85 void ContractionState::Grow(int sizeNew
) {
86 OneLine
*linesNew
= new OneLine
[sizeNew
];
89 for (; i
< size
; i
++) {
90 linesNew
[i
] = lines
[i
];
92 for (; i
< sizeNew
; i
++) {
93 linesNew
[i
].displayLine
= i
;
100 Platform::DebugPrintf("No memory available\n");
105 void ContractionState::InsertLines(int lineDoc
, int lineCount
) {
107 linesInDoc
+= lineCount
;
108 linesInDisplay
+= lineCount
;
111 //Platform::DebugPrintf("InsertLine[%d] = %d\n", lineDoc);
112 if ((linesInDoc
+ lineCount
+ 2) >= size
) {
113 Grow(linesInDoc
+ lineCount
+ growSize
);
115 linesInDoc
+= lineCount
;
116 linesInDisplay
+= lineCount
;
117 for (int i
= linesInDoc
; i
>= lineDoc
+ lineCount
; i
--) {
118 lines
[i
].visible
= lines
[i
- lineCount
].visible
;
119 lines
[i
].expanded
= lines
[i
- lineCount
].expanded
;
121 for (int d
=0;d
<lineCount
;d
++) {
122 lines
[lineDoc
+d
].visible
= true; // Should inherit visibility from context ?
123 lines
[lineDoc
+d
].expanded
= true;
128 void ContractionState::DeleteLines(int lineDoc
, int lineCount
) {
130 linesInDoc
-= lineCount
;
131 linesInDisplay
-= lineCount
;
134 int deltaDisplayed
= 0;
135 for (int d
=0;d
<lineCount
;d
++) {
136 if (lines
[lineDoc
+d
].visible
)
139 for (int i
= lineDoc
; i
< linesInDoc
-lineCount
; i
++) {
140 if (i
!= 0) // Line zero is always visible
141 lines
[i
].visible
= lines
[i
+ lineCount
].visible
;
142 lines
[i
].expanded
= lines
[i
+ lineCount
].expanded
;
144 linesInDoc
-= lineCount
;
145 linesInDisplay
+= deltaDisplayed
;
149 bool ContractionState::GetVisible(int lineDoc
) const {
152 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
153 return lines
[lineDoc
].visible
;
159 bool ContractionState::SetVisible(int lineDocStart
, int lineDocEnd
, bool visible
) {
160 if (lineDocStart
== 0)
162 if (lineDocStart
> lineDocEnd
)
165 Grow(linesInDoc
+ growSize
);
167 // TODO: modify docLine members to mirror displayLine
170 if ((lineDocStart
<= lineDocEnd
) && (lineDocStart
>= 0) && (lineDocEnd
< linesInDoc
)) {
171 for (int line
=lineDocStart
; line
<= lineDocEnd
; line
++) {
172 if (lines
[line
].visible
!= visible
) {
173 delta
+= visible
? 1 : -1;
174 lines
[line
].visible
= visible
;
178 linesInDisplay
+= delta
;
183 bool ContractionState::GetExpanded(int lineDoc
) const {
186 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
187 return lines
[lineDoc
].expanded
;
193 bool ContractionState::SetExpanded(int lineDoc
, bool expanded
) {
195 Grow(linesInDoc
+ growSize
);
197 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
198 if (lines
[lineDoc
].expanded
!= expanded
) {
199 lines
[lineDoc
].expanded
= expanded
;
206 void ContractionState::ShowAll() {