1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/nonownedwnd.mm
3 // Purpose: non owned window for cocoa
4 // Author: DavidStefan Csomor
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);
129 else if ( [event type] == NSMouseMoved )
131 NSPoint nsPoint = [event locationInWindow];
132 if ( [event window] != nil )
133 nsPoint = [[event window] convertBaseToScreen:nsPoint];
135 wxPoint pt = wxFromNSPoint(NULL, nsPoint);
136 wxWindow* mw = ::wxFindWindowAtPoint(pt);
139 ((wxWidgetCocoaImpl*)mw->GetPeer())->DoHandleMouseEvent( event);
149 // wx native implementation
152 @interface wxNSWindow : NSWindow
156 - (void) sendEvent:(NSEvent *)event;
157 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
158 - (void)noResponderFor: (SEL) selector;
161 @implementation wxNSWindow
163 - (void)sendEvent:(NSEvent *) event
165 if ( ![self WX_filterSendEvent: event] )
167 WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
168 WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
171 wxTheApp->MacSetCurrentEvent(event, NULL);
173 [super sendEvent: event];
176 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
180 // The default implementation always moves the window back onto the screen,
181 // even when the programmer explicitly wants to hide it.
182 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
188 - (void)doCommandBySelector:(SEL)selector
190 if (shouldHandleSelector(selector) &&
191 !(selector == @selector(cancel:) || selector == @selector(cancelOperation:)) )
192 [super doCommandBySelector:selector];
196 // NB: if we don't do this, all key downs that get handled lead to a NSBeep
197 - (void)noResponderFor: (SEL) selector
199 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
201 [super noResponderFor:selector];
205 // We need this for borderless windows, i.e. shaped windows or windows without
206 // a title bar. For more info, see:
207 // http://lists.apple.com/archives/cocoa-dev/2008/May/msg02091.html
208 - (BOOL)canBecomeKeyWindow
215 @interface wxNSPanel : NSPanel
219 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
220 - (void)noResponderFor: (SEL) selector;
221 - (void)sendEvent:(NSEvent *)event;
224 @implementation wxNSPanel
226 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
228 wxNonOwnedWindowCocoaImpl* impl = (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
229 if (impl && impl->IsFullScreen())
232 return [super constrainFrameRect:frameRect toScreen:screen];
235 - (BOOL)canBecomeKeyWindow
240 - (void)doCommandBySelector:(SEL)selector
242 if (shouldHandleSelector(selector))
243 [super doCommandBySelector:selector];
246 // NB: if we don't do this, it seems that all events that end here lead to a NSBeep
247 - (void)noResponderFor: (SEL) selector
249 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
251 [super noResponderFor:selector];
255 - (void)sendEvent:(NSEvent *) event
257 if ( ![self WX_filterSendEvent: event] )
258 [super sendEvent: event];
268 @interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>)
272 - (void)windowDidResize:(NSNotification *)notification;
273 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
274 - (void)windowDidResignKey:(NSNotification *)notification;
275 - (void)windowDidBecomeKey:(NSNotification *)notification;
276 - (void)windowDidMove:(NSNotification *)notification;
277 - (BOOL)windowShouldClose:(id)window;
278 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
282 extern int wxOSXGetIdFromSelector(SEL action );
284 @implementation wxNonOwnedWindowController
292 - (BOOL) triggerMenu:(SEL) action
294 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
298 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
299 if ( menu != NULL && menuitem != NULL)
300 return menu->HandleCommandProcess(menuitem);
305 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
307 SEL action = [menuItem action];
309 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
313 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
314 if ( menu != NULL && menuitem != NULL)
316 menu->HandleCommandUpdateStatus(menuitem);
317 return menuitem->IsEnabled();
323 - (void)undo:(id)sender
326 [self triggerMenu:_cmd];
329 - (void)redo:(id)sender
332 [self triggerMenu:_cmd];
335 - (void)cut:(id)sender
338 [self triggerMenu:_cmd];
341 - (void)copy:(id)sender
344 [self triggerMenu:_cmd];
347 - (void)paste:(id)sender
350 [self triggerMenu:_cmd];
353 - (void)delete:(id)sender
356 [self triggerMenu:_cmd];
359 - (void)selectAll:(id)sender
362 [self triggerMenu:_cmd];
365 - (BOOL)windowShouldClose:(id)nwindow
367 wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation];
370 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
377 - (NSSize)windowWillResize:(NSWindow *)window
378 toSize:(NSSize)proposedFrameSize
380 NSRect frame = [window frame];
381 wxRect wxframe = wxFromNSRect( NULL, frame );
382 wxframe.SetWidth( (int)proposedFrameSize.width );
383 wxframe.SetHeight( (int)proposedFrameSize.height );
385 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
388 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
391 wxpeer->HandleResizing( 0, &wxframe );
392 NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight());
397 return proposedFrameSize;
400 - (void)windowDidResize:(NSNotification *)notification
402 NSWindow* window = (NSWindow*) [notification object];
403 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
406 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
408 wxpeer->HandleResized(0);
412 - (void)windowDidMove:(NSNotification *)notification
414 wxNSWindow* window = (wxNSWindow*) [notification object];
415 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
418 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
420 wxpeer->HandleMoved(0);
424 - (void)windowDidBecomeKey:(NSNotification *)notification
426 NSWindow* window = (NSWindow*) [notification object];
427 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
430 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
432 wxpeer->HandleActivated(0, true);
436 - (void)windowDidResignKey:(NSNotification *)notification
438 NSWindow* window = (NSWindow*) [notification object];
439 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
442 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
445 wxpeer->HandleActivated(0, false);
446 // Needed for popup window since the firstResponder
447 // (focus in wx) doesn't change when this
448 // TLW becomes inactive.
449 wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
450 event.SetEventObject(wxpeer);
451 wxpeer->HandleWindowEvent(event);
456 - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
460 if ([anObject isKindOfClass:[wxNSTextField class]])
462 wxNSTextField* tf = (wxNSTextField*) anObject;
463 wxNSTextFieldEditor* editor = [tf fieldEditor];
466 editor = [[wxNSTextFieldEditor alloc] init];
467 [editor setFieldEditor:YES];
468 [tf setFieldEditor:editor];
477 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
479 wxUnusedVar(newFrame);
480 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
483 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
484 wxMaximizeEvent event(wxpeer->GetId());
485 event.SetEventObject(wxpeer);
486 return !wxpeer->HandleWindowEvent(event);
493 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
495 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
496 wxNonOwnedWindowImpl(nonownedwnd)
499 m_macFullScreenData = NULL;
502 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
505 m_macFullScreenData = NULL;
508 wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
510 if ( !m_wxPeer->IsNativeWindowWrapper() )
512 [m_macWindow setDelegate:nil];
513 [m_macWindow release];
517 void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
519 if ( !m_wxPeer->IsNativeWindowWrapper() )
521 [m_macWindow setDelegate:nil];
525 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
526 long style, long extraStyle, const wxString& WXUNUSED(name) )
528 static wxNonOwnedWindowController* controller = NULL;
531 controller =[[wxNonOwnedWindowController alloc] init];
534 int windowstyle = NSBorderlessWindowMask;
536 if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) ||
537 GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
539 m_macWindow = [wxNSPanel alloc];
542 m_macWindow = [wxNSWindow alloc];
544 CGWindowLevel level = kCGNormalWindowLevel;
546 if ( style & wxFRAME_TOOL_WINDOW )
548 windowstyle |= NSUtilityWindowMask;
550 else if ( ( style & wxPOPUP_WINDOW ) )
552 level = kCGPopUpMenuWindowLevel;
554 else if ( ( style & wxFRAME_DRAWER ) )
557 wclass = kDrawerWindowClass;
561 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
562 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) || ( style & wxCAPTION ) )
564 windowstyle |= NSTitledWindowMask ;
565 if ( ( style & wxMINIMIZE_BOX ) )
566 windowstyle |= NSMiniaturizableWindowMask ;
568 if ( ( style & wxMAXIMIZE_BOX ) )
569 windowstyle |= NSResizableWindowMask ;
571 if ( ( style & wxCLOSE_BOX) )
572 windowstyle |= NSClosableWindowMask ;
575 if ( ( style & wxRESIZE_BORDER ) )
576 windowstyle |= NSResizableWindowMask ;
578 if ( extraStyle & wxFRAME_EX_METAL)
579 windowstyle |= NSTexturedBackgroundWindowMask;
581 if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) )
582 level = kCGFloatingWindowLevel;
584 if ( ( style & wxSTAY_ON_TOP ) )
585 level = kCGUtilityWindowLevel;
587 NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
589 r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle];
591 [m_macWindow initWithContentRect:r
592 styleMask:windowstyle
593 backing:NSBackingStoreBuffered
597 // if we just have a title bar with no buttons needed, hide them
598 if ( (windowstyle & NSTitledWindowMask) &&
599 !(style & wxCLOSE_BOX) && !(style & wxMAXIMIZE_BOX) && !(style & wxMINIMIZE_BOX) )
601 [[m_macWindow standardWindowButton:NSWindowZoomButton] setHidden:YES];
602 [[m_macWindow standardWindowButton:NSWindowCloseButton] setHidden:YES];
603 [[m_macWindow standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
606 // If the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
607 // to be in kCGUtilityWindowLevel and not kCGFloatingWindowLevel to stay
609 wxDialog * const parentDialog = wxDynamicCast(parent, wxDialog);
610 if (parentDialog && parentDialog->IsModal())
612 if (level == kCGFloatingWindowLevel)
614 level = kCGUtilityWindowLevel;
617 // Cocoa's modal loop does not process other windows by default, but
618 // don't call this on normal window levels so nested modal dialogs will
619 // still behave modally.
620 if (level != kCGNormalWindowLevel)
622 if ([m_macWindow isKindOfClass:[NSPanel class]])
624 [(NSPanel*)m_macWindow setWorksWhenModal:YES];
629 [m_macWindow setLevel:level];
630 m_macWindowLevel = level;
632 [m_macWindow setDelegate:controller];
634 [m_macWindow setAcceptsMouseMovedEvents: YES];
636 if ( ( style & wxFRAME_SHAPED) )
638 [m_macWindow setOpaque:NO];
639 [m_macWindow setAlphaValue:1.0];
642 if ( !(style & wxFRAME_TOOL_WINDOW) )
643 [m_macWindow setHidesOnDeactivate:NO];
646 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
648 m_macWindow = nativeWindow;
651 WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
656 void wxNonOwnedWindowCocoaImpl::Raise()
658 [m_macWindow makeKeyAndOrderFront:nil];
661 void wxNonOwnedWindowCocoaImpl::Lower()
663 [m_macWindow orderWindow:NSWindowBelow relativeTo:0];
666 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
668 [m_macWindow orderFront:nil];
669 [[m_macWindow contentView] setNeedsDisplay: YES];
672 bool wxNonOwnedWindowCocoaImpl::Show(bool show)
676 wxNonOwnedWindow* wxpeer = GetWXPeer();
677 if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
678 [m_macWindow makeKeyAndOrderFront:nil];
680 [m_macWindow orderFront:nil];
681 [[m_macWindow contentView] setNeedsDisplay: YES];
684 [m_macWindow orderOut:nil];
688 bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show,
692 return wxWidgetCocoaImpl::
693 ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout);
696 void wxNonOwnedWindowCocoaImpl::Update()
698 [m_macWindow displayIfNeeded];
701 bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
703 [m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
707 bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& col )
709 [m_macWindow setBackgroundColor:[NSColor colorWithCalibratedRed:(CGFloat) (col.Red() / 255.0)
710 green:(CGFloat) (col.Green() / 255.0)
711 blue:(CGFloat) (col.Blue() / 255.0)
712 alpha:(CGFloat) (col.Alpha() / 255.0)]];
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];
745 m_macWindowLevel = level;
749 bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
751 if ( style == wxBG_STYLE_TRANSPARENT )
753 [m_macWindow setOpaque:NO];
754 [m_macWindow setBackgroundColor:[NSColor clearColor]];
760 bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
765 void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
767 NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
768 // do not trigger refreshes upon invisible and possible partly created objects
769 [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()];
772 void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
774 wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
779 void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
781 NSRect rect = [m_macWindow frame];
782 width = (int)rect.size.width;
783 height = (int)rect.size.height;
786 void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
788 NSRect rect = [[m_macWindow contentView] frame];
789 left = (int)rect.origin.x;
790 top = (int)rect.origin.y;
791 width = (int)rect.size.width;
792 height = (int)rect.size.height;
795 bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
797 [m_macWindow setOpaque:NO];
798 [m_macWindow setBackgroundColor:[NSColor clearColor]];
803 void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
805 [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
808 bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
810 if (([m_macWindow styleMask] & NSResizableWindowMask) != 0)
812 return [m_macWindow isZoomed];
816 NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
817 NSRect rectWindow = [m_macWindow frame];
818 return (rectScreen.origin.x == rectWindow.origin.x &&
819 rectScreen.origin.y == rectWindow.origin.y &&
820 rectScreen.size.width == rectWindow.size.width &&
821 rectScreen.size.height == rectWindow.size.height);
825 bool wxNonOwnedWindowCocoaImpl::IsIconized() const
827 return [m_macWindow isMiniaturized];
830 void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
833 [m_macWindow miniaturize:nil];
835 [m_macWindow deminiaturize:nil];
838 void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize))
840 [m_macWindow zoom:nil];
844 // http://cocoadevcentral.com/articles/000028.php
848 NSUInteger m_formerStyleMask;
850 NSRect m_formerFrame;
853 bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
855 return m_macFullScreenData != NULL ;
858 bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
862 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
864 data = new FullScreenData();
866 m_macFullScreenData = data ;
867 data->m_formerLevel = [m_macWindow level];
868 data->m_formerFrame = [m_macWindow frame];
869 data->m_formerStyleMask = [m_macWindow styleMask];
871 // CGDisplayCapture( kCGDirectMainDisplay );
872 //[m_macWindow setLevel:NSMainMenuWindowLevel+1/*CGShieldingWindowLevel()*/];
874 NSRect screenframe = [[NSScreen mainScreen] frame];
875 NSRect frame = NSMakeRect (0, 0, 100, 100);
878 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
879 if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
880 [m_macWindow setStyleMask:data->m_formerStyleMask & ~ NSResizableWindowMask];
883 contentRect = [NSWindow contentRectForFrameRect: frame
884 styleMask: [m_macWindow styleMask]];
885 screenframe.origin.y += (frame.origin.y - contentRect.origin.y);
886 screenframe.size.height += (frame.size.height - contentRect.size.height);
887 [m_macWindow setFrame:screenframe display:YES];
889 SetSystemUIMode(kUIModeAllHidden,
890 kUIOptionDisableAppleMenu
892 | kUIOptionDisableProcessSwitch
893 | kUIOptionDisableForceQuit
896 else if ( m_macFullScreenData != NULL )
898 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
900 // CGDisplayRelease( kCGDirectMainDisplay );
901 // [m_macWindow setLevel:data->m_formerLevel];
904 [m_macWindow setFrame:data->m_formerFrame display:YES];
905 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
906 if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
907 [m_macWindow setStyleMask:data->m_formerStyleMask];
910 m_macFullScreenData = NULL ;
912 SetSystemUIMode(kUIModeNormal, 0);
918 void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX)
920 NSRequestUserAttentionType flagsOSX;
923 case wxUSER_ATTENTION_INFO:
924 flagsOSX = NSInformationalRequest;
927 case wxUSER_ATTENTION_ERROR:
928 flagsOSX = NSCriticalRequest;
932 wxFAIL_MSG( "invalid RequestUserAttention() flags" );
936 [NSApp requestUserAttention:flagsOSX];
939 void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
941 wxPoint p((x ? *x : 0), (y ? *y : 0) );
942 NSPoint nspt = wxToNSPoint( NULL, p );
943 nspt = [m_macWindow convertScreenToBase:nspt];
944 nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil];
945 p = wxFromNSPoint([m_macWindow contentView], nspt);
952 void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
954 wxPoint p((x ? *x : 0), (y ? *y : 0) );
955 NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p );
956 nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil];
957 nspt = [m_macWindow convertBaseToScreen:nspt];
958 p = wxFromNSPoint( NULL, nspt);
965 bool wxNonOwnedWindowCocoaImpl::IsActive()
967 return [m_macWindow isKeyWindow];
970 void wxNonOwnedWindowCocoaImpl::SetModified(bool modified)
972 [m_macWindow setDocumentEdited:modified];
975 bool wxNonOwnedWindowCocoaImpl::IsModified() const
977 return [m_macWindow isDocumentEdited];
980 void wxNonOwnedWindowCocoaImpl::SetRepresentedFilename(const wxString& filename)
982 [m_macWindow setRepresentedFilename:wxCFStringRef(filename).AsNSString()];
985 void wxNonOwnedWindowCocoaImpl::RestoreWindowLevel()
987 if ( [m_macWindow level] != m_macWindowLevel )
988 [m_macWindow setLevel:m_macWindowLevel];
995 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
997 wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
998 now->Create( parent, nativeWindow );
1002 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
1003 long style, long extraStyle, const wxString& name )
1005 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
1006 now->Create( parent, pos, size, style , extraStyle, name );