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