From b8a8f2e3ff043891c9a1c5b41742cd5d121d5bae Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 2 Jun 2026 01:32:40 +0200 Subject: [PATCH] Factor out wxPropertyGrid::ReallocDoubleBufferIfNeeded() No real changes, just extract the code (re)creating m_doubleBuffer into its own function to allow for its reuse in the upcoming commit. --- include/wx/propgrid/propgrid.h | 2 ++ src/propgrid/propgrid.cpp | 61 ++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index 25e3a560a5..016feef016 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -1882,6 +1882,8 @@ private: bool ButtonTriggerKeyTest(wxPGKeyboardAction action, wxKeyEvent& event); + void ReallocDoubleBufferIfNeeded(); + wxDECLARE_EVENT_TABLE(); }; diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 81f21378bd..88a3285e78 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -4561,6 +4561,38 @@ void wxPropertyGrid::RecalculateVirtualSize( int forceXPos ) // ----------------------------------------------------------------------- +void wxPropertyGrid::ReallocDoubleBufferIfNeeded() +{ + if ( !HasExtraStyle(wxPG_EX_NATIVE_DOUBLE_BUFFERING) ) + { + double scaleFactor = GetDPIScaleFactor(); + int dblh = (m_lineHeight*2); + if ( !m_doubleBuffer ) + { + // Create double buffer bitmap to draw on, if none + int w = wxMax(m_width, FromDIP(250)); + int h = wxMax(m_height + dblh, FromDIP(400)); + m_doubleBuffer = new wxBitmap; + m_doubleBuffer->CreateWithLogicalSize( w, h, scaleFactor ); + } + else + { + int w = m_doubleBuffer->GetLogicalWidth(); + int h = m_doubleBuffer->GetLogicalHeight(); + + // Double buffer must be large enough + if ( w < m_width || h < (m_height+dblh) ) + { + if ( w < m_width ) w = m_width; + if ( h < (m_height+dblh) ) h = m_height + dblh; + delete m_doubleBuffer; + m_doubleBuffer = new wxBitmap; + m_doubleBuffer->CreateWithLogicalSize( w, h, scaleFactor ); + } + } + } +} + void wxPropertyGrid::OnResize( wxSizeEvent& event ) { if ( !(m_iFlags & wxPG_FL_INITIALIZED) ) @@ -4572,34 +4604,7 @@ void wxPropertyGrid::OnResize( wxSizeEvent& event ) m_width = width; m_height = height; - if ( !HasExtraStyle(wxPG_EX_NATIVE_DOUBLE_BUFFERING) ) - { - double scaleFactor = GetDPIScaleFactor(); - int dblh = (m_lineHeight*2); - if ( !m_doubleBuffer ) - { - // Create double buffer bitmap to draw on, if none - int w = wxMax(width, FromDIP(250)); - int h = wxMax(height + dblh, FromDIP(400)); - m_doubleBuffer = new wxBitmap; - m_doubleBuffer->CreateWithLogicalSize( w, h, scaleFactor ); - } - else - { - int w = m_doubleBuffer->GetLogicalWidth(); - int h = m_doubleBuffer->GetLogicalHeight(); - - // Double buffer must be large enough - if ( w < width || h < (height+dblh) ) - { - if ( w < width ) w = width; - if ( h < (height+dblh) ) h = height + dblh; - delete m_doubleBuffer; - m_doubleBuffer = new wxBitmap; - m_doubleBuffer->CreateWithLogicalSize( w, h, scaleFactor ); - } - } - } + ReallocDoubleBufferIfNeeded(); m_pState->OnClientWidthChange( width, event.GetSize().x - m_ncWidth, true ); m_ncWidth = event.GetSize().x;