Add utils_get_real_path() and use it
[geany-mirror.git] / scintilla / src / CellBuffer.h
blob8e670aca563e7670e10c607ec101298866a7e7c1
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(Sci::Line line)=0;
21 virtual void RemoveLine(Sci::Line 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 // Deleted so LineVector objects can not be copied.
36 LineVector(const LineVector &) = delete;
37 void operator=(const LineVector &) = delete;
38 ~LineVector();
39 void Init();
40 void SetPerLine(PerLine *pl);
42 void InsertText(Sci::Line line, Sci::Position delta);
43 void InsertLine(Sci::Line line, Sci::Position position, bool lineStart);
44 void SetLineStart(Sci::Line line, Sci::Position position);
45 void RemoveLine(Sci::Line line);
46 Sci::Line Lines() const {
47 return starts.Partitions();
49 Sci::Line LineFromPosition(Sci::Position pos) const;
50 Sci::Position LineStart(Sci::Line line) const {
51 return starts.PositionFromPartition(line);
55 enum actionType { insertAction, removeAction, startAction, containerAction };
57 /**
58 * Actions are used to store all the information required to perform one undo/redo step.
60 class Action {
61 public:
62 actionType at;
63 Sci::Position position;
64 std::unique_ptr<char[]> data;
65 Sci::Position lenData;
66 bool mayCoalesce;
68 Action();
69 // Deleted so Action objects can not be copied.
70 Action(const Action &other) = delete;
71 Action &operator=(const Action &other) = delete;
72 Action &operator=(const Action &&other) = delete;
73 // Move constructor allows vector to be resized without reallocating.
74 // Could use =default but MSVC 2013 warns.
75 Action(Action &&other);
76 ~Action();
77 void Create(actionType at_, Sci::Position position_=0, const char *data_=0, Sci::Position lenData_=0, bool mayCoalesce_=true);
78 void Clear();
81 /**
84 class UndoHistory {
85 std::vector<Action> actions;
86 int maxAction;
87 int currentAction;
88 int undoSequenceDepth;
89 int savePoint;
90 int tentativePoint;
92 void EnsureUndoRoom();
94 public:
95 UndoHistory();
96 // Deleted so UndoHistory objects can not be copied.
97 UndoHistory(const UndoHistory &) = delete;
98 void operator=(const UndoHistory &) = delete;
99 ~UndoHistory();
101 const char *AppendAction(actionType at, Sci::Position position, const char *data, Sci::Position lengthData, bool &startSequence, bool mayCoalesce=true);
103 void BeginUndoAction();
104 void EndUndoAction();
105 void DropUndoSequence();
106 void DeleteUndoHistory();
108 /// The save point is a marker in the undo stack where the container has stated that
109 /// the buffer was saved. Undo and redo can move over the save point.
110 void SetSavePoint();
111 bool IsSavePoint() const;
113 // Tentative actions are used for input composition so that it can be undone cleanly
114 void TentativeStart();
115 void TentativeCommit();
116 bool TentativeActive() const { return tentativePoint >= 0; }
117 int TentativeSteps();
119 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
120 /// called that many times. Similarly for redo.
121 bool CanUndo() const;
122 int StartUndo();
123 const Action &GetUndoStep() const;
124 void CompletedUndoStep();
125 bool CanRedo() const;
126 int StartRedo();
127 const Action &GetRedoStep() const;
128 void CompletedRedoStep();
132 * Holder for an expandable array of characters that supports undo and line markers.
133 * Based on article "Data Structures in a Bit-Mapped Text Editor"
134 * by Wilfred J. Hansen, Byte January 1987, page 183.
136 class CellBuffer {
137 private:
138 SplitVector<char> substance;
139 SplitVector<char> style;
140 bool readOnly;
141 int utf8LineEnds;
143 bool collectingUndo;
144 UndoHistory uh;
146 LineVector lv;
148 bool UTF8LineEndOverlaps(Sci::Position position) const;
149 void ResetLineEnds();
150 /// Actions without undo
151 void BasicInsertString(Sci::Position position, const char *s, Sci::Position insertLength);
152 void BasicDeleteChars(Sci::Position position, Sci::Position deleteLength);
154 public:
156 CellBuffer();
157 // Deleted so CellBuffer objects can not be copied.
158 CellBuffer(const CellBuffer &) = delete;
159 void operator=(const CellBuffer &) = delete;
160 ~CellBuffer();
162 /// Retrieving positions outside the range of the buffer works and returns 0
163 char CharAt(Sci::Position position) const;
164 void GetCharRange(char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const;
165 char StyleAt(Sci::Position position) const;
166 void GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const;
167 const char *BufferPointer();
168 const char *RangePointer(Sci::Position position, Sci::Position rangeLength);
169 Sci::Position GapPosition() const;
171 Sci::Position Length() const;
172 void Allocate(Sci::Position newSize);
173 int GetLineEndTypes() const { return utf8LineEnds; }
174 void SetLineEndTypes(int utf8LineEnds_);
175 bool ContainsLineEnd(const char *s, Sci::Position length) const;
176 void SetPerLine(PerLine *pl);
177 Sci::Line Lines() const;
178 Sci::Position LineStart(Sci::Line line) const;
179 Sci::Line LineFromPosition(Sci::Position pos) const { return lv.LineFromPosition(pos); }
180 void InsertLine(Sci::Line line, Sci::Position position, bool lineStart);
181 void RemoveLine(Sci::Line line);
182 const char *InsertString(Sci::Position position, const char *s, Sci::Position insertLength, bool &startSequence);
184 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
185 /// @return true if the style of a character is changed.
186 bool SetStyleAt(Sci::Position position, char styleValue);
187 bool SetStyleFor(Sci::Position position, Sci::Position lengthStyle, char styleValue);
189 const char *DeleteChars(Sci::Position position, Sci::Position deleteLength, bool &startSequence);
191 bool IsReadOnly() const;
192 void SetReadOnly(bool set);
194 /// The save point is a marker in the undo stack where the container has stated that
195 /// the buffer was saved. Undo and redo can move over the save point.
196 void SetSavePoint();
197 bool IsSavePoint() const;
199 void TentativeStart();
200 void TentativeCommit();
201 bool TentativeActive() const;
202 int TentativeSteps();
204 bool SetUndoCollection(bool collectUndo);
205 bool IsCollectingUndo() const;
206 void BeginUndoAction();
207 void EndUndoAction();
208 void AddUndoAction(Sci::Position token, bool mayCoalesce);
209 void DeleteUndoHistory();
211 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
212 /// called that many times. Similarly for redo.
213 bool CanUndo() const;
214 int StartUndo();
215 const Action &GetUndoStep() const;
216 void PerformUndoStep();
217 bool CanRedo() const;
218 int StartRedo();
219 const Action &GetRedoStep() const;
220 void PerformRedoStep();
223 #ifdef SCI_NAMESPACE
225 #endif
227 #endif