1 /////////////////////////////////////////////////////////////////////////////
 
   2 // Name:        src/osx/cocoa/nonownedwnd.mm
 
   3 // Purpose:     non owned window for cocoa
 
   4 // Author:      DavidStefan Csomor
 
   7 // Copyright:   (c) Stefan Csomor
 
   8 // Licence:     wxWindows licence
 
   9 /////////////////////////////////////////////////////////////////////////////
 
  11 #include "wx/wxprec.h"
 
  13     #include "wx/nonownedwnd.h"
 
  16     #include "wx/dialog.h"
 
  17     #include "wx/menuitem.h"
 
  21 #include "wx/osx/private.h"
 
  23 NSScreen* wxOSXGetMenuScreen()
 
  25     if ( [NSScreen screens] == nil )
 
  26         return [NSScreen mainScreen];
 
  29         return [[NSScreen screens] objectAtIndex:0];
 
  33 NSRect wxToNSRect( NSView* parent, const wxRect& r )
 
  35     NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
 
  38     if ( parent == NULL || ![ parent isFlipped ] )
 
  39         y = (int)(frame.size.height - ( r.y + r.height ));
 
  40     return NSMakeRect(x, y, r.width , r.height);
 
  43 wxRect wxFromNSRect( NSView* parent, const NSRect& rect )
 
  45     NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
 
  46     int y = (int)rect.origin.y;
 
  47     int x = (int)rect.origin.x;
 
  48     if ( parent == NULL || ![ parent isFlipped ] )
 
  49         y = (int)(frame.size.height - (rect.origin.y + rect.size.height));
 
  50     return wxRect( x, y, (int)rect.size.width, (int)rect.size.height );
 
  53 NSPoint wxToNSPoint( NSView* parent, const wxPoint& p )
 
  55     NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
 
  58     if ( parent == NULL || ![ parent isFlipped ] )
 
  59         y = (int)(frame.size.height - ( p.y ));
 
  60     return NSMakePoint(x, y);
 
  63 wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
 
  65     NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
 
  68     if ( parent == NULL || ![ parent isFlipped ] )
 
  69         y = (int)(frame.size.height - ( p.y ));
 
  70     return wxPoint( x, y);
 
  73 bool shouldHandleSelector(SEL selector)
 
  75     if (selector == @selector(noop:)
 
  76             || selector == @selector(complete:)
 
  77             || selector == @selector(deleteBackward:)
 
  78             || selector == @selector(deleteForward:)
 
  79             || selector == @selector(insertNewline:)
 
  80             || selector == @selector(insertTab:)
 
  81             || selector == @selector(insertBacktab:)
 
  82             || selector == @selector(keyDown:)
 
  83             || selector == @selector(keyUp:)
 
  84             || selector == @selector(scrollPageUp:)
 
  85             || selector == @selector(scrollPageDown:)
 
  86             || selector == @selector(scrollToBeginningOfDocument:)
 
  87             || selector == @selector(scrollToEndOfDocument:))
 
  95 // wx category for NSWindow (our own and wrapped instances)
 
  98 @interface NSWindow (wxNSWindowSupport)
 
 100 - (wxNonOwnedWindowCocoaImpl*) WX_implementation;
 
 102 - (bool) WX_filterSendEvent:(NSEvent *) event;
 
 106 @implementation NSWindow (wxNSWindowSupport)
 
 108 - (wxNonOwnedWindowCocoaImpl*) WX_implementation
 
 110     return (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
 
 113 // TODO in cocoa everything during a drag is sent to the NSWindow the mouse down occurred,
 
 114 // this does not conform to the wx behaviour if the window is not captured, so try to resend
 
 115 // or capture all wx mouse event handling at the tlw as we did for carbon
 
 117 - (bool) WX_filterSendEvent:(NSEvent *) event
 
 119     bool handled = false;
 
 120     if ( ([event type] >= NSLeftMouseDown) && ([event type] <= NSMouseExited) )
 
 122         WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
 
 123         WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
 
 125         wxWindow* cw = wxWindow::GetCapture();
 
 129                 wxTheApp->MacSetCurrentEvent(event, NULL);
 
 130             ((wxWidgetCocoaImpl*)cw->GetPeer())->DoHandleMouseEvent( event);
 
 136                 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
 
 144 // wx native implementation 
 
 147 static NSResponder* s_nextFirstResponder = NULL;
 
 149 @interface wxNSWindow : NSWindow
 
 153 - (void) sendEvent:(NSEvent *)event;
 
 154 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
 
 155 - (void)noResponderFor: (SEL) selector;
 
 156 - (BOOL)makeFirstResponder:(NSResponder *)aResponder;
 
 159 @implementation wxNSWindow
 
 161 - (void)sendEvent:(NSEvent *) event
 
 163     if ( ![self WX_filterSendEvent: event] )
 
 165         WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
 
 166         WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
 
 169             wxTheApp->MacSetCurrentEvent(event, NULL);
 
 171         [super sendEvent: event];
 
 174             wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
 
 178 // The default implementation always moves the window back onto the screen,
 
 179 // even when the programmer explicitly wants to hide it.
 
 180 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
 
 186 - (void)doCommandBySelector:(SEL)selector
 
 188     if (shouldHandleSelector(selector) &&
 
 189         !(selector == @selector(cancel:) || selector == @selector(cancelOperation:)) )
 
 190         [super doCommandBySelector:selector];
 
 194 // NB: if we don't do this, all key downs that get handled lead to a NSBeep
 
 195 - (void)noResponderFor: (SEL) selector
 
 197     if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
 
 199         [super noResponderFor:selector];
 
 203 // We need this for borderless windows, i.e. shaped windows or windows without  
 
 204 // a title bar. For more info, see:
 
 205 // http://lists.apple.com/archives/cocoa-dev/2008/May/msg02091.html
 
 206 - (BOOL)canBecomeKeyWindow
 
 211 - (BOOL)makeFirstResponder:(NSResponder *)aResponder
 
 213     s_nextFirstResponder = aResponder;
 
 214     BOOL retval = [super makeFirstResponder:aResponder];
 
 215     s_nextFirstResponder = nil;
 
 221 @interface wxNSPanel : NSPanel
 
 225 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
 
 226 - (void)noResponderFor: (SEL) selector;
 
 227 - (void)sendEvent:(NSEvent *)event;
 
 228 - (BOOL)makeFirstResponder:(NSResponder *)aResponder;
 
 231 @implementation wxNSPanel
 
 233 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
 
 235     wxNonOwnedWindowCocoaImpl* impl = (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
 
 236     if (impl && impl->IsFullScreen())
 
 239         return [super constrainFrameRect:frameRect toScreen:screen];
 
 242 - (BOOL)canBecomeKeyWindow
 
 247 - (void)doCommandBySelector:(SEL)selector
 
 249     if (shouldHandleSelector(selector))
 
 250         [super doCommandBySelector:selector];
 
 253 // NB: if we don't do this, it seems that all events that end here lead to a NSBeep
 
 254 - (void)noResponderFor: (SEL) selector
 
 256     if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
 
 258         [super noResponderFor:selector];
 
 262 - (void)sendEvent:(NSEvent *) event
 
 264     if ( ![self WX_filterSendEvent: event] )
 
 266         WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
 
 267         WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
 
 270             wxTheApp->MacSetCurrentEvent(event, NULL);
 
 272         [super sendEvent: event];
 
 275             wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
 
 279 - (BOOL)makeFirstResponder:(NSResponder *)aResponder
 
 281     s_nextFirstResponder = aResponder;
 
 282     BOOL retval = [super makeFirstResponder:aResponder];
 
 283     s_nextFirstResponder = nil;
 
 294 @interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>)
 
 298 - (void)windowDidResize:(NSNotification *)notification;
 
 299 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
 
 300 - (void)windowDidResignKey:(NSNotification *)notification;
 
 301 - (void)windowDidBecomeKey:(NSNotification *)notification;
 
 302 - (void)windowDidMove:(NSNotification *)notification;
 
 303 - (BOOL)windowShouldClose:(id)window;
 
 304 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
 
 308 extern int wxOSXGetIdFromSelector(SEL action );
 
 310 @implementation wxNonOwnedWindowController
 
 318 - (BOOL) triggerMenu:(SEL) action
 
 320     wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
 
 324         wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
 
 325         if ( menu != NULL && menuitem != NULL)
 
 326             return menu->HandleCommandProcess(menuitem);
 
 331 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem 
 
 333     SEL action = [menuItem action];
 
 335     wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
 
 339         wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
 
 340         if ( menu != NULL && menuitem != NULL)
 
 342             menu->HandleCommandUpdateStatus(menuitem);
 
 343             return menuitem->IsEnabled();
 
 349 - (void)undo:(id)sender 
 
 352     [self triggerMenu:_cmd];
 
 355 - (void)redo:(id)sender 
 
 358     [self triggerMenu:_cmd];
 
 361 - (void)cut:(id)sender 
 
 364     [self triggerMenu:_cmd];
 
 367 - (void)copy:(id)sender
 
 370     [self triggerMenu:_cmd];
 
 373 - (void)paste:(id)sender
 
 376     [self triggerMenu:_cmd];
 
 379 - (void)delete:(id)sender 
 
 382     [self triggerMenu:_cmd];
 
 385 - (void)selectAll:(id)sender 
 
 388     [self triggerMenu:_cmd];
 
 391 - (BOOL)windowShouldClose:(id)nwindow
 
 393     wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation];
 
 396         wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 
 403 - (NSSize)windowWillResize:(NSWindow *)window
 
 404                     toSize:(NSSize)proposedFrameSize
 
 406     NSRect frame = [window frame];
 
 407     wxRect wxframe = wxFromNSRect( NULL, frame );
 
 408     wxframe.SetWidth( (int)proposedFrameSize.width );
 
 409     wxframe.SetHeight( (int)proposedFrameSize.height );
 
 411     wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
 
 414         wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 
 417             wxpeer->HandleResizing( 0, &wxframe );
 
 418             NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight());
 
 423     return proposedFrameSize;
 
 426 - (void)windowDidResize:(NSNotification *)notification
 
 428     NSWindow* window = (NSWindow*) [notification object];
 
 429     wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
 
 432         wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 
 434             wxpeer->HandleResized(0);
 
 438 - (void)windowDidMove:(NSNotification *)notification
 
 440     wxNSWindow* window = (wxNSWindow*) [notification object];
 
 441     wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
 
 444         wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 
 446             wxpeer->HandleMoved(0);
 
 450 - (void)windowDidBecomeKey:(NSNotification *)notification
 
 452     NSWindow* window = (NSWindow*) [notification object];
 
 453     wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
 
 456         wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 
 458             wxpeer->HandleActivated(0, true);
 
 462 - (void)windowDidResignKey:(NSNotification *)notification
 
 464     NSWindow* window = (NSWindow*) [notification object];
 
 465     wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
 
 468         wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 
 471             wxpeer->HandleActivated(0, false);
 
 472             // as for wx the deactivation also means losing focus we
 
 473             // must trigger this manually
 
 474             [window makeFirstResponder:nil];
 
 476             // TODO Remove if no problems arise with Popup Windows
 
 478             // Needed for popup window since the firstResponder
 
 479             // (focus in wx) doesn't change when this
 
 480             // TLW becomes inactive.
 
 481             wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
 
 482             event.SetEventObject(wxpeer);
 
 483             wxpeer->HandleWindowEvent(event);
 
 489 - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
 
 493     if ([anObject isKindOfClass:[wxNSTextField class]])
 
 495         wxNSTextField* tf = (wxNSTextField*) anObject;
 
 496         wxNSTextFieldEditor* editor = [tf fieldEditor];
 
 499             editor = [[wxNSTextFieldEditor alloc] init];
 
 500             [editor setFieldEditor:YES];
 
 501             [tf setFieldEditor:editor];
 
 506     else if ([anObject isKindOfClass:[wxNSComboBox class]])
 
 508         wxNSComboBox * cb = (wxNSComboBox*) anObject;
 
 509         wxNSTextFieldEditor* editor = [cb fieldEditor];
 
 512             editor = [[wxNSTextFieldEditor alloc] init];
 
 513             [editor setFieldEditor:YES];
 
 514             [cb setFieldEditor:editor];
 
 523 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
 
 525     wxUnusedVar(newFrame);
 
 526     wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
 
 529         wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
 
 530         wxMaximizeEvent event(wxpeer->GetId());
 
 531         event.SetEventObject(wxpeer);
 
 532         return !wxpeer->HandleWindowEvent(event);
 
 539 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
 
 541 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
 
 542     wxNonOwnedWindowImpl(nonownedwnd)
 
 545     m_macFullScreenData = NULL;
 
 548 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
 
 551     m_macFullScreenData = NULL;
 
 554 wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
 
 556     if ( !m_wxPeer->IsNativeWindowWrapper() )
 
 558         [m_macWindow setDelegate:nil];
 
 560         // make sure we remove this first, otherwise the ref count will not lead to the 
 
 561         // native window's destruction
 
 562         if ([m_macWindow parentWindow] != 0)
 
 563             [[m_macWindow parentWindow] removeChildWindow: m_macWindow];
 
 565         [m_macWindow release];
 
 569 void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
 
 571     if ( !m_wxPeer->IsNativeWindowWrapper() )
 
 573         [m_macWindow setDelegate:nil];
 
 577 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
 
 578 long style, long extraStyle, const wxString& WXUNUSED(name) )
 
 580     static wxNonOwnedWindowController* controller = NULL;
 
 583         controller =[[wxNonOwnedWindowController alloc] init];
 
 586     int windowstyle = NSBorderlessWindowMask;
 
 588     if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) ||
 
 589             GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
 
 590         m_macWindow = [wxNSPanel alloc];
 
 592         m_macWindow = [wxNSWindow alloc];
 
 594     [m_macWindow setAcceptsMouseMovedEvents:YES];
 
 596     CGWindowLevel level = kCGNormalWindowLevel;
 
 598     if ( style & wxFRAME_TOOL_WINDOW )
 
 600         windowstyle |= NSUtilityWindowMask;
 
 602     else if ( ( style & wxPOPUP_WINDOW ) )
 
 604         level = kCGPopUpMenuWindowLevel;
 
 606     else if ( ( style & wxFRAME_DRAWER ) )
 
 609         wclass = kDrawerWindowClass;
 
 613     if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
 
 614         ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) || ( style & wxCAPTION ) )
 
 616         windowstyle |= NSTitledWindowMask ;
 
 617         if ( ( style & wxMINIMIZE_BOX ) )
 
 618             windowstyle |= NSMiniaturizableWindowMask ;
 
 620         if ( ( style & wxMAXIMIZE_BOX ) )
 
 621             windowstyle |= NSResizableWindowMask ;
 
 623         if ( ( style & wxCLOSE_BOX) )
 
 624             windowstyle |= NSClosableWindowMask ;
 
 627     if ( ( style & wxRESIZE_BORDER ) )
 
 628         windowstyle |= NSResizableWindowMask ;
 
 630     if ( extraStyle & wxFRAME_EX_METAL)
 
 631         windowstyle |= NSTexturedBackgroundWindowMask;
 
 633     if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) )
 
 634         level = kCGFloatingWindowLevel;
 
 636     if ( ( style & wxSTAY_ON_TOP ) )
 
 637         level = kCGUtilityWindowLevel;
 
 639     NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
 
 641     r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle];
 
 643     [m_macWindow initWithContentRect:r
 
 644         styleMask:windowstyle
 
 645         backing:NSBackingStoreBuffered
 
 649     // if we just have a title bar with no buttons needed, hide them
 
 650     if ( (windowstyle & NSTitledWindowMask) && 
 
 651         !(style & wxCLOSE_BOX) && !(style & wxMAXIMIZE_BOX) && !(style & wxMINIMIZE_BOX) )
 
 653         [[m_macWindow standardWindowButton:NSWindowZoomButton] setHidden:YES];
 
 654         [[m_macWindow standardWindowButton:NSWindowCloseButton] setHidden:YES];
 
 655         [[m_macWindow standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
 
 658     // If the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
 
 659     // to be in kCGUtilityWindowLevel and not kCGFloatingWindowLevel to stay
 
 661     wxDialog * const parentDialog = parent == NULL ? NULL : wxDynamicCast(parent->MacGetTopLevelWindow(), wxDialog);
 
 662     if (parentDialog && parentDialog->IsModal())
 
 664         if (level == kCGFloatingWindowLevel)
 
 666             level = kCGUtilityWindowLevel;
 
 669         // Cocoa's modal loop does not process other windows by default, but
 
 670         // don't call this on normal window levels so nested modal dialogs will
 
 671         // still behave modally.
 
 672         if (level != kCGNormalWindowLevel)
 
 674             if ([m_macWindow isKindOfClass:[NSPanel class]])
 
 676                 [(NSPanel*)m_macWindow setWorksWhenModal:YES];
 
 681     [m_macWindow setLevel:level];
 
 682     m_macWindowLevel = level;
 
 684     [m_macWindow setDelegate:controller];
 
 686     if ( ( style & wxFRAME_SHAPED) )
 
 688         [m_macWindow setOpaque:NO];
 
 689         [m_macWindow setAlphaValue:1.0];
 
 692     if ( !(style & wxFRAME_TOOL_WINDOW) )
 
 693         [m_macWindow setHidesOnDeactivate:NO];
 
 696 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
 
 698     m_macWindow = nativeWindow;
 
 701 WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
 
 706 void wxNonOwnedWindowCocoaImpl::Raise()
 
 708     [m_macWindow makeKeyAndOrderFront:nil];
 
 711 void wxNonOwnedWindowCocoaImpl::Lower()
 
 713     [m_macWindow orderWindow:NSWindowBelow relativeTo:0];
 
 716 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
 
 718     [m_macWindow orderFront:nil];
 
 719     [[m_macWindow contentView] setNeedsDisplay: YES];
 
 722 bool wxNonOwnedWindowCocoaImpl::Show(bool show)
 
 726         wxNonOwnedWindow* wxpeer = GetWXPeer(); 
 
 729             // add to parent window before showing
 
 730             wxDialog * const dialog = wxDynamicCast(wxpeer, wxDialog);
 
 731             if ( wxpeer->GetParent() && dialog && dialog->IsModal())
 
 733                 NSView * parentView = wxpeer->GetParent()->GetPeer()->GetWXWidget();
 
 736                     NSWindow* parentNSWindow = [parentView window];
 
 737                     if ( parentNSWindow )
 
 738                         [parentNSWindow addChildWindow:m_macWindow ordered:NSWindowAbove];
 
 742             if (!(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW)) 
 
 743                 [m_macWindow makeKeyAndOrderFront:nil];
 
 745                 [m_macWindow orderFront:nil]; 
 
 747         [[m_macWindow contentView] setNeedsDisplay: YES];
 
 751         // avoid propagation of orderOut to parent 
 
 752         if ([m_macWindow parentWindow] != 0)
 
 753             [[m_macWindow parentWindow] removeChildWindow: m_macWindow];
 
 754         [m_macWindow orderOut:nil];
 
 759 bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show,
 
 763     return wxWidgetCocoaImpl::
 
 764             ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout);
 
 767 void wxNonOwnedWindowCocoaImpl::Update()
 
 769     [m_macWindow displayIfNeeded];
 
 772 bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
 
 774     [m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
 
 778 bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& col )
 
 780     [m_macWindow setBackgroundColor:[NSColor colorWithCalibratedRed:(CGFloat) (col.Red() / 255.0)
 
 781                                                              green:(CGFloat) (col.Green() / 255.0)
 
 782                                                               blue:(CGFloat) (col.Blue() / 255.0)
 
 783                                                              alpha:(CGFloat) (col.Alpha() / 255.0)]];
 
 787 void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle )
 
 791         bool metal = exStyle & wxFRAME_EX_METAL ;
 
 792         int windowStyle = [ m_macWindow styleMask];
 
 793         if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) )
 
 795             wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
 
 797         else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) )
 
 799             wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
 
 804 void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style )
 
 806     // don't mess with native wrapped windows, they might throw an exception when their level is changed
 
 807     if (!m_wxPeer->IsNativeWindowWrapper() && m_macWindow)
 
 809         CGWindowLevel level = kCGNormalWindowLevel;
 
 811         if (style & wxSTAY_ON_TOP)
 
 812             level = kCGUtilityWindowLevel;
 
 813         else if (( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ))
 
 814             level = kCGFloatingWindowLevel;
 
 816         [m_macWindow setLevel: level];
 
 817         m_macWindowLevel = level;
 
 821 bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
 
 823     if ( style == wxBG_STYLE_TRANSPARENT )
 
 825         [m_macWindow setOpaque:NO];
 
 826         [m_macWindow setBackgroundColor:[NSColor clearColor]];
 
 832 bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
 
 837 void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
 
 839     NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
 
 840     // do not trigger refreshes upon invisible and possible partly created objects
 
 841     [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()];
 
 844 void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
 
 846     wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
 
 851 void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
 
 853     NSRect rect = [m_macWindow frame];
 
 854     width = (int)rect.size.width;
 
 855     height = (int)rect.size.height;
 
 858 void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
 
 860     NSRect rect = [[m_macWindow contentView] frame];
 
 861     left = (int)rect.origin.x;
 
 862     top = (int)rect.origin.y;
 
 863     width = (int)rect.size.width;
 
 864     height = (int)rect.size.height;
 
 867 bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
 
 869     [m_macWindow setOpaque:NO];
 
 870     [m_macWindow setBackgroundColor:[NSColor clearColor]];
 
 875 void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
 
 877     [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
 
 880 bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
 
 882     if (([m_macWindow styleMask] & NSResizableWindowMask) != 0)
 
 884         return [m_macWindow isZoomed];
 
 888         NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
 
 889         NSRect rectWindow = [m_macWindow frame];
 
 890         return (rectScreen.origin.x == rectWindow.origin.x &&
 
 891                 rectScreen.origin.y == rectWindow.origin.y &&
 
 892                 rectScreen.size.width == rectWindow.size.width &&
 
 893                 rectScreen.size.height == rectWindow.size.height);
 
 897 bool wxNonOwnedWindowCocoaImpl::IsIconized() const
 
 899     return [m_macWindow isMiniaturized];
 
 902 void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
 
 905         [m_macWindow miniaturize:nil];
 
 907         [m_macWindow deminiaturize:nil];
 
 910 void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize))
 
 912     [m_macWindow zoom:nil];
 
 916 // http://cocoadevcentral.com/articles/000028.php
 
 920     NSUInteger m_formerStyleMask;
 
 922     NSRect m_formerFrame;
 
 925 bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
 
 927     return m_macFullScreenData != NULL ;
 
 930 bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
 
 934         FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
 
 936         data = new FullScreenData();
 
 938         m_macFullScreenData = data ;
 
 939         data->m_formerLevel = [m_macWindow level];
 
 940         data->m_formerFrame = [m_macWindow frame];
 
 941         data->m_formerStyleMask = [m_macWindow styleMask];
 
 943         // CGDisplayCapture( kCGDirectMainDisplay );
 
 944         //[m_macWindow setLevel:NSMainMenuWindowLevel+1/*CGShieldingWindowLevel()*/];
 
 946         NSRect screenframe = [[NSScreen mainScreen] frame];
 
 947         NSRect frame = NSMakeRect (0, 0, 100, 100);
 
 950 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
 
 951         if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
 
 952             [m_macWindow setStyleMask:data->m_formerStyleMask & ~ NSResizableWindowMask];
 
 955         contentRect = [NSWindow contentRectForFrameRect: frame
 
 956                                 styleMask: [m_macWindow styleMask]];
 
 957         screenframe.origin.y += (frame.origin.y - contentRect.origin.y);
 
 958         screenframe.size.height += (frame.size.height - contentRect.size.height);
 
 959         [m_macWindow setFrame:screenframe display:YES];
 
 961         SetSystemUIMode(kUIModeAllHidden,
 
 962                                 kUIOptionDisableAppleMenu
 
 964                                 | kUIOptionDisableProcessSwitch
 
 965                                 | kUIOptionDisableForceQuit
 
 968     else if ( m_macFullScreenData != NULL )
 
 970         FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
 
 972         // CGDisplayRelease( kCGDirectMainDisplay );
 
 973         // [m_macWindow setLevel:data->m_formerLevel];
 
 976         [m_macWindow setFrame:data->m_formerFrame display:YES];
 
 977 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
 
 978         if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
 
 979             [m_macWindow setStyleMask:data->m_formerStyleMask];
 
 982         m_macFullScreenData = NULL ;
 
 984         SetSystemUIMode(kUIModeNormal, 0); 
 
 990 void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX)
 
 992     NSRequestUserAttentionType flagsOSX;
 
 995         case wxUSER_ATTENTION_INFO:
 
 996             flagsOSX = NSInformationalRequest;
 
 999         case wxUSER_ATTENTION_ERROR:
 
1000             flagsOSX = NSCriticalRequest;
 
1004             wxFAIL_MSG( "invalid RequestUserAttention() flags" );
 
1008     [NSApp requestUserAttention:flagsOSX];
 
1011 void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
 
1013     wxPoint p((x ? *x : 0), (y ? *y : 0) );
 
1014     NSPoint nspt = wxToNSPoint( NULL, p );
 
1015     nspt = [m_macWindow convertScreenToBase:nspt];
 
1016     nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil];
 
1017     p = wxFromNSPoint([m_macWindow contentView], nspt);
 
1024 void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
 
1026     wxPoint p((x ? *x : 0), (y ? *y : 0) );
 
1027     NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p );
 
1028     nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil];
 
1029     nspt = [m_macWindow convertBaseToScreen:nspt];
 
1030     p = wxFromNSPoint( NULL, nspt);
 
1037 bool wxNonOwnedWindowCocoaImpl::IsActive()
 
1039     return [m_macWindow isKeyWindow];
 
1042 void wxNonOwnedWindowCocoaImpl::SetModified(bool modified)
 
1044     [m_macWindow setDocumentEdited:modified];
 
1047 bool wxNonOwnedWindowCocoaImpl::IsModified() const
 
1049     return [m_macWindow isDocumentEdited];
 
1052 void wxNonOwnedWindowCocoaImpl::SetRepresentedFilename(const wxString& filename)
 
1054     [m_macWindow setRepresentedFilename:wxCFStringRef(filename).AsNSString()];
 
1057 void wxNonOwnedWindowCocoaImpl::RestoreWindowLevel()
 
1059     if ( [m_macWindow level] != m_macWindowLevel )
 
1060         [m_macWindow setLevel:m_macWindowLevel];
 
1063 WX_NSResponder wxNonOwnedWindowCocoaImpl::GetNextFirstResponder()
 
1065     return s_nextFirstResponder;
 
1073 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
 
1075     wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
 
1076     now->Create( parent, nativeWindow );
 
1080 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
 
1081     long style, long extraStyle, const wxString& name )
 
1083     wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
 
1084     now->Create( parent, pos, size, style , extraStyle, name );