Handle wxEVT_SYS_COLOUR_CHANGED in wxAUI classes

Update the colours used when the system theme changes.

This is especially important to use the colour scheme compatible with
macOS 10.14+ dark mode.

Note that this commit is best viewed with "git diff --color-moved".

Closes https://github.com/wxWidgets/wxWidgets/pull/916
This commit is contained in:
Daniel Kulp
2018-11-01 11:02:30 -04:00
committed by Vadim Zeitlin
parent 974b7c0990
commit 727a100a6a
11 changed files with 161 additions and 76 deletions

View File

@@ -141,6 +141,7 @@ All (GUI):
- Add wxJoystickEvent::GetButtonOrdinal() (Mick Phillips).
- Add wxGraphicsContext::GetWindow() and implement wxGraphicsContext::GetDPI().
- Add wxToolbook::EnablePage() (Stefan Ziegler).
- Adapt AUI colours to system colour changes (Daniel Kulp).
wxGTK:

View File

@@ -344,6 +344,10 @@ public:
virtual int ShowDropDown(
wxWindow* wnd,
const wxAuiToolBarItemArray& items) = 0;
// Provide opportunity for subclasses to recalculate colours
virtual void UpdateColoursFromSystem() {}
};
@@ -429,6 +433,8 @@ public:
virtual int ShowDropDown(wxWindow* wnd,
const wxAuiToolBarItemArray& items) wxOVERRIDE;
virtual void UpdateColoursFromSystem() wxOVERRIDE;
protected:
wxBitmap m_buttonDropDownBmp;
@@ -651,6 +657,7 @@ protected: // handlers
void OnLeaveWindow(wxMouseEvent& evt);
void OnCaptureLost(wxMouseCaptureLostEvent& evt);
void OnSetCursor(wxSetCursorEvent& evt);
void OnSysColourChanged(wxSysColourChangedEvent& event);
protected:

View File

@@ -226,6 +226,7 @@ protected:
void OnKillFocus(wxFocusEvent& event);
void OnChar(wxKeyEvent& event);
void OnCaptureLost(wxMouseCaptureLostEvent& evt);
void OnSysColourChanged(wxSysColourChangedEvent& event);
protected:
@@ -408,6 +409,7 @@ protected:
void OnTabRightUp(wxAuiNotebookEvent& evt);
void OnTabBgDClick(wxAuiNotebookEvent& evt);
void OnNavigationKeyNotebook(wxNavigationKeyEvent& event);
void OnSysColourChanged(wxSysColourChangedEvent& event);
// set selection to the given window (which must be non-NULL and be one of
// our pages, otherwise an assert is raised)

View File

@@ -76,6 +76,9 @@ public:
int buttonState,
const wxRect& rect,
wxAuiPaneInfo& pane) = 0;
// Provide opportunity for subclasses to recalculate colours
virtual void UpdateColoursFromSystem() {}
};
@@ -136,6 +139,9 @@ public:
wxAuiPaneInfo& pane);
#endif
virtual void UpdateColoursFromSystem() wxOVERRIDE;
protected:
void DrawCaptionBackground(wxDC& dc, const wxRect& rect, bool active);

View File

@@ -616,6 +616,7 @@ protected:
void OnChildFocus(wxChildFocusEvent& evt);
void OnHintFadeTimer(wxTimerEvent& evt);
void OnFindManager(wxAuiManagerEvent& evt);
void OnSysColourChanged(wxSysColourChangedEvent& event);
protected:

View File

@@ -109,6 +109,9 @@ public:
wxWindow* wnd,
const wxAuiNotebookPageArray& pages,
const wxSize& requiredBmpSize) = 0;
// Provide opportunity for subclasses to recalculate colours
virtual void UpdateColoursFromSystem() {}
};
@@ -185,6 +188,9 @@ public:
const wxAuiNotebookPageArray& pages,
const wxSize& requiredBmpSize) wxOVERRIDE;
// Provide opportunity for subclasses to recalculate colours
virtual void UpdateColoursFromSystem() wxOVERRIDE;
protected:
wxFont m_normalFont;

View File

@@ -124,28 +124,16 @@ const wxColour DISABLED_TEXT_COLOR(DISABLED_TEXT_GREY_HUE,
wxAuiGenericToolBarArt::wxAuiGenericToolBarArt()
{
m_baseColour = GetBaseColor();
UpdateColoursFromSystem();
m_flags = 0;
m_textOrientation = wxAUI_TBTOOL_TEXT_BOTTOM;
m_highlightColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
m_separatorSize = wxWindow::FromDIP( 7, NULL);
m_gripperSize = wxWindow::FromDIP( 7, NULL);
m_overflowSize = wxWindow::FromDIP(16, NULL);
m_dropdownSize = wxWindow::FromDIP(10, NULL);
wxColor darker1Colour = m_baseColour.ChangeLightness(85);
wxColor darker2Colour = m_baseColour.ChangeLightness(75);
wxColor darker3Colour = m_baseColour.ChangeLightness(60);
wxColor darker4Colour = m_baseColour.ChangeLightness(50);
wxColor darker5Colour = m_baseColour.ChangeLightness(40);
int pen_width = wxWindow::FromDIP(1, NULL);
m_gripperPen1 = wxPen(darker5Colour, pen_width);
m_gripperPen2 = wxPen(darker3Colour, pen_width);
m_gripperPen3 = wxPen(*wxWHITE, pen_width);
// TODO: Provide x1.5 and x2.0 versions or migrate to SVG.
static const unsigned char buttonDropdownBits[] = { 0xe0, 0xf1, 0xfb };
static const unsigned char overflowBits[] = { 0x80, 0xff, 0x80, 0xc1, 0xe3, 0xf7 };
@@ -165,13 +153,27 @@ wxAuiGenericToolBarArt::~wxAuiGenericToolBarArt()
{
m_font = *wxNORMAL_FONT;
}
wxAuiToolBarArt* wxAuiGenericToolBarArt::Clone()
{
return static_cast<wxAuiToolBarArt*>(new wxAuiGenericToolBarArt);
}
void wxAuiGenericToolBarArt::UpdateColoursFromSystem()
{
m_baseColour = GetBaseColor();
m_highlightColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
wxColor darker1Colour = m_baseColour.ChangeLightness(85);
wxColor darker2Colour = m_baseColour.ChangeLightness(75);
wxColor darker3Colour = m_baseColour.ChangeLightness(60);
wxColor darker4Colour = m_baseColour.ChangeLightness(50);
wxColor darker5Colour = m_baseColour.ChangeLightness(40);
int pen_width = wxWindow::FromDIP(1, NULL);
m_gripperPen1 = wxPen(darker5Colour, pen_width);
m_gripperPen2 = wxPen(darker3Colour, pen_width);
m_gripperPen3 = wxPen(*wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE), pen_width);
}
void wxAuiGenericToolBarArt::SetFlags(unsigned int flags)
{
m_flags = flags;
@@ -858,6 +860,7 @@ wxBEGIN_EVENT_TABLE(wxAuiToolBar, wxControl)
EVT_LEAVE_WINDOW(wxAuiToolBar::OnLeaveWindow)
EVT_MOUSE_CAPTURE_LOST(wxAuiToolBar::OnCaptureLost)
EVT_SET_CURSOR(wxAuiToolBar::OnSetCursor)
EVT_SYS_COLOUR_CHANGED(wxAuiToolBar::OnSysColourChanged)
wxEND_EVENT_TABLE()
void wxAuiToolBar::Init()
@@ -2428,6 +2431,14 @@ void wxAuiToolBar::UpdateWindowUI(long flags)
wxControl::UpdateWindowUI(flags);
}
void wxAuiToolBar::OnSysColourChanged(wxSysColourChangedEvent& event)
{
event.Skip();
m_art->UpdateColoursFromSystem();
Refresh();
}
void wxAuiToolBar::OnPaint(wxPaintEvent& WXUNUSED(evt))
{
wxAutoBufferedPaintDC dc(this);

View File

@@ -998,6 +998,7 @@ wxBEGIN_EVENT_TABLE(wxAuiTabCtrl, wxControl)
EVT_KILL_FOCUS(wxAuiTabCtrl::OnKillFocus)
EVT_CHAR(wxAuiTabCtrl::OnChar)
EVT_MOUSE_CAPTURE_LOST(wxAuiTabCtrl::OnCaptureLost)
EVT_SYS_COLOUR_CHANGED(wxAuiTabCtrl::OnSysColourChanged)
wxEND_EVENT_TABLE()
@@ -1028,6 +1029,16 @@ void wxAuiTabCtrl::OnPaint(wxPaintEvent&)
Render(&dc, this);
}
void wxAuiTabCtrl::OnSysColourChanged(wxSysColourChangedEvent &event)
{
event.Skip();
if (m_art)
{
m_art->UpdateColoursFromSystem();
}
}
void wxAuiTabCtrl::OnEraseBackground(wxEraseEvent& WXUNUSED(evt))
{
}
@@ -1669,8 +1680,30 @@ wxBEGIN_EVENT_TABLE(wxAuiNotebook, wxControl)
wxEVT_AUINOTEBOOK_BG_DCLICK,
wxAuiNotebook::OnTabBgDClick)
EVT_NAVIGATION_KEY(wxAuiNotebook::OnNavigationKeyNotebook)
EVT_SYS_COLOUR_CHANGED(wxAuiNotebook::OnSysColourChanged)
wxEND_EVENT_TABLE()
void wxAuiNotebook::OnSysColourChanged(wxSysColourChangedEvent &event)
{
event.Skip(true);
wxAuiTabArt* art = m_tabs.GetArtProvider();
art->UpdateColoursFromSystem();
wxAuiPaneInfoArray& all_panes = m_mgr.GetAllPanes();
size_t i, pane_count = all_panes.GetCount();
for (i = 0; i < pane_count; ++i)
{
wxAuiPaneInfo& pane = all_panes.Item(i);
if (pane.name == wxT("dummy"))
continue;
wxTabFrame* tab_frame = (wxTabFrame*)pane.window;
wxAuiTabCtrl* tabctrl = tab_frame->m_tabs;
tabctrl->GetArtProvider()->UpdateColoursFromSystem();
tabctrl->Refresh();
}
Refresh();
}
void wxAuiNotebook::Init()
{
m_curPage = -1;

View File

@@ -156,48 +156,7 @@ wxString wxAuiChopText(wxDC& dc, const wxString& text, int max_size)
wxAuiDefaultDockArt::wxAuiDefaultDockArt()
{
#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
#else
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
#endif
// the baseColour is too pale to use as our base colour,
// so darken it a bit --
if ((255-baseColour.Red()) +
(255-baseColour.Green()) +
(255-baseColour.Blue()) < 60)
{
baseColour = baseColour.ChangeLightness(92);
}
m_baseColour = baseColour;
wxColor darker1Colour = baseColour.ChangeLightness(85);
wxColor darker2Colour = baseColour.ChangeLightness(75);
wxColor darker3Colour = baseColour.ChangeLightness(60);
//wxColor darker4Colour = baseColour.ChangeLightness(50);
wxColor darker5Colour = baseColour.ChangeLightness(40);
m_activeCaptionColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
m_activeCaptionGradientColour = wxAuiLightContrastColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
m_activeCaptionTextColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
m_inactiveCaptionColour = darker1Colour;
m_inactiveCaptionGradientColour = baseColour.ChangeLightness(97);
#ifdef __WXMAC__
m_inactiveCaptionTextColour = wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT);
#else
m_inactiveCaptionTextColour = *wxBLACK;
#endif
m_sashBrush = wxBrush(baseColour);
m_backgroundBrush = wxBrush(baseColour);
m_gripperBrush = wxBrush(baseColour);
m_borderPen = wxPen(darker2Colour);
int pen_width = wxWindow::FromDIP(1, NULL);
m_gripperPen1 = wxPen(darker5Colour, pen_width);
m_gripperPen2 = wxPen(darker3Colour, pen_width);
m_gripperPen3 = wxPen(*wxWHITE, pen_width);
UpdateColoursFromSystem();
#ifdef __WXMAC__
m_captionFont = *wxSMALL_FONT;
@@ -296,6 +255,53 @@ wxAuiDefaultDockArt::InitBitmaps ()
m_activePinBitmap = wxAuiBitmapFromBits(pin_bits, 16, 16, m_activeCaptionTextColour);
}
void wxAuiDefaultDockArt::UpdateColoursFromSystem()
{
#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
#else
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
#endif
// the baseColour is too pale to use as our base colour,
// so darken it a bit --
if ((255-baseColour.Red()) +
(255-baseColour.Green()) +
(255-baseColour.Blue()) < 60)
{
baseColour = baseColour.ChangeLightness(92);
}
m_baseColour = baseColour;
wxColor darker1Colour = baseColour.ChangeLightness(85);
wxColor darker2Colour = baseColour.ChangeLightness(75);
wxColor darker3Colour = baseColour.ChangeLightness(60);
//wxColor darker4Colour = baseColour.ChangeLightness(50);
wxColor darker5Colour = baseColour.ChangeLightness(40);
m_activeCaptionColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
m_activeCaptionGradientColour = wxAuiLightContrastColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
m_activeCaptionTextColour = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
m_inactiveCaptionColour = darker1Colour;
m_inactiveCaptionGradientColour = baseColour.ChangeLightness(97);
#ifdef __WXMAC__
m_inactiveCaptionTextColour = wxSystemSettings::GetColour(wxSYS_COLOUR_INACTIVECAPTIONTEXT);
#else
m_inactiveCaptionTextColour = *wxBLACK;
#endif
m_sashBrush = wxBrush(baseColour);
m_backgroundBrush = wxBrush(baseColour);
m_gripperBrush = wxBrush(baseColour);
m_borderPen = wxPen(darker2Colour);
int pen_width = wxWindow::FromDIP(1, NULL);
m_gripperPen1 = wxPen(darker5Colour, pen_width);
m_gripperPen2 = wxPen(darker3Colour, pen_width);
m_gripperPen3 = wxPen(*wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE), pen_width);
InitBitmaps();
}
int wxAuiDefaultDockArt::GetMetric(int id)
{
switch (id)

View File

@@ -604,6 +604,7 @@ wxBEGIN_EVENT_TABLE(wxAuiManager, wxEvtHandler)
EVT_MOUSE_CAPTURE_LOST(wxAuiManager::OnCaptureLost)
EVT_CHILD_FOCUS(wxAuiManager::OnChildFocus)
EVT_AUI_FIND_MANAGER(wxAuiManager::OnFindManager)
EVT_SYS_COLOUR_CHANGED(wxAuiManager::OnSysColourChanged)
wxEND_EVENT_TABLE()
@@ -648,6 +649,13 @@ wxAuiManager::~wxAuiManager()
delete m_art;
}
void wxAuiManager::OnSysColourChanged(wxSysColourChangedEvent& event)
{
m_art->UpdateColoursFromSystem();
m_frame->Refresh();
event.Skip(true);
}
// creates a floating frame for the windows
wxAuiFloatingFrame* wxAuiManager::CreateFloatingFrame(wxWindow* parent,
const wxAuiPaneInfo& paneInfo)

View File

@@ -164,6 +164,29 @@ wxAuiGenericTabArt::wxAuiGenericTabArt()
m_fixedTabWidth = wxWindow::FromDIP(100, NULL);
m_tabCtrlHeight = 0;
UpdateColoursFromSystem();
m_activeCloseBmp = wxAuiBitmapFromBits(close_bits, 16, 16, *wxBLACK);
m_disabledCloseBmp = wxAuiBitmapFromBits(close_bits, 16, 16, wxColour(128,128,128));
m_activeLeftBmp = wxAuiBitmapFromBits(left_bits, 16, 16, *wxBLACK);
m_disabledLeftBmp = wxAuiBitmapFromBits(left_bits, 16, 16, wxColour(128,128,128));
m_activeRightBmp = wxAuiBitmapFromBits(right_bits, 16, 16, *wxBLACK);
m_disabledRightBmp = wxAuiBitmapFromBits(right_bits, 16, 16, wxColour(128,128,128));
m_activeWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, *wxBLACK);
m_disabledWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, wxColour(128,128,128));
m_flags = 0;
}
wxAuiGenericTabArt::~wxAuiGenericTabArt()
{
}
void wxAuiGenericTabArt::UpdateColoursFromSystem()
{
#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
wxColor baseColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
#else
@@ -186,24 +209,6 @@ wxAuiGenericTabArt::wxAuiGenericTabArt()
m_borderPen = wxPen(borderColour);
m_baseColourPen = wxPen(m_baseColour);
m_baseColourBrush = wxBrush(m_baseColour);
m_activeCloseBmp = wxAuiBitmapFromBits(close_bits, 16, 16, *wxBLACK);
m_disabledCloseBmp = wxAuiBitmapFromBits(close_bits, 16, 16, wxColour(128,128,128));
m_activeLeftBmp = wxAuiBitmapFromBits(left_bits, 16, 16, *wxBLACK);
m_disabledLeftBmp = wxAuiBitmapFromBits(left_bits, 16, 16, wxColour(128,128,128));
m_activeRightBmp = wxAuiBitmapFromBits(right_bits, 16, 16, *wxBLACK);
m_disabledRightBmp = wxAuiBitmapFromBits(right_bits, 16, 16, wxColour(128,128,128));
m_activeWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, *wxBLACK);
m_disabledWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, wxColour(128,128,128));
m_flags = 0;
}
wxAuiGenericTabArt::~wxAuiGenericTabArt()
{
}
wxAuiTabArt* wxAuiGenericTabArt::Clone()
@@ -919,7 +924,6 @@ wxAuiSimpleTabArt::wxAuiSimpleTabArt()
m_activeWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, *wxBLACK);
m_disabledWindowListBmp = wxAuiBitmapFromBits(list_bits, 16, 16, wxColour(128,128,128));
}
wxAuiSimpleTabArt::~wxAuiSimpleTabArt()