]> git.saurik.com Git - wxWidgets.git/commitdiff
Use one wxNSWindowDelegate instance per wxCocoaNSWindow instance
authorDavid Elliott <dfe@tgwbd.org>
Thu, 19 Feb 2004 06:32:34 +0000 (06:32 +0000)
committerDavid Elliott <dfe@tgwbd.org>
Thu, 19 Feb 2004 06:32:34 +0000 (06:32 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25860 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cocoa/NSWindow.h
src/cocoa/NSWindow.mm

index 3bf28f62e03dda5c3d84d20d6d1ee7ce26733732..808656f44267aea418fe4475c01ce5f5e7b677aa 100644 (file)
@@ -19,6 +19,8 @@ WX_DECLARE_OBJC_HASHMAP(NSWindow);
 
 class WXDLLEXPORT wxMenuBar;
 
+DECLARE_WXCOCOA_OBJC_CLASS(wxNSWindowDelegate);
+
 class wxCocoaNSWindow
 {
 /* NSWindow is a rather special case and requires some extra attention */
@@ -36,7 +38,9 @@ public:
     virtual void CocoaDelegate_windowDidResignMain(void) { }
     virtual wxMenuBar* GetAppMenuBar(wxCocoaNSWindow *win);
 protected:
-    static struct objc_object *sm_cocoaDelegate;
+    wxCocoaNSWindow();
+    virtual ~wxCocoaNSWindow();
+    WX_wxNSWindowDelegate m_cocoaDelegate;
 };
 
 #endif // _WX_COCOA_NSWINDOW_H_
index 7032045d68c51b3a3ff0513600624fb5a35865c8..a0c4a5f196d7d3f3e6c9c78dcad268b2bc7e10b1 100644 (file)
 // ============================================================================
 @interface wxNSWindowDelegate : NSObject
 {
+    wxCocoaNSWindow *m_wxCocoaInterface;
 }
 
+- (id)init;
+- (void)setWxCocoaInterface: (wxCocoaNSWindow *)wxCocoaInterface;
+- (wxCocoaNSWindow *)wxCocoaInterface;
+
+// Delegate message handlers
 - (void)windowDidBecomeKey: (NSNotification *)notification;
 - (void)windowDidResignKey: (NSNotification *)notification;
 - (void)windowDidBecomeMain: (NSNotification *)notification;
 
 @implementation wxNSWindowDelegate : NSObject
 
+- (id)init
+{
+    m_wxCocoaInterface = NULL;
+    return [super init];
+}
+
+- (void)setWxCocoaInterface: (wxCocoaNSWindow *)wxCocoaInterface
+{
+    m_wxCocoaInterface = wxCocoaInterface;
+}
+
+- (wxCocoaNSWindow *)wxCocoaInterface
+{
+    return m_wxCocoaInterface;
+}
+
 - (void)windowDidBecomeKey: (NSNotification *)notification
 {
     wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
+    wxASSERT(win==m_wxCocoaInterface);
     wxCHECK_RET(win,wxT("notificationDidBecomeKey received but no wxWindow exists"));
     win->CocoaDelegate_windowDidBecomeKey();
 }
@@ -57,6 +80,7 @@
 - (void)windowDidResignKey: (NSNotification *)notification
 {
     wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
+    wxASSERT(win==m_wxCocoaInterface);
     wxCHECK_RET(win,wxT("notificationDidResignKey received but no wxWindow exists"));
     win->CocoaDelegate_windowDidResignKey();
 }
@@ -64,6 +88,7 @@
 - (void)windowDidBecomeMain: (NSNotification *)notification
 {
     wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
+    wxASSERT(win==m_wxCocoaInterface);
     wxCHECK_RET(win,wxT("notificationDidBecomeMain received but no wxWindow exists"));
     win->CocoaDelegate_windowDidBecomeMain();
 }
@@ -71,6 +96,7 @@
 - (void)windowDidResignMain: (NSNotification *)notification
 {
     wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
+    wxASSERT(win==m_wxCocoaInterface);
     wxCHECK_RET(win,wxT("notificationDidResignMain received but no wxWindow exists"));
     win->CocoaDelegate_windowDidResignMain();
 }
 {
     wxLogTrace(wxTRACE_COCOA,wxT("windowShouldClose"));
     wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
+    wxASSERT(tlw==m_wxCocoaInterface);
     if(tlw && !tlw->CocoaDelegate_windowShouldClose())
     {
         wxLogTrace(wxTRACE_COCOA,wxT("Window will not be closed"));
 - (void)windowWillClose: (NSNotification *)notification
 {
     wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
+    wxASSERT(win==m_wxCocoaInterface);
     wxCHECK_RET(win,wxT("windowWillClose received but no wxWindow exists"));
     win->CocoaDelegate_windowWillClose();
 }
 
 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
 
-struct objc_object *wxCocoaNSWindow::sm_cocoaDelegate = [[wxNSWindowDelegate alloc] init];
+wxCocoaNSWindow::wxCocoaNSWindow()
+{
+    m_cocoaDelegate = [[wxNSWindowDelegate alloc] init];
+    [m_cocoaDelegate setWxCocoaInterface: this];
+}
+
+wxCocoaNSWindow::~wxCocoaNSWindow()
+{
+    [m_cocoaDelegate setWxCocoaInterface: NULL];
+    [m_cocoaDelegate release];
+}
 
 void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
 {
@@ -111,7 +149,7 @@ void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
     {
         [cocoaNSWindow setReleasedWhenClosed: NO];
         sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
-        [cocoaNSWindow setDelegate: sm_cocoaDelegate];
+        [cocoaNSWindow setDelegate: m_cocoaDelegate];
     }
 }