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
;
87 hotspotSingleLine
= source
.hotspotSingleLine
;
89 whitespaceForegroundSet
= source
.whitespaceForegroundSet
;
90 whitespaceForeground
.desired
= source
.whitespaceForeground
.desired
;
91 whitespaceBackgroundSet
= source
.whitespaceBackgroundSet
;
92 whitespaceBackground
.desired
= source
.whitespaceBackground
.desired
;
93 selbar
.desired
= source
.selbar
.desired
;
94 selbarlight
.desired
= source
.selbarlight
.desired
;
95 caretcolour
.desired
= source
.caretcolour
.desired
;
96 showCaretLineBackground
= source
.showCaretLineBackground
;
97 caretLineBackground
.desired
= source
.caretLineBackground
.desired
;
98 edgecolour
.desired
= source
.edgecolour
.desired
;
99 edgeState
= source
.edgeState
;
100 caretWidth
= source
.caretWidth
;
101 leftMarginWidth
= source
.leftMarginWidth
;
102 rightMarginWidth
= source
.rightMarginWidth
;
103 for (int i
=0;i
< margins
; i
++) {
104 ms
[i
] = source
.ms
[i
];
106 symbolMargin
= source
.symbolMargin
;
107 maskInLine
= source
.maskInLine
;
108 fixedColumnWidth
= source
.fixedColumnWidth
;
109 zoomLevel
= source
.zoomLevel
;
110 viewWhitespace
= source
.viewWhitespace
;
111 viewIndentationGuides
= source
.viewIndentationGuides
;
112 viewEOL
= source
.viewEOL
;
113 showMarkedLines
= source
.showMarkedLines
;
116 ViewStyle::~ViewStyle() {
119 void ViewStyle::Init() {
123 indicators
[0].style
= INDIC_SQUIGGLE
;
124 indicators
[0].fore
= ColourDesired(0, 0x7f, 0);
125 indicators
[1].style
= INDIC_TT
;
126 indicators
[1].fore
= ColourDesired(0, 0, 0xff);
127 indicators
[2].style
= INDIC_PLAIN
;
128 indicators
[2].fore
= ColourDesired(0xff, 0, 0);
137 selforeground
.desired
= ColourDesired(0xff, 0, 0);
139 selbackground
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
140 selbackground2
.desired
= ColourDesired(0xb0, 0xb0, 0xb0);
142 foldmarginColourSet
= false;
143 foldmarginColour
.desired
= ColourDesired(0xff, 0, 0);
144 foldmarginHighlightColourSet
= false;
145 foldmarginHighlightColour
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
147 whitespaceForegroundSet
= false;
148 whitespaceForeground
.desired
= ColourDesired(0, 0, 0);
149 whitespaceBackgroundSet
= false;
150 whitespaceBackground
.desired
= ColourDesired(0xff, 0xff, 0xff);
151 selbar
.desired
= Platform::Chrome();
152 selbarlight
.desired
= Platform::ChromeHighlight();
153 styles
[STYLE_LINENUMBER
].fore
.desired
= ColourDesired(0, 0, 0);
154 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
155 caretcolour
.desired
= ColourDesired(0, 0, 0);
156 showCaretLineBackground
= false;
157 caretLineBackground
.desired
= ColourDesired(0xff, 0xff, 0);
158 edgecolour
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
159 edgeState
= EDGE_NONE
;
161 someStylesProtected
= false;
163 hotspotForegroundSet
= false;
164 hotspotForeground
.desired
= ColourDesired(0, 0, 0xff);
165 hotspotBackgroundSet
= false;
166 hotspotBackground
.desired
= ColourDesired(0xff, 0xff, 0xff);
167 hotspotUnderline
= true;
168 hotspotSingleLine
= true;
171 rightMarginWidth
= 1;
172 ms
[0].symbol
= false;
177 ms
[1].mask
= ~SC_MASK_FOLDERS
;
181 fixedColumnWidth
= leftMarginWidth
;
182 symbolMargin
= false;
183 maskInLine
= 0xffffffff;
184 for (int margin
=0; margin
< margins
; margin
++) {
185 fixedColumnWidth
+= ms
[margin
].width
;
186 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
187 if (ms
[margin
].width
> 0)
188 maskInLine
&= ~ms
[margin
].mask
;
191 viewWhitespace
= wsInvisible
;
192 viewIndentationGuides
= false;
194 showMarkedLines
= true;
197 void ViewStyle::RefreshColourPalette(Palette
&pal
, bool want
) {
199 for (i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
200 pal
.WantFind(styles
[i
].fore
, want
);
201 pal
.WantFind(styles
[i
].back
, want
);
203 for (i
=0;i
<(sizeof(indicators
)/sizeof(indicators
[0]));i
++) {
204 pal
.WantFind(indicators
[i
].fore
, want
);
206 for (i
=0;i
<(sizeof(markers
)/sizeof(markers
[0]));i
++) {
207 markers
[i
].RefreshColourPalette(pal
, want
);
209 pal
.WantFind(selforeground
, want
);
210 pal
.WantFind(selbackground
, want
);
211 pal
.WantFind(selbackground2
, want
);
213 pal
.WantFind(foldmarginColour
, want
);
214 pal
.WantFind(foldmarginHighlightColour
, want
);
216 pal
.WantFind(whitespaceForeground
, want
);
217 pal
.WantFind(whitespaceBackground
, want
);
218 pal
.WantFind(selbar
, want
);
219 pal
.WantFind(selbarlight
, want
);
220 pal
.WantFind(caretcolour
, want
);
221 pal
.WantFind(caretLineBackground
, want
);
222 pal
.WantFind(edgecolour
, want
);
223 pal
.WantFind(hotspotForeground
, want
);
224 pal
.WantFind(hotspotBackground
, want
);
227 void ViewStyle::Refresh(Surface
&surface
) {
228 selbar
.desired
= Platform::Chrome();
229 selbarlight
.desired
= Platform::ChromeHighlight();
230 styles
[STYLE_DEFAULT
].Realise(surface
, zoomLevel
);
231 maxAscent
= styles
[STYLE_DEFAULT
].ascent
;
232 maxDescent
= styles
[STYLE_DEFAULT
].descent
;
233 someStylesProtected
= false;
234 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
235 if (i
!= STYLE_DEFAULT
) {
236 styles
[i
].Realise(surface
, zoomLevel
, &styles
[STYLE_DEFAULT
]);
237 if (maxAscent
< styles
[i
].ascent
)
238 maxAscent
= styles
[i
].ascent
;
239 if (maxDescent
< styles
[i
].descent
)
240 maxDescent
= styles
[i
].descent
;
242 if (styles
[i
].IsProtected()) {
243 someStylesProtected
= true;
247 lineHeight
= maxAscent
+ maxDescent
;
248 aveCharWidth
= styles
[STYLE_DEFAULT
].aveCharWidth
;
249 spaceWidth
= styles
[STYLE_DEFAULT
].spaceWidth
;
251 fixedColumnWidth
= leftMarginWidth
;
252 symbolMargin
= false;
253 maskInLine
= 0xffffffff;
254 for (int margin
=0; margin
< margins
; margin
++) {
255 fixedColumnWidth
+= ms
[margin
].width
;
256 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
257 if (ms
[margin
].width
> 0)
258 maskInLine
&= ~ms
[margin
].mask
;
262 void ViewStyle::ResetDefaultStyle() {
263 styles
[STYLE_DEFAULT
].Clear(ColourDesired(0,0,0),
264 ColourDesired(0xff,0xff,0xff),
265 Platform::DefaultFontSize(), fontNames
.Save(Platform::DefaultFont()),
267 false, false, false, false, Style::caseMixed
, true, true, false);
270 void ViewStyle::ClearStyles() {
271 // Reset all styles to be like the default style
272 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
273 if (i
!= STYLE_DEFAULT
) {
274 styles
[i
].ClearTo(styles
[STYLE_DEFAULT
]);
277 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
280 void ViewStyle::SetStyleFontName(int styleIndex
, const char *name
) {
281 styles
[styleIndex
].fontName
= fontNames
.Save(name
);
284 bool ViewStyle::ProtectionActive() const {
285 return someStylesProtected
;