]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/NSWindow.mm
reSWIGed
[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/ObjcPose.h"
27 #include "wx/cocoa/NSWindow.h"
28
29 #import <Appkit/NSWindow.h>
30 #import <Foundation/NSNotification.h>
31 #import <Foundation/NSString.h>
32
33 // ============================================================================
34 // @class wxNSWindowDelegate
35 // ============================================================================
36 @interface wxNSWindowDelegate : NSObject
37 {
38 }
39
40 - (void)windowDidBecomeKey: (NSNotification *)notification;
41 - (void)windowDidResignKey: (NSNotification *)notification;
42 - (void)windowDidBecomeMain: (NSNotification *)notification;
43 - (void)windowDidResignMain: (NSNotification *)notification;
44 - (BOOL)windowShouldClose: (id)sender;
45 - (void)windowWillClose: (NSNotification *)notification;
46 @end //interface wxNSWindowDelegate
47
48 @implementation wxNSWindowDelegate : NSObject
49
50 - (void)windowDidBecomeKey: (NSNotification *)notification
51 {
52 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
53 wxCHECK_RET(win,"notificationDidBecomeKey received but no wxWindow exists");
54 win->CocoaDelegate_windowDidBecomeKey();
55 }
56
57 - (void)windowDidResignKey: (NSNotification *)notification
58 {
59 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
60 wxCHECK_RET(win,"notificationDidResignKey received but no wxWindow exists");
61 win->CocoaDelegate_windowDidResignKey();
62 }
63
64 - (void)windowDidBecomeMain: (NSNotification *)notification
65 {
66 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
67 wxCHECK_RET(win,"notificationDidBecomeMain received but no wxWindow exists");
68 win->CocoaDelegate_windowDidBecomeMain();
69 }
70
71 - (void)windowDidResignMain: (NSNotification *)notification
72 {
73 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
74 wxCHECK_RET(win,"notificationDidResignMain received but no wxWindow exists");
75 win->CocoaDelegate_windowDidResignMain();
76 }
77
78 - (BOOL)windowShouldClose: (id)sender
79 {
80 wxLogDebug("windowShouldClose");
81 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
82 if(tlw && !tlw->CocoaDelegate_windowShouldClose())
83 {
84 wxLogDebug("Window will not be closed");
85 return NO;
86 }
87 wxLogDebug("Window will be closed");
88 return YES;
89 }
90
91 - (void)windowWillClose: (NSNotification *)notification
92 {
93 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
94 wxCHECK_RET(win,"windowWillClose received but no wxWindow exists");
95 win->CocoaDelegate_windowWillClose();
96 }
97
98 @end //implementation wxNSWindowDelegate
99
100 // ============================================================================
101 // class wxCocoaNSWindow
102 // ============================================================================
103
104 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
105
106 struct objc_object *wxCocoaNSWindow::sm_cocoaDelegate = [[wxNSWindowDelegate alloc] init];
107
108 void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
109 {
110 if(cocoaNSWindow)
111 {
112 [cocoaNSWindow setReleasedWhenClosed: NO];
113 sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
114 [cocoaNSWindow setDelegate: sm_cocoaDelegate];
115 }
116 }
117
118 void wxCocoaNSWindow::DisassociateNSWindow(WX_NSWindow cocoaNSWindow)
119 {
120 if(cocoaNSWindow)
121 {
122 [cocoaNSWindow setDelegate: nil];
123 sm_cocoaHash.erase(cocoaNSWindow);
124 }
125 }
126
127 wxMenuBar* wxCocoaNSWindow::GetAppMenuBar(wxCocoaNSWindow *win)
128 {
129 return NULL;
130 }
131
132 // ============================================================================
133 // @class wxPoserNSWindow
134 // ============================================================================
135 @interface wxPoserNSWindow : NSWindow
136 {
137 }
138
139 - (BOOL)canBecomeMainWindow;
140 @end // wxPoserNSwindow
141
142 WX_IMPLEMENT_POSER(wxPoserNSWindow);
143 @implementation wxPoserNSWindow : NSWindow
144
145 - (BOOL)canBecomeMainWindow
146 {
147 bool canBecome = false;
148 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
149 if(!tlw || !tlw->Cocoa_canBecomeMainWindow(canBecome))
150 canBecome = [super canBecomeMainWindow];
151 return canBecome;
152 }
153
154 @end // implementation wxPoserNSWindow
155