]> git.saurik.com Git - wxWidgets.git/blame - src/stc/scintilla/src/ViewStyle.cxx
Added 'Back' to accelerator possibilities
[wxWidgets.git] / src / stc / scintilla / src / ViewStyle.cxx
CommitLineData
9ce192d4 1// Scintilla source code edit control
65ec6247
RD
2/** @file ViewStyle.cxx
3 ** Store information on how the document is to be viewed.
4 **/
9e730a78 5// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
9ce192d4
RD
6// The License.txt file describes the conditions under which this software may be distributed.
7
8#include <string.h>
9
10#include "Platform.h"
11
12#include "Scintilla.h"
13#include "Indicator.h"
9e730a78 14#include "XPM.h"
9ce192d4
RD
15#include "LineMarker.h"
16#include "Style.h"
17#include "ViewStyle.h"
18
65ec6247 19MarginStyle::MarginStyle() :
9ce192d4
RD
20 symbol(false), width(16), mask(0xffffffff), sensitive(false) {
21}
22
f6bcfd97
BP
23// A list of the fontnames - avoids wasting space in each style
24FontNames::FontNames() {
25 max = 0;
26}
27
28FontNames::~FontNames() {
29 Clear();
30}
31
32void FontNames::Clear() {
33 for (int i=0;i<max;i++) {
34 delete []names[i];
35 }
36 max = 0;
37}
38
39const char *FontNames::Save(const char *name) {
40 if (!name)
41 return 0;
42 for (int i=0;i<max;i++) {
43 if (strcmp(names[i], name) == 0) {
44 return names[i];
45 }
46 }
47 names[max] = new char[strlen(name) + 1];
48 strcpy(names[max], name);
49 max++;
50 return names[max-1];
51}
52
9ce192d4
RD
53ViewStyle::ViewStyle() {
54 Init();
55}
56
57ViewStyle::ViewStyle(const ViewStyle &source) {
58 Init();
f6bcfd97 59 for (unsigned int sty=0;sty<(sizeof(styles)/sizeof(styles[0]));sty++) {
9ce192d4 60 styles[sty] = source.styles[sty];
f6bcfd97
BP
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);
9ce192d4
RD
63 }
64 for (int mrk=0;mrk<=MARKER_MAX;mrk++) {
65 markers[mrk] = source.markers[mrk];
66 }
67 for (int ind=0;ind<=INDIC_MAX;ind++) {
68 indicators[ind] = source.indicators[ind];
69 }
65ec6247 70
9ce192d4
RD
71 selforeset = source.selforeset;
72 selforeground.desired = source.selforeground.desired;
73 selbackset = source.selbackset;
74 selbackground.desired = source.selbackground.desired;
d134f170 75 selbackground2.desired = source.selbackground2.desired;
9e730a78
RD
76
77 foldmarginColourSet = source.foldmarginColourSet;
78 foldmarginColour.desired = source.foldmarginColour.desired;
79 foldmarginHighlightColourSet = source.foldmarginHighlightColourSet;
80 foldmarginHighlightColour.desired = source.foldmarginHighlightColour.desired;
81
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
f114b858
RD
88 whitespaceForegroundSet = source.whitespaceForegroundSet;
89 whitespaceForeground.desired = source.whitespaceForeground.desired;
90 whitespaceBackgroundSet = source.whitespaceBackgroundSet;
91 whitespaceBackground.desired = source.whitespaceBackground.desired;
9ce192d4
RD
92 selbar.desired = source.selbar.desired;
93 selbarlight.desired = source.selbarlight.desired;
94 caretcolour.desired = source.caretcolour.desired;
65ec6247
RD
95 showCaretLineBackground = source.showCaretLineBackground;
96 caretLineBackground.desired = source.caretLineBackground.desired;
9ce192d4 97 edgecolour.desired = source.edgecolour.desired;
d134f170 98 edgeState = source.edgeState;
65ec6247 99 caretWidth = source.caretWidth;
9ce192d4
RD
100 leftMarginWidth = source.leftMarginWidth;
101 rightMarginWidth = source.rightMarginWidth;
102 for (int i=0;i < margins; i++) {
103 ms[i] = source.ms[i];
104 }
105 symbolMargin = source.symbolMargin;
106 maskInLine = source.maskInLine;
107 fixedColumnWidth = source.fixedColumnWidth;
108 zoomLevel = source.zoomLevel;
109 viewWhitespace = source.viewWhitespace;
d134f170 110 viewIndentationGuides = source.viewIndentationGuides;
9ce192d4 111 viewEOL = source.viewEOL;
65ec6247 112 showMarkedLines = source.showMarkedLines;
9ce192d4
RD
113}
114
115ViewStyle::~ViewStyle() {
116}
117
118void ViewStyle::Init() {
f6bcfd97
BP
119 fontNames.Clear();
120 ResetDefaultStyle();
65ec6247 121
9ce192d4 122 indicators[0].style = INDIC_SQUIGGLE;
1a2fb4cd 123 indicators[0].fore = ColourDesired(0, 0x7f, 0);
9ce192d4 124 indicators[1].style = INDIC_TT;
1a2fb4cd 125 indicators[1].fore = ColourDesired(0, 0, 0xff);
9ce192d4 126 indicators[2].style = INDIC_PLAIN;
1a2fb4cd 127 indicators[2].fore = ColourDesired(0xff, 0, 0);
9ce192d4
RD
128
129 lineHeight = 1;
130 maxAscent = 1;
131 maxDescent = 1;
132 aveCharWidth = 8;
133 spaceWidth = 8;
134
135 selforeset = false;
1a2fb4cd 136 selforeground.desired = ColourDesired(0xff, 0, 0);
9ce192d4 137 selbackset = true;
1a2fb4cd
RD
138 selbackground.desired = ColourDesired(0xc0, 0xc0, 0xc0);
139 selbackground2.desired = ColourDesired(0xb0, 0xb0, 0xb0);
9e730a78
RD
140
141 foldmarginColourSet = false;
142 foldmarginColour.desired = ColourDesired(0xff, 0, 0);
143 foldmarginHighlightColourSet = false;
144 foldmarginHighlightColour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
145
f114b858
RD
146 whitespaceForegroundSet = false;
147 whitespaceForeground.desired = ColourDesired(0, 0, 0);
148 whitespaceBackgroundSet = false;
149 whitespaceBackground.desired = ColourDesired(0xff, 0xff, 0xff);
9ce192d4
RD
150 selbar.desired = Platform::Chrome();
151 selbarlight.desired = Platform::ChromeHighlight();
1a2fb4cd 152 styles[STYLE_LINENUMBER].fore.desired = ColourDesired(0, 0, 0);
9ce192d4 153 styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
1a2fb4cd 154 caretcolour.desired = ColourDesired(0, 0, 0);
65ec6247 155 showCaretLineBackground = false;
1a2fb4cd
RD
156 caretLineBackground.desired = ColourDesired(0xff, 0xff, 0);
157 edgecolour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
d134f170 158 edgeState = EDGE_NONE;
65ec6247 159 caretWidth = 1;
9e730a78
RD
160 someStylesProtected = false;
161
162 hotspotForegroundSet = false;
163 hotspotForeground.desired = ColourDesired(0, 0, 0xff);
164 hotspotBackgroundSet = false;
165 hotspotBackground.desired = ColourDesired(0xff, 0xff, 0xff);
166 hotspotUnderline = true;
65ec6247 167
9ce192d4
RD
168 leftMarginWidth = 1;
169 rightMarginWidth = 1;
170 ms[0].symbol = false;
171 ms[0].width = 0;
172 ms[0].mask = 0;
173 ms[1].symbol = true;
174 ms[1].width = 16;
175 ms[1].mask = ~SC_MASK_FOLDERS;
176 ms[2].symbol = true;
9e730a78 177 ms[2].width = 0;
9ce192d4
RD
178 ms[2].mask = 0;
179 fixedColumnWidth = leftMarginWidth;
180 symbolMargin = false;
181 maskInLine = 0xffffffff;
182 for (int margin=0; margin < margins; margin++) {
183 fixedColumnWidth += ms[margin].width;
184 symbolMargin = symbolMargin || ms[margin].symbol;
185 if (ms[margin].width > 0)
186 maskInLine &= ~ms[margin].mask;
187 }
188 zoomLevel = 0;
d134f170
RD
189 viewWhitespace = wsInvisible;
190 viewIndentationGuides = false;
9ce192d4
RD
191 viewEOL = false;
192 showMarkedLines = true;
193}
194
195void ViewStyle::RefreshColourPalette(Palette &pal, bool want) {
196 unsigned int i;
197 for (i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
198 pal.WantFind(styles[i].fore, want);
199 pal.WantFind(styles[i].back, want);
200 }
201 for (i=0;i<(sizeof(indicators)/sizeof(indicators[0]));i++) {
202 pal.WantFind(indicators[i].fore, want);
203 }
204 for (i=0;i<(sizeof(markers)/sizeof(markers[0]));i++) {
9e730a78 205 markers[i].RefreshColourPalette(pal, want);
9ce192d4
RD
206 }
207 pal.WantFind(selforeground, want);
208 pal.WantFind(selbackground, want);
d134f170 209 pal.WantFind(selbackground2, want);
9e730a78
RD
210
211 pal.WantFind(foldmarginColour, want);
212 pal.WantFind(foldmarginHighlightColour, want);
213
f114b858
RD
214 pal.WantFind(whitespaceForeground, want);
215 pal.WantFind(whitespaceBackground, want);
9ce192d4
RD
216 pal.WantFind(selbar, want);
217 pal.WantFind(selbarlight, want);
218 pal.WantFind(caretcolour, want);
65ec6247 219 pal.WantFind(caretLineBackground, want);
9ce192d4 220 pal.WantFind(edgecolour, want);
9e730a78
RD
221 pal.WantFind(hotspotForeground, want);
222 pal.WantFind(hotspotBackground, want);
9ce192d4
RD
223}
224
225void ViewStyle::Refresh(Surface &surface) {
226 selbar.desired = Platform::Chrome();
227 selbarlight.desired = Platform::ChromeHighlight();
f6bcfd97
BP
228 styles[STYLE_DEFAULT].Realise(surface, zoomLevel);
229 maxAscent = styles[STYLE_DEFAULT].ascent;
230 maxDescent = styles[STYLE_DEFAULT].descent;
9e730a78 231 someStylesProtected = false;
9ce192d4 232 for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
f6bcfd97
BP
233 if (i != STYLE_DEFAULT) {
234 styles[i].Realise(surface, zoomLevel, &styles[STYLE_DEFAULT]);
235 if (maxAscent < styles[i].ascent)
236 maxAscent = styles[i].ascent;
237 if (maxDescent < styles[i].descent)
238 maxDescent = styles[i].descent;
239 }
9e730a78
RD
240 if (styles[i].IsProtected()) {
241 someStylesProtected = true;
242 }
9ce192d4 243 }
65ec6247 244
9ce192d4
RD
245 lineHeight = maxAscent + maxDescent;
246 aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth;
247 spaceWidth = styles[STYLE_DEFAULT].spaceWidth;
248
249 fixedColumnWidth = leftMarginWidth;
250 symbolMargin = false;
251 maskInLine = 0xffffffff;
252 for (int margin=0; margin < margins; margin++) {
253 fixedColumnWidth += ms[margin].width;
254 symbolMargin = symbolMargin || ms[margin].symbol;
255 if (ms[margin].width > 0)
256 maskInLine &= ~ms[margin].mask;
257 }
258}
259
260void ViewStyle::ResetDefaultStyle() {
9e730a78 261 styles[STYLE_DEFAULT].Clear(ColourDesired(0,0,0),
1a2fb4cd 262 ColourDesired(0xff,0xff,0xff),
65ec6247 263 Platform::DefaultFontSize(), fontNames.Save(Platform::DefaultFont()),
f6bcfd97 264 SC_CHARSET_DEFAULT,
9e730a78 265 false, false, false, false, Style::caseMixed, true, true, false);
9ce192d4
RD
266}
267
268void ViewStyle::ClearStyles() {
269 // Reset all styles to be like the default style
f6bcfd97 270 for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
9ce192d4 271 if (i != STYLE_DEFAULT) {
65ec6247 272 styles[i].ClearTo(styles[STYLE_DEFAULT]);
9ce192d4
RD
273 }
274 }
275 styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
276}
277
f6bcfd97
BP
278void ViewStyle::SetStyleFontName(int styleIndex, const char *name) {
279 styles[styleIndex].fontName = fontNames.Save(name);
280}
9e730a78
RD
281
282bool ViewStyle::ProtectionActive() const {
283 return someStylesProtected;
284}