1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
// Scintilla source code edit control
/** @file ViewStyle.h
** Store information on how the document is to be viewed.
**/
// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#ifndef VIEWSTYLE_H
#define VIEWSTYLE_H
namespace Scintilla {
/**
*/
class MarginStyle {
public:
int style;
ColourAlpha back;
int width;
int mask;
bool sensitive;
int cursor;
MarginStyle(int style_= SC_MARGIN_SYMBOL, int width_=0, int mask_=0) noexcept;
};
/**
*/
class FontRealised : public FontMeasurements {
public:
std::shared_ptr<Font> font;
FontRealised() noexcept;
// FontRealised objects can not be copied.
FontRealised(const FontRealised &) = delete;
FontRealised(FontRealised &&) = delete;
FontRealised &operator=(const FontRealised &) = delete;
FontRealised &operator=(FontRealised &&) = delete;
virtual ~FontRealised();
void Realise(Surface &surface, int zoomLevel, int technology, const FontSpecification &fs, const char *localeName);
};
enum class IndentView {none, real, lookForward, lookBoth};
enum class WhiteSpace {invisible=0, visibleAlways=1, visibleAfterIndent=2, visibleOnlyInIndent=3};
enum class TabDrawMode {longArrow=0, strikeOut=1};
typedef std::map<FontSpecification, std::unique_ptr<FontRealised>> FontMap;
enum class WrapMode { none, word, character, whitespace };
inline std::optional<ColourAlpha> OptionalColour(uptr_t wParam, sptr_t lParam) {
if (wParam) {
return ColourAlpha::FromRGB(static_cast<int>(lParam));
} else {
return {};
}
}
struct ForeBackColours {
std::optional<ColourAlpha> fore;
std::optional<ColourAlpha> back;
};
struct SelectionAppearance {
// Whether to draw on base layer or over text
Layer layer;
// Draw selection past line end characters up to right border
bool eolFilled;
};
struct CaretLineAppearance {
// Whether to draw on base layer or over text
Layer layer;
// Also show when non-focused
bool alwaysShow;
// Non-0: draw a rectangle around line instead of filling line. Value is pixel width of frame
int frame;
};
struct CaretAppearance {
// Line, block, over-strike bar ...
int style;
// Width in pixels
int width;
};
struct WrapAppearance {
// No wrapping, word, character, whitespace appearance
WrapMode state;
// Show indication of wrap at line end, line start, or in margin
int visualFlags;
// Show indication near margin or near text
int visualFlagsLocation;
// How much indentation to show wrapping
int visualStartIndent;
// SC_WRAPINDENT_FIXED, _SAME, _INDENT, _DEEPINDENT
int indentMode;
};
struct EdgeProperties {
int column = 0;
ColourAlpha colour;
EdgeProperties(int column_ = 0, ColourAlpha colour_ = ColourAlpha::FromRGB(0)) noexcept :
column(column_), colour(colour_) {
}
EdgeProperties(uptr_t wParam, sptr_t lParam) noexcept :
column(static_cast<int>(wParam)), colour(ColourAlpha::FromRGB(static_cast<int>(lParam))) {
}
};
/**
*/
class ViewStyle {
UniqueStringSet fontNames;
FontMap fonts;
public:
std::vector<Style> styles;
int nextExtendedStyle;
std::vector<LineMarker> markers;
int largestMarkerHeight;
std::vector<Indicator> indicators;
bool indicatorsDynamic;
bool indicatorsSetFore;
int technology;
int lineHeight;
int lineOverlap;
unsigned int maxAscent;
unsigned int maxDescent;
XYPOSITION aveCharWidth;
XYPOSITION spaceWidth;
XYPOSITION tabWidth;
SelectionAppearance selection;
int controlCharSymbol;
XYPOSITION controlCharWidth;
ColourAlpha selbar;
ColourAlpha selbarlight;
std::optional<ColourAlpha> foldmarginColour;
std::optional<ColourAlpha> foldmarginHighlightColour;
ForeBackColours hotspotColours;
bool hotspotUnderline;
/// Margins are ordered: Line Numbers, Selection Margin, Spacing Margin
int leftMarginWidth; ///< Spacing margin on left of text
int rightMarginWidth; ///< Spacing margin on right of text
int maskInLine; ///< Mask for markers to be put into text because there is nowhere for them to go in margin
int maskDrawInText; ///< Mask for markers that always draw in text
std::vector<MarginStyle> ms;
int fixedColumnWidth; ///< Total width of margins
bool marginInside; ///< true: margin included in text view, false: separate views
int textStart; ///< Starting x position of text within the view
int zoomLevel;
WhiteSpace viewWhitespace;
std::optional<ColourAlpha> whitespaceBack;
TabDrawMode tabDrawMode;
int whitespaceSize;
IndentView viewIndentationGuides;
bool viewEOL;
CaretAppearance caret;
CaretLineAppearance caretLine;
bool someStylesProtected;
bool someStylesForceCase;
int extraFontFlag;
int extraAscent;
int extraDescent;
int marginStyleOffset;
int annotationVisible;
int annotationStyleOffset;
int eolAnnotationVisible;
int eolAnnotationStyleOffset;
bool braceHighlightIndicatorSet;
int braceHighlightIndicator;
bool braceBadLightIndicatorSet;
int braceBadLightIndicator;
int edgeState;
EdgeProperties theEdge;
std::vector<EdgeProperties> theMultiEdge;
int marginNumberPadding; // the right-side padding of the number margin
int ctrlCharPadding; // the padding around control character text blobs
int lastSegItalicsOffset; // the offset so as not to clip italic characters at EOLs
using ElementMap = std::map<int, std::optional<ColourAlpha>>;
ElementMap elementColours;
ElementMap elementBaseColours;
std::set<int> elementAllowsTranslucent;
WrapAppearance wrap;
std::string localeName;
ViewStyle();
ViewStyle(const ViewStyle &source);
ViewStyle(ViewStyle &&) = delete;
// Can only be copied through copy constructor which ensures font names initialised correctly
ViewStyle &operator=(const ViewStyle &) = delete;
ViewStyle &operator=(ViewStyle &&) = delete;
~ViewStyle();
void CalculateMarginWidthAndMask() noexcept;
void Init(size_t stylesSize_=256);
void Refresh(Surface &surface, int tabInChars);
void ReleaseAllExtendedStyles() noexcept;
int AllocateExtendedStyles(int numberStyles);
void EnsureStyle(size_t index);
void ResetDefaultStyle();
void ClearStyles();
void SetStyleFontName(int styleIndex, const char *name);
void SetFontLocaleName(const char *name);
bool ProtectionActive() const noexcept;
int ExternalMarginWidth() const noexcept;
int MarginFromLocation(Point pt) const noexcept;
bool ValidStyle(size_t styleIndex) const noexcept;
void CalcLargestMarkerHeight() noexcept;
int GetFrameWidth() const noexcept;
bool IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) const;
std::optional<ColourAlpha> Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const;
bool SelectionBackgroundDrawn() const noexcept;
bool SelectionTextDrawn() const;
bool WhitespaceBackgroundDrawn() const noexcept;
ColourAlpha WrapColour() const noexcept;
void AddMultiEdge(uptr_t wParam, sptr_t lParam);
std::optional<ColourAlpha> ElementColour(int element) const;
bool ElementAllowsTranslucent(int element) const;
bool ResetElement(int element);
bool SetElementColour(int element, ColourAlpha colour);
bool SetElementColourOptional(int element, uptr_t wParam, sptr_t lParam);
void SetElementRGB(int element, int rgb);
void SetElementAlpha(int element, int alpha);
bool ElementIsSet(int element) const;
bool SetElementBase(int element, ColourAlpha colour);
bool SetWrapState(int wrapState_) noexcept;
bool SetWrapVisualFlags(int wrapVisualFlags_) noexcept;
bool SetWrapVisualFlagsLocation(int wrapVisualFlagsLocation_) noexcept;
bool SetWrapVisualStartIndent(int wrapVisualStartIndent_) noexcept;
bool SetWrapIndentMode(int wrapIndentMode_) noexcept;
bool WhiteSpaceVisible(bool inIndent) const noexcept;
enum class CaretShape { invisible, line, block, bar };
bool IsBlockCaretStyle() const noexcept;
bool IsCaretVisible() const noexcept;
bool DrawCaretInsideSelection(bool inOverstrike, bool imeCaretBlockOverride) const noexcept;
CaretShape CaretShapeForMode(bool inOverstrike) const noexcept;
private:
void AllocStyles(size_t sizeNew);
void CreateAndAddFont(const FontSpecification &fs);
FontRealised *Find(const FontSpecification &fs);
void FindMaxAscentDescent();
};
}
#endif
|