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