forked from dail8859/LuaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStyleWriter.cpp
More file actions
124 lines (105 loc) · 2.98 KB
/
Copy pathStyleWriter.cpp
File metadata and controls
124 lines (105 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// SciTE - Scintilla based Text Editor
/** @file StyleWriter.cxx
** Simple buffered interface to the text and styles of a document held by Scintilla.
**/
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <string>
#include "Scintilla.h"
#include "GUI.h"
#include "StyleWriter.h"
TextReader::TextReader(GUI::ScintillaWindow &sw_) :
startPos(extremePosition),
endPos(0),
codePage(0),
sw(sw_),
lenDoc(-1) {
buf[0] = 0;
}
bool TextReader::InternalIsLeadByte(char ch) const {
return GUI::IsDBCSLeadByte(codePage, ch);
}
void TextReader::Fill(intptr_t position) {
if (lenDoc == -1)
lenDoc = sw.Call(SCI_GETTEXTLENGTH, 0, 0);
startPos = position - slopSize;
if (startPos + bufferSize > lenDoc)
startPos = lenDoc - bufferSize;
if (startPos < 0)
startPos = 0;
endPos = startPos + bufferSize;
if (endPos > lenDoc)
endPos = lenDoc;
sw.Call(SCI_SETTARGETRANGE, startPos, endPos);
sw.CallPointer(SCI_GETTARGETTEXT, 0, buf);
}
bool TextReader::Match(int pos, const char *s) {
for (int i=0; *s; i++) {
if (*s != SafeGetCharAt(pos+i))
return false;
s++;
}
return true;
}
int TextReader::StyleAt(intptr_t position) {
return static_cast<unsigned char>(sw.Call(SCI_GETSTYLEAT, position, 0));
}
intptr_t TextReader::GetLine(intptr_t position) {
return sw.Call(SCI_LINEFROMPOSITION, position, 0);
}
intptr_t TextReader::LineStart(intptr_t line) {
return sw.Call(SCI_POSITIONFROMLINE, line, 0);
}
int TextReader::LevelAt(intptr_t line) {
return static_cast<int>(sw.Call(SCI_GETFOLDLEVEL, line, 0));
}
intptr_t TextReader::Length() {
if (lenDoc == -1)
lenDoc = sw.Call(SCI_GETTEXTLENGTH, 0, 0);
return lenDoc;
}
int TextReader::GetLineState(intptr_t line) {
return static_cast<int>(sw.Call(SCI_GETLINESTATE, line));
}
StyleWriter::StyleWriter(GUI::ScintillaWindow &sw_) :
TextReader(sw_),
validLen(0),
startSeg(0) {
styleBuf[0] = 0;
}
int StyleWriter::SetLineState(intptr_t line, int state) {
return static_cast<int>(sw.Call(SCI_SETLINESTATE, line, state));
}
void StyleWriter::StartAt(uintptr_t start, char chMask) {
sw.Call(SCI_STARTSTYLING, start, chMask);
}
void StyleWriter::StartSegment(uintptr_t pos) {
startSeg = pos;
}
void StyleWriter::ColourTo(uintptr_t pos, int chAttr) {
// Only perform styling if non empty range
if (pos != startSeg - 1) {
if (validLen + (pos - startSeg + 1) >= bufferSize)
Flush();
if (validLen + (pos - startSeg + 1) >= bufferSize) {
// Too big for buffer so send directly
sw.Call(SCI_SETSTYLING, pos - startSeg + 1, chAttr);
} else {
for (uintptr_t i = startSeg; i <= pos; i++) {
styleBuf[validLen++] = static_cast<char>(chAttr);
}
}
}
startSeg = pos+1;
}
void StyleWriter::SetLevel(intptr_t line, int level) {
sw.Call(SCI_SETFOLDLEVEL, line, level);
}
void StyleWriter::Flush() {
startPos = extremePosition;
lenDoc = -1;
if (validLen > 0) {
sw.SendPointer(SCI_SETSTYLINGEX, validLen, styleBuf);
validLen = 0;
}
}