extract button size calculation from button label size to a separate function to allow reusing it elsewhere
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55474 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -49,6 +49,10 @@ void UpdateMultilineStyle(HWND hwnd, const wxString& label);
|
|||||||
// (implemented in src/msw/button.cpp)
|
// (implemented in src/msw/button.cpp)
|
||||||
wxSize ComputeBestSize(wxControl *btn);
|
wxSize ComputeBestSize(wxControl *btn);
|
||||||
|
|
||||||
|
// compute the button size (as if wxBU_EXACTFIT were specified, i.e. without
|
||||||
|
// adjusting it to be of default size if it's smaller) for the given label size
|
||||||
|
wxSize GetFittingSize(wxWindow *win, const wxSize& sizeLabel);
|
||||||
|
|
||||||
} // namespace wxMSWButton
|
} // namespace wxMSWButton
|
||||||
|
|
||||||
#endif // _WX_MSW_PRIVATE_BUTTON_H_
|
#endif // _WX_MSW_PRIVATE_BUTTON_H_
|
||||||
|
@@ -163,33 +163,41 @@ void wxMSWButton::UpdateMultilineStyle(HWND hwnd, const wxString& label)
|
|||||||
::SetWindowLong(hwnd, GWL_STYLE, styleNew);
|
::SetWindowLong(hwnd, GWL_STYLE, styleNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxSize wxMSWButton::GetFittingSize(wxWindow *win, const wxSize& sizeLabel)
|
||||||
|
{
|
||||||
|
// FIXME: this is pure guesswork, need to retrieve the real button margins
|
||||||
|
wxSize sizeBtn = sizeLabel;
|
||||||
|
|
||||||
|
sizeBtn.x += 3*win->GetCharWidth();
|
||||||
|
sizeBtn.y = 11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(sizeLabel.y)/10;
|
||||||
|
|
||||||
|
return sizeBtn;
|
||||||
|
}
|
||||||
|
|
||||||
wxSize wxMSWButton::ComputeBestSize(wxControl *btn)
|
wxSize wxMSWButton::ComputeBestSize(wxControl *btn)
|
||||||
{
|
{
|
||||||
wxClientDC dc(btn);
|
wxClientDC dc(btn);
|
||||||
|
|
||||||
wxCoord wBtn,
|
wxSize sizeBtn;
|
||||||
hBtn;
|
dc.GetMultiLineTextExtent(btn->GetLabelText(), &sizeBtn.x, &sizeBtn.y);
|
||||||
dc.GetMultiLineTextExtent(btn->GetLabelText(), &wBtn, &hBtn);
|
|
||||||
|
|
||||||
// FIXME: this is pure guesswork, need to retrieve the real button margins
|
sizeBtn = GetFittingSize(btn, sizeBtn);
|
||||||
wBtn += 3*btn->GetCharWidth();
|
|
||||||
hBtn = 11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(hBtn)/10;
|
|
||||||
|
|
||||||
// all buttons have at least the standard size unless the user explicitly
|
// all buttons have at least the standard size unless the user explicitly
|
||||||
// wants them to be of smaller size and used wxBU_EXACTFIT style when
|
// wants them to be of smaller size and used wxBU_EXACTFIT style when
|
||||||
// creating the button
|
// creating the button
|
||||||
if ( !btn->HasFlag(wxBU_EXACTFIT) )
|
if ( !btn->HasFlag(wxBU_EXACTFIT) )
|
||||||
{
|
{
|
||||||
wxSize sz = wxButton::GetDefaultSize();
|
wxSize sizeDef = wxButton::GetDefaultSize();
|
||||||
if ( wBtn < sz.x )
|
if ( sizeBtn.x < sizeDef.x )
|
||||||
wBtn = sz.x;
|
sizeBtn.x = sizeDef.x;
|
||||||
if ( hBtn < sz.y )
|
if ( sizeBtn.y < sizeDef.y )
|
||||||
hBtn = sz.y;
|
sizeBtn.y = sizeDef.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize best(wBtn, hBtn);
|
btn->CacheBestSize(sizeBtn);
|
||||||
btn->CacheBestSize(best);
|
|
||||||
return best;
|
return sizeBtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user