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);