X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/15f37147958a61adb54e0d64c82dc7b93c1f1cbe..abd474ea63667f727940a009cc3e0b23ba9f418f:/src/cocoa/toplevel.mm diff --git a/src/cocoa/toplevel.mm b/src/cocoa/toplevel.mm index 8cce120e00..cf8559d9de 100644 --- a/src/cocoa/toplevel.mm +++ b/src/cocoa/toplevel.mm @@ -6,7 +6,7 @@ // Created: 2002/11/27 // RCS-ID: $Id$ // Copyright: (c) 2002 David Elliott -// Licence: wxWidgets licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -32,6 +32,7 @@ #include "wx/cocoa/autorelease.h" #include "wx/cocoa/string.h" +#include "wx/cocoa/ObjcRef.h" #include "wx/cocoa/objc/NSView.h" #include "wx/cocoa/objc/NSWindow.h" @@ -190,8 +191,8 @@ void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow) bool need_debug = cocoaNSWindow || m_cocoaNSWindow; if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxTopLevelWindowCocoa=%p::SetNSWindow [m_cocoaNSWindow=%p retainCount]=%d"),this,m_cocoaNSWindow,[m_cocoaNSWindow retainCount]); DisassociateNSWindow(m_cocoaNSWindow); - [cocoaNSWindow retain]; - [m_cocoaNSWindow release]; + wxGCSafeRetain(cocoaNSWindow); + wxGCSafeRelease(m_cocoaNSWindow); 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. @@ -222,7 +223,7 @@ void wxTopLevelWindowCocoa::CocoaDelegate_windowDidBecomeKey(void) wxLogTrace(wxTRACE_COCOA,wxT("wxTopLevelWindowCocoa=%p::CocoaDelegate_windowDidBecomeKey"),this); wxActivateEvent event(wxEVT_ACTIVATE, true, GetId()); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + HandleWindowEvent(event); } void wxTopLevelWindowCocoa::CocoaDelegate_windowDidResignKey(void) @@ -230,7 +231,7 @@ void wxTopLevelWindowCocoa::CocoaDelegate_windowDidResignKey(void) wxLogTrace(wxTRACE_COCOA,wxT("wxTopLevelWindowCocoa=%p::CocoaDelegate_windowDidResignKey"),this); wxActivateEvent event(wxEVT_ACTIVATE, false, GetId()); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + HandleWindowEvent(event); } void wxTopLevelWindowCocoa::CocoaDelegate_windowDidBecomeMain(void) @@ -301,7 +302,7 @@ bool wxTopLevelWindowCocoa::Show(bool show) // is shown. I doubt this will cause any problems though. wxSizeEvent event(GetSize(), GetId()); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + HandleWindowEvent(event); [m_cocoaNSWindow makeKeyAndOrderFront:m_cocoaNSWindow]; } @@ -352,21 +353,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; } @@ -385,16 +391,22 @@ void wxTopLevelWindowCocoa::CocoaSetWxWindowSize(int width, int height) { // Set the NSView size by setting the frame size to enclose it unsigned int styleMask = [m_cocoaNSWindow styleMask]; - NSRect frameRect = [m_cocoaNSWindow frame]; + NSRect oldFrameRect = [m_cocoaNSWindow frame]; NSRect contentRect = [NSWindow - contentRectForFrameRect: frameRect + contentRectForFrameRect: oldFrameRect styleMask: styleMask]; contentRect.size.width = width; contentRect.size.height = height; - frameRect = [NSWindow + NSRect newFrameRect = [NSWindow frameRectForContentRect: contentRect styleMask: styleMask]; - [m_cocoaNSWindow setFrame: frameRect display: NO]; + + // Cocoa uses +y is up but wxWidgets uses +y is down. We want an increase/decrease in height + // to not effect where the top of the window is placed so we set the new y origin relative the + // old one taking the height change into account. + newFrameRect.origin.y = oldFrameRect.origin.y + oldFrameRect.size.height - newFrameRect.size.height; + + [m_cocoaNSWindow setFrame: newFrameRect display: NO]; } void wxTopLevelWindowCocoa::DoMoveWindow(int x, int y, int width, int height)