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