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