]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/WindowAccessor.cxx
added translation of mac system into language, adaption of search paths
[wxWidgets.git] / src / stc / scintilla / src / WindowAccessor.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 <string.h>
8 #include <ctype.h>
9 #include <stdio.h>
10
11 #include "Platform.h"
12
13 #include "PropSet.h"
14 #include "Accessor.h"
15 #include "WindowAccessor.h"
16 #include "Scintilla.h"
17
18 WindowAccessor::~WindowAccessor() {
19 }
20
21 #if PLAT_WIN
22 bool WindowAccessor::InternalIsLeadByte(char ch) {
23 if (SC_CP_UTF8 == codePage)
24 // For lexing, all characters >= 0x80 are treated the
25 // same so none is considered a lead byte.
26 return false;
27 else
28 return IsDBCSLeadByteEx(codePage, ch);
29 }
30 #else
31 // PLAT_GTK or PLAT_WX
32 // TODO: support DBCS under GTK+ and WX
33 bool WindowAccessor::InternalIsLeadByte(char) {
34 return false;
35 }
36 #endif
37
38 void WindowAccessor::Fill(int position) {
39 if (lenDoc == -1)
40 lenDoc = Platform::SendScintilla(id, SCI_GETTEXTLENGTH, 0, 0);
41 startPos = position - slopSize;
42 if (startPos + bufferSize > lenDoc)
43 startPos = lenDoc - bufferSize;
44 if (startPos < 0)
45 startPos = 0;
46 endPos = startPos + bufferSize;
47 if (endPos > lenDoc)
48 endPos = lenDoc;
49
50 TextRange tr = {{startPos, endPos}, buf};
51 Platform::SendScintilla(id, SCI_GETTEXTRANGE, 0, reinterpret_cast<long>(&tr));
52 }
53
54 char WindowAccessor::StyleAt(int position) {
55 return static_cast<char>(Platform::SendScintilla(
56 id, SCI_GETSTYLEAT, position, 0));
57 }
58
59 int WindowAccessor::GetLine(int position) {
60 return Platform::SendScintilla(id, SCI_LINEFROMPOSITION, position, 0);
61 }
62
63 int WindowAccessor::LineStart(int line) {
64 return Platform::SendScintilla(id, SCI_POSITIONFROMLINE, line, 0);
65 }
66
67 int WindowAccessor::LevelAt(int line) {
68 return Platform::SendScintilla(id, SCI_GETFOLDLEVEL, line, 0);
69 }
70
71 int WindowAccessor::Length() {
72 if (lenDoc == -1)
73 lenDoc = Platform::SendScintilla(id, SCI_GETTEXTLENGTH, 0, 0);
74 return lenDoc;
75 }
76
77 int WindowAccessor::GetLineState(int line) {
78 return Platform::SendScintilla(id, SCI_GETLINESTATE, line);
79 }
80
81 int WindowAccessor::SetLineState(int line, int state) {
82 return Platform::SendScintilla(id, SCI_SETLINESTATE, line, state);
83 }
84
85 void WindowAccessor::StartAt(unsigned int start, char chMask) {
86 Platform::SendScintilla(id, SCI_STARTSTYLING, start, chMask);
87 }
88
89 void WindowAccessor::StartSegment(unsigned int pos) {
90 startSeg = pos;
91 }
92
93 void WindowAccessor::ColourTo(unsigned int pos, int chAttr) {
94 // Only perform styling if non empty range
95 if (pos != startSeg - 1) {
96 if (pos < startSeg) {
97 Platform::DebugPrintf("Bad colour positions %d - %d\n", startSeg, pos);
98 }
99
100 if (validLen + (pos - startSeg + 1) >= bufferSize)
101 Flush();
102 if (validLen + (pos - startSeg + 1) >= bufferSize) {
103 // Too big for buffer so send directly
104 Platform::SendScintilla(id, SCI_SETSTYLING, pos - startSeg + 1, chAttr);
105 } else {
106 if (chAttr != chWhile)
107 chFlags = 0;
108 chAttr |= chFlags;
109 for (unsigned int i = startSeg; i <= pos; i++) {
110 styleBuf[validLen++] = static_cast<char>(chAttr);
111 }
112 }
113 }
114 startSeg = pos+1;
115 }
116
117 void WindowAccessor::SetLevel(int line, int level) {
118 Platform::SendScintilla(id, SCI_SETFOLDLEVEL, line, level);
119 }
120
121 void WindowAccessor::Flush() {
122 startPos = extremePosition;
123 lenDoc = -1;
124 if (validLen > 0) {
125 Platform::SendScintilla(id, SCI_SETSTYLINGEX, validLen,
126 reinterpret_cast<long>(styleBuf));
127 validLen = 0;
128 }
129 }
130
131 int WindowAccessor::IndentAmount(int line, int *flags, PFNIsCommentLeader pfnIsCommentLeader) {
132 int end = Length();
133 int spaceFlags = 0;
134
135 // Determines the indentation level of the current line and also checks for consistent
136 // indentation compared to the previous line.
137 // Indentation is judged consistent when the indentation whitespace of each line lines
138 // the same or the indentation of one line is a prefix of the other.
139
140 int pos = LineStart(line);
141 char ch = (*this)[pos];
142 int indent = 0;
143 bool inPrevPrefix = line > 0;
144 int posPrev = inPrevPrefix ? LineStart(line-1) : 0;
145 while ((ch == ' ' || ch == '\t') && (pos < end)) {
146 if (inPrevPrefix) {
147 char chPrev = (*this)[posPrev++];
148 if (chPrev == ' ' || chPrev == '\t') {
149 if (chPrev != ch)
150 spaceFlags |= wsInconsistent;
151 } else {
152 inPrevPrefix = false;
153 }
154 }
155 if (ch == ' ') {
156 spaceFlags |= wsSpace;
157 indent++;
158 } else { // Tab
159 spaceFlags |= wsTab;
160 if (spaceFlags & wsSpace)
161 spaceFlags |= wsSpaceTab;
162 indent = (indent / 8 + 1) * 8;
163 }
164 ch = (*this)[++pos];
165 }
166
167 *flags = spaceFlags;
168 indent += SC_FOLDLEVELBASE;
169 // if completely empty line or the start of a comment...
170 if (isspace(ch) || (pfnIsCommentLeader && (*pfnIsCommentLeader)(*this, pos, end-pos)) )
171 return indent | SC_FOLDLEVELWHITEFLAG;
172 else
173 return indent;
174 }
175