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:
@@ -72,6 +72,10 @@ class WXDLLIMPEXP_CORE wxToolBar: public wxToolBarBase
|
||||
#endif
|
||||
|
||||
#if wxOSX_USE_NATIVE_TOOLBAR
|
||||
// make all tools selectable
|
||||
void OSXSetSelectableTools(bool set);
|
||||
void OSXSelectTool(int toolId);
|
||||
|
||||
bool MacInstallNativeToolbar(bool usesNative);
|
||||
void MacUninstallNativeToolbar();
|
||||
bool MacWantsNativeToolbar();
|
||||
|
@@ -305,8 +305,11 @@ private:
|
||||
|
||||
@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;
|
||||
@@ -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,7 +391,9 @@ private:
|
||||
|
||||
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
|
||||
{
|
||||
wxUnusedVar(toolbar);
|
||||
if ( m_isSelectable )
|
||||
return [[toolbar items] valueForKey:@"itemIdentifier"];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
Reference in New Issue
Block a user