@interface wxNSToolbarDelegate : NSObject wxOSX_10_6_AND_LATER(<NSToolbarDelegate>)
{
+ bool m_isSelectable;
}
+- (void)setSelectable:(bool) value;
+
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag;
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;
@implementation wxNSToolbarDelegate
+- (id)init
+{
+ m_isSelectable = false;
+ return [super init];
+}
+
+- (void)setSelectable:(bool) value
+{
+ m_isSelectable = true;
+}
+
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
wxUnusedVar(toolbar);
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
{
- wxUnusedVar(toolbar);
- return nil;
+ if ( m_isSelectable )
+ return [[toolbar items] valueForKey:@"itemIdentifier"];
+ else
+ return nil;
}
- (NSToolbarItem*) toolbar:(NSToolbar*) toolbar itemForItemIdentifier:(NSString*) itemIdentifier willBeInsertedIntoToolbar:(BOOL) flag
event.Skip();
}
+#if wxOSX_USE_NATIVE_TOOLBAR
+void wxToolBar::OSXSetSelectableTools(bool set)
+{
+ wxCHECK_RET( m_macToolbar, "toolbar must be non-NULL" );
+ [(wxNSToolbarDelegate*)[(NSToolbar*)m_macToolbar delegate] setSelectable:set];
+}
+
+void wxToolBar::OSXSelectTool(int toolId)
+{
+ wxToolBarToolBase *tool = FindById(toolId);
+ wxCHECK_RET( tool, "invalid tool ID" );
+ wxCHECK_RET( m_macToolbar, "toolbar must be non-NULL" );
+
+ wxString identifier = wxString::Format(wxT("%ld"), (long)tool);
+ wxCFStringRef cfidentifier(identifier, wxFont::GetDefaultEncoding());
+ [(NSToolbar*)m_macToolbar setSelectedItemIdentifier:cfidentifier.AsNSString()];
+}
+#endif // wxOSX_USE_NATIVE_TOOLBAR
+
#endif // wxUSE_TOOLBAR