From 942fcf8285fd3a7b9043f0a24004bbefcaefb3fc Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Thu, 26 Jun 2025 13:33:57 +0200 Subject: [PATCH] Don't use hard-coded expander sizes in wxPropertyGrid Use wxRendererNative::GetExpanderSize() instead. Update the tests to work with the bigger expander. Fixes #25571 --- src/propgrid/propgrid.cpp | 57 +++++++++++++++------------------ tests/controls/propgridtest.cpp | 6 +--- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 1dd8362bb7..9d19beb4d4 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -412,11 +412,11 @@ void wxPropertyGrid::Init1() m_doubleBuffer = nullptr; #ifndef wxPG_ICON_WIDTH - m_iconWidth = 11; - m_iconHeight = 11; + m_iconWidth = FromDIP(11); + m_iconHeight = FromDIP(11); #else - m_iconWidth = wxPG_ICON_WIDTH; - m_iconHeight = wxPG_ICON_WIDTH; + m_iconWidth = FromDIP(wxPG_ICON_WIDTH); + m_iconHeight = FromDIP(wxPG_ICON_WIDTH); #endif m_gutterWidth = wxPG_GUTTER_MIN; @@ -1314,19 +1314,14 @@ void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing ) m_subgroup_extramargin = x + (x/2); m_fontHeight = y; -#if wxPG_USE_RENDERER_NATIVE - m_iconWidth = FromDIP(wxPG_ICON_WIDTH); -#elif wxPG_ICON_WIDTH - // scale icon - m_iconWidth = (m_fontHeight * wxPG_ICON_WIDTH) / 13; - if ( m_iconWidth < 5 ) m_iconWidth = 5; - else if ( !(m_iconWidth & 0x01) ) m_iconWidth++; // must be odd - -#endif - #ifdef wxPG_ICON_WIDTH - // Icons are always square in this case. - m_iconHeight = m_iconWidth; +#if wxPG_USE_RENDERER_NATIVE + wxSize iconSize = wxRendererNative::Get().GetExpanderSize(this); +#else + wxSize iconSize = wxRendererNative::GetGeneric().GetExpanderSize(this); +#endif + m_iconWidth = iconSize.GetWidth(); + m_iconHeight = iconSize.GetHeight(); #endif m_gutterWidth = m_iconWidth / wxPG_GUTTER_DIV; @@ -1963,23 +1958,21 @@ void wxPropertyGrid::DrawExpanderButton( wxDC& dc, const wxRect& rect, // wxRenderer functions are non-mutating in nature, so it // should be safe to cast "const wxPropertyGrid*" to "wxWindow*". // Hopefully this does not cause problems. -#if wxPG_USE_RENDERER_NATIVE - wxRendererNative::Get().DrawTreeItemButton( - const_cast(this), - dc, - r, - property->IsExpanded() ? wxCONTROL_EXPANDED : wxCONTROL_NONE - ); -#elif wxPG_ICON_WIDTH - wxRendererNative::GetGeneric().DrawTreeItemButton( - const_cast(this), - dc, - r, - property->IsExpanded() ? wxCONTROL_EXPANDED : wxCONTROL_NONE - ); -#else +#ifndef wxPG_ICON_WIDTH wxBitmap bmp = property->IsExpanded() ? s_collbmp : s_expandbmp; - dc.DrawBitmap( bmp, r.x, r.y, true ); + dc.DrawBitmap(bmp, r.x, r.y, true); +#else +#if wxPG_USE_RENDERER_NATIVE + wxRendererNative::Get(). +#else + wxRendererNative::GetGeneric(). +#endif + DrawTreeItemButton( + const_cast(this), + dc, + r, + property->IsExpanded() ? wxCONTROL_EXPANDED : wxCONTROL_NONE + ); #endif } diff --git a/tests/controls/propgridtest.cpp b/tests/controls/propgridtest.cpp index c9560ed59c..db2f6a0b9b 100644 --- a/tests/controls/propgridtest.cpp +++ b/tests/controls/propgridtest.cpp @@ -1460,11 +1460,7 @@ TEST_CASE("PropertyGridTestCase", "[propgrid]") SECTION("SetSplitterPosition") { -#ifndef __WXQT__ - const int trySplitterPos = wxTheApp->GetTopWindow()->FromDIP(50); -#else - const int trySplitterPos = 51; // FIXME! -#endif + const int trySplitterPos = wxTheApp->GetTopWindow()->FromDIP(60); int style = wxPG_AUTO_SORT; // wxPG_SPLITTER_AUTO_CENTER; ReplaceGrid(pgManager, style, -1);