]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/ContractionState.cxx
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.
34 for (int line
=0; line
<linesInDoc
; line
++) {
35 lines
[line
].displayLine
= lineDisplay
;
36 if (lines
[line
].visible
) {
37 lines
[lineDisplay
].docLine
= line
;
45 void ContractionState::Clear() {
53 int ContractionState::LinesInDoc() const {
57 int ContractionState::LinesDisplayed() const {
58 return linesInDisplay
;
61 int ContractionState::DisplayFromDoc(int lineDoc
) const {
66 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
67 return lines
[lineDoc
].displayLine
;
72 int ContractionState::DocFromDisplay(int lineDisplay
) const {
75 if (lineDisplay
>= linesInDisplay
)
80 return lines
[lineDisplay
].docLine
;
83 void ContractionState::Grow(int sizeNew
) {
84 OneLine
*linesNew
= new OneLine
[sizeNew
];
87 for (; i
< size
; i
++) {
88 linesNew
[i
] = lines
[i
];
90 for (; i
< sizeNew
; i
++) {
91 linesNew
[i
].displayLine
= i
;
98 Platform::DebugPrintf("No memory available\n");
103 void ContractionState::InsertLines(int lineDoc
, int lineCount
) {
105 linesInDoc
+= lineCount
;
106 linesInDisplay
+= lineCount
;
109 //Platform::DebugPrintf("InsertLine[%d] = %d\n", lineDoc);
110 if ((linesInDoc
+ lineCount
+ 2) >= size
) {
111 Grow(linesInDoc
+ lineCount
+ growSize
);
113 linesInDoc
+= lineCount
;
114 linesInDisplay
+= lineCount
;
115 for (int i
= linesInDoc
; i
>= lineDoc
+ lineCount
; i
--) {
116 lines
[i
].visible
= lines
[i
- lineCount
].visible
;
117 lines
[i
].expanded
= lines
[i
- lineCount
].expanded
;
119 for (int d
=0;d
<lineCount
;d
++) {
120 lines
[lineDoc
+d
].visible
= true; // Should inherit visibility from context ?
121 lines
[lineDoc
+d
].expanded
= true;
126 void ContractionState::DeleteLines(int lineDoc
, int lineCount
) {
128 linesInDoc
-= lineCount
;
129 linesInDisplay
-= lineCount
;
132 int deltaDisplayed
= 0;
133 for (int d
=0;d
<lineCount
;d
++) {
134 if (lines
[lineDoc
+d
].visible
)
137 for (int i
= lineDoc
; i
< linesInDoc
-lineCount
; i
++) {
138 if (i
!= 0) // Line zero is always visible
139 lines
[i
].visible
= lines
[i
+ lineCount
].visible
;
140 lines
[i
].expanded
= lines
[i
+ lineCount
].expanded
;
142 linesInDoc
-= lineCount
;
143 linesInDisplay
+= deltaDisplayed
;
147 bool ContractionState::GetVisible(int lineDoc
) const {
150 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
151 return lines
[lineDoc
].visible
;
157 bool ContractionState::SetVisible(int lineDocStart
, int lineDocEnd
, bool visible
) {
158 if (lineDocStart
== 0)
160 if (lineDocStart
> lineDocEnd
)
163 Grow(linesInDoc
+ growSize
);
165 // TODO: modify docLine members to mirror displayLine
168 if ((lineDocStart
<= lineDocEnd
) && (lineDocStart
>= 0) && (lineDocEnd
< linesInDoc
)) {
169 for (int line
=lineDocStart
; line
<= lineDocEnd
; line
++) {
170 if (lines
[line
].visible
!= visible
) {
171 delta
+= visible
? 1 : -1;
172 lines
[line
].visible
= visible
;
176 linesInDisplay
+= delta
;
181 bool ContractionState::GetExpanded(int lineDoc
) const {
184 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
185 return lines
[lineDoc
].expanded
;
191 bool ContractionState::SetExpanded(int lineDoc
, bool expanded
) {
193 Grow(linesInDoc
+ growSize
);
195 if ((lineDoc
>= 0) && (lineDoc
< linesInDoc
)) {
196 if (lines
[lineDoc
].expanded
!= expanded
) {
197 lines
[lineDoc
].expanded
= expanded
;
204 void ContractionState::ShowAll() {