]>
Commit | Line | Data |
---|---|---|
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 | class Accessor { | |
7 | protected: | |
8 | // bufferSize is a trade off between time taken to copy the characters and SendMessage overhead | |
9 | // slopSize positions the buffer before the desired position in case there is some backtracking | |
10 | enum {bufferSize=4000, slopSize=bufferSize/8}; | |
11 | char buf[bufferSize+1]; | |
12 | WindowID id; | |
13 | PropSet &props; | |
14 | int startPos; | |
15 | int endPos; | |
16 | int lenDoc; | |
17 | int offset; // Optional but including an offset makes GCC generate better code | |
18 | void Fill(int position); | |
19 | public: | |
20 | Accessor(WindowID id_, PropSet &props_, int offset_=0) : | |
21 | id(id_), props(props_), startPos(0x7FFFFFFF), endPos(0), | |
22 | lenDoc(-1), offset(offset_) { | |
23 | } | |
24 | char operator[](int position) { | |
25 | position += offset; | |
26 | if (position < startPos || position >= endPos) { | |
27 | Fill(position); | |
28 | } | |
29 | return buf[position - startPos]; | |
30 | } | |
31 | char SafeGetCharAt(int position, char chDefault=' ') { | |
32 | // Safe version of operator[], returning a defined value for invalid position | |
33 | position += offset; | |
34 | if (position < startPos || position >= endPos) { | |
35 | Fill(position); | |
36 | if (position < startPos || position >= endPos) { | |
37 | // Position is outside range of document | |
38 | return chDefault; | |
39 | } | |
40 | } | |
41 | return buf[position - startPos]; | |
42 | } | |
43 | char StyleAt(int position); | |
44 | int GetLine(int position); | |
45 | int LineStart(int line); | |
46 | int LevelAt(int line); | |
47 | int Length(); | |
48 | void Flush() { | |
49 | startPos = 0x7FFFFFFF; | |
50 | lenDoc = -1; | |
51 | } | |
52 | int GetLineState(int line); | |
53 | int SetLineState(int line, int state); | |
54 | PropSet &GetPropSet() { return props; } | |
55 | }; | |
56 | ||
57 | class StylingContext : public Accessor { | |
58 | char styleBuf[bufferSize]; | |
59 | int validLen; | |
60 | char chFlags; | |
61 | char chWhile; | |
62 | unsigned int startSeg; | |
63 | public: | |
64 | StylingContext(WindowID id_, PropSet &props_, int offset_=0) : | |
65 | Accessor(id_,props_,offset_), validLen(0), chFlags(0) {} | |
66 | void StartAt(unsigned int start, char chMask=31); | |
67 | void SetFlags(char chFlags_, char chWhile_) {chFlags = chFlags_; chWhile = chWhile_; }; | |
68 | void ColourSegment(unsigned int start, unsigned int end, int chAttr); | |
69 | unsigned int GetStartSegment() { return startSeg; } | |
70 | void StartSegment(unsigned int pos); | |
71 | void ColourTo(unsigned int pos, int chAttr); | |
72 | int GetLine(int position); | |
73 | void SetLevel(int line, int level); | |
74 | void Flush(); | |
75 | }; | |
76 |