]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/toplevel.mm
moved compat content to formats, there will be more wx-specific formats
[wxWidgets.git] / src / cocoa / toplevel.mm
index 39b1b48f9dea7c1b54af0eb3ac073de756261d54..fa9ffc308c6a47b1a73ef399eff7a6d043052468 100644 (file)
@@ -28,6 +28,8 @@
     #include "wx/app.h"
 #endif //WX_PRECOMP
 
+#include "wx/cocoa/autorelease.h"
+
 #import <AppKit/NSView.h>
 #import <AppKit/NSWindow.h>
 // ----------------------------------------------------------------------------
@@ -63,6 +65,7 @@ bool wxTopLevelWindowCocoa::Create(wxWindow *parent,
                                  long style,
                                  const wxString& name)
 {
+    wxAutoNSAutoreleasePool pool;
     wxTopLevelWindows.Append(this);
 
     if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
@@ -94,12 +97,9 @@ bool wxTopLevelWindowCocoa::Create(wxWindow *parent,
 
 wxTopLevelWindowCocoa::~wxTopLevelWindowCocoa()
 {
-    // Hand ownership of the content view to wxWindow so it can destroy
-    // itself properly.
-    NSView *view = [m_cocoaNSView retain];
+    wxAutoNSAutoreleasePool pool;
+    DestroyChildren();
     SetNSWindow(NULL);
-    SetNSView(view);
-    [view release];
 }
 
 // ----------------------------------------------------------------------------
@@ -122,8 +122,26 @@ void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow)
     if(need_debug) wxLogDebug("wxTopLevelWindowCocoa=%p::SetNSWindow [cocoaNSWindow=%p retainCount]=%d",this,cocoaNSWindow,[cocoaNSWindow retainCount]);
 }
 
-void wxTopLevelWindowCocoa::Cocoa_wxMenuItemAction(wxMenuItem& item)
+void wxTopLevelWindowCocoa::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
+{
+    if([m_cocoaNSWindow contentView] == oldView)
+        [m_cocoaNSWindow setContentView:newView];
+}
+
+void wxTopLevelWindowCocoa::CocoaDelegate_windowDidBecomeKey(void)
 {
+    wxLogDebug("wxTopLevelWindowCocoa=%p::CocoaDelegate_windowDidBecomeKey",this);
+    wxActivateEvent event(wxEVT_ACTIVATE, TRUE, GetId());
+    event.SetEventObject(this);
+    GetEventHandler()->ProcessEvent(event);
+}
+
+void wxTopLevelWindowCocoa::CocoaDelegate_windowDidResignKey(void)
+{
+    wxLogDebug("wxTopLevelWindowCocoa=%p::CocoaDelegate_windowDidResignKey",this);
+    wxActivateEvent event(wxEVT_ACTIVATE, FALSE, GetId());
+    event.SetEventObject(this);
+    GetEventHandler()->ProcessEvent(event);
 }
 
 void wxTopLevelWindowCocoa::Cocoa_close(void)
@@ -136,7 +154,7 @@ void wxTopLevelWindowCocoa::Cocoa_close(void)
     wxTheApp->CocoaInstallRequestedIdleHandler();
 }
 
-bool wxTopLevelWindowCocoa::Cocoa_windowShouldClose()
+bool wxTopLevelWindowCocoa::CocoaDelegate_windowShouldClose()
 {
     return wxWindowBase::Close(false);
 }
@@ -169,8 +187,18 @@ void wxTopLevelWindowCocoa::Restore()
 
 bool wxTopLevelWindowCocoa::Show(bool show)
 {
+    wxAutoNSAutoreleasePool pool;
     if(show)
+    {
+        // Send the window a size event because wxWindows apps expect it
+        // NOTE: This should really only be done the first time a window
+        // is shown.  I doubt this will cause any problems though.
+        wxSizeEvent event(GetSize(), GetId());
+        event.SetEventObject(this);
+        GetEventHandler()->ProcessEvent(event);
+
         [m_cocoaNSWindow makeKeyAndOrderFront:m_cocoaNSWindow];
+    }
     else
         [m_cocoaNSWindow orderOut:m_cocoaNSWindow];
     return true;
@@ -214,9 +242,25 @@ bool wxTopLevelWindowCocoa::IsFullScreen() const
     return FALSE;
 }
 
+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 contentRect = [NSWindow
+        contentRectForFrameRect: frameRect
+        styleMask: styleMask];
+    contentRect.size.width = width;
+    contentRect.size.height = height;
+    frameRect = [NSWindow
+        frameRectForContentRect: contentRect
+        styleMask: styleMask];
+    [m_cocoaNSWindow setFrame: frameRect display: NO];
+}
+
 void wxTopLevelWindowCocoa::DoMoveWindow(int x, int y, int width, int height)
 {
-    wxLogDebug("wxTopLevelWindow=%p::DoMoveWindow(%d,%d,%d,%d)",this,x,y,width,height);
+//    wxLogDebug("wxTopLevelWindow=%p::DoMoveWindow(%d,%d,%d,%d)",this,x,y,width,height);
 
     NSRect cocoaRect = NSMakeRect(x,y,width,height);
     [m_cocoaNSWindow setFrame: cocoaRect display:NO];
@@ -229,7 +273,7 @@ void wxTopLevelWindowCocoa::DoGetSize(int *w, int *h) const
         *w=(int)cocoaRect.size.width;
     if(h)
         *h=(int)cocoaRect.size.height;
-    wxLogDebug("wxTopLevelWindow=%p::DoGetSize = (%d,%d)",this,(int)cocoaRect.size.width,(int)cocoaRect.size.height);
+//    wxLogDebug("wxTopLevelWindow=%p::DoGetSize = (%d,%d)",this,(int)cocoaRect.size.width,(int)cocoaRect.size.height);
 }
 
 void wxTopLevelWindowCocoa::DoGetPosition(int *x, int *y) const
@@ -239,6 +283,6 @@ void wxTopLevelWindowCocoa::DoGetPosition(int *x, int *y) const
         *x=(int)cocoaRect.origin.x;
     if(y)
         *y=(int)cocoaRect.origin.y;
-    wxLogDebug("wxTopLevelWindow=%p::DoGetPosition = (%d,%d)",this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y);
+//    wxLogDebug("wxTopLevelWindow=%p::DoGetPosition = (%d,%d)",this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y);
 }