Add AutoCompSetColours method to stc
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.
This commit is contained in:
@@ -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() {
|
||||
}
|
||||
|
@@ -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&);
|
||||
};
|
||||
|
||||
|
||||
|
@@ -1337,6 +1337,15 @@ void ScintillaWX::DoRegisterImage(int type, const wxBitmap& bmp) {
|
||||
static_cast<ListBoxImpl*>(ac.lb)->RegisterImageHelper(type, bmp);
|
||||
}
|
||||
|
||||
void ScintillaWX::SetListBoxColours(const wxColour& background,
|
||||
const wxColour& text,
|
||||
const wxColour& highlight,
|
||||
const wxColour& highlightText)
|
||||
{
|
||||
static_cast<ListBoxImpl*>(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);
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user