summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d07825b)
messages do in fact retain the new subview properly. This is what the
documentation clearly states, and it checks out when looking at the
retainCount. I think I had been covering up a bug which I've since fixed.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22638
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
{
void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
{
- [child->m_cocoaNSView retain];
- // NOTE: addSubView takes ownership of, but does not retain the subview
- // Upon a removeFromView or closing the super view, the child WILL be
- // released!!! I think the idea here is that normally you would alloc
- // the subview and add it to the superview and this way you don't have
- // to release what you just alloced. Unfortunately, that doesn't
- // make sense for wxCocoa, so we do this instead.
[m_cocoaNSView addSubview: child->m_cocoaNSView];
wxASSERT(!child->m_dummyNSView);
child->m_isShown = true;
[m_cocoaNSView addSubview: child->m_cocoaNSView];
wxASSERT(!child->m_dummyNSView);
child->m_isShown = true;
if(m_dummyNSView)
{
wxASSERT(m_cocoaNSView);
if(m_dummyNSView)
{
wxASSERT(m_cocoaNSView);
+ // balances the replaceSubView:with:
[m_dummyNSView removeFromSuperview];
[m_dummyNSView removeFromSuperview];
- // But since we also retained it ourselves
+ // But since we were the ones to alloc it
[m_dummyNSView release];
m_dummyNSView = nil;
// m_cocoaNSView has of course already been removed by virtue of
[m_dummyNSView release];
m_dummyNSView = nil;
// m_cocoaNSView has of course already been removed by virtue of
// If state isn't changing, return false
if(!m_dummyNSView)
return false;
// If state isn't changing, return false
if(!m_dummyNSView)
return false;
- // replaceSubView releases m_dummyNSView, balancing the alloc
- [m_cocoaNSView retain];
+ // replaceSubView:with: releases m_dummyNSView, balancing the
+ // previous replaceSubView:with
[[m_dummyNSView superview] replaceSubview:m_dummyNSView with:m_cocoaNSView];
[[m_dummyNSView superview] replaceSubview:m_dummyNSView with:m_cocoaNSView];
- // But since we also retained it ourselves
wxASSERT(![m_dummyNSView superview]);
wxASSERT(![m_dummyNSView superview]);
+ // But since we were the ones to alloc it
[m_dummyNSView release];
m_dummyNSView = nil;
wxASSERT([m_cocoaNSView superview]);
[m_dummyNSView release];
m_dummyNSView = nil;
wxASSERT([m_cocoaNSView superview]);
if(m_dummyNSView)
return false;
m_dummyNSView = [[NSView alloc] initWithFrame: [m_cocoaNSView frame]];
if(m_dummyNSView)
return false;
m_dummyNSView = [[NSView alloc] initWithFrame: [m_cocoaNSView frame]];
- [m_dummyNSView retain];
- // NOTE: replaceSubView will cause m_cocaNSView to be released
+ // NOTE: replaceSubView will cause m_cocaNSView to be (auto)released
+ // which balances out addSubView
[[m_cocoaNSView superview] replaceSubview:m_cocoaNSView with:m_dummyNSView];
// m_coocaNSView is now only retained by us
wxASSERT([m_dummyNSView superview]);
[[m_cocoaNSView superview] replaceSubview:m_cocoaNSView with:m_dummyNSView];
// m_coocaNSView is now only retained by us
wxASSERT([m_dummyNSView superview]);
wxAutoNSAutoreleasePool pool;
NSView *nsview = m_dummyNSView?m_dummyNSView:m_cocoaNSView;
NSView *superview = [nsview superview];
wxAutoNSAutoreleasePool pool;
NSView *nsview = m_dummyNSView?m_dummyNSView:m_cocoaNSView;
NSView *superview = [nsview superview];
[nsview removeFromSuperview];
[superview addSubview:nsview];
}
[nsview removeFromSuperview];
[superview addSubview:nsview];
}