]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/Accessor.cxx
57b7e4dc4e3eecd35b8d3e45d0dfb022c12a6800
[wxWidgets.git] / src / stc / scintilla / src / Accessor.cxx
1 // SciTE - Scintilla based Text Editor
2 // Accessor.cxx - 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 #include <stdlib.h>
7 #include <stdio.h>
8
9 #include "Platform.h"
10
11 #include "PropSet.h"
12 #include "Accessor.h"
13 #include "Scintilla.h"
14
15 void Accessor::Fill(int position) {
16 if (lenDoc == -1)
17 lenDoc = Platform::SendScintilla(id, WM_GETTEXTLENGTH, 0, 0);
18 startPos = position - slopSize;
19 if (startPos + bufferSize > lenDoc)
20 startPos = lenDoc - bufferSize;
21 if (startPos < 0)
22 startPos = 0;
23 endPos = startPos + bufferSize;
24 if (endPos > lenDoc)
25 endPos = lenDoc;
26
27 TEXTRANGE tr = {{startPos, endPos}, buf};
28 Platform::SendScintilla(id, EM_GETTEXTRANGE, 0, reinterpret_cast<LPARAM>(&tr));
29 }
30
31 char Accessor::StyleAt(int position) {
32 return static_cast<char>(Platform::SendScintilla(
33 id, SCI_GETSTYLEAT, position, 0));
34 }
35
36 int Accessor::GetLine(int position) {
37 return Platform::SendScintilla(id, EM_LINEFROMCHAR, position, 0);
38 }
39
40 int Accessor::LineStart(int line) {
41 return Platform::SendScintilla(id, EM_LINEINDEX, line, 0);
42 }
43
44 int Accessor::LevelAt(int line) {
45 return Platform::SendScintilla(id, SCI_GETFOLDLEVEL, line, 0);
46 }
47
48 int Accessor::Length() {
49 if (lenDoc == -1)
50 lenDoc = Platform::SendScintilla(id, WM_GETTEXTLENGTH, 0, 0);
51 return lenDoc;
52 }
53
54 int Accessor::GetLineState(int line) {
55 return Platform::SendScintilla(id, SCI_GETLINESTATE, line);
56 }
57
58 int Accessor::SetLineState(int line, int state) {
59 return Platform::SendScintilla(id, SCI_SETLINESTATE, line, state);
60 }
61
62 void StylingContext::StartAt(unsigned int start, char chMask) {
63 Platform::SendScintilla(id, SCI_STARTSTYLING, start, chMask);
64 }
65
66 void StylingContext::ColourSegment(unsigned int start, unsigned int end, int chAttr) {
67 // Only perform styling if non empty range
68 if (end != start - 1) {
69 if (end < start) {
70 Platform::DebugPrintf("Bad colour positions %d - %d\n", start, end);
71 }
72
73 if (validLen + (end - start + 1) >= bufferSize)
74 Flush();
75 if (validLen + (end - start + 1) >= bufferSize) {
76 // Too big for buffer so send directly
77 Platform::SendScintilla(id, SCI_SETSTYLING, end - start + 1, chAttr);
78 } else {
79 if (chAttr != chWhile)
80 chFlags = 0;
81 chAttr |= chFlags;
82 for (unsigned int i = start; i <= end; i++) {
83 styleBuf[validLen++] = chAttr;
84 }
85 }
86 }
87 }
88
89 void StylingContext::StartSegment(unsigned int pos) {
90 startSeg = pos;
91 }
92
93 void StylingContext::ColourTo(unsigned int pos, int chAttr) {
94 ColourSegment(startSeg, pos, chAttr);
95 startSeg = pos+1;
96 }
97
98 int StylingContext::GetLine(int position) {
99 return Platform::SendScintilla(id, EM_LINEFROMCHAR, position, 0);
100 }
101
102 void StylingContext::SetLevel(int line, int level) {
103 Platform::SendScintilla(id, SCI_SETFOLDLEVEL, line, level);
104 }
105
106 void StylingContext::Flush() {
107 if (validLen > 0) {
108 Platform::SendScintilla(id, SCI_SETSTYLINGEX, validLen,
109 reinterpret_cast<LPARAM>(styleBuf));
110 validLen = 0;
111 }
112 }