]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/toplevel.mm
test undividable words
[wxWidgets.git] / src / cocoa / toplevel.mm
index 93fb983c77bbf666c6c315f02de88c6ca9960e43..c4bfd67a419ab4a83e1a03ee9f30b43821f0f9cb 100644 (file)
@@ -28,6 +28,9 @@
     #include "wx/app.h"
 #endif //WX_PRECOMP
 
+#include "wx/cocoa/autorelease.h"
+
+#import <AppKit/NSView.h>
 #import <AppKit/NSWindow.h>
 // ----------------------------------------------------------------------------
 // globals
@@ -43,7 +46,6 @@ wxWindowList       wxModelessWindows;
 // ----------------------------------------------------------------------------
 // wxTopLevelWindowCocoa creation
 // ----------------------------------------------------------------------------
-IMPLEMENT_CLASS(wxTopLevelWindowCocoa,wxWindowCocoa)
 BEGIN_EVENT_TABLE(wxTopLevelWindowCocoa,wxTopLevelWindowBase)
     EVT_CLOSE(wxTopLevelWindowCocoa::OnCloseWindow)
 END_EVENT_TABLE()
@@ -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,7 +97,13 @@ bool wxTopLevelWindowCocoa::Create(wxWindow *parent,
 
 wxTopLevelWindowCocoa::~wxTopLevelWindowCocoa()
 {
+    wxAutoNSAutoreleasePool pool;
+    // Hand ownership of the content view to wxWindow so it can destroy
+    // itself properly.
+    NSView *view = [m_cocoaNSView retain];
     SetNSWindow(NULL);
+    SetNSView(view);
+    [view release];
 }
 
 // ----------------------------------------------------------------------------
@@ -105,8 +114,7 @@ void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow)
 {
     bool need_debug = cocoaNSWindow || m_cocoaNSWindow;
     if(need_debug) wxLogDebug("wxTopLevelWindowCocoa=%p::SetNSWindow [m_cocoaNSWindow=%p retainCount]=%d",this,m_cocoaNSWindow,[m_cocoaNSWindow retainCount]);
-    if(m_cocoaNSWindow)
-        DisassociateNSWindow(m_cocoaNSWindow);
+    DisassociateNSWindow(m_cocoaNSWindow);
     [cocoaNSWindow retain];
     [m_cocoaNSWindow release];
     m_cocoaNSWindow = cocoaNSWindow;
@@ -114,8 +122,7 @@ void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow)
         SetNSView([m_cocoaNSWindow contentView]);
     else
         SetNSView(NULL);
-    if(m_cocoaNSWindow)
-        AssociateNSWindow(m_cocoaNSWindow);
+    AssociateNSWindow(m_cocoaNSWindow);
     if(need_debug) wxLogDebug("wxTopLevelWindowCocoa=%p::SetNSWindow [cocoaNSWindow=%p retainCount]=%d",this,cocoaNSWindow,[cocoaNSWindow retainCount]);
 }
 
@@ -166,6 +173,7 @@ void wxTopLevelWindowCocoa::Restore()
 
 bool wxTopLevelWindowCocoa::Show(bool show)
 {
+    wxAutoNSAutoreleasePool pool;
     if(show)
         [m_cocoaNSWindow makeKeyAndOrderFront:m_cocoaNSWindow];
     else