Update Scintilla to version 3.6.3
[geany-mirror.git] / scintilla / src / CellBuffer.h
blob1c53d14e65523069d37cad027d73dd043f9417d8
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 bool ContainsLineEnd(const char *s, int length) const;
181 void SetPerLine(PerLine *pl);
182 int Lines() const;
183 int LineStart(int line) const;
184 int LineFromPosition(int pos) const { return lv.LineFromPosition(pos); }
185 void InsertLine(int line, int position, bool lineStart);
186 void RemoveLine(int line);
187 const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);
189 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
190 /// @return true if the style of a character is changed.
191 bool SetStyleAt(int position, char styleValue);
192 bool SetStyleFor(int position, int length, char styleValue);
194 const char *DeleteChars(int position, int deleteLength, bool &startSequence);
196 bool IsReadOnly() const;
197 void SetReadOnly(bool set);
199 /// The save point is a marker in the undo stack where the container has stated that
200 /// the buffer was saved. Undo and redo can move over the save point.
201 void SetSavePoint();
202 bool IsSavePoint() const;
204 void TentativeStart();
205 void TentativeCommit();
206 bool TentativeActive() const;
207 int TentativeSteps();
209 bool SetUndoCollection(bool collectUndo);
210 bool IsCollectingUndo() const;
211 void BeginUndoAction();
212 void EndUndoAction();
213 void AddUndoAction(int token, bool mayCoalesce);
214 void DeleteUndoHistory();
216 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
217 /// called that many times. Similarly for redo.
218 bool CanUndo() const;
219 int StartUndo();
220 const Action &GetUndoStep() const;
221 void PerformUndoStep();
222 bool CanRedo() const;
223 int StartRedo();
224 const Action &GetRedoStep() const;
225 void PerformRedoStep();
228 #ifdef SCI_NAMESPACE
230 #endif
232 #endif