]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/include/Accessor.h
This commit includes the following changes:
[wxWidgets.git] / src / stc / scintilla / include / Accessor.h
1 // SciTE - Scintilla based Text Editor
2 // Accessor.h - rapid easy access to contents of a Scintilla
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 enum { wsSpace = 1, wsTab = 2, wsSpaceTab = 4, wsInconsistent=8};
7
8 class Accessor {
9 protected:
10 // bufferSize is a trade off between time taken to copy the characters and SendMessage overhead
11 // slopSize positions the buffer before the desired position in case there is some backtracking
12 enum {bufferSize=4000, slopSize=bufferSize/8};
13 char buf[bufferSize+1];
14 WindowID id;
15 PropSet &props;
16 int startPos;
17 int endPos;
18 int lenDoc;
19 int offset; // Optional but including an offset makes GCC generate better code
20 int codePage;
21 bool InternalIsLeadByte(char ch);
22 void Fill(int position);
23 public:
24 Accessor(WindowID id_, PropSet &props_, int offset_=0) :
25 id(id_), props(props_), startPos(0x7FFFFFFF), endPos(0),
26 lenDoc(-1), offset(offset_), codePage(0) {
27 }
28 void SetCodePage(int codePage_) { codePage = codePage_; }
29 char operator[](int position) {
30 position += offset;
31 if (position < startPos || position >= endPos) {
32 Fill(position);
33 }
34 return buf[position - startPos];
35 }
36 char SafeGetCharAt(int position, char chDefault=' ') {
37 // Safe version of operator[], returning a defined value for invalid position
38 position += offset;
39 if (position < startPos || position >= endPos) {
40 Fill(position);
41 if (position < startPos || position >= endPos) {
42 // Position is outside range of document
43 return chDefault;
44 }
45 }
46 return buf[position - startPos];
47 }
48 bool IsLeadByte(char ch) {
49 return codePage && InternalIsLeadByte(ch);
50 }
51 char StyleAt(int position);
52 int GetLine(int position);
53 int LineStart(int line);
54 int LevelAt(int line);
55 int Length();
56 void Flush() {
57 startPos = 0x7FFFFFFF;
58 lenDoc = -1;
59 }
60 int GetLineState(int line);
61 int SetLineState(int line, int state);
62 PropSet &GetPropSet() { return props; }
63 };
64
65 class StylingContext;
66
67 typedef bool (*PFNIsCommentLeader)(StylingContext &styler, int pos, int len);
68
69 class StylingContext : public Accessor {
70 char styleBuf[bufferSize];
71 int validLen;
72 char chFlags;
73 char chWhile;
74 unsigned int startSeg;
75 public:
76 StylingContext(WindowID id_, PropSet &props_, int offset_=0) :
77 Accessor(id_,props_,offset_), validLen(0), chFlags(0) {}
78 void StartAt(unsigned int start, char chMask=31);
79 void SetFlags(char chFlags_, char chWhile_) {chFlags = chFlags_; chWhile = chWhile_; };
80 unsigned int GetStartSegment() { return startSeg; }
81 void StartSegment(unsigned int pos);
82 void ColourTo(unsigned int pos, int chAttr);
83 int GetLine(int position);
84 void SetLevel(int line, int level);
85 void Flush();
86 int IndentAmount(int line, int *flags, PFNIsCommentLeader pfnIsCommentLeader = 0);
87 };
88