]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/CellBuffer.h
1 // Scintilla source code edit control
3 ** Manages the text of the document.
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.
12 * This holds the marker identifier and the marker type to display.
13 * MarkerHandleNumbers are members of lists.
15 struct MarkerHandleNumber
{
18 MarkerHandleNumber
*next
;
22 * A marker handle set contains any number of MarkerHandleNumbers.
24 class MarkerHandleSet
{
25 MarkerHandleNumber
*root
;
31 int NumberFromHandle(int handle
);
32 int MarkValue(); ///< Bit set of marker numbers.
33 bool Contains(int handle
);
34 bool InsertHandle(int handle
, int markerNum
);
35 void RemoveHandle(int handle
);
36 bool RemoveNumber(int markerNum
);
37 void CombineWith(MarkerHandleSet
*other
);
41 * Each line stores the starting position of the first character of the line in the cell buffer
42 * and potentially a marker handle set. Often a line will not have any attached markers.
46 MarkerHandleSet
*handleSet
;
47 LineData() : startPosition(0), handleSet(0) {
52 * The line vector contains information about each of the lines in a cell buffer.
63 /// Handles are allocated sequentially and should never have to be reused as 32 bit ints are very big.
70 void Expand(int sizeNew
);
71 void ExpandLevels(int sizeNew
=-1);
73 void InsertValue(int pos
, int value
);
74 void SetValue(int pos
, int value
);
76 int LineFromPosition(int pos
);
78 int AddMark(int line
, int marker
);
79 void MergeMarkers(int pos
);
80 void DeleteMark(int line
, int markerNum
, bool all
);
81 void DeleteMarkFromHandle(int markerHandle
);
82 int LineFromHandle(int markerHandle
);
85 enum actionType
{ insertAction
, removeAction
, startAction
};
88 * Actions are used to store all the information required to perform one undo/redo step.
100 void Create(actionType at_
, int position_
=0, char *data_
=0, int lenData_
=0, bool mayCoalesce_
=true);
102 void Grab(Action
*source
);
113 int undoSequenceDepth
;
116 void EnsureUndoRoom();
122 void AppendAction(actionType at
, int position
, char *data
, int length
);
124 void BeginUndoAction();
125 void EndUndoAction();
126 void DropUndoSequence();
127 void DeleteUndoHistory();
129 /// The save point is a marker in the undo stack where the container has stated that
130 /// the buffer was saved. Undo and redo can move over the save point.
132 bool IsSavePoint() const;
134 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
135 /// called that many times. Similarly for redo.
136 bool CanUndo() const;
138 const Action
&GetUndoStep() const;
139 void CompletedUndoStep();
140 bool CanRedo() const;
142 const Action
&GetRedoStep() const;
143 void CompletedRedoStep();
147 * Holder for an expandable array of characters that supports undo and line markers.
148 * Based on article "Data Structures in a Bit-Mapped Text Editor"
149 * by Wilfred J. Hansen, Byte January 1987, page 183.
153 char *body
; ///< The cell buffer itself.
154 int size
; ///< Allocated size of the buffer.
155 int length
; ///< Total length of the data.
156 int part1len
; ///< Length of the first part.
157 int gaplen
; ///< Length of the gap between the two parts.
158 char *part2body
; ///< The second part of the cell buffer.
159 ///< Doesn't point after the gap but set so that
160 ///< part2body[position] is consistent with body[position].
171 void GapTo(int position
);
172 void RoomFor(int insertionLength
);
174 inline char ByteAt(int position
);
175 void SetByteAt(int position
, char ch
);
179 CellBuffer(int initialLength
= 4000);
182 /// Retrieving positions outside the range of the buffer works and returns 0
183 char CharAt(int position
);
184 void GetCharRange(char *buffer
, int position
, int lengthRetrieve
);
185 char StyleAt(int position
);
189 void Allocate(int newSize
);
191 int LineStart(int line
);
192 int LineFromPosition(int pos
) { return lv
.LineFromPosition(pos
); }
193 const char *InsertString(int position
, char *s
, int insertLength
);
195 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
196 /// @return true if the style of a character is changed.
197 bool SetStyleAt(int position
, char style
, char mask
='\377');
198 bool SetStyleFor(int position
, int length
, char style
, char mask
);
200 const char *DeleteChars(int position
, int deleteLength
);
203 void SetReadOnly(bool set
);
205 /// The save point is a marker in the undo stack where the container has stated that
206 /// the buffer was saved. Undo and redo can move over the save point.
210 /// Line marker functions
211 int AddMark(int line
, int markerNum
);
212 void DeleteMark(int line
, int markerNum
);
213 void DeleteMarkFromHandle(int markerHandle
);
214 int GetMark(int line
);
215 void DeleteAllMarks(int markerNum
);
216 int LineFromHandle(int markerHandle
);
218 /// Actions without undo
219 void BasicInsertString(int position
, char *s
, int insertLength
);
220 void BasicDeleteChars(int position
, int deleteLength
);
222 bool SetUndoCollection(bool collectUndo
);
223 bool IsCollectingUndo();
224 void BeginUndoAction();
225 void EndUndoAction();
226 void DeleteUndoHistory();
228 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
229 /// called that many times. Similarly for redo.
232 const Action
&GetUndoStep() const;
233 void PerformUndoStep();
236 const Action
&GetRedoStep() const;
237 void PerformRedoStep();
239 int SetLineState(int line
, int state
);
240 int GetLineState(int line
);
241 int GetMaxLineState();
243 int SetLevel(int line
, int level
);
244 int GetLevel(int line
);