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