Reuse helper MSWGetFittingtSizeForControl() in a couple of places
Refactor the code to reuse the same function for determining the size needed by an embedded control in the toolbar, including its label.
This commit is contained in:
@@ -183,6 +183,10 @@ private:
|
|||||||
return HasFlag(wxTB_TEXT) && !HasFlag(wxTB_NOICONS);
|
return HasFlag(wxTB_TEXT) && !HasFlag(wxTB_NOICONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the size required to accommodate the given tool which must be of
|
||||||
|
// "control" type.
|
||||||
|
wxSize MSWGetFittingtSizeForControl(class wxToolBarTool* tool) const;
|
||||||
|
|
||||||
|
|
||||||
wxDECLARE_EVENT_TABLE();
|
wxDECLARE_EVENT_TABLE();
|
||||||
wxDECLARE_DYNAMIC_CLASS(wxToolBar);
|
wxDECLARE_DYNAMIC_CLASS(wxToolBar);
|
||||||
|
@@ -530,6 +530,31 @@ wxToolBar::~wxToolBar()
|
|||||||
delete m_disabledImgList;
|
delete m_disabledImgList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxSize wxToolBar::MSWGetFittingtSizeForControl(wxToolBarTool* tool) const
|
||||||
|
{
|
||||||
|
wxSize size = tool->GetControl()->GetBestSize();
|
||||||
|
|
||||||
|
// Account for the label, if any.
|
||||||
|
if ( wxStaticText * const staticText = tool->GetStaticText() )
|
||||||
|
{
|
||||||
|
if ( AreControlLabelsShown() )
|
||||||
|
{
|
||||||
|
const wxSize sizeLabel = staticText->GetSize();
|
||||||
|
|
||||||
|
if ( size.x < sizeLabel.x )
|
||||||
|
size.x = sizeLabel.x;
|
||||||
|
|
||||||
|
size.y += sizeLabel.y;
|
||||||
|
size.y += MARGIN_CONTROL_LABEL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also account for the tool padding value.
|
||||||
|
size += wxSize(m_toolPacking, m_toolPacking);
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
wxSize wxToolBar::DoGetBestSize() const
|
wxSize wxToolBar::DoGetBestSize() const
|
||||||
{
|
{
|
||||||
wxSize sizeBest;
|
wxSize sizeBest;
|
||||||
@@ -578,10 +603,8 @@ wxSize wxToolBar::DoGetBestSize() const
|
|||||||
tool = static_cast<wxToolBarTool *>(node->GetData());
|
tool = static_cast<wxToolBarTool *>(node->GetData());
|
||||||
if (tool->IsControl())
|
if (tool->IsControl())
|
||||||
{
|
{
|
||||||
int y = tool->GetControl()->GetSize().y;
|
// Ensure we're tall enough for the embedded controls.
|
||||||
// Approximate border size
|
sizeBest.IncTo(wxSize(-1, MSWGetFittingtSizeForControl(tool).y));
|
||||||
if (y > (sizeBest.y - 4))
|
|
||||||
sizeBest.y = y + 4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1057,8 +1080,8 @@ bool wxToolBar::Realize()
|
|||||||
// taking into account tool padding value.
|
// taking into account tool padding value.
|
||||||
// (height is not used but it is set for the sake of consistency).
|
// (height is not used but it is set for the sake of consistency).
|
||||||
{
|
{
|
||||||
const wxSize sizeControl = tool->GetControl()->GetSize();
|
const wxSize size = MSWGetFittingtSizeForControl(tool);
|
||||||
button.iBitmap = m_toolPacking + (IsVertical() ? sizeControl.y : sizeControl.x);
|
button.iBitmap = size.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFALLTHROUGH;
|
wxFALLTHROUGH;
|
||||||
|
Reference in New Issue
Block a user