X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a7689c49fe02c0c065facf736ab28b19f5997b7c..48e05747043db02c4e9d2e286eca4fdf5dee7881:/src/osx/cocoa/toolbar.mm diff --git a/src/osx/cocoa/toolbar.mm b/src/osx/cocoa/toolbar.mm index 4293801329..1a989ddd6c 100644 --- a/src/osx/cocoa/toolbar.mm +++ b/src/osx/cocoa/toolbar.mm @@ -305,8 +305,11 @@ private: @interface wxNSToolbarDelegate : NSObject wxOSX_10_6_AND_LATER() { + bool m_isSelectable; } +- (void)setSelectable:(bool) value; + - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag; - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar; @@ -363,6 +366,17 @@ private: @implementation wxNSToolbarDelegate +- (id)init +{ + m_isSelectable = false; + return [super init]; +} + +- (void)setSelectable:(bool) value +{ + m_isSelectable = true; +} + - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar { wxUnusedVar(toolbar); @@ -377,8 +391,10 @@ private: - (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 @@ -1609,4 +1625,23 @@ void wxToolBar::OnPaint(wxPaintEvent& event) 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