]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/ViewStyle.cxx
c52f1e47287a51a1a1ed45acf8a2f54500332a0e
[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 someStylesProtected = false;
102 leftMarginWidth = source.leftMarginWidth;
103 rightMarginWidth = source.rightMarginWidth;
104 for (int i=0;i < margins; i++) {
105 ms[i] = source.ms[i];
106 }
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;
116 }
117
118 ViewStyle::~ViewStyle() {
119 }
120
121 void ViewStyle::Init() {
122 fontNames.Clear();
123 ResetDefaultStyle();
124
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);
131
132 lineHeight = 1;
133 maxAscent = 1;
134 maxDescent = 1;
135 aveCharWidth = 8;
136 spaceWidth = 8;
137
138 selforeset = false;
139 selforeground.desired = ColourDesired(0xff, 0, 0);
140 selbackset = true;
141 selbackground.desired = ColourDesired(0xc0, 0xc0, 0xc0);
142 selbackground2.desired = ColourDesired(0xb0, 0xb0, 0xb0);
143
144 foldmarginColourSet = false;
145 foldmarginColour.desired = ColourDesired(0xff, 0, 0);
146 foldmarginHighlightColourSet = false;
147 foldmarginHighlightColour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
148
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;
162 caretWidth = 1;
163 someStylesProtected = false;
164
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;
171
172 leftMarginWidth = 1;
173 rightMarginWidth = 1;
174 ms[0].symbol = false;
175 ms[0].width = 0;
176 ms[0].mask = 0;
177 ms[1].symbol = true;
178 ms[1].width = 16;
179 ms[1].mask = ~SC_MASK_FOLDERS;
180 ms[2].symbol = true;
181 ms[2].width = 0;
182 ms[2].mask = 0;
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;
191 }
192 zoomLevel = 0;
193 viewWhitespace = wsInvisible;
194 viewIndentationGuides = false;
195 viewEOL = false;
196 showMarkedLines = true;
197 extraFontFlag = false;
198 }
199
200 void ViewStyle::RefreshColourPalette(Palette &pal, bool want) {
201 unsigned int i;
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);
205 }
206 for (i=0;i<(sizeof(indicators)/sizeof(indicators[0]));i++) {
207 pal.WantFind(indicators[i].fore, want);
208 }
209 for (i=0;i<(sizeof(markers)/sizeof(markers[0]));i++) {
210 markers[i].RefreshColourPalette(pal, want);
211 }
212 pal.WantFind(selforeground, want);
213 pal.WantFind(selbackground, want);
214 pal.WantFind(selbackground2, want);
215
216 pal.WantFind(foldmarginColour, want);
217 pal.WantFind(foldmarginHighlightColour, want);
218
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);
228 }
229
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;
244 }
245 if (styles[i].IsProtected()) {
246 someStylesProtected = true;
247 }
248 }
249
250 lineHeight = maxAscent + maxDescent;
251 aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth;
252 spaceWidth = styles[STYLE_DEFAULT].spaceWidth;
253
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;
262 }
263 }
264
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()),
269 SC_CHARSET_DEFAULT,
270 false, false, false, false, Style::caseMixed, true, true, false);
271 }
272
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]);
278 }
279 }
280 styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
281 }
282
283 void ViewStyle::SetStyleFontName(int styleIndex, const char *name) {
284 styles[styleIndex].fontName = fontNames.Save(name);
285 }
286
287 bool ViewStyle::ProtectionActive() const {
288 return someStylesProtected;
289 }