Don't show labels for toolbars showing icons only in wxOSX

In For the toolbars in non-top orientation, calling SetToolShortHelp() also
showed the item label even if the toolbar was supposed to show the icons only.

Closes #16669.
This commit is contained in:
sbrowne
2016-02-23 01:44:50 +01:00
committed by Vadim Zeitlin
parent 899b56c4a7
commit 1f7cd4807f

View File

@@ -174,7 +174,13 @@ public:
void UpdateLabel()
{
wxString labelStr = wxStripMenuCodes(m_label);
// Use an empty string if we're not displaying text
wxString labelStr;
wxToolBar *tbar = (wxToolBar*) GetToolBar();
int style = (tbar ? tbar->GetWindowStyleFlag() : 0);
if ( (style & (wxTB_NOICONS | wxTB_TEXT)) != 0 )
labelStr = wxStripMenuCodes(m_label);
wxCFStringRef l(labelStr, GetToolBarFontEncoding());
wxCFStringRef sh( GetShortHelp(), GetToolBarFontEncoding() );
#if wxOSX_USE_NATIVE_TOOLBAR
@@ -189,7 +195,31 @@ public:
}
#endif
if ( IsButton() )
[(NSButton*)m_controlHandle setTitle:l.AsNSString()];
{
NSButton* const btn = (NSButton*)m_controlHandle;
[btn setTitle:l.AsNSString()];
if ( style & wxTB_NOICONS )
[btn setImagePosition:NSNoImage];
else if ( style & wxTB_TEXT )
[btn setImagePosition:NSImageAbove];
else
[btn setImagePosition:NSImageOnly];
if ( (style & (wxTB_NOICONS | wxTB_TEXT)) != 0 )
{
[btn sizeToFit];
}
else if (tbar)
{
wxSize toolsize = tbar->GetToolSize();
NSRect frame = [m_controlHandle frame];
frame.size.width = toolsize.x;
frame.size.height = toolsize.y + 2;
[btn setFrame:frame];
}
}
if ( m_controlHandle )
{
@@ -588,7 +618,11 @@ void wxToolBarTool::UpdateImages()
void wxToolBarTool::UpdateToggleImage( bool toggle )
{
#if wxOSX_USE_NATIVE_TOOLBAR
if (m_toolbarItem != NULL )
// Avoid setting the image if we're not showing icons because the image may
// be invalid.
wxToolBar *tbar = (wxToolBar*) GetToolBar();
int style = tbar ? tbar->GetWindowStyleFlag() : 0;
if ( m_toolbarItem != NULL && !(style & wxTB_NOICONS) )
{
// the native toolbar item only has a 'selected' state (one for one toolbar)
// so we emulate the toggle here
@@ -868,6 +902,21 @@ void wxToolBar::SetWindowStyleFlag( long style )
[(NSToolbar*) m_macToolbar setDisplayMode:mode];
}
#endif
wxToolBarTool *tool;
wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
while ( node )
{
tool = (wxToolBarTool *) node->GetData();
if ( tool != NULL )
{
tool->UpdateLabel();
}
node = node->GetNext();
}
InvalidateBestSize();
}
#if wxOSX_USE_NATIVE_TOOLBAR
@@ -1482,14 +1531,6 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
if ( !(style & wxTB_NOICONS) )
tool->UpdateImages();
tool->UpdateLabel();
if ( style & wxTB_NOICONS )
[v setImagePosition:NSNoImage];
else if ( style & wxTB_TEXT )
[v setImagePosition:NSImageAbove];
else
[v setImagePosition:NSImageOnly];
[v sizeToFit];
#if 0
InstallControlEventHandler(