In destructor, pass the NSView ownership to the base class

Avoid extra if tests now that Associate/Disassociate do the test themselves


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21945 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Elliott
2003-07-14 03:02:04 +00:00
parent bc34fa2617
commit fe169919d8

View File

@@ -28,6 +28,7 @@
#include "wx/app.h" #include "wx/app.h"
#endif //WX_PRECOMP #endif //WX_PRECOMP
#import <AppKit/NSView.h>
#import <AppKit/NSWindow.h> #import <AppKit/NSWindow.h>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// globals // globals
@@ -93,7 +94,12 @@ bool wxTopLevelWindowCocoa::Create(wxWindow *parent,
wxTopLevelWindowCocoa::~wxTopLevelWindowCocoa() wxTopLevelWindowCocoa::~wxTopLevelWindowCocoa()
{ {
// Hand ownership of the content view to wxWindow so it can destroy
// itself properly.
NSView *view = [m_cocoaNSView retain];
SetNSWindow(NULL); SetNSWindow(NULL);
SetNSView(view);
[view release];
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -104,8 +110,7 @@ void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow)
{ {
bool need_debug = cocoaNSWindow || m_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(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]; [cocoaNSWindow retain];
[m_cocoaNSWindow release]; [m_cocoaNSWindow release];
m_cocoaNSWindow = cocoaNSWindow; m_cocoaNSWindow = cocoaNSWindow;
@@ -113,8 +118,7 @@ void wxTopLevelWindowCocoa::SetNSWindow(WX_NSWindow cocoaNSWindow)
SetNSView([m_cocoaNSWindow contentView]); SetNSView([m_cocoaNSWindow contentView]);
else else
SetNSView(NULL); 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]); if(need_debug) wxLogDebug("wxTopLevelWindowCocoa=%p::SetNSWindow [cocoaNSWindow=%p retainCount]=%d",this,cocoaNSWindow,[cocoaNSWindow retainCount]);
} }