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
;
114 extraFontFlag
= source
.extraFontFlag
;
117 ViewStyle::~ViewStyle() {
120 void ViewStyle::Init() {
124 indicators
[0].style
= INDIC_SQUIGGLE
;
125 indicators
[0].fore
= ColourDesired(0, 0x7f, 0);
126 indicators
[1].style
= INDIC_TT
;
127 indicators
[1].fore
= ColourDesired(0, 0, 0xff);
128 indicators
[2].style
= INDIC_PLAIN
;
129 indicators
[2].fore
= ColourDesired(0xff, 0, 0);
138 selforeground
.desired
= ColourDesired(0xff, 0, 0);
140 selbackground
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
141 selbackground2
.desired
= ColourDesired(0xb0, 0xb0, 0xb0);
143 foldmarginColourSet
= false;
144 foldmarginColour
.desired
= ColourDesired(0xff, 0, 0);
145 foldmarginHighlightColourSet
= false;
146 foldmarginHighlightColour
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
148 whitespaceForegroundSet
= false;
149 whitespaceForeground
.desired
= ColourDesired(0, 0, 0);
150 whitespaceBackgroundSet
= false;
151 whitespaceBackground
.desired
= ColourDesired(0xff, 0xff, 0xff);
152 selbar
.desired
= Platform::Chrome();
153 selbarlight
.desired
= Platform::ChromeHighlight();
154 styles
[STYLE_LINENUMBER
].fore
.desired
= ColourDesired(0, 0, 0);
155 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
156 caretcolour
.desired
= ColourDesired(0, 0, 0);
157 showCaretLineBackground
= false;
158 caretLineBackground
.desired
= ColourDesired(0xff, 0xff, 0);
159 edgecolour
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
160 edgeState
= EDGE_NONE
;
162 someStylesProtected
= false;
164 hotspotForegroundSet
= false;
165 hotspotForeground
.desired
= ColourDesired(0, 0, 0xff);
166 hotspotBackgroundSet
= false;
167 hotspotBackground
.desired
= ColourDesired(0xff, 0xff, 0xff);
168 hotspotUnderline
= true;
169 hotspotSingleLine
= true;
172 rightMarginWidth
= 1;
173 ms
[0].symbol
= false;
178 ms
[1].mask
= ~SC_MASK_FOLDERS
;
182 fixedColumnWidth
= leftMarginWidth
;
183 symbolMargin
= false;
184 maskInLine
= 0xffffffff;
185 for (int margin
=0; margin
< margins
; margin
++) {
186 fixedColumnWidth
+= ms
[margin
].width
;
187 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
188 if (ms
[margin
].width
> 0)
189 maskInLine
&= ~ms
[margin
].mask
;
192 viewWhitespace
= wsInvisible
;
193 viewIndentationGuides
= false;
195 showMarkedLines
= true;
196 extraFontFlag
= false;
199 void ViewStyle::RefreshColourPalette(Palette
&pal
, bool want
) {
201 for (i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
202 pal
.WantFind(styles
[i
].fore
, want
);
203 pal
.WantFind(styles
[i
].back
, want
);
205 for (i
=0;i
<(sizeof(indicators
)/sizeof(indicators
[0]));i
++) {
206 pal
.WantFind(indicators
[i
].fore
, want
);
208 for (i
=0;i
<(sizeof(markers
)/sizeof(markers
[0]));i
++) {
209 markers
[i
].RefreshColourPalette(pal
, want
);
211 pal
.WantFind(selforeground
, want
);
212 pal
.WantFind(selbackground
, want
);
213 pal
.WantFind(selbackground2
, want
);
215 pal
.WantFind(foldmarginColour
, want
);
216 pal
.WantFind(foldmarginHighlightColour
, want
);
218 pal
.WantFind(whitespaceForeground
, want
);
219 pal
.WantFind(whitespaceBackground
, want
);
220 pal
.WantFind(selbar
, want
);
221 pal
.WantFind(selbarlight
, want
);
222 pal
.WantFind(caretcolour
, want
);
223 pal
.WantFind(caretLineBackground
, want
);
224 pal
.WantFind(edgecolour
, want
);
225 pal
.WantFind(hotspotForeground
, want
);
226 pal
.WantFind(hotspotBackground
, want
);
229 void ViewStyle::Refresh(Surface
&surface
) {
230 selbar
.desired
= Platform::Chrome();
231 selbarlight
.desired
= Platform::ChromeHighlight();
232 styles
[STYLE_DEFAULT
].Realise(surface
, zoomLevel
, NULL
, extraFontFlag
);
233 maxAscent
= styles
[STYLE_DEFAULT
].ascent
;
234 maxDescent
= styles
[STYLE_DEFAULT
].descent
;
235 someStylesProtected
= false;
236 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
237 if (i
!= STYLE_DEFAULT
) {
238 styles
[i
].Realise(surface
, zoomLevel
, &styles
[STYLE_DEFAULT
], extraFontFlag
);
239 if (maxAscent
< styles
[i
].ascent
)
240 maxAscent
= styles
[i
].ascent
;
241 if (maxDescent
< styles
[i
].descent
)
242 maxDescent
= styles
[i
].descent
;
244 if (styles
[i
].IsProtected()) {
245 someStylesProtected
= true;
249 lineHeight
= maxAscent
+ maxDescent
;
250 aveCharWidth
= styles
[STYLE_DEFAULT
].aveCharWidth
;
251 spaceWidth
= styles
[STYLE_DEFAULT
].spaceWidth
;
253 fixedColumnWidth
= leftMarginWidth
;
254 symbolMargin
= false;
255 maskInLine
= 0xffffffff;
256 for (int margin
=0; margin
< margins
; margin
++) {
257 fixedColumnWidth
+= ms
[margin
].width
;
258 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
259 if (ms
[margin
].width
> 0)
260 maskInLine
&= ~ms
[margin
].mask
;
264 void ViewStyle::ResetDefaultStyle() {
265 styles
[STYLE_DEFAULT
].Clear(ColourDesired(0,0,0),
266 ColourDesired(0xff,0xff,0xff),
267 Platform::DefaultFontSize(), fontNames
.Save(Platform::DefaultFont()),
269 false, false, false, false, Style::caseMixed
, true, true, false);
272 void ViewStyle::ClearStyles() {
273 // Reset all styles to be like the default style
274 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
275 if (i
!= STYLE_DEFAULT
) {
276 styles
[i
].ClearTo(styles
[STYLE_DEFAULT
]);
279 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
282 void ViewStyle::SetStyleFontName(int styleIndex
, const char *name
) {
283 styles
[styleIndex
].fontName
= fontNames
.Save(name
);
286 bool ViewStyle::ProtectionActive() const {
287 return someStylesProtected
;