]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/ViewStyle.cxx
2188fd03f7890ab414c511eccfc534fb7e261b93
1 // Scintilla source code edit control
2 // ViewStyle.cxx - store information on how the document is to be viewed
3 // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
10 #include "Scintilla.h"
11 #include "Indicator.h"
12 #include "LineMarker.h"
14 #include "ViewStyle.h"
16 MarginStyle::MarginStyle() :
17 symbol(false), width(16), mask(0xffffffff), sensitive(false) {
20 // A list of the fontnames - avoids wasting space in each style
21 FontNames::FontNames() {
25 FontNames::~FontNames() {
29 void FontNames::Clear() {
30 for (int i
=0;i
<max
;i
++) {
36 const char *FontNames::Save(const char *name
) {
39 for (int i
=0;i
<max
;i
++) {
40 if (strcmp(names
[i
], name
) == 0) {
44 names
[max
] = new char[strlen(name
) + 1];
45 strcpy(names
[max
], name
);
50 ViewStyle::ViewStyle() {
54 ViewStyle::ViewStyle(const ViewStyle
&source
) {
56 for (unsigned int sty
=0;sty
<(sizeof(styles
)/sizeof(styles
[0]));sty
++) {
57 styles
[sty
] = source
.styles
[sty
];
58 // Can't just copy fontname as its lifetime is relative to its owning ViewStyle
59 styles
[sty
].fontName
= fontNames
.Save(source
.styles
[sty
].fontName
);
61 for (int mrk
=0;mrk
<=MARKER_MAX
;mrk
++) {
62 markers
[mrk
] = source
.markers
[mrk
];
64 for (int ind
=0;ind
<=INDIC_MAX
;ind
++) {
65 indicators
[ind
] = source
.indicators
[ind
];
68 selforeset
= source
.selforeset
;
69 selforeground
.desired
= source
.selforeground
.desired
;
70 selbackset
= source
.selbackset
;
71 selbackground
.desired
= source
.selbackground
.desired
;
72 selbar
.desired
= source
.selbar
.desired
;
73 selbarlight
.desired
= source
.selbarlight
.desired
;
74 caretcolour
.desired
= source
.caretcolour
.desired
;
75 edgecolour
.desired
= source
.edgecolour
.desired
;
76 leftMarginWidth
= source
.leftMarginWidth
;
77 rightMarginWidth
= source
.rightMarginWidth
;
78 for (int i
=0;i
< margins
; i
++) {
81 symbolMargin
= source
.symbolMargin
;
82 maskInLine
= source
.maskInLine
;
83 fixedColumnWidth
= source
.fixedColumnWidth
;
84 zoomLevel
= source
.zoomLevel
;
85 viewWhitespace
= source
.viewWhitespace
;
86 viewEOL
= source
.viewEOL
;
87 showMarkedLines
= source
.showMarkedLines
;
90 ViewStyle::~ViewStyle() {
93 void ViewStyle::Init() {
97 indicators
[0].style
= INDIC_SQUIGGLE
;
98 indicators
[0].fore
= Colour(0, 0x7f, 0);
99 indicators
[1].style
= INDIC_TT
;
100 indicators
[1].fore
= Colour(0, 0, 0xff);
101 indicators
[2].style
= INDIC_PLAIN
;
102 indicators
[2].fore
= Colour(0xff, 0, 0);
111 selforeground
.desired
= Colour(0xff, 0, 0);
113 selbackground
.desired
= Colour(0xc0, 0xc0, 0xc0);
114 selbar
.desired
= Platform::Chrome();
115 selbarlight
.desired
= Platform::ChromeHighlight();
116 styles
[STYLE_LINENUMBER
].fore
.desired
= Colour(0, 0, 0);
117 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
118 //caretcolour.desired = Colour(0xff, 0, 0);
119 caretcolour
.desired
= Colour(0, 0, 0);
120 edgecolour
.desired
= Colour(0xc0, 0xc0, 0xc0);
123 rightMarginWidth
= 1;
124 ms
[0].symbol
= false;
129 ms
[1].mask
= ~SC_MASK_FOLDERS
;
131 ms
[2].width
= 14; // Nice width for arrows
132 ms
[2].mask
= SC_MASK_FOLDERS
;
133 ms
[2].width
= 0; // Nice width for arrows
135 fixedColumnWidth
= leftMarginWidth
;
136 symbolMargin
= false;
137 maskInLine
= 0xffffffff;
138 for (int margin
=0; margin
< margins
; margin
++) {
139 fixedColumnWidth
+= ms
[margin
].width
;
140 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
141 if (ms
[margin
].width
> 0)
142 maskInLine
&= ~ms
[margin
].mask
;
145 viewWhitespace
= false;
147 showMarkedLines
= true;
150 void ViewStyle::RefreshColourPalette(Palette
&pal
, bool want
) {
152 for (i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
153 pal
.WantFind(styles
[i
].fore
, want
);
154 pal
.WantFind(styles
[i
].back
, want
);
156 for (i
=0;i
<(sizeof(indicators
)/sizeof(indicators
[0]));i
++) {
157 pal
.WantFind(indicators
[i
].fore
, want
);
159 for (i
=0;i
<(sizeof(markers
)/sizeof(markers
[0]));i
++) {
160 pal
.WantFind(markers
[i
].fore
, want
);
161 pal
.WantFind(markers
[i
].back
, want
);
163 pal
.WantFind(selforeground
, want
);
164 pal
.WantFind(selbackground
, want
);
165 pal
.WantFind(selbar
, want
);
166 pal
.WantFind(selbarlight
, want
);
167 pal
.WantFind(caretcolour
, want
);
168 pal
.WantFind(edgecolour
, want
);
171 void ViewStyle::Refresh(Surface
&surface
) {
172 selbar
.desired
= Platform::Chrome();
173 selbarlight
.desired
= Platform::ChromeHighlight();
174 styles
[STYLE_DEFAULT
].Realise(surface
, zoomLevel
);
175 maxAscent
= styles
[STYLE_DEFAULT
].ascent
;
176 maxDescent
= styles
[STYLE_DEFAULT
].descent
;
177 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
178 if (i
!= STYLE_DEFAULT
) {
179 styles
[i
].Realise(surface
, zoomLevel
, &styles
[STYLE_DEFAULT
]);
180 if (maxAscent
< styles
[i
].ascent
)
181 maxAscent
= styles
[i
].ascent
;
182 if (maxDescent
< styles
[i
].descent
)
183 maxDescent
= styles
[i
].descent
;
187 lineHeight
= maxAscent
+ maxDescent
;
188 aveCharWidth
= styles
[STYLE_DEFAULT
].aveCharWidth
;
189 spaceWidth
= styles
[STYLE_DEFAULT
].spaceWidth
;
191 fixedColumnWidth
= leftMarginWidth
;
192 symbolMargin
= false;
193 maskInLine
= 0xffffffff;
194 for (int margin
=0; margin
< margins
; margin
++) {
195 fixedColumnWidth
+= ms
[margin
].width
;
196 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
197 if (ms
[margin
].width
> 0)
198 maskInLine
&= ~ms
[margin
].mask
;
202 void ViewStyle::ResetDefaultStyle() {
203 styles
[STYLE_DEFAULT
].Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
204 Platform::DefaultFontSize(), fontNames
.Save(Platform::DefaultFont()),
205 false, false, false);
208 void ViewStyle::ClearStyles() {
209 // Reset all styles to be like the default style
210 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
211 if (i
!= STYLE_DEFAULT
) {
213 styles
[STYLE_DEFAULT
].fore
.desired
,
214 styles
[STYLE_DEFAULT
].back
.desired
,
215 styles
[STYLE_DEFAULT
].size
,
216 styles
[STYLE_DEFAULT
].fontName
,
217 styles
[STYLE_DEFAULT
].bold
,
218 styles
[STYLE_DEFAULT
].italic
,
219 styles
[STYLE_DEFAULT
].eolFilled
);
222 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
225 void ViewStyle::SetStyleFontName(int styleIndex
, const char *name
) {
226 styles
[styleIndex
].fontName
= fontNames
.Save(name
);