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
};
85 void Create(actionType at_
, int position_
=0, char *data_
=0, int lenData_
=0);
87 void Grab(Action
*source
);
90 enum undoCollectionType
{ undoCollectNone
, undoCollectAutoStart
, undoCollectManualStart
};
97 int undoSequenceDepth
;
100 void EnsureUndoRoom();
106 void AppendAction(actionType at
, int position
, char *data
, int length
);
108 void BeginUndoAction();
109 void EndUndoAction();
110 void DropUndoSequence();
111 void DeleteUndoHistory();
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.
116 bool IsSavePoint() const;
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;
122 const Action
&UndoStep();
123 bool CanRedo() const;
125 const Action
&RedoStep();
128 // Holder for an expandable array of characters that supports undo and line markers
129 // Based on article "Data Structures in a Bit-Mapped Text Editor"
130 // by Wilfred J. Hansen, Byte January 1987, page 183
141 undoCollectionType collectingUndo
;
146 SVector
<int, 4000> lineStates
;
148 void GapTo(int position
);
149 void RoomFor(int insertionLength
);
151 inline char ByteAt(int position
);
152 void SetByteAt(int position
, char ch
);
156 CellBuffer(int initialLength
= 4000);
159 // Retrieving positions outside the range of the buffer works and returns 0
160 char CharAt(int position
);
161 void GetCharRange(char *buffer
, int position
, int lengthRetrieve
);
162 char StyleAt(int position
);
167 int LineStart(int line
);
168 int LineFromPosition(int pos
) { return lv
.LineFromPosition(pos
); }
169 const char *InsertString(int position
, char *s
, int insertLength
);
170 void InsertCharStyle(int position
, char ch
, char style
);
172 // Setting styles for positions outside the range of the buffer is safe and has no effect.
173 // True is returned if the style of a character changed.
174 bool SetStyleAt(int position
, char style
, char mask
=(char)0xff);
175 bool SetStyleFor(int position
, int length
, char style
, char mask
);
177 const char *DeleteChars(int position
, int deleteLength
);
180 void SetReadOnly(bool set
);
182 // The save point is a marker in the undo stack where the container has stated that
183 // the buffer was saved. Undo and redo can move over the save point.
187 // Line marker functions
188 int AddMark(int line
, int markerNum
);
189 void DeleteMark(int line
, int markerNum
);
190 void DeleteMarkFromHandle(int markerHandle
);
191 int GetMark(int line
);
192 void DeleteAllMarks(int markerNum
);
193 int LineFromHandle(int markerHandle
);
196 void BasicInsertString(int position
, char *s
, int insertLength
);
197 void BasicDeleteChars(int position
, int deleteLength
);
199 undoCollectionType
SetUndoCollection(undoCollectionType collectUndo
);
200 bool IsCollectingUndo();
201 void BeginUndoAction();
202 void EndUndoAction();
203 void DeleteUndoHistory();
205 // To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
206 // called that many times. Similarly for redo.
209 const Action
&UndoStep();
212 const Action
&RedoStep();
214 int SetLineState(int line
, int state
);
215 int GetLineState(int line
);
216 int GetMaxLineState();
218 int SetLevel(int line
, int level
);
219 int GetLevel(int line
);