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