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