]> git.saurik.com Git - wxWidgets.git/commitdiff
Associate/Disassociate now check for non-NULL pointer instead of requiring
authorDavid Elliott <dfe@tgwbd.org>
Fri, 11 Jul 2003 17:47:57 +0000 (17:47 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Fri, 11 Jul 2003 17:47:57 +0000 (17:47 +0000)
the caller to do so.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21894 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/NSButton.h
include/wx/cocoa/NSWindow.h
include/wx/cocoa/ObjcAssociate.h
src/cocoa/NSButton.mm
src/cocoa/NSView.mm
src/cocoa/NSWindow.mm
src/cocoa/window.mm

index 7e8f8add03912101abce3bdf4227c4d854eaf6b8..687fd77655b5e092d2b7b85514412dbab133bae1 100644 (file)
@@ -24,7 +24,8 @@ public:
     void AssociateNSButton(WX_NSButton cocoaNSButton);
     inline void DisassociateNSButton(WX_NSButton cocoaNSButton)
     {
-        sm_cocoaHash.erase(cocoaNSButton);
+        if(cocoaNSButton)
+            sm_cocoaHash.erase(cocoaNSButton);
     }
 
 public:
index 15a0ac79969bb6905f0be2c19033410f56d8ee55..04da760edc8e25e21bc882a3b8c0683ca4d7efa0 100644 (file)
@@ -25,7 +25,8 @@ public:
     void AssociateNSWindow(WX_NSWindow cocoaNSWindow);
     inline void DisassociateNSWindow(WX_NSWindow cocoaNSWindow)
     {
-        sm_cocoaHash.erase(cocoaNSWindow);
+        if(cocoaNSWindow)
+            sm_cocoaHash.erase(cocoaNSWindow);
     }
     virtual void Cocoa_close(void) = 0;
     virtual bool Cocoa_windowShouldClose(void) = 0;
index 4a460143e038789e4aeea932d95b16ce5aaa3829..31b087e46c69f90d252feff7343019b4df487532 100644 (file)
@@ -45,11 +45,13 @@ WX_DECLARE_OBJC_INTERFACE_HASHMAP(ObjcClass) \
 public: \
     inline void Associate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
     { \
-        sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \
+        if(cocoaObjcClass) \
+            sm_cocoaHash.insert(wxCocoa##ObjcClass##Hash::value_type(cocoaObjcClass,this)); \
     } \
     inline void Disassociate##ObjcClass(WX_##ObjcClass cocoaObjcClass) \
     { \
-        sm_cocoaHash.erase(cocoaObjcClass); \
+        if(cocoaObjcClass) \
+            sm_cocoaHash.erase(cocoaObjcClass); \
     }
 
 #define WX_IMPLEMENT_OBJC_INTERFACE(ObjcClass) \
@@ -68,11 +70,9 @@ 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); \
+    Disassociate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
     Set##ObjcBase(cocoaObjcClass); \
-    if(m_cocoa##ObjcRoot) \
-        Associate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
+    Associate##ObjcClass((WX_##ObjcClass)m_cocoa##ObjcRoot); \
 }
 
 #endif // __WX_COCOA_OBJC_ASSOCIATE_H__
index c228460dd41cfc59d51363bfa39d7536105574a6..b9923b7f7fa067191bad9a6ae1f363d90e323232 100644 (file)
@@ -57,8 +57,11 @@ WX_IMPLEMENT_POSER(wxPoserNSButton);
 
 void wxCocoaNSButton::AssociateNSButton(WX_NSButton cocoaNSButton)
 {
-    sm_cocoaHash.insert(wxCocoaNSButtonHash::value_type(cocoaNSButton,this));
-    [cocoaNSButton setTarget: cocoaNSButton];
-    [cocoaNSButton setAction: @selector(wxNSButtonAction:)];
+    if(cocoaNSButton)
+    {
+        sm_cocoaHash.insert(wxCocoaNSButtonHash::value_type(cocoaNSButton,this));
+        [cocoaNSButton setTarget: cocoaNSButton];
+        [cocoaNSButton setAction: @selector(wxNSButtonAction:)];
+    }
 }
 
index 280c06b91b3c5d6824f00c56e67e940ca802732c..7f880656e6918117bc20fd5b79e36e4017a2bd73 100644 (file)
@@ -36,15 +36,21 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSView)
 
 void wxCocoaNSView::AssociateNSView(WX_NSView 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];
+    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)
 {
-    sm_cocoaHash.erase(cocoaNSView);
-    [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:@"NSViewFrameDidChangeNotification" object:cocoaNSView];
+    if(cocoaNSView)
+    {
+        sm_cocoaHash.erase(cocoaNSView);
+        [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:@"NSViewFrameDidChangeNotification" object:cocoaNSView];
+    }
 }
 
 // ============================================================================
index c0a6fdba0ecab677b7abf60b8b1309acabc19893..d230b1a09322037f82e0d26a6466a0b5e96c6f5d 100644 (file)
@@ -35,8 +35,11 @@ WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
 
 void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
 {
-    [cocoaNSWindow setReleasedWhenClosed: NO];
-    sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
+    if(cocoaNSWindow)
+    {
+        [cocoaNSWindow setReleasedWhenClosed: NO];
+        sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
+    }
 }
 
 // ============================================================================
index 5666a121ac7248632928f2b9b91f387f39823552..9adb78257a130ba296f24fbc17e6ac92635ec1f3 100644 (file)
@@ -108,13 +108,11 @@ 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);
+    DisassociateNSView(m_cocoaNSView);
     [cocoaNSView retain];
     [m_cocoaNSView release];
     m_cocoaNSView = cocoaNSView;
-    if(m_cocoaNSView)
-        AssociateNSView(m_cocoaNSView);
+    AssociateNSView(m_cocoaNSView);
     if(need_debug) wxLogDebug("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d",this,cocoaNSView,[cocoaNSView retainCount]);
 }