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