]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/ViewStyle.cxx
e2a65e09e4c685d64770401cfaa90710275a5105
[wxWidgets.git] / contrib / 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 }
115
116 ViewStyle::~ViewStyle() {
117 }
118
119 void ViewStyle::Init() {
120 fontNames.Clear();
121 ResetDefaultStyle();
122
123 indicators[0].style = INDIC_SQUIGGLE;
124 indicators[0].fore = ColourDesired(0, 0x7f, 0);
125 indicators[1].style = INDIC_TT;
126 indicators[1].fore = ColourDesired(0, 0, 0xff);
127 indicators[2].style = INDIC_PLAIN;
128 indicators[2].fore = ColourDesired(0xff, 0, 0);
129
130 lineHeight = 1;
131 maxAscent = 1;
132 maxDescent = 1;
133 aveCharWidth = 8;
134 spaceWidth = 8;
135
136 selforeset = false;
137 selforeground.desired = ColourDesired(0xff, 0, 0);
138 selbackset = true;
139 selbackground.desired = ColourDesired(0xc0, 0xc0, 0xc0);
140 selbackground2.desired = ColourDesired(0xb0, 0xb0, 0xb0);
141
142 foldmarginColourSet = false;
143 foldmarginColour.desired = ColourDesired(0xff, 0, 0);
144 foldmarginHighlightColourSet = false;
145 foldmarginHighlightColour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
146
147 whitespaceForegroundSet = false;
148 whitespaceForeground.desired = ColourDesired(0, 0, 0);
149 whitespaceBackgroundSet = false;
150 whitespaceBackground.desired = ColourDesired(0xff, 0xff, 0xff);
151 selbar.desired = Platform::Chrome();
152 selbarlight.desired = Platform::ChromeHighlight();
153 styles[STYLE_LINENUMBER].fore.desired = ColourDesired(0, 0, 0);
154 styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
155 caretcolour.desired = ColourDesired(0, 0, 0);
156 showCaretLineBackground = false;
157 caretLineBackground.desired = ColourDesired(0xff, 0xff, 0);
158 edgecolour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
159 edgeState = EDGE_NONE;
160 caretWidth = 1;
161 someStylesProtected = false;
162
163 hotspotForegroundSet = false;
164 hotspotForeground.desired = ColourDesired(0, 0, 0xff);
165 hotspotBackgroundSet = false;
166 hotspotBackground.desired = ColourDesired(0xff, 0xff, 0xff);
167 hotspotUnderline = true;
168 hotspotSingleLine = true;
169
170 leftMarginWidth = 1;
171 rightMarginWidth = 1;
172 ms[0].symbol = false;
173 ms[0].width = 0;
174 ms[0].mask = 0;
175 ms[1].symbol = true;
176 ms[1].width = 16;
177 ms[1].mask = ~SC_MASK_FOLDERS;
178 ms[2].symbol = true;
179 ms[2].width = 0;
180 ms[2].mask = 0;
181 fixedColumnWidth = leftMarginWidth;
182 symbolMargin = false;
183 maskInLine = 0xffffffff;
184 for (int margin=0; margin < margins; margin++) {
185 fixedColumnWidth += ms[margin].width;
186 symbolMargin = symbolMargin || ms[margin].symbol;
187 if (ms[margin].width > 0)
188 maskInLine &= ~ms[margin].mask;
189 }
190 zoomLevel = 0;
191 viewWhitespace = wsInvisible;
192 viewIndentationGuides = false;
193 viewEOL = false;
194 showMarkedLines = true;
195 }
196
197 void ViewStyle::RefreshColourPalette(Palette &pal, bool want) {
198 unsigned int i;
199 for (i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
200 pal.WantFind(styles[i].fore, want);
201 pal.WantFind(styles[i].back, want);
202 }
203 for (i=0;i<(sizeof(indicators)/sizeof(indicators[0]));i++) {
204 pal.WantFind(indicators[i].fore, want);
205 }
206 for (i=0;i<(sizeof(markers)/sizeof(markers[0]));i++) {
207 markers[i].RefreshColourPalette(pal, want);
208 }
209 pal.WantFind(selforeground, want);
210 pal.WantFind(selbackground, want);
211 pal.WantFind(selbackground2, want);
212
213 pal.WantFind(foldmarginColour, want);
214 pal.WantFind(foldmarginHighlightColour, want);
215
216 pal.WantFind(whitespaceForeground, want);
217 pal.WantFind(whitespaceBackground, want);
218 pal.WantFind(selbar, want);
219 pal.WantFind(selbarlight, want);
220 pal.WantFind(caretcolour, want);
221 pal.WantFind(caretLineBackground, want);
222 pal.WantFind(edgecolour, want);
223 pal.WantFind(hotspotForeground, want);
224 pal.WantFind(hotspotBackground, want);
225 }
226
227 void ViewStyle::Refresh(Surface &surface) {
228 selbar.desired = Platform::Chrome();
229 selbarlight.desired = Platform::ChromeHighlight();
230 styles[STYLE_DEFAULT].Realise(surface, zoomLevel);
231 maxAscent = styles[STYLE_DEFAULT].ascent;
232 maxDescent = styles[STYLE_DEFAULT].descent;
233 someStylesProtected = false;
234 for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
235 if (i != STYLE_DEFAULT) {
236 styles[i].Realise(surface, zoomLevel, &styles[STYLE_DEFAULT]);
237 if (maxAscent < styles[i].ascent)
238 maxAscent = styles[i].ascent;
239 if (maxDescent < styles[i].descent)
240 maxDescent = styles[i].descent;
241 }
242 if (styles[i].IsProtected()) {
243 someStylesProtected = true;
244 }
245 }
246
247 lineHeight = maxAscent + maxDescent;
248 aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth;
249 spaceWidth = styles[STYLE_DEFAULT].spaceWidth;
250
251 fixedColumnWidth = leftMarginWidth;
252 symbolMargin = false;
253 maskInLine = 0xffffffff;
254 for (int margin=0; margin < margins; margin++) {
255 fixedColumnWidth += ms[margin].width;
256 symbolMargin = symbolMargin || ms[margin].symbol;
257 if (ms[margin].width > 0)
258 maskInLine &= ~ms[margin].mask;
259 }
260 }
261
262 void ViewStyle::ResetDefaultStyle() {
263 styles[STYLE_DEFAULT].Clear(ColourDesired(0,0,0),
264 ColourDesired(0xff,0xff,0xff),
265 Platform::DefaultFontSize(), fontNames.Save(Platform::DefaultFont()),
266 SC_CHARSET_DEFAULT,
267 false, false, false, false, Style::caseMixed, true, true, false);
268 }
269
270 void ViewStyle::ClearStyles() {
271 // Reset all styles to be like the default style
272 for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
273 if (i != STYLE_DEFAULT) {
274 styles[i].ClearTo(styles[STYLE_DEFAULT]);
275 }
276 }
277 styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
278 }
279
280 void ViewStyle::SetStyleFontName(int styleIndex, const char *name) {
281 styles[styleIndex].fontName = fontNames.Save(name);
282 }
283
284 bool ViewStyle::ProtectionActive() const {
285 return someStylesProtected;
286 }