1 // Scintilla source code edit control
\r
2 /** @file CellBuffer.h
\r
3 ** Manages the text of the document.
\r
5 // Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
\r
6 // The License.txt file describes the conditions under which this software may be distributed.
\r
11 #ifdef SCI_NAMESPACE
\r
12 namespace Scintilla {
\r
16 * This holds the marker identifier and the marker type to display.
\r
17 * MarkerHandleNumbers are members of lists.
\r
19 struct MarkerHandleNumber {
\r
22 MarkerHandleNumber *next;
\r
26 * A marker handle set contains any number of MarkerHandleNumbers.
\r
28 class MarkerHandleSet {
\r
29 MarkerHandleNumber *root;
\r
35 int NumberFromHandle(int handle) const;
\r
36 int MarkValue() const; ///< Bit set of marker numbers.
\r
37 bool Contains(int handle) const;
\r
38 bool InsertHandle(int handle, int markerNum);
\r
39 void RemoveHandle(int handle);
\r
40 bool RemoveNumber(int markerNum);
\r
41 void CombineWith(MarkerHandleSet *other);
\r
45 * The line vector contains information about each of the lines in a cell buffer.
\r
49 Partitioning starts;
\r
50 SplitVector<MarkerHandleSet *> markers;
\r
51 SplitVector<int> levels;
\r
52 /// Handles are allocated sequentially and should never have to be reused as 32 bit ints are very big.
\r
61 void ExpandLevels(int sizeNew=-1);
\r
63 int SetLevel(int line, int level);
\r
64 int GetLevel(int line);
\r
66 void InsertText(int line, int delta);
\r
67 void InsertLine(int line, int position);
\r
68 void SetLineStart(int line, int position);
\r
69 void RemoveLine(int line);
\r
71 return starts.Partitions();
\r
73 int LineFromPosition(int pos);
\r
74 int LineStart(int line) const {
\r
75 return starts.PositionFromPartition(line);
\r
78 int MarkValue(int line);
\r
79 int AddMark(int line, int marker);
\r
80 void MergeMarkers(int pos);
\r
81 void DeleteMark(int line, int markerNum, bool all);
\r
82 void DeleteMarkFromHandle(int markerHandle);
\r
83 int LineFromHandle(int markerHandle);
\r
86 enum actionType { insertAction, removeAction, startAction };
\r
89 * Actions are used to store all the information required to perform one undo/redo step.
\r
101 void Create(actionType at_, int position_=0, char *data_=0, int lenData_=0, bool mayCoalesce_=true);
\r
103 void Grab(Action *source);
\r
109 class UndoHistory {
\r
114 int undoSequenceDepth;
\r
117 void EnsureUndoRoom();
\r
123 void AppendAction(actionType at, int position, char *data, int length, bool &startSequence);
\r
125 void BeginUndoAction();
\r
126 void EndUndoAction();
\r
127 void DropUndoSequence();
\r
128 void DeleteUndoHistory();
\r
130 /// The save point is a marker in the undo stack where the container has stated that
\r
131 /// the buffer was saved. Undo and redo can move over the save point.
\r
132 void SetSavePoint();
\r
133 bool IsSavePoint() const;
\r
135 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
\r
136 /// called that many times. Similarly for redo.
\r
137 bool CanUndo() const;
\r
139 const Action &GetUndoStep() const;
\r
140 void CompletedUndoStep();
\r
141 bool CanRedo() const;
\r
143 const Action &GetRedoStep() const;
\r
144 void CompletedRedoStep();
\r
148 * Holder for an expandable array of characters that supports undo and line markers.
\r
149 * Based on article "Data Structures in a Bit-Mapped Text Editor"
\r
150 * by Wilfred J. Hansen, Byte January 1987, page 183.
\r
154 SplitVector<char> substance;
\r
155 SplitVector<char> style;
\r
158 bool collectingUndo;
\r
163 SplitVector<int> lineStates;
\r
170 /// Retrieving positions outside the range of the buffer works and returns 0
\r
171 char CharAt(int position) const;
\r
172 void GetCharRange(char *buffer, int position, int lengthRetrieve);
\r
173 char StyleAt(int position);
\r
174 const char *BufferPointer();
\r
176 int Length() const;
\r
177 void Allocate(int newSize);
\r
179 int LineStart(int line) const;
\r
180 int LineFromPosition(int pos) { return lv.LineFromPosition(pos); }
\r
181 void InsertLine(int line, int position);
\r
182 void RemoveLine(int line);
\r
183 const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);
\r
185 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
\r
186 /// @return true if the style of a character is changed.
\r
187 bool SetStyleAt(int position, char styleValue, char mask='\377');
\r
188 bool SetStyleFor(int position, int length, char styleValue, char mask);
\r
190 const char *DeleteChars(int position, int deleteLength, bool &startSequence);
\r
193 void SetReadOnly(bool set);
\r
195 /// The save point is a marker in the undo stack where the container has stated that
\r
196 /// the buffer was saved. Undo and redo can move over the save point.
\r
197 void SetSavePoint();
\r
198 bool IsSavePoint();
\r
200 /// Line marker functions
\r
201 int AddMark(int line, int markerNum);
\r
202 void DeleteMark(int line, int markerNum);
\r
203 void DeleteMarkFromHandle(int markerHandle);
\r
204 int GetMark(int line);
\r
205 void DeleteAllMarks(int markerNum);
\r
206 int LineFromHandle(int markerHandle);
\r
208 /// Actions without undo
\r
209 void BasicInsertString(int position, const char *s, int insertLength);
\r
210 void BasicDeleteChars(int position, int deleteLength);
\r
212 bool SetUndoCollection(bool collectUndo);
\r
213 bool IsCollectingUndo();
\r
214 void BeginUndoAction();
\r
215 void EndUndoAction();
\r
216 void DeleteUndoHistory();
\r
218 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
\r
219 /// called that many times. Similarly for redo.
\r
222 const Action &GetUndoStep() const;
\r
223 void PerformUndoStep();
\r
226 const Action &GetRedoStep() const;
\r
227 void PerformRedoStep();
\r
229 int SetLineState(int line, int state);
\r
230 int GetLineState(int line);
\r
231 int GetMaxLineState();
\r
233 int SetLevel(int line, int level);
\r
234 int GetLevel(int line);
\r
235 void ClearLevels();
\r
238 #ifdef SCI_NAMESPACE
\r