]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/ViewStyle.cxx
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 selbar
.desired
= source
.selbar
.desired
;
76 selbarlight
.desired
= source
.selbarlight
.desired
;
77 caretcolour
.desired
= source
.caretcolour
.desired
;
78 showCaretLineBackground
= source
.showCaretLineBackground
;
79 caretLineBackground
.desired
= source
.caretLineBackground
.desired
;
80 edgecolour
.desired
= source
.edgecolour
.desired
;
81 edgeState
= source
.edgeState
;
82 caretWidth
= source
.caretWidth
;
83 leftMarginWidth
= source
.leftMarginWidth
;
84 rightMarginWidth
= source
.rightMarginWidth
;
85 for (int i
=0;i
< margins
; i
++) {
88 symbolMargin
= source
.symbolMargin
;
89 maskInLine
= source
.maskInLine
;
90 fixedColumnWidth
= source
.fixedColumnWidth
;
91 zoomLevel
= source
.zoomLevel
;
92 viewWhitespace
= source
.viewWhitespace
;
93 viewIndentationGuides
= source
.viewIndentationGuides
;
94 viewEOL
= source
.viewEOL
;
95 showMarkedLines
= source
.showMarkedLines
;
98 ViewStyle::~ViewStyle() {
101 void ViewStyle::Init() {
105 indicators
[0].style
= INDIC_SQUIGGLE
;
106 indicators
[0].fore
= Colour(0, 0x7f, 0);
107 indicators
[1].style
= INDIC_TT
;
108 indicators
[1].fore
= Colour(0, 0, 0xff);
109 indicators
[2].style
= INDIC_PLAIN
;
110 indicators
[2].fore
= Colour(0xff, 0, 0);
119 selforeground
.desired
= Colour(0xff, 0, 0);
121 selbackground
.desired
= Colour(0xc0, 0xc0, 0xc0);
122 selbackground2
.desired
= Colour(0xb0, 0xb0, 0xb0);
123 selbar
.desired
= Platform::Chrome();
124 selbarlight
.desired
= Platform::ChromeHighlight();
125 styles
[STYLE_LINENUMBER
].fore
.desired
= Colour(0, 0, 0);
126 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
127 caretcolour
.desired
= Colour(0, 0, 0);
128 showCaretLineBackground
= false;
129 caretLineBackground
.desired
= Colour(0xff, 0xff, 0);
130 edgecolour
.desired
= Colour(0xc0, 0xc0, 0xc0);
131 edgeState
= EDGE_NONE
;
135 rightMarginWidth
= 1;
136 ms
[0].symbol
= false;
141 ms
[1].mask
= ~SC_MASK_FOLDERS
;
143 ms
[2].width
= 14; // Nice width for arrows
144 ms
[2].mask
= SC_MASK_FOLDERS
;
145 ms
[2].width
= 0; // Nice width for arrows
147 fixedColumnWidth
= leftMarginWidth
;
148 symbolMargin
= false;
149 maskInLine
= 0xffffffff;
150 for (int margin
=0; margin
< margins
; margin
++) {
151 fixedColumnWidth
+= ms
[margin
].width
;
152 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
153 if (ms
[margin
].width
> 0)
154 maskInLine
&= ~ms
[margin
].mask
;
157 viewWhitespace
= wsInvisible
;
158 viewIndentationGuides
= false;
160 showMarkedLines
= true;
163 void ViewStyle::RefreshColourPalette(Palette
&pal
, bool want
) {
165 for (i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
166 pal
.WantFind(styles
[i
].fore
, want
);
167 pal
.WantFind(styles
[i
].back
, want
);
169 for (i
=0;i
<(sizeof(indicators
)/sizeof(indicators
[0]));i
++) {
170 pal
.WantFind(indicators
[i
].fore
, want
);
172 for (i
=0;i
<(sizeof(markers
)/sizeof(markers
[0]));i
++) {
173 pal
.WantFind(markers
[i
].fore
, want
);
174 pal
.WantFind(markers
[i
].back
, want
);
176 pal
.WantFind(selforeground
, want
);
177 pal
.WantFind(selbackground
, want
);
178 pal
.WantFind(selbackground2
, want
);
179 pal
.WantFind(selbar
, want
);
180 pal
.WantFind(selbarlight
, want
);
181 pal
.WantFind(caretcolour
, want
);
182 pal
.WantFind(caretLineBackground
, want
);
183 pal
.WantFind(edgecolour
, want
);
186 void ViewStyle::Refresh(Surface
&surface
) {
187 selbar
.desired
= Platform::Chrome();
188 selbarlight
.desired
= Platform::ChromeHighlight();
189 styles
[STYLE_DEFAULT
].Realise(surface
, zoomLevel
);
190 maxAscent
= styles
[STYLE_DEFAULT
].ascent
;
191 maxDescent
= styles
[STYLE_DEFAULT
].descent
;
192 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
193 if (i
!= STYLE_DEFAULT
) {
194 styles
[i
].Realise(surface
, zoomLevel
, &styles
[STYLE_DEFAULT
]);
195 if (maxAscent
< styles
[i
].ascent
)
196 maxAscent
= styles
[i
].ascent
;
197 if (maxDescent
< styles
[i
].descent
)
198 maxDescent
= styles
[i
].descent
;
202 lineHeight
= maxAscent
+ maxDescent
;
203 aveCharWidth
= styles
[STYLE_DEFAULT
].aveCharWidth
;
204 spaceWidth
= styles
[STYLE_DEFAULT
].spaceWidth
;
206 fixedColumnWidth
= leftMarginWidth
;
207 symbolMargin
= false;
208 maskInLine
= 0xffffffff;
209 for (int margin
=0; margin
< margins
; margin
++) {
210 fixedColumnWidth
+= ms
[margin
].width
;
211 symbolMargin
= symbolMargin
|| ms
[margin
].symbol
;
212 if (ms
[margin
].width
> 0)
213 maskInLine
&= ~ms
[margin
].mask
;
217 void ViewStyle::ResetDefaultStyle() {
218 styles
[STYLE_DEFAULT
].Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
219 Platform::DefaultFontSize(), fontNames
.Save(Platform::DefaultFont()),
221 false, false, false, false, Style::caseMixed
, true);
224 void ViewStyle::ClearStyles() {
225 // Reset all styles to be like the default style
226 for (unsigned int i
=0;i
<(sizeof(styles
)/sizeof(styles
[0]));i
++) {
227 if (i
!= STYLE_DEFAULT
) {
228 styles
[i
].ClearTo(styles
[STYLE_DEFAULT
]);
231 styles
[STYLE_LINENUMBER
].back
.desired
= Platform::Chrome();
234 void ViewStyle::SetStyleFontName(int styleIndex
, const char *name
) {
235 styles
[styleIndex
].fontName
= fontNames
.Save(name
);