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