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
};
92 // Holder for an expandable array of characters that supports undo and line markers
93 // Based on article "Data Structures in a Bit-Mapped Text Editor"
94 // by Wilfred J. Hansen, Byte January 1987, page 183
109 undoCollectionType collectingUndo
;
110 int undoSequenceDepth
;
115 SVector
<int, 4000> lineStates
;
117 void GapTo(int position
);
118 void RoomFor(int insertionLength
);
120 void EnsureUndoRoom();
121 void AppendAction(actionType at
, int position
, char *data
, int length
);
123 inline char ByteAt(int position
);
124 void SetByteAt(int position
, char ch
);
128 CellBuffer(int initialLength
= 4000);
131 // Retrieving positions outside the range of the buffer works and returns 0
132 char CharAt(int position
);
133 void GetCharRange(char *buffer
, int position
, int lengthRetrieve
);
134 char StyleAt(int position
);
139 int LineStart(int line
);
140 int LineFromPosition(int pos
) { return lv
.LineFromPosition(pos
); }
141 const char *InsertString(int position
, char *s
, int insertLength
);
142 void InsertCharStyle(int position
, char ch
, char style
);
144 // Setting styles for positions outside the range of the buffer is safe and has no effect.
145 // True is returned if the style of a character changed.
146 bool SetStyleAt(int position
, char style
, char mask
=(char)0xff);
147 bool SetStyleFor(int position
, int length
, char style
, char mask
);
149 const char *DeleteChars(int position
, int deleteLength
);
152 void SetReadOnly(bool set
);
154 // The save point is a marker in the undo stack where the container has stated that
155 // the buffer was saved. Undo and redo can move over the save point.
159 // Line marker functions
160 int AddMark(int line
, int markerNum
);
161 void DeleteMark(int line
, int markerNum
);
162 void DeleteMarkFromHandle(int markerHandle
);
163 int GetMark(int line
);
164 void DeleteAllMarks(int markerNum
);
165 int LineFromHandle(int markerHandle
);
168 void BasicInsertString(int position
, char *s
, int insertLength
);
169 void BasicDeleteChars(int position
, int deleteLength
);
171 undoCollectionType
SetUndoCollection(undoCollectionType collectUndo
);
172 bool IsCollectingUndo();
173 void AppendUndoStartAction();
174 void BeginUndoAction();
175 void EndUndoAction();
176 void DeleteUndoHistory();
178 // To perform an undo, StartUndo is called to retreive the number of steps, then UndoStep is
179 // called that many times. Similarly for redo.
182 const Action
&UndoStep();
185 const Action
&RedoStep();
187 int SetLineState(int line
, int state
);
188 int GetLineState(int line
);
189 int GetMaxLineState();
191 int SetLevel(int line
, int level
);
192 int GetLevel(int line
);