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.
14 #include "Scintilla.h"
16 bool Accessor::InternalIsLeadByte(char ch
) {
18 // TODO: support DBCS under GTK+
21 return IsDBCSLeadByteEx(codePage
, ch
);
27 void Accessor::Fill(int position
) {
29 lenDoc
= Platform::SendScintilla(id
, WM_GETTEXTLENGTH
, 0, 0);
30 startPos
= position
- slopSize
;
31 if (startPos
+ bufferSize
> lenDoc
)
32 startPos
= lenDoc
- bufferSize
;
35 endPos
= startPos
+ bufferSize
;
39 TEXTRANGE tr
= {{startPos
, endPos
}, buf
};
40 Platform::SendScintilla(id
, EM_GETTEXTRANGE
, 0, reinterpret_cast<LPARAM
>(&tr
));
43 char Accessor::StyleAt(int position
) {
44 return static_cast<char>(Platform::SendScintilla(
45 id
, SCI_GETSTYLEAT
, position
, 0));
48 int Accessor::GetLine(int position
) {
49 return Platform::SendScintilla(id
, EM_LINEFROMCHAR
, position
, 0);
52 int Accessor::LineStart(int line
) {
53 return Platform::SendScintilla(id
, EM_LINEINDEX
, line
, 0);
56 int Accessor::LevelAt(int line
) {
57 return Platform::SendScintilla(id
, SCI_GETFOLDLEVEL
, line
, 0);
60 int Accessor::Length() {
62 lenDoc
= Platform::SendScintilla(id
, WM_GETTEXTLENGTH
, 0, 0);
66 int Accessor::GetLineState(int line
) {
67 return Platform::SendScintilla(id
, SCI_GETLINESTATE
, line
);
70 int Accessor::SetLineState(int line
, int state
) {
71 return Platform::SendScintilla(id
, SCI_SETLINESTATE
, line
, state
);
74 void StylingContext::StartAt(unsigned int start
, char chMask
) {
75 Platform::SendScintilla(id
, SCI_STARTSTYLING
, start
, chMask
);
78 void StylingContext::StartSegment(unsigned int pos
) {
82 void StylingContext::ColourTo(unsigned int pos
, int chAttr
) {
83 // Only perform styling if non empty range
84 if (pos
!= startSeg
- 1) {
86 Platform::DebugPrintf("Bad colour positions %d - %d\n", startSeg
, pos
);
89 if (validLen
+ (pos
- startSeg
+ 1) >= bufferSize
)
91 if (validLen
+ (pos
- startSeg
+ 1) >= bufferSize
) {
92 // Too big for buffer so send directly
93 Platform::SendScintilla(id
, SCI_SETSTYLING
, pos
- startSeg
+ 1, chAttr
);
95 if (chAttr
!= chWhile
)
98 for (unsigned int i
= startSeg
; i
<= pos
; i
++) {
99 styleBuf
[validLen
++] = chAttr
;
106 int StylingContext::GetLine(int position
) {
107 return Platform::SendScintilla(id
, EM_LINEFROMCHAR
, position
, 0);
110 void StylingContext::SetLevel(int line
, int level
) {
111 Platform::SendScintilla(id
, SCI_SETFOLDLEVEL
, line
, level
);
114 void StylingContext::Flush() {
116 Platform::SendScintilla(id
, SCI_SETSTYLINGEX
, validLen
,
117 reinterpret_cast<LPARAM
>(styleBuf
));
122 int StylingContext::IndentAmount(int line
, int *flags
, PFNIsCommentLeader pfnIsCommentLeader
) {
126 // Determines the indentation level of the current line and also checks for consistent
127 // indentation compared to the previous line.
128 // Indentation is judged consistent when the indentation whitespace of each line lines
129 // the same or the indentation of one line is a prefix of the other.
131 int pos
= LineStart(line
);
132 char ch
= (*this)[pos
];
134 bool inPrevPrefix
= line
> 0;
135 int posPrev
= inPrevPrefix
? LineStart(line
-1) : 0;
136 while ((ch
== ' ' || ch
== '\t') && (pos
< end
)) {
138 char chPrev
= (*this)[posPrev
++];
139 if (chPrev
== ' ' || chPrev
== '\t') {
141 spaceFlags
|= wsInconsistent
;
143 inPrevPrefix
= false;
147 spaceFlags
|= wsSpace
;
151 if (spaceFlags
& wsSpace
)
152 spaceFlags
|= wsSpaceTab
;
153 indent
= (indent
/ 8 + 1) * 8;
159 indent
+= SC_FOLDLEVELBASE
;
160 // if completely empty line or the start of a comment...
161 if (isspace(ch
) || (pfnIsCommentLeader
&& (*pfnIsCommentLeader
)(*this, pos
, end
-pos
)) )
162 return indent
| SC_FOLDLEVELWHITEFLAG
;