X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/65aeaf19f6781193697d28f868901a80ee623396..5a1e0e91a1ca5ec98b0eeb335cda757d1261ed08:/src/cocoa/toplevel.mm diff --git a/src/cocoa/toplevel.mm b/src/cocoa/toplevel.mm index c6bbd38319..f2e44d4b44 100644 --- a/src/cocoa/toplevel.mm +++ b/src/cocoa/toplevel.mm @@ -33,9 +33,12 @@ #include "wx/cocoa/autorelease.h" #include "wx/cocoa/string.h" -#import -#import +#include "wx/cocoa/objc/NSView.h" +#include "wx/cocoa/objc/NSWindow.h" #import +#import +#import + // ---------------------------------------------------------------------------- // globals // ---------------------------------------------------------------------------- @@ -131,10 +134,18 @@ bool wxTopLevelWindowCocoa::Create(wxWindow *parent, m_cocoaNSWindow = NULL; m_cocoaNSView = NULL; + // NOTE: We may need to deal with the contentView becoming a wx NSView as well. + NSWindow *newWindow; + // Create a WXNSPanel or a WXNSWindow depending on what type of window is desired. if(style & wxFRAME_TOOL_WINDOW) - SetNSWindow([[NSPanel alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]); + newWindow = [[WXNSPanel alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]; else - SetNSWindow([[NSWindow alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]); + newWindow = [[WXNSWindow alloc] initWithContentRect:cocoaRect styleMask:cocoaStyle backing:NSBackingStoreBuffered defer:NO]; + // Make sure the default content view is a WXNSView + [newWindow setContentView: [[WX_GET_OBJC_CLASS(WXNSView) alloc] initWithFrame: [[newWindow contentView] frame]]]; + // Associate the window and view + SetNSWindow(newWindow); + // NOTE: SetNSWindow has retained the Cocoa object for this object. // Because we do not release on close, the following release matches the // above alloc and thus the retain count will be 1. @@ -144,7 +155,7 @@ bool wxTopLevelWindowCocoa::Create(wxWindow *parent, [m_cocoaNSWindow setExcludedFromWindowsMenu: YES]; if(style & wxSTAY_ON_TOP) [m_cocoaNSWindow setLevel:NSFloatingWindowLevel]; - SetTitle(title); + [m_cocoaNSWindow setTitle:wxNSStringWithWxString(title)]; return true; } @@ -188,6 +199,8 @@ void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow) [cocoaNSWindow retain]; [m_cocoaNSWindow release]; m_cocoaNSWindow = cocoaNSWindow; + // NOTE: We are no longer using posing so we won't get events on the + // window's view unless it was explicitly created as the wx view class. if(m_cocoaNSWindow) SetNSView([m_cocoaNSWindow contentView]); else @@ -332,7 +345,7 @@ void wxTopLevelWindowCocoa::OnCloseWindow(wxCloseEvent& event) // wxTopLevelWindowCocoa misc // ---------------------------------------------------------------------------- -void wxTopLevelWindowCocoa::SetTitle( const wxString& WXUNUSED(title)) +void wxTopLevelWindowCocoa::SetTitle(const wxString& title) { [m_cocoaNSWindow setTitle:wxNSStringWithWxString(title)]; } @@ -342,6 +355,28 @@ wxString wxTopLevelWindowCocoa::GetTitle() const return wxStringWithNSString([m_cocoaNSWindow title]); } +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]; + 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; +} + bool wxTopLevelWindowCocoa::ShowFullScreen(bool show, long style) { return false;