supporting disabled tools, fixes #11457
[wxWidgets.git] / src / osx / cocoa / nonownedwnd.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/nonownedwnd.mm
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"
13 #ifndef WX_PRECOMP
14 #include "wx/nonownedwnd.h"
15 #include "wx/frame.h"
16 #include "wx/app.h"
17 #endif
18
19 #include "wx/osx/private.h"
20
21 NSRect wxToNSRect( NSView* parent, const wxRect& r )
22 {
23 NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
24 int y = r.y;
25 int x = r.x ;
26 if ( parent == NULL || ![ parent isFlipped ] )
27 y = (int)(frame.size.height - ( r.y + r.height ));
28 return NSMakeRect(x, y, r.width , r.height);
29 }
30
31 wxRect wxFromNSRect( NSView* parent, const NSRect& rect )
32 {
33 NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
34 int y = (int)rect.origin.y;
35 int x = (int)rect.origin.x;
36 if ( parent == NULL || ![ parent isFlipped ] )
37 y = (int)(frame.size.height - (rect.origin.y + rect.size.height));
38 return wxRect( x, y, (int)rect.size.width, (int)rect.size.height );
39 }
40
41 NSPoint wxToNSPoint( NSView* parent, const wxPoint& p )
42 {
43 NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
44 int x = p.x ;
45 int y = p.y;
46 if ( parent == NULL || ![ parent isFlipped ] )
47 y = (int)(frame.size.height - ( p.y ));
48 return NSMakePoint(x, y);
49 }
50
51 wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
52 {
53 NSRect frame = parent ? [parent bounds] : [[NSScreen mainScreen] frame];
54 int x = (int)p.x;
55 int y = (int)p.y;
56 if ( parent == NULL || ![ parent isFlipped ] )
57 y = (int)(frame.size.height - ( p.y ));
58 return wxPoint( x, y);
59 }
60
61 bool shouldHandleSelector(SEL selector)
62 {
63 if (selector == @selector(noop:)
64 || selector == @selector(complete:)
65 || selector == @selector(deleteBackward:)
66 || selector == @selector(deleteForward:)
67 || selector == @selector(insertNewline:)
68 || selector == @selector(insertTab:)
69 || selector == @selector(keyDown:)
70 || selector == @selector(keyUp:)
71 || selector == @selector(scrollPageUp:)
72 || selector == @selector(scrollPageDown:)
73 || selector == @selector(scrollToBeginningOfDocument:)
74 || selector == @selector(scrollToEndOfDocument:))
75 return false;
76
77 return true;
78
79 }
80
81 //
82 // wx category for NSWindow (our own and wrapped instances)
83 //
84
85 @interface NSWindow (wxNSWindowSupport)
86
87 - (wxNonOwnedWindowCocoaImpl*) WX_implementation;
88
89 - (bool) WX_filterSendEvent:(NSEvent *) event;
90
91 @end
92
93 @implementation NSWindow (wxNSWindowSupport)
94
95 - (wxNonOwnedWindowCocoaImpl*) WX_implementation
96 {
97 return (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
98 }
99
100 // TODO in cocoa everything during a drag is sent to the NSWindow the mouse down occured,
101 // this does not conform to the wx behaviour if the window is not captured, so try to resend
102 // or capture all wx mouse event handling at the tlw as we did for carbon
103
104 - (bool) WX_filterSendEvent:(NSEvent *) event
105 {
106 bool handled = false;
107 if ( ([event type] >= NSLeftMouseDown) && ([event type] <= NSMouseExited) )
108 {
109 wxWindow* cw = wxWindow::GetCapture();
110 if ( cw != NULL )
111 {
112 ((wxWidgetCocoaImpl*)cw->GetPeer())->DoHandleMouseEvent( event);
113 handled = true;
114 }
115 }
116 return handled;
117 }
118 @end
119
120 //
121 // wx native implementation
122 //
123
124 @interface wxNSWindow : NSWindow
125 {
126 }
127
128 - (void) sendEvent:(NSEvent *)event;
129 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
130 - (void)noResponderFor: (SEL) selector;
131 @end
132
133 @implementation wxNSWindow
134
135 - (void)sendEvent:(NSEvent *) event
136 {
137 if ( ![self WX_filterSendEvent: event] )
138 {
139 WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
140 WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
141
142 if (wxTheApp)
143 wxTheApp->MacSetCurrentEvent(event, NULL);
144
145 [super sendEvent: event];
146
147 if (wxTheApp)
148 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
149 }
150 }
151
152 // The default implementation always moves the window back onto the screen,
153 // even when the programmer explicitly wants to hide it.
154 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
155 {
156 wxUnusedVar(screen);
157 return frameRect;
158 }
159
160 - (void)doCommandBySelector:(SEL)selector
161 {
162 if (shouldHandleSelector(selector) &&
163 !(selector == @selector(cancel:) || selector == @selector(cancelOperation:)) )
164 [super doCommandBySelector:selector];
165 }
166
167
168 // NB: if we don't do this, all key downs that get handled lead to a NSBeep
169 - (void)noResponderFor: (SEL) selector
170 {
171 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
172 {
173 [super noResponderFor:selector];
174 }
175 }
176
177 // We need this for borderless windows, i.e. shaped windows or windows without
178 // a title bar. For more info, see:
179 // http://lists.apple.com/archives/cocoa-dev/2008/May/msg02091.html
180 - (BOOL)canBecomeKeyWindow
181 {
182 return YES;
183 }
184
185 @end
186
187 @interface wxNSPanel : NSPanel
188 {
189 }
190
191 - (void)noResponderFor: (SEL) selector;
192 - (void)sendEvent:(NSEvent *)event;
193 @end
194
195 @implementation wxNSPanel
196
197 - (BOOL)canBecomeKeyWindow
198 {
199 return YES;
200 }
201
202 - (void)doCommandBySelector:(SEL)selector
203 {
204 if (shouldHandleSelector(selector))
205 [super doCommandBySelector:selector];
206 }
207
208 // NB: if we don't do this, it seems that all events that end here lead to a NSBeep
209 - (void)noResponderFor: (SEL) selector
210 {
211 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
212 {
213 [super noResponderFor:selector];
214 }
215 }
216
217 - (void)sendEvent:(NSEvent *) event
218 {
219 if ( ![self WX_filterSendEvent: event] )
220 [super sendEvent: event];
221 }
222
223 @end
224
225
226 //
227 // controller
228 //
229
230 @interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>)
231 {
232 }
233
234 - (void)windowDidResize:(NSNotification *)notification;
235 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
236 - (void)windowDidResignKey:(NSNotification *)notification;
237 - (void)windowDidBecomeKey:(NSNotification *)notification;
238 - (void)windowDidMove:(NSNotification *)notification;
239 - (BOOL)windowShouldClose:(id)window;
240 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
241
242 @end
243
244 @implementation wxNonOwnedWindowController
245
246 - (id) init
247 {
248 [super init];
249 return self;
250 }
251
252 - (BOOL)windowShouldClose:(id)nwindow
253 {
254 wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation];
255 if ( windowimpl )
256 {
257 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
258 if ( wxpeer )
259 wxpeer->Close();
260 }
261 return NO;
262 }
263
264 - (NSSize)windowWillResize:(NSWindow *)window
265 toSize:(NSSize)proposedFrameSize
266 {
267 NSRect frame = [window frame];
268 wxRect wxframe = wxFromNSRect( NULL, frame );
269 wxframe.SetWidth( (int)proposedFrameSize.width );
270 wxframe.SetHeight( (int)proposedFrameSize.height );
271
272 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
273 if ( windowimpl )
274 {
275 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
276 if ( wxpeer )
277 {
278 wxpeer->HandleResizing( 0, &wxframe );
279 NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight());
280 return newSize;
281 }
282 }
283
284 return proposedFrameSize;
285 }
286
287 - (void)windowDidResize:(NSNotification *)notification
288 {
289 NSWindow* window = (NSWindow*) [notification object];
290 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
291 if ( windowimpl )
292 {
293 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
294 if ( wxpeer )
295 wxpeer->HandleResized(0);
296 }
297 }
298
299 - (void)windowDidMove:(NSNotification *)notification
300 {
301 wxNSWindow* window = (wxNSWindow*) [notification object];
302 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
303 if ( windowimpl )
304 {
305 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
306 if ( wxpeer )
307 wxpeer->HandleMoved(0);
308 }
309 }
310
311 - (void)windowDidBecomeKey:(NSNotification *)notification
312 {
313 NSWindow* window = (NSWindow*) [notification object];
314 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
315 if ( windowimpl )
316 {
317 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
318 if ( wxpeer )
319 wxpeer->HandleActivated(0, true);
320 }
321 }
322
323 - (void)windowDidResignKey:(NSNotification *)notification
324 {
325 NSWindow* window = (NSWindow*) [notification object];
326 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
327 if ( windowimpl )
328 {
329 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
330 if ( wxpeer )
331 {
332 wxpeer->HandleActivated(0, false);
333 // Needed for popup window since the firstResponder
334 // (focus in wx) doesn't change when this
335 // TLW becomes inactive.
336 wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
337 event.SetEventObject(wxpeer);
338 wxpeer->HandleWindowEvent(event);
339 }
340 }
341 }
342
343 - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
344 {
345 wxUnusedVar(sender);
346
347 if ([anObject isKindOfClass:[wxNSTextField class]])
348 {
349 wxNSTextField* tf = (wxNSTextField*) anObject;
350 wxNSTextFieldEditor* editor = [tf fieldEditor];
351 if ( editor == nil )
352 {
353 editor = [[wxNSTextFieldEditor alloc] init];
354 [editor setFieldEditor:YES];
355 [tf setFieldEditor:editor];
356 }
357 return editor;
358 }
359
360 return nil;
361 }
362
363 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
364 {
365 wxUnusedVar(newFrame);
366 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
367 if ( windowimpl )
368 {
369 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
370 wxMaximizeEvent event(wxpeer->GetId());
371 event.SetEventObject(wxpeer);
372 return !wxpeer->HandleWindowEvent(event);
373 }
374 return true;
375 }
376
377 @end
378
379 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
380
381 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
382 wxNonOwnedWindowImpl(nonownedwnd)
383 {
384 m_macWindow = NULL;
385 m_macFullScreenData = NULL;
386 }
387
388 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
389 {
390 m_macWindow = NULL;
391 m_macFullScreenData = NULL;
392 }
393
394 wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
395 {
396 if ( !m_wxPeer->IsNativeWindowWrapper() )
397 {
398 [m_macWindow setDelegate:nil];
399 [m_macWindow release];
400 }
401 }
402
403 void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
404 {
405 if ( !m_wxPeer->IsNativeWindowWrapper() )
406 {
407 [m_macWindow setDelegate:nil];
408 }
409 }
410
411 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), const wxPoint& pos, const wxSize& size,
412 long style, long extraStyle, const wxString& WXUNUSED(name) )
413 {
414 static wxNonOwnedWindowController* controller = NULL;
415
416 if ( !controller )
417 controller =[[wxNonOwnedWindowController alloc] init];
418
419
420 int windowstyle = NSBorderlessWindowMask;
421
422 if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) ||
423 GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
424 {
425 m_macWindow = [wxNSPanel alloc];
426 }
427 else
428 m_macWindow = [wxNSWindow alloc];
429
430 CGWindowLevel level = kCGNormalWindowLevel;
431
432 if ( style & wxFRAME_TOOL_WINDOW )
433 {
434 windowstyle |= NSUtilityWindowMask;
435 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
436 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
437 {
438 windowstyle |= NSTitledWindowMask ;
439 }
440 }
441 else if ( ( style & wxPOPUP_WINDOW ) )
442 {
443 level = kCGPopUpMenuWindowLevel;
444 /*
445 if ( ( style & wxBORDER_NONE ) )
446 {
447 wclass = kHelpWindowClass ; // has no border
448 attr |= kWindowNoShadowAttribute;
449 }
450 else
451 {
452 wclass = kPlainWindowClass ; // has a single line border, it will have to do for now
453 }
454 */
455 }
456 else if ( ( style & wxCAPTION ) )
457 {
458 windowstyle |= NSTitledWindowMask ;
459 }
460 else if ( ( style & wxFRAME_DRAWER ) )
461 {
462 /*
463 wclass = kDrawerWindowClass;
464 */
465 }
466 else
467 {
468 // set these even if we have no title, otherwise the controls won't be visible
469 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
470 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
471 {
472 windowstyle |= NSTitledWindowMask ;
473 }
474 /*
475 else if ( ( style & wxNO_BORDER ) )
476 {
477 wclass = kSimpleWindowClass ;
478 }
479 else
480 {
481 wclass = kPlainWindowClass ;
482 }
483 */
484 }
485
486 if ( windowstyle & NSTitledWindowMask )
487 {
488 if ( ( style & wxMINIMIZE_BOX ) )
489 windowstyle |= NSMiniaturizableWindowMask ;
490
491 if ( ( style & wxMAXIMIZE_BOX ) )
492 windowstyle |= NSResizableWindowMask ; // TODO showing ZOOM ?
493
494 if ( ( style & wxRESIZE_BORDER ) )
495 windowstyle |= NSResizableWindowMask ;
496
497 if ( ( style & wxCLOSE_BOX) )
498 windowstyle |= NSClosableWindowMask ;
499 }
500 if ( extraStyle & wxFRAME_EX_METAL)
501 windowstyle |= NSTexturedBackgroundWindowMask;
502
503 if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) )
504 level = kCGFloatingWindowLevel;
505
506 if ( ( style & wxSTAY_ON_TOP ) )
507 level = kCGUtilityWindowLevel;
508
509 NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
510
511 r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle];
512
513 [m_macWindow initWithContentRect:r
514 styleMask:windowstyle
515 backing:NSBackingStoreBuffered
516 defer:NO
517 ];
518
519 [m_macWindow setLevel:level];
520
521 [m_macWindow setDelegate:controller];
522
523 [m_macWindow setAcceptsMouseMovedEvents: YES];
524
525 if ( ( style & wxFRAME_SHAPED) )
526 {
527 [m_macWindow setOpaque:NO];
528 [m_macWindow setAlphaValue:1.0];
529 }
530 }
531
532 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
533 {
534 m_macWindow = nativeWindow;
535 }
536
537 WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
538 {
539 return m_macWindow;
540 }
541
542 void wxNonOwnedWindowCocoaImpl::Raise()
543 {
544 [m_macWindow orderWindow:NSWindowAbove relativeTo:0];
545 }
546
547 void wxNonOwnedWindowCocoaImpl::Lower()
548 {
549 [m_macWindow orderWindow:NSWindowBelow relativeTo:0];
550 }
551
552 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
553 {
554 [m_macWindow orderFront:nil];
555 [[m_macWindow contentView] setNeedsDisplay: YES];
556 }
557
558 bool wxNonOwnedWindowCocoaImpl::Show(bool show)
559 {
560 if ( show )
561 {
562 wxNonOwnedWindow* wxpeer = GetWXPeer();
563 if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
564 [m_macWindow makeKeyAndOrderFront:nil];
565 else
566 [m_macWindow orderFront:nil];
567 [[m_macWindow contentView] setNeedsDisplay: YES];
568 }
569 else
570 [m_macWindow orderOut:nil];
571 return true;
572 }
573
574 bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show,
575 wxShowEffect effect,
576 unsigned timeout)
577 {
578 return wxWidgetCocoaImpl::
579 ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout);
580 }
581
582 void wxNonOwnedWindowCocoaImpl::Update()
583 {
584 [m_macWindow displayIfNeeded];
585 }
586
587 bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
588 {
589 [m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
590 return true;
591 }
592
593 bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& WXUNUSED(col) )
594 {
595 return true;
596 }
597
598 void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle )
599 {
600 if ( m_macWindow )
601 {
602 bool metal = exStyle & wxFRAME_EX_METAL ;
603 int windowStyle = [ m_macWindow styleMask];
604 if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) )
605 {
606 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
607 }
608 else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) )
609 {
610 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
611 }
612 }
613 }
614
615 void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style )
616 {
617 if (m_macWindow)
618 {
619 CGWindowLevel level = kCGNormalWindowLevel;
620
621 if (style & wxSTAY_ON_TOP)
622 level = kCGUtilityWindowLevel;
623 else if (( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ))
624 level = kCGFloatingWindowLevel;
625
626 [m_macWindow setLevel: level];
627 }
628 }
629
630 bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
631 {
632 if ( style == wxBG_STYLE_TRANSPARENT )
633 {
634 [m_macWindow setOpaque:NO];
635 [m_macWindow setBackgroundColor:[NSColor clearColor]];
636 }
637
638 return true;
639 }
640
641 bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
642 {
643 return true;
644 }
645
646 void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
647 {
648 NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
649 // do not trigger refreshes upon invisible and possible partly created objects
650 [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()];
651 }
652
653 void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
654 {
655 wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
656 x = r.GetLeft();
657 y = r.GetTop();
658 }
659
660 void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
661 {
662 NSRect rect = [m_macWindow frame];
663 width = (int)rect.size.width;
664 height = (int)rect.size.height;
665 }
666
667 void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
668 {
669 NSRect outer = NSMakeRect(100,100,100,100);
670 NSRect content = [NSWindow contentRectForFrameRect:outer styleMask:[m_macWindow styleMask] ];
671 NSRect rect = [[m_macWindow contentView] frame];
672 left = (int)rect.origin.x;
673 top = (int)rect.origin.y;
674 width = (int)rect.size.width;
675 height = (int)rect.size.height;
676 }
677
678 bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
679 {
680 [m_macWindow setOpaque:NO];
681 [m_macWindow setBackgroundColor:[NSColor clearColor]];
682
683 return true;
684 }
685
686 void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
687 {
688 [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
689 }
690
691 bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
692 {
693 if (([m_macWindow styleMask] & NSResizableWindowMask) != 0)
694 {
695 return [m_macWindow isZoomed];
696 }
697 else
698 {
699 NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
700 NSRect rectWindow = [m_macWindow frame];
701 return (rectScreen.origin.x == rectWindow.origin.x &&
702 rectScreen.origin.y == rectWindow.origin.y &&
703 rectScreen.size.width == rectWindow.size.width &&
704 rectScreen.size.height == rectWindow.size.height);
705 }
706 }
707
708 bool wxNonOwnedWindowCocoaImpl::IsIconized() const
709 {
710 return [m_macWindow isMiniaturized];
711 }
712
713 void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
714 {
715 if ( iconize )
716 [m_macWindow miniaturize:nil];
717 else
718 [m_macWindow deminiaturize:nil];
719 }
720
721 void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize))
722 {
723 [m_macWindow zoom:nil];
724 }
725
726
727 // http://cocoadevcentral.com/articles/000028.php
728
729 typedef struct
730 {
731 int m_formerLevel;
732 NSRect m_formerFrame;
733 } FullScreenData ;
734
735 bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
736 {
737 return m_macFullScreenData != NULL ;
738 }
739
740 bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
741 {
742 if ( show )
743 {
744 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
745 delete data ;
746 data = new FullScreenData();
747
748 m_macFullScreenData = data ;
749 data->m_formerLevel = [m_macWindow level];
750 data->m_formerFrame = [m_macWindow frame];
751 CGDisplayCapture( kCGDirectMainDisplay );
752 [m_macWindow setLevel:CGShieldingWindowLevel()];
753 [m_macWindow setFrame:[[NSScreen mainScreen] frame] display:YES];
754 }
755 else if ( m_macFullScreenData != NULL )
756 {
757 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
758 CGDisplayRelease( kCGDirectMainDisplay );
759 [m_macWindow setLevel:data->m_formerLevel];
760 [m_macWindow setFrame:data->m_formerFrame display:YES];
761 delete data ;
762 m_macFullScreenData = NULL ;
763 }
764
765 return true;
766 }
767
768 void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX)
769 {
770 NSRequestUserAttentionType flagsOSX;
771 switch ( flagsWX )
772 {
773 case wxUSER_ATTENTION_INFO:
774 flagsOSX = NSInformationalRequest;
775 break;
776
777 case wxUSER_ATTENTION_ERROR:
778 flagsOSX = NSCriticalRequest;
779 break;
780
781 default:
782 wxFAIL_MSG( "invalid RequestUserAttention() flags" );
783 return;
784 }
785
786 [NSApp requestUserAttention:flagsOSX];
787 }
788
789 void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
790 {
791 wxPoint p((x ? *x : 0), (y ? *y : 0) );
792 NSPoint nspt = wxToNSPoint( NULL, p );
793 nspt = [m_macWindow convertScreenToBase:nspt];
794 nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil];
795 p = wxFromNSPoint([m_macWindow contentView], nspt);
796 if ( x )
797 *x = p.x;
798 if ( y )
799 *y = p.y;
800 }
801
802 void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
803 {
804 wxPoint p((x ? *x : 0), (y ? *y : 0) );
805 NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p );
806 nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil];
807 nspt = [m_macWindow convertBaseToScreen:nspt];
808 p = wxFromNSPoint( NULL, nspt);
809 if ( x )
810 *x = p.x;
811 if ( y )
812 *y = p.y;
813 }
814
815 bool wxNonOwnedWindowCocoaImpl::IsActive()
816 {
817 return [m_macWindow isKeyWindow];
818 }
819
820 void wxNonOwnedWindowCocoaImpl::SetModified(bool modified)
821 {
822 [m_macWindow setDocumentEdited:modified];
823 }
824
825 bool wxNonOwnedWindowCocoaImpl::IsModified() const
826 {
827 return [m_macWindow isDocumentEdited];
828 }
829
830 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
831 {
832 wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
833 now->Create( parent, nativeWindow );
834 return now;
835 }
836
837 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
838 long style, long extraStyle, const wxString& name )
839 {
840 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
841 now->Create( parent, pos, size, style , extraStyle, name );
842 return now;
843 }