updated Scintilla to 2.29
[TortoiseGit.git] / ext / scintilla / src / CellBuffer.h
blob37bc58c340cc84ec57dc9b74f32fbfced560d634
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)=0;
21 virtual void RemoveLine(int)=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, 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 public:
102 UndoHistory();
103 ~UndoHistory();
105 void AppendAction(actionType at, int position, char *data, int length, bool &startSequence, bool mayCoalesce=true);
107 void BeginUndoAction();
108 void EndUndoAction();
109 void DropUndoSequence();
110 void DeleteUndoHistory();
112 /// The save point is a marker in the undo stack where the container has stated that
113 /// the buffer was saved. Undo and redo can move over the save point.
114 void SetSavePoint();
115 bool IsSavePoint() const;
117 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
118 /// called that many times. Similarly for redo.
119 bool CanUndo() const;
120 int StartUndo();
121 const Action &GetUndoStep() const;
122 void CompletedUndoStep();
123 bool CanRedo() const;
124 int StartRedo();
125 const Action &GetRedoStep() const;
126 void CompletedRedoStep();
130 * Holder for an expandable array of characters that supports undo and line markers.
131 * Based on article "Data Structures in a Bit-Mapped Text Editor"
132 * by Wilfred J. Hansen, Byte January 1987, page 183.
134 class CellBuffer {
135 private:
136 SplitVector<char> substance;
137 SplitVector<char> style;
138 bool readOnly;
140 bool collectingUndo;
141 UndoHistory uh;
143 LineVector lv;
145 /// Actions without undo
146 void BasicInsertString(int position, const char *s, int insertLength);
147 void BasicDeleteChars(int position, int deleteLength);
149 public:
151 CellBuffer();
152 ~CellBuffer();
154 /// Retrieving positions outside the range of the buffer works and returns 0
155 char CharAt(int position) const;
156 void GetCharRange(char *buffer, int position, int lengthRetrieve) const;
157 char StyleAt(int position) const;
158 void GetStyleRange(unsigned char *buffer, int position, int lengthRetrieve) const;
159 const char *BufferPointer();
161 int Length() const;
162 void Allocate(int newSize);
163 void SetPerLine(PerLine *pl);
164 int Lines() const;
165 int LineStart(int line) const;
166 int LineFromPosition(int pos) const { return lv.LineFromPosition(pos); }
167 void InsertLine(int line, int position, bool lineStart);
168 void RemoveLine(int line);
169 const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);
171 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
172 /// @return true if the style of a character is changed.
173 bool SetStyleAt(int position, char styleValue, char mask='\377');
174 bool SetStyleFor(int position, int length, char styleValue, char mask);
176 const char *DeleteChars(int position, int deleteLength, bool &startSequence);
178 bool IsReadOnly() const;
179 void SetReadOnly(bool set);
181 /// The save point is a marker in the undo stack where the container has stated that
182 /// the buffer was saved. Undo and redo can move over the save point.
183 void SetSavePoint();
184 bool IsSavePoint();
186 bool SetUndoCollection(bool collectUndo);
187 bool IsCollectingUndo() const;
188 void BeginUndoAction();
189 void EndUndoAction();
190 void AddUndoAction(int token, bool mayCoalesce);
191 void DeleteUndoHistory();
193 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
194 /// called that many times. Similarly for redo.
195 bool CanUndo();
196 int StartUndo();
197 const Action &GetUndoStep() const;
198 void PerformUndoStep();
199 bool CanRedo();
200 int StartRedo();
201 const Action &GetRedoStep() const;
202 void PerformRedoStep();
205 #ifdef SCI_NAMESPACE
207 #endif
209 #endif