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 - (BOOL)windowShouldClose: (id)sender;
43 @end //interface wxNSWindowDelegate
45 @implementation wxNSWindowDelegate : NSObject
47 - (void)windowDidBecomeKey: (NSNotification *)notification
49 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
50 wxCHECK_RET(win,"notificationDidBecomeKey received but no wxWindow exists");
51 win->CocoaDelegate_windowDidBecomeKey();
54 - (void)windowDidResignKey: (NSNotification *)notification
56 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
57 wxCHECK_RET(win,"notificationDidResignKey received but no wxWindow exists");
58 win->CocoaDelegate_windowDidResignKey();
61 - (BOOL)windowShouldClose: (id)sender
63 wxLogDebug("windowShouldClose");
64 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
65 if(tlw && !tlw->CocoaDelegate_windowShouldClose())
67 wxLogDebug("Window will not be closed");
70 wxLogDebug("Window will be closed");
74 @end //implementation wxNSWindowDelegate
76 // ============================================================================
77 // class wxCocoaNSWindow
78 // ============================================================================
80 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
82 struct objc_object *wxCocoaNSWindow::sm_cocoaDelegate = [[wxNSWindowDelegate alloc] init];
84 void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
88 [cocoaNSWindow setReleasedWhenClosed: NO];
89 sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
90 [cocoaNSWindow setDelegate: sm_cocoaDelegate];
94 void wxCocoaNSWindow::DisassociateNSWindow(WX_NSWindow cocoaNSWindow)
98 [cocoaNSWindow setDelegate: nil];
99 sm_cocoaHash.erase(cocoaNSWindow);
103 // ============================================================================
104 // @class wxPoserNSWindow
105 // ============================================================================
106 @interface wxPoserNSWindow : NSWindow
111 @end // wxPoserNSwindow
113 WX_IMPLEMENT_POSER(wxPoserNSWindow);
114 @implementation wxPoserNSWindow : NSWindow
119 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
125 @end // implementation wxPoserNSWindow