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