1 // Scintilla source code edit control
\r
2 /** @file ViewStyle.cxx
\r
3 ** Store information on how the document is to be viewed.
\r
5 // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
\r
6 // The License.txt file describes the conditions under which this software may be distributed.
\r
10 #include "Platform.h"
\r
12 #include "Scintilla.h"
\r
13 #include "SplitVector.h"
\r
14 #include "Partitioning.h"
\r
15 #include "RunStyles.h"
\r
16 #include "Indicator.h"
\r
18 #include "LineMarker.h"
\r
20 #include "ViewStyle.h"
\r
22 #ifdef SCI_NAMESPACE
\r
23 using namespace Scintilla;
\r
26 MarginStyle::MarginStyle() :
\r
27 style(SC_MARGIN_SYMBOL), width(0), mask(0), sensitive(false) {
\r
30 // A list of the fontnames - avoids wasting space in each style
\r
31 FontNames::FontNames() {
\r
33 names = new char *[size];
\r
37 FontNames::~FontNames() {
\r
43 void FontNames::Clear() {
\r
44 for (int i=0;i<max;i++) {
\r
50 const char *FontNames::Save(const char *name) {
\r
53 for (int i=0;i<max;i++) {
\r
54 if (strcmp(names[i], name) == 0) {
\r
60 int sizeNew = size * 2;
\r
61 char **namesNew = new char *[sizeNew];
\r
62 for (int j=0;j<max;j++) {
\r
63 namesNew[j] = names[j];
\r
69 names[max] = new char[strlen(name) + 1];
\r
70 strcpy(names[max], name);
\r
72 return names[max-1];
\r
75 ViewStyle::ViewStyle() {
\r
79 ViewStyle::ViewStyle(const ViewStyle &source) {
\r
80 Init(source.stylesSize);
\r
81 for (unsigned int sty=0;sty<source.stylesSize;sty++) {
\r
82 styles[sty] = source.styles[sty];
\r
83 // Can't just copy fontname as its lifetime is relative to its owning ViewStyle
\r
84 styles[sty].fontName = fontNames.Save(source.styles[sty].fontName);
\r
86 for (int mrk=0;mrk<=MARKER_MAX;mrk++) {
\r
87 markers[mrk] = source.markers[mrk];
\r
89 for (int ind=0;ind<=INDIC_MAX;ind++) {
\r
90 indicators[ind] = source.indicators[ind];
\r
93 selforeset = source.selforeset;
\r
94 selforeground.desired = source.selforeground.desired;
\r
95 selbackset = source.selbackset;
\r
96 selbackground.desired = source.selbackground.desired;
\r
97 selbackground2.desired = source.selbackground2.desired;
\r
98 selAlpha = source.selAlpha;
\r
99 selEOLFilled = source.selEOLFilled;
\r
101 foldmarginColourSet = source.foldmarginColourSet;
\r
102 foldmarginColour.desired = source.foldmarginColour.desired;
\r
103 foldmarginHighlightColourSet = source.foldmarginHighlightColourSet;
\r
104 foldmarginHighlightColour.desired = source.foldmarginHighlightColour.desired;
\r
106 hotspotForegroundSet = source.hotspotForegroundSet;
\r
107 hotspotForeground.desired = source.hotspotForeground.desired;
\r
108 hotspotBackgroundSet = source.hotspotBackgroundSet;
\r
109 hotspotBackground.desired = source.hotspotBackground.desired;
\r
110 hotspotUnderline = source.hotspotUnderline;
\r
111 hotspotSingleLine = source.hotspotSingleLine;
\r
113 whitespaceForegroundSet = source.whitespaceForegroundSet;
\r
114 whitespaceForeground.desired = source.whitespaceForeground.desired;
\r
115 whitespaceBackgroundSet = source.whitespaceBackgroundSet;
\r
116 whitespaceBackground.desired = source.whitespaceBackground.desired;
\r
117 selbar.desired = source.selbar.desired;
\r
118 selbarlight.desired = source.selbarlight.desired;
\r
119 caretcolour.desired = source.caretcolour.desired;
\r
120 showCaretLineBackground = source.showCaretLineBackground;
\r
121 caretLineBackground.desired = source.caretLineBackground.desired;
\r
122 caretLineAlpha = source.caretLineAlpha;
\r
123 edgecolour.desired = source.edgecolour.desired;
\r
124 edgeState = source.edgeState;
\r
125 caretStyle = source.caretStyle;
\r
126 caretWidth = source.caretWidth;
\r
127 someStylesProtected = false;
\r
128 leftMarginWidth = source.leftMarginWidth;
\r
129 rightMarginWidth = source.rightMarginWidth;
\r
130 for (int i=0;i < margins; i++) {
\r
131 ms[i] = source.ms[i];
\r
133 symbolMargin = source.symbolMargin;
\r
134 maskInLine = source.maskInLine;
\r
135 fixedColumnWidth = source.fixedColumnWidth;
\r
136 zoomLevel = source.zoomLevel;
\r
137 viewWhitespace = source.viewWhitespace;
\r
138 viewIndentationGuides = source.viewIndentationGuides;
\r
139 viewEOL = source.viewEOL;
\r
140 showMarkedLines = source.showMarkedLines;
\r
141 extraFontFlag = source.extraFontFlag;
\r
144 ViewStyle::~ViewStyle() {
\r
149 void ViewStyle::Init(size_t stylesSize_) {
\r
152 AllocStyles(stylesSize_);
\r
154 ResetDefaultStyle();
\r
156 indicators[0].style = INDIC_SQUIGGLE;
\r
157 indicators[0].under = false;
\r
158 indicators[0].fore = ColourDesired(0, 0x7f, 0);
\r
159 indicators[1].style = INDIC_TT;
\r
160 indicators[1].under = false;
\r
161 indicators[1].fore = ColourDesired(0, 0, 0xff);
\r
162 indicators[2].style = INDIC_PLAIN;
\r
163 indicators[2].under = false;
\r
164 indicators[2].fore = ColourDesired(0xff, 0, 0);
\r
172 selforeset = false;
\r
173 selforeground.desired = ColourDesired(0xff, 0, 0);
\r
175 selbackground.desired = ColourDesired(0xc0, 0xc0, 0xc0);
\r
176 selbackground2.desired = ColourDesired(0xb0, 0xb0, 0xb0);
\r
177 selAlpha = SC_ALPHA_NOALPHA;
\r
178 selEOLFilled = false;
\r
180 foldmarginColourSet = false;
\r
181 foldmarginColour.desired = ColourDesired(0xff, 0, 0);
\r
182 foldmarginHighlightColourSet = false;
\r
183 foldmarginHighlightColour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
\r
185 whitespaceForegroundSet = false;
\r
186 whitespaceForeground.desired = ColourDesired(0, 0, 0);
\r
187 whitespaceBackgroundSet = false;
\r
188 whitespaceBackground.desired = ColourDesired(0xff, 0xff, 0xff);
\r
189 selbar.desired = Platform::Chrome();
\r
190 selbarlight.desired = Platform::ChromeHighlight();
\r
191 styles[STYLE_LINENUMBER].fore.desired = ColourDesired(0, 0, 0);
\r
192 styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
\r
193 caretcolour.desired = ColourDesired(0, 0, 0);
\r
194 showCaretLineBackground = false;
\r
195 caretLineBackground.desired = ColourDesired(0xff, 0xff, 0);
\r
196 caretLineAlpha = SC_ALPHA_NOALPHA;
\r
197 edgecolour.desired = ColourDesired(0xc0, 0xc0, 0xc0);
\r
198 edgeState = EDGE_NONE;
\r
199 caretStyle = CARETSTYLE_LINE;
\r
201 someStylesProtected = false;
\r
203 hotspotForegroundSet = false;
\r
204 hotspotForeground.desired = ColourDesired(0, 0, 0xff);
\r
205 hotspotBackgroundSet = false;
\r
206 hotspotBackground.desired = ColourDesired(0xff, 0xff, 0xff);
\r
207 hotspotUnderline = true;
\r
208 hotspotSingleLine = true;
\r
210 leftMarginWidth = 1;
\r
211 rightMarginWidth = 1;
\r
212 ms[0].style = SC_MARGIN_NUMBER;
\r
215 ms[1].style = SC_MARGIN_SYMBOL;
\r
217 ms[1].mask = ~SC_MASK_FOLDERS;
\r
218 ms[2].style = SC_MARGIN_SYMBOL;
\r
221 fixedColumnWidth = leftMarginWidth;
\r
222 symbolMargin = false;
\r
223 maskInLine = 0xffffffff;
\r
224 for (int margin=0; margin < margins; margin++) {
\r
225 fixedColumnWidth += ms[margin].width;
\r
226 symbolMargin = symbolMargin || (ms[margin].style != SC_MARGIN_NUMBER);
\r
227 if (ms[margin].width > 0)
\r
228 maskInLine &= ~ms[margin].mask;
\r
231 viewWhitespace = wsInvisible;
\r
232 viewIndentationGuides = ivNone;
\r
234 showMarkedLines = true;
\r
235 extraFontFlag = false;
\r
238 void ViewStyle::RefreshColourPalette(Palette &pal, bool want) {
\r
240 for (i=0;i<stylesSize;i++) {
\r
241 pal.WantFind(styles[i].fore, want);
\r
242 pal.WantFind(styles[i].back, want);
\r
244 for (i=0;i<(sizeof(indicators)/sizeof(indicators[0]));i++) {
\r
245 pal.WantFind(indicators[i].fore, want);
\r
247 for (i=0;i<(sizeof(markers)/sizeof(markers[0]));i++) {
\r
248 markers[i].RefreshColourPalette(pal, want);
\r
250 pal.WantFind(selforeground, want);
\r
251 pal.WantFind(selbackground, want);
\r
252 pal.WantFind(selbackground2, want);
\r
254 pal.WantFind(foldmarginColour, want);
\r
255 pal.WantFind(foldmarginHighlightColour, want);
\r
257 pal.WantFind(whitespaceForeground, want);
\r
258 pal.WantFind(whitespaceBackground, want);
\r
259 pal.WantFind(selbar, want);
\r
260 pal.WantFind(selbarlight, want);
\r
261 pal.WantFind(caretcolour, want);
\r
262 pal.WantFind(caretLineBackground, want);
\r
263 pal.WantFind(edgecolour, want);
\r
264 pal.WantFind(hotspotForeground, want);
\r
265 pal.WantFind(hotspotBackground, want);
\r
268 void ViewStyle::Refresh(Surface &surface) {
\r
269 selbar.desired = Platform::Chrome();
\r
270 selbarlight.desired = Platform::ChromeHighlight();
\r
271 styles[STYLE_DEFAULT].Realise(surface, zoomLevel, NULL, extraFontFlag);
\r
272 maxAscent = styles[STYLE_DEFAULT].ascent;
\r
273 maxDescent = styles[STYLE_DEFAULT].descent;
\r
274 someStylesProtected = false;
\r
275 for (unsigned int i=0; i<stylesSize; i++) {
\r
276 if (i != STYLE_DEFAULT) {
\r
277 styles[i].Realise(surface, zoomLevel, &styles[STYLE_DEFAULT], extraFontFlag);
\r
278 if (maxAscent < styles[i].ascent)
\r
279 maxAscent = styles[i].ascent;
\r
280 if (maxDescent < styles[i].descent)
\r
281 maxDescent = styles[i].descent;
\r
283 if (styles[i].IsProtected()) {
\r
284 someStylesProtected = true;
\r
288 lineHeight = maxAscent + maxDescent;
\r
289 aveCharWidth = styles[STYLE_DEFAULT].aveCharWidth;
\r
290 spaceWidth = styles[STYLE_DEFAULT].spaceWidth;
\r
292 fixedColumnWidth = leftMarginWidth;
\r
293 symbolMargin = false;
\r
294 maskInLine = 0xffffffff;
\r
295 for (int margin=0; margin < margins; margin++) {
\r
296 fixedColumnWidth += ms[margin].width;
\r
297 symbolMargin = symbolMargin || (ms[margin].style != SC_MARGIN_NUMBER);
\r
298 if (ms[margin].width > 0)
\r
299 maskInLine &= ~ms[margin].mask;
\r
303 void ViewStyle::AllocStyles(size_t sizeNew) {
\r
304 Style *stylesNew = new Style[sizeNew];
\r
306 for (; i<stylesSize; i++) {
\r
307 stylesNew[i] = styles[i];
\r
308 stylesNew[i].fontName = styles[i].fontName;
\r
310 if (stylesSize > STYLE_DEFAULT) {
\r
311 for (; i<sizeNew; i++) {
\r
312 if (i != STYLE_DEFAULT) {
\r
313 stylesNew[i].ClearTo(styles[STYLE_DEFAULT]);
\r
318 styles = stylesNew;
\r
319 stylesSize = sizeNew;
\r
322 void ViewStyle::EnsureStyle(size_t index) {
\r
323 if (index >= stylesSize) {
\r
324 size_t sizeNew = stylesSize * 2;
\r
325 while (sizeNew < index)
\r
327 AllocStyles(sizeNew);
\r
331 void ViewStyle::ResetDefaultStyle() {
\r
332 styles[STYLE_DEFAULT].Clear(ColourDesired(0,0,0),
\r
333 ColourDesired(0xff,0xff,0xff),
\r
334 Platform::DefaultFontSize(), fontNames.Save(Platform::DefaultFont()),
\r
335 SC_CHARSET_DEFAULT,
\r
336 false, false, false, false, Style::caseMixed, true, true, false);
\r
339 void ViewStyle::ClearStyles() {
\r
340 // Reset all styles to be like the default style
\r
341 for (unsigned int i=0; i<stylesSize; i++) {
\r
342 if (i != STYLE_DEFAULT) {
\r
343 styles[i].ClearTo(styles[STYLE_DEFAULT]);
\r
346 styles[STYLE_LINENUMBER].back.desired = Platform::Chrome();
\r
348 // Set call tip fore/back to match the values previously set for call tips
\r
349 styles[STYLE_CALLTIP].back.desired = ColourDesired(0xff, 0xff, 0xff);
\r
350 styles[STYLE_CALLTIP].fore.desired = ColourDesired(0x80, 0x80, 0x80);
\r
353 void ViewStyle::SetStyleFontName(int styleIndex, const char *name) {
\r
354 styles[styleIndex].fontName = fontNames.Save(name);
\r
357 bool ViewStyle::ProtectionActive() const {
\r
358 return someStylesProtected;
\r