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