]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/nonownedwnd.mm
reducing key event handling complexity
[wxWidgets.git] / src / osx / cocoa / nonownedwnd.mm
CommitLineData
33e90275 1/////////////////////////////////////////////////////////////////////////////
0f9b48d1 2// Name: src/osx/cocoa/nonownedwnd.mm
33e90275
SC
3// Purpose: non owned window for cocoa
4// Author: DavidStefan Csomor
5// Modified by:
6// Created: 2008-06-20
7// RCS-ID: $Id: nonownedwnd.mm 48805 2007-09-19 14:52:25Z SC $
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
05cf95ed
SC
13#ifndef WX_PRECOMP
14 #include "wx/nonownedwnd.h"
15 #include "wx/frame.h"
33e90275
SC
16#endif
17
33e90275 18#include "wx/osx/private.h"
33e90275 19
33e90275
SC
20NSRect wxToNSRect( NSView* parent, const wxRect& r )
21{
22 NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
23 int y = r.y;
24 int x = r.x ;
94929e7b 25 if ( parent == NULL || ![ parent isFlipped ] )
e490b0d2 26 y = (int)(frame.size.height - ( r.y + r.height ));
33e90275
SC
27 return NSMakeRect(x, y, r.width , r.height);
28}
29
30wxRect wxFromNSRect( NSView* parent, const NSRect& rect )
31{
32 NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
e490b0d2
VZ
33 int y = (int)rect.origin.y;
34 int x = (int)rect.origin.x;
94929e7b 35 if ( parent == NULL || ![ parent isFlipped ] )
e490b0d2
VZ
36 y = (int)(frame.size.height - (rect.origin.y + rect.size.height));
37 return wxRect( x, y, (int)rect.size.width, (int)rect.size.height );
33e90275
SC
38}
39
40NSPoint wxToNSPoint( NSView* parent, const wxPoint& p )
41{
42 NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
43 int x = p.x ;
44 int y = p.y;
94929e7b 45 if ( parent == NULL || ![ parent isFlipped ] )
e490b0d2 46 y = (int)(frame.size.height - ( p.y ));
33e90275
SC
47 return NSMakePoint(x, y);
48}
49
50wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
51{
52 NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
e490b0d2
VZ
53 int x = (int)p.x;
54 int y = (int)p.y;
94929e7b 55 if ( parent == NULL || ![ parent isFlipped ] )
e490b0d2 56 y = (int)(frame.size.height - ( p.y ));
33e90275
SC
57 return wxPoint( x, y);
58}
59
46f573dc
KO
60bool shouldHandleSelector(SEL selector)
61{
03647350 62 if (selector == @selector(noop:)
46f573dc
KO
63 || selector == @selector(complete:)
64 || selector == @selector(deleteBackward:)
65 || selector == @selector(deleteForward:)
66 || selector == @selector(insertNewline:)
67 || selector == @selector(insertTab:)
68 || selector == @selector(keyDown:)
69 || selector == @selector(keyUp:)
70 || selector == @selector(scrollPageUp:)
71 || selector == @selector(scrollPageDown:)
72 || selector == @selector(scrollToBeginningOfDocument:)
73 || selector == @selector(scrollToEndOfDocument:))
74 return false;
03647350 75
46f573dc
KO
76 return true;
77
78}
79
dbeddfb9
SC
80//
81// wx native implementation classes
82//
83
9130dfd7
KO
84typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector);
85
dbeddfb9 86@interface wxNSWindow : NSWindow
dbeddfb9
SC
87{
88 wxNonOwnedWindowCocoaImpl* impl;
89}
90
91- (void)setImplementation: (wxNonOwnedWindowCocoaImpl *) theImplementation;
92- (wxNonOwnedWindowCocoaImpl*) implementation;
9130dfd7 93- (void)noResponderFor: (SEL) selector;
dbeddfb9
SC
94@end
95
96@implementation wxNSWindow
97
98- (void)setImplementation: (wxNonOwnedWindowCocoaImpl *) theImplementation
99{
100 impl = theImplementation;
101}
102
103- (wxNonOwnedWindowCocoaImpl*) implementation
104{
105 return impl;
106}
107
46f573dc
KO
108- (void)doCommandBySelector:(SEL)selector
109{
03647350 110 if (shouldHandleSelector(selector) &&
46f573dc
KO
111 !(selector == @selector(cancel:) || selector == @selector(cancelOperation:)) )
112 [super doCommandBySelector:selector];
113}
114
115
9130dfd7
KO
116// NB: if we don't do this, all key downs that get handled lead to a NSBeep
117- (void)noResponderFor: (SEL) selector
118{
46f573dc 119 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
9130dfd7 120 {
20ede392
SC
121 [super noResponderFor:selector];
122// wxOSX_NoResponderHandlerPtr superimpl = (wxOSX_NoResponderHandlerPtr) [[self superclass] instanceMethodForSelector:@selector(noResponderFor:)];
123// superimpl(self, @selector(noResponderFor:), selector);
9130dfd7
KO
124 }
125}
dbeddfb9
SC
126
127@end
128
bb839504 129@interface wxNSPanel : NSPanel
dbeddfb9
SC
130
131{
bb839504 132 wxNonOwnedWindowCocoaImpl* impl;
dbeddfb9
SC
133}
134
bb839504
KO
135- (void)setImplementation: (wxNonOwnedWindowCocoaImpl *) theImplementation;
136- (wxNonOwnedWindowCocoaImpl*) implementation;
9130dfd7 137- (void)noResponderFor: (SEL) selector;
dbeddfb9
SC
138@end
139
03647350 140@implementation wxNSPanel
dbeddfb9 141
bb839504
KO
142- (void)setImplementation: (wxNonOwnedWindowCocoaImpl *) theImplementation
143{
144 impl = theImplementation;
145}
146
09a9eb20
KO
147- (BOOL)canBecomeKeyWindow
148{
149 return YES;
150}
151
bb839504
KO
152- (wxNonOwnedWindowCocoaImpl*) implementation
153{
154 return impl;
155}
156
46f573dc
KO
157- (void)doCommandBySelector:(SEL)selector
158{
159 if (shouldHandleSelector(selector))
160 [super doCommandBySelector:selector];
161}
162
163// NB: if we don't do this, it seems that all events that end here lead to a NSBeep
9130dfd7
KO
164- (void)noResponderFor: (SEL) selector
165{
46f573dc 166 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
9130dfd7 167 {
20ede392
SC
168 [super noResponderFor:selector];
169// wxOSX_NoResponderHandlerPtr superimpl = (wxOSX_NoResponderHandlerPtr) [[self superclass] instanceMethodForSelector:@selector(noResponderFor:)];
170// superimpl(self, @selector(noResponderFor:), selector);
9130dfd7
KO
171 }
172}
173
dbeddfb9
SC
174@end
175
176
177//
178// controller
179//
180
181@interface wxNonOwnedWindowController : NSObject
182{
183}
184
185- (void)windowDidResize:(NSNotification *)notification;
186- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
09a9eb20
KO
187- (void)windowDidResignKey:(NSNotification *)notification;
188- (void)windowDidBecomeKey:(NSNotification *)notification;
dbeddfb9
SC
189- (void)windowDidMove:(NSNotification *)notification;
190- (BOOL)windowShouldClose:(id)window;
191
192@end
193
194@implementation wxNonOwnedWindowController
195
196- (id) init
197{
198 [super init];
199 return self;
200}
201
202- (BOOL)windowShouldClose:(id)nwindow
203{
204 wxNSWindow* window = (wxNSWindow*) nwindow;
205 wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
206 if ( windowimpl )
207 {
208 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
209 if ( wxpeer )
210 wxpeer->Close();
211 }
212 return NO;
213}
214
5da125c7 215- (NSSize)windowWillResize:(NSWindow *)win
dbeddfb9
SC
216 toSize:(NSSize)proposedFrameSize
217{
5da125c7
SC
218 NSRect frame = [win frame];
219 wxRect wxframe = wxFromNSRect( NULL, frame );
e490b0d2
VZ
220 wxframe.SetWidth( (int)proposedFrameSize.width );
221 wxframe.SetHeight( (int)proposedFrameSize.height );
5da125c7
SC
222 wxNSWindow* window = (wxNSWindow*) win;
223 wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
224 if ( windowimpl )
225 {
226 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
227 if ( wxpeer )
228 {
229 wxpeer->HandleResizing( 0, &wxframe );
230 NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight());
231 return newSize;
232 }
233 }
234
dbeddfb9
SC
235 return proposedFrameSize;
236}
237
238- (void)windowDidResize:(NSNotification *)notification
239{
240 wxNSWindow* window = (wxNSWindow*) [notification object];
241 wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
242 if ( windowimpl )
243 {
244 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
245 if ( wxpeer )
246 wxpeer->HandleResized(0);
247 }
248}
249
250- (void)windowDidMove:(NSNotification *)notification
251{
252 wxNSWindow* window = (wxNSWindow*) [notification object];
253 wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
254 if ( windowimpl )
255 {
256 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
257 if ( wxpeer )
258 wxpeer->HandleMoved(0);
259 }
260}
261
09a9eb20 262- (void)windowDidBecomeKey:(NSNotification *)notification
dbeddfb9
SC
263{
264 wxNSWindow* window = (wxNSWindow*) [notification object];
265 wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
266 if ( windowimpl )
267 {
268 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
269 if ( wxpeer )
270 wxpeer->HandleActivated(0, true);
271 }
272}
273
09a9eb20 274- (void)windowDidResignKey:(NSNotification *)notification
dbeddfb9
SC
275{
276 wxNSWindow* window = (wxNSWindow*) [notification object];
277 wxNonOwnedWindowCocoaImpl* windowimpl = [window implementation];
278 if ( windowimpl )
279 {
280 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
281 if ( wxpeer )
09a9eb20 282 {
dbeddfb9 283 wxpeer->HandleActivated(0, false);
03647350
VZ
284 // Needed for popup window since the firstResponder
285 // (focus in wx) doesn't change when this
09a9eb20
KO
286 // TLW becomes inactive.
287 wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
288 event.SetEventObject(wxpeer);
289 wxpeer->HandleWindowEvent(event);
290 }
dbeddfb9
SC
291 }
292}
293
7cb2a241
SC
294- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
295{
296 wxUnusedVar(sender);
297
298 if ([anObject isKindOfClass:[wxNSTextField class]])
299 {
300 wxNSTextField* tf = (wxNSTextField*) anObject;
301 wxNSTextFieldEditor* editor = [tf fieldEditor];
302 if ( editor == nil )
303 {
304 editor = [[wxNSTextFieldEditor alloc] init];
305 [editor setFieldEditor:YES];
306 [tf setFieldEditor:editor];
307 }
308 return editor;
309 }
310
311 return nil;
312}
313
dbeddfb9
SC
314@end
315
33e90275
SC
316IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
317
03647350 318wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
33e90275
SC
319 wxNonOwnedWindowImpl(nonownedwnd)
320{
321 m_macWindow = NULL;
322 m_macFullScreenData = NULL;
323}
03647350
VZ
324
325wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
33e90275
SC
326{
327 m_macWindow = NULL;
328 m_macFullScreenData = NULL;
329}
03647350 330
33e90275
SC
331wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
332{
be136f07 333 [m_macWindow setImplementation:nil];
42c2b729 334 [m_macWindow setDelegate:nil];
33e90275
SC
335 [m_macWindow release];
336}
337
338void wxNonOwnedWindowCocoaImpl::Destroy()
339{
340 wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) );
341}
342
20ede392
SC
343void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), const wxPoint& pos, const wxSize& size,
344long style, long extraStyle, const wxString& WXUNUSED(name) )
33e90275 345{
dbeddfb9 346 static wxNonOwnedWindowController* controller = NULL;
03647350 347
dbeddfb9
SC
348 if ( !controller )
349 controller =[[wxNonOwnedWindowController alloc] init];
350
351
33e90275 352 int windowstyle = NSBorderlessWindowMask;
03647350
VZ
353
354 if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) ||
09a9eb20
KO
355 GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
356 {
dbeddfb9 357 m_macWindow = [wxNSPanel alloc];
09a9eb20 358 }
33e90275 359 else
dbeddfb9 360 m_macWindow = [wxNSWindow alloc];
03647350 361
e912ebe3 362 CGWindowLevel level = kCGNormalWindowLevel;
03647350 363
33e90275
SC
364 if ( style & wxFRAME_TOOL_WINDOW )
365 {
aa960026
KO
366 windowstyle |= NSUtilityWindowMask;
367 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
368 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
369 {
370 windowstyle |= NSTitledWindowMask ;
371 }
33e90275
SC
372 }
373 else if ( ( style & wxPOPUP_WINDOW ) )
374 {
375 level = kCGPopUpMenuWindowLevel;
376 /*
377 if ( ( style & wxBORDER_NONE ) )
378 {
379 wclass = kHelpWindowClass ; // has no border
380 attr |= kWindowNoShadowAttribute;
381 }
382 else
383 {
384 wclass = kPlainWindowClass ; // has a single line border, it will have to do for now
385 }
386 */
387 }
388 else if ( ( style & wxCAPTION ) )
389 {
390 windowstyle |= NSTitledWindowMask ;
391 }
392 else if ( ( style & wxFRAME_DRAWER ) )
393 {
394 /*
395 wclass = kDrawerWindowClass;
396 */
397 }
398 else
399 {
400 // set these even if we have no title, otherwise the controls won't be visible
401 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
402 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
403 {
404 windowstyle |= NSTitledWindowMask ;
405 }
406 /*
407 else if ( ( style & wxNO_BORDER ) )
408 {
409 wclass = kSimpleWindowClass ;
410 }
411 else
412 {
413 wclass = kPlainWindowClass ;
414 }
415 */
416 }
417
418 if ( windowstyle & NSTitledWindowMask )
419 {
420 if ( ( style & wxMINIMIZE_BOX ) )
421 windowstyle |= NSMiniaturizableWindowMask ;
422
423 if ( ( style & wxMAXIMIZE_BOX ) )
424 windowstyle |= NSResizableWindowMask ; // TODO showing ZOOM ?
425
426 if ( ( style & wxRESIZE_BORDER ) )
427 windowstyle |= NSResizableWindowMask ;
428
429 if ( ( style & wxCLOSE_BOX) )
430 windowstyle |= NSClosableWindowMask ;
431 }
432 if ( extraStyle & wxFRAME_EX_METAL)
433 windowstyle |= NSTexturedBackgroundWindowMask;
434
bb839504
KO
435 if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) )
436 level = kCGFloatingWindowLevel;
437
33e90275
SC
438 if ( ( style & wxSTAY_ON_TOP ) )
439 level = kCGUtilityWindowLevel;
03647350 440
33e90275 441 NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
03647350 442
dbeddfb9 443 [m_macWindow setImplementation:this];
03647350 444
33e90275
SC
445 [m_macWindow initWithContentRect:r
446 styleMask:windowstyle
447 backing:NSBackingStoreBuffered
03647350 448 defer:NO
33e90275 449 ];
03647350 450
33e90275 451 [m_macWindow setLevel:level];
dbeddfb9
SC
452
453 [m_macWindow setDelegate:controller];
03647350 454
826da451 455 [m_macWindow setAcceptsMouseMovedEvents: YES];
33e90275
SC
456}
457
458
459WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
460{
461 return m_macWindow;
462}
463
464void wxNonOwnedWindowCocoaImpl::Raise()
465{
466 [m_macWindow orderWindow:NSWindowAbove relativeTo:0];
467}
03647350 468
33e90275
SC
469void wxNonOwnedWindowCocoaImpl::Lower()
470{
471 [m_macWindow orderWindow:NSWindowBelow relativeTo:0];
472}
473
474bool wxNonOwnedWindowCocoaImpl::Show(bool show)
475{
476 if ( show )
477 {
1f83c631
SC
478 wxNonOwnedWindow* wxpeer = GetWXPeer();
479 if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
480 [m_macWindow makeKeyAndOrderFront:nil];
481 else
482 [m_macWindow orderFront:nil];
483
33e90275
SC
484 [[m_macWindow contentView] setNeedsDisplay:YES];
485 }
03647350 486 else
33e90275
SC
487 [m_macWindow orderOut:nil];
488 return true;
489}
03647350 490
20ede392 491bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show, wxShowEffect WXUNUSED(effect), unsigned WXUNUSED(timeout))
33e90275
SC
492{
493 return Show(show);
494}
495
496void wxNonOwnedWindowCocoaImpl::Update()
497{
498 [m_macWindow displayIfNeeded];
499}
500
501bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
502{
503 [m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
504 return true;
505}
506
20ede392 507bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& WXUNUSED(col) )
33e90275
SC
508{
509 return true;
510}
511
512void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle )
513{
514 if ( m_macWindow )
515 {
516 bool metal = exStyle & wxFRAME_EX_METAL ;
517 int windowStyle = [ m_macWindow styleMask];
518 if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) )
519 {
9a83f860 520 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
33e90275
SC
521 }
522 else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) )
523 {
9a83f860 524 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
03647350 525 }
33e90275
SC
526 }
527}
03647350 528
20ede392 529bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle WXUNUSED(style))
33e90275
SC
530{
531 return true;
532}
03647350 533
33e90275
SC
534bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
535{
536 return true;
537}
538
539void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
540{
541 NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
54f11060
SC
542 // do not trigger refreshes upon invisible and possible partly created objects
543 [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()];
33e90275
SC
544}
545
546void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
547{
548 wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
549 x = r.GetLeft();
550 y = r.GetTop();
551}
552
553void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
554{
555 NSRect rect = [m_macWindow frame];
e490b0d2
VZ
556 width = (int)rect.size.width;
557 height = (int)rect.size.height;
33e90275
SC
558}
559
b0ec7fbb 560void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
33e90275
SC
561{
562 NSRect outer = NSMakeRect(100,100,100,100);
563 NSRect content = [NSWindow contentRectForFrameRect:outer styleMask:[m_macWindow styleMask] ];
564 NSRect rect = [[m_macWindow contentView] frame];
e490b0d2
VZ
565 left = (int)rect.origin.x;
566 top = (int)rect.origin.y;
567 width = (int)rect.size.width;
568 height = (int)rect.size.height;
33e90275 569}
03647350 570
20ede392 571bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
33e90275
SC
572{
573 return false;
574}
575
03647350 576void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
33e90275
SC
577{
578 [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
579}
03647350 580
33e90275
SC
581bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
582{
583 return [m_macWindow isZoomed];
584}
03647350 585
33e90275
SC
586bool wxNonOwnedWindowCocoaImpl::IsIconized() const
587{
588 return [m_macWindow isMiniaturized];
589}
03647350 590
33e90275
SC
591void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
592{
593 if ( iconize )
594 [m_macWindow miniaturize:nil];
595 else
596 [m_macWindow deminiaturize:nil];
597}
03647350 598
20ede392 599void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize))
33e90275
SC
600{
601 [m_macWindow zoom:nil];
602}
03647350 603
33e90275
SC
604
605// http://cocoadevcentral.com/articles/000028.php
606
607typedef struct
608{
609 int m_formerLevel;
610 NSRect m_formerFrame;
611} FullScreenData ;
612
613bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
614{
615 return m_macFullScreenData != NULL ;
616}
03647350 617
20ede392 618bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
33e90275
SC
619{
620 if ( show )
621 {
622 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
623 delete data ;
624 data = new FullScreenData();
625
626 m_macFullScreenData = data ;
627 data->m_formerLevel = [m_macWindow level];
628 data->m_formerFrame = [m_macWindow frame];
629 CGDisplayCapture( kCGDirectMainDisplay );
630 [m_macWindow setLevel:CGShieldingWindowLevel()];
631 [m_macWindow setFrame:[[NSScreen mainScreen] frame] display:YES];
632 }
633 else if ( m_macFullScreenData != NULL )
634 {
635 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
636 CGDisplayRelease( kCGDirectMainDisplay );
637 [m_macWindow setLevel:data->m_formerLevel];
638 [m_macWindow setFrame:data->m_formerFrame display:YES];
639 delete data ;
640 m_macFullScreenData = NULL ;
641 }
03647350 642
33e90275
SC
643 return true;
644}
645
646void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int WXUNUSED(flags))
647{
648}
dbeddfb9
SC
649
650void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
651{
652 wxPoint p((x ? *x : 0), (y ? *y : 0) );
dbeddfb9 653 NSPoint nspt = wxToNSPoint( NULL, p );
54f11060
SC
654 nspt = [m_macWindow convertScreenToBase:nspt];
655 nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil];
656 p = wxFromNSPoint([m_macWindow contentView], nspt);
dbeddfb9 657 if ( x )
03647350 658 *x = p.x;
dbeddfb9
SC
659 if ( y )
660 *y = p.y;
661}
662
663void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
664{
54f11060
SC
665 wxPoint p((x ? *x : 0), (y ? *y : 0) );
666 NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p );
667 nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil];
668 nspt = [m_macWindow convertBaseToScreen:nspt];
669 p = wxFromNSPoint( NULL, nspt);
dbeddfb9
SC
670 if ( x )
671 *x = p.x;
672 if ( y )
673 *y = p.y;
674}
675
676wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
677 long style, long extraStyle, const wxString& name )
678{
679 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
680 now->Create( parent, pos, size, style , extraStyle, name );
681 return now;
54f11060 682}