1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/NSWindow.mm
3 // Purpose: wxCocoaNSWindow
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
23 #include "wx/menuitem.h"
26 #include "wx/cocoa/ObjcPose.h"
27 #include "wx/cocoa/NSWindow.h"
29 #import <Appkit/NSWindow.h>
30 #import <Foundation/NSNotification.h>
31 #import <Foundation/NSString.h>
33 // ============================================================================
34 // @class wxNSWindowDelegate
35 // ============================================================================
36 @interface wxNSWindowDelegate : NSObject
40 - (void)windowDidBecomeKey: (NSNotification *)notification;
41 - (void)windowDidResignKey: (NSNotification *)notification;
42 @end //interface wxNSWindowDelegate
44 @implementation wxNSWindowDelegate : NSObject
46 - (void)windowDidBecomeKey: (NSNotification *)notification
48 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
49 wxCHECK_RET(win,"notificationDidBecomeKey received but no wxWindow exists");
50 win->CocoaNotification_DidBecomeKey();
53 - (void)windowDidResignKey: (NSNotification *)notification
55 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
56 wxCHECK_RET(win,"notificationDidResignKey received but no wxWindow exists");
57 win->CocoaNotification_DidResignKey();
60 @end //implementation wxNSWindowDelegate
62 // ============================================================================
63 // class wxCocoaNSWindow
64 // ============================================================================
66 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
68 struct objc_object *wxCocoaNSWindow::sm_cocoaDelegate = [[wxNSWindowDelegate alloc] init];
70 void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
74 [cocoaNSWindow setReleasedWhenClosed: NO];
75 sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
76 [cocoaNSWindow setDelegate: sm_cocoaDelegate];
80 void wxCocoaNSWindow::DisassociateNSWindow(WX_NSWindow cocoaNSWindow)
84 [cocoaNSWindow setDelegate: nil];
85 sm_cocoaHash.erase(cocoaNSWindow);
89 // ============================================================================
90 // @class wxPoserNSWindow
91 // ============================================================================
92 @interface wxPoserNSWindow : NSWindow
97 - (BOOL)windowShouldClose: (id)sender;
99 @end // wxPoserNSwindow
101 WX_IMPLEMENT_POSER(wxPoserNSWindow);
102 @implementation wxPoserNSWindow : NSWindow
107 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
113 - (BOOL)windowShouldClose: (id)sender
115 wxLogDebug("windowShouldClose");
116 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
117 if(tlw && !tlw->Cocoa_windowShouldClose())
119 wxLogDebug("Window will most likely be CLOSED");
120 if([[wxPoserNSWindow superclass] instancesRespondToSelector:@selector(windowShouldClose:)])
121 return [super windowShouldClose: sender];
125 @end // implementation wxPoserNSWindow