]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/Document.h
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.
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.
12 const Position invalidPosition
= -1;
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.
23 Range(Position pos
=0) :
24 start(pos
), end(pos
) {
26 Range(Position start_
, Position end_
) :
27 start(start_
), end(end_
) {
31 return (start
!= invalidPosition
) && (end
!= invalidPosition
);
34 bool Contains(Position pos
) const {
36 return (pos
>= start
&& pos
<= end
);
38 return (pos
<= start
&& pos
>= end
);
42 bool Contains(Range other
) const {
43 return Contains(other
.start
) && Contains(other
.end
);
46 bool Overlaps(Range other
) const {
48 Contains(other
.start
) ||
49 Contains(other
.end
) ||
50 other
.Contains(start
) ||
56 class DocModification
;
61 // Used to pair watcher pointer with user data
62 class WatcherWithUserData
{
66 WatcherWithUserData() {
80 int enteredReadOnlyCount
;
82 WatcherWithUserData
*watchers
;
90 // dbcsCodePage can also be SC_CP_UTF8 to enable UTF-8 mode
102 int LineFromPosition(int pos
);
103 int ClampPositionIntoDocument(int pos
);
104 bool IsCrLf(int pos
);
105 int LenChar(int pos
);
106 int MovePositionOutsideChar(int pos
, int moveDir
, bool checkLineEnd
=true);
108 // Gateways to modifying document
109 void DeleteChars(int pos
, int len
);
110 void InsertStyledString(int position
, char *s
, int insertLength
);
113 bool CanUndo() { return cb
.CanUndo(); }
114 bool CanRedo() { return cb
.CanRedo(); }
115 void DeleteUndoHistory() { cb
.DeleteUndoHistory(); }
116 bool SetUndoCollection(bool collectUndo
) {
117 return cb
.SetUndoCollection(collectUndo
);
119 bool IsCollectingUndo() { return cb
.IsCollectingUndo(); }
120 void BeginUndoAction() { cb
.BeginUndoAction(); }
121 void EndUndoAction() { cb
.EndUndoAction(); }
123 bool IsSavePoint() { return cb
.IsSavePoint(); }
125 int GetLineIndentation(int line
);
126 void SetLineIndentation(int line
, int indent
);
127 int GetLineIndentPosition(int line
);
128 int GetColumn(int position
);
129 void Indent(bool forwards
, int lineBottom
, int lineTop
);
130 void ConvertLineEnds(int eolModeSet
);
131 void SetReadOnly(bool set
) { cb
.SetReadOnly(set
); }
132 bool IsReadOnly() { return cb
.IsReadOnly(); }
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
);
137 void ChangeChar(int pos
, char ch
);
138 void DelChar(int pos
);
139 int DelCharBack(int pos
);
141 char CharAt(int position
) { return cb
.CharAt(position
); }
142 void GetCharRange(char *buffer
, int position
, int lengthRetrieve
) {
143 cb
.GetCharRange(buffer
, position
, lengthRetrieve
);
145 char StyleAt(int position
) { return cb
.StyleAt(position
); }
146 int GetMark(int line
) { return cb
.GetMark(line
); }
147 int AddMark(int line
, int markerNum
);
148 void DeleteMark(int line
, int markerNum
);
149 void DeleteMarkFromHandle(int markerHandle
);
150 void DeleteAllMarks(int markerNum
);
151 int LineFromHandle(int markerHandle
) { return cb
.LineFromHandle(markerHandle
); }
152 int LineStart(int line
);
153 int LineEnd(int line
);
154 int LineEndPosition(int position
);
155 int VCHomePosition(int position
);
157 int SetLevel(int line
, int level
);
158 int GetLevel(int line
) { return cb
.GetLevel(line
); }
159 void ClearLevels() { cb
.ClearLevels(); }
160 int GetLastChild(int lineParent
, int level
=-1);
161 int GetFoldParent(int line
);
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(); }
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
);
172 void ChangeCase(Range r
, bool makeUpperCase
);
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
; }
180 bool EnsureStyledTo(int pos
);
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(); }
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
; }
192 bool IsDBCS(int pos
);
193 bool IsWordChar(unsigned char ch
);
194 bool IsWordStartAt(int pos
);
195 bool IsWordEndAt(int pos
);
196 bool IsWordAt(int start
, int end
);
197 void ModifiedAt(int pos
);
199 void NotifyModifyAttempt();
200 void NotifySavePoint(bool atSavePoint
);
201 void NotifyModified(DocModification mh
);
203 int IndentSize() { return indentInChars
? indentInChars
: tabInChars
; }
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.
209 class DocModification
{
211 int modificationType
;
214 int linesAdded
; // Negative if lines deleted
215 const char *text
; // Only valid for changes to text, not for changes to style
220 DocModification(int modificationType_
, int position_
=0, int length_
=0,
221 int linesAdded_
=0, const char *text_
=0) :
222 modificationType(modificationType_
),
225 linesAdded(linesAdded_
),
231 DocModification(int modificationType_
, const Action
&act
, int linesAdded_
=0) :
232 modificationType(modificationType_
),
233 position(act
.position
/ 2),
235 linesAdded(linesAdded_
),
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.
246 virtual ~DocWatcher() {}
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;
252 virtual void NotifyStyleNeeded(Document
*doc
, void *userData
, int endPos
) = 0;