]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/Document.h
394c8f94b0cb7b2af48a50cdb8f15cecc291f958
1 // Scintilla source code edit control
3 ** Text document that handles notifications, DBCS, styling, words and end of line.
5 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
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.
16 const Position invalidPosition
= -1;
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.
29 Range(Position pos
=0) :
30 start(pos
), end(pos
) {
32 Range(Position start_
, Position end_
) :
33 start(start_
), end(end_
) {
37 return (start
!= invalidPosition
) && (end
!= invalidPosition
);
40 bool Contains(Position pos
) const {
42 return (pos
>= start
&& pos
<= end
);
44 return (pos
<= start
&& pos
>= end
);
48 bool Contains(Range other
) const {
49 return Contains(other
.start
) && Contains(other
.end
);
52 bool Overlaps(Range other
) const {
54 Contains(other
.start
) ||
55 Contains(other
.end
) ||
56 other
.Contains(start
) ||
62 class DocModification
;
70 /** Used to pair watcher pointer with user data. */
71 class WatcherWithUserData
{
75 WatcherWithUserData() {
88 int enteredReadOnlyCount
;
90 WatcherWithUserData
*watchers
;
102 /// Can also be SC_CP_UTF8 to enable UTF-8 mode
108 bool backspaceUnindents
;
116 int LineFromPosition(int pos
);
117 int ClampPositionIntoDocument(int pos
);
118 bool IsCrLf(int pos
);
119 int LenChar(int pos
);
120 int MovePositionOutsideChar(int pos
, int moveDir
, bool checkLineEnd
=true);
122 // Gateways to modifying document
123 void DeleteChars(int pos
, int len
);
124 void InsertStyledString(int position
, char *s
, int insertLength
);
127 bool CanUndo() { return cb
.CanUndo(); }
128 bool CanRedo() { return cb
.CanRedo(); }
129 void DeleteUndoHistory() { cb
.DeleteUndoHistory(); }
130 bool SetUndoCollection(bool collectUndo
) {
131 return cb
.SetUndoCollection(collectUndo
);
133 bool IsCollectingUndo() { return cb
.IsCollectingUndo(); }
134 void BeginUndoAction() { cb
.BeginUndoAction(); }
135 void EndUndoAction() { cb
.EndUndoAction(); }
137 bool IsSavePoint() { return cb
.IsSavePoint(); }
139 int GetLineIndentation(int line
);
140 void SetLineIndentation(int line
, int indent
);
141 int GetLineIndentPosition(int line
);
142 int GetColumn(int position
);
143 void Indent(bool forwards
, int lineBottom
, int lineTop
);
144 void ConvertLineEnds(int eolModeSet
);
145 void SetReadOnly(bool set
) { cb
.SetReadOnly(set
); }
146 bool IsReadOnly() { return cb
.IsReadOnly(); }
148 void InsertChar(int pos
, char ch
);
149 void InsertString(int position
, const char *s
);
150 void InsertString(int position
, const char *s
, int insertLength
);
151 void ChangeChar(int pos
, char ch
);
152 void DelChar(int pos
);
153 int DelCharBack(int pos
);
155 char CharAt(int position
) { return cb
.CharAt(position
); }
156 void GetCharRange(char *buffer
, int position
, int lengthRetrieve
) {
157 cb
.GetCharRange(buffer
, position
, lengthRetrieve
);
159 char StyleAt(int position
) { return cb
.StyleAt(position
); }
160 int GetMark(int line
) { return cb
.GetMark(line
); }
161 int AddMark(int line
, int markerNum
);
162 void DeleteMark(int line
, int markerNum
);
163 void DeleteMarkFromHandle(int markerHandle
);
164 void DeleteAllMarks(int markerNum
);
165 int LineFromHandle(int markerHandle
) { return cb
.LineFromHandle(markerHandle
); }
166 int LineStart(int line
);
167 int LineEnd(int line
);
168 int LineEndPosition(int position
);
169 int VCHomePosition(int position
);
171 int SetLevel(int line
, int level
);
172 int GetLevel(int line
) { return cb
.GetLevel(line
); }
173 void ClearLevels() { cb
.ClearLevels(); }
174 int GetLastChild(int lineParent
, int level
=-1);
175 int GetFoldParent(int line
);
177 void Indent(bool forwards
);
178 int ExtendWordSelect(int pos
, int delta
);
179 int NextWordStart(int pos
, int delta
);
180 int Length() { return cb
.Length(); }
181 long FindText(int minPos
, int maxPos
, const char *s
,
182 bool caseSensitive
, bool word
, bool wordStart
, bool regExp
, int *length
);
183 long FindText(int iMessage
, unsigned long wParam
, long lParam
);
184 const char *SubstituteByPosition(const char *text
, int *length
);
187 void ChangeCase(Range r
, bool makeUpperCase
);
189 void SetWordChars(unsigned char *chars
);
190 void SetStylingBits(int bits
);
191 void StartStyling(int position
, char mask
);
192 void SetStyleFor(int length
, char style
);
193 void SetStyles(int length
, char *styles
);
194 int GetEndStyled() { return endStyled
; }
195 bool EnsureStyledTo(int pos
);
197 int SetLineState(int line
, int state
) { return cb
.SetLineState(line
, state
); }
198 int GetLineState(int line
) { return cb
.GetLineState(line
); }
199 int GetMaxLineState() { return cb
.GetMaxLineState(); }
201 bool AddWatcher(DocWatcher
*watcher
, void *userData
);
202 bool RemoveWatcher(DocWatcher
*watcher
, void *userData
);
203 const WatcherWithUserData
*GetWatchers() const { return watchers
; }
204 int GetLenWatchers() const { return lenWatchers
; }
206 bool IsWordPartSeparator(char ch
);
207 int WordPartLeft(int pos
);
208 int WordPartRight(int pos
);
211 bool IsDBCS(int pos
);
212 bool IsWordChar(unsigned char ch
);
213 bool IsWordStartAt(int pos
);
214 bool IsWordEndAt(int pos
);
215 bool IsWordAt(int start
, int end
);
216 void ModifiedAt(int pos
);
218 void NotifyModifyAttempt();
219 void NotifySavePoint(bool atSavePoint
);
220 void NotifyModified(DocModification mh
);
222 int IndentSize() { return indentInChars
? indentInChars
: tabInChars
; }
226 * To optimise processing of document modifications by DocWatchers, a hint is passed indicating the
227 * scope of the change.
228 * If the DocWatcher is a document view then this can be used to optimise screen updating.
230 class DocModification
{
232 int modificationType
;
235 int linesAdded
; /**< Negative if lines deleted. */
236 const char *text
; /**< Only valid for changes to text, not for changes to style. */
241 DocModification(int modificationType_
, int position_
=0, int length_
=0,
242 int linesAdded_
=0, const char *text_
=0) :
243 modificationType(modificationType_
),
246 linesAdded(linesAdded_
),
252 DocModification(int modificationType_
, const Action
&act
, int linesAdded_
=0) :
253 modificationType(modificationType_
),
254 position(act
.position
/ 2),
256 linesAdded(linesAdded_
),
264 * A class that wants to receive notifications from a Document must be derived from DocWatcher
265 * and implement the notification methods. It can then be added to the watcher list with AddWatcher.
269 virtual ~DocWatcher() {}
271 virtual void NotifyModifyAttempt(Document
*doc
, void *userData
) = 0;
272 virtual void NotifySavePoint(Document
*doc
, void *userData
, bool atSavePoint
) = 0;
273 virtual void NotifyModified(Document
*doc
, DocModification mh
, void *userData
) = 0;
274 virtual void NotifyDeleted(Document
*doc
, void *userData
) = 0;
275 virtual void NotifyStyleNeeded(Document
*doc
, void *userData
, int endPos
) = 0;