]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/ViewStyle.cxx
This form of the event cloning patch survived my
[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 selbar.desired = source.selbar.desired;
76 selbarlight.desired = source.selbarlight.desired;
77 caretcolour.desired = source.caretcolour.desired;
78 showCaretLineBackground = source.showCaretLineBackground;
79 caretLineBackground.desired = source.caretLineBackground.desired;
80 edgecolour.desired = source.edgecolour.desired;
81 edgeState = source.edgeState;
82 caretWidth = source.caretWidth;
83 leftMarginWidth = source.leftMarginWidth;
84 rightMarginWidth = source.rightMarginWidth;
85 for (int i=0;i < margins; i++) {
86 ms[i] = source.ms[i];
87 }
88 symbolMargin = source.symbolMargin;
89 maskInLine = source.maskInLine;
90 fixedColumnWidth = source.fixedColumnWidth;
91 zoomLevel = source.zoomLevel;
92 viewWhitespace = source.viewWhitespace;
93 viewIndentationGuides = source.viewIndentationGuides;
94 viewEOL = source.viewEOL;
95 showMarkedLines = source.showMarkedLines;
96 }
97
98 ViewStyle::~ViewStyle() {
99 }
100
101 void ViewStyle::Init() {
102 fontNames.Clear();
103 ResetDefaultStyle();
104
105 indicators[0].style = INDIC_SQUIGGLE;
106 indicators[0].fore = Colour(0, 0x7f, 0);
107 indicators[1].style = INDIC_TT;
108 indicators[1].fore = Colour(0, 0, 0xff);
109 indicators[2].style = INDIC_PLAIN;
110 indicators[2].fore = Colour(0xff, 0, 0);
111
112 lineHeight = 1;
113 maxAscent = 1;
114 maxDescent = 1;
115 aveCharWidth = 8;
116 spaceWidth = 8;
117
118 selforeset = false;
119 selforeground.desired = Colour(0xff, 0, 0);
120 selbackset = true;
121 selbackground.desired = Colour(0xc0, 0xc0, 0xc0);
122 selbackground2.desired = Colour(0xb0, 0xb0, 0xb0);
123 selbar.desired = Platform::Chrome();
124 selbarlight.desired = Platform::ChromeHighlight();
125 styles[STYLE_LINENUMBER].fore.desired = Colour(0, 0, 0);
126 styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
127 caretcolour.desired = Colour(0, 0, 0);
128 showCaretLineBackground = false;
129 caretLineBackground.desired = Colour(0xff, 0xff, 0);
130 edgecolour.desired = Colour(0xc0, 0xc0, 0xc0);
131 edgeState = EDGE_NONE;
132 caretWidth = 1;
133
134 leftMarginWidth = 1;
135 rightMarginWidth = 1;
136 ms[0].symbol = false;
137 ms[0].width = 0;
138 ms[0].mask = 0;
139 ms[1].symbol = true;
140 ms[1].width = 16;
141 ms[1].mask = ~SC_MASK_FOLDERS;
142 ms[2].symbol = true;
143 ms[2].width = 14; // Nice width for arrows
144 ms[2].mask = SC_MASK_FOLDERS;
145 ms[2].width = 0; // Nice width for arrows
146 ms[2].mask = 0;
147 fixedColumnWidth = leftMarginWidth;
148 symbolMargin = false;
149 maskInLine = 0xffffffff;
150 for (int margin=0; margin < margins; margin++) {
151 fixedColumnWidth += ms[margin].width;
152 symbolMargin = symbolMargin || ms[margin].symbol;
153 if (ms[margin].width > 0)
154 maskInLine &= ~ms[margin].mask;
155 }
156 zoomLevel = 0;
157 viewWhitespace = wsInvisible;
158 viewIndentationGuides = false;
159 viewEOL = false;
160 showMarkedLines = true;
161 }
162
163 void ViewStyle::RefreshColourPalette(Palette &pal, bool want) {
164 unsigned int i;
165 for (i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
166 pal.WantFind(styles[i].fore, want);
167 pal.WantFind(styles[i].back, want);
168 }
169 for (i=0;i<(sizeof(indicators)/sizeof(indicators[0]));i++) {
170 pal.WantFind(indicators[i].fore, want);
171 }
172 for (i=0;i<(sizeof(markers)/sizeof(markers[0]));i++) {
173 pal.WantFind(markers[i].fore, want);
174 pal.WantFind(markers[i].back, want);
175 }
176 pal.WantFind(selforeground, want);
177 pal.WantFind(selbackground, want);
178 pal.WantFind(selbackground2, want);
179 pal.WantFind(selbar, want);
180 pal.WantFind(selbarlight, want);
181 pal.WantFind(caretcolour, want);
182 pal.WantFind(caretLineBackground, want);
183 pal.WantFind(edgecolour, want);
184 }
185
186 void ViewStyle::Refresh(Surface &surface) {
187 selbar.desired = Platform::Chrome();
188 selbarlight.desired = Platform::ChromeHighlight();
189 styles[STYLE_DEFAULT].Realise(surface, zoomLevel);
190 maxAscent = styles[STYLE_DEFAULT].ascent;
191 maxDescent = styles[STYLE_DEFAULT].descent;
192 for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
193 if (i != STYLE_DEFAULT) {
194 styles[i].Realise(surface, zoomLevel, &styles[STYLE_DEFAULT]);
195 if (maxAscent < styles[i].ascent)
196 maxAscent = styles[i].ascent;
197 if (maxDescent < styles[i].descent)
198 maxDescent = styles[i].descent;
199 }
200 }
201
202 lineHeight = maxAscent + maxDescent;
203 aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth;
204 spaceWidth = styles[STYLE_DEFAULT].spaceWidth;
205
206 fixedColumnWidth = leftMarginWidth;
207 symbolMargin = false;
208 maskInLine = 0xffffffff;
209 for (int margin=0; margin < margins; margin++) {
210 fixedColumnWidth += ms[margin].width;
211 symbolMargin = symbolMargin || ms[margin].symbol;
212 if (ms[margin].width > 0)
213 maskInLine &= ~ms[margin].mask;
214 }
215 }
216
217 void ViewStyle::ResetDefaultStyle() {
218 styles[STYLE_DEFAULT].Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
219 Platform::DefaultFontSize(), fontNames.Save(Platform::DefaultFont()),
220 SC_CHARSET_DEFAULT,
221 false, false, false, false, Style::caseMixed, true);
222 }
223
224 void ViewStyle::ClearStyles() {
225 // Reset all styles to be like the default style
226 for (unsigned int i=0;i<(sizeof(styles)/sizeof(styles[0]));i++) {
227 if (i != STYLE_DEFAULT) {
228 styles[i].ClearTo(styles[STYLE_DEFAULT]);
229 }
230 }
231 styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
232 }
233
234 void ViewStyle::SetStyleFontName(int styleIndex, const char *name) {
235 styles[styleIndex].fontName = fontNames.Save(name);
236 }