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)
38 [cocoaNSWindow setReleasedWhenClosed: NO];
39 sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
42 // ============================================================================
43 // @class wxPoserNSWindow
44 // ============================================================================
45 @interface wxPoserNSWindow : NSWindow
50 - (BOOL)windowShouldClose: (id)sender;
52 - (BOOL)wxMenuItemAction: (id)sender;
53 @end // wxPoserNSwindow
55 WX_IMPLEMENT_POSER(wxPoserNSWindow);
56 @implementation wxPoserNSWindow : NSWindow
61 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
67 - (BOOL)windowShouldClose: (id)sender
69 wxLogDebug("windowShouldClose");
70 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
71 if(tlw && !tlw->Cocoa_windowShouldClose())
73 wxLogDebug("Window will most likely be CLOSED");
74 if([[wxPoserNSWindow superclass] instancesRespondToSelector:@selector(windowShouldClose:)])
75 return [super windowShouldClose: sender];
79 - (BOOL)wxMenuItemAction: (id)sender
81 wxLogDebug("wxMenuItemAction");
82 wxMenuItem *item = wxMenuItem::GetFromCocoa(sender);
86 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
88 tlw->Cocoa_wxMenuItemAction(*item);
91 @end // implementation wxPoserNSWindow