From 727a100a6ac8815058c37f8827c5c93044166b37 Mon Sep 17 00:00:00 2001 From: Daniel Kulp Date: Thu, 1 Nov 2018 11:02:30 -0400 Subject: [PATCH] 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 --- docs/changes.txt | 1 + include/wx/aui/auibar.h | 7 +++ include/wx/aui/auibook.h | 2 + include/wx/aui/dockart.h | 6 +++ include/wx/aui/framemanager.h | 1 + include/wx/aui/tabart.h | 6 +++ src/aui/auibar.cpp | 41 ++++++++++------ src/aui/auibook.cpp | 33 +++++++++++++ src/aui/dockart.cpp | 90 +++++++++++++++++++---------------- src/aui/framemanager.cpp | 8 ++++ src/aui/tabart.cpp | 42 ++++++++-------- 11 files changed, 161 insertions(+), 76 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 37e3a5e8ac..3cf2901ca5 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/include/wx/aui/auibar.h b/include/wx/aui/auibar.h index 2ee3c02d24..274757d88e 100644 --- a/include/wx/aui/auibar.h +++ b/include/wx/aui/auibar.h @@ -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: diff --git a/include/wx/aui/auibook.h b/include/wx/aui/auibook.h index c6d232e48d..2571f7d9ac 100644 --- a/include/wx/aui/auibook.h +++ b/include/wx/aui/auibook.h @@ -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) diff --git a/include/wx/aui/dockart.h b/include/wx/aui/dockart.h index 48ee31bc25..bb931d7acc 100644 --- a/include/wx/aui/dockart.h +++ b/include/wx/aui/dockart.h @@ -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); diff --git a/include/wx/aui/framemanager.h b/include/wx/aui/framemanager.h index 300e767125..2e6cf222e3 100644 --- a/include/wx/aui/framemanager.h +++ b/include/wx/aui/framemanager.h @@ -616,6 +616,7 @@ protected: void OnChildFocus(wxChildFocusEvent& evt); void OnHintFadeTimer(wxTimerEvent& evt); void OnFindManager(wxAuiManagerEvent& evt); + void OnSysColourChanged(wxSysColourChangedEvent& event); protected: diff --git a/include/wx/aui/tabart.h b/include/wx/aui/tabart.h index 47efe359e3..f11e75b4ba 100644 --- a/include/wx/aui/tabart.h +++ b/include/wx/aui/tabart.h @@ -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; diff --git a/src/aui/auibar.cpp b/src/aui/auibar.cpp index c0b67db7ae..f31bb456a9 100644 --- a/src/aui/auibar.cpp +++ b/src/aui/auibar.cpp @@ -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(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); diff --git a/src/aui/auibook.cpp b/src/aui/auibook.cpp index f1298c9997..9bfe2a7589 100644 --- a/src/aui/auibook.cpp +++ b/src/aui/auibook.cpp @@ -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; diff --git a/src/aui/dockart.cpp b/src/aui/dockart.cpp index 870f5c2d68..7168307302 100644 --- a/src/aui/dockart.cpp +++ b/src/aui/dockart.cpp @@ -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) diff --git a/src/aui/framemanager.cpp b/src/aui/framemanager.cpp index a57599fcb5..6c20bea464 100644 --- a/src/aui/framemanager.cpp +++ b/src/aui/framemanager.cpp @@ -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) diff --git a/src/aui/tabart.cpp b/src/aui/tabart.cpp index 993f6f8605..97667be5fa 100644 --- a/src/aui/tabart.cpp +++ b/src/aui/tabart.cpp @@ -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()