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