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 "Indicator.h"
15 #include "LineMarker.h"
17 #include "ViewStyle.h"
19 MarginStyle::MarginStyle() :
20 symbol(false), width(16), mask(0xffffffff), sensitive(false) {
23 // A list of the fontnames - avoids wasting space in each style
24 FontNames::FontNames() {
28 FontNames::~FontNames() {
32 void FontNames::Clear() {
33 for (int i
=0;i
<max
;i
++) {
39 const char *FontNames::Save(const char *name
) {
42 for (int i
=0;i
<max
;i
++) {
43 if (strcmp(names
[i
], name
) == 0) {
47 names
[max
] = new char[strlen(name
) + 1];
48 strcpy(names
[max
], name
);
53 ViewStyle::ViewStyle() {
57 ViewStyle::ViewStyle(const ViewStyle
&source
) {
59 for (unsigned int sty
=0;sty
<(sizeof(styles
)/sizeof(styles
[0]));sty
++) {
60 styles
[sty
] = source
.styles
[sty
];
61 // Can't just copy fontname as its lifetime is relative to its owning ViewStyle
62 styles
[sty
].fontName
= fontNames
.Save(source
.styles
[sty
].fontName
);
64 for (int mrk
=0;mrk
<=MARKER_MAX
;mrk
++) {
65 markers
[mrk
] = source
.markers
[mrk
];
67 for (int ind
=0;ind
<=INDIC_MAX
;ind
++) {
68 indicators
[ind
] = source
.indicators
[ind
];
71 selforeset
= source
.selforeset
;
72 selforeground
.desired
= source
.selforeground
.desired
;
73 selbackset
= source
.selbackset
;
74 selbackground
.desired
= source
.selbackground
.desired
;
75 selbackground2
.desired
= source
.selbackground2
.desired
;
77 foldmarginColourSet
= source
.foldmarginColourSet
;
78 foldmarginColour
.desired
= source
.foldmarginColour
.desired
;
79 foldmarginHighlightColourSet
= source
.foldmarginHighlightColourSet
;
80 foldmarginHighlightColour
.desired
= source
.foldmarginHighlightColour
.desired
;
82 hotspotForegroundSet
= source
.hotspotForegroundSet
;
83 hotspotForeground
.desired
= source
.hotspotForeground
.desired
;
84 hotspotBackgroundSet
= source
.hotspotBackgroundSet
;
85 hotspotBackground
.desired
= source
.hotspotBackground
.desired
;
86 hotspotUnderline
= source
.hotspotUnderline
;
88 whitespaceForegroundSet
= source
.whitespaceForegroundSet
;
89 whitespaceForeground
.desired
= source
.whitespaceForeground
.desired
;
90 whitespaceBackgroundSet
= source
.whitespaceBackgroundSet
;
91 whitespaceBackground
.desired
= source
.whitespaceBackground
.desired
;
92 selbar
.desired
= source
.selbar
.desired
;
93 selbarlight
.desired
= source
.selbarlight
.desired
;
94 caretcolour
.desired
= source
.caretcolour
.desired
;
95 showCaretLineBackground
= source
.showCaretLineBackground
;
96 caretLineBackground
.desired
= source
.caretLineBackground
.desired
;
97 edgecolour
.desired
= source
.edgecolour
.desired
;
98 edgeState
= source
.edgeState
;
99 caretWidth
= source
.caretWidth
;
100 leftMarginWidth
= source
.leftMarginWidth
;
101 rightMarginWidth
= source
.rightMarginWidth
;
102 for (int i
=0;i
< margins
; i
++) {
103 ms
[i
] = source
.ms
[i
];
105 symbolMargin
= source
.symbolMargin
;
106 maskInLine
= source
.maskInLine
;
107 fixedColumnWidth
= source
.fixedColumnWidth
;
108 zoomLevel
= source
.zoomLevel
;
109 viewWhitespace
= source
.viewWhitespace
;
110 viewIndentationGuides
= source
.viewIndentationGuides
;
111 viewEOL
= source
.viewEOL
;
112 showMarkedLines
= source
.showMarkedLines
;
115 ViewStyle::~ViewStyle() {
118 void ViewStyle::Init() {
122 indicators
[0].style
= INDIC_SQUIGGLE
;
123 indicators
[0].fore
= ColourDesired(0, 0x7f, 0);
124 indicators
[1].style
= INDIC_TT
;
125 indicators
[1].fore
= ColourDesired(0, 0, 0xff);
126 indicators
[2].style
= INDIC_PLAIN
;
127 indicators
[2].fore
= ColourDesired(0xff, 0, 0);
136 selforeground
.desired
= ColourDesired(0xff, 0, 0);
138 selbackground
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
139 selbackground2
.desired
= ColourDesired(0xb0, 0xb0, 0xb0);
141 foldmarginColourSet
= false;
142 foldmarginColour
.desired
= ColourDesired(0xff, 0, 0);
143 foldmarginHighlightColourSet
= false;
144 foldmarginHighlightColour
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
146 whitespaceForegroundSet
= false;
147 whitespaceForeground
.desired
= ColourDesired(0, 0, 0);
148 whitespaceBackgroundSet
= false;
149 whitespaceBackground
.desired
= ColourDesired(0xff, 0xff, 0xff);
150 selbar
.desired
= Platform::Chrome();
151 selbarlight
.desired
= Platform::ChromeHighlight();
152 styles
[STYLE_LINENUMBER
].fore
.desired
= ColourDesired(0, 0, 0);
153 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
154 caretcolour
.desired
= ColourDesired(0, 0, 0);
155 showCaretLineBackground
= false;
156 caretLineBackground
.desired
= ColourDesired(0xff, 0xff, 0);
157 edgecolour
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
158 edgeState
= EDGE_NONE
;
160 someStylesProtected
= false;
162 hotspotForegroundSet
= false;
163 hotspotForeground
.desired
= ColourDesired(0, 0, 0xff);
164 hotspotBackgroundSet
= false;
165 hotspotBackground
.desired
= ColourDesired(0xff, 0xff, 0xff);
166 hotspotUnderline
= true;
169 rightMarginWidth
= 1;
170 ms
[0].symbol
= false;
175 ms
[1].mask
= ~SC_MASK_FOLDERS
;
179 fixedColumnWidth
= leftMarginWidth
;
180 symbolMargin
= false;
181 maskInLine
= 0xffffffff;
182 for (int margin
=0; margin
< margins
; margin
++) {
183 fixedColumnWidth
+= ms
[margin
].width
;
184 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
185 if (ms
[margin
].width
> 0)
186 maskInLine
&= ~ms
[margin
].mask
;
189 viewWhitespace
= wsInvisible
;
190 viewIndentationGuides
= false;
192 showMarkedLines
= true;
195 void ViewStyle::RefreshColourPalette(Palette
&pal
, bool want
) {
197 for (i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
198 pal
.WantFind(styles
[i
].fore
, want
);
199 pal
.WantFind(styles
[i
].back
, want
);
201 for (i
=0;i
<(sizeof(indicators
)/sizeof(indicators
[0]));i
++) {
202 pal
.WantFind(indicators
[i
].fore
, want
);
204 for (i
=0;i
<(sizeof(markers
)/sizeof(markers
[0]));i
++) {
205 markers
[i
].RefreshColourPalette(pal
, want
);
207 pal
.WantFind(selforeground
, want
);
208 pal
.WantFind(selbackground
, want
);
209 pal
.WantFind(selbackground2
, want
);
211 pal
.WantFind(foldmarginColour
, want
);
212 pal
.WantFind(foldmarginHighlightColour
, want
);
214 pal
.WantFind(whitespaceForeground
, want
);
215 pal
.WantFind(whitespaceBackground
, want
);
216 pal
.WantFind(selbar
, want
);
217 pal
.WantFind(selbarlight
, want
);
218 pal
.WantFind(caretcolour
, want
);
219 pal
.WantFind(caretLineBackground
, want
);
220 pal
.WantFind(edgecolour
, want
);
221 pal
.WantFind(hotspotForeground
, want
);
222 pal
.WantFind(hotspotBackground
, want
);
225 void ViewStyle::Refresh(Surface
&surface
) {
226 selbar
.desired
= Platform::Chrome();
227 selbarlight
.desired
= Platform::ChromeHighlight();
228 styles
[STYLE_DEFAULT
].Realise(surface
, zoomLevel
);
229 maxAscent
= styles
[STYLE_DEFAULT
].ascent
;
230 maxDescent
= styles
[STYLE_DEFAULT
].descent
;
231 someStylesProtected
= false;
232 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
233 if (i
!= STYLE_DEFAULT
) {
234 styles
[i
].Realise(surface
, zoomLevel
, &styles
[STYLE_DEFAULT
]);
235 if (maxAscent
< styles
[i
].ascent
)
236 maxAscent
= styles
[i
].ascent
;
237 if (maxDescent
< styles
[i
].descent
)
238 maxDescent
= styles
[i
].descent
;
240 if (styles
[i
].IsProtected()) {
241 someStylesProtected
= true;
245 lineHeight
= maxAscent
+ maxDescent
;
246 aveCharWidth
= styles
[STYLE_DEFAULT
].aveCharWidth
;
247 spaceWidth
= styles
[STYLE_DEFAULT
].spaceWidth
;
249 fixedColumnWidth
= leftMarginWidth
;
250 symbolMargin
= false;
251 maskInLine
= 0xffffffff;
252 for (int margin
=0; margin
< margins
; margin
++) {
253 fixedColumnWidth
+= ms
[margin
].width
;
254 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
255 if (ms
[margin
].width
> 0)
256 maskInLine
&= ~ms
[margin
].mask
;
260 void ViewStyle::ResetDefaultStyle() {
261 styles
[STYLE_DEFAULT
].Clear(ColourDesired(0,0,0),
262 ColourDesired(0xff,0xff,0xff),
263 Platform::DefaultFontSize(), fontNames
.Save(Platform::DefaultFont()),
265 false, false, false, false, Style::caseMixed
, true, true, false);
268 void ViewStyle::ClearStyles() {
269 // Reset all styles to be like the default style
270 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
271 if (i
!= STYLE_DEFAULT
) {
272 styles
[i
].ClearTo(styles
[STYLE_DEFAULT
]);
275 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
278 void ViewStyle::SetStyleFontName(int styleIndex
, const char *name
) {
279 styles
[styleIndex
].fontName
= fontNames
.Save(name
);
282 bool ViewStyle::ProtectionActive() const {
283 return someStylesProtected
;