From 10018c1de0205e533863fca4c3a7cd9b44e96b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Thu, 25 Sep 2014 16:10:23 +0000 Subject: [PATCH] Don't break other toolbars with wxToolBar::OSXSetSelectableTools() wxOSX's implementation used a shared global delegate for all toolbars, which is not only highly unusual, but broke with code that modified the delegate. Specifically, wxPreferencesEditor's window uses OSXSetSelectableTools() to make its toolbar selectable. Because the delegate was shared, all toolbars in the application would start behaving as selectable as soon as the user opened preferences (even after the preferences window was closed). Don't share the delegate. Create a unique copy and store it in wxNSToolbar instance. This isn't particularly elegant solution, but it has the advantage of being binary compatible and simple. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77885 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/cocoa/toolbar.mm | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/osx/cocoa/toolbar.mm b/src/osx/cocoa/toolbar.mm index 56ac64385d..b8ee882143 100644 --- a/src/osx/cocoa/toolbar.mm +++ b/src/osx/cocoa/toolbar.mm @@ -315,6 +315,16 @@ private: - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar; +@end + + +@interface wxNSToolbar : NSToolbar +{ + wxNSToolbarDelegate* toolbarDelegate; +} + +- (id)initWithIdentifier:(NSString *)identifier; +- (void) dealloc; @end @@ -423,6 +433,28 @@ private: @end + +@implementation wxNSToolbar + +- (id)initWithIdentifier:(NSString *)identifier +{ + self = [super initWithIdentifier:identifier]; + if (self) + { + toolbarDelegate = [[wxNSToolbarDelegate alloc] init]; + [self setDelegate:toolbarDelegate]; + } + return self; +} + +- (void)dealloc +{ + [toolbarDelegate release]; + [super dealloc]; +} + +@end + #endif @implementation wxNSToolBarButton @@ -645,20 +677,14 @@ bool wxToolBar::Create( if (parent->IsKindOf(CLASSINFO(wxFrame)) && wxSystemOptions::GetOptionInt(wxT("mac.toolbar.no-native")) != 1) { - static wxNSToolbarDelegate* controller = nil; - - if ( controller == nil ) - controller = [[wxNSToolbarDelegate alloc] init]; wxString identifier = wxString::Format( wxT("%p"), this ); wxCFStringRef cfidentifier(identifier); - NSToolbar* tb = [[NSToolbar alloc] initWithIdentifier:cfidentifier.AsNSString()]; + NSToolbar* tb = [[wxNSToolbar alloc] initWithIdentifier:cfidentifier.AsNSString()]; m_macToolbar = tb ; if (m_macToolbar != NULL) { - [tb setDelegate:controller]; - NSToolbarDisplayMode mode = NSToolbarDisplayModeDefault; NSToolbarSizeMode displaySize = NSToolbarSizeModeSmall;