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.
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user