Add small helper function to wxMSW wxToolBar code

Encapsulate the logic for deciding whether we should show the labels for
the embedded controls or not in a small helper function, to make it
simpler to change it in the future if needed and also to have a single
place to explain why do we do what we do now.

No real changes.
This commit is contained in:
Vadim Zeitlin
2019-02-24 02:03:23 +01:00
parent 4a02b73a6a
commit 82857cfa9d
2 changed files with 11 additions and 5 deletions

View File

@@ -174,6 +174,16 @@ private:
WXHBRUSH MSWGetToolbarBgBrush(); WXHBRUSH MSWGetToolbarBgBrush();
#endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
// Return true if we're showing the labels for the embedded controls: we
// only do it if text is enabled and, somewhat less expectedly, if icons
// are enabled too because showing both the control and its label when only
// text is shown for the other buttons is too inconsistent to be useful.
bool AreControlLabelsShown() const
{
return HasFlag(wxTB_TEXT) && !HasFlag(wxTB_NOICONS);
}
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
wxDECLARE_DYNAMIC_CLASS(wxToolBar); wxDECLARE_DYNAMIC_CLASS(wxToolBar);
wxDECLARE_NO_COPY_CLASS(wxToolBar); wxDECLARE_NO_COPY_CLASS(wxToolBar);

View File

@@ -1050,11 +1050,7 @@ bool wxToolBar::Realize()
case wxTOOL_STYLE_CONTROL: case wxTOOL_STYLE_CONTROL:
if ( wxStaticText *staticText = tool->GetStaticText() ) if ( wxStaticText *staticText = tool->GetStaticText() )
{ {
// Display control and its label only if buttons have icons staticText->Show(AreControlLabelsShown());
// and texts as otherwise there is not enough room on the
// toolbar to fit the label.
staticText->
Show(HasFlag(wxTB_TEXT) && !HasFlag(wxTB_NOICONS));
} }
// Set separator width/height to fit the control width/height // Set separator width/height to fit the control width/height