From 50f70a8bb42fc982350731da104b042ae75b1df2 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 10 May 2021 14:33:37 +1000 Subject: Add elementBaseColours to hold default or system derived colours. Editor::UpdateBaseElements can be overridden by platform layers to set base colours although they should also do this when they detect changes in system settings. --- src/Editor.cxx | 6 +++++- src/Editor.h | 1 + src/ViewStyle.cxx | 32 ++++++++++++++++++++++++++++++++ src/ViewStyle.h | 4 ++++ 4 files changed, 42 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Editor.cxx b/src/Editor.cxx index f843a08d2..477173c6b 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5089,6 +5089,10 @@ void Editor::SetFocusState(bool focusState) { ShowCaretAtCurrentPosition(); } +void Editor::UpdateBaseElements() { + // Overridden by subclasses +} + Sci::Position Editor::PositionAfterArea(PRectangle rcArea) const { // The start of the document line after the display line after the area // This often means that the line after a modification is restyled which helps @@ -7199,7 +7203,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return vs.ElementColour(static_cast(wParam)).value_or(ColourAlpha()).OpaqueRGB(); case SCI_RESETELEMENTCOLOUR: - vs.elementColours[static_cast(wParam)].reset(); + vs.ResetElement(static_cast(wParam)); break; case SCI_GETELEMENTISSET: diff --git a/src/Editor.h b/src/Editor.h index ae3f0ef5a..42944929b 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -526,6 +526,7 @@ protected: // ScintillaBase subclass needs access to much of Editor virtual void SetMouseCapture(bool on) = 0; virtual bool HaveMouseCapture() = 0; void SetFocusState(bool focusState); + virtual void UpdateBaseElements(); Sci::Position PositionAfterArea(PRectangle rcArea) const; void StyleToPositionInView(Sci::Position pos); diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx index 58af810b8..16701983e 100644 --- a/src/ViewStyle.cxx +++ b/src/ViewStyle.cxx @@ -523,6 +523,12 @@ std::optional ViewStyle::ElementColour(int element) const { return search->second; } } + ElementMap::const_iterator searchBase = elementBaseColours.find(element); + if (searchBase != elementBaseColours.end()) { + if (searchBase->second.has_value()) { + return searchBase->second; + } + } return {}; } @@ -530,6 +536,32 @@ bool ViewStyle::ElementAllowsTranslucent(int element) const { return elementAllowsTranslucent.count(element) > 0; } +void ViewStyle::ResetElement(int element) { + elementColours.erase(element); +} + +bool ViewStyle::ElementIsSet(int element) const { + ElementMap::const_iterator search = elementColours.find(element); + if (search != elementColours.end()) { + return search->second.has_value(); + } + return false; +} + +bool ViewStyle::SetElementBase(int element, ColourAlpha colour) { + bool different = false; + ElementMap::const_iterator search = elementBaseColours.find(element); + if (search == elementBaseColours.end()) { + different = true; + } else { + if (search->second.has_value() && !(*search->second == colour)) { + different = true; + } + } + elementBaseColours[element] = colour; + return different; +} + bool ViewStyle::SetWrapState(int wrapState_) noexcept { WrapMode wrapStateWanted; switch (wrapState_) { diff --git a/src/ViewStyle.h b/src/ViewStyle.h index 4118f0daf..a9fe58131 100644 --- a/src/ViewStyle.h +++ b/src/ViewStyle.h @@ -203,6 +203,7 @@ public: using ElementMap = std::map>; ElementMap elementColours; + ElementMap elementBaseColours; std::set elementAllowsTranslucent; WrapAppearance wrap; @@ -243,6 +244,9 @@ public: std::optional ElementColour(int element) const; bool ElementAllowsTranslucent(int element) const; + void ResetElement(int element); + bool ElementIsSet(int element) const; + bool SetElementBase(int element, ColourAlpha colour); bool SetWrapState(int wrapState_) noexcept; bool SetWrapVisualFlags(int wrapVisualFlags_) noexcept; -- cgit v1.2.3