From 73e23a4fd22c527cf7cf2e00500862b2d8c84537 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 21 Feb 2022 23:28:30 +0000 Subject: [PATCH 1/2] Revert "Improve calculating wxButton best size under wxMSW" This reverts commit de10f054c4b0557ee1d97f2420f884959e189d6a and a bunch of commits improving it done since then: 6f888df474 (Restore button size calculation when not using manifest in wxMSW, 2021-04-24) de10f054c4 (Improve calculating wxButton best size under wxMSW, 2021-04-08) 6f888df474 (Restore button size calculation when not using manifest in wxMSW, 2021-04-24) 75d508b6e6 (Fix regression in sizes of buttons with bitmaps in wxMSW, 2021-07-08) 051418ac00 (Fix recent wxMSW buttons with bitmaps appearance regression, 2021-08-26) fbc6462375 (Fix a gcc warning introduced by the previous commit, 2021-08-26) The reason for reverting is that using BCM_GETIDEALSIZE doesn't seem to have any advantages compared to using our old code, as it doesn't take the margins into account neither and we still have to add them ourselves and so it's simpler to just always do it without using this message. --- include/wx/msw/anybutton.h | 1 - src/msw/anybutton.cpp | 76 +++++++++++--------------------------- 2 files changed, 21 insertions(+), 56 deletions(-) diff --git a/include/wx/msw/anybutton.h b/include/wx/msw/anybutton.h index d6def3d6fd..be548f4468 100644 --- a/include/wx/msw/anybutton.h +++ b/include/wx/msw/anybutton.h @@ -59,7 +59,6 @@ protected: // Should only be called if we do have a button, i.e. if m_imageData is // non-NULL. void AdjustForBitmapSize(wxSize& size) const; - void AdjustForBitmapMargins(wxSize& size) const; class wxButtonImageData *m_imageData; diff --git a/src/msw/anybutton.cpp b/src/msw/anybutton.cpp index cf72f305fd..34fad4a94f 100644 --- a/src/msw/anybutton.cpp +++ b/src/msw/anybutton.cpp @@ -75,11 +75,6 @@ using namespace wxMSWImpl; #endif #endif // wxUSE_UXTHEME -// BCM_GETIDEALSIZE is defined since XP -#ifndef BCM_GETIDEALSIZE - #define BCM_GETIDEALSIZE 0x1601 -#endif // BCM_GETIDEALSIZE - #ifndef ODS_NOACCEL #define ODS_NOACCEL 0x0100 #endif @@ -640,16 +635,6 @@ void wxAnyButton::AdjustForBitmapSize(wxSize &size) const size.x = sizeBmp.x; } - // and also for the margins we always add internally (unless we have no - // border at all in which case the button has exactly the same size as - // bitmap and so no margins should be used) - AdjustForBitmapMargins(size); -} - -void wxAnyButton::AdjustForBitmapMargins(wxSize& size) const -{ - wxCHECK_RET(m_imageData, wxT("shouldn't be called if no image")); - // and also for the margins we always add internally (unless we have no // border at all in which case the button has exactly the same size as // bitmap and so no margins should be used) @@ -699,52 +684,33 @@ wxSize wxAnyButton::DoGetBestSize() const wxSize size; - // The preferred way is to use BCM_GETIDEALSIZE, but it only works properly - // if there is a text label in the button and can't be used under old - // systems or without a manifest. - if ( !IsOwnerDrawn() && ShowsLabel() && - wxGetWinVersion() >= wxWinVersion_Vista ) + // Account for the text part if we have it. + if ( ShowsLabel() ) { - SIZE idealSize = { 0, 0 }; - if ( ::SendMessage(GetHwnd(), BCM_GETIDEALSIZE, 0, (LPARAM)&idealSize) ) - size.Set(idealSize.cx, idealSize.cy); - - if ( m_imageData ) - AdjustForBitmapMargins(size); - } - - // If we failed to set the size using BCM_GETIDEALSIZE above, determine it - // ourselves. - if ( size == wxSize() ) - { - // Account for the text part if we have it. - if ( ShowsLabel() ) - { - int flags = 0; - if ( HasFlag(wxBU_EXACTFIT) ) - flags |= wxMSWButton::Size_ExactFit; - if ( DoGetAuthNeeded() ) - flags |= wxMSWButton::Size_AuthNeeded; + int flags = 0; + if ( HasFlag(wxBU_EXACTFIT) ) + flags |= wxMSWButton::Size_ExactFit; + if ( DoGetAuthNeeded() ) + flags |= wxMSWButton::Size_AuthNeeded; #if wxUSE_MARKUP - if ( m_markupText ) - { - wxClientDC dc(self); - size = wxMSWButton::GetFittingSize(self, - m_markupText->Measure(dc), - flags); - } - else // Normal plain text (but possibly multiline) label. -#endif // wxUSE_MARKUP - { - size = wxMSWButton::ComputeBestFittingSize(self, flags); - } + if ( m_markupText ) + { + wxClientDC dc(self); + size = wxMSWButton::GetFittingSize(self, + m_markupText->Measure(dc), + flags); + } + else // Normal plain text (but possibly multiline) label. +#endif // wxUSE_MARKUP + { + size = wxMSWButton::ComputeBestFittingSize(self, flags); } - - if ( m_imageData ) - AdjustForBitmapSize(size); } + if ( m_imageData ) + AdjustForBitmapSize(size); + return wxMSWButton::IncreaseToStdSizeAndCache(self, size); } From 5d3a544db13f4d86694c5473cdd3e196a72419c6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 21 Feb 2022 23:34:36 +0000 Subject: [PATCH 2/2] Decrease the margin used for wxBU_EXACTFIT in wxMSW This should achieve the same result as de10f054c4 (Improve calculating wxButton best size under wxMSW, 2021-04-08) but in a much simpler way. --- src/msw/anybutton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/msw/anybutton.cpp b/src/msw/anybutton.cpp index 34fad4a94f..409dfc407d 100644 --- a/src/msw/anybutton.cpp +++ b/src/msw/anybutton.cpp @@ -515,7 +515,7 @@ wxSize wxMSWButton::GetFittingSize(wxWindow *win, { // We still need some margin or the text would be overwritten, just // make it as small as possible. - sizeBtn.x += 2*win->GetCharWidth(); + sizeBtn.x += win->GetCharWidth(); } else {