Associate/Disassociate now check for non-NULL pointer instead of requiring

the caller to do so.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21894 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Elliott
2003-07-11 17:47:57 +00:00
parent 7d27dcf906
commit bac6f2348d
7 changed files with 34 additions and 22 deletions

View File

@@ -24,6 +24,7 @@ public:
void AssociateNSButton(WX_NSButton cocoaNSButton);
inline void DisassociateNSButton(WX_NSButton cocoaNSButton)
{
if(cocoaNSButton)
sm_cocoaHash.erase(cocoaNSButton);
}

View File

@@ -25,6 +25,7 @@ public:
void AssociateNSWindow(WX_NSWindow cocoaNSWindow);
inline void DisassociateNSWindow(WX_NSWindow cocoaNSWindow)
{
if(cocoaNSWindow)
sm_cocoaHash.erase(cocoaNSWindow);
}
virtual void Cocoa_close(void) = 0;

View File

@@ -45,10 +45,12 @@ WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
public: \
inline void Associate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
{ \
if(cocoaObjcClass) \
sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \
} \
inline void Disassociate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
{ \
if(cocoaObjcClass) \
sm_cocoaHash.erase(cocoaObjcClass); \
}
@@ -68,10 +70,8 @@ protected: \
#define WX_IMPLEMENT_COCOA_OWNER(wxClass,ObjcClass,ObjcBase,ObjcRoot) \
void wxClass::Set##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
{ \
if(m_cocoa##ObjcRoot) \
Disassociate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
Set##ObjcBase(cocoaObjcClass); \
if(m_cocoa##ObjcRoot) \
Associate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
}

View File

@@ -57,8 +57,11 @@ WX_IMPLEMENT_POSER(wxPoserNSButton);
void wxCocoaNSButton::AssociateNSButton(WX_NSButton cocoaNSButton)
{
if(cocoaNSButton)
{
sm_cocoaHash.insert(wxCocoaNSButtonHash::value_type(cocoaNSButton,this));
[cocoaNSButton setTarget: cocoaNSButton];
[cocoaNSButton setAction: @selector(wxNSButtonAction:)];
}
}

View File

@@ -36,15 +36,21 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSView)
void wxCocoaNSView::AssociateNSView(WX_NSView cocoaNSView)
{
if(cocoaNSView)
{
sm_cocoaHash.insert(wxCocoaNSViewHash::value_type(cocoaNSView,this));
[[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(notificationFrameChanged:) name:@"NSViewFrameDidChangeNotification" object:cocoaNSView];
[cocoaNSView setPostsFrameChangedNotifications: YES];
}
}
void wxCocoaNSView::DisassociateNSView(WX_NSView cocoaNSView)
{
if(cocoaNSView)
{
sm_cocoaHash.erase(cocoaNSView);
[[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:@"NSViewFrameDidChangeNotification" object:cocoaNSView];
}
}
// ============================================================================

View File

@@ -35,8 +35,11 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
{
if(cocoaNSWindow)
{
[cocoaNSWindow setReleasedWhenClosed: NO];
sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
}
}
// ============================================================================

View File

@@ -108,12 +108,10 @@ void wxWindowCocoa::SetNSView(WX_NSView cocoaNSView)
{
bool need_debug = cocoaNSView || m_cocoaNSView;
if(need_debug) wxLogDebug("wxWindowCocoa=%p::SetNSView [m_cocoaNSView=%p retainCount]=%d",this,m_cocoaNSView,[m_cocoaNSView retainCount]);
if(m_cocoaNSView)
DisassociateNSView(m_cocoaNSView);
[cocoaNSView retain];
[m_cocoaNSView release];
m_cocoaNSView = cocoaNSView;
if(m_cocoaNSView)
AssociateNSView(m_cocoaNSView);
if(need_debug) wxLogDebug("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d",this,cocoaNSView,[cocoaNSView retainCount]);
}