From: Vadim Zeitlin Date: Sat, 8 Dec 2001 00:26:30 +0000 (+0000) Subject: fixes for handling WM_SYSCOLORCHANGE - now seems to work X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/23895080c2666917f1c4ff2e40e327451a5fbcbf?ds=inline fixes for handling WM_SYSCOLORCHANGE - now seems to work git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12922 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/univ/window.h b/include/wx/univ/window.h index baabd53502..cfe3c89bb7 100644 --- a/include/wx/univ/window.h +++ b/include/wx/univ/window.h @@ -200,11 +200,6 @@ public: // we refresh the window when it is dis/enabled virtual bool Enable(bool enable = TRUE); - // remember that the font/colour was changed - virtual bool SetBackgroundColour(const wxColour& colour); - virtual bool SetForegroundColour(const wxColour& colour); - virtual bool SetFont(const wxFont& font); - // our Capture/ReleaseMouse() maintains the stack of windows which had // captured the mouse and when ReleaseMouse() is called, the mouse freed // only if the stack is empty, otherwise it is captured back by the window @@ -272,11 +267,8 @@ protected: int m_alignBgBitmap; wxStretch m_stretchBgBitmap; - // more flags - bool m_isCurrent:1; // is the mouse currently inside the window? - bool m_hasBgCol:1; // was the bg colour explicitly changed by user? - bool m_hasFgCol:1; // fg - bool m_hasFont:1; // font + // is the mouse currently inside the window? + bool m_isCurrent:1; private: // the window scrollbars diff --git a/include/wx/window.h b/include/wx/window.h index 4be6c62c95..3abbf6a330 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: window.h +// Name: wx/window.h // Purpose: wxWindowBase class - the interface of wxWindow // Author: Vadim Zeitlin // Modified by: @@ -823,6 +823,11 @@ protected: bool m_isEnabled:1; bool m_isBeingDeleted:1; + // was the window colours/font explicitly changed by user? + bool m_hasBgCol:1; + bool m_hasFgCol:1; + bool m_hasFont:1; + // window attributes long m_windowStyle, m_exStyle; diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 26df7cc81f..c052a11bb4 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -637,6 +637,8 @@ bool wxWindowBase::SetBackgroundColour( const wxColour &colour ) m_backgroundColour = colour; + m_hasBgCol = TRUE; + return TRUE; } @@ -647,6 +649,8 @@ bool wxWindowBase::SetForegroundColour( const wxColour &colour ) m_foregroundColour = colour; + m_hasFgCol = TRUE; + return TRUE; } @@ -678,6 +682,8 @@ bool wxWindowBase::SetFont(const wxFont& font) m_font = fontOk; + m_hasFont = TRUE; + return TRUE; } diff --git a/src/msw/control.cpp b/src/msw/control.cpp index b3f223c210..5454e029f9 100644 --- a/src/msw/control.cpp +++ b/src/msw/control.cpp @@ -46,9 +46,6 @@ END_EVENT_TABLE() // Item members wxControl::wxControl() { - m_backgroundColour = *wxWHITE; - m_foregroundColour = *wxBLACK; - #if WXWIN_COMPATIBILITY m_callback = 0; #endif // WXWIN_COMPATIBILITY diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 5b4cbc254a..2979f857d5 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -3257,7 +3257,11 @@ bool wxWindowMSW::HandleSysColorChange() wxSysColourChangedEvent event; event.SetEventObject(this); - return GetEventHandler()->ProcessEvent(event); + (void)GetEventHandler()->ProcessEvent(event); + + // always let the system carry on the default processing to allow the + // native controls to react to the colours update + return FALSE; } bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush, @@ -3324,19 +3328,35 @@ bool wxWindowMSW::HandleQueryNewPalette() // Responds to colour changes: passes event on to children. void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& event) { - wxNode *node = GetChildren().First(); + wxWindowList::Node *node = GetChildren().GetFirst(); while ( node ) { - // Only propagate to non-top-level windows - wxWindow *win = (wxWindow *)node->Data(); - if ( win->GetParent() ) + // Only propagate to non-top-level windows because Windows already + // sends this event to all top-level ones + wxWindow *win = node->GetData(); + if ( !win->IsTopLevel() ) { - wxSysColourChangedEvent event2; - event.m_eventObject = win; - win->GetEventHandler()->ProcessEvent(event2); + // we need to send the real WM_SYSCOLORCHANGE and not just trigger + // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for + // the standard controls + ::SendMessage(GetHwndOf(win), WM_SYSCOLORCHANGE, 0, 0); } - node = node->Next(); + node = node->GetNext(); + } + + // update the colours we use if they were not set explicitly by the user: + // this must be done or OnCtlColor() would continue to use the old colours + if ( !m_hasFgCol ) + { + m_foregroundColour = wxSystemSettings:: + GetSystemColour(wxSYS_COLOUR_WINDOWTEXT); + } + + if ( !m_hasBgCol ) + { + m_backgroundColour = wxSystemSettings:: + GetSystemColour(wxSYS_COLOUR_BTNFACE); } } diff --git a/src/univ/winuniv.cpp b/src/univ/winuniv.cpp index a7430cb2e4..2727e0b89a 100644 --- a/src/univ/winuniv.cpp +++ b/src/univ/winuniv.cpp @@ -938,40 +938,6 @@ wxRect wxWindow::ScrollNoRefresh(int dx, int dy, const wxRect *rectTotal) return rect; } -// ---------------------------------------------------------------------------- -// colours/fonts -// ---------------------------------------------------------------------------- - -bool wxWindow::SetBackgroundColour(const wxColour& colour) -{ - if ( !wxWindowNative::SetBackgroundColour(colour) ) - return FALSE; - - m_hasBgCol = TRUE; - - return TRUE; -} - -bool wxWindow::SetForegroundColour(const wxColour& colour) -{ - if ( !wxWindowNative::SetForegroundColour(colour) ) - return FALSE; - - m_hasFgCol = TRUE; - - return TRUE; -} - -bool wxWindow::SetFont(const wxFont& font) -{ - if ( !wxWindowNative::SetFont(font) ) - return FALSE; - - m_hasFont = TRUE; - - return TRUE; -} - // ---------------------------------------------------------------------------- // mouse capture // ----------------------------------------------------------------------------