]>
Commit | Line | Data |
---|---|---|
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 | ||
88 | whitespaceForegroundSet = source.whitespaceForegroundSet; | |
89 | whitespaceForeground.desired = source.whitespaceForeground.desired; | |
90 | whitespaceBackgroundSet = source.whitespaceBackgroundSet; | |
91 | whitespaceBackground.desired = source.whitespaceBackground.desired; | |
92 | selbar.desired = source.selbar.desired; | |
93 | selbarlight.desired = source.selbarlight.desired; | |
94 | caretcolour.desired = source.caretcolour.desired; | |
95 | showCaretLineBackground = source.showCaretLineBackground; | |
96 | caretLineBackground.desired = source.caretLineBackground.desired; | |
97 | edgecolour.desired = source.edgecolour.desired; | |
98 | edgeState = source.edgeState; | |
99 | caretWidth = source.caretWidth; | |
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; | |
110 | viewIndentationGuides = source.viewIndentationGuides; | |
111 | viewEOL = source.viewEOL; | |
112 | showMarkedLines = source.showMarkedLines; | |
113 | } | |
114 | ||
115 | ViewStyle::~ViewStyle() { | |
116 | } | |
117 | ||
118 | void ViewStyle::Init() { | |
119 | fontNames.Clear(); | |
120 | ResetDefaultStyle(); | |
121 | ||
122 | indicators[0].style = INDIC_SQUIGGLE; | |
123 | indicators[0].fore = ColourDesired(0, 0x7f, 0); | |
124 | indicators[1].style = INDIC_TT; | |
125 | indicators[1].fore = ColourDesired(0, 0, 0xff); | |
126 | indicators[2].style = INDIC_PLAIN; | |
127 | indicators[2].fore = ColourDesired(0xff, 0, 0); | |
128 | ||
129 | lineHeight = 1; | |
130 | maxAscent = 1; | |
131 | maxDescent = 1; | |
132 | aveCharWidth = 8; | |
133 | spaceWidth = 8; | |
134 | ||
135 | selforeset = false; | |
136 | selforeground.desired = ColourDesired(0xff, 0, 0); | |
137 | selbackset = true; | |
138 | selbackground.desired = ColourDesired(0xc0, 0xc0, 0xc0); | |
139 | selbackground2.desired = ColourDesired(0xb0, 0xb0, 0xb0); | |
140 | ||
141 | foldmarginColourSet = false; | |
142 | foldmarginColour.desired = ColourDesired(0xff, 0, 0); | |
143 | foldmarginHighlightColourSet = false; | |
144 | foldmarginHighlightColour.desired = ColourDesired(0xc0, 0xc0, 0xc0); | |
145 | ||
146 | whitespaceForegroundSet = false; | |
147 | whitespaceForeground.desired = ColourDesired(0, 0, 0); | |
148 | whitespaceBackgroundSet = false; | |
149 | whitespaceBackground.desired = ColourDesired(0xff, 0xff, 0xff); | |
150 | selbar.desired = Platform::Chrome(); | |
151 | selbarlight.desired = Platform::ChromeHighlight(); | |
152 | styles[STYLE_LINENUMBER].fore.desired = ColourDesired(0, 0, 0); | |
153 | styles[STYLE_LINENUMBER].back.desired = Platform::Chrome(); | |
154 | caretcolour.desired = ColourDesired(0, 0, 0); | |
155 | showCaretLineBackground = false; | |
156 | caretLineBackground.desired = ColourDesired(0xff, 0xff, 0); | |
157 | edgecolour.desired = ColourDesired(0xc0, 0xc0, 0xc0); | |
158 | edgeState = EDGE_NONE; | |
159 | caretWidth = 1; | |
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; | |
167 | ||
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; | |
177 | ms[2].width = 0; | |
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; | |
189 | viewWhitespace = wsInvisible; | |
190 | viewIndentationGuides = false; | |
191 | viewEOL = false; | |
192 | showMarkedLines = true; | |
193 | } | |
194 | ||
195 | void 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++) { | |
205 | markers[i].RefreshColourPalette(pal, want); | |
206 | } | |
207 | pal.WantFind(selforeground, want); | |
208 | pal.WantFind(selbackground, want); | |
209 | pal.WantFind(selbackground2, want); | |
210 | ||
211 | pal.WantFind(foldmarginColour, want); | |
212 | pal.WantFind(foldmarginHighlightColour, want); | |
213 | ||
214 | pal.WantFind(whitespaceForeground, want); | |
215 | pal.WantFind(whitespaceBackground, want); | |
216 | pal.WantFind(selbar, want); | |
217 | pal.WantFind(selbarlight, want); | |
218 | pal.WantFind(caretcolour, want); | |
219 | pal.WantFind(caretLineBackground, want); | |
220 | pal.WantFind(edgecolour, want); | |
221 | pal.WantFind(hotspotForeground, want); | |
222 | pal.WantFind(hotspotBackground, want); | |
223 | } | |
224 | ||
225 | void ViewStyle::Refresh(Surface &surface) { | |
226 | selbar.desired = Platform::Chrome(); | |
227 | selbarlight.desired = Platform::ChromeHighlight(); | |
228 | styles[STYLE_DEFAULT].Realise(surface, zoomLevel); | |
229 | maxAscent = styles[STYLE_DEFAULT].ascent; | |
230 | maxDescent = styles[STYLE_DEFAULT].descent; | |
231 | someStylesProtected = false; | |
232 | for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) { | |
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 | } | |
240 | if (styles[i].IsProtected()) { | |
241 | someStylesProtected = true; | |
242 | } | |
243 | } | |
244 | ||
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 | ||
260 | void ViewStyle::ResetDefaultStyle() { | |
261 | styles[STYLE_DEFAULT].Clear(ColourDesired(0,0,0), | |
262 | ColourDesired(0xff,0xff,0xff), | |
263 | Platform::DefaultFontSize(), fontNames.Save(Platform::DefaultFont()), | |
264 | SC_CHARSET_DEFAULT, | |
265 | false, false, false, false, Style::caseMixed, true, true, false); | |
266 | } | |
267 | ||
268 | void ViewStyle::ClearStyles() { | |
269 | // Reset all styles to be like the default style | |
270 | for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) { | |
271 | if (i != STYLE_DEFAULT) { | |
272 | styles[i].ClearTo(styles[STYLE_DEFAULT]); | |
273 | } | |
274 | } | |
275 | styles[STYLE_LINENUMBER].back.desired = Platform::Chrome(); | |
276 | } | |
277 | ||
278 | void ViewStyle::SetStyleFontName(int styleIndex, const char *name) { | |
279 | styles[styleIndex].fontName = fontNames.Save(name); | |
280 | } | |
281 | ||
282 | bool ViewStyle::ProtectionActive() const { | |
283 | return someStylesProtected; | |
284 | } |