From bc81682e7fb651ce479e112b267b5621a6c1ffb2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 7 Apr 2022 23:32:05 +0100 Subject: [PATCH] Refactor wxWindowDisabler to allow skipping more than one window This is not implemented yet, but this commit changes DoDisable() to disable all windows except those in the list of the windows not to be disabled instead of explicitly checking for just a single window to skip. Rename m_winDisabled to m_windowsToSkip to better describe its purpose and also because it's a vector, and so should use plural form in its name. Finally note that AfterDisable() is called with NULL argument from the ctor not taking the window to skip for compatibility with the old code, but it's not clear if it's really the right thing to do and perhaps this shouldn't be done. No real changes yet. --- include/wx/utils.h | 6 +++--- src/common/utilscmn.cpp | 30 ++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/wx/utils.h b/include/wx/utils.h index b522ec1f51..54d06f2fbd 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -739,8 +739,8 @@ public: ~wxWindowDisabler(); private: - // disable all windows except the given one (used by both ctors) - void DoDisable(wxWindow *winToSkip = NULL); + // disable all windows not in m_windowsToSkip + void DoDisable(); #if defined(__WXOSX__) && wxOSX_USE_COCOA void AfterDisable(wxWindow* winToSkip); @@ -748,7 +748,7 @@ private: wxEventLoop* m_modalEventLoop = NULL; #endif - wxVector m_winDisabled; + wxVector m_windowsToSkip; bool m_disabled; wxDECLARE_NO_COPY_CLASS(wxWindowDisabler); diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 4294dbb115..6dcc445618 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -1517,16 +1517,30 @@ wxWindowDisabler::wxWindowDisabler(bool disable) { m_disabled = disable; if ( disable ) + { DoDisable(); + +#if defined(__WXOSX__) && wxOSX_USE_COCOA + AfterDisable(NULL); +#endif + } } wxWindowDisabler::wxWindowDisabler(wxWindow *winToSkip) { m_disabled = true; - DoDisable(winToSkip); + + if ( winToSkip ) + m_windowsToSkip.push_back(winToSkip); + + DoDisable(); + +#if defined(__WXOSX__) && wxOSX_USE_COCOA + AfterDisable(winToSkip); +#endif } -void wxWindowDisabler::DoDisable(wxWindow *winToSkip) +void wxWindowDisabler::DoDisable() { // remember the top level windows which were already disabled, so that we // don't reenable them later @@ -1534,7 +1548,7 @@ void wxWindowDisabler::DoDisable(wxWindow *winToSkip) for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() ) { wxWindow *winTop = node->GetData(); - if ( winTop == winToSkip ) + if ( wxVectorContains(m_windowsToSkip, winTop) ) continue; // we don't need to disable the hidden or already disabled windows @@ -1544,13 +1558,9 @@ void wxWindowDisabler::DoDisable(wxWindow *winToSkip) } else { - m_winDisabled.push_back(winTop); + m_windowsToSkip.push_back(winTop); } } - -#if defined(__WXOSX__) && wxOSX_USE_COCOA - AfterDisable(winToSkip); -#endif } wxWindowDisabler::~wxWindowDisabler() @@ -1566,11 +1576,11 @@ wxWindowDisabler::~wxWindowDisabler() for ( node = wxTopLevelWindows.GetFirst(); node; node = node->GetNext() ) { wxWindow *winTop = node->GetData(); - if ( !wxVectorContains(m_winDisabled, winTop) ) + if ( !wxVectorContains(m_windowsToSkip, winTop) ) { winTop->Enable(); } - //else: had been already disabled, don't reenable + //else: we didn't disable this window, so don't reenable it neither } }