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