Use one wxNSWindowDelegate instance per wxCocoaNSWindow instance

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25860 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Elliott
2004-02-19 06:32:34 +00:00
parent dbd22c6a0e
commit c6f73d05cc
2 changed files with 45 additions and 3 deletions

View 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_

View File

@@ -35,8 +35,14 @@
// ============================================================================
@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;
@@ -47,9 +53,26 @@
@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();
}
@@ -79,6 +105,7 @@
{
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"));
@@ -91,6 +118,7 @@
- (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();
}
@@ -103,7 +131,17 @@
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];
}
}