Add support for Cocoa's selectable toolbar items.

The support is currently limited to making all toolbar items selectable
and is only available in wxOSX with Cocoa and native toolbars.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73575 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2013-02-28 16:28:56 +00:00
parent 72625b36b6
commit d52a1abad3
2 changed files with 41 additions and 2 deletions

View File

@@ -72,6 +72,10 @@ class WXDLLIMPEXP_CORE wxToolBar: public wxToolBarBase
#endif #endif
#if wxOSX_USE_NATIVE_TOOLBAR #if wxOSX_USE_NATIVE_TOOLBAR
// make all tools selectable
void OSXSetSelectableTools(bool set);
void OSXSelectTool(int toolId);
bool MacInstallNativeToolbar(bool usesNative); bool MacInstallNativeToolbar(bool usesNative);
void MacUninstallNativeToolbar(); void MacUninstallNativeToolbar();
bool MacWantsNativeToolbar(); bool MacWantsNativeToolbar();

View File

@@ -305,8 +305,11 @@ private:
@interface wxNSToolbarDelegate : NSObject wxOSX_10_6_AND_LATER(<NSToolbarDelegate>) @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; - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag;
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar; - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;
@@ -363,6 +366,17 @@ private:
@implementation wxNSToolbarDelegate @implementation wxNSToolbarDelegate
- (id)init
{
m_isSelectable = false;
return [super init];
}
- (void)setSelectable:(bool) value
{
m_isSelectable = true;
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{ {
wxUnusedVar(toolbar); wxUnusedVar(toolbar);
@@ -377,8 +391,10 @@ private:
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
{ {
wxUnusedVar(toolbar); if ( m_isSelectable )
return nil; return [[toolbar items] valueForKey:@"itemIdentifier"];
else
return nil;
} }
- (NSToolbarItem*) toolbar:(NSToolbar*) toolbar itemForItemIdentifier:(NSString*) itemIdentifier willBeInsertedIntoToolbar:(BOOL) flag - (NSToolbarItem*) toolbar:(NSToolbar*) toolbar itemForItemIdentifier:(NSString*) itemIdentifier willBeInsertedIntoToolbar:(BOOL) flag
@@ -1609,4 +1625,23 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
event.Skip(); 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 #endif // wxUSE_TOOLBAR