]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/ViewStyle.cxx
12e1406aa440db3930e2e8d1ae8f51f36b4b8bcc
1 // Scintilla source code edit control
2 /** @file ViewStyle.cxx
3 ** Store information on how the document is to be viewed.
5 // Copyright 1998-2001 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"
14 #include "LineMarker.h"
16 #include "ViewStyle.h"
18 MarginStyle::MarginStyle() :
19 symbol(false), width(16), mask(0xffffffff), sensitive(false) {
22 // A list of the fontnames - avoids wasting space in each style
23 FontNames::FontNames() {
27 FontNames::~FontNames() {
31 void FontNames::Clear() {
32 for (int i
=0;i
<max
;i
++) {
38 const char *FontNames::Save(const char *name
) {
41 for (int i
=0;i
<max
;i
++) {
42 if (strcmp(names
[i
], name
) == 0) {
46 names
[max
] = new char[strlen(name
) + 1];
47 strcpy(names
[max
], name
);
52 ViewStyle::ViewStyle() {
56 ViewStyle::ViewStyle(const ViewStyle
&source
) {
58 for (unsigned int sty
=0;sty
<(sizeof(styles
)/sizeof(styles
[0]));sty
++) {
59 styles
[sty
] = source
.styles
[sty
];
60 // Can't just copy fontname as its lifetime is relative to its owning ViewStyle
61 styles
[sty
].fontName
= fontNames
.Save(source
.styles
[sty
].fontName
);
63 for (int mrk
=0;mrk
<=MARKER_MAX
;mrk
++) {
64 markers
[mrk
] = source
.markers
[mrk
];
66 for (int ind
=0;ind
<=INDIC_MAX
;ind
++) {
67 indicators
[ind
] = source
.indicators
[ind
];
70 selforeset
= source
.selforeset
;
71 selforeground
.desired
= source
.selforeground
.desired
;
72 selbackset
= source
.selbackset
;
73 selbackground
.desired
= source
.selbackground
.desired
;
74 selbackground2
.desired
= source
.selbackground2
.desired
;
75 whitespaceForegroundSet
= source
.whitespaceForegroundSet
;
76 whitespaceForeground
.desired
= source
.whitespaceForeground
.desired
;
77 whitespaceBackgroundSet
= source
.whitespaceBackgroundSet
;
78 whitespaceBackground
.desired
= source
.whitespaceBackground
.desired
;
79 selbar
.desired
= source
.selbar
.desired
;
80 selbarlight
.desired
= source
.selbarlight
.desired
;
81 caretcolour
.desired
= source
.caretcolour
.desired
;
82 showCaretLineBackground
= source
.showCaretLineBackground
;
83 caretLineBackground
.desired
= source
.caretLineBackground
.desired
;
84 edgecolour
.desired
= source
.edgecolour
.desired
;
85 edgeState
= source
.edgeState
;
86 caretWidth
= source
.caretWidth
;
87 leftMarginWidth
= source
.leftMarginWidth
;
88 rightMarginWidth
= source
.rightMarginWidth
;
89 for (int i
=0;i
< margins
; i
++) {
92 symbolMargin
= source
.symbolMargin
;
93 maskInLine
= source
.maskInLine
;
94 fixedColumnWidth
= source
.fixedColumnWidth
;
95 zoomLevel
= source
.zoomLevel
;
96 viewWhitespace
= source
.viewWhitespace
;
97 viewIndentationGuides
= source
.viewIndentationGuides
;
98 viewEOL
= source
.viewEOL
;
99 showMarkedLines
= source
.showMarkedLines
;
102 ViewStyle::~ViewStyle() {
105 void ViewStyle::Init() {
109 indicators
[0].style
= INDIC_SQUIGGLE
;
110 indicators
[0].fore
= ColourDesired(0, 0x7f, 0);
111 indicators
[1].style
= INDIC_TT
;
112 indicators
[1].fore
= ColourDesired(0, 0, 0xff);
113 indicators
[2].style
= INDIC_PLAIN
;
114 indicators
[2].fore
= ColourDesired(0xff, 0, 0);
123 selforeground
.desired
= ColourDesired(0xff, 0, 0);
125 selbackground
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
126 selbackground2
.desired
= ColourDesired(0xb0, 0xb0, 0xb0);
127 whitespaceForegroundSet
= false;
128 whitespaceForeground
.desired
= ColourDesired(0, 0, 0);
129 whitespaceBackgroundSet
= false;
130 whitespaceBackground
.desired
= ColourDesired(0xff, 0xff, 0xff);
131 selbar
.desired
= Platform::Chrome();
132 selbarlight
.desired
= Platform::ChromeHighlight();
133 styles
[STYLE_LINENUMBER
].fore
.desired
= ColourDesired(0, 0, 0);
134 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
135 caretcolour
.desired
= ColourDesired(0, 0, 0);
136 showCaretLineBackground
= false;
137 caretLineBackground
.desired
= ColourDesired(0xff, 0xff, 0);
138 edgecolour
.desired
= ColourDesired(0xc0, 0xc0, 0xc0);
139 edgeState
= EDGE_NONE
;
143 rightMarginWidth
= 1;
144 ms
[0].symbol
= false;
149 ms
[1].mask
= ~SC_MASK_FOLDERS
;
151 ms
[2].width
= 14; // Nice width for arrows
152 ms
[2].mask
= SC_MASK_FOLDERS
;
153 ms
[2].width
= 0; // Nice width for arrows
155 fixedColumnWidth
= leftMarginWidth
;
156 symbolMargin
= false;
157 maskInLine
= 0xffffffff;
158 for (int margin
=0; margin
< margins
; margin
++) {
159 fixedColumnWidth
+= ms
[margin
].width
;
160 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
161 if (ms
[margin
].width
> 0)
162 maskInLine
&= ~ms
[margin
].mask
;
165 viewWhitespace
= wsInvisible
;
166 viewIndentationGuides
= false;
168 showMarkedLines
= true;
171 void ViewStyle::RefreshColourPalette(Palette
&pal
, bool want
) {
173 for (i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
174 pal
.WantFind(styles
[i
].fore
, want
);
175 pal
.WantFind(styles
[i
].back
, want
);
177 for (i
=0;i
<(sizeof(indicators
)/sizeof(indicators
[0]));i
++) {
178 pal
.WantFind(indicators
[i
].fore
, want
);
180 for (i
=0;i
<(sizeof(markers
)/sizeof(markers
[0]));i
++) {
181 pal
.WantFind(markers
[i
].fore
, want
);
182 pal
.WantFind(markers
[i
].back
, want
);
184 pal
.WantFind(selforeground
, want
);
185 pal
.WantFind(selbackground
, want
);
186 pal
.WantFind(selbackground2
, want
);
187 pal
.WantFind(whitespaceForeground
, want
);
188 pal
.WantFind(whitespaceBackground
, want
);
189 pal
.WantFind(selbar
, want
);
190 pal
.WantFind(selbarlight
, want
);
191 pal
.WantFind(caretcolour
, want
);
192 pal
.WantFind(caretLineBackground
, want
);
193 pal
.WantFind(edgecolour
, want
);
196 void ViewStyle::Refresh(Surface
&surface
) {
197 selbar
.desired
= Platform::Chrome();
198 selbarlight
.desired
= Platform::ChromeHighlight();
199 styles
[STYLE_DEFAULT
].Realise(surface
, zoomLevel
);
200 maxAscent
= styles
[STYLE_DEFAULT
].ascent
;
201 maxDescent
= styles
[STYLE_DEFAULT
].descent
;
202 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
203 if (i
!= STYLE_DEFAULT
) {
204 styles
[i
].Realise(surface
, zoomLevel
, &styles
[STYLE_DEFAULT
]);
205 if (maxAscent
< styles
[i
].ascent
)
206 maxAscent
= styles
[i
].ascent
;
207 if (maxDescent
< styles
[i
].descent
)
208 maxDescent
= styles
[i
].descent
;
212 lineHeight
= maxAscent
+ maxDescent
;
213 aveCharWidth
= styles
[STYLE_DEFAULT
].aveCharWidth
;
214 spaceWidth
= styles
[STYLE_DEFAULT
].spaceWidth
;
216 fixedColumnWidth
= leftMarginWidth
;
217 symbolMargin
= false;
218 maskInLine
= 0xffffffff;
219 for (int margin
=0; margin
< margins
; margin
++) {
220 fixedColumnWidth
+= ms
[margin
].width
;
221 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
222 if (ms
[margin
].width
> 0)
223 maskInLine
&= ~ms
[margin
].mask
;
227 void ViewStyle::ResetDefaultStyle() {
228 styles
[STYLE_DEFAULT
].Clear(ColourDesired(0,0,0),
229 ColourDesired(0xff,0xff,0xff),
230 Platform::DefaultFontSize(), fontNames
.Save(Platform::DefaultFont()),
232 false, false, false, false, Style::caseMixed
, true, true);
235 void ViewStyle::ClearStyles() {
236 // Reset all styles to be like the default style
237 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
238 if (i
!= STYLE_DEFAULT
) {
239 styles
[i
].ClearTo(styles
[STYLE_DEFAULT
]);
242 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
245 void ViewStyle::SetStyleFontName(int styleIndex
, const char *name
) {
246 styles
[styleIndex
].fontName
= fontNames
.Save(name
);