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"
18 #include "wx/menuitem.h"
22 #include "wx/osx/private.h"
24 NSScreen* wxOSXGetMenuScreen()
26 if ( [NSScreen screens] == nil )
27 return [NSScreen mainScreen];
30 return [[NSScreen screens] objectAtIndex:0];
34 NSRect wxToNSRect( NSView* parent, const wxRect& r )
36 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
39 if ( parent == NULL || ![ parent isFlipped ] )
40 y = (int)(frame.size.height - ( r.y + r.height ));
41 return NSMakeRect(x, y, r.width , r.height);
44 wxRect wxFromNSRect( NSView* parent, const NSRect& rect )
46 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
47 int y = (int)rect.origin.y;
48 int x = (int)rect.origin.x;
49 if ( parent == NULL || ![ parent isFlipped ] )
50 y = (int)(frame.size.height - (rect.origin.y + rect.size.height));
51 return wxRect( x, y, (int)rect.size.width, (int)rect.size.height );
54 NSPoint wxToNSPoint( NSView* parent, const wxPoint& p )
56 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
59 if ( parent == NULL || ![ parent isFlipped ] )
60 y = (int)(frame.size.height - ( p.y ));
61 return NSMakePoint(x, y);
64 wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
66 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
69 if ( parent == NULL || ![ parent isFlipped ] )
70 y = (int)(frame.size.height - ( p.y ));
71 return wxPoint( x, y);
74 bool shouldHandleSelector(SEL selector)
76 if (selector == @selector(noop:)
77 || selector == @selector(complete:)
78 || selector == @selector(deleteBackward:)
79 || selector == @selector(deleteForward:)
80 || selector == @selector(insertNewline:)
81 || selector == @selector(insertTab:)
82 || selector == @selector(insertBacktab:)
83 || selector == @selector(keyDown:)
84 || selector == @selector(keyUp:)
85 || selector == @selector(scrollPageUp:)
86 || selector == @selector(scrollPageDown:)
87 || selector == @selector(scrollToBeginningOfDocument:)
88 || selector == @selector(scrollToEndOfDocument:))
96 // wx category for NSWindow (our own and wrapped instances)
99 @interface NSWindow (wxNSWindowSupport)
101 - (wxNonOwnedWindowCocoaImpl*) WX_implementation;
103 - (bool) WX_filterSendEvent:(NSEvent *) event;
107 @implementation NSWindow (wxNSWindowSupport)
109 - (wxNonOwnedWindowCocoaImpl*) WX_implementation
111 return (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
114 // TODO in cocoa everything during a drag is sent to the NSWindow the mouse down occured,
115 // this does not conform to the wx behaviour if the window is not captured, so try to resend
116 // or capture all wx mouse event handling at the tlw as we did for carbon
118 - (bool) WX_filterSendEvent:(NSEvent *) event
120 bool handled = false;
121 if ( ([event type] >= NSLeftMouseDown) && ([event type] <= NSMouseExited) )
123 wxWindow* cw = wxWindow::GetCapture();
126 ((wxWidgetCocoaImpl*)cw->GetPeer())->DoHandleMouseEvent( event);
135 // wx native implementation
138 @interface wxNSWindow : NSWindow
142 - (void) sendEvent:(NSEvent *)event;
143 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
144 - (void)noResponderFor: (SEL) selector;
147 @implementation wxNSWindow
149 - (void)sendEvent:(NSEvent *) event
151 if ( ![self WX_filterSendEvent: event] )
153 WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
154 WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
157 wxTheApp->MacSetCurrentEvent(event, NULL);
159 [super sendEvent: event];
162 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
166 // The default implementation always moves the window back onto the screen,
167 // even when the programmer explicitly wants to hide it.
168 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
174 - (void)doCommandBySelector:(SEL)selector
176 if (shouldHandleSelector(selector) &&
177 !(selector == @selector(cancel:) || selector == @selector(cancelOperation:)) )
178 [super doCommandBySelector:selector];
182 // NB: if we don't do this, all key downs that get handled lead to a NSBeep
183 - (void)noResponderFor: (SEL) selector
185 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
187 [super noResponderFor:selector];
191 // We need this for borderless windows, i.e. shaped windows or windows without
192 // a title bar. For more info, see:
193 // http://lists.apple.com/archives/cocoa-dev/2008/May/msg02091.html
194 - (BOOL)canBecomeKeyWindow
201 @interface wxNSPanel : NSPanel
205 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
206 - (void)noResponderFor: (SEL) selector;
207 - (void)sendEvent:(NSEvent *)event;
210 @implementation wxNSPanel
212 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
214 wxNonOwnedWindowCocoaImpl* impl = (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
215 if (impl && impl->IsFullScreen())
218 return [super constrainFrameRect:frameRect toScreen:screen];
221 - (BOOL)canBecomeKeyWindow
226 - (void)doCommandBySelector:(SEL)selector
228 if (shouldHandleSelector(selector))
229 [super doCommandBySelector:selector];
232 // NB: if we don't do this, it seems that all events that end here lead to a NSBeep
233 - (void)noResponderFor: (SEL) selector
235 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
237 [super noResponderFor:selector];
241 - (void)sendEvent:(NSEvent *) event
243 if ( ![self WX_filterSendEvent: event] )
244 [super sendEvent: event];
254 @interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>)
258 - (void)windowDidResize:(NSNotification *)notification;
259 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
260 - (void)windowDidResignKey:(NSNotification *)notification;
261 - (void)windowDidBecomeKey:(NSNotification *)notification;
262 - (void)windowDidMove:(NSNotification *)notification;
263 - (BOOL)windowShouldClose:(id)window;
264 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
268 extern int wxOSXGetIdFromSelector(SEL action );
270 @implementation wxNonOwnedWindowController
278 - (BOOL) triggerMenu:(SEL) action
280 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
284 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
285 if ( menu != NULL && menuitem != NULL)
286 return menu->HandleCommandProcess(menuitem);
291 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
293 SEL action = [menuItem action];
295 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
299 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
300 if ( menu != NULL && menuitem != NULL)
302 if ( menu->HandleCommandUpdateStatus(menuitem) )
303 return menuitem->IsEnabled();
309 - (void)undo:(id)sender
311 [self triggerMenu:_cmd];
314 - (void)redo:(id)sender
316 [self triggerMenu:_cmd];
319 - (void)cut:(id)sender
321 [self triggerMenu:_cmd];
324 - (void)copy:(id)sender
326 [self triggerMenu:_cmd];
329 - (void)paste:(id)sender
331 [self triggerMenu:_cmd];
334 - (void)delete:(id)sender
336 [self triggerMenu:_cmd];
339 - (void)selectAll:(id)sender
341 [self triggerMenu:_cmd];
344 - (BOOL)windowShouldClose:(id)nwindow
346 wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation];
349 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
356 - (NSSize)windowWillResize:(NSWindow *)window
357 toSize:(NSSize)proposedFrameSize
359 NSRect frame = [window frame];
360 wxRect wxframe = wxFromNSRect( NULL, frame );
361 wxframe.SetWidth( (int)proposedFrameSize.width );
362 wxframe.SetHeight( (int)proposedFrameSize.height );
364 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
367 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
370 wxpeer->HandleResizing( 0, &wxframe );
371 NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight());
376 return proposedFrameSize;
379 - (void)windowDidResize:(NSNotification *)notification
381 NSWindow* window = (NSWindow*) [notification object];
382 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
385 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
387 wxpeer->HandleResized(0);
391 - (void)windowDidMove:(NSNotification *)notification
393 wxNSWindow* window = (wxNSWindow*) [notification object];
394 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
397 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
399 wxpeer->HandleMoved(0);
403 - (void)windowDidBecomeKey:(NSNotification *)notification
405 NSWindow* window = (NSWindow*) [notification object];
406 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
409 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
411 wxpeer->HandleActivated(0, true);
415 - (void)windowDidResignKey:(NSNotification *)notification
417 NSWindow* window = (NSWindow*) [notification object];
418 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
421 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
424 wxpeer->HandleActivated(0, false);
425 // Needed for popup window since the firstResponder
426 // (focus in wx) doesn't change when this
427 // TLW becomes inactive.
428 wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
429 event.SetEventObject(wxpeer);
430 wxpeer->HandleWindowEvent(event);
435 - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
439 if ([anObject isKindOfClass:[wxNSTextField class]])
441 wxNSTextField* tf = (wxNSTextField*) anObject;
442 wxNSTextFieldEditor* editor = [tf fieldEditor];
445 editor = [[wxNSTextFieldEditor alloc] init];
446 [editor setFieldEditor:YES];
447 [tf setFieldEditor:editor];
455 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
457 wxUnusedVar(newFrame);
458 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
461 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
462 wxMaximizeEvent event(wxpeer->GetId());
463 event.SetEventObject(wxpeer);
464 return !wxpeer->HandleWindowEvent(event);
471 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
473 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
474 wxNonOwnedWindowImpl(nonownedwnd)
477 m_macFullScreenData = NULL;
480 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
483 m_macFullScreenData = NULL;
486 wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
488 if ( !m_wxPeer->IsNativeWindowWrapper() )
490 [m_macWindow setDelegate:nil];
491 [m_macWindow release];
495 void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
497 if ( !m_wxPeer->IsNativeWindowWrapper() )
499 [m_macWindow setDelegate:nil];
503 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
504 long style, long extraStyle, const wxString& WXUNUSED(name) )
506 static wxNonOwnedWindowController* controller = NULL;
509 controller =[[wxNonOwnedWindowController alloc] init];
512 int windowstyle = NSBorderlessWindowMask;
514 if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) ||
515 GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
517 m_macWindow = [wxNSPanel alloc];
520 m_macWindow = [wxNSWindow alloc];
522 CGWindowLevel level = kCGNormalWindowLevel;
524 if ( style & wxFRAME_TOOL_WINDOW )
526 windowstyle |= NSUtilityWindowMask;
527 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
528 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
530 windowstyle |= NSTitledWindowMask ;
533 else if ( ( style & wxPOPUP_WINDOW ) )
535 level = kCGPopUpMenuWindowLevel;
537 if ( ( style & wxBORDER_NONE ) )
539 wclass = kHelpWindowClass ; // has no border
540 attr |= kWindowNoShadowAttribute;
544 wclass = kPlainWindowClass ; // has a single line border, it will have to do for now
548 else if ( ( style & wxCAPTION ) )
550 windowstyle |= NSTitledWindowMask ;
552 else if ( ( style & wxFRAME_DRAWER ) )
555 wclass = kDrawerWindowClass;
560 // set these even if we have no title, otherwise the controls won't be visible
561 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
562 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
564 windowstyle |= NSTitledWindowMask ;
567 else if ( ( style & wxNO_BORDER ) )
569 wclass = kSimpleWindowClass ;
573 wclass = kPlainWindowClass ;
578 if ( windowstyle & NSTitledWindowMask )
580 if ( ( style & wxMINIMIZE_BOX ) )
581 windowstyle |= NSMiniaturizableWindowMask ;
583 if ( ( style & wxMAXIMIZE_BOX ) )
584 windowstyle |= NSResizableWindowMask ; // TODO showing ZOOM ?
586 if ( ( style & wxRESIZE_BORDER ) )
587 windowstyle |= NSResizableWindowMask ;
589 if ( ( style & wxCLOSE_BOX) )
590 windowstyle |= NSClosableWindowMask ;
592 if ( extraStyle & wxFRAME_EX_METAL)
593 windowstyle |= NSTexturedBackgroundWindowMask;
595 if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) )
596 level = kCGFloatingWindowLevel;
598 if ( ( style & wxSTAY_ON_TOP ) )
599 level = kCGUtilityWindowLevel;
601 NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
603 r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle];
605 [m_macWindow initWithContentRect:r
606 styleMask:windowstyle
607 backing:NSBackingStoreBuffered
611 // If the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
612 // to be in kCGUtilityWindowLevel and not kCGFloatingWindowLevel to stay
614 wxDialog * const parentDialog = wxDynamicCast(parent, wxDialog);
615 if (parentDialog && parentDialog->IsModal())
617 if (level == kCGFloatingWindowLevel)
619 level = kCGUtilityWindowLevel;
622 // Cocoa's modal loop does not process other windows by default, but
623 // don't call this on normal window levels so nested modal dialogs will
624 // still behave modally.
625 if (level != kCGNormalWindowLevel)
627 if ([m_macWindow isKindOfClass:[NSPanel class]])
629 [(NSPanel*)m_macWindow setWorksWhenModal:YES];
634 [m_macWindow setLevel:level];
636 [m_macWindow setDelegate:controller];
638 [m_macWindow setAcceptsMouseMovedEvents: YES];
640 if ( ( style & wxFRAME_SHAPED) )
642 [m_macWindow setOpaque:NO];
643 [m_macWindow setAlphaValue:1.0];
646 if ( !(style & wxFRAME_TOOL_WINDOW) )
647 [m_macWindow setHidesOnDeactivate:NO];
650 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
652 m_macWindow = nativeWindow;
655 WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
660 void wxNonOwnedWindowCocoaImpl::Raise()
662 [m_macWindow makeKeyAndOrderFront:nil];
665 void wxNonOwnedWindowCocoaImpl::Lower()
667 [m_macWindow orderWindow:NSWindowBelow relativeTo:0];
670 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
672 [m_macWindow orderFront:nil];
673 [[m_macWindow contentView] setNeedsDisplay: YES];
676 bool wxNonOwnedWindowCocoaImpl::Show(bool show)
680 wxNonOwnedWindow* wxpeer = GetWXPeer();
681 if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
682 [m_macWindow makeKeyAndOrderFront:nil];
684 [m_macWindow orderFront:nil];
685 [[m_macWindow contentView] setNeedsDisplay: YES];
688 [m_macWindow orderOut:nil];
692 bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show,
696 return wxWidgetCocoaImpl::
697 ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout);
700 void wxNonOwnedWindowCocoaImpl::Update()
702 [m_macWindow displayIfNeeded];
705 bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
707 [m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
711 bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& WXUNUSED(col) )
716 void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle )
720 bool metal = exStyle & wxFRAME_EX_METAL ;
721 int windowStyle = [ m_macWindow styleMask];
722 if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) )
724 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
726 else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) )
728 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
733 void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style )
737 CGWindowLevel level = kCGNormalWindowLevel;
739 if (style & wxSTAY_ON_TOP)
740 level = kCGUtilityWindowLevel;
741 else if (( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ))
742 level = kCGFloatingWindowLevel;
744 [m_macWindow setLevel: level];
748 bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
750 if ( style == wxBG_STYLE_TRANSPARENT )
752 [m_macWindow setOpaque:NO];
753 [m_macWindow setBackgroundColor:[NSColor clearColor]];
759 bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
764 void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
766 NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
767 // do not trigger refreshes upon invisible and possible partly created objects
768 [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()];
771 void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
773 wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
778 void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
780 NSRect rect = [m_macWindow frame];
781 width = (int)rect.size.width;
782 height = (int)rect.size.height;
785 void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
787 NSRect rect = [[m_macWindow contentView] frame];
788 left = (int)rect.origin.x;
789 top = (int)rect.origin.y;
790 width = (int)rect.size.width;
791 height = (int)rect.size.height;
794 bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
796 [m_macWindow setOpaque:NO];
797 [m_macWindow setBackgroundColor:[NSColor clearColor]];
802 void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
804 [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
807 bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
809 if (([m_macWindow styleMask] & NSResizableWindowMask) != 0)
811 return [m_macWindow isZoomed];
815 NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
816 NSRect rectWindow = [m_macWindow frame];
817 return (rectScreen.origin.x == rectWindow.origin.x &&
818 rectScreen.origin.y == rectWindow.origin.y &&
819 rectScreen.size.width == rectWindow.size.width &&
820 rectScreen.size.height == rectWindow.size.height);
824 bool wxNonOwnedWindowCocoaImpl::IsIconized() const
826 return [m_macWindow isMiniaturized];
829 void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
832 [m_macWindow miniaturize:nil];
834 [m_macWindow deminiaturize:nil];
837 void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize))
839 [m_macWindow zoom:nil];
843 // http://cocoadevcentral.com/articles/000028.php
848 NSRect m_formerFrame;
851 bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
853 return m_macFullScreenData != NULL ;
856 bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
860 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
862 data = new FullScreenData();
864 m_macFullScreenData = data ;
865 data->m_formerLevel = [m_macWindow level];
866 data->m_formerFrame = [m_macWindow frame];
867 CGDisplayCapture( kCGDirectMainDisplay );
868 [m_macWindow setLevel:CGShieldingWindowLevel()];
869 NSRect screenframe = [[NSScreen mainScreen] frame];
870 NSRect frame = NSMakeRect (0, 0, 100, 100);
872 contentRect = [NSWindow contentRectForFrameRect: frame
873 styleMask: NSTitledWindowMask];
874 screenframe.origin.y += (frame.origin.y - contentRect.origin.y);
875 screenframe.size.height += (frame.size.height - contentRect.size.height);
876 [m_macWindow setFrame:screenframe display:YES];
878 else if ( m_macFullScreenData != NULL )
880 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
881 CGDisplayRelease( kCGDirectMainDisplay );
882 [m_macWindow setLevel:data->m_formerLevel];
883 [m_macWindow setFrame:data->m_formerFrame display:YES];
885 m_macFullScreenData = NULL ;
891 void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX)
893 NSRequestUserAttentionType flagsOSX;
896 case wxUSER_ATTENTION_INFO:
897 flagsOSX = NSInformationalRequest;
900 case wxUSER_ATTENTION_ERROR:
901 flagsOSX = NSCriticalRequest;
905 wxFAIL_MSG( "invalid RequestUserAttention() flags" );
909 [NSApp requestUserAttention:flagsOSX];
912 void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
914 wxPoint p((x ? *x : 0), (y ? *y : 0) );
915 NSPoint nspt = wxToNSPoint( NULL, p );
916 nspt = [m_macWindow convertScreenToBase:nspt];
917 nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil];
918 p = wxFromNSPoint([m_macWindow contentView], nspt);
925 void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
927 wxPoint p((x ? *x : 0), (y ? *y : 0) );
928 NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p );
929 nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil];
930 nspt = [m_macWindow convertBaseToScreen:nspt];
931 p = wxFromNSPoint( NULL, nspt);
938 bool wxNonOwnedWindowCocoaImpl::IsActive()
940 return [m_macWindow isKeyWindow];
943 void wxNonOwnedWindowCocoaImpl::SetModified(bool modified)
945 [m_macWindow setDocumentEdited:modified];
948 bool wxNonOwnedWindowCocoaImpl::IsModified() const
950 return [m_macWindow isDocumentEdited];
953 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
955 wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
956 now->Create( parent, nativeWindow );
960 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
961 long style, long extraStyle, const wxString& name )
963 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
964 now->Create( parent, pos, size, style , extraStyle, name );