]> git.saurik.com Git - wxWidgets.git/blame - src/stc/scintilla/src/DocumentAccessor.cxx
fixed scaling of print preview if there's not enough RAM for the full page
[wxWidgets.git] / src / stc / scintilla / src / DocumentAccessor.cxx
CommitLineData
65ec6247
RD
1// Scintilla source code edit control
2/** @file DocumentAccessor.cxx
3 ** Rapid easy access to contents of a Scintilla.
4 **/
5// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
f6bcfd97
BP
6// The License.txt file describes the conditions under which this software may be distributed.
7
8#include <stdlib.h>
d134f170 9#include <string.h>
65ec6247 10#include <ctype.h>
f6bcfd97
BP
11#include <stdio.h>
12
13#include "Platform.h"
14
15#include "PropSet.h"
f6bcfd97
BP
16#include "Accessor.h"
17#include "DocumentAccessor.h"
7e0c58e9
RD
18#include "SplitVector.h"
19#include "Partitioning.h"
20#include "RunStyles.h"
f6bcfd97
BP
21#include "CellBuffer.h"
22#include "Scintilla.h"
b8193d80 23#include "CharClassify.h"
7e0c58e9 24#include "Decoration.h"
f6bcfd97
BP
25#include "Document.h"
26
7e0c58e9
RD
27#ifdef SCI_NAMESPACE
28using namespace Scintilla;
29#endif
30
f6bcfd97
BP
31DocumentAccessor::~DocumentAccessor() {
32}
33
34bool DocumentAccessor::InternalIsLeadByte(char ch) {
f6bcfd97
BP
35 if (SC_CP_UTF8 == codePage)
36 // For lexing, all characters >= 0x80 are treated the
37 // same so none is considered a lead byte.
65ec6247 38 return false;
f6bcfd97 39 else
1a2fb4cd 40 return Platform::IsDBCSLeadByte(codePage, ch);
d134f170 41}
f6bcfd97
BP
42
43void DocumentAccessor::Fill(int position) {
44 if (lenDoc == -1)
45 lenDoc = pdoc->Length();
46 startPos = position - slopSize;
47 if (startPos + bufferSize > lenDoc)
48 startPos = lenDoc - bufferSize;
49 if (startPos < 0)
50 startPos = 0;
51 endPos = startPos + bufferSize;
52 if (endPos > lenDoc)
53 endPos = lenDoc;
54
55 pdoc->GetCharRange(buf, startPos, endPos-startPos);
56 buf[endPos-startPos] = '\0';
57}
58
a834585d
RD
59bool DocumentAccessor::Match(int pos, const char *s) {
60 for (int i=0; *s; i++) {
61 if (*s != SafeGetCharAt(pos+i))
62 return false;
63 s++;
64 }
65 return true;
66}
67
f6bcfd97 68char DocumentAccessor::StyleAt(int position) {
1e9bafca
RD
69 // Mask off all bits which aren't in the 'mask'.
70 return static_cast<char>(pdoc->StyleAt(position) & mask);
f6bcfd97
BP
71}
72
73int DocumentAccessor::GetLine(int position) {
74 return pdoc->LineFromPosition(position);
75}
76
77int DocumentAccessor::LineStart(int line) {
78 return pdoc->LineStart(line);
79}
80
81int DocumentAccessor::LevelAt(int line) {
82 return pdoc->GetLevel(line);
83}
84
65ec6247
RD
85int DocumentAccessor::Length() {
86 if (lenDoc == -1)
f6bcfd97 87 lenDoc = pdoc->Length();
65ec6247 88 return lenDoc;
f6bcfd97
BP
89}
90
91int DocumentAccessor::GetLineState(int line) {
92 return pdoc->GetLineState(line);
93}
94
95int DocumentAccessor::SetLineState(int line, int state) {
96 return pdoc->SetLineState(line, state);
97}
98
99void DocumentAccessor::StartAt(unsigned int start, char chMask) {
1e9bafca
RD
100 // Store the mask specified for use with StyleAt.
101 mask = chMask;
f6bcfd97 102 pdoc->StartStyling(start, chMask);
1a2fb4cd 103 startPosStyling = start;
f6bcfd97
BP
104}
105
106void DocumentAccessor::StartSegment(unsigned int pos) {
107 startSeg = pos;
108}
109
110void DocumentAccessor::ColourTo(unsigned int pos, int chAttr) {
111 // Only perform styling if non empty range
112 if (pos != startSeg - 1) {
7e0c58e9 113 PLATFORM_ASSERT(pos >= startSeg);
f6bcfd97 114 if (pos < startSeg) {
7e0c58e9 115 return;
f6bcfd97
BP
116 }
117
118 if (validLen + (pos - startSeg + 1) >= bufferSize)
119 Flush();
120 if (validLen + (pos - startSeg + 1) >= bufferSize) {
121 // Too big for buffer so send directly
122 pdoc->SetStyleFor(pos - startSeg + 1, static_cast<char>(chAttr));
123 } else {
124 if (chAttr != chWhile)
125 chFlags = 0;
126 chAttr |= chFlags;
127 for (unsigned int i = startSeg; i <= pos; i++) {
1a2fb4cd 128 PLATFORM_ASSERT((startPosStyling + validLen) < Length());
f6bcfd97
BP
129 styleBuf[validLen++] = static_cast<char>(chAttr);
130 }
131 }
132 }
133 startSeg = pos+1;
134}
135
136void DocumentAccessor::SetLevel(int line, int level) {
137 pdoc->SetLevel(line, level);
138}
139
140void DocumentAccessor::Flush() {
141 startPos = extremePosition;
142 lenDoc = -1;
143 if (validLen > 0) {
144 pdoc->SetStyles(validLen, styleBuf);
1a2fb4cd 145 startPosStyling += validLen;
88a8b04e 146 validLen = 0;
f6bcfd97
BP
147 }
148}
149
150int DocumentAccessor::IndentAmount(int line, int *flags, PFNIsCommentLeader pfnIsCommentLeader) {
151 int end = Length();
152 int spaceFlags = 0;
65ec6247
RD
153
154 // Determines the indentation level of the current line and also checks for consistent
f6bcfd97 155 // indentation compared to the previous line.
65ec6247 156 // Indentation is judged consistent when the indentation whitespace of each line lines
f6bcfd97 157 // the same or the indentation of one line is a prefix of the other.
65ec6247 158
f6bcfd97
BP
159 int pos = LineStart(line);
160 char ch = (*this)[pos];
161 int indent = 0;
162 bool inPrevPrefix = line > 0;
163 int posPrev = inPrevPrefix ? LineStart(line-1) : 0;
164 while ((ch == ' ' || ch == '\t') && (pos < end)) {
165 if (inPrevPrefix) {
166 char chPrev = (*this)[posPrev++];
167 if (chPrev == ' ' || chPrev == '\t') {
168 if (chPrev != ch)
169 spaceFlags |= wsInconsistent;
170 } else {
171 inPrevPrefix = false;
172 }
173 }
174 if (ch == ' ') {
175 spaceFlags |= wsSpace;
176 indent++;
177 } else { // Tab
178 spaceFlags |= wsTab;
179 if (spaceFlags & wsSpace)
180 spaceFlags |= wsSpaceTab;
181 indent = (indent / 8 + 1) * 8;
182 }
183 ch = (*this)[++pos];
184 }
65ec6247 185
f6bcfd97
BP
186 *flags = spaceFlags;
187 indent += SC_FOLDLEVELBASE;
188 // if completely empty line or the start of a comment...
9e730a78 189 if ((ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') ||
65ec6247 190 (pfnIsCommentLeader && (*pfnIsCommentLeader)(*this, pos, end-pos)) )
f6bcfd97
BP
191 return indent | SC_FOLDLEVELWHITEFLAG;
192 else
193 return indent;
194}
195
7e0c58e9
RD
196void DocumentAccessor::IndicatorFill(int start, int end, int indicator, int value) {
197 pdoc->decorations.SetCurrentIndicator(indicator);
198 pdoc->DecorationFillRange(start, value, end - start);
199}