From 3e32e0fa678e4d314a050c24f5f067df14c1493d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 26 Dec 2023 19:26:42 +0100 Subject: [PATCH] Allow using non-live resize in wxAUI with wxGTK3/X11 In this case we can still use wxClientDC, so let people do it if they really want to for consistency with wxSplitterWindow and because it doesn't really cost us anything. --- include/wx/aui/framemanager.h | 2 +- interface/wx/aui/framemanager.h | 10 ++++++--- src/aui/framemanager.cpp | 36 +++++++++++++-------------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/include/wx/aui/framemanager.h b/include/wx/aui/framemanager.h index 167c486c35..0533a5b6f2 100644 --- a/include/wx/aui/framemanager.h +++ b/include/wx/aui/framemanager.h @@ -417,7 +417,7 @@ public: void SetFlags(unsigned int flags); unsigned int GetFlags() const; - static bool AlwaysUsesLiveResize(); + static bool AlwaysUsesLiveResize(const wxWindow* window = nullptr); bool HasLiveResize() const; void SetManagedWindow(wxWindow* managedWnd); diff --git a/interface/wx/aui/framemanager.h b/interface/wx/aui/framemanager.h index 549492f354..832b0282c8 100644 --- a/interface/wx/aui/framemanager.h +++ b/interface/wx/aui/framemanager.h @@ -219,12 +219,16 @@ public: If this function returns true, ::wxAUI_MGR_LIVE_RESIZE flag is ignored and live resize is always used, whether it's specified or not. - Currently this is the case for wxOSX and wxGTK3 ports, as live resizing - is the only implemented method there. + Currently this is the case for wxOSX and wxGTK3 when using Wayland, as + live resizing is the only implemented method there. See + wxClientDC::CanBeUsedForDrawing() for more details. + + @param window The associated window, may be null (this parameter was + added in wxWidgets 3.3.0) @since 3.1.4 */ - static bool AlwaysUsesLiveResize(); + static bool AlwaysUsesLiveResize(const wxWindow* window); /** This function is used by controls to calculate the drop hint rectangle. diff --git a/src/aui/framemanager.cpp b/src/aui/framemanager.cpp index 3d8af0aeb3..793e9498be 100644 --- a/src/aui/framemanager.cpp +++ b/src/aui/framemanager.cpp @@ -767,26 +767,17 @@ unsigned int wxAuiManager::GetFlags() const return m_flags; } -// With Core Graphics on Mac or GTK 3, it's not possible to show sash feedback, -// so we'll always use live update instead. -#if defined(__WXMAC__) || defined(__WXGTK3__) - #define wxUSE_AUI_LIVE_RESIZE_ALWAYS 1 -#else - #define wxUSE_AUI_LIVE_RESIZE_ALWAYS 0 -#endif - -/* static */ bool wxAuiManager::AlwaysUsesLiveResize() +/* static */ bool wxAuiManager::AlwaysUsesLiveResize(const wxWindow* window) { - return wxUSE_AUI_LIVE_RESIZE_ALWAYS; + // Not using live resize relies on wxClientDC being usable for drawing, so + // we have to use live resize if it can't be used on the current platform. + return !wxClientDC::CanBeUsedForDrawing(window); } bool wxAuiManager::HasLiveResize() const { -#if wxUSE_AUI_LIVE_RESIZE_ALWAYS - return true; -#else - return (GetFlags() & wxAUI_MGR_LIVE_RESIZE) == wxAUI_MGR_LIVE_RESIZE; -#endif + return AlwaysUsesLiveResize(m_frame) || + (GetFlags() & wxAUI_MGR_LIVE_RESIZE) == wxAUI_MGR_LIVE_RESIZE; } // don't use these anymore as they are deprecated @@ -3925,15 +3916,16 @@ void wxAuiManager::Repaint(wxDC* dc) // make a client dc if (!dc) { -#if wxUSE_AUI_LIVE_RESIZE_ALWAYS - // We can't use wxClientDC in these ports. - m_frame->Refresh() ; - m_frame->Update() ; - return ; -#else + if ( AlwaysUsesLiveResize(m_frame) ) + { + // We can't use wxClientDC in these ports. + m_frame->Refresh() ; + m_frame->Update() ; + return ; + } + client_dc.reset(new wxClientDC(m_frame)); dc = client_dc.get(); -#endif } int w, h;