From 92290868cf9753d2df0d494cb44e2ff62a570b58 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 24 May 2021 19:31:06 +1000 Subject: Define C++ version of the Scintilla API in ScintillaTypes.h, ScintillaMessages.h and ScintillaStructures.h using scoped enumerations. Use these headers instead of Scintilla.h internally. External definitions go in the Scintilla namespace and internal definitio0ns in Scintilla::Internal. --- src/ViewStyle.cxx | 269 ++++++++++++++++++++++++++---------------------------- 1 file changed, 128 insertions(+), 141 deletions(-) (limited to 'src/ViewStyle.cxx') diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 675c7cedf..8340cd68f 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -19,11 +19,12 @@ #include #include +#include "ScintillaTypes.h" + #include "Debugging.h" #include "Geometry.h" #include "Platform.h" -#include "Scintilla.h" #include "Position.h" #include "UniqueString.h" #include "Indicator.h" @@ -33,27 +34,28 @@ #include "ViewStyle.h" using namespace Scintilla; +using namespace Scintilla::Internal; -MarginStyle::MarginStyle(int style_, int width_, int mask_) noexcept : - style(style_), width(width_), mask(mask_), sensitive(false), cursor(SC_CURSORREVERSEARROW) { +MarginStyle::MarginStyle(MarginType style_, int width_, int mask_) noexcept : + style(style_), width(width_), mask(mask_), sensitive(false), cursor(CursorShape::ReverseArrow) { } bool MarginStyle::ShowsFolding() const noexcept { - return (mask & SC_MASK_FOLDERS) != 0; + return (mask & MaskFolders) != 0; } FontRealised::FontRealised() noexcept = default; FontRealised::~FontRealised() = default; -void FontRealised::Realise(Surface &surface, int zoomLevel, int technology, const FontSpecification &fs, const char *localeName) { +void FontRealised::Realise(Surface &surface, int zoomLevel, Technology technology, const FontSpecification &fs, const char *localeName) { PLATFORM_ASSERT(fs.fontName); - sizeZoomed = fs.size + zoomLevel * SC_FONT_SIZE_MULTIPLIER; - if (sizeZoomed <= 2 * SC_FONT_SIZE_MULTIPLIER) // Hangs if sizeZoomed <= 1 - sizeZoomed = 2 * SC_FONT_SIZE_MULTIPLIER; + sizeZoomed = fs.size + zoomLevel * FontSizeMultiplier; + if (sizeZoomed <= 2 * FontSizeMultiplier) // Hangs if sizeZoomed <= 1 + sizeZoomed = 2 * FontSizeMultiplier; const float deviceHeight = static_cast(surface.DeviceHeightFont(sizeZoomed)); - const FontParameters fp(fs.fontName, deviceHeight / SC_FONT_SIZE_MULTIPLIER, fs.weight, + const FontParameters fp(fs.fontName, deviceHeight / FontSizeMultiplier, fs.weight, fs.italic, fs.extraFontFlag, technology, fs.characterSet, localeName); font = Font::Allocate(fp); @@ -64,13 +66,13 @@ void FontRealised::Realise(Surface &surface, int zoomLevel, int technology, cons spaceWidth = surface.WidthText(font.get(), " "); } -ViewStyle::ViewStyle() : markers(MARKER_MAX + 1), indicators(INDICATOR_MAX + 1) { +ViewStyle::ViewStyle() : markers(MarkerMax + 1), indicators(static_cast(IndicatorNumbers::Max) + 1) { Init(); } // Copy constructor only called when printing copies the screen ViewStyle so it can be // modified for printing styles. -ViewStyle::ViewStyle(const ViewStyle &source) : markers(MARKER_MAX + 1), indicators(INDICATOR_MAX + 1) { +ViewStyle::ViewStyle(const ViewStyle &source) : markers(MarkerMax + 1), indicators(static_cast(IndicatorNumbers::Max) + 1) { Init(source.styles.size()); styles = source.styles; for (size_t sty=0; sty= 32) { const char cc[2] = { static_cast(controlCharSymbol), '\0' }; - controlCharWidth = surface.WidthText(styles[STYLE_CONTROLCHAR].font.get(), cc); + controlCharWidth = surface.WidthText(styles[StyleControlChar].font.get(), cc); } CalculateMarginWidthAndMask(); @@ -376,7 +378,7 @@ int ViewStyle::AllocateExtendedStyles(int numberStyles) { nextExtendedStyle += numberStyles; EnsureStyle(nextExtendedStyle); for (int i=startRange; iGetHeight() > largestMarkerHeight) largestMarkerHeight = marker.pxpm->GetHeight(); break; - case SC_MARK_RGBAIMAGE: + case MarkerSymbol::RgbaImage: if (marker.image && marker.image->GetHeight() > largestMarkerHeight) largestMarkerHeight = marker.image->GetHeight(); break; @@ -464,27 +466,27 @@ int ViewStyle::GetFrameWidth() const noexcept { bool ViewStyle::IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) const { return caretLine.frame && (caretActive || caretLine.alwaysShow) && - ElementColour(SC_ELEMENT_CARET_LINE_BACK) && - (caretLine.layer == Layer::base) && lineContainsCaret; + ElementColour(Element::CaretLineBack) && + (caretLine.layer == Layer::Base) && lineContainsCaret; } // See if something overrides the line background colour: Either if caret is on the line // and background colour is set for that, or if a marker is defined that forces its background // colour onto the line, or if a marker is defined but has no selection margin in which to -// display itself (as long as it's not an SC_MARK_EMPTY marker). These are checked in order +// display itself (as long as it's not an MarkerSymbol::Empty marker). These are checked in order // with the earlier taking precedence. When multiple markers cause background override, // the colour for the highest numbered one is used. std::optional ViewStyle::Background(int marksOfLine, bool caretActive, bool lineContainsCaret) const { std::optional background; if (!caretLine.frame && (caretActive || caretLine.alwaysShow) && - (caretLine.layer == Layer::base) && lineContainsCaret) { - background = ElementColour(SC_ELEMENT_CARET_LINE_BACK); + (caretLine.layer == Layer::Base) && lineContainsCaret) { + background = ElementColour(Element::CaretLineBack); } if (!background && marksOfLine) { int marks = marksOfLine; for (int markBit = 0; (markBit < 32) && marks; markBit++) { - if ((marks & 1) && (markers[markBit].markType == SC_MARK_BACKGROUND) && - (markers[markBit].layer == Layer::base)) { + if ((marks & 1) && (markers[markBit].markType == MarkerSymbol::Background) && + (markers[markBit].layer == Layer::Base)) { background = markers[markBit].back; } marks >>= 1; @@ -495,7 +497,7 @@ std::optional ViewStyle::Background(int marksOfLine, bool caretActiv if (marksMasked) { for (int markBit = 0; (markBit < 32) && marksMasked; markBit++) { if ((marksMasked & 1) && - (markers[markBit].layer == Layer::base)) { + (markers[markBit].layer == Layer::Base)) { background = markers[markBit].back; } marksMasked >>= 1; @@ -510,29 +512,29 @@ std::optional ViewStyle::Background(int marksOfLine, bool caretActiv } bool ViewStyle::SelectionBackgroundDrawn() const noexcept { - return selection.layer == Layer::base; + return selection.layer == Layer::Base; } bool ViewStyle::SelectionTextDrawn() const { return - ElementIsSet(SC_ELEMENT_SELECTION_TEXT) || - ElementIsSet(SC_ELEMENT_SELECTION_ADDITIONAL_TEXT) || - ElementIsSet(SC_ELEMENT_SELECTION_SECONDARY_TEXT) || - ElementIsSet(SC_ELEMENT_SELECTION_NO_FOCUS_TEXT); + ElementIsSet(Element::SelectionText) || + ElementIsSet(Element::SelectionAdditionalText) || + ElementIsSet(Element::SelectionSecondaryText) || + ElementIsSet(Element::SelectionNoFocusText); } bool ViewStyle::WhitespaceBackgroundDrawn() const { - return (viewWhitespace != WhiteSpace::invisible) && (ElementIsSet(SC_ELEMENT_WHITE_SPACE_BACK)); + return (viewWhitespace != WhiteSpace::Invisible) && (ElementIsSet(Element::WhiteSpaceBack)); } bool ViewStyle::WhiteSpaceVisible(bool inIndent) const noexcept { - return (!inIndent && viewWhitespace == WhiteSpace::visibleAfterIndent) || - (inIndent && viewWhitespace == WhiteSpace::visibleOnlyInIndent) || - viewWhitespace == WhiteSpace::visibleAlways; + return (!inIndent && viewWhitespace == WhiteSpace::VisibleAfterIndent) || + (inIndent && viewWhitespace == WhiteSpace::VisibleOnlyInIndent) || + viewWhitespace == WhiteSpace::VisibleAlways; } ColourRGBA ViewStyle::WrapColour() const { - return ElementColour(SC_ELEMENT_WHITE_SPACE).value_or(styles[STYLE_DEFAULT].fore); + return ElementColour(Element::WhiteSpace).value_or(styles[StyleDefault].fore); } // Insert new edge in sorted order. @@ -546,7 +548,7 @@ void ViewStyle::AddMultiEdge(uptr_t wParam, sptr_t lParam) { EdgeProperties(column, lParam)); } -std::optional ViewStyle::ElementColour(int element) const { +std::optional ViewStyle::ElementColour(Element element) const { ElementMap::const_iterator search = elementColours.find(element); if (search != elementColours.end()) { if (search->second.has_value()) { @@ -562,18 +564,18 @@ std::optional ViewStyle::ElementColour(int element) const { return {}; } -bool ViewStyle::ElementAllowsTranslucent(int element) const { +bool ViewStyle::ElementAllowsTranslucent(Element element) const { return elementAllowsTranslucent.count(element) > 0; } -bool ViewStyle::ResetElement(int element) { +bool ViewStyle::ResetElement(Element element) { ElementMap::const_iterator search = elementColours.find(element); const bool changed = (search != elementColours.end()) && (search->second.has_value()); elementColours.erase(element); return changed; } -bool ViewStyle::SetElementColour(int element, ColourRGBA colour) { +bool ViewStyle::SetElementColour(Element element, ColourRGBA colour) { ElementMap::const_iterator search = elementColours.find(element); const bool changed = (search == elementColours.end()) || @@ -582,7 +584,7 @@ bool ViewStyle::SetElementColour(int element, ColourRGBA colour) { return changed; } -bool ViewStyle::SetElementColourOptional(int element, uptr_t wParam, sptr_t lParam) { +bool ViewStyle::SetElementColourOptional(Element element, uptr_t wParam, sptr_t lParam) { if (wParam) { return SetElementColour(element, ColourRGBA::FromRGB(static_cast(lParam))); } else { @@ -590,17 +592,17 @@ bool ViewStyle::SetElementColourOptional(int element, uptr_t wParam, sptr_t lPar } } -void ViewStyle::SetElementRGB(int element, int rgb) { +void ViewStyle::SetElementRGB(Element element, int rgb) { const ColourRGBA current = ElementColour(element).value_or(ColourRGBA(0, 0, 0, 0)); elementColours[element] = ColourRGBA(ColourRGBA(rgb), current.GetAlpha()); } -void ViewStyle::SetElementAlpha(int element, int alpha) { +void ViewStyle::SetElementAlpha(Element element, int alpha) { const ColourRGBA current = ElementColour(element).value_or(ColourRGBA(0, 0, 0, 0)); elementColours[element] = ColourRGBA(current, std::min(alpha, 0xff)); } -bool ViewStyle::ElementIsSet(int element) const { +bool ViewStyle::ElementIsSet(Element element) const { ElementMap::const_iterator search = elementColours.find(element); if (search != elementColours.end()) { return search->second.has_value(); @@ -608,7 +610,7 @@ bool ViewStyle::ElementIsSet(int element) const { return false; } -bool ViewStyle::SetElementBase(int element, ColourRGBA colour) { +bool ViewStyle::SetElementBase(Element element, ColourRGBA colour) { ElementMap::const_iterator search = elementBaseColours.find(element); const bool changed = (search == elementBaseColours.end()) || @@ -617,34 +619,19 @@ bool ViewStyle::SetElementBase(int element, ColourRGBA colour) { return changed; } -bool ViewStyle::SetWrapState(int wrapState_) noexcept { - WrapMode wrapStateWanted; - switch (wrapState_) { - case SC_WRAP_WORD: - wrapStateWanted = WrapMode::word; - break; - case SC_WRAP_CHAR: - wrapStateWanted = WrapMode::character; - break; - case SC_WRAP_WHITESPACE: - wrapStateWanted = WrapMode::whitespace; - break; - default: - wrapStateWanted = WrapMode::none; - break; - } - const bool changed = wrap.state != wrapStateWanted; - wrap.state = wrapStateWanted; +bool ViewStyle::SetWrapState(Wrap wrapState_) noexcept { + const bool changed = wrap.state != wrapState_; + wrap.state = wrapState_; return changed; } -bool ViewStyle::SetWrapVisualFlags(int wrapVisualFlags_) noexcept { +bool ViewStyle::SetWrapVisualFlags(WrapVisualFlag wrapVisualFlags_) noexcept { const bool changed = wrap.visualFlags != wrapVisualFlags_; wrap.visualFlags = wrapVisualFlags_; return changed; } -bool ViewStyle::SetWrapVisualFlagsLocation(int wrapVisualFlagsLocation_) noexcept { +bool ViewStyle::SetWrapVisualFlagsLocation(WrapVisualLocation wrapVisualFlagsLocation_) noexcept { const bool changed = wrap.visualFlagsLocation != wrapVisualFlagsLocation_; wrap.visualFlagsLocation = wrapVisualFlagsLocation_; return changed; @@ -656,45 +643,45 @@ bool ViewStyle::SetWrapVisualStartIndent(int wrapVisualStartIndent_) noexcept { return changed; } -bool ViewStyle::SetWrapIndentMode(int wrapIndentMode_) noexcept { +bool ViewStyle::SetWrapIndentMode(WrapIndentMode wrapIndentMode_) noexcept { const bool changed = wrap.indentMode != wrapIndentMode_; wrap.indentMode = wrapIndentMode_; return changed; } bool ViewStyle::IsBlockCaretStyle() const noexcept { - return ((caret.style & CARETSTYLE_INS_MASK) == CARETSTYLE_BLOCK) || - (caret.style & CARETSTYLE_OVERSTRIKE_BLOCK) != 0; + return ((caret.style & CaretStyle::InsMask) == CaretStyle::Block) || + (FlagSet(caret.style, CaretStyle::OverstrikeBlock)) != 0; } bool ViewStyle::IsCaretVisible() const noexcept { - return caret.width > 0 && caret.style != CARETSTYLE_INVISIBLE; + return caret.width > 0 && caret.style != CaretStyle::Invisible; } bool ViewStyle::DrawCaretInsideSelection(bool inOverstrike, bool imeCaretBlockOverride) const noexcept { - if (caret.style & CARETSTYLE_BLOCK_AFTER) + if (FlagSet(caret.style, CaretStyle::BlockAfter)) return false; - return ((caret.style & CARETSTYLE_INS_MASK) == CARETSTYLE_BLOCK) || - (inOverstrike && (caret.style & CARETSTYLE_OVERSTRIKE_BLOCK) != 0) || + return ((caret.style & CaretStyle::InsMask) == CaretStyle::Block) || + (inOverstrike && (FlagSet(caret.style, CaretStyle::OverstrikeBlock)) != 0) || imeCaretBlockOverride; } ViewStyle::CaretShape ViewStyle::CaretShapeForMode(bool inOverstrike) const noexcept { if (inOverstrike) { - return (caret.style & CARETSTYLE_OVERSTRIKE_BLOCK) ? CaretShape::block : CaretShape::bar; + return (FlagSet(caret.style, CaretStyle::OverstrikeBlock)) ? CaretShape::block : CaretShape::bar; } - const int caretStyle = caret.style & CARETSTYLE_INS_MASK; - return (caretStyle <= CARETSTYLE_BLOCK) ? static_cast(caretStyle) : CaretShape::line; + const CaretStyle caretStyle = caret.style & CaretStyle::InsMask; + return (caretStyle <= CaretStyle::Block) ? static_cast(caretStyle) : CaretShape::line; } void ViewStyle::AllocStyles(size_t sizeNew) { size_t i=styles.size(); styles.resize(sizeNew); - if (styles.size() > STYLE_DEFAULT) { + if (styles.size() > StyleDefault) { for (; i