1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/nonownedwnd.mm
3 // Purpose: non owned window for cocoa
4 // Author: DavidStefan Csomor
7 // RCS-ID: $Id: nonownedwnd.mm 48805 2007-09-19 14:52:25Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/nonownedwnd.h"
17 #include "wx/dialog.h"
20 #include "wx/osx/private.h"
22 NSScreen* wxOSXGetMenuScreen()
24 if ( [NSScreen screens] == nil )
25 return [NSScreen mainScreen];
28 return [[NSScreen screens] objectAtIndex:0];
32 NSRect wxToNSRect( NSView* parent, const wxRect& r )
34 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
37 if ( parent == NULL || ![ parent isFlipped ] )
38 y = (int)(frame.size.height - ( r.y + r.height ));
39 return NSMakeRect(x, y, r.width , r.height);
42 wxRect wxFromNSRect( NSView* parent, const NSRect& rect )
44 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
45 int y = (int)rect.origin.y;
46 int x = (int)rect.origin.x;
47 if ( parent == NULL || ![ parent isFlipped ] )
48 y = (int)(frame.size.height - (rect.origin.y + rect.size.height));
49 return wxRect( x, y, (int)rect.size.width, (int)rect.size.height );
52 NSPoint wxToNSPoint( NSView* parent, const wxPoint& p )
54 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
57 if ( parent == NULL || ![ parent isFlipped ] )
58 y = (int)(frame.size.height - ( p.y ));
59 return NSMakePoint(x, y);
62 wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
64 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
67 if ( parent == NULL || ![ parent isFlipped ] )
68 y = (int)(frame.size.height - ( p.y ));
69 return wxPoint( x, y);
72 bool shouldHandleSelector(SEL selector)
74 if (selector == @selector(noop:)
75 || selector == @selector(complete:)
76 || selector == @selector(deleteBackward:)
77 || selector == @selector(deleteForward:)
78 || selector == @selector(insertNewline:)
79 || selector == @selector(insertTab:)
80 || selector == @selector(keyDown:)
81 || selector == @selector(keyUp:)
82 || selector == @selector(scrollPageUp:)
83 || selector == @selector(scrollPageDown:)
84 || selector == @selector(scrollToBeginningOfDocument:)
85 || selector == @selector(scrollToEndOfDocument:))
93 // wx category for NSWindow (our own and wrapped instances)
96 @interface NSWindow (wxNSWindowSupport)
98 - (wxNonOwnedWindowCocoaImpl*) WX_implementation;
100 - (bool) WX_filterSendEvent:(NSEvent *) event;
104 @implementation NSWindow (wxNSWindowSupport)
106 - (wxNonOwnedWindowCocoaImpl*) WX_implementation
108 return (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
111 // TODO in cocoa everything during a drag is sent to the NSWindow the mouse down occured,
112 // this does not conform to the wx behaviour if the window is not captured, so try to resend
113 // or capture all wx mouse event handling at the tlw as we did for carbon
115 - (bool) WX_filterSendEvent:(NSEvent *) event
117 bool handled = false;
118 if ( ([event type] >= NSLeftMouseDown) && ([event type] <= NSMouseExited) )
120 wxWindow* cw = wxWindow::GetCapture();
123 ((wxWidgetCocoaImpl*)cw->GetPeer())->DoHandleMouseEvent( event);
132 // wx native implementation
135 @interface wxNSWindow : NSWindow
139 - (void) sendEvent:(NSEvent *)event;
140 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
141 - (void)noResponderFor: (SEL) selector;
144 @implementation wxNSWindow
146 - (void)sendEvent:(NSEvent *) event
148 if ( ![self WX_filterSendEvent: event] )
150 WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
151 WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
154 wxTheApp->MacSetCurrentEvent(event, NULL);
156 [super sendEvent: event];
159 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
163 // The default implementation always moves the window back onto the screen,
164 // even when the programmer explicitly wants to hide it.
165 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
171 - (void)doCommandBySelector:(SEL)selector
173 if (shouldHandleSelector(selector) &&
174 !(selector == @selector(cancel:) || selector == @selector(cancelOperation:)) )
175 [super doCommandBySelector:selector];
179 // NB: if we don't do this, all key downs that get handled lead to a NSBeep
180 - (void)noResponderFor: (SEL) selector
182 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
184 [super noResponderFor:selector];
188 // We need this for borderless windows, i.e. shaped windows or windows without
189 // a title bar. For more info, see:
190 // http://lists.apple.com/archives/cocoa-dev/2008/May/msg02091.html
191 - (BOOL)canBecomeKeyWindow
198 @interface wxNSPanel : NSPanel
202 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
203 - (void)noResponderFor: (SEL) selector;
204 - (void)sendEvent:(NSEvent *)event;
207 @implementation wxNSPanel
209 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
211 wxNonOwnedWindowCocoaImpl* impl = (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
212 if (impl && impl->IsFullScreen())
215 return [super constrainFrameRect:frameRect toScreen:screen];
218 - (BOOL)canBecomeKeyWindow
223 - (void)doCommandBySelector:(SEL)selector
225 if (shouldHandleSelector(selector))
226 [super doCommandBySelector:selector];
229 // NB: if we don't do this, it seems that all events that end here lead to a NSBeep
230 - (void)noResponderFor: (SEL) selector
232 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
234 [super noResponderFor:selector];
238 - (void)sendEvent:(NSEvent *) event
240 if ( ![self WX_filterSendEvent: event] )
241 [super sendEvent: event];
251 @interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>)
255 - (void)windowDidResize:(NSNotification *)notification;
256 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
257 - (void)windowDidResignKey:(NSNotification *)notification;
258 - (void)windowDidBecomeKey:(NSNotification *)notification;
259 - (void)windowDidMove:(NSNotification *)notification;
260 - (BOOL)windowShouldClose:(id)window;
261 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
265 @implementation wxNonOwnedWindowController
273 - (BOOL)windowShouldClose:(id)nwindow
275 wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation];
278 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
285 - (NSSize)windowWillResize:(NSWindow *)window
286 toSize:(NSSize)proposedFrameSize
288 NSRect frame = [window frame];
289 wxRect wxframe = wxFromNSRect( NULL, frame );
290 wxframe.SetWidth( (int)proposedFrameSize.width );
291 wxframe.SetHeight( (int)proposedFrameSize.height );
293 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
296 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
299 wxpeer->HandleResizing( 0, &wxframe );
300 NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight());
305 return proposedFrameSize;
308 - (void)windowDidResize:(NSNotification *)notification
310 NSWindow* window = (NSWindow*) [notification object];
311 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
314 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
316 wxpeer->HandleResized(0);
320 - (void)windowDidMove:(NSNotification *)notification
322 wxNSWindow* window = (wxNSWindow*) [notification object];
323 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
326 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
328 wxpeer->HandleMoved(0);
332 - (void)windowDidBecomeKey:(NSNotification *)notification
334 NSWindow* window = (NSWindow*) [notification object];
335 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
338 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
340 wxpeer->HandleActivated(0, true);
344 - (void)windowDidResignKey:(NSNotification *)notification
346 NSWindow* window = (NSWindow*) [notification object];
347 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
350 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
353 wxpeer->HandleActivated(0, false);
354 // Needed for popup window since the firstResponder
355 // (focus in wx) doesn't change when this
356 // TLW becomes inactive.
357 wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
358 event.SetEventObject(wxpeer);
359 wxpeer->HandleWindowEvent(event);
364 - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
368 if ([anObject isKindOfClass:[wxNSTextField class]])
370 wxNSTextField* tf = (wxNSTextField*) anObject;
371 wxNSTextFieldEditor* editor = [tf fieldEditor];
374 editor = [[wxNSTextFieldEditor alloc] init];
375 [editor setFieldEditor:YES];
376 [tf setFieldEditor:editor];
384 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
386 wxUnusedVar(newFrame);
387 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
390 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
391 wxMaximizeEvent event(wxpeer->GetId());
392 event.SetEventObject(wxpeer);
393 return !wxpeer->HandleWindowEvent(event);
400 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
402 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
403 wxNonOwnedWindowImpl(nonownedwnd)
406 m_macFullScreenData = NULL;
409 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
412 m_macFullScreenData = NULL;
415 wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
417 if ( !m_wxPeer->IsNativeWindowWrapper() )
419 [m_macWindow setDelegate:nil];
420 [m_macWindow release];
424 void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
426 if ( !m_wxPeer->IsNativeWindowWrapper() )
428 [m_macWindow setDelegate:nil];
432 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
433 long style, long extraStyle, const wxString& WXUNUSED(name) )
435 static wxNonOwnedWindowController* controller = NULL;
438 controller =[[wxNonOwnedWindowController alloc] init];
441 int windowstyle = NSBorderlessWindowMask;
443 if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) ||
444 GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
446 m_macWindow = [wxNSPanel alloc];
449 m_macWindow = [wxNSWindow alloc];
451 CGWindowLevel level = kCGNormalWindowLevel;
453 if ( style & wxFRAME_TOOL_WINDOW )
455 windowstyle |= NSUtilityWindowMask;
456 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
457 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
459 windowstyle |= NSTitledWindowMask ;
462 else if ( ( style & wxPOPUP_WINDOW ) )
464 level = kCGPopUpMenuWindowLevel;
466 if ( ( style & wxBORDER_NONE ) )
468 wclass = kHelpWindowClass ; // has no border
469 attr |= kWindowNoShadowAttribute;
473 wclass = kPlainWindowClass ; // has a single line border, it will have to do for now
477 else if ( ( style & wxCAPTION ) )
479 windowstyle |= NSTitledWindowMask ;
481 else if ( ( style & wxFRAME_DRAWER ) )
484 wclass = kDrawerWindowClass;
489 // set these even if we have no title, otherwise the controls won't be visible
490 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
491 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
493 windowstyle |= NSTitledWindowMask ;
496 else if ( ( style & wxNO_BORDER ) )
498 wclass = kSimpleWindowClass ;
502 wclass = kPlainWindowClass ;
507 if ( windowstyle & NSTitledWindowMask )
509 if ( ( style & wxMINIMIZE_BOX ) )
510 windowstyle |= NSMiniaturizableWindowMask ;
512 if ( ( style & wxMAXIMIZE_BOX ) )
513 windowstyle |= NSResizableWindowMask ; // TODO showing ZOOM ?
515 if ( ( style & wxRESIZE_BORDER ) )
516 windowstyle |= NSResizableWindowMask ;
518 if ( ( style & wxCLOSE_BOX) )
519 windowstyle |= NSClosableWindowMask ;
521 if ( extraStyle & wxFRAME_EX_METAL)
522 windowstyle |= NSTexturedBackgroundWindowMask;
524 if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) )
525 level = kCGFloatingWindowLevel;
527 if ( ( style & wxSTAY_ON_TOP ) )
528 level = kCGUtilityWindowLevel;
530 NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
532 r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle];
534 [m_macWindow initWithContentRect:r
535 styleMask:windowstyle
536 backing:NSBackingStoreBuffered
540 // If the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
541 // to be in kCGUtilityWindowLevel and not kCGFloatingWindowLevel to stay
543 wxDialog * const parentDialog = wxDynamicCast(parent, wxDialog);
544 if (parentDialog && parentDialog->IsModal())
546 if (level == kCGFloatingWindowLevel)
548 level = kCGUtilityWindowLevel;
551 // Cocoa's modal loop does not process other windows by default, but
552 // don't call this on normal window levels so nested modal dialogs will
553 // still behave modally.
554 if (level != kCGNormalWindowLevel)
556 if ([m_macWindow isKindOfClass:[NSPanel class]])
558 [(NSPanel*)m_macWindow setWorksWhenModal:YES];
563 [m_macWindow setLevel:level];
565 [m_macWindow setDelegate:controller];
567 [m_macWindow setAcceptsMouseMovedEvents: YES];
569 if ( ( style & wxFRAME_SHAPED) )
571 [m_macWindow setOpaque:NO];
572 [m_macWindow setAlphaValue:1.0];
575 if ( !(style & wxFRAME_TOOL_WINDOW) )
576 [m_macWindow setHidesOnDeactivate:NO];
579 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
581 m_macWindow = nativeWindow;
584 WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
589 void wxNonOwnedWindowCocoaImpl::Raise()
591 [m_macWindow orderWindow:NSWindowAbove relativeTo:0];
594 void wxNonOwnedWindowCocoaImpl::Lower()
596 [m_macWindow orderWindow:NSWindowBelow relativeTo:0];
599 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
601 [m_macWindow orderFront:nil];
602 [[m_macWindow contentView] setNeedsDisplay: YES];
605 bool wxNonOwnedWindowCocoaImpl::Show(bool show)
609 wxNonOwnedWindow* wxpeer = GetWXPeer();
610 if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
611 [m_macWindow makeKeyAndOrderFront:nil];
613 [m_macWindow orderFront:nil];
614 [[m_macWindow contentView] setNeedsDisplay: YES];
617 [m_macWindow orderOut:nil];
621 bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show,
625 return wxWidgetCocoaImpl::
626 ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout);
629 void wxNonOwnedWindowCocoaImpl::Update()
631 [m_macWindow displayIfNeeded];
634 bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
636 [m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
640 bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& WXUNUSED(col) )
645 void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle )
649 bool metal = exStyle & wxFRAME_EX_METAL ;
650 int windowStyle = [ m_macWindow styleMask];
651 if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) )
653 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
655 else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) )
657 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
662 void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style )
666 CGWindowLevel level = kCGNormalWindowLevel;
668 if (style & wxSTAY_ON_TOP)
669 level = kCGUtilityWindowLevel;
670 else if (( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ))
671 level = kCGFloatingWindowLevel;
673 [m_macWindow setLevel: level];
677 bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
679 if ( style == wxBG_STYLE_TRANSPARENT )
681 [m_macWindow setOpaque:NO];
682 [m_macWindow setBackgroundColor:[NSColor clearColor]];
688 bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
693 void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
695 NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
696 // do not trigger refreshes upon invisible and possible partly created objects
697 [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()];
700 void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
702 wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
707 void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
709 NSRect rect = [m_macWindow frame];
710 width = (int)rect.size.width;
711 height = (int)rect.size.height;
714 void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
716 NSRect outer = NSMakeRect(100,100,100,100);
717 NSRect content = [NSWindow contentRectForFrameRect:outer styleMask:[m_macWindow styleMask] ];
718 NSRect rect = [[m_macWindow contentView] frame];
719 left = (int)rect.origin.x;
720 top = (int)rect.origin.y;
721 width = (int)rect.size.width;
722 height = (int)rect.size.height;
725 bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
727 [m_macWindow setOpaque:NO];
728 [m_macWindow setBackgroundColor:[NSColor clearColor]];
733 void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
735 [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
738 bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
740 if (([m_macWindow styleMask] & NSResizableWindowMask) != 0)
742 return [m_macWindow isZoomed];
746 NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
747 NSRect rectWindow = [m_macWindow frame];
748 return (rectScreen.origin.x == rectWindow.origin.x &&
749 rectScreen.origin.y == rectWindow.origin.y &&
750 rectScreen.size.width == rectWindow.size.width &&
751 rectScreen.size.height == rectWindow.size.height);
755 bool wxNonOwnedWindowCocoaImpl::IsIconized() const
757 return [m_macWindow isMiniaturized];
760 void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
763 [m_macWindow miniaturize:nil];
765 [m_macWindow deminiaturize:nil];
768 void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize))
770 [m_macWindow zoom:nil];
774 // http://cocoadevcentral.com/articles/000028.php
779 NSRect m_formerFrame;
782 bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
784 return m_macFullScreenData != NULL ;
787 bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
791 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
793 data = new FullScreenData();
795 m_macFullScreenData = data ;
796 data->m_formerLevel = [m_macWindow level];
797 data->m_formerFrame = [m_macWindow frame];
798 CGDisplayCapture( kCGDirectMainDisplay );
799 [m_macWindow setLevel:CGShieldingWindowLevel()];
800 NSRect screenframe = [[NSScreen mainScreen] frame];
801 NSRect frame = NSMakeRect (0, 0, 100, 100);
803 contentRect = [NSWindow contentRectForFrameRect: frame
804 styleMask: NSTitledWindowMask];
805 screenframe.origin.y += (frame.origin.y - contentRect.origin.y);
806 screenframe.size.height += (frame.size.height - contentRect.size.height);
807 [m_macWindow setFrame:screenframe display:YES];
809 else if ( m_macFullScreenData != NULL )
811 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
812 CGDisplayRelease( kCGDirectMainDisplay );
813 [m_macWindow setLevel:data->m_formerLevel];
814 [m_macWindow setFrame:data->m_formerFrame display:YES];
816 m_macFullScreenData = NULL ;
822 void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX)
824 NSRequestUserAttentionType flagsOSX;
827 case wxUSER_ATTENTION_INFO:
828 flagsOSX = NSInformationalRequest;
831 case wxUSER_ATTENTION_ERROR:
832 flagsOSX = NSCriticalRequest;
836 wxFAIL_MSG( "invalid RequestUserAttention() flags" );
840 [NSApp requestUserAttention:flagsOSX];
843 void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
845 wxPoint p((x ? *x : 0), (y ? *y : 0) );
846 NSPoint nspt = wxToNSPoint( NULL, p );
847 nspt = [m_macWindow convertScreenToBase:nspt];
848 nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil];
849 p = wxFromNSPoint([m_macWindow contentView], nspt);
856 void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
858 wxPoint p((x ? *x : 0), (y ? *y : 0) );
859 NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p );
860 nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil];
861 nspt = [m_macWindow convertBaseToScreen:nspt];
862 p = wxFromNSPoint( NULL, nspt);
869 bool wxNonOwnedWindowCocoaImpl::IsActive()
871 return [m_macWindow isKeyWindow];
874 void wxNonOwnedWindowCocoaImpl::SetModified(bool modified)
876 [m_macWindow setDocumentEdited:modified];
879 bool wxNonOwnedWindowCocoaImpl::IsModified() const
881 return [m_macWindow isDocumentEdited];
884 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
886 wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
887 now->Create( parent, nativeWindow );
891 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
892 long style, long extraStyle, const wxString& name )
894 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
895 now->Create( parent, pos, size, style , extraStyle, name );