]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/NSWindow.mm
No real changes.
[wxWidgets.git] / src / cocoa / NSWindow.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/NSWindow.mm
3 // Purpose: wxCocoaNSWindow
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/03/16
7 // RCS-ID: $Id:
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21 #ifndef WX_PRECOMP
22 #include "wx/log.h"
23 #include "wx/menuitem.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/cocoa/NSWindow.h"
27
28 #import <Appkit/NSWindow.h>
29
30 // ----------------------------------------------------------------------------
31 // globals
32 // ----------------------------------------------------------------------------
33 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
34
35 void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
36 {
37 [cocoaNSWindow setReleasedWhenClosed: NO];
38 sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
39 }
40
41 // ============================================================================
42 // @class wxPoserNSWindow
43 // ============================================================================
44 @interface wxPoserNSWindow : NSWindow
45 {
46 }
47
48 - (void)close;
49 - (BOOL)windowShouldClose: (id)sender;
50
51 - (BOOL)wxMenuItemAction: (id)sender;
52 @end // wxPoserNSwindow
53
54 WX_IMPLEMENT_POSER(wxPoserNSWindow);
55 @implementation wxPoserNSWindow : NSWindow
56
57 - (void)close
58 {
59 wxLogDebug("close");
60 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
61 if(tlw)
62 tlw->Cocoa_close();
63 [super close];
64 }
65
66 - (BOOL)windowShouldClose: (id)sender
67 {
68 wxLogDebug("windowShouldClose");
69 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
70 if(tlw && !tlw->Cocoa_windowShouldClose())
71 return NO;
72 wxLogDebug("Window will most likely be CLOSED");
73 if([[wxPoserNSWindow superclass] instancesRespondToSelector:@selector(windowShouldClose:)])
74 return [super windowShouldClose: sender];
75 return YES;
76 }
77
78 - (BOOL)wxMenuItemAction: (id)sender
79 {
80 wxLogDebug("wxMenuItemAction");
81 wxMenuItem *item = wxMenuItem::GetFromCocoa(sender);
82 if(!item)
83 return NO;
84
85 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
86 wxASSERT(tlw);
87 tlw->Cocoa_wxMenuItemAction(*item);
88 return YES;
89 }
90 @end // implementation wxPoserNSWindow
91