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);
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 menu->HandleCommandUpdateStatus(menuitem);
303 return menuitem->IsEnabled();
309 - (void)undo:(id)sender
312 [self triggerMenu:_cmd];
315 - (void)redo:(id)sender
318 [self triggerMenu:_cmd];
321 - (void)cut:(id)sender
324 [self triggerMenu:_cmd];
327 - (void)copy:(id)sender
330 [self triggerMenu:_cmd];
333 - (void)paste:(id)sender
336 [self triggerMenu:_cmd];
339 - (void)delete:(id)sender
342 [self triggerMenu:_cmd];
345 - (void)selectAll:(id)sender
348 [self triggerMenu:_cmd];
351 - (BOOL)windowShouldClose:(id)nwindow
353 wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation];
356 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
363 - (NSSize)windowWillResize:(NSWindow *)window
364 toSize:(NSSize)proposedFrameSize
366 NSRect frame = [window frame];
367 wxRect wxframe = wxFromNSRect( NULL, frame );
368 wxframe.SetWidth( (int)proposedFrameSize.width );
369 wxframe.SetHeight( (int)proposedFrameSize.height );
371 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
374 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
377 wxpeer->HandleResizing( 0, &wxframe );
378 NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight());
383 return proposedFrameSize;
386 - (void)windowDidResize:(NSNotification *)notification
388 NSWindow* window = (NSWindow*) [notification object];
389 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
392 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
394 wxpeer->HandleResized(0);
398 - (void)windowDidMove:(NSNotification *)notification
400 wxNSWindow* window = (wxNSWindow*) [notification object];
401 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
404 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
406 wxpeer->HandleMoved(0);
410 - (void)windowDidBecomeKey:(NSNotification *)notification
412 NSWindow* window = (NSWindow*) [notification object];
413 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
416 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
418 wxpeer->HandleActivated(0, true);
422 - (void)windowDidResignKey:(NSNotification *)notification
424 NSWindow* window = (NSWindow*) [notification object];
425 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
428 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
431 wxpeer->HandleActivated(0, false);
432 // Needed for popup window since the firstResponder
433 // (focus in wx) doesn't change when this
434 // TLW becomes inactive.
435 wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
436 event.SetEventObject(wxpeer);
437 wxpeer->HandleWindowEvent(event);
442 - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
446 if ([anObject isKindOfClass:[wxNSTextField class]])
448 wxNSTextField* tf = (wxNSTextField*) anObject;
449 wxNSTextFieldEditor* editor = [tf fieldEditor];
452 editor = [[wxNSTextFieldEditor alloc] init];
453 [editor setFieldEditor:YES];
454 [tf setFieldEditor:editor];
463 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
465 wxUnusedVar(newFrame);
466 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
469 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
470 wxMaximizeEvent event(wxpeer->GetId());
471 event.SetEventObject(wxpeer);
472 return !wxpeer->HandleWindowEvent(event);
479 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
481 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
482 wxNonOwnedWindowImpl(nonownedwnd)
485 m_macFullScreenData = NULL;
488 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
491 m_macFullScreenData = NULL;
494 wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
496 if ( !m_wxPeer->IsNativeWindowWrapper() )
498 [m_macWindow setDelegate:nil];
499 [m_macWindow release];
503 void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
505 if ( !m_wxPeer->IsNativeWindowWrapper() )
507 [m_macWindow setDelegate:nil];
511 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
512 long style, long extraStyle, const wxString& WXUNUSED(name) )
514 static wxNonOwnedWindowController* controller = NULL;
517 controller =[[wxNonOwnedWindowController alloc] init];
520 int windowstyle = NSBorderlessWindowMask;
522 if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) ||
523 GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
525 m_macWindow = [wxNSPanel alloc];
528 m_macWindow = [wxNSWindow alloc];
530 CGWindowLevel level = kCGNormalWindowLevel;
532 if ( style & wxFRAME_TOOL_WINDOW )
534 windowstyle |= NSUtilityWindowMask;
535 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
536 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
538 windowstyle |= NSTitledWindowMask ;
541 else if ( ( style & wxPOPUP_WINDOW ) )
543 level = kCGPopUpMenuWindowLevel;
545 if ( ( style & wxBORDER_NONE ) )
547 wclass = kHelpWindowClass ; // has no border
548 attr |= kWindowNoShadowAttribute;
552 wclass = kPlainWindowClass ; // has a single line border, it will have to do for now
556 else if ( ( style & wxCAPTION ) )
558 windowstyle |= NSTitledWindowMask ;
560 else if ( ( style & wxFRAME_DRAWER ) )
563 wclass = kDrawerWindowClass;
568 // set these even if we have no title, otherwise the controls won't be visible
569 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
570 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
572 windowstyle |= NSTitledWindowMask ;
575 else if ( ( style & wxNO_BORDER ) )
577 wclass = kSimpleWindowClass ;
581 wclass = kPlainWindowClass ;
586 if ( windowstyle & NSTitledWindowMask )
588 if ( ( style & wxMINIMIZE_BOX ) )
589 windowstyle |= NSMiniaturizableWindowMask ;
591 if ( ( style & wxMAXIMIZE_BOX ) )
592 windowstyle |= NSResizableWindowMask ; // TODO showing ZOOM ?
594 if ( ( style & wxRESIZE_BORDER ) )
595 windowstyle |= NSResizableWindowMask ;
597 if ( ( style & wxCLOSE_BOX) )
598 windowstyle |= NSClosableWindowMask ;
600 if ( extraStyle & wxFRAME_EX_METAL)
601 windowstyle |= NSTexturedBackgroundWindowMask;
603 if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) )
604 level = kCGFloatingWindowLevel;
606 if ( ( style & wxSTAY_ON_TOP ) )
607 level = kCGUtilityWindowLevel;
609 NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
611 r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle];
613 [m_macWindow initWithContentRect:r
614 styleMask:windowstyle
615 backing:NSBackingStoreBuffered
619 // If the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
620 // to be in kCGUtilityWindowLevel and not kCGFloatingWindowLevel to stay
622 wxDialog * const parentDialog = wxDynamicCast(parent, wxDialog);
623 if (parentDialog && parentDialog->IsModal())
625 if (level == kCGFloatingWindowLevel)
627 level = kCGUtilityWindowLevel;
630 // Cocoa's modal loop does not process other windows by default, but
631 // don't call this on normal window levels so nested modal dialogs will
632 // still behave modally.
633 if (level != kCGNormalWindowLevel)
635 if ([m_macWindow isKindOfClass:[NSPanel class]])
637 [(NSPanel*)m_macWindow setWorksWhenModal:YES];
642 [m_macWindow setLevel:level];
643 m_macWindowLevel = level;
645 [m_macWindow setDelegate:controller];
647 [m_macWindow setAcceptsMouseMovedEvents: YES];
649 if ( ( style & wxFRAME_SHAPED) )
651 [m_macWindow setOpaque:NO];
652 [m_macWindow setAlphaValue:1.0];
655 if ( !(style & wxFRAME_TOOL_WINDOW) )
656 [m_macWindow setHidesOnDeactivate:NO];
659 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
661 m_macWindow = nativeWindow;
664 WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
669 void wxNonOwnedWindowCocoaImpl::Raise()
671 [m_macWindow makeKeyAndOrderFront:nil];
674 void wxNonOwnedWindowCocoaImpl::Lower()
676 [m_macWindow orderWindow:NSWindowBelow relativeTo:0];
679 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
681 [m_macWindow orderFront:nil];
682 [[m_macWindow contentView] setNeedsDisplay: YES];
685 bool wxNonOwnedWindowCocoaImpl::Show(bool show)
689 wxNonOwnedWindow* wxpeer = GetWXPeer();
690 if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
691 [m_macWindow makeKeyAndOrderFront:nil];
693 [m_macWindow orderFront:nil];
694 [[m_macWindow contentView] setNeedsDisplay: YES];
697 [m_macWindow orderOut:nil];
701 bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show,
705 return wxWidgetCocoaImpl::
706 ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout);
709 void wxNonOwnedWindowCocoaImpl::Update()
711 [m_macWindow displayIfNeeded];
714 bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
716 [m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
720 bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& col )
722 [m_macWindow setBackgroundColor:[NSColor colorWithCalibratedRed:(CGFloat) (col.Red() / 255.0)
723 green:(CGFloat) (col.Green() / 255.0)
724 blue:(CGFloat) (col.Blue() / 255.0)
725 alpha:(CGFloat) (col.Alpha() / 255.0)]];
729 void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle )
733 bool metal = exStyle & wxFRAME_EX_METAL ;
734 int windowStyle = [ m_macWindow styleMask];
735 if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) )
737 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
739 else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) )
741 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
746 void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style )
750 CGWindowLevel level = kCGNormalWindowLevel;
752 if (style & wxSTAY_ON_TOP)
753 level = kCGUtilityWindowLevel;
754 else if (( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ))
755 level = kCGFloatingWindowLevel;
757 [m_macWindow setLevel: level];
758 m_macWindowLevel = level;
762 bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
764 if ( style == wxBG_STYLE_TRANSPARENT )
766 [m_macWindow setOpaque:NO];
767 [m_macWindow setBackgroundColor:[NSColor clearColor]];
773 bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
778 void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
780 NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
781 // do not trigger refreshes upon invisible and possible partly created objects
782 [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()];
785 void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
787 wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
792 void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
794 NSRect rect = [m_macWindow frame];
795 width = (int)rect.size.width;
796 height = (int)rect.size.height;
799 void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
801 NSRect rect = [[m_macWindow contentView] frame];
802 left = (int)rect.origin.x;
803 top = (int)rect.origin.y;
804 width = (int)rect.size.width;
805 height = (int)rect.size.height;
808 bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
810 [m_macWindow setOpaque:NO];
811 [m_macWindow setBackgroundColor:[NSColor clearColor]];
816 void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
818 [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
821 bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
823 if (([m_macWindow styleMask] & NSResizableWindowMask) != 0)
825 return [m_macWindow isZoomed];
829 NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
830 NSRect rectWindow = [m_macWindow frame];
831 return (rectScreen.origin.x == rectWindow.origin.x &&
832 rectScreen.origin.y == rectWindow.origin.y &&
833 rectScreen.size.width == rectWindow.size.width &&
834 rectScreen.size.height == rectWindow.size.height);
838 bool wxNonOwnedWindowCocoaImpl::IsIconized() const
840 return [m_macWindow isMiniaturized];
843 void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
846 [m_macWindow miniaturize:nil];
848 [m_macWindow deminiaturize:nil];
851 void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize))
853 [m_macWindow zoom:nil];
857 // http://cocoadevcentral.com/articles/000028.php
861 NSUInteger m_formerStyleMask;
863 NSRect m_formerFrame;
866 bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
868 return m_macFullScreenData != NULL ;
871 bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
875 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
877 data = new FullScreenData();
879 m_macFullScreenData = data ;
880 data->m_formerLevel = [m_macWindow level];
881 data->m_formerFrame = [m_macWindow frame];
882 data->m_formerStyleMask = [m_macWindow styleMask];
884 // CGDisplayCapture( kCGDirectMainDisplay );
885 //[m_macWindow setLevel:NSMainMenuWindowLevel+1/*CGShieldingWindowLevel()*/];
887 NSRect screenframe = [[NSScreen mainScreen] frame];
888 NSRect frame = NSMakeRect (0, 0, 100, 100);
891 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
892 if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
893 [m_macWindow setStyleMask:data->m_formerStyleMask & ~ NSResizableWindowMask];
896 contentRect = [NSWindow contentRectForFrameRect: frame
897 styleMask: [m_macWindow styleMask]];
898 screenframe.origin.y += (frame.origin.y - contentRect.origin.y);
899 screenframe.size.height += (frame.size.height - contentRect.size.height);
900 [m_macWindow setFrame:screenframe display:YES];
902 SetSystemUIMode(kUIModeAllHidden,
903 kUIOptionDisableAppleMenu
905 | kUIOptionDisableProcessSwitch
906 | kUIOptionDisableForceQuit
909 else if ( m_macFullScreenData != NULL )
911 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
913 // CGDisplayRelease( kCGDirectMainDisplay );
914 // [m_macWindow setLevel:data->m_formerLevel];
917 [m_macWindow setFrame:data->m_formerFrame display:YES];
918 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
919 if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
920 [m_macWindow setStyleMask:data->m_formerStyleMask];
923 m_macFullScreenData = NULL ;
925 SetSystemUIMode(kUIModeNormal, 0);
931 void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX)
933 NSRequestUserAttentionType flagsOSX;
936 case wxUSER_ATTENTION_INFO:
937 flagsOSX = NSInformationalRequest;
940 case wxUSER_ATTENTION_ERROR:
941 flagsOSX = NSCriticalRequest;
945 wxFAIL_MSG( "invalid RequestUserAttention() flags" );
949 [NSApp requestUserAttention:flagsOSX];
952 void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
954 wxPoint p((x ? *x : 0), (y ? *y : 0) );
955 NSPoint nspt = wxToNSPoint( NULL, p );
956 nspt = [m_macWindow convertScreenToBase:nspt];
957 nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil];
958 p = wxFromNSPoint([m_macWindow contentView], nspt);
965 void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
967 wxPoint p((x ? *x : 0), (y ? *y : 0) );
968 NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p );
969 nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil];
970 nspt = [m_macWindow convertBaseToScreen:nspt];
971 p = wxFromNSPoint( NULL, nspt);
978 bool wxNonOwnedWindowCocoaImpl::IsActive()
980 return [m_macWindow isKeyWindow];
983 void wxNonOwnedWindowCocoaImpl::SetModified(bool modified)
985 [m_macWindow setDocumentEdited:modified];
988 bool wxNonOwnedWindowCocoaImpl::IsModified() const
990 return [m_macWindow isDocumentEdited];
993 void wxNonOwnedWindowCocoaImpl::SetRepresentedFilename(const wxString& filename)
995 [m_macWindow setRepresentedFilename:wxCFStringRef(filename).AsNSString()];
998 void wxNonOwnedWindowCocoaImpl::RestoreWindowLevel()
1000 if ( [m_macWindow level] != m_macWindowLevel )
1001 [m_macWindow setLevel:m_macWindowLevel];
1008 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
1010 wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
1011 now->Create( parent, nativeWindow );
1015 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
1016 long style, long extraStyle, const wxString& name )
1018 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
1019 now->Create( parent, pos, size, style , extraStyle, name );