From 84c566bb051c39d09145ac7589f777b03b99bf08 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 15 May 2017 22:26:15 +0200 Subject: [PATCH] Minor cleanup in wxMSW wxSpinCtrl::Create() No real changes, just explain the real reason why we can't create the windows with the correct sizes and need to set them later (it's not because of the font but because UDM_SETBUDDY changes them) and also use a helper "effectiveSpinWidth" variable. --- src/msw/spinctrl.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/msw/spinctrl.cpp b/src/msw/spinctrl.cpp index 8c50bfef6e..1b47c3e428 100644 --- a/src/msw/spinctrl.cpp +++ b/src/msw/spinctrl.cpp @@ -340,20 +340,23 @@ bool wxSpinCtrl::Create(wxWindow *parent, if (!m_hasFont) SetFont(GetDefaultAttributes().font); - // finally deal with the size, now that both windows are created and the - // font is set - const wxSize sizeBtn = wxSpinButton::DoGetBestSize(); + // Finally deal with the size: notice that this can only be done now both + // windows are created and the text one is set up as buddy because + // UDM_SETBUDDY changes its size using some unknown algorithm, so setting + // the sizes earlier is useless. + const int bestSpinWidth = wxSpinButton::DoGetBestSize().x; + const int effectiveSpinWidth = bestSpinWidth - GetOverlap(); wxSize sizeCtrl(size); if ( sizeCtrl.x <= 0 ) { // DEFAULT_ITEM_WIDTH is the default width for the text control - sizeCtrl.x = FromDIP(DEFAULT_ITEM_WIDTH) + sizeBtn.x - GetOverlap(); + sizeCtrl.x = FromDIP(DEFAULT_ITEM_WIDTH) + effectiveSpinWidth; } - else if ( sizeCtrl.x <= sizeBtn.x ) + else if ( sizeCtrl.x <= effectiveSpinWidth ) { wxLogDebug(wxS("wxSpinCtrl \"%s\": initial width %d is too small, ") wxS("at least %d pixels needed."), - name, size.x, sizeBtn.x); + name, size.x, effectiveSpinWidth); } // adjust an invalid height for text control @@ -365,6 +368,7 @@ bool wxSpinCtrl::Create(wxWindow *parent, sizeCtrl.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); } + // This will call our DoMoveWindow() and lay out the windows correctly. SetInitialSize(sizeCtrl); (void)::ShowWindow(GetBuddyHwnd(), SW_SHOW);