1
// Scintilla source code edit control
2
/** @file WindowAccessor.cxx
3
** Rapid easy access to contents of a Scintilla.
5
// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
6
// The License.txt file describes the conditions under which this software may be distributed.
17
#include "WindowAccessor.h"
18
#include "Scintilla.h"
20
WindowAccessor::~WindowAccessor() {
23
bool WindowAccessor::InternalIsLeadByte(char ch) {
24
if (SC_CP_UTF8 == codePage)
25
// For lexing, all characters >= 0x80 are treated the
26
// same so none is considered a lead byte.
29
return Platform::IsDBCSLeadByte(codePage, ch);
32
void WindowAccessor::Fill(int position) {
34
lenDoc = Platform::SendScintilla(id, SCI_GETTEXTLENGTH, 0, 0);
35
startPos = position - slopSize;
36
if (startPos + bufferSize > lenDoc)
37
startPos = lenDoc - bufferSize;
40
endPos = startPos + bufferSize;
44
TextRange tr = {{startPos, endPos}, buf};
45
Platform::SendScintillaPointer(id, SCI_GETTEXTRANGE, 0, &tr);
48
bool WindowAccessor::Match(int pos, const char *s) {
49
for (int i=0; *s; i++) {
50
if (*s != SafeGetCharAt(pos+i))
57
char WindowAccessor::StyleAt(int position) {
58
return static_cast<char>(Platform::SendScintilla(
59
id, SCI_GETSTYLEAT, position, 0));
62
int WindowAccessor::GetLine(int position) {
63
return Platform::SendScintilla(id, SCI_LINEFROMPOSITION, position, 0);
66
int WindowAccessor::LineStart(int line) {
67
return Platform::SendScintilla(id, SCI_POSITIONFROMLINE, line, 0);
70
int WindowAccessor::LevelAt(int line) {
71
return Platform::SendScintilla(id, SCI_GETFOLDLEVEL, line, 0);
74
int WindowAccessor::Length() {
76
lenDoc = Platform::SendScintilla(id, SCI_GETTEXTLENGTH, 0, 0);
80
int WindowAccessor::GetLineState(int line) {
81
return Platform::SendScintilla(id, SCI_GETLINESTATE, line);
84
int WindowAccessor::SetLineState(int line, int state) {
85
return Platform::SendScintilla(id, SCI_SETLINESTATE, line, state);
88
void WindowAccessor::StartAt(unsigned int start, char chMask) {
89
Platform::SendScintilla(id, SCI_STARTSTYLING, start, chMask);
92
void WindowAccessor::StartSegment(unsigned int pos) {
96
void WindowAccessor::ColourTo(unsigned int pos, int chAttr) {
97
// Only perform styling if non empty range
98
if (pos != startSeg - 1) {
100
Platform::DebugPrintf("Bad colour positions %d - %d\n", startSeg, pos);
103
if (validLen + (pos - startSeg + 1) >= bufferSize)
105
if (validLen + (pos - startSeg + 1) >= bufferSize) {
106
// Too big for buffer so send directly
107
Platform::SendScintilla(id, SCI_SETSTYLING, pos - startSeg + 1, chAttr);
109
if (chAttr != chWhile)
112
for (unsigned int i = startSeg; i <= pos; i++) {
113
styleBuf[validLen++] = static_cast<char>(chAttr);
120
void WindowAccessor::SetLevel(int line, int level) {
121
Platform::SendScintilla(id, SCI_SETFOLDLEVEL, line, level);
124
void WindowAccessor::Flush() {
125
startPos = extremePosition;
128
Platform::SendScintillaPointer(id, SCI_SETSTYLINGEX, validLen,
134
int WindowAccessor::IndentAmount(int line, int *flags, PFNIsCommentLeader pfnIsCommentLeader) {
138
// Determines the indentation level of the current line and also checks for consistent
139
// indentation compared to the previous line.
140
// Indentation is judged consistent when the indentation whitespace of each line lines
141
// the same or the indentation of one line is a prefix of the other.
143
int pos = LineStart(line);
144
char ch = (*this)[pos];
146
bool inPrevPrefix = line > 0;
147
int posPrev = inPrevPrefix ? LineStart(line-1) : 0;
148
while ((ch == ' ' || ch == '\t') && (pos < end)) {
150
char chPrev = (*this)[posPrev++];
151
if (chPrev == ' ' || chPrev == '\t') {
153
spaceFlags |= wsInconsistent;
155
inPrevPrefix = false;
159
spaceFlags |= wsSpace;
163
if (spaceFlags & wsSpace)
164
spaceFlags |= wsSpaceTab;
165
indent = (indent / 8 + 1) * 8;
171
indent += SC_FOLDLEVELBASE;
172
// if completely empty line or the start of a comment...
173
if (isspace(ch) || (pfnIsCommentLeader && (*pfnIsCommentLeader)(*this, pos, end-pos)) )
174
return indent | SC_FOLDLEVELWHITEFLAG;