]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/ViewStyle.cxx
12e1406aa440db3930e2e8d1ae8f51f36b4b8bcc
[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-2001 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 "LineMarker.h"
15 #include "Style.h"
16 #include "ViewStyle.h"
17
18 MarginStyle::MarginStyle() :
19 symbol(false), width(16), mask(0xffffffff), sensitive(false) {
20 }
21
22 // A list of the fontnames - avoids wasting space in each style
23 FontNames::FontNames() {
24 max = 0;
25 }
26
27 FontNames::~FontNames() {
28 Clear();
29 }
30
31 void FontNames::Clear() {
32 for (int i=0;i<max;i++) {
33 delete []names[i];
34 }
35 max = 0;
36 }
37
38 const char *FontNames::Save(const char *name) {
39 if (!name)
40 return 0;
41 for (int i=0;i<max;i++) {
42 if (strcmp(names[i], name) == 0) {
43 return names[i];
44 }
45 }
46 names[max] = new char[strlen(name) + 1];
47 strcpy(names[max], name);
48 max++;
49 return names[max-1];
50 }
51
52 ViewStyle::ViewStyle() {
53 Init();
54 }
55
56 ViewStyle::ViewStyle(const ViewStyle &source) {
57 Init();
58 for (unsigned int sty=0;sty<(sizeof(styles)/sizeof(styles[0]));sty++) {
59 styles[sty] = source.styles[sty];
60 // Can't just copy fontname as its lifetime is relative to its owning ViewStyle
61 styles[sty].fontName = fontNames.Save(source.styles[sty].fontName);
62 }
63 for (int mrk=0;mrk<=MARKER_MAX;mrk++) {
64 markers[mrk] = source.markers[mrk];
65 }
66 for (int ind=0;ind<=INDIC_MAX;ind++) {
67 indicators[ind] = source.indicators[ind];
68 }
69
70 selforeset = source.selforeset;
71 selforeground.desired = source.selforeground.desired;
72 selbackset = source.selbackset;
73 selbackground.desired = source.selbackground.desired;
74 selbackground2.desired = source.selbackground2.desired;
75 whitespaceForegroundSet = source.whitespaceForegroundSet;
76 whitespaceForeground.desired = source.whitespaceForeground.desired;
77 whitespaceBackgroundSet = source.whitespaceBackgroundSet;
78 whitespaceBackground.desired = source.whitespaceBackground.desired;
79 selbar.desired = source.selbar.desired;
80 selbarlight.desired = source.selbarlight.desired;
81 caretcolour.desired = source.caretcolour.desired;
82 showCaretLineBackground = source.showCaretLineBackground;
83 caretLineBackground.desired = source.caretLineBackground.desired;
84 edgecolour.desired = source.edgecolour.desired;
85 edgeState = source.edgeState;
86 caretWidth = source.caretWidth;
87 leftMarginWidth = source.leftMarginWidth;
88 rightMarginWidth = source.rightMarginWidth;
89 for (int i=0;i < margins; i++) {
90 ms[i] = source.ms[i];
91 }
92 symbolMargin = source.symbolMargin;
93 maskInLine = source.maskInLine;
94 fixedColumnWidth = source.fixedColumnWidth;
95 zoomLevel = source.zoomLevel;
96 viewWhitespace = source.viewWhitespace;
97 viewIndentationGuides = source.viewIndentationGuides;
98 viewEOL = source.viewEOL;
99 showMarkedLines = source.showMarkedLines;
100 }
101
102 ViewStyle::~ViewStyle() {
103 }
104
105 void ViewStyle::Init() {
106 fontNames.Clear();
107 ResetDefaultStyle();
108
109 indicators[0].style = INDIC_SQUIGGLE;
110 indicators[0].fore = ColourDesired(0, 0x7f, 0);
111 indicators[1].style = INDIC_TT;
112 indicators[1].fore = ColourDesired(0, 0, 0xff);
113 indicators[2].style = INDIC_PLAIN;
114 indicators[2].fore = ColourDesired(0xff, 0, 0);
115
116 lineHeight = 1;
117 maxAscent = 1;
118 maxDescent = 1;
119 aveCharWidth = 8;
120 spaceWidth = 8;
121
122 selforeset = false;
123 selforeground.desired = ColourDesired(0xff, 0, 0);
124 selbackset = true;
125 selbackground.desired = ColourDesired(0xc0, 0xc0, 0xc0);
126 selbackground2.desired = ColourDesired(0xb0, 0xb0, 0xb0);
127 whitespaceForegroundSet = false;
128 whitespaceForeground.desired = ColourDesired(0, 0, 0);
129 whitespaceBackgroundSet = false;
130 whitespaceBackground.desired = ColourDesired(0xff, 0xff, 0xff);
131 selbar.desired = Platform::Chrome();
132 selbarlight.desired = Platform::ChromeHighlight();
133 styles[STYLE_LINENUMBER].fore.desired = ColourDesired(0, 0, 0);
134 styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
135 caretcolour.desired = ColourDesired(0, 0, 0);
136 showCaretLineBackground = false;
137 caretLineBackground.desired = ColourDesired(0xff, 0xff, 0);
138 edgecolour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
139 edgeState = EDGE_NONE;
140 caretWidth = 1;
141
142 leftMarginWidth = 1;
143 rightMarginWidth = 1;
144 ms[0].symbol = false;
145 ms[0].width = 0;
146 ms[0].mask = 0;
147 ms[1].symbol = true;
148 ms[1].width = 16;
149 ms[1].mask = ~SC_MASK_FOLDERS;
150 ms[2].symbol = true;
151 ms[2].width = 14; // Nice width for arrows
152 ms[2].mask = SC_MASK_FOLDERS;
153 ms[2].width = 0; // Nice width for arrows
154 ms[2].mask = 0;
155 fixedColumnWidth = leftMarginWidth;
156 symbolMargin = false;
157 maskInLine = 0xffffffff;
158 for (int margin=0; margin < margins; margin++) {
159 fixedColumnWidth += ms[margin].width;
160 symbolMargin = symbolMargin || ms[margin].symbol;
161 if (ms[margin].width > 0)
162 maskInLine &= ~ms[margin].mask;
163 }
164 zoomLevel = 0;
165 viewWhitespace = wsInvisible;
166 viewIndentationGuides = false;
167 viewEOL = false;
168 showMarkedLines = true;
169 }
170
171 void ViewStyle::RefreshColourPalette(Palette &pal, bool want) {
172 unsigned int i;
173 for (i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
174 pal.WantFind(styles[i].fore, want);
175 pal.WantFind(styles[i].back, want);
176 }
177 for (i=0;i<(sizeof(indicators)/sizeof(indicators[0]));i++) {
178 pal.WantFind(indicators[i].fore, want);
179 }
180 for (i=0;i<(sizeof(markers)/sizeof(markers[0]));i++) {
181 pal.WantFind(markers[i].fore, want);
182 pal.WantFind(markers[i].back, want);
183 }
184 pal.WantFind(selforeground, want);
185 pal.WantFind(selbackground, want);
186 pal.WantFind(selbackground2, want);
187 pal.WantFind(whitespaceForeground, want);
188 pal.WantFind(whitespaceBackground, want);
189 pal.WantFind(selbar, want);
190 pal.WantFind(selbarlight, want);
191 pal.WantFind(caretcolour, want);
192 pal.WantFind(caretLineBackground, want);
193 pal.WantFind(edgecolour, want);
194 }
195
196 void ViewStyle::Refresh(Surface &surface) {
197 selbar.desired = Platform::Chrome();
198 selbarlight.desired = Platform::ChromeHighlight();
199 styles[STYLE_DEFAULT].Realise(surface, zoomLevel);
200 maxAscent = styles[STYLE_DEFAULT].ascent;
201 maxDescent = styles[STYLE_DEFAULT].descent;
202 for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
203 if (i != STYLE_DEFAULT) {
204 styles[i].Realise(surface, zoomLevel, &styles[STYLE_DEFAULT]);
205 if (maxAscent < styles[i].ascent)
206 maxAscent = styles[i].ascent;
207 if (maxDescent < styles[i].descent)
208 maxDescent = styles[i].descent;
209 }
210 }
211
212 lineHeight = maxAscent + maxDescent;
213 aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth;
214 spaceWidth = styles[STYLE_DEFAULT].spaceWidth;
215
216 fixedColumnWidth = leftMarginWidth;
217 symbolMargin = false;
218 maskInLine = 0xffffffff;
219 for (int margin=0; margin < margins; margin++) {
220 fixedColumnWidth += ms[margin].width;
221 symbolMargin = symbolMargin || ms[margin].symbol;
222 if (ms[margin].width > 0)
223 maskInLine &= ~ms[margin].mask;
224 }
225 }
226
227 void ViewStyle::ResetDefaultStyle() {
228 styles[STYLE_DEFAULT].Clear(ColourDesired(0,0,0),
229 ColourDesired(0xff,0xff,0xff),
230 Platform::DefaultFontSize(), fontNames.Save(Platform::DefaultFont()),
231 SC_CHARSET_DEFAULT,
232 false, false, false, false, Style::caseMixed, true, true);
233 }
234
235 void ViewStyle::ClearStyles() {
236 // Reset all styles to be like the default style
237 for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
238 if (i != STYLE_DEFAULT) {
239 styles[i].ClearTo(styles[STYLE_DEFAULT]);
240 }
241 }
242 styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
243 }
244
245 void ViewStyle::SetStyleFontName(int styleIndex, const char *name) {
246 styles[styleIndex].fontName = fontNames.Save(name);
247 }