return wxPoint( m_x, m_y );
}
- bool DoEnable( bool enable );
+ bool Enable( bool enable );
void UpdateImages();
{
wxToolBarToolBase::SetLabel(label);
UpdateLabel();
- }
+ }
+
+ virtual bool SetShortHelp(const wxString& help)
+ {
+ if ( !wxToolBarToolBase::SetShortHelp(help) )
+ return false;
+
+ UpdateLabel();
+
+ return true;
+ }
#endif // wxOSX_USE_NATIVE_TOOLBAR
private:
- (void)setImplementation: (wxToolBarTool *) theImplementation;
- (wxToolBarTool*) implementation;
- (void) clickedAction: (id) sender;
+- (BOOL) validateToolbarItem:(NSToolbarItem *)theItem;
@end
-@interface wxNSToolbarDelegate : NSObject
+@interface wxNSToolbarDelegate : NSObject wxOSX_10_6_AND_LATER(<NSToolbarDelegate>)
{
}
return impl;
}
+- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
+{
+ wxUnusedVar(theItem);
+ return impl->IsEnabled() ? YES:NO;
+}
+
@end
@implementation wxNSToolbarDelegate
@end
-bool wxToolBarTool::DoEnable( bool enable )
+bool wxToolBarTool::Enable( bool enable )
{
+ if ( wxToolBarToolBase::Enable( enable ) == false )
+ return false;
+
if ( IsControl() )
{
GetControl()->Enable( enable );
dc.SelectObject( m_alternateBitmap );
dc.SetPen( wxPen(*wxBLACK) );
dc.SetBrush( wxBrush( *wxLIGHT_GREY ));
- dc.DrawRectangle( 0, 0, w, h );
+ dc.DrawRoundedRectangle( 0, 0, w, h, 2 );
dc.DrawBitmap( m_bmpNormal, 0, 0, true );
dc.SelectObject( wxNullBitmap );
else
[m_toolbarItem setImage:m_bmpNormal.GetNSImage()];
}
+ else
#endif
+ {
+ [(NSButton*)m_controlHandle setState:(toggle ? NSOnState : NSOffState)];
+ }
}
wxToolBarTool::wxToolBarTool(
}
wxToolBar::~wxToolBar()
-{
-#if wxOSX_USE_NATIVE_TOOLBAR
- if (m_macToolbar != NULL)
- {
- // if this is the installed toolbar, then deinstall it
- if (m_macUsesNativeToolbar)
- MacInstallNativeToolbar( false );
-
- [(NSToolbar*)m_macToolbar setDelegate:nil];
- [(NSToolbar*)m_macToolbar release];
- m_macToolbar = NULL;
- }
-#endif
+{
+ [(NSToolbar*)m_macToolbar setDelegate:nil];
+ [(NSToolbar*)m_macToolbar release];
+ m_macToolbar = NULL;
}
bool wxToolBar::Show( bool show )
{
bResult = true;
[(NSToolbar*) m_macToolbar setVisible:NO];
- [tlw setToolbar:nil];
+ MacUninstallNativeToolbar();
m_peer->SetVisibility( true );
}
}
// wxLogDebug( wxT(" --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
return bResult;
}
+
+void wxToolBar::MacUninstallNativeToolbar()
+{
+ if (!m_macToolbar)
+ return;
+
+ WXWindow tlw = MacGetTopLevelWindowRef();
+ if (tlw)
+ [tlw setToolbar:nil];
+}
#endif
bool wxToolBar::Realize()
}
}
}
- wxString identifier = wxString::Format( wxT("%ld"), (long) tool );
- wxCFStringRef cfidentifier(identifier);
- [refTB insertItemWithItemIdentifier:cfidentifier.AsNSString() atIndex:currentPosition];
+ wxCFStringRef cfidentifier;
+ const NSString *nsItemId;
+ if (tool->GetStyle() == wxTOOL_STYLE_SEPARATOR)
+ {
+ nsItemId = tool->IsStretchable() ? NSToolbarFlexibleSpaceItemIdentifier
+ : NSToolbarSeparatorItemIdentifier;
+ }
+ else
+ {
+ cfidentifier = wxCFStringRef(wxString::Format("%ld", (long)tool));
+ nsItemId = cfidentifier.AsNSString();
+ }
+
+ [refTB insertItemWithItemIdentifier:nsItemId atIndex:currentPosition];
tool->SetIndex( currentPosition );
}
return wxEmptyString;
}
-void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable)
+void wxToolBar::DoEnableTool(wxToolBarToolBase * WXUNUSED(t), bool WXUNUSED(enable))
{
- if ( t != NULL )
- ((wxToolBarTool*)t)->DoEnable( enable );
+ // everything already done in the tool's Enable implementation
}
void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle)
#if wxOSX_USE_NATIVE_TOOLBAR
if (m_macToolbar != NULL)
{
- NSToolbarItem* item = [[NSToolbarItem alloc] initWithItemIdentifier:NSToolbarSeparatorItemIdentifier];
+ const NSString * const
+ nsItemId = tool->IsStretchable() ? NSToolbarFlexibleSpaceItemIdentifier
+ : NSToolbarSeparatorItemIdentifier;
+ NSToolbarItem* item = [[NSToolbarItem alloc] initWithItemIdentifier:nsItemId];
tool->SetToolbarItemRef( item );
}
#endif // wxOSX_USE_NATIVE_TOOLBAR
[v setBezelStyle:NSRegularSquareBezelStyle];
[v setBordered:NO];
- [v setButtonType: ( tool->CanBeToggled() ? NSOnOffButton : NSMomentaryPushInButton )];
+ [v setButtonType: ( tool->CanBeToggled() ? NSToggleButton : NSMomentaryPushInButton )];
[v setImplementation:tool];
controlHandle = v;