~ubuntu-branches/ubuntu/wily/geany/wily-proposed

« back to all changes in this revision

Viewing changes to scintilla/src/Document.h

  • Committer: Package Import Robot
  • Author(s): Evgeni Golov
  • Date: 2011-11-17 12:59:57 UTC
  • mfrom: (1.1.16)
  • Revision ID: package-import@ubuntu.com-20111117125957-nv48s8qkd2clcmr1
Tags: 0.21-1
* Imported Upstream version 0.21
* Refresh filetypes patch against 0.21
* Fix Description (thanks lintian!)
* Standards-Version: 3.9.2
* dpatch → 3.0 (quilt)
* Switch to new dh-style debian/rules
* Add a patch to search for plugins in both, multiarch and
  non-multiarch folders
* Add misc:Pre-Depends to Pre-Depends for multiarch
* Generate geany:Provides with GEANY_ABI_VERSION and GEANY_API_VERSION
* Split arch independent parts into geany-common
* Set maintainer to pkg-geany
* Set Vcs-* headers for pkg-geany
* Drop README.source, we're using standard 3.0 quilt now

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Scintilla source code edit control
 
2
/** @file Document.h
 
3
 ** Text document that handles notifications, DBCS, styling, words and end of line.
 
4
 **/
 
5
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
 
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
 
 
11
#ifdef SCI_NAMESPACE
 
12
namespace Scintilla {
 
13
#endif
 
14
 
 
15
/**
 
16
 * A Position is a position within a document between two characters or at the beginning or end.
 
17
 * Sometimes used as a character index where it identifies the character after the position.
 
18
 */
 
19
typedef int Position;
 
20
const Position invalidPosition = -1;
 
21
 
 
22
/**
 
23
 * The range class represents a range of text in a document.
 
24
 * The two values are not sorted as one end may be more significant than the other
 
25
 * as is the case for the selection where the end position is the position of the caret.
 
26
 * If either position is invalidPosition then the range is invalid and most operations will fail.
 
27
 */
 
28
class Range {
 
29
public:
 
30
        Position start;
 
31
        Position end;
 
32
 
 
33
        Range(Position pos=0) :
 
34
                start(pos), end(pos) {
 
35
        }
 
36
        Range(Position start_, Position end_) :
 
37
                start(start_), end(end_) {
 
38
        }
 
39
 
 
40
        bool Valid() const {
 
41
                return (start != invalidPosition) && (end != invalidPosition);
 
42
        }
 
43
 
 
44
        // Is the position within the range?
 
45
        bool Contains(Position pos) const {
 
46
                if (start < end) {
 
47
                        return (pos >= start && pos <= end);
 
48
                } else {
 
49
                        return (pos <= start && pos >= end);
 
50
                }
 
51
        }
 
52
 
 
53
        // Is the character after pos within the range?
 
54
        bool ContainsCharacter(Position pos) const {
 
55
                if (start < end) {
 
56
                        return (pos >= start && pos < end);
 
57
                } else {
 
58
                        return (pos < start && pos >= end);
 
59
                }
 
60
        }
 
61
 
 
62
        bool Contains(Range other) const {
 
63
                return Contains(other.start) && Contains(other.end);
 
64
        }
 
65
 
 
66
        bool Overlaps(Range other) const {
 
67
                return
 
68
                Contains(other.start) ||
 
69
                Contains(other.end) ||
 
70
                other.Contains(start) ||
 
71
                other.Contains(end);
 
72
        }
 
73
};
 
74
 
 
75
class DocWatcher;
 
76
class DocModification;
 
77
class Document;
 
78
 
 
79
/**
 
80
 * Interface class for regular expression searching
 
81
 */
 
82
class RegexSearchBase {
 
83
public:
 
84
        virtual ~RegexSearchBase() {}
 
85
 
 
86
        virtual long FindText(Document *doc, int minPos, int maxPos, const char *s,
 
87
                        bool caseSensitive, bool word, bool wordStart, int flags, int *length) = 0;
 
88
 
 
89
        ///@return String with the substitutions, must remain valid until the next call or destruction
 
90
        virtual const char *SubstituteByPosition(Document *doc, const char *text, int *length) = 0;
 
91
};
 
92
 
 
93
/// Factory function for RegexSearchBase
 
94
extern RegexSearchBase *CreateRegexSearch(CharClassify *charClassTable);
 
95
 
 
96
struct StyledText {
 
97
        size_t length;
 
98
        const char *text;
 
99
        bool multipleStyles;
 
100
        size_t style;
 
101
        const unsigned char *styles;
 
102
        StyledText(size_t length_, const char *text_, bool multipleStyles_, int style_, const unsigned char *styles_) :
 
103
                length(length_), text(text_), multipleStyles(multipleStyles_), style(style_), styles(styles_) {
 
104
        }
 
105
        // Return number of bytes from start to before '\n' or end of text.
 
106
        // Return 1 when start is outside text
 
107
        size_t LineLength(size_t start) const {
 
108
                size_t cur = start;
 
109
                while ((cur < length) && (text[cur] != '\n'))
 
110
                        cur++;
 
111
                return cur-start;
 
112
        }
 
113
        size_t StyleAt(size_t i) const {
 
114
                return multipleStyles ? styles[i] : style;
 
115
        }
 
116
};
 
117
 
 
118
class CaseFolder {
 
119
public:
 
120
        virtual ~CaseFolder() {
 
121
        }
 
122
        virtual size_t Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) = 0;
 
123
};
 
124
 
 
125
class CaseFolderTable : public CaseFolder {
 
126
protected:
 
127
        char mapping[256];
 
128
public:
 
129
        CaseFolderTable();
 
130
        virtual ~CaseFolderTable();
 
131
        virtual size_t Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed);
 
132
        void SetTranslation(char ch, char chTranslation);
 
133
        void StandardASCII();
 
134
};
 
135
 
 
136
class Document;
 
137
 
 
138
class LexInterface {
 
139
protected:
 
140
        Document *pdoc;
 
141
        ILexer *instance;
 
142
        bool performingStyle;   ///< Prevent reentrance
 
143
public:
 
144
        LexInterface(Document *pdoc_) : pdoc(pdoc_), instance(0), performingStyle(false) {
 
145
        }
 
146
        virtual ~LexInterface() {
 
147
        }
 
148
        void Colourise(int start, int end);
 
149
        bool UseContainerLexing() const {
 
150
                return instance == 0;
 
151
        }
 
152
};
 
153
 
 
154
/**
 
155
 */
 
156
class Document : PerLine, public IDocument {
 
157
 
 
158
public:
 
159
        /** Used to pair watcher pointer with user data. */
 
160
        class WatcherWithUserData {
 
161
        public:
 
162
                DocWatcher *watcher;
 
163
                void *userData;
 
164
                WatcherWithUserData() {
 
165
                        watcher = 0;
 
166
                        userData = 0;
 
167
                }
 
168
        };
 
169
 
 
170
        enum charClassification { ccSpace, ccNewLine, ccWord, ccPunctuation };
 
171
private:
 
172
        int refCount;
 
173
        CellBuffer cb;
 
174
        CharClassify charClass;
 
175
        char stylingMask;
 
176
        int endStyled;
 
177
        int styleClock;
 
178
        int enteredModification;
 
179
        int enteredStyling;
 
180
        int enteredReadOnlyCount;
 
181
 
 
182
        WatcherWithUserData *watchers;
 
183
        int lenWatchers;
 
184
 
 
185
        // ldSize is not real data - it is for dimensions and loops
 
186
        enum lineData { ldMarkers, ldLevels, ldState, ldMargin, ldAnnotation, ldSize };
 
187
        PerLine *perLineData[ldSize];
 
188
 
 
189
        bool matchesValid;
 
190
        RegexSearchBase *regex;
 
191
 
 
192
public:
 
193
 
 
194
        LexInterface *pli;
 
195
 
 
196
        int stylingBits;
 
197
        int stylingBitsMask;
 
198
 
 
199
        int eolMode;
 
200
        /// Can also be SC_CP_UTF8 to enable UTF-8 mode
 
201
        int dbcsCodePage;
 
202
        int tabInChars;
 
203
        int indentInChars;
 
204
        int actualIndentInChars;
 
205
        bool useTabs;
 
206
        bool tabIndents;
 
207
        bool backspaceUnindents;
 
208
 
 
209
        DecorationList decorations;
 
210
 
 
211
        Document();
 
212
        virtual ~Document();
 
213
 
 
214
        int AddRef();
 
215
        int Release();
 
216
 
 
217
        virtual void Init();
 
218
        virtual void InsertLine(int line);
 
219
        virtual void RemoveLine(int line);
 
220
 
 
221
        int SCI_METHOD Version() const {
 
222
                return dvOriginal;
 
223
        }
 
224
 
 
225
        void SCI_METHOD SetErrorStatus(int status);
 
226
 
 
227
        int SCI_METHOD LineFromPosition(int pos) const;
 
228
        int ClampPositionIntoDocument(int pos);
 
229
        bool IsCrLf(int pos);
 
230
        int LenChar(int pos);
 
231
        bool InGoodUTF8(int pos, int &start, int &end) const;
 
232
        int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);
 
233
        int NextPosition(int pos, int moveDir) const;
 
234
        bool NextCharacter(int &pos, int moveDir);      // Returns true if pos changed
 
235
        int SCI_METHOD CodePage() const;
 
236
        bool SCI_METHOD IsDBCSLeadByte(char ch) const;
 
237
 
 
238
        // Gateways to modifying document
 
239
        void ModifiedAt(int pos);
 
240
        void CheckReadOnly();
 
241
        bool DeleteChars(int pos, int len);
 
242
        bool InsertString(int position, const char *s, int insertLength);
 
243
        int Undo();
 
244
        int Redo();
 
245
        bool CanUndo() { return cb.CanUndo(); }
 
246
        bool CanRedo() { return cb.CanRedo(); }
 
247
        void DeleteUndoHistory() { cb.DeleteUndoHistory(); }
 
248
        bool SetUndoCollection(bool collectUndo) {
 
249
                return cb.SetUndoCollection(collectUndo);
 
250
        }
 
251
        bool IsCollectingUndo() { return cb.IsCollectingUndo(); }
 
252
        void BeginUndoAction() { cb.BeginUndoAction(); }
 
253
        void EndUndoAction() { cb.EndUndoAction(); }
 
254
        void AddUndoAction(int token, bool mayCoalesce) { cb.AddUndoAction(token, mayCoalesce); }
 
255
        void SetSavePoint();
 
256
        bool IsSavePoint() { return cb.IsSavePoint(); }
 
257
        const char * SCI_METHOD BufferPointer() { return cb.BufferPointer(); }
 
258
 
 
259
        int SCI_METHOD GetLineIndentation(int line);
 
260
        void SetLineIndentation(int line, int indent);
 
261
        int GetLineIndentPosition(int line) const;
 
262
        int GetColumn(int position);
 
263
        int FindColumn(int line, int column);
 
264
        void Indent(bool forwards, int lineBottom, int lineTop);
 
265
        static char *TransformLineEnds(int *pLenOut, const char *s, size_t len, int eolMode);
 
266
        void ConvertLineEnds(int eolModeSet);
 
267
        void SetReadOnly(bool set) { cb.SetReadOnly(set); }
 
268
        bool IsReadOnly() { return cb.IsReadOnly(); }
 
269
 
 
270
        bool InsertChar(int pos, char ch);
 
271
        bool InsertCString(int position, const char *s);
 
272
        void ChangeChar(int pos, char ch);
 
273
        void DelChar(int pos);
 
274
        void DelCharBack(int pos);
 
275
 
 
276
        char CharAt(int position) { return cb.CharAt(position); }
 
277
        void SCI_METHOD GetCharRange(char *buffer, int position, int lengthRetrieve) const {
 
278
                cb.GetCharRange(buffer, position, lengthRetrieve);
 
279
        }
 
280
        char SCI_METHOD StyleAt(int position) const { return cb.StyleAt(position); }
 
281
        void GetStyleRange(unsigned char *buffer, int position, int lengthRetrieve) const {
 
282
                cb.GetStyleRange(buffer, position, lengthRetrieve);
 
283
        }
 
284
        int GetMark(int line);
 
285
        int AddMark(int line, int markerNum);
 
286
        void AddMarkSet(int line, int valueSet);
 
287
        void DeleteMark(int line, int markerNum);
 
288
        void DeleteMarkFromHandle(int markerHandle);
 
289
        void DeleteAllMarks(int markerNum);
 
290
        int LineFromHandle(int markerHandle);
 
291
        int SCI_METHOD LineStart(int line) const;
 
292
        int LineEnd(int line) const;
 
293
        int LineEndPosition(int position) const;
 
294
        bool IsLineEndPosition(int position) const;
 
295
        int VCHomePosition(int position) const;
 
296
 
 
297
        int SCI_METHOD SetLevel(int line, int level);
 
298
        int SCI_METHOD GetLevel(int line) const;
 
299
        void ClearLevels();
 
300
        int GetLastChild(int lineParent, int level=-1);
 
301
        int GetFoldParent(int line);
 
302
 
 
303
        void Indent(bool forwards);
 
304
        int ExtendWordSelect(int pos, int delta, bool onlyWordCharacters=false);
 
305
        int NextWordStart(int pos, int delta);
 
306
        int NextWordEnd(int pos, int delta);
 
307
        int SCI_METHOD Length() const { return cb.Length(); }
 
308
        void Allocate(int newSize) { cb.Allocate(newSize); }
 
309
        size_t ExtractChar(int pos, char *bytes);
 
310
        bool MatchesWordOptions(bool word, bool wordStart, int pos, int length);
 
311
        long FindText(int minPos, int maxPos, const char *search, bool caseSensitive, bool word,
 
312
                bool wordStart, bool regExp, int flags, int *length, CaseFolder *pcf);
 
313
        const char *SubstituteByPosition(const char *text, int *length);
 
314
        int LinesTotal() const;
 
315
 
 
316
        void ChangeCase(Range r, bool makeUpperCase);
 
317
 
 
318
        void SetDefaultCharClasses(bool includeWordClass);
 
319
        void SetCharClasses(const unsigned char *chars, CharClassify::cc newCharClass);
 
320
        void SetStylingBits(int bits);
 
321
        void SCI_METHOD StartStyling(int position, char mask);
 
322
        bool SCI_METHOD SetStyleFor(int length, char style);
 
323
        bool SCI_METHOD SetStyles(int length, const char *styles);
 
324
        int GetEndStyled() { return endStyled; }
 
325
        void EnsureStyledTo(int pos);
 
326
        void LexerChanged();
 
327
        int GetStyleClock() { return styleClock; }
 
328
        void IncrementStyleClock();
 
329
        void SCI_METHOD DecorationSetCurrentIndicator(int indicator) {
 
330
                decorations.SetCurrentIndicator(indicator);
 
331
        }
 
332
        void SCI_METHOD DecorationFillRange(int position, int value, int fillLength);
 
333
 
 
334
        int SCI_METHOD SetLineState(int line, int state);
 
335
        int SCI_METHOD GetLineState(int line) const;
 
336
        int GetMaxLineState();
 
337
        void SCI_METHOD ChangeLexerState(int start, int end);
 
338
 
 
339
        StyledText MarginStyledText(int line);
 
340
        void MarginSetStyle(int line, int style);
 
341
        void MarginSetStyles(int line, const unsigned char *styles);
 
342
        void MarginSetText(int line, const char *text);
 
343
        int MarginLength(int line) const;
 
344
        void MarginClearAll();
 
345
 
 
346
        bool AnnotationAny() const;
 
347
        StyledText AnnotationStyledText(int line);
 
348
        void AnnotationSetText(int line, const char *text);
 
349
        void AnnotationSetStyle(int line, int style);
 
350
        void AnnotationSetStyles(int line, const unsigned char *styles);
 
351
        int AnnotationLength(int line) const;
 
352
        int AnnotationLines(int line) const;
 
353
        void AnnotationClearAll();
 
354
 
 
355
        bool AddWatcher(DocWatcher *watcher, void *userData);
 
356
        bool RemoveWatcher(DocWatcher *watcher, void *userData);
 
357
        const WatcherWithUserData *GetWatchers() const { return watchers; }
 
358
        int GetLenWatchers() const { return lenWatchers; }
 
359
 
 
360
        CharClassify::cc WordCharClass(unsigned char ch);
 
361
        bool IsWordPartSeparator(char ch);
 
362
        int WordPartLeft(int pos);
 
363
        int WordPartRight(int pos);
 
364
        int ExtendStyleRange(int pos, int delta, bool singleLine = false);
 
365
        bool IsWhiteLine(int line) const;
 
366
        int ParaUp(int pos);
 
367
        int ParaDown(int pos);
 
368
        int IndentSize() { return actualIndentInChars; }
 
369
        int BraceMatch(int position, int maxReStyle);
 
370
 
 
371
private:
 
372
        bool IsWordStartAt(int pos);
 
373
        bool IsWordEndAt(int pos);
 
374
        bool IsWordAt(int start, int end);
 
375
 
 
376
        void NotifyModifyAttempt();
 
377
        void NotifySavePoint(bool atSavePoint);
 
378
        void NotifyModified(DocModification mh);
 
379
};
 
380
 
 
381
class UndoGroup {
 
382
        Document *pdoc;
 
383
        bool groupNeeded;
 
384
public:
 
385
        UndoGroup(Document *pdoc_, bool groupNeeded_=true) :
 
386
                pdoc(pdoc_), groupNeeded(groupNeeded_) {
 
387
                if (groupNeeded) {
 
388
                        pdoc->BeginUndoAction();
 
389
                }
 
390
        }
 
391
        ~UndoGroup() {
 
392
                if (groupNeeded) {
 
393
                        pdoc->EndUndoAction();
 
394
                }
 
395
        }
 
396
        bool Needed() const {
 
397
                return groupNeeded;
 
398
        }
 
399
};
 
400
 
 
401
 
 
402
/**
 
403
 * To optimise processing of document modifications by DocWatchers, a hint is passed indicating the
 
404
 * scope of the change.
 
405
 * If the DocWatcher is a document view then this can be used to optimise screen updating.
 
406
 */
 
407
class DocModification {
 
408
public:
 
409
        int modificationType;
 
410
        int position;
 
411
        int length;
 
412
        int linesAdded; /**< Negative if lines deleted. */
 
413
        const char *text;       /**< Only valid for changes to text, not for changes to style. */
 
414
        int line;
 
415
        int foldLevelNow;
 
416
        int foldLevelPrev;
 
417
        int annotationLinesAdded;
 
418
        int token;
 
419
 
 
420
        DocModification(int modificationType_, int position_=0, int length_=0,
 
421
                int linesAdded_=0, const char *text_=0, int line_=0) :
 
422
                modificationType(modificationType_),
 
423
                position(position_),
 
424
                length(length_),
 
425
                linesAdded(linesAdded_),
 
426
                text(text_),
 
427
                line(line_),
 
428
                foldLevelNow(0),
 
429
                foldLevelPrev(0),
 
430
                annotationLinesAdded(0),
 
431
                token(0) {}
 
432
 
 
433
        DocModification(int modificationType_, const Action &act, int linesAdded_=0) :
 
434
                modificationType(modificationType_),
 
435
                position(act.position),
 
436
                length(act.lenData),
 
437
                linesAdded(linesAdded_),
 
438
                text(act.data),
 
439
                line(0),
 
440
                foldLevelNow(0),
 
441
                foldLevelPrev(0),
 
442
                annotationLinesAdded(0),
 
443
                token(0) {}
 
444
};
 
445
 
 
446
/**
 
447
 * A class that wants to receive notifications from a Document must be derived from DocWatcher
 
448
 * and implement the notification methods. It can then be added to the watcher list with AddWatcher.
 
449
 */
 
450
class DocWatcher {
 
451
public:
 
452
        virtual ~DocWatcher() {}
 
453
 
 
454
        virtual void NotifyModifyAttempt(Document *doc, void *userData) = 0;
 
455
        virtual void NotifySavePoint(Document *doc, void *userData, bool atSavePoint) = 0;
 
456
        virtual void NotifyModified(Document *doc, DocModification mh, void *userData) = 0;
 
457
        virtual void NotifyDeleted(Document *doc, void *userData) = 0;
 
458
        virtual void NotifyStyleNeeded(Document *doc, void *userData, int endPos) = 0;
 
459
        virtual void NotifyLexerChanged(Document *doc, void *userData) = 0;
 
460
        virtual void NotifyErrorOccurred(Document *doc, void *userData, int status) = 0;
 
461
};
 
462
 
 
463
#ifdef SCI_NAMESPACE
 
464
}
 
465
#endif
 
466
 
 
467
#endif