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/NSWindow.h"
28 #import <Appkit/NSWindow.h>
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
33 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
35 void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
37 [cocoaNSWindow setReleasedWhenClosed: NO];
38 sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
41 // ============================================================================
42 // @class wxPoserNSWindow
43 // ============================================================================
44 @interface wxPoserNSWindow : NSWindow
49 - (BOOL)windowShouldClose: (id)sender;
51 - (BOOL)wxMenuItemAction: (id)sender;
52 @end // wxPoserNSwindow
54 WX_IMPLEMENT_POSER(wxPoserNSWindow);
55 @implementation wxPoserNSWindow : NSWindow
60 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
66 - (BOOL)windowShouldClose: (id)sender
68 wxLogDebug("windowShouldClose");
69 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
70 if(tlw && !tlw->Cocoa_windowShouldClose())
72 wxLogDebug("Window will most likely be CLOSED");
73 if([[wxPoserNSWindow superclass] instancesRespondToSelector:@selector(windowShouldClose:)])
74 return [super windowShouldClose: sender];
78 - (BOOL)wxMenuItemAction: (id)sender
80 wxLogDebug("wxMenuItemAction");
81 wxMenuItem *item = wxMenuItem::GetFromCocoa(sender);
85 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
87 tlw->Cocoa_wxMenuItemAction(*item);
90 @end // implementation wxPoserNSWindow