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.
9 // This holds the marker identifier and the marker type to display.
10 // MarkerHandleNumbers are members of lists.
11 struct MarkerHandleNumber
{
14 MarkerHandleNumber
*next
;
17 // A marker handle set contains any number of MarkerHandleNumbers
18 class MarkerHandleSet
{
19 MarkerHandleNumber
*root
;
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
);
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.
37 MarkerHandleSet
*handleSet
;
38 LineData() : startPosition(0), handleSet(0) {
42 // The line vector contains information about each of the lines in a cell buffer.
45 enum { growSize
= 4000 };
52 // Handles are allocated sequentially and should never have to be reused as 32 bit ints are very big.
59 void Expand(int sizeNew
);
60 void ExpandLevels(int sizeNew
=-1);
61 void InsertValue(int pos
, int value
);
62 void SetValue(int pos
, int value
);
64 int LineFromPosition(int pos
);
66 int AddMark(int line
, int marker
);
67 void MergeMarkers(int pos
);
68 void DeleteMark(int line
, int markerNum
);
69 void DeleteMarkFromHandle(int markerHandle
);
70 int LineFromHandle(int markerHandle
);
73 // Actions are used to store all the information required to perform one undo/redo step.
74 enum actionType
{ insertAction
, removeAction
, startAction
};
86 void Create(actionType at_
, int position_
=0, char *data_
=0, int lenData_
=0, bool mayCoalesce_
=true);
88 void Grab(Action
*source
);
91 enum undoCollectionType
{ undoCollectNone
, undoCollectAutoStart
, undoCollectManualStart
};
98 int undoSequenceDepth
;
101 void EnsureUndoRoom();
107 void AppendAction(actionType at
, int position
, char *data
, int length
);
109 void BeginUndoAction();
110 void EndUndoAction();
111 void DropUndoSequence();
112 void DeleteUndoHistory();
114 // The save point is a marker in the undo stack where the container has stated that
115 // the buffer was saved. Undo and redo can move over the save point.
117 bool IsSavePoint() const;
119 // To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
120 // called that many times. Similarly for redo.
121 bool CanUndo() const;
123 const Action
&GetUndoStep() const;
124 void CompletedUndoStep();
125 bool CanRedo() const;
127 const Action
&GetRedoStep() const;
128 void CompletedRedoStep();
131 // Holder for an expandable array of characters that supports undo and line markers
132 // Based on article "Data Structures in a Bit-Mapped Text Editor"
133 // by Wilfred J. Hansen, Byte January 1987, page 183
144 undoCollectionType collectingUndo
;
149 SVector
<int, 4000> lineStates
;
151 void GapTo(int position
);
152 void RoomFor(int insertionLength
);
154 inline char ByteAt(int position
);
155 void SetByteAt(int position
, char ch
);
159 CellBuffer(int initialLength
= 4000);
162 // Retrieving positions outside the range of the buffer works and returns 0
163 char CharAt(int position
);
164 void GetCharRange(char *buffer
, int position
, int lengthRetrieve
);
165 char StyleAt(int position
);
170 int LineStart(int line
);
171 int LineFromPosition(int pos
) { return lv
.LineFromPosition(pos
); }
172 const char *InsertString(int position
, char *s
, int insertLength
);
173 void InsertCharStyle(int position
, char ch
, char style
);
175 // Setting styles for positions outside the range of the buffer is safe and has no effect.
176 // True is returned if the style of a character changed.
177 bool SetStyleAt(int position
, char style
, char mask
='\377');
178 bool SetStyleFor(int position
, int length
, char style
, char mask
);
180 const char *DeleteChars(int position
, int deleteLength
);
183 void SetReadOnly(bool set
);
185 // The save point is a marker in the undo stack where the container has stated that
186 // the buffer was saved. Undo and redo can move over the save point.
190 // Line marker functions
191 int AddMark(int line
, int markerNum
);
192 void DeleteMark(int line
, int markerNum
);
193 void DeleteMarkFromHandle(int markerHandle
);
194 int GetMark(int line
);
195 void DeleteAllMarks(int markerNum
);
196 int LineFromHandle(int markerHandle
);
199 void BasicInsertString(int position
, char *s
, int insertLength
);
200 void BasicDeleteChars(int position
, int deleteLength
);
202 undoCollectionType
SetUndoCollection(undoCollectionType collectUndo
);
203 bool IsCollectingUndo();
204 void BeginUndoAction();
205 void EndUndoAction();
206 void DeleteUndoHistory();
208 // To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
209 // called that many times. Similarly for redo.
212 const Action
&GetUndoStep() const;
213 void PerformUndoStep();
216 const Action
&GetRedoStep() const;
217 void PerformRedoStep();
219 int SetLineState(int line
, int state
);
220 int GetLineState(int line
);
221 int GetMaxLineState();
223 int SetLevel(int line
, int level
);
224 int GetLevel(int line
);