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
This commit is contained in:
Václav Slavík 2014-09-25 16:10:23 +00:00
parent 5d0c8c9302
commit 10018c1de0

View File

@ -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;