Use control current, not best, size in wxMSW wxToolBar layout code

Avoid allocating too much space to the control in the toolbar, it may
have been made smaller than its best size on purpose and, in any case,
we don't resize the control, so it's useless to allocate more space to
it than it's going to use.

See #18294.
This commit is contained in:
Vadim Zeitlin 2019-03-31 13:39:57 +02:00
parent 58d4b0e209
commit b0ad9ccffd
2 changed files with 5 additions and 2 deletions

View File

@ -443,7 +443,7 @@ void MyFrame::PopulateToolbar(wxToolBarBase* toolBar)
wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO, wxEmptyString, wxDefaultPosition, wxSize(100,-1) );
combo->Append("This");
combo->Append("is a");
combo->Append("combobox");
combo->Append("combobox with extremely, extremely, extremely, extremely long label");
combo->Append("in a");
combo->Append("toolbar");
toolBar->AddControl(combo, "Combo Label");

View File

@ -548,7 +548,10 @@ wxToolBar::~wxToolBar()
wxSize wxToolBar::MSWGetFittingtSizeForControl(wxToolBarTool* tool) const
{
wxSize size = tool->GetControl()->GetBestSize();
// Note that we intentionally use GetSize() and not GetBestSize() here as
// the control could have been added to the toolbar with the size less than
// its best size in order to avoid taking too much space.
wxSize size = tool->GetControl()->GetSize();
// This is arbitrary, but we want to leave at least 1px around the control
// vertically, otherwise it really looks too cramped.