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>
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
34 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
36 void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
40 [cocoaNSWindow setReleasedWhenClosed: NO];
41 sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
45 // ============================================================================
46 // @class wxPoserNSWindow
47 // ============================================================================
48 @interface wxPoserNSWindow : NSWindow
53 - (BOOL)windowShouldClose: (id)sender;
55 - (BOOL)wxMenuItemAction: (id)sender;
56 @end // wxPoserNSwindow
58 WX_IMPLEMENT_POSER(wxPoserNSWindow);
59 @implementation wxPoserNSWindow : NSWindow
64 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
70 - (BOOL)windowShouldClose: (id)sender
72 wxLogDebug("windowShouldClose");
73 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
74 if(tlw && !tlw->Cocoa_windowShouldClose())
76 wxLogDebug("Window will most likely be CLOSED");
77 if([[wxPoserNSWindow superclass] instancesRespondToSelector:@selector(windowShouldClose:)])
78 return [super windowShouldClose: sender];
82 - (BOOL)wxMenuItemAction: (id)sender
84 wxLogDebug("wxMenuItemAction");
85 wxMenuItem *item = wxMenuItem::GetFromCocoa(sender);
89 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
91 tlw->Cocoa_wxMenuItemAction(*item);
94 @end // implementation wxPoserNSWindow