From b18ebec9568bcfc59b3c22d45c37fd73bdf1718c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 27 Aug 2011 14:11:28 +0000 Subject: [PATCH] Make wxBU_EXACTFIT fir the button text more exactly. Too big margins were added for the buttons with wxBU_EXACTFIT style making them larger than strictly necessary. Reduce the margins to make them really as small as possible. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68922 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/private/button.h | 3 ++- src/msw/anybutton.cpp | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/wx/msw/private/button.h b/include/wx/msw/private/button.h index 1e6336197d..2f344f2d53 100644 --- a/include/wx/msw/private/button.h +++ b/include/wx/msw/private/button.h @@ -44,7 +44,8 @@ void UpdateMultilineStyle(HWND hwnd, const wxString& label); // flags for ComputeBestSize() and GetFittingSize() enum { - Size_AuthNeeded = 1 + Size_AuthNeeded = 1, + Size_ExactFit = 2 }; // NB: All the functions below are implemented in src/msw/button.cpp diff --git a/src/msw/anybutton.cpp b/src/msw/anybutton.cpp index 2603cdfdf3..a2382422e7 100644 --- a/src/msw/anybutton.cpp +++ b/src/msw/anybutton.cpp @@ -387,11 +387,21 @@ wxSize wxMSWButton::GetFittingSize(wxWindow *win, const wxSize& sizeLabel, int flags) { - // FIXME: this is pure guesswork, need to retrieve the real button margins wxSize sizeBtn = sizeLabel; - sizeBtn.x += 3*win->GetCharWidth(); - sizeBtn.y += win->GetCharHeight()/2; + // FIXME: The numbers here are pure guesswork, no idea how should the + // button margins be really calculated. + if ( flags & Size_ExactFit ) + { + // We still need some margin or the text would be overwritten, just + // make it as small as possible. + sizeBtn.x += (3*win->GetCharWidth())/2; + } + else + { + sizeBtn.x += 3*win->GetCharWidth(); + sizeBtn.y += win->GetCharHeight()/2; + } // account for the shield UAC icon if we have it if ( flags & Size_AuthNeeded ) @@ -555,6 +565,8 @@ wxSize wxAnyButton::DoGetBestSize() const if ( ShowsLabel() ) { int flags = 0; + if ( HasFlag(wxBU_EXACTFIT) ) + flags |= wxMSWButton::Size_ExactFit; if ( DoGetAuthNeeded() ) flags |= wxMSWButton::Size_AuthNeeded; -- 2.45.2