]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/CellBuffer.h
4f654a8fd99aec2651734f0dbeccc2e710f9bf76
[wxWidgets.git] / src / stc / scintilla / src / CellBuffer.h
1 // Scintilla source code edit control
2 /** @file CellBuffer.h
3 ** Manages the text of the document.
4 **/
5 // Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
7
8 #ifndef CELLBUFFER_H
9 #define CELLBUFFER_H
10
11 #ifdef SCI_NAMESPACE
12 namespace Scintilla {
13 #endif
14
15 /**
16 * This holds the marker identifier and the marker type to display.
17 * MarkerHandleNumbers are members of lists.
18 */
19 struct MarkerHandleNumber {
20 int handle;
21 int number;
22 MarkerHandleNumber *next;
23 };
24
25 /**
26 * A marker handle set contains any number of MarkerHandleNumbers.
27 */
28 class MarkerHandleSet {
29 MarkerHandleNumber *root;
30
31 public:
32 MarkerHandleSet();
33 ~MarkerHandleSet();
34 int Length() const;
35 int NumberFromHandle(int handle) const;
36 int MarkValue() const; ///< Bit set of marker numbers.
37 bool Contains(int handle) const;
38 bool InsertHandle(int handle, int markerNum);
39 void RemoveHandle(int handle);
40 bool RemoveNumber(int markerNum);
41 void CombineWith(MarkerHandleSet *other);
42 };
43
44 /**
45 * The line vector contains information about each of the lines in a cell buffer.
46 */
47 class LineVector {
48
49 Partitioning starts;
50 SplitVector<MarkerHandleSet *> markers;
51 SplitVector<int> levels;
52 /// Handles are allocated sequentially and should never have to be reused as 32 bit ints are very big.
53 int handleCurrent;
54
55 public:
56
57 LineVector();
58 ~LineVector();
59 void Init();
60
61 void ExpandLevels(int sizeNew=-1);
62 void ClearLevels();
63 int SetLevel(int line, int level);
64 int GetLevel(int line);
65
66 void InsertText(int line, int delta);
67 void InsertLine(int line, int position);
68 void SetLineStart(int line, int position);
69 void RemoveLine(int line);
70 int Lines() const {
71 return starts.Partitions();
72 }
73 int LineFromPosition(int pos);
74 int LineStart(int line) const {
75 return starts.PositionFromPartition(line);
76 }
77
78 int MarkValue(int line);
79 int AddMark(int line, int marker);
80 void MergeMarkers(int pos);
81 void DeleteMark(int line, int markerNum, bool all);
82 void DeleteMarkFromHandle(int markerHandle);
83 int LineFromHandle(int markerHandle);
84 };
85
86 enum actionType { insertAction, removeAction, startAction };
87
88 /**
89 * Actions are used to store all the information required to perform one undo/redo step.
90 */
91 class Action {
92 public:
93 actionType at;
94 int position;
95 char *data;
96 int lenData;
97 bool mayCoalesce;
98
99 Action();
100 ~Action();
101 void Create(actionType at_, int position_=0, char *data_=0, int lenData_=0, bool mayCoalesce_=true);
102 void Destroy();
103 void Grab(Action *source);
104 };
105
106 /**
107 *
108 */
109 class UndoHistory {
110 Action *actions;
111 int lenActions;
112 int maxAction;
113 int currentAction;
114 int undoSequenceDepth;
115 int savePoint;
116
117 void EnsureUndoRoom();
118
119 public:
120 UndoHistory();
121 ~UndoHistory();
122
123 void AppendAction(actionType at, int position, char *data, int length, bool &startSequence);
124
125 void BeginUndoAction();
126 void EndUndoAction();
127 void DropUndoSequence();
128 void DeleteUndoHistory();
129
130 /// The save point is a marker in the undo stack where the container has stated that
131 /// the buffer was saved. Undo and redo can move over the save point.
132 void SetSavePoint();
133 bool IsSavePoint() const;
134
135 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
136 /// called that many times. Similarly for redo.
137 bool CanUndo() const;
138 int StartUndo();
139 const Action &GetUndoStep() const;
140 void CompletedUndoStep();
141 bool CanRedo() const;
142 int StartRedo();
143 const Action &GetRedoStep() const;
144 void CompletedRedoStep();
145 };
146
147 /**
148 * Holder for an expandable array of characters that supports undo and line markers.
149 * Based on article "Data Structures in a Bit-Mapped Text Editor"
150 * by Wilfred J. Hansen, Byte January 1987, page 183.
151 */
152 class CellBuffer {
153 private:
154 SplitVector<char> substance;
155 SplitVector<char> style;
156 bool readOnly;
157
158 bool collectingUndo;
159 UndoHistory uh;
160
161 LineVector lv;
162
163 SplitVector<int> lineStates;
164
165 public:
166
167 CellBuffer();
168 ~CellBuffer();
169
170 /// Retrieving positions outside the range of the buffer works and returns 0
171 char CharAt(int position) const;
172 void GetCharRange(char *buffer, int position, int lengthRetrieve);
173 char StyleAt(int position);
174
175 int Length() const;
176 void Allocate(int newSize);
177 int Lines() const;
178 int LineStart(int line) const;
179 int LineFromPosition(int pos) { return lv.LineFromPosition(pos); }
180 void InsertLine(int line, int position);
181 void RemoveLine(int line);
182 const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);
183
184 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
185 /// @return true if the style of a character is changed.
186 bool SetStyleAt(int position, char styleValue, char mask='\377');
187 bool SetStyleFor(int position, int length, char styleValue, char mask);
188
189 const char *DeleteChars(int position, int deleteLength, bool &startSequence);
190
191 bool IsReadOnly();
192 void SetReadOnly(bool set);
193
194 /// The save point is a marker in the undo stack where the container has stated that
195 /// the buffer was saved. Undo and redo can move over the save point.
196 void SetSavePoint();
197 bool IsSavePoint();
198
199 /// Line marker functions
200 int AddMark(int line, int markerNum);
201 void DeleteMark(int line, int markerNum);
202 void DeleteMarkFromHandle(int markerHandle);
203 int GetMark(int line);
204 void DeleteAllMarks(int markerNum);
205 int LineFromHandle(int markerHandle);
206
207 /// Actions without undo
208 void BasicInsertString(int position, const char *s, int insertLength);
209 void BasicDeleteChars(int position, int deleteLength);
210
211 bool SetUndoCollection(bool collectUndo);
212 bool IsCollectingUndo();
213 void BeginUndoAction();
214 void EndUndoAction();
215 void DeleteUndoHistory();
216
217 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
218 /// called that many times. Similarly for redo.
219 bool CanUndo();
220 int StartUndo();
221 const Action &GetUndoStep() const;
222 void PerformUndoStep();
223 bool CanRedo();
224 int StartRedo();
225 const Action &GetRedoStep() const;
226 void PerformRedoStep();
227
228 int SetLineState(int line, int state);
229 int GetLineState(int line);
230 int GetMaxLineState();
231
232 int SetLevel(int line, int level);
233 int GetLevel(int line);
234 void ClearLevels();
235 };
236
237 #ifdef SCI_NAMESPACE
238 }
239 #endif
240
241 #endif