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 "Indicator.h"
15
#include "LineMarker.h"
17
#include "ViewStyle.h"
19
MarginStyle::MarginStyle() :
20
symbol(false), width(16), mask(0xffffffff), sensitive(false) {
23
// A list of the fontnames - avoids wasting space in each style
24
FontNames::FontNames() {
28
FontNames::~FontNames() {
32
void FontNames::Clear() {
33
for (int i=0;i<max;i++) {
39
const char *FontNames::Save(const char *name) {
42
for (int i=0;i<max;i++) {
43
if (strcmp(names[i], name) == 0) {
47
names[max] = new char[strlen(name) + 1];
48
strcpy(names[max], name);
53
ViewStyle::ViewStyle() {
57
ViewStyle::ViewStyle(const ViewStyle &source) {
59
for (unsigned int sty=0;sty<(sizeof(styles)/sizeof(styles[0]));sty++) {
60
styles[sty] = source.styles[sty];
61
// Can't just copy fontname as its lifetime is relative to its owning ViewStyle
62
styles[sty].fontName = fontNames.Save(source.styles[sty].fontName);
64
for (int mrk=0;mrk<=MARKER_MAX;mrk++) {
65
markers[mrk] = source.markers[mrk];
67
for (int ind=0;ind<=INDIC_MAX;ind++) {
68
indicators[ind] = source.indicators[ind];
71
selforeset = source.selforeset;
72
selforeground.desired = source.selforeground.desired;
73
selbackset = source.selbackset;
74
selbackground.desired = source.selbackground.desired;
75
selbackground2.desired = source.selbackground2.desired;
77
foldmarginColourSet = source.foldmarginColourSet;
78
foldmarginColour.desired = source.foldmarginColour.desired;
79
foldmarginHighlightColourSet = source.foldmarginHighlightColourSet;
80
foldmarginHighlightColour.desired = source.foldmarginHighlightColour.desired;
82
hotspotForegroundSet = source.hotspotForegroundSet;
83
hotspotForeground.desired = source.hotspotForeground.desired;
84
hotspotBackgroundSet = source.hotspotBackgroundSet;
85
hotspotBackground.desired = source.hotspotBackground.desired;
86
hotspotUnderline = source.hotspotUnderline;
87
hotspotSingleLine = source.hotspotSingleLine;
89
whitespaceForegroundSet = source.whitespaceForegroundSet;
90
whitespaceForeground.desired = source.whitespaceForeground.desired;
91
whitespaceBackgroundSet = source.whitespaceBackgroundSet;
92
whitespaceBackground.desired = source.whitespaceBackground.desired;
93
selbar.desired = source.selbar.desired;
94
selbarlight.desired = source.selbarlight.desired;
95
caretcolour.desired = source.caretcolour.desired;
96
showCaretLineBackground = source.showCaretLineBackground;
97
caretLineBackground.desired = source.caretLineBackground.desired;
98
edgecolour.desired = source.edgecolour.desired;
99
edgeState = source.edgeState;
100
caretWidth = source.caretWidth;
101
someStylesProtected = false;
102
leftMarginWidth = source.leftMarginWidth;
103
rightMarginWidth = source.rightMarginWidth;
104
for (int i=0;i < margins; i++) {
105
ms[i] = source.ms[i];
107
symbolMargin = source.symbolMargin;
108
maskInLine = source.maskInLine;
109
fixedColumnWidth = source.fixedColumnWidth;
110
zoomLevel = source.zoomLevel;
111
viewWhitespace = source.viewWhitespace;
112
viewIndentationGuides = source.viewIndentationGuides;
113
viewEOL = source.viewEOL;
114
showMarkedLines = source.showMarkedLines;
115
extraFontFlag = source.extraFontFlag;
118
ViewStyle::~ViewStyle() {
121
void ViewStyle::Init() {
125
indicators[0].style = INDIC_SQUIGGLE;
126
indicators[0].fore = ColourDesired(0, 0x7f, 0);
127
indicators[1].style = INDIC_TT;
128
indicators[1].fore = ColourDesired(0, 0, 0xff);
129
indicators[2].style = INDIC_PLAIN;
130
indicators[2].fore = ColourDesired(0xff, 0, 0);
139
selforeground.desired = ColourDesired(0xff, 0, 0);
141
selbackground.desired = ColourDesired(0xc0, 0xc0, 0xc0);
142
selbackground2.desired = ColourDesired(0xb0, 0xb0, 0xb0);
144
foldmarginColourSet = false;
145
foldmarginColour.desired = ColourDesired(0xff, 0, 0);
146
foldmarginHighlightColourSet = false;
147
foldmarginHighlightColour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
149
whitespaceForegroundSet = false;
150
whitespaceForeground.desired = ColourDesired(0, 0, 0);
151
whitespaceBackgroundSet = false;
152
whitespaceBackground.desired = ColourDesired(0xff, 0xff, 0xff);
153
selbar.desired = Platform::Chrome();
154
selbarlight.desired = Platform::ChromeHighlight();
155
styles[STYLE_LINENUMBER].fore.desired = ColourDesired(0, 0, 0);
156
styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
157
caretcolour.desired = ColourDesired(0, 0, 0);
158
showCaretLineBackground = false;
159
caretLineBackground.desired = ColourDesired(0xff, 0xff, 0);
160
edgecolour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
161
edgeState = EDGE_NONE;
163
someStylesProtected = false;
165
hotspotForegroundSet = false;
166
hotspotForeground.desired = ColourDesired(0, 0, 0xff);
167
hotspotBackgroundSet = false;
168
hotspotBackground.desired = ColourDesired(0xff, 0xff, 0xff);
169
hotspotUnderline = true;
170
hotspotSingleLine = true;
173
rightMarginWidth = 1;
174
ms[0].symbol = false;
179
ms[1].mask = ~SC_MASK_FOLDERS;
183
fixedColumnWidth = leftMarginWidth;
184
symbolMargin = false;
185
maskInLine = 0xffffffff;
186
for (int margin=0; margin < margins; margin++) {
187
fixedColumnWidth += ms[margin].width;
188
symbolMargin = symbolMargin || ms[margin].symbol;
189
if (ms[margin].width > 0)
190
maskInLine &= ~ms[margin].mask;
193
viewWhitespace = wsInvisible;
194
viewIndentationGuides = false;
196
showMarkedLines = true;
197
extraFontFlag = false;
200
void ViewStyle::RefreshColourPalette(Palette &pal, bool want) {
202
for (i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
203
pal.WantFind(styles[i].fore, want);
204
pal.WantFind(styles[i].back, want);
206
for (i=0;i<(sizeof(indicators)/sizeof(indicators[0]));i++) {
207
pal.WantFind(indicators[i].fore, want);
209
for (i=0;i<(sizeof(markers)/sizeof(markers[0]));i++) {
210
markers[i].RefreshColourPalette(pal, want);
212
pal.WantFind(selforeground, want);
213
pal.WantFind(selbackground, want);
214
pal.WantFind(selbackground2, want);
216
pal.WantFind(foldmarginColour, want);
217
pal.WantFind(foldmarginHighlightColour, want);
219
pal.WantFind(whitespaceForeground, want);
220
pal.WantFind(whitespaceBackground, want);
221
pal.WantFind(selbar, want);
222
pal.WantFind(selbarlight, want);
223
pal.WantFind(caretcolour, want);
224
pal.WantFind(caretLineBackground, want);
225
pal.WantFind(edgecolour, want);
226
pal.WantFind(hotspotForeground, want);
227
pal.WantFind(hotspotBackground, want);
230
void ViewStyle::Refresh(Surface &surface) {
231
selbar.desired = Platform::Chrome();
232
selbarlight.desired = Platform::ChromeHighlight();
233
styles[STYLE_DEFAULT].Realise(surface, zoomLevel, NULL, extraFontFlag);
234
maxAscent = styles[STYLE_DEFAULT].ascent;
235
maxDescent = styles[STYLE_DEFAULT].descent;
236
someStylesProtected = false;
237
for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
238
if (i != STYLE_DEFAULT) {
239
styles[i].Realise(surface, zoomLevel, &styles[STYLE_DEFAULT], extraFontFlag);
240
if (maxAscent < styles[i].ascent)
241
maxAscent = styles[i].ascent;
242
if (maxDescent < styles[i].descent)
243
maxDescent = styles[i].descent;
245
if (styles[i].IsProtected()) {
246
someStylesProtected = true;
250
lineHeight = maxAscent + maxDescent;
251
aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth;
252
spaceWidth = styles[STYLE_DEFAULT].spaceWidth;
254
fixedColumnWidth = leftMarginWidth;
255
symbolMargin = false;
256
maskInLine = 0xffffffff;
257
for (int margin=0; margin < margins; margin++) {
258
fixedColumnWidth += ms[margin].width;
259
symbolMargin = symbolMargin || ms[margin].symbol;
260
if (ms[margin].width > 0)
261
maskInLine &= ~ms[margin].mask;
265
void ViewStyle::ResetDefaultStyle() {
266
styles[STYLE_DEFAULT].Clear(ColourDesired(0,0,0),
267
ColourDesired(0xff,0xff,0xff),
268
Platform::DefaultFontSize(), fontNames.Save(Platform::DefaultFont()),
270
false, false, false, false, Style::caseMixed, true, true, false);
273
void ViewStyle::ClearStyles() {
274
// Reset all styles to be like the default style
275
for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
276
if (i != STYLE_DEFAULT) {
277
styles[i].ClearTo(styles[STYLE_DEFAULT]);
280
styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
283
void ViewStyle::SetStyleFontName(int styleIndex, const char *name) {
284
styles[styleIndex].fontName = fontNames.Save(name);
287
bool ViewStyle::ProtectionActive() const {
288
return someStylesProtected;