Update Scintilla to version 3.5.3
[TortoiseGit.git] / ext / scintilla / src / CellBuffer.h
blobcb81a7db47b1d63fc14b7cc76f37ae367661f18a
1 // Scintilla source code edit control
2 /** @file CellBuffer.h
3 ** Manages the text of the document.
4 **/
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.
8 #ifndef CELLBUFFER_H
9 #define CELLBUFFER_H
11 #ifdef SCI_NAMESPACE
12 namespace Scintilla {
13 #endif
15 // Interface to per-line data that wants to see each line insertion and deletion
16 class PerLine {
17 public:
18 virtual ~PerLine() {}
19 virtual void Init()=0;
20 virtual void InsertLine(int line)=0;
21 virtual void RemoveLine(int line)=0;
24 /**
25 * The line vector contains information about each of the lines in a cell buffer.
27 class LineVector {
29 Partitioning starts;
30 PerLine *perLine;
32 public:
34 LineVector();
35 ~LineVector();
36 void Init();
37 void SetPerLine(PerLine *pl);
39 void InsertText(int line, int delta);
40 void InsertLine(int line, int position, bool lineStart);
41 void SetLineStart(int line, int position);
42 void RemoveLine(int line);
43 int Lines() const {
44 return starts.Partitions();
46 int LineFromPosition(int pos) const;
47 int LineStart(int line) const {
48 return starts.PositionFromPartition(line);
51 int MarkValue(int line);
52 int AddMark(int line, int marker);
53 void MergeMarkers(int pos);
54 void DeleteMark(int line, int markerNum, bool all);
55 void DeleteMarkFromHandle(int markerHandle);
56 int LineFromHandle(int markerHandle);
58 void ClearLevels();
59 int SetLevel(int line, int level);
60 int GetLevel(int line);
62 int SetLineState(int line, int state);
63 int GetLineState(int line);
64 int GetMaxLineState();
68 enum actionType { insertAction, removeAction, startAction, containerAction };
70 /**
71 * Actions are used to store all the information required to perform one undo/redo step.
73 class Action {
74 public:
75 actionType at;
76 int position;
77 char *data;
78 int lenData;
79 bool mayCoalesce;
81 Action();
82 ~Action();
83 void Create(actionType at_, int position_=0, const char *data_=0, int lenData_=0, bool mayCoalesce_=true);
84 void Destroy();
85 void Grab(Action *source);
88 /**
91 class UndoHistory {
92 Action *actions;
93 int lenActions;
94 int maxAction;
95 int currentAction;
96 int undoSequenceDepth;
97 int savePoint;
98 int tentativePoint;
100 void EnsureUndoRoom();
102 // Private so UndoHistory objects can not be copied
103 UndoHistory(const UndoHistory &);
105 public:
106 UndoHistory();
107 ~UndoHistory();
109 const char *AppendAction(actionType at, int position, const char *data, int length, bool &startSequence, bool mayCoalesce=true);
111 void BeginUndoAction();
112 void EndUndoAction();
113 void DropUndoSequence();
114 void DeleteUndoHistory();
116 /// The save point is a marker in the undo stack where the container has stated that
117 /// the buffer was saved. Undo and redo can move over the save point.
118 void SetSavePoint();
119 bool IsSavePoint() const;
121 // Tentative actions are used for input composition so that it can be undone cleanly
122 void TentativeStart();
123 void TentativeCommit();
124 bool TentativeActive() const { return tentativePoint >= 0; }
125 int TentativeSteps();
127 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
128 /// called that many times. Similarly for redo.
129 bool CanUndo() const;
130 int StartUndo();
131 const Action &GetUndoStep() const;
132 void CompletedUndoStep();
133 bool CanRedo() const;
134 int StartRedo();
135 const Action &GetRedoStep() const;
136 void CompletedRedoStep();
140 * Holder for an expandable array of characters that supports undo and line markers.
141 * Based on article "Data Structures in a Bit-Mapped Text Editor"
142 * by Wilfred J. Hansen, Byte January 1987, page 183.
144 class CellBuffer {
145 private:
146 SplitVector<char> substance;
147 SplitVector<char> style;
148 bool readOnly;
149 int utf8LineEnds;
151 bool collectingUndo;
152 UndoHistory uh;
154 LineVector lv;
156 bool UTF8LineEndOverlaps(int position) const;
157 void ResetLineEnds();
158 /// Actions without undo
159 void BasicInsertString(int position, const char *s, int insertLength);
160 void BasicDeleteChars(int position, int deleteLength);
162 public:
164 CellBuffer();
165 ~CellBuffer();
167 /// Retrieving positions outside the range of the buffer works and returns 0
168 char CharAt(int position) const;
169 void GetCharRange(char *buffer, int position, int lengthRetrieve) const;
170 char StyleAt(int position) const;
171 void GetStyleRange(unsigned char *buffer, int position, int lengthRetrieve) const;
172 const char *BufferPointer();
173 const char *RangePointer(int position, int rangeLength);
174 int GapPosition() const;
176 int Length() const;
177 void Allocate(int newSize);
178 int GetLineEndTypes() const { return utf8LineEnds; }
179 void SetLineEndTypes(int utf8LineEnds_);
180 void SetPerLine(PerLine *pl);
181 int Lines() const;
182 int LineStart(int line) const;
183 int LineFromPosition(int pos) const { return lv.LineFromPosition(pos); }
184 void InsertLine(int line, int position, bool lineStart);
185 void RemoveLine(int line);
186 const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);
188 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
189 /// @return true if the style of a character is changed.
190 bool SetStyleAt(int position, char styleValue);
191 bool SetStyleFor(int position, int length, char styleValue);
193 const char *DeleteChars(int position, int deleteLength, bool &startSequence);
195 bool IsReadOnly() const;
196 void SetReadOnly(bool set);
198 /// The save point is a marker in the undo stack where the container has stated that
199 /// the buffer was saved. Undo and redo can move over the save point.
200 void SetSavePoint();
201 bool IsSavePoint() const;
203 void TentativeStart();
204 void TentativeCommit();
205 bool TentativeActive() const;
206 int TentativeSteps();
208 bool SetUndoCollection(bool collectUndo);
209 bool IsCollectingUndo() const;
210 void BeginUndoAction();
211 void EndUndoAction();
212 void AddUndoAction(int token, bool mayCoalesce);
213 void DeleteUndoHistory();
215 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
216 /// called that many times. Similarly for redo.
217 bool CanUndo() const;
218 int StartUndo();
219 const Action &GetUndoStep() const;
220 void PerformUndoStep();
221 bool CanRedo() const;
222 int StartRedo();
223 const Action &GetRedoStep() const;
224 void PerformRedoStep();
227 #ifdef SCI_NAMESPACE
229 #endif
231 #endif