From 3900cfec27c0337477491b56568dcdaf7f34f428 Mon Sep 17 00:00:00 2001 From: New Pagodi Date: Mon, 18 Mar 2019 22:54:47 -0500 Subject: [PATCH] Add AutoCompSetColours method to stc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With some system themes, the default colors used for a list box can be hard to read or otherwise unsuitable for use with an autocompletion popup. This method lets a user manually specify colours for the list box’s background, text, selection background, and selected text. --- src/stc/PlatWX.cpp | 54 +++++++++++++++++++++++++++++++++----- src/stc/PlatWX.h | 2 ++ src/stc/ScintillaWX.cpp | 9 +++++++ src/stc/ScintillaWX.h | 2 ++ src/stc/stc.cpp.in | 8 ++++++ src/stc/stc.h.in | 5 ++++ src/stc/stc.interface.h.in | 24 +++++++++++++++++ 7 files changed, 97 insertions(+), 7 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 1d5fa51fc1..244960c93a 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -2321,6 +2321,8 @@ public: // Colour data void ComputeColours(); const wxColour& GetBorderColour() const; + void SetColours(const wxColour&, const wxColour&, + const wxColour&,const wxColour&); const wxColour& GetBgColour() const; const wxColour& GetTextColour() const; const wxColour& GetHighlightBgColour() const; @@ -2337,9 +2339,16 @@ private: wxColour m_textColour; wxColour m_highlightBgColour; wxColour m_highlightTextColour; + bool m_bgColourIsSet; + bool m_textColourIsSet; + bool m_highlightBgColourIsSet; + bool m_highlightTextColourIsSet; }; -wxSTCListBoxVisualData::wxSTCListBoxVisualData(int d):m_desiredVisibleRows(d) +wxSTCListBoxVisualData::wxSTCListBoxVisualData(int d):m_desiredVisibleRows(d), + m_bgColourIsSet(false), m_textColourIsSet(false), + m_highlightBgColourIsSet(false), + m_highlightTextColourIsSet(false) { ComputeColours(); } @@ -2419,17 +2428,42 @@ void wxSTCListBoxVisualData::ComputeColours() // wxSYS_COLOUR_BTNSHADOW seems to be the closest match with most themes. m_borderColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW ); - m_bgColour = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX); - m_textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT); + if ( !m_bgColourIsSet ) + m_bgColour = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX); + + if ( !m_textColourIsSet ) + m_textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT); #ifdef __WXOSX_COCOA__ - m_highlightBgColour = GetListHighlightColour(); + if ( !m_highlightBgColourIsSet ) + m_highlightBgColour = GetListHighlightColour(); #else - m_highlightBgColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); + if ( !m_highlightBgColourIsSet ) + m_highlightBgColour = + wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); #endif - m_highlightTextColour = - wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT); + if ( !m_highlightTextColourIsSet ) + m_highlightTextColour = + wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT); +} + +void SetColourHelper(bool& isSet, wxColour& itemCol, const wxColour& newColour) +{ + isSet = newColour.IsOk(); + itemCol = newColour; +} + +void wxSTCListBoxVisualData::SetColours(const wxColour& bg, + const wxColour& txt, + const wxColour& hlbg, + const wxColour& hltext) +{ + SetColourHelper(m_bgColourIsSet, m_bgColour, bg); + SetColourHelper(m_textColourIsSet, m_textColour, txt); + SetColourHelper(m_highlightBgColourIsSet, m_highlightBgColour, hlbg); + SetColourHelper(m_highlightTextColourIsSet, m_highlightTextColour, hltext); + ComputeColours(); } const wxColour& wxSTCListBoxVisualData::GetBorderColour() const @@ -2974,6 +3008,12 @@ void ListBoxImpl::SetDoubleClickAction(CallBackAction action, void *data) { m_listBox->SetDoubleClickAction(action, data); } +void ListBoxImpl::SetColours(const wxColour& background, const wxColour& text, + const wxColour& hiliBg, const wxColour& hiliText) +{ + m_visualData->SetColours(background, text, hiliBg, hiliText); +} + ListBox::ListBox() { } diff --git a/src/stc/PlatWX.h b/src/stc/PlatWX.h index 52c7eb92c9..2540e5e927 100644 --- a/src/stc/PlatWX.h +++ b/src/stc/PlatWX.h @@ -49,6 +49,8 @@ public: virtual void ClearRegisteredImages() wxOVERRIDE; virtual void SetDoubleClickAction(CallBackAction, void *) wxOVERRIDE; virtual void SetList(const char* list, char separator, char typesep) wxOVERRIDE; + void SetColours(const wxColour&, const wxColour&, + const wxColour&, const wxColour&); }; diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index de9bd8196d..7c5d1e5320 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -1337,6 +1337,15 @@ void ScintillaWX::DoRegisterImage(int type, const wxBitmap& bmp) { static_cast(ac.lb)->RegisterImageHelper(type, bmp); } +void ScintillaWX::SetListBoxColours(const wxColour& background, + const wxColour& text, + const wxColour& highlight, + const wxColour& highlightText) +{ + static_cast(ac.lb)->SetColours(background, text, + highlight, highlightText); +} + sptr_t ScintillaWX::DirectFunction( ScintillaWX* swx, unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return swx->WndProc(iMessage, wParam, lParam); diff --git a/src/stc/ScintillaWX.h b/src/stc/ScintillaWX.h index 92079170e3..a4ab484b10 100644 --- a/src/stc/ScintillaWX.h +++ b/src/stc/ScintillaWX.h @@ -201,6 +201,8 @@ public: void SetPaintAbandoned(){paintState = paintAbandoned;} void DoMarkerDefineBitmap(int markerNumber, const wxBitmap& bmp); void DoRegisterImage(int type, const wxBitmap& bmp); + void SetListBoxColours(const wxColour&, const wxColour&, + const wxColour&, const wxColour&); private: bool capturedMouse; diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index fb44624ab7..e6cb53a92e 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -573,6 +573,14 @@ void wxStyledTextCtrl::RegisterImage(int type, const wxBitmap& bmp) m_swx->DoRegisterImage(type, bmp); } +void wxStyledTextCtrl::AutoCompSetColours(const wxColour& background, + const wxColour& text, + const wxColour& highlight, + const wxColour& highlightText) +{ + m_swx->SetListBoxColours(background, text, highlight, highlightText); +} + diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index ef38ee1b20..4c75e1589a 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -304,6 +304,11 @@ public: // Register an image for use in autocompletion lists. void RegisterImage(int type, const wxBitmap& bmp); + // Set the colours used to display the items in an autocompletion list. + void AutoCompSetColours(const wxColour& background, const wxColour& text, + const wxColour& highlight, + const wxColour& highlightText); + // The following methods are nearly equivalent to their similarly named diff --git a/src/stc/stc.interface.h.in b/src/stc/stc.interface.h.in index f2ac38130b..e21f40f546 100644 --- a/src/stc/stc.interface.h.in +++ b/src/stc/stc.interface.h.in @@ -363,6 +363,30 @@ public: */ void RegisterImage(int type, const wxBitmap& bmp); + /** + Set the colours used to display the items in an autocompletion list. + + This method can be used if the default colours make the list hard to + read or if specific colours are desired for whatever reason. + @param background + The colour used for the background of the list. + @param text + The colour used for all text except for the selected item. + @param highlight + The colour used to highlight the selected item in the list. + @param highlightText + The colour used for the text of the selected item. + @remarks + To reset one or more of the colours to its default, + call this method with wxNullColour for the colour or colours + to be reset. + + @since 3.1.3 + */ + void AutoCompSetColours(const wxColour& background, const wxColour& text, + const wxColour& highlight, + const wxColour& highlightText); + //@}