1
// Scintilla source code edit control
2
/** @file ViewStyle.cxx
3
** Store information on how the document is to be viewed.
5
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
6
// The License.txt file describes the conditions under which this software may be distributed.
12
#include "Scintilla.h"
13
#include "SplitVector.h"
14
#include "Partitioning.h"
15
#include "RunStyles.h"
16
#include "Indicator.h"
18
#include "LineMarker.h"
20
#include "ViewStyle.h"
23
using namespace Scintilla;
26
MarginStyle::MarginStyle() :
27
style(SC_MARGIN_SYMBOL), width(0), mask(0), sensitive(false) {
30
// A list of the fontnames - avoids wasting space in each style
31
FontNames::FontNames() {
33
names = new char *[size];
37
FontNames::~FontNames() {
43
void FontNames::Clear() {
44
for (int i=0; i<max; i++) {
50
const char *FontNames::Save(const char *name) {
53
for (int i=0; i<max; i++) {
54
if (strcmp(names[i], name) == 0) {
60
int sizeNew = size * 2;
61
char **namesNew = new char *[sizeNew];
62
for (int j=0; j<max; j++) {
63
namesNew[j] = names[j];
69
names[max] = new char[strlen(name) + 1];
70
strcpy(names[max], name);
75
ViewStyle::ViewStyle() {
79
ViewStyle::ViewStyle(const ViewStyle &source) {
80
Init(source.stylesSize);
81
for (unsigned int sty=0; sty<source.stylesSize; sty++) {
82
styles[sty] = source.styles[sty];
83
// Can't just copy fontname as its lifetime is relative to its owning ViewStyle
84
styles[sty].fontName = fontNames.Save(source.styles[sty].fontName);
86
for (int mrk=0; mrk<=MARKER_MAX; mrk++) {
87
markers[mrk] = source.markers[mrk];
89
for (int ind=0; ind<=INDIC_MAX; ind++) {
90
indicators[ind] = source.indicators[ind];
93
selforeset = source.selforeset;
94
selforeground.desired = source.selforeground.desired;
95
selAdditionalForeground.desired = source.selAdditionalForeground.desired;
96
selbackset = source.selbackset;
97
selbackground.desired = source.selbackground.desired;
98
selAdditionalBackground.desired = source.selAdditionalBackground.desired;
99
selbackground2.desired = source.selbackground2.desired;
100
selAlpha = source.selAlpha;
101
selAdditionalAlpha = source.selAdditionalAlpha;
102
selEOLFilled = source.selEOLFilled;
104
foldmarginColourSet = source.foldmarginColourSet;
105
foldmarginColour.desired = source.foldmarginColour.desired;
106
foldmarginHighlightColourSet = source.foldmarginHighlightColourSet;
107
foldmarginHighlightColour.desired = source.foldmarginHighlightColour.desired;
109
hotspotForegroundSet = source.hotspotForegroundSet;
110
hotspotForeground.desired = source.hotspotForeground.desired;
111
hotspotBackgroundSet = source.hotspotBackgroundSet;
112
hotspotBackground.desired = source.hotspotBackground.desired;
113
hotspotUnderline = source.hotspotUnderline;
114
hotspotSingleLine = source.hotspotSingleLine;
116
whitespaceForegroundSet = source.whitespaceForegroundSet;
117
whitespaceForeground.desired = source.whitespaceForeground.desired;
118
whitespaceBackgroundSet = source.whitespaceBackgroundSet;
119
whitespaceBackground.desired = source.whitespaceBackground.desired;
120
selbar.desired = source.selbar.desired;
121
selbarlight.desired = source.selbarlight.desired;
122
caretcolour.desired = source.caretcolour.desired;
123
additionalCaretColour.desired = source.additionalCaretColour.desired;
124
showCaretLineBackground = source.showCaretLineBackground;
125
caretLineBackground.desired = source.caretLineBackground.desired;
126
caretLineAlpha = source.caretLineAlpha;
127
edgecolour.desired = source.edgecolour.desired;
128
edgeState = source.edgeState;
129
caretStyle = source.caretStyle;
130
caretWidth = source.caretWidth;
131
someStylesProtected = false;
132
leftMarginWidth = source.leftMarginWidth;
133
rightMarginWidth = source.rightMarginWidth;
134
for (int i=0; i < margins; i++) {
135
ms[i] = source.ms[i];
137
symbolMargin = source.symbolMargin;
138
maskInLine = source.maskInLine;
139
fixedColumnWidth = source.fixedColumnWidth;
140
zoomLevel = source.zoomLevel;
141
viewWhitespace = source.viewWhitespace;
142
whitespaceSize = source.whitespaceSize;
143
viewIndentationGuides = source.viewIndentationGuides;
144
viewEOL = source.viewEOL;
145
showMarkedLines = source.showMarkedLines;
146
extraFontFlag = source.extraFontFlag;
147
extraAscent = source.extraAscent;
148
extraDescent = source.extraDescent;
149
marginStyleOffset = source.marginStyleOffset;
150
annotationVisible = source.annotationVisible;
151
annotationStyleOffset = source.annotationStyleOffset;
154
ViewStyle::~ViewStyle() {
159
void ViewStyle::Init(size_t stylesSize_) {
162
AllocStyles(stylesSize_);
166
indicators[0].style = INDIC_SQUIGGLE;
167
indicators[0].under = false;
168
indicators[0].fore = ColourDesired(0, 0x7f, 0);
169
indicators[1].style = INDIC_TT;
170
indicators[1].under = false;
171
indicators[1].fore = ColourDesired(0, 0, 0xff);
172
indicators[2].style = INDIC_PLAIN;
173
indicators[2].under = false;
174
indicators[2].fore = ColourDesired(0xff, 0, 0);
183
selforeground.desired = ColourDesired(0xff, 0, 0);
184
selAdditionalForeground.desired = ColourDesired(0xff, 0, 0);
186
selbackground.desired = ColourDesired(0xc0, 0xc0, 0xc0);
187
selAdditionalBackground.desired = ColourDesired(0xd7, 0xd7, 0xd7);
188
selbackground2.desired = ColourDesired(0xb0, 0xb0, 0xb0);
189
selAlpha = SC_ALPHA_NOALPHA;
190
selAdditionalAlpha = SC_ALPHA_NOALPHA;
191
selEOLFilled = false;
193
foldmarginColourSet = false;
194
foldmarginColour.desired = ColourDesired(0xff, 0, 0);
195
foldmarginHighlightColourSet = false;
196
foldmarginHighlightColour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
198
whitespaceForegroundSet = false;
199
whitespaceForeground.desired = ColourDesired(0, 0, 0);
200
whitespaceBackgroundSet = false;
201
whitespaceBackground.desired = ColourDesired(0xff, 0xff, 0xff);
202
selbar.desired = Platform::Chrome();
203
selbarlight.desired = Platform::ChromeHighlight();
204
styles[STYLE_LINENUMBER].fore.desired = ColourDesired(0, 0, 0);
205
styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
206
caretcolour.desired = ColourDesired(0, 0, 0);
207
additionalCaretColour.desired = ColourDesired(0x7f, 0x7f, 0x7f);
208
showCaretLineBackground = false;
209
caretLineBackground.desired = ColourDesired(0xff, 0xff, 0);
210
caretLineAlpha = SC_ALPHA_NOALPHA;
211
edgecolour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
212
edgeState = EDGE_NONE;
213
caretStyle = CARETSTYLE_LINE;
215
someStylesProtected = false;
217
hotspotForegroundSet = false;
218
hotspotForeground.desired = ColourDesired(0, 0, 0xff);
219
hotspotBackgroundSet = false;
220
hotspotBackground.desired = ColourDesired(0xff, 0xff, 0xff);
221
hotspotUnderline = true;
222
hotspotSingleLine = true;
225
rightMarginWidth = 1;
226
ms[0].style = SC_MARGIN_NUMBER;
229
ms[1].style = SC_MARGIN_SYMBOL;
231
ms[1].mask = ~SC_MASK_FOLDERS;
232
ms[2].style = SC_MARGIN_SYMBOL;
235
fixedColumnWidth = leftMarginWidth;
236
symbolMargin = false;
237
maskInLine = 0xffffffff;
238
for (int margin=0; margin < margins; margin++) {
239
fixedColumnWidth += ms[margin].width;
240
symbolMargin = symbolMargin || (ms[margin].style != SC_MARGIN_NUMBER);
241
if (ms[margin].width > 0)
242
maskInLine &= ~ms[margin].mask;
245
viewWhitespace = wsInvisible;
247
viewIndentationGuides = ivNone;
249
showMarkedLines = true;
253
marginStyleOffset = 0;
254
annotationVisible = ANNOTATION_HIDDEN;
255
annotationStyleOffset = 0;
258
void ViewStyle::RefreshColourPalette(Palette &pal, bool want) {
260
for (i=0; i<stylesSize; i++) {
261
pal.WantFind(styles[i].fore, want);
262
pal.WantFind(styles[i].back, want);
264
for (i=0; i<(sizeof(indicators)/sizeof(indicators[0])); i++) {
265
pal.WantFind(indicators[i].fore, want);
267
for (i=0; i<(sizeof(markers)/sizeof(markers[0])); i++) {
268
markers[i].RefreshColourPalette(pal, want);
270
pal.WantFind(selforeground, want);
271
pal.WantFind(selAdditionalForeground, want);
272
pal.WantFind(selbackground, want);
273
pal.WantFind(selAdditionalBackground, want);
274
pal.WantFind(selbackground2, want);
276
pal.WantFind(foldmarginColour, want);
277
pal.WantFind(foldmarginHighlightColour, want);
279
pal.WantFind(whitespaceForeground, want);
280
pal.WantFind(whitespaceBackground, want);
281
pal.WantFind(selbar, want);
282
pal.WantFind(selbarlight, want);
283
pal.WantFind(caretcolour, want);
284
pal.WantFind(additionalCaretColour, want);
285
pal.WantFind(caretLineBackground, want);
286
pal.WantFind(edgecolour, want);
287
pal.WantFind(hotspotForeground, want);
288
pal.WantFind(hotspotBackground, want);
291
void ViewStyle::Refresh(Surface &surface) {
292
selbar.desired = Platform::Chrome();
293
selbarlight.desired = Platform::ChromeHighlight();
294
styles[STYLE_DEFAULT].Realise(surface, zoomLevel, NULL, extraFontFlag);
295
maxAscent = styles[STYLE_DEFAULT].ascent;
296
maxDescent = styles[STYLE_DEFAULT].descent;
297
someStylesProtected = false;
298
for (unsigned int i=0; i<stylesSize; i++) {
299
if (i != STYLE_DEFAULT) {
300
styles[i].Realise(surface, zoomLevel, &styles[STYLE_DEFAULT], extraFontFlag);
301
if (maxAscent < styles[i].ascent)
302
maxAscent = styles[i].ascent;
303
if (maxDescent < styles[i].descent)
304
maxDescent = styles[i].descent;
306
if (styles[i].IsProtected()) {
307
someStylesProtected = true;
310
maxAscent += extraAscent;
311
maxDescent += extraDescent;
313
lineHeight = maxAscent + maxDescent;
314
aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth;
315
spaceWidth = styles[STYLE_DEFAULT].spaceWidth;
317
fixedColumnWidth = leftMarginWidth;
318
symbolMargin = false;
319
maskInLine = 0xffffffff;
320
for (int margin=0; margin < margins; margin++) {
321
fixedColumnWidth += ms[margin].width;
322
symbolMargin = symbolMargin || (ms[margin].style != SC_MARGIN_NUMBER);
323
if (ms[margin].width > 0)
324
maskInLine &= ~ms[margin].mask;
328
void ViewStyle::AllocStyles(size_t sizeNew) {
329
Style *stylesNew = new Style[sizeNew];
331
for (; i<stylesSize; i++) {
332
stylesNew[i] = styles[i];
333
stylesNew[i].fontName = styles[i].fontName;
335
if (stylesSize > STYLE_DEFAULT) {
336
for (; i<sizeNew; i++) {
337
if (i != STYLE_DEFAULT) {
338
stylesNew[i].ClearTo(styles[STYLE_DEFAULT]);
344
stylesSize = sizeNew;
347
void ViewStyle::EnsureStyle(size_t index) {
348
if (index >= stylesSize) {
349
size_t sizeNew = stylesSize * 2;
350
while (sizeNew <= index)
352
AllocStyles(sizeNew);
356
void ViewStyle::ResetDefaultStyle() {
357
styles[STYLE_DEFAULT].Clear(ColourDesired(0,0,0),
358
ColourDesired(0xff,0xff,0xff),
359
Platform::DefaultFontSize(), fontNames.Save(Platform::DefaultFont()),
361
false, false, false, false, Style::caseMixed, true, true, false);
364
void ViewStyle::ClearStyles() {
365
// Reset all styles to be like the default style
366
for (unsigned int i=0; i<stylesSize; i++) {
367
if (i != STYLE_DEFAULT) {
368
styles[i].ClearTo(styles[STYLE_DEFAULT]);
371
styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
373
// Set call tip fore/back to match the values previously set for call tips
374
styles[STYLE_CALLTIP].back.desired = ColourDesired(0xff, 0xff, 0xff);
375
styles[STYLE_CALLTIP].fore.desired = ColourDesired(0x80, 0x80, 0x80);
378
void ViewStyle::SetStyleFontName(int styleIndex, const char *name) {
379
styles[styleIndex].fontName = fontNames.Save(name);
382
bool ViewStyle::ProtectionActive() const {
383
return someStylesProtected;
386
bool ViewStyle::ValidStyle(size_t styleIndex) const {
387
return styleIndex < stylesSize;