Merge pull request #1404 from b4n/search/gtk-3-20-history
[geany-mirror.git] / scintilla / src / CellBuffer.h
blobc1e973cff3b94cf310f625f2134f7ed34fc764ab
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);
52 enum actionType { insertAction, removeAction, startAction, containerAction };
54 /**
55 * Actions are used to store all the information required to perform one undo/redo step.
57 class Action {
58 public:
59 actionType at;
60 int position;
61 char *data;
62 int lenData;
63 bool mayCoalesce;
65 Action();
66 ~Action();
67 void Create(actionType at_, int position_=0, const char *data_=0, int lenData_=0, bool mayCoalesce_=true);
68 void Destroy();
69 void Grab(Action *source);
72 /**
75 class UndoHistory {
76 Action *actions;
77 int lenActions;
78 int maxAction;
79 int currentAction;
80 int undoSequenceDepth;
81 int savePoint;
82 int tentativePoint;
84 void EnsureUndoRoom();
86 // Private so UndoHistory objects can not be copied
87 UndoHistory(const UndoHistory &);
89 public:
90 UndoHistory();
91 ~UndoHistory();
93 const char *AppendAction(actionType at, int position, const char *data, int length, bool &startSequence, bool mayCoalesce=true);
95 void BeginUndoAction();
96 void EndUndoAction();
97 void DropUndoSequence();
98 void DeleteUndoHistory();
100 /// The save point is a marker in the undo stack where the container has stated that
101 /// the buffer was saved. Undo and redo can move over the save point.
102 void SetSavePoint();
103 bool IsSavePoint() const;
105 // Tentative actions are used for input composition so that it can be undone cleanly
106 void TentativeStart();
107 void TentativeCommit();
108 bool TentativeActive() const { return tentativePoint >= 0; }
109 int TentativeSteps();
111 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
112 /// called that many times. Similarly for redo.
113 bool CanUndo() const;
114 int StartUndo();
115 const Action &GetUndoStep() const;
116 void CompletedUndoStep();
117 bool CanRedo() const;
118 int StartRedo();
119 const Action &GetRedoStep() const;
120 void CompletedRedoStep();
124 * Holder for an expandable array of characters that supports undo and line markers.
125 * Based on article "Data Structures in a Bit-Mapped Text Editor"
126 * by Wilfred J. Hansen, Byte January 1987, page 183.
128 class CellBuffer {
129 private:
130 SplitVector<char> substance;
131 SplitVector<char> style;
132 bool readOnly;
133 int utf8LineEnds;
135 bool collectingUndo;
136 UndoHistory uh;
138 LineVector lv;
140 bool UTF8LineEndOverlaps(int position) const;
141 void ResetLineEnds();
142 /// Actions without undo
143 void BasicInsertString(int position, const char *s, int insertLength);
144 void BasicDeleteChars(int position, int deleteLength);
146 public:
148 CellBuffer();
149 ~CellBuffer();
151 /// Retrieving positions outside the range of the buffer works and returns 0
152 char CharAt(int position) const;
153 void GetCharRange(char *buffer, int position, int lengthRetrieve) const;
154 char StyleAt(int position) const;
155 void GetStyleRange(unsigned char *buffer, int position, int lengthRetrieve) const;
156 const char *BufferPointer();
157 const char *RangePointer(int position, int rangeLength);
158 int GapPosition() const;
160 int Length() const;
161 void Allocate(int newSize);
162 int GetLineEndTypes() const { return utf8LineEnds; }
163 void SetLineEndTypes(int utf8LineEnds_);
164 bool ContainsLineEnd(const char *s, int length) const;
165 void SetPerLine(PerLine *pl);
166 int Lines() const;
167 int LineStart(int line) const;
168 int LineFromPosition(int pos) const { return lv.LineFromPosition(pos); }
169 void InsertLine(int line, int position, bool lineStart);
170 void RemoveLine(int line);
171 const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);
173 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
174 /// @return true if the style of a character is changed.
175 bool SetStyleAt(int position, char styleValue);
176 bool SetStyleFor(int position, int length, char styleValue);
178 const char *DeleteChars(int position, int deleteLength, bool &startSequence);
180 bool IsReadOnly() const;
181 void SetReadOnly(bool set);
183 /// The save point is a marker in the undo stack where the container has stated that
184 /// the buffer was saved. Undo and redo can move over the save point.
185 void SetSavePoint();
186 bool IsSavePoint() const;
188 void TentativeStart();
189 void TentativeCommit();
190 bool TentativeActive() const;
191 int TentativeSteps();
193 bool SetUndoCollection(bool collectUndo);
194 bool IsCollectingUndo() const;
195 void BeginUndoAction();
196 void EndUndoAction();
197 void AddUndoAction(int token, bool mayCoalesce);
198 void DeleteUndoHistory();
200 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
201 /// called that many times. Similarly for redo.
202 bool CanUndo() const;
203 int StartUndo();
204 const Action &GetUndoStep() const;
205 void PerformUndoStep();
206 bool CanRedo() const;
207 int StartRedo();
208 const Action &GetRedoStep() const;
209 void PerformRedoStep();
212 #ifdef SCI_NAMESPACE
214 #endif
216 #endif