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 <[email protected]> 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 { 12 13 /** 14 */ 15 class MarginStyle { 16 public: 17 int style; 18 ColourDesired back; 19 int width; 20 int mask; 21 bool sensitive; 22 int cursor; 23 MarginStyle(int style_= SC_MARGIN_SYMBOL, int width_=0, int mask_=0) noexcept; 24 }; 25 26 /** 27 */ 28 29 30 class FontRealised : public FontMeasurements { 31 public: 32 Font font; 33 FontRealised() noexcept; 34 // FontRealised objects can not be copied. 35 FontRealised(const FontRealised &) = delete; 36 FontRealised(FontRealised &&) = delete; 37 FontRealised &operator=(const FontRealised &) = delete; 38 FontRealised &operator=(FontRealised &&) = delete; 39 virtual ~FontRealised(); 40 void Realise(Surface &surface, int zoomLevel, int technology, const FontSpecification &fs); 41 }; 42 43 enum IndentView {ivNone, ivReal, ivLookForward, ivLookBoth}; 44 45 enum WhiteSpaceVisibility {wsInvisible=0, wsVisibleAlways=1, wsVisibleAfterIndent=2, wsVisibleOnlyInIndent=3}; 46 47 enum TabDrawMode {tdLongArrow=0, tdStrikeOut=1}; 48 49 typedef std::map<FontSpecification, std::unique_ptr<FontRealised>> FontMap; 50 51 enum class WrapMode { none, word, character, whitespace }; 52 53 class ColourOptional : public ColourDesired { 54 public: 55 bool isSet; ColourDesired(colour_)56 ColourOptional(ColourDesired colour_=ColourDesired(0,0,0), bool isSet_=false) noexcept : ColourDesired(colour_), isSet(isSet_) { 57 } ColourOptional(uptr_t wParam,sptr_t lParam)58 ColourOptional(uptr_t wParam, sptr_t lParam) noexcept : ColourDesired(static_cast<int>(lParam)), isSet(wParam != 0) { 59 } 60 }; 61 62 struct ForeBackColours { 63 ColourOptional fore; 64 ColourOptional back; 65 }; 66 67 struct EdgeProperties { 68 int column; 69 ColourDesired colour; 70 EdgeProperties(int column_ = 0, ColourDesired colour_ = ColourDesired(0)) noexcept : columnEdgeProperties71 column(column_), colour(colour_) { 72 } EdgePropertiesEdgeProperties73 EdgeProperties(uptr_t wParam, sptr_t lParam) noexcept : 74 column(static_cast<int>(wParam)), colour(static_cast<int>(lParam)) { 75 } 76 }; 77 78 /** 79 */ 80 class ViewStyle { 81 UniqueStringSet fontNames; 82 FontMap fonts; 83 public: 84 std::vector<Style> styles; 85 int nextExtendedStyle; 86 std::vector<LineMarker> markers; 87 int largestMarkerHeight; 88 std::vector<Indicator> indicators; 89 bool indicatorsDynamic; 90 bool indicatorsSetFore; 91 int technology; 92 int lineHeight; 93 int lineOverlap; 94 unsigned int maxAscent; 95 unsigned int maxDescent; 96 XYPOSITION aveCharWidth; 97 XYPOSITION spaceWidth; 98 XYPOSITION tabWidth; 99 ForeBackColours selColours; 100 ColourDesired selAdditionalForeground; 101 ColourDesired selAdditionalBackground; 102 ColourDesired selBackground2; 103 int selAlpha; 104 int selAdditionalAlpha; 105 bool selEOLFilled; 106 ForeBackColours whitespaceColours; 107 int controlCharSymbol; 108 XYPOSITION controlCharWidth; 109 ColourDesired selbar; 110 ColourDesired selbarlight; 111 ColourOptional foldmarginColour; 112 ColourOptional foldmarginHighlightColour; 113 ForeBackColours hotspotColours; 114 bool hotspotUnderline; 115 bool hotspotSingleLine; 116 /// Margins are ordered: Line Numbers, Selection Margin, Spacing Margin 117 int leftMarginWidth; ///< Spacing margin on left of text 118 int rightMarginWidth; ///< Spacing margin on right of text 119 int maskInLine; ///< Mask for markers to be put into text because there is nowhere for them to go in margin 120 int maskDrawInText; ///< Mask for markers that always draw in text 121 std::vector<MarginStyle> ms; 122 int fixedColumnWidth; ///< Total width of margins 123 bool marginInside; ///< true: margin included in text view, false: separate views 124 int textStart; ///< Starting x position of text within the view 125 int zoomLevel; 126 WhiteSpaceVisibility viewWhitespace; 127 TabDrawMode tabDrawMode; 128 int whitespaceSize; 129 IndentView viewIndentationGuides; 130 bool viewEOL; 131 ColourDesired caretcolour; 132 ColourDesired additionalCaretColour; 133 int caretLineFrame; 134 bool showCaretLineBackground; 135 bool alwaysShowCaretLineBackground; 136 ColourDesired caretLineBackground; 137 int caretLineAlpha; 138 int caretStyle; 139 int caretWidth; 140 bool someStylesProtected; 141 bool someStylesForceCase; 142 int extraFontFlag; 143 int extraAscent; 144 int extraDescent; 145 int marginStyleOffset; 146 int annotationVisible; 147 int annotationStyleOffset; 148 int eolAnnotationVisible; 149 int eolAnnotationStyleOffset; 150 bool braceHighlightIndicatorSet; 151 int braceHighlightIndicator; 152 bool braceBadLightIndicatorSet; 153 int braceBadLightIndicator; 154 int edgeState; 155 EdgeProperties theEdge; 156 std::vector<EdgeProperties> theMultiEdge; 157 int marginNumberPadding; // the right-side padding of the number margin 158 int ctrlCharPadding; // the padding around control character text blobs 159 int lastSegItalicsOffset; // the offset so as not to clip italic characters at EOLs 160 161 // Wrapping support 162 WrapMode wrapState; 163 int wrapVisualFlags; 164 int wrapVisualFlagsLocation; 165 int wrapVisualStartIndent; 166 int wrapIndentMode; // SC_WRAPINDENT_FIXED, _SAME, _INDENT 167 168 ViewStyle(); 169 ViewStyle(const ViewStyle &source); 170 ViewStyle(ViewStyle &&) = delete; 171 // Can only be copied through copy constructor which ensures font names initialised correctly 172 ViewStyle &operator=(const ViewStyle &) = delete; 173 ViewStyle &operator=(ViewStyle &&) = delete; 174 ~ViewStyle(); 175 void CalculateMarginWidthAndMask() noexcept; 176 void Init(size_t stylesSize_=256); 177 void Refresh(Surface &surface, int tabInChars); 178 void ReleaseAllExtendedStyles() noexcept; 179 int AllocateExtendedStyles(int numberStyles); 180 void EnsureStyle(size_t index); 181 void ResetDefaultStyle(); 182 void ClearStyles(); 183 void SetStyleFontName(int styleIndex, const char *name); 184 bool ProtectionActive() const noexcept; 185 int ExternalMarginWidth() const noexcept; 186 int MarginFromLocation(Point pt) const noexcept; 187 bool ValidStyle(size_t styleIndex) const noexcept; 188 void CalcLargestMarkerHeight() noexcept; 189 int GetFrameWidth() const noexcept; 190 bool IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) const noexcept; 191 ColourOptional Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const noexcept; 192 bool SelectionBackgroundDrawn() const noexcept; 193 bool WhitespaceBackgroundDrawn() const noexcept; 194 ColourDesired WrapColour() const noexcept; 195 196 void AddMultiEdge(uptr_t wParam, sptr_t lParam); 197 198 bool SetWrapState(int wrapState_) noexcept; 199 bool SetWrapVisualFlags(int wrapVisualFlags_) noexcept; 200 bool SetWrapVisualFlagsLocation(int wrapVisualFlagsLocation_) noexcept; 201 bool SetWrapVisualStartIndent(int wrapVisualStartIndent_) noexcept; 202 bool SetWrapIndentMode(int wrapIndentMode_) noexcept; 203 204 bool WhiteSpaceVisible(bool inIndent) const noexcept; 205 206 enum class CaretShape { invisible, line, block, bar }; 207 bool IsBlockCaretStyle() const noexcept; 208 bool IsCaretVisible() const noexcept; 209 bool DrawCaretInsideSelection(bool inOverstrike, bool imeCaretBlockOverride) const noexcept; 210 CaretShape CaretShapeForMode(bool inOverstrike) const noexcept; 211 212 private: 213 void AllocStyles(size_t sizeNew); 214 void CreateAndAddFont(const FontSpecification &fs); 215 FontRealised *Find(const FontSpecification &fs); 216 void FindMaxAscentDescent(); 217 }; 218 219 } 220 221 #endif 222