OSDN Git Service

Add SCI Edit to GitBlameView
[tortoisegit/TortoiseGitJp.git] / ext / scintilla / src / CellBuffer.h
1 // Scintilla source code edit control\r
2 /** @file CellBuffer.h\r
3  ** Manages the text of the document.\r
4  **/\r
5 // Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>\r
6 // The License.txt file describes the conditions under which this software may be distributed.\r
7 \r
8 #ifndef CELLBUFFER_H\r
9 #define CELLBUFFER_H\r
10 \r
11 #ifdef SCI_NAMESPACE\r
12 namespace Scintilla {\r
13 #endif\r
14 \r
15 /**\r
16  * This holds the marker identifier and the marker type to display.\r
17  * MarkerHandleNumbers are members of lists.\r
18  */\r
19 struct MarkerHandleNumber {\r
20         int handle;\r
21         int number;\r
22         MarkerHandleNumber *next;\r
23 };\r
24 \r
25 /**\r
26  * A marker handle set contains any number of MarkerHandleNumbers.\r
27  */\r
28 class MarkerHandleSet {\r
29         MarkerHandleNumber *root;\r
30 \r
31 public:\r
32         MarkerHandleSet();\r
33         ~MarkerHandleSet();\r
34         int Length() const;\r
35         int NumberFromHandle(int handle) const;\r
36         int MarkValue() const;  ///< Bit set of marker numbers.\r
37         bool Contains(int handle) const;\r
38         bool InsertHandle(int handle, int markerNum);\r
39         void RemoveHandle(int handle);\r
40         bool RemoveNumber(int markerNum);\r
41         void CombineWith(MarkerHandleSet *other);\r
42 };\r
43 \r
44 /**\r
45  * The line vector contains information about each of the lines in a cell buffer.\r
46  */\r
47 class LineVector {\r
48 \r
49         Partitioning starts;\r
50         SplitVector<MarkerHandleSet *> markers;\r
51         SplitVector<int> levels;\r
52         /// Handles are allocated sequentially and should never have to be reused as 32 bit ints are very big.\r
53         int handleCurrent;\r
54 \r
55 public:\r
56 \r
57         LineVector();\r
58         ~LineVector();\r
59         void Init();\r
60 \r
61         void ExpandLevels(int sizeNew=-1);\r
62         void ClearLevels();\r
63         int SetLevel(int line, int level);\r
64         int GetLevel(int line);\r
65 \r
66         void InsertText(int line, int delta);\r
67         void InsertLine(int line, int position);\r
68         void SetLineStart(int line, int position);\r
69         void RemoveLine(int line);\r
70         int Lines() const {\r
71                 return starts.Partitions();\r
72         }\r
73         int LineFromPosition(int pos);\r
74         int LineStart(int line) const {\r
75                 return starts.PositionFromPartition(line);\r
76         }\r
77 \r
78         int MarkValue(int line);\r
79         int AddMark(int line, int marker);\r
80         void MergeMarkers(int pos);\r
81         void DeleteMark(int line, int markerNum, bool all);\r
82         void DeleteMarkFromHandle(int markerHandle);\r
83         int LineFromHandle(int markerHandle);\r
84 };\r
85 \r
86 enum actionType { insertAction, removeAction, startAction };\r
87 \r
88 /**\r
89  * Actions are used to store all the information required to perform one undo/redo step.\r
90  */\r
91 class Action {\r
92 public:\r
93         actionType at;\r
94         int position;\r
95         char *data;\r
96         int lenData;\r
97         bool mayCoalesce;\r
98 \r
99         Action();\r
100         ~Action();\r
101         void Create(actionType at_, int position_=0, char *data_=0, int lenData_=0, bool mayCoalesce_=true);\r
102         void Destroy();\r
103         void Grab(Action *source);\r
104 };\r
105 \r
106 /**\r
107  *\r
108  */\r
109 class UndoHistory {\r
110         Action *actions;\r
111         int lenActions;\r
112         int maxAction;\r
113         int currentAction;\r
114         int undoSequenceDepth;\r
115         int savePoint;\r
116 \r
117         void EnsureUndoRoom();\r
118 \r
119 public:\r
120         UndoHistory();\r
121         ~UndoHistory();\r
122 \r
123         void AppendAction(actionType at, int position, char *data, int length, bool &startSequence);\r
124 \r
125         void BeginUndoAction();\r
126         void EndUndoAction();\r
127         void DropUndoSequence();\r
128         void DeleteUndoHistory();\r
129 \r
130         /// The save point is a marker in the undo stack where the container has stated that\r
131         /// the buffer was saved. Undo and redo can move over the save point.\r
132         void SetSavePoint();\r
133         bool IsSavePoint() const;\r
134 \r
135         /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is\r
136         /// called that many times. Similarly for redo.\r
137         bool CanUndo() const;\r
138         int StartUndo();\r
139         const Action &GetUndoStep() const;\r
140         void CompletedUndoStep();\r
141         bool CanRedo() const;\r
142         int StartRedo();\r
143         const Action &GetRedoStep() const;\r
144         void CompletedRedoStep();\r
145 };\r
146 \r
147 /**\r
148  * Holder for an expandable array of characters that supports undo and line markers.\r
149  * Based on article "Data Structures in a Bit-Mapped Text Editor"\r
150  * by Wilfred J. Hansen, Byte January 1987, page 183.\r
151  */\r
152 class CellBuffer {\r
153 private:\r
154         SplitVector<char> substance;\r
155         SplitVector<char> style;\r
156         bool readOnly;\r
157 \r
158         bool collectingUndo;\r
159         UndoHistory uh;\r
160 \r
161         LineVector lv;\r
162 \r
163         SplitVector<int> lineStates;\r
164 \r
165 public:\r
166 \r
167         CellBuffer();\r
168         ~CellBuffer();\r
169 \r
170         /// Retrieving positions outside the range of the buffer works and returns 0\r
171         char CharAt(int position) const;\r
172         void GetCharRange(char *buffer, int position, int lengthRetrieve);\r
173         char StyleAt(int position);\r
174         const char *BufferPointer();\r
175 \r
176         int Length() const;\r
177         void Allocate(int newSize);\r
178         int Lines() const;\r
179         int LineStart(int line) const;\r
180         int LineFromPosition(int pos) { return lv.LineFromPosition(pos); }\r
181         void InsertLine(int line, int position);\r
182         void RemoveLine(int line);\r
183         const char *InsertString(int position, const char *s, int insertLength, bool &startSequence);\r
184 \r
185         /// Setting styles for positions outside the range of the buffer is safe and has no effect.\r
186         /// @return true if the style of a character is changed.\r
187         bool SetStyleAt(int position, char styleValue, char mask='\377');\r
188         bool SetStyleFor(int position, int length, char styleValue, char mask);\r
189 \r
190         const char *DeleteChars(int position, int deleteLength, bool &startSequence);\r
191 \r
192         bool IsReadOnly();\r
193         void SetReadOnly(bool set);\r
194 \r
195         /// The save point is a marker in the undo stack where the container has stated that\r
196         /// the buffer was saved. Undo and redo can move over the save point.\r
197         void SetSavePoint();\r
198         bool IsSavePoint();\r
199 \r
200         /// Line marker functions\r
201         int AddMark(int line, int markerNum);\r
202         void DeleteMark(int line, int markerNum);\r
203         void DeleteMarkFromHandle(int markerHandle);\r
204         int GetMark(int line);\r
205         void DeleteAllMarks(int markerNum);\r
206         int LineFromHandle(int markerHandle);\r
207 \r
208         /// Actions without undo\r
209         void BasicInsertString(int position, const char *s, int insertLength);\r
210         void BasicDeleteChars(int position, int deleteLength);\r
211 \r
212         bool SetUndoCollection(bool collectUndo);\r
213         bool IsCollectingUndo();\r
214         void BeginUndoAction();\r
215         void EndUndoAction();\r
216         void DeleteUndoHistory();\r
217 \r
218         /// To perform an undo, StartUndo is called to retrieve the number of steps, then UndoStep is\r
219         /// called that many times. Similarly for redo.\r
220         bool CanUndo();\r
221         int StartUndo();\r
222         const Action &GetUndoStep() const;\r
223         void PerformUndoStep();\r
224         bool CanRedo();\r
225         int StartRedo();\r
226         const Action &GetRedoStep() const;\r
227         void PerformRedoStep();\r
228 \r
229         int SetLineState(int line, int state);\r
230         int GetLineState(int line);\r
231         int GetMaxLineState();\r
232 \r
233         int SetLevel(int line, int level);\r
234         int GetLevel(int line);\r
235         void ClearLevels();\r
236 };\r
237 \r
238 #ifdef SCI_NAMESPACE\r
239 }\r
240 #endif\r
241 \r
242 #endif\r