From f3f56f2fe2a5931e8ec97bacb81d7fdd30ba6909 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Thu, 31 Jan 2008 19:17:42 +0000 Subject: [PATCH] Allow wxTopLevelWindowCocoa::SetDefaultItem(NULL) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51476 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/cocoa/toplevel.mm | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/cocoa/toplevel.mm b/src/cocoa/toplevel.mm index 626dba2773..a23e990cab 100644 --- a/src/cocoa/toplevel.mm +++ b/src/cocoa/toplevel.mm @@ -352,21 +352,26 @@ wxString wxTopLevelWindowCocoa::GetTitle() const wxWindow* wxTopLevelWindowCocoa::SetDefaultItem(wxWindow *win) { wxWindow *old = wxTopLevelWindowBase::SetDefaultItem(win); - NSView *newView = win->GetNSView(); NSCell *newCell; - // newView does not have to be an NSControl, we only cast to NSControl* - // to silence the warning about cell not being implemented. - if(newView != nil && [newView respondsToSelector:@selector(cell)]) - newCell = [(NSControl*)newView cell]; + if(win != NULL) + { + NSView *newView = win->GetNSView(); + // newView does not have to be an NSControl, we only cast to NSControl* + // to silence the warning about cell not being implemented. + if(newView != nil && [newView respondsToSelector:@selector(cell)]) + newCell = [(NSControl*)newView cell]; + else + newCell = nil; + + if(newCell != nil && ![newCell isKindOfClass:[NSButtonCell class]]) + { // It's not an NSButtonCell, set the default to nil. + newCell = nil; + } + } else newCell = nil; - if(newCell != nil && ![newCell isKindOfClass:[NSButtonCell class]]) - { // It's not an NSButtonCell, set the default to nil. - newCell = nil; - } - [GetNSWindow() setDefaultButtonCell:(NSButtonCell*)newCell]; return old; } -- 2.45.2