OSDN Git Service

Commit DialogBox compile Okay
[tortoisegit/TortoiseGitJp.git] / ext / scintilla / src / Document.h
1 // Scintilla source code edit control\r
2 /** @file Document.h\r
3  ** Text document that handles notifications, DBCS, styling, words and end of line.\r
4  **/\r
5 // Copyright 1998-2003 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 DOCUMENT_H\r
9 #define DOCUMENT_H\r
10 \r
11 #ifdef SCI_NAMESPACE\r
12 namespace Scintilla {\r
13 #endif\r
14 \r
15 /**\r
16  * A Position is a position within a document between two characters or at the beginning or end.\r
17  * Sometimes used as a character index where it identifies the character after the position.\r
18  */\r
19 typedef int Position;\r
20 const Position invalidPosition = -1;\r
21 \r
22 /**\r
23  * The range class represents a range of text in a document.\r
24  * The two values are not sorted as one end may be more significant than the other\r
25  * as is the case for the selection where the end position is the position of the caret.\r
26  * If either position is invalidPosition then the range is invalid and most operations will fail.\r
27  */\r
28 class Range {\r
29 public:\r
30         Position start;\r
31         Position end;\r
32 \r
33         Range(Position pos=0) :\r
34                 start(pos), end(pos) {\r
35         };\r
36         Range(Position start_, Position end_) :\r
37                 start(start_), end(end_) {\r
38         };\r
39 \r
40         bool Valid() const {\r
41                 return (start != invalidPosition) && (end != invalidPosition);\r
42         }\r
43 \r
44         // Is the position within the range?\r
45         bool Contains(Position pos) const {\r
46                 if (start < end) {\r
47                         return (pos >= start && pos <= end);\r
48                 } else {\r
49                         return (pos <= start && pos >= end);\r
50                 }\r
51         }\r
52 \r
53         // Is the character after pos within the range?\r
54         bool ContainsCharacter(Position pos) const {\r
55                 if (start < end) {\r
56                         return (pos >= start && pos < end);\r
57                 } else {\r
58                         return (pos < start && pos >= end);\r
59                 }\r
60         }\r
61 \r
62         bool Contains(Range other) const {\r
63                 return Contains(other.start) && Contains(other.end);\r
64         }\r
65 \r
66         bool Overlaps(Range other) const {\r
67                 return\r
68                 Contains(other.start) ||\r
69                 Contains(other.end) ||\r
70                 other.Contains(start) ||\r
71                 other.Contains(end);\r
72         }\r
73 };\r
74 \r
75 class DocWatcher;\r
76 class DocModification;\r
77 class Document;\r
78 \r
79 /**\r
80  * Interface class for regular expression searching\r
81  */\r
82 class RegexSearchBase {\r
83 public:\r
84         virtual ~RegexSearchBase(){}\r
85 \r
86         virtual long FindText(Document* doc, int minPos, int maxPos, const char *s,\r
87                         bool caseSensitive, bool word, bool wordStart, int flags, int *length) = 0;\r
88 \r
89         ///@return String with the substitutions, must remain valid until the next call or destruction\r
90         virtual const char *SubstituteByPosition(Document* doc, const char *text, int *length) = 0;\r
91 };\r
92 \r
93 /// Factory function for RegexSearchBase\r
94 extern RegexSearchBase* CreateRegexSearch(CharClassify *charClassTable);\r
95 \r
96 /**\r
97  */\r
98 class Document {\r
99 \r
100 public:\r
101         /** Used to pair watcher pointer with user data. */\r
102         class WatcherWithUserData {\r
103         public:\r
104                 DocWatcher *watcher;\r
105                 void *userData;\r
106                 WatcherWithUserData() {\r
107                         watcher = 0;\r
108                         userData = 0;\r
109                 }\r
110         };\r
111 \r
112         enum charClassification { ccSpace, ccNewLine, ccWord, ccPunctuation };\r
113 \r
114 private:\r
115         int refCount;\r
116         CellBuffer cb;\r
117         CharClassify charClass;\r
118         char stylingMask;\r
119         int endStyled;\r
120         int styleClock;\r
121         int enteredModification;\r
122         int enteredStyling;\r
123         int enteredReadOnlyCount;\r
124 \r
125         WatcherWithUserData *watchers;\r
126         int lenWatchers;\r
127 \r
128         bool matchesValid;\r
129         RegexSearchBase* regex;\r
130 \r
131 public:\r
132         int stylingBits;\r
133         int stylingBitsMask;\r
134 \r
135         int eolMode;\r
136         /// Can also be SC_CP_UTF8 to enable UTF-8 mode\r
137         int dbcsCodePage;\r
138         int tabInChars;\r
139         int indentInChars;\r
140         int actualIndentInChars;\r
141         bool useTabs;\r
142         bool tabIndents;\r
143         bool backspaceUnindents;\r
144 \r
145         DecorationList decorations;\r
146 \r
147         Document();\r
148         virtual ~Document();\r
149 \r
150         int AddRef();\r
151         int Release();\r
152 \r
153         int LineFromPosition(int pos);\r
154         int ClampPositionIntoDocument(int pos);\r
155         bool IsCrLf(int pos);\r
156         int LenChar(int pos);\r
157         bool InGoodUTF8(int pos, int &start, int &end);\r
158         int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);\r
159 \r
160         // Gateways to modifying document\r
161         void ModifiedAt(int pos);\r
162         void CheckReadOnly();\r
163         bool DeleteChars(int pos, int len);\r
164         bool InsertString(int position, const char *s, int insertLength);\r
165         int Undo();\r
166         int Redo();\r
167         bool CanUndo() { return cb.CanUndo(); }\r
168         bool CanRedo() { return cb.CanRedo(); }\r
169         void DeleteUndoHistory() { cb.DeleteUndoHistory(); }\r
170         bool SetUndoCollection(bool collectUndo) {\r
171                 return cb.SetUndoCollection(collectUndo);\r
172         }\r
173         bool IsCollectingUndo() { return cb.IsCollectingUndo(); }\r
174         void BeginUndoAction() { cb.BeginUndoAction(); }\r
175         void EndUndoAction() { cb.EndUndoAction(); }\r
176         void SetSavePoint();\r
177         bool IsSavePoint() { return cb.IsSavePoint(); }\r
178         const char *BufferPointer() { return cb.BufferPointer(); }\r
179 \r
180         int GetLineIndentation(int line);\r
181         void SetLineIndentation(int line, int indent);\r
182         int GetLineIndentPosition(int line) const;\r
183         int GetColumn(int position);\r
184         int FindColumn(int line, int column);\r
185         void Indent(bool forwards, int lineBottom, int lineTop);\r
186         static char *TransformLineEnds(int *pLenOut, const char *s, size_t len, int eolMode);\r
187         void ConvertLineEnds(int eolModeSet);\r
188         void SetReadOnly(bool set) { cb.SetReadOnly(set); }\r
189         bool IsReadOnly() { return cb.IsReadOnly(); }\r
190 \r
191         bool InsertChar(int pos, char ch);\r
192         bool InsertCString(int position, const char *s);\r
193         void ChangeChar(int pos, char ch);\r
194         void DelChar(int pos);\r
195         void DelCharBack(int pos);\r
196 \r
197         char CharAt(int position) { return cb.CharAt(position); }\r
198         void GetCharRange(char *buffer, int position, int lengthRetrieve) {\r
199                 cb.GetCharRange(buffer, position, lengthRetrieve);\r
200         }\r
201         char StyleAt(int position) { return cb.StyleAt(position); }\r
202         int GetMark(int line) { return cb.GetMark(line); }\r
203         int AddMark(int line, int markerNum);\r
204         void AddMarkSet(int line, int valueSet);\r
205         void DeleteMark(int line, int markerNum);\r
206         void DeleteMarkFromHandle(int markerHandle);\r
207         void DeleteAllMarks(int markerNum);\r
208         int LineFromHandle(int markerHandle) { return cb.LineFromHandle(markerHandle); }\r
209         int LineStart(int line) const;\r
210         int LineEnd(int line) const;\r
211         int LineEndPosition(int position);\r
212         int VCHomePosition(int position);\r
213 \r
214         int SetLevel(int line, int level);\r
215         int GetLevel(int line) { return cb.GetLevel(line); }\r
216         void ClearLevels() { cb.ClearLevels(); }\r
217         int GetLastChild(int lineParent, int level=-1);\r
218         int GetFoldParent(int line);\r
219 \r
220         void Indent(bool forwards);\r
221         int ExtendWordSelect(int pos, int delta, bool onlyWordCharacters=false);\r
222         int NextWordStart(int pos, int delta);\r
223         int NextWordEnd(int pos, int delta);\r
224         int Length() const { return cb.Length(); }\r
225         void Allocate(int newSize) { cb.Allocate(newSize); }\r
226         long FindText(int minPos, int maxPos, const char *s,\r
227                 bool caseSensitive, bool word, bool wordStart, bool regExp, int flags, int *length);\r
228         long FindText(int iMessage, unsigned long wParam, long lParam);\r
229         const char *SubstituteByPosition(const char *text, int *length);\r
230         int LinesTotal() const;\r
231 \r
232         void ChangeCase(Range r, bool makeUpperCase);\r
233 \r
234         void SetDefaultCharClasses(bool includeWordClass);\r
235         void SetCharClasses(const unsigned char *chars, CharClassify::cc newCharClass);\r
236         void SetStylingBits(int bits);\r
237         void StartStyling(int position, char mask);\r
238         bool SetStyleFor(int length, char style);\r
239         bool SetStyles(int length, char *styles);\r
240         int GetEndStyled() { return endStyled; }\r
241         void EnsureStyledTo(int pos);\r
242         int GetStyleClock() { return styleClock; }\r
243         void IncrementStyleClock();\r
244         void DecorationFillRange(int position, int value, int fillLength);\r
245 \r
246         int SetLineState(int line, int state);\r
247         int GetLineState(int line) { return cb.GetLineState(line); }\r
248         int GetMaxLineState() { return cb.GetMaxLineState(); }\r
249 \r
250         bool AddWatcher(DocWatcher *watcher, void *userData);\r
251         bool RemoveWatcher(DocWatcher *watcher, void *userData);\r
252         const WatcherWithUserData *GetWatchers() const { return watchers; }\r
253         int GetLenWatchers() const { return lenWatchers; }\r
254 \r
255         bool IsWordPartSeparator(char ch);\r
256         int WordPartLeft(int pos);\r
257         int WordPartRight(int pos);\r
258         int ExtendStyleRange(int pos, int delta, bool singleLine = false);\r
259         bool IsWhiteLine(int line) const;\r
260         int ParaUp(int pos);\r
261         int ParaDown(int pos);\r
262         int IndentSize() { return actualIndentInChars; }\r
263         int BraceMatch(int position, int maxReStyle);\r
264 \r
265 private:\r
266         CharClassify::cc WordCharClass(unsigned char ch);\r
267         bool IsWordStartAt(int pos);\r
268         bool IsWordEndAt(int pos);\r
269         bool IsWordAt(int start, int end);\r
270 \r
271         void NotifyModifyAttempt();\r
272         void NotifySavePoint(bool atSavePoint);\r
273         void NotifyModified(DocModification mh);\r
274 };\r
275 \r
276 /**\r
277  * To optimise processing of document modifications by DocWatchers, a hint is passed indicating the\r
278  * scope of the change.\r
279  * If the DocWatcher is a document view then this can be used to optimise screen updating.\r
280  */\r
281 class DocModification {\r
282 public:\r
283         int modificationType;\r
284         int position;\r
285         int length;\r
286         int linesAdded; /**< Negative if lines deleted. */\r
287         const char *text;       /**< Only valid for changes to text, not for changes to style. */\r
288         int line;\r
289         int foldLevelNow;\r
290         int foldLevelPrev;\r
291 \r
292         DocModification(int modificationType_, int position_=0, int length_=0,\r
293                 int linesAdded_=0, const char *text_=0, int line_=0) :\r
294                 modificationType(modificationType_),\r
295                 position(position_),\r
296                 length(length_),\r
297                 linesAdded(linesAdded_),\r
298                 text(text_),\r
299                 line(line_),\r
300                 foldLevelNow(0),\r
301                 foldLevelPrev(0) {}\r
302 \r
303         DocModification(int modificationType_, const Action &act, int linesAdded_=0) :\r
304                 modificationType(modificationType_),\r
305                 position(act.position),\r
306                 length(act.lenData),\r
307                 linesAdded(linesAdded_),\r
308                 text(act.data),\r
309                 line(0),\r
310                 foldLevelNow(0),\r
311                 foldLevelPrev(0) {}\r
312 };\r
313 \r
314 /**\r
315  * A class that wants to receive notifications from a Document must be derived from DocWatcher\r
316  * and implement the notification methods. It can then be added to the watcher list with AddWatcher.\r
317  */\r
318 class DocWatcher {\r
319 public:\r
320         virtual ~DocWatcher() {}\r
321 \r
322         virtual void NotifyModifyAttempt(Document *doc, void *userData) = 0;\r
323         virtual void NotifySavePoint(Document *doc, void *userData, bool atSavePoint) = 0;\r
324         virtual void NotifyModified(Document *doc, DocModification mh, void *userData) = 0;\r
325         virtual void NotifyDeleted(Document *doc, void *userData) = 0;\r
326         virtual void NotifyStyleNeeded(Document *doc, void *userData, int endPos) = 0;\r
327 };\r
328 \r
329 #ifdef SCI_NAMESPACE\r
330 }\r
331 #endif\r
332 \r
333 #endif\r