]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/NSWindow.mm
Add virtual ~wxAnyScrollHelperBase() to fix compiler warning.
[wxWidgets.git] / src / cocoa / NSWindow.mm
CommitLineData
fb896a32 1/////////////////////////////////////////////////////////////////////////////
1c4e8f38 2// Name: src/cocoa/NSWindow.mm
fb896a32
DE
3// Purpose: wxCocoaNSWindow
4// Author: David Elliott
5// Modified by:
6// Created: 2003/03/16
fb896a32 7// Copyright: (c) 2003 David Elliott
526954c5 8// Licence: wxWindows licence
fb896a32
DE
9/////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19#include "wx/wxprec.h"
20#ifndef WX_PRECOMP
21 #include "wx/log.h"
22 #include "wx/menuitem.h"
23#endif // WX_PRECOMP
24
25#include "wx/cocoa/NSWindow.h"
26
e7e1ad7d
DE
27#include "wx/cocoa/objc/objc_uniquifying.h"
28
720e01c3
DE
29#import <Foundation/NSNotification.h>
30#import <Foundation/NSString.h>
ad3628fa 31#include "wx/cocoa/objc/NSWindow.h"
720e01c3
DE
32
33// ============================================================================
78c67cb6 34// @class wxNSWindowDelegate
720e01c3 35// ============================================================================
78c67cb6 36@interface wxNSWindowDelegate : NSObject
720e01c3 37{
c6f73d05 38 wxCocoaNSWindow *m_wxCocoaInterface;
720e01c3
DE
39}
40
c6f73d05
DE
41- (id)init;
42- (void)setWxCocoaInterface: (wxCocoaNSWindow *)wxCocoaInterface;
43- (wxCocoaNSWindow *)wxCocoaInterface;
44
45// Delegate message handlers
78c67cb6
DE
46- (void)windowDidBecomeKey: (NSNotification *)notification;
47- (void)windowDidResignKey: (NSNotification *)notification;
8fc821cc
DE
48- (void)windowDidBecomeMain: (NSNotification *)notification;
49- (void)windowDidResignMain: (NSNotification *)notification;
eb3426e7 50- (BOOL)windowShouldClose: (id)sender;
9692f42b 51- (void)windowWillClose: (NSNotification *)notification;
86adc758
DE
52
53// Menu item handlers
7dd8b1ea
DE
54- (void)wxMenuItemAction: (NSMenuItem *)menuItem;
55- (BOOL)validateMenuItem: (NSMenuItem *)menuItem;
78c67cb6 56@end //interface wxNSWindowDelegate
e7e1ad7d 57WX_DECLARE_GET_OBJC_CLASS(wxNSWindowDelegate,NSObject)
720e01c3 58
78c67cb6 59@implementation wxNSWindowDelegate : NSObject
720e01c3 60
c6f73d05
DE
61- (id)init
62{
63 m_wxCocoaInterface = NULL;
64 return [super init];
65}
66
67- (void)setWxCocoaInterface: (wxCocoaNSWindow *)wxCocoaInterface
68{
69 m_wxCocoaInterface = wxCocoaInterface;
70}
71
72- (wxCocoaNSWindow *)wxCocoaInterface
73{
74 return m_wxCocoaInterface;
75}
76
86adc758 77// Delegate message handlers
78c67cb6 78- (void)windowDidBecomeKey: (NSNotification *)notification
720e01c3
DE
79{
80 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
c6f73d05 81 wxASSERT(win==m_wxCocoaInterface);
2b030203 82 wxCHECK_RET(win,wxT("notificationDidBecomeKey received but no wxWindow exists"));
aa992c59 83 win->CocoaDelegate_windowDidBecomeKey();
720e01c3
DE
84}
85
78c67cb6 86- (void)windowDidResignKey: (NSNotification *)notification
720e01c3
DE
87{
88 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
c6f73d05 89 wxASSERT(win==m_wxCocoaInterface);
2b030203 90 wxCHECK_RET(win,wxT("notificationDidResignKey received but no wxWindow exists"));
aa992c59 91 win->CocoaDelegate_windowDidResignKey();
720e01c3
DE
92}
93
8fc821cc
DE
94- (void)windowDidBecomeMain: (NSNotification *)notification
95{
96 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
c6f73d05 97 wxASSERT(win==m_wxCocoaInterface);
2b030203 98 wxCHECK_RET(win,wxT("notificationDidBecomeMain received but no wxWindow exists"));
8fc821cc
DE
99 win->CocoaDelegate_windowDidBecomeMain();
100}
101
102- (void)windowDidResignMain: (NSNotification *)notification
103{
104 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
c6f73d05 105 wxASSERT(win==m_wxCocoaInterface);
2b030203 106 wxCHECK_RET(win,wxT("notificationDidResignMain received but no wxWindow exists"));
8fc821cc
DE
107 win->CocoaDelegate_windowDidResignMain();
108}
109
eb3426e7
DE
110- (BOOL)windowShouldClose: (id)sender
111{
48580976 112 wxLogTrace(wxTRACE_COCOA,wxT("windowShouldClose"));
eb3426e7 113 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(sender);
c6f73d05 114 wxASSERT(tlw==m_wxCocoaInterface);
aa992c59 115 if(tlw && !tlw->CocoaDelegate_windowShouldClose())
eb3426e7 116 {
48580976 117 wxLogTrace(wxTRACE_COCOA,wxT("Window will not be closed"));
eb3426e7
DE
118 return NO;
119 }
48580976 120 wxLogTrace(wxTRACE_COCOA,wxT("Window will be closed"));
eb3426e7
DE
121 return YES;
122}
123
9692f42b
DE
124- (void)windowWillClose: (NSNotification *)notification
125{
126 wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
c6f73d05 127 wxASSERT(win==m_wxCocoaInterface);
2b030203 128 wxCHECK_RET(win,wxT("windowWillClose received but no wxWindow exists"));
9692f42b
DE
129 win->CocoaDelegate_windowWillClose();
130}
131
86adc758 132// Menu item handlers
7dd8b1ea 133- (void)wxMenuItemAction: (NSMenuItem *)sender
86adc758
DE
134{
135 wxASSERT(m_wxCocoaInterface);
136 m_wxCocoaInterface->CocoaDelegate_wxMenuItemAction(sender);
137}
138
7dd8b1ea 139- (BOOL)validateMenuItem: (NSMenuItem *)sender
86adc758
DE
140{
141 wxASSERT(m_wxCocoaInterface);
142 return m_wxCocoaInterface->CocoaDelegate_validateMenuItem(sender);
143}
144
78c67cb6 145@end //implementation wxNSWindowDelegate
e7e1ad7d 146WX_IMPLEMENT_GET_OBJC_CLASS(wxNSWindowDelegate,NSObject)
720e01c3
DE
147
148// ============================================================================
149// class wxCocoaNSWindow
150// ============================================================================
fb896a32 151
fb896a32
DE
152WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
153
0092ef0d
DE
154wxCocoaNSWindow::wxCocoaNSWindow(wxTopLevelWindowCocoa *tlw)
155: m_wxTopLevelWindowCocoa(tlw)
c6f73d05 156{
e7e1ad7d 157 m_cocoaDelegate = [[WX_GET_OBJC_CLASS(wxNSWindowDelegate) alloc] init];
c6f73d05
DE
158 [m_cocoaDelegate setWxCocoaInterface: this];
159}
160
161wxCocoaNSWindow::~wxCocoaNSWindow()
162{
163 [m_cocoaDelegate setWxCocoaInterface: NULL];
164 [m_cocoaDelegate release];
165}
720e01c3 166
fb896a32
DE
167void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
168{
bac6f234
DE
169 if(cocoaNSWindow)
170 {
171 [cocoaNSWindow setReleasedWhenClosed: NO];
172 sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
c6f73d05 173 [cocoaNSWindow setDelegate: m_cocoaDelegate];
720e01c3
DE
174 }
175}
176
177void wxCocoaNSWindow::DisassociateNSWindow(WX_NSWindow cocoaNSWindow)
178{
179 if(cocoaNSWindow)
180 {
78c67cb6 181 [cocoaNSWindow setDelegate: nil];
720e01c3 182 sm_cocoaHash.erase(cocoaNSWindow);
bac6f234 183 }
fb896a32
DE
184}
185
8ded703d 186wxMenuBar* wxCocoaNSWindow::GetAppMenuBar(wxCocoaNSWindow *win)
360be3c0
DE
187{
188 return NULL;
189}
190
fb896a32 191// ============================================================================
829a2e95 192// @class WXNSWindow
fb896a32 193// ============================================================================
829a2e95 194@implementation WXNSWindow : NSWindow
fb896a32 195
3d012d1b
DE
196- (BOOL)canBecomeKeyWindow
197{
198 bool canBecome = false;
199 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
200 if(!tlw || !tlw->Cocoa_canBecomeKeyWindow(canBecome))
201 canBecome = [super canBecomeKeyWindow];
202 return canBecome;
203}
204
8fc821cc
DE
205- (BOOL)canBecomeMainWindow
206{
207 bool canBecome = false;
208 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
209 if(!tlw || !tlw->Cocoa_canBecomeMainWindow(canBecome))
210 canBecome = [super canBecomeMainWindow];
211 return canBecome;
212}
213
829a2e95 214@end // implementation WXNSWindow
dc834029 215WX_IMPLEMENT_GET_OBJC_CLASS(WXNSWindow,NSWindow)
829a2e95
DE
216
217// ============================================================================
218// @class WXNSPanel
219// ============================================================================
220@implementation WXNSPanel : NSPanel
221
222- (BOOL)canBecomeKeyWindow
223{
224 bool canBecome = false;
225 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
226 if(!tlw || !tlw->Cocoa_canBecomeKeyWindow(canBecome))
227 canBecome = [super canBecomeKeyWindow];
228 return canBecome;
229}
230
231- (BOOL)canBecomeMainWindow
232{
233 bool canBecome = false;
234 wxCocoaNSWindow *tlw = wxCocoaNSWindow::GetFromCocoa(self);
235 if(!tlw || !tlw->Cocoa_canBecomeMainWindow(canBecome))
236 canBecome = [super canBecomeMainWindow];
237 return canBecome;
238}
239
240@end // implementation WXNSPanel
dc834029 241WX_IMPLEMENT_GET_OBJC_CLASS(WXNSPanel,NSPanel)