]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/CellBuffer.h
3381c19c2c6ad90c3b6726d930d3af5fadeaf4f6
[wxWidgets.git] / src / stc / scintilla / src / CellBuffer.h
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.
7
8 #ifndef CELLBUFFER_H
9 #define CELLBUFFER_H
10
11 #ifdef SCI_NAMESPACE
12 namespace Scintilla {
13 #endif
14
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;
22 };
23
24 /**
25 * The line vector contains information about each of the lines in a cell buffer.
26 */
27 class LineVector {
28
29 Partitioning starts;
30 PerLine *perLine;
31
32 public:
33
34 LineVector();
35 ~LineVector();
36 void Init();
37 void SetPerLine(PerLine *pl);
38
39 void InsertText(int line, int delta);
40 void InsertLine(int line, int position);
41 void SetLineStart(int line, int position);
42 void RemoveLine(int line);
43 int Lines() const {
44 return starts.Partitions();
45 }
46 int LineFromPosition(int pos) const;
47 int LineStart(int line) const {
48 return starts.PositionFromPartition(line);
49 }
50
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);
57
58 void ClearLevels();
59 int SetLevel(int line, int level);
60 int GetLevel(int line);
61
62 int SetLineState(int line, int state);
63 int GetLineState(int line);
64 int GetMaxLineState();
65
66 };
67
68 enum actionType { insertAction, removeAction, startAction, containerAction };
69
70 /**
71 * Actions are used to store all the information required to perform one undo/redo step.
72 */
73 class Action {
74 public:
75 actionType at;
76 int position;
77 char *data;
78 int lenData;
79 bool mayCoalesce;
80
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);
86 };
87
88 /**
89 *
90 */
91 class UndoHistory {
92 Action *actions;
93 int lenActions;
94 int maxAction;
95 int currentAction;
96 int undoSequenceDepth;
97 int savePoint;
98
99 void EnsureUndoRoom();
100
101 public:
102 UndoHistory();
103 ~UndoHistory();
104
105 void AppendAction(actionType at, int position, char *data, int length, bool &startSequence, bool mayCoalesce=true);
106
107 void BeginUndoAction();
108 void EndUndoAction();
109 void DropUndoSequence();
110 void DeleteUndoHistory();
111
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;
116
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();
127 };
128
129 /**
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.
133 */
134 class CellBuffer {
135 private:
136 SplitVector<char> substance;
137 SplitVector<char> style;
138 bool readOnly;
139
140 bool collectingUndo;
141 UndoHistory uh;
142
143 LineVector lv;
144
145 public:
146
147 CellBuffer();
148 ~CellBuffer();
149
150 /// Retrieving positions outside the range of the buffer works and returns 0
151 char CharAt(int position) const;
152 void GetCharRange(char *buffer, int position, int lengthRetrieve);
153 char StyleAt(int position);
154 const char *BufferPointer();
155
156 int Length() const;
157 void Allocate(int newSize);
158 void SetPerLine(PerLine *pl);
159 int Lines() const;
160 int LineStart(int line) const;
161 int LineFromPosition(int pos) const { return lv.LineFromPosition(pos); }
162 void InsertLine(int line, int position);
163 void RemoveLine(int line);
164 const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);
165
166 /// Setting styles for positions outside the range of the buffer is safe and has no effect.
167 /// @return true if the style of a character is changed.
168 bool SetStyleAt(int position, char styleValue, char mask='\377');
169 bool SetStyleFor(int position, int length, char styleValue, char mask);
170
171 const char *DeleteChars(int position, int deleteLength, bool &startSequence);
172
173 bool IsReadOnly();
174 void SetReadOnly(bool set);
175
176 /// The save point is a marker in the undo stack where the container has stated that
177 /// the buffer was saved. Undo and redo can move over the save point.
178 void SetSavePoint();
179 bool IsSavePoint();
180
181 /// Actions without undo
182 void BasicInsertString(int position, const char *s, int insertLength);
183 void BasicDeleteChars(int position, int deleteLength);
184
185 bool SetUndoCollection(bool collectUndo);
186 bool IsCollectingUndo();
187 void BeginUndoAction();
188 void EndUndoAction();
189 void AddUndoAction(int token, bool mayCoalesce);
190 void DeleteUndoHistory();
191
192 /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is
193 /// called that many times. Similarly for redo.
194 bool CanUndo();
195 int StartUndo();
196 const Action &GetUndoStep() const;
197 void PerformUndoStep();
198 bool CanRedo();
199 int StartRedo();
200 const Action &GetRedoStep() const;
201 void PerformRedoStep();
202 };
203
204 #ifdef SCI_NAMESPACE
205 }
206 #endif
207
208 #endif