Update Scintilla to version 3.4.4
[TortoiseGit.git] / ext / scintilla / src / CellBuffer.h
blob6e03677085c32dbdef1c674daa1351d0bda8bf9f
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;
99 void EnsureUndoRoom();
101 // Private so UndoHistory objects can not be copied
102 UndoHistory(const UndoHistory &);
104 public:
105 UndoHistory();
106 ~UndoHistory();
108 const char *AppendAction(actionType at, int position, const char *data, int length, bool &startSequence, bool mayCoalesce=true);
110 void BeginUndoAction();
111 void EndUndoAction();
112 void DropUndoSequence();
113 void DeleteUndoHistory();
115 /// The save point is a marker in the undo stack where the container has stated that
116 /// the buffer was saved. Undo and redo can move over the save point.
117 void SetSavePoint();
118 bool IsSavePoint() const;
120 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
121 /// called that many times. Similarly for redo.
122 bool CanUndo() const;
123 int StartUndo();
124 const Action &GetUndoStep() const;
125 void CompletedUndoStep();
126 bool CanRedo() const;
127 int StartRedo();
128 const Action &GetRedoStep() const;
129 void CompletedRedoStep();
133 * Holder for an expandable array of characters that supports undo and line markers.
134 * Based on article "Data Structures in a Bit-Mapped Text Editor"
135 * by Wilfred J. Hansen, Byte January 1987, page 183.
137 class CellBuffer {
138 private:
139 SplitVector<char> substance;
140 SplitVector<char> style;
141 bool readOnly;
142 int utf8LineEnds;
144 bool collectingUndo;
145 UndoHistory uh;
147 LineVector lv;
149 bool UTF8LineEndOverlaps(int position) const;
150 void ResetLineEnds();
151 /// Actions without undo
152 void BasicInsertString(int position, const char *s, int insertLength);
153 void BasicDeleteChars(int position, int deleteLength);
155 public:
157 CellBuffer();
158 ~CellBuffer();
160 /// Retrieving positions outside the range of the buffer works and returns 0
161 char CharAt(int position) const;
162 void GetCharRange(char *buffer, int position, int lengthRetrieve) const;
163 char StyleAt(int position) const;
164 void GetStyleRange(unsigned char *buffer, int position, int lengthRetrieve) const;
165 const char *BufferPointer();
166 const char *RangePointer(int position, int rangeLength);
167 int GapPosition() const;
169 int Length() const;
170 void Allocate(int newSize);
171 int GetLineEndTypes() const { return utf8LineEnds; }
172 void SetLineEndTypes(int utf8LineEnds_);
173 void SetPerLine(PerLine *pl);
174 int Lines() const;
175 int LineStart(int line) const;
176 int LineFromPosition(int pos) const { return lv.LineFromPosition(pos); }
177 void InsertLine(int line, int position, bool lineStart);
178 void RemoveLine(int line);
179 const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);
181 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
182 /// @return true if the style of a character is changed.
183 bool SetStyleAt(int position, char styleValue);
184 bool SetStyleFor(int position, int length, char styleValue);
186 const char *DeleteChars(int position, int deleteLength, bool &startSequence);
188 bool IsReadOnly() const;
189 void SetReadOnly(bool set);
191 /// The save point is a marker in the undo stack where the container has stated that
192 /// the buffer was saved. Undo and redo can move over the save point.
193 void SetSavePoint();
194 bool IsSavePoint() const;
196 bool SetUndoCollection(bool collectUndo);
197 bool IsCollectingUndo() const;
198 void BeginUndoAction();
199 void EndUndoAction();
200 void AddUndoAction(int token, bool mayCoalesce);
201 void DeleteUndoHistory();
203 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
204 /// called that many times. Similarly for redo.
205 bool CanUndo() const;
206 int StartUndo();
207 const Action &GetUndoStep() const;
208 void PerformUndoStep();
209 bool CanRedo() const;
210 int StartRedo();
211 const Action &GetRedoStep() const;
212 void PerformRedoStep();
215 #ifdef SCI_NAMESPACE
217 #endif
219 #endif