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