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 WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
124 WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
126 wxWindow* cw = wxWindow::GetCapture();
130 wxTheApp->MacSetCurrentEvent(event, NULL);
131 ((wxWidgetCocoaImpl*)cw->GetPeer())->DoHandleMouseEvent( event);
134 else if ( [event type] == NSMouseMoved )
136 NSPoint nsPoint = [event locationInWindow];
137 if ( [event window] != nil )
138 nsPoint = [[event window] convertBaseToScreen:nsPoint];
140 wxPoint pt = wxFromNSPoint(NULL, nsPoint);
141 wxWindow* mw = ::wxFindWindowAtPoint(pt);
145 wxTheApp->MacSetCurrentEvent(event, NULL);
146 ((wxWidgetCocoaImpl*)mw->GetPeer())->DoHandleMouseEvent( event);
153 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
161 // wx native implementation
164 @interface wxNSWindow : NSWindow
168 - (void) sendEvent:(NSEvent *)event;
169 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
170 - (void)noResponderFor: (SEL) selector;
173 @implementation wxNSWindow
175 - (void)sendEvent:(NSEvent *) event
177 if ( ![self WX_filterSendEvent: event] )
179 WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
180 WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
183 wxTheApp->MacSetCurrentEvent(event, NULL);
185 [super sendEvent: event];
188 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
192 // The default implementation always moves the window back onto the screen,
193 // even when the programmer explicitly wants to hide it.
194 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
200 - (void)doCommandBySelector:(SEL)selector
202 if (shouldHandleSelector(selector) &&
203 !(selector == @selector(cancel:) || selector == @selector(cancelOperation:)) )
204 [super doCommandBySelector:selector];
208 // NB: if we don't do this, all key downs that get handled lead to a NSBeep
209 - (void)noResponderFor: (SEL) selector
211 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
213 [super noResponderFor:selector];
217 // We need this for borderless windows, i.e. shaped windows or windows without
218 // a title bar. For more info, see:
219 // http://lists.apple.com/archives/cocoa-dev/2008/May/msg02091.html
220 - (BOOL)canBecomeKeyWindow
227 @interface wxNSPanel : NSPanel
231 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
232 - (void)noResponderFor: (SEL) selector;
233 - (void)sendEvent:(NSEvent *)event;
236 @implementation wxNSPanel
238 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
240 wxNonOwnedWindowCocoaImpl* impl = (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
241 if (impl && impl->IsFullScreen())
244 return [super constrainFrameRect:frameRect toScreen:screen];
247 - (BOOL)canBecomeKeyWindow
252 - (void)doCommandBySelector:(SEL)selector
254 if (shouldHandleSelector(selector))
255 [super doCommandBySelector:selector];
258 // NB: if we don't do this, it seems that all events that end here lead to a NSBeep
259 - (void)noResponderFor: (SEL) selector
261 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
263 [super noResponderFor:selector];
267 - (void)sendEvent:(NSEvent *) event
269 if ( ![self WX_filterSendEvent: event] )
271 WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
272 WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
275 wxTheApp->MacSetCurrentEvent(event, NULL);
277 [super sendEvent: event];
280 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
291 @interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>)
295 - (void)windowDidResize:(NSNotification *)notification;
296 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
297 - (void)windowDidResignKey:(NSNotification *)notification;
298 - (void)windowDidBecomeKey:(NSNotification *)notification;
299 - (void)windowDidMove:(NSNotification *)notification;
300 - (BOOL)windowShouldClose:(id)window;
301 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
305 extern int wxOSXGetIdFromSelector(SEL action );
307 @implementation wxNonOwnedWindowController
315 - (BOOL) triggerMenu:(SEL) action
317 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
321 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
322 if ( menu != NULL && menuitem != NULL)
323 return menu->HandleCommandProcess(menuitem);
328 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
330 SEL action = [menuItem action];
332 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
336 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
337 if ( menu != NULL && menuitem != NULL)
339 menu->HandleCommandUpdateStatus(menuitem);
340 return menuitem->IsEnabled();
346 - (void)undo:(id)sender
349 [self triggerMenu:_cmd];
352 - (void)redo:(id)sender
355 [self triggerMenu:_cmd];
358 - (void)cut:(id)sender
361 [self triggerMenu:_cmd];
364 - (void)copy:(id)sender
367 [self triggerMenu:_cmd];
370 - (void)paste:(id)sender
373 [self triggerMenu:_cmd];
376 - (void)delete:(id)sender
379 [self triggerMenu:_cmd];
382 - (void)selectAll:(id)sender
385 [self triggerMenu:_cmd];
388 - (BOOL)windowShouldClose:(id)nwindow
390 wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation];
393 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
400 - (NSSize)windowWillResize:(NSWindow *)window
401 toSize:(NSSize)proposedFrameSize
403 NSRect frame = [window frame];
404 wxRect wxframe = wxFromNSRect( NULL, frame );
405 wxframe.SetWidth( (int)proposedFrameSize.width );
406 wxframe.SetHeight( (int)proposedFrameSize.height );
408 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
411 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
414 wxpeer->HandleResizing( 0, &wxframe );
415 NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight());
420 return proposedFrameSize;
423 - (void)windowDidResize:(NSNotification *)notification
425 NSWindow* window = (NSWindow*) [notification object];
426 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
429 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
431 wxpeer->HandleResized(0);
435 - (void)windowDidMove:(NSNotification *)notification
437 wxNSWindow* window = (wxNSWindow*) [notification object];
438 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
441 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
443 wxpeer->HandleMoved(0);
447 - (void)windowDidBecomeKey:(NSNotification *)notification
449 NSWindow* window = (NSWindow*) [notification object];
450 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
453 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
455 wxpeer->HandleActivated(0, true);
459 - (void)windowDidResignKey:(NSNotification *)notification
461 NSWindow* window = (NSWindow*) [notification object];
462 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
465 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
468 wxpeer->HandleActivated(0, false);
469 // Needed for popup window since the firstResponder
470 // (focus in wx) doesn't change when this
471 // TLW becomes inactive.
472 wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
473 event.SetEventObject(wxpeer);
474 wxpeer->HandleWindowEvent(event);
479 - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
483 if ([anObject isKindOfClass:[wxNSTextField class]])
485 wxNSTextField* tf = (wxNSTextField*) anObject;
486 wxNSTextFieldEditor* editor = [tf fieldEditor];
489 editor = [[wxNSTextFieldEditor alloc] init];
490 [editor setFieldEditor:YES];
491 [tf setFieldEditor:editor];
500 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
502 wxUnusedVar(newFrame);
503 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
506 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
507 wxMaximizeEvent event(wxpeer->GetId());
508 event.SetEventObject(wxpeer);
509 return !wxpeer->HandleWindowEvent(event);
516 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
518 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
519 wxNonOwnedWindowImpl(nonownedwnd)
522 m_macFullScreenData = NULL;
525 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
528 m_macFullScreenData = NULL;
531 wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
533 if ( !m_wxPeer->IsNativeWindowWrapper() )
535 [m_macWindow setDelegate:nil];
536 [m_macWindow release];
540 void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
542 if ( !m_wxPeer->IsNativeWindowWrapper() )
544 [m_macWindow setDelegate:nil];
548 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
549 long style, long extraStyle, const wxString& WXUNUSED(name) )
551 static wxNonOwnedWindowController* controller = NULL;
554 controller =[[wxNonOwnedWindowController alloc] init];
557 int windowstyle = NSBorderlessWindowMask;
559 if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) ||
560 GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
562 m_macWindow = [wxNSPanel alloc];
565 m_macWindow = [wxNSWindow alloc];
567 CGWindowLevel level = kCGNormalWindowLevel;
569 if ( style & wxFRAME_TOOL_WINDOW )
571 windowstyle |= NSUtilityWindowMask;
573 else if ( ( style & wxPOPUP_WINDOW ) )
575 level = kCGPopUpMenuWindowLevel;
577 else if ( ( style & wxFRAME_DRAWER ) )
580 wclass = kDrawerWindowClass;
584 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
585 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) || ( style & wxCAPTION ) )
587 windowstyle |= NSTitledWindowMask ;
588 if ( ( style & wxMINIMIZE_BOX ) )
589 windowstyle |= NSMiniaturizableWindowMask ;
591 if ( ( style & wxMAXIMIZE_BOX ) )
592 windowstyle |= NSResizableWindowMask ;
594 if ( ( style & wxCLOSE_BOX) )
595 windowstyle |= NSClosableWindowMask ;
598 if ( ( style & wxRESIZE_BORDER ) )
599 windowstyle |= NSResizableWindowMask ;
601 if ( extraStyle & wxFRAME_EX_METAL)
602 windowstyle |= NSTexturedBackgroundWindowMask;
604 if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) )
605 level = kCGFloatingWindowLevel;
607 if ( ( style & wxSTAY_ON_TOP ) )
608 level = kCGUtilityWindowLevel;
610 NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
612 r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle];
614 [m_macWindow initWithContentRect:r
615 styleMask:windowstyle
616 backing:NSBackingStoreBuffered
620 // if we just have a title bar with no buttons needed, hide them
621 if ( (windowstyle & NSTitledWindowMask) &&
622 !(style & wxCLOSE_BOX) && !(style & wxMAXIMIZE_BOX) && !(style & wxMINIMIZE_BOX) )
624 [[m_macWindow standardWindowButton:NSWindowZoomButton] setHidden:YES];
625 [[m_macWindow standardWindowButton:NSWindowCloseButton] setHidden:YES];
626 [[m_macWindow standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
629 // If the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
630 // to be in kCGUtilityWindowLevel and not kCGFloatingWindowLevel to stay
632 wxDialog * const parentDialog = wxDynamicCast(parent, wxDialog);
633 if (parentDialog && parentDialog->IsModal())
635 if (level == kCGFloatingWindowLevel)
637 level = kCGUtilityWindowLevel;
640 // Cocoa's modal loop does not process other windows by default, but
641 // don't call this on normal window levels so nested modal dialogs will
642 // still behave modally.
643 if (level != kCGNormalWindowLevel)
645 if ([m_macWindow isKindOfClass:[NSPanel class]])
647 [(NSPanel*)m_macWindow setWorksWhenModal:YES];
652 [m_macWindow setLevel:level];
653 m_macWindowLevel = level;
655 [m_macWindow setDelegate:controller];
657 [m_macWindow setAcceptsMouseMovedEvents: YES];
659 if ( ( style & wxFRAME_SHAPED) )
661 [m_macWindow setOpaque:NO];
662 [m_macWindow setAlphaValue:1.0];
665 if ( !(style & wxFRAME_TOOL_WINDOW) )
666 [m_macWindow setHidesOnDeactivate:NO];
669 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
671 m_macWindow = nativeWindow;
674 WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
679 void wxNonOwnedWindowCocoaImpl::Raise()
681 [m_macWindow makeKeyAndOrderFront:nil];
684 void wxNonOwnedWindowCocoaImpl::Lower()
686 [m_macWindow orderWindow:NSWindowBelow relativeTo:0];
689 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
691 [m_macWindow orderFront:nil];
692 [[m_macWindow contentView] setNeedsDisplay: YES];
695 bool wxNonOwnedWindowCocoaImpl::Show(bool show)
699 wxNonOwnedWindow* wxpeer = GetWXPeer();
700 if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
701 [m_macWindow makeKeyAndOrderFront:nil];
703 [m_macWindow orderFront:nil];
704 [[m_macWindow contentView] setNeedsDisplay: YES];
707 [m_macWindow orderOut:nil];
711 bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show,
715 return wxWidgetCocoaImpl::
716 ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout);
719 void wxNonOwnedWindowCocoaImpl::Update()
721 [m_macWindow displayIfNeeded];
724 bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
726 [m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
730 bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& col )
732 [m_macWindow setBackgroundColor:[NSColor colorWithCalibratedRed:(CGFloat) (col.Red() / 255.0)
733 green:(CGFloat) (col.Green() / 255.0)
734 blue:(CGFloat) (col.Blue() / 255.0)
735 alpha:(CGFloat) (col.Alpha() / 255.0)]];
739 void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle )
743 bool metal = exStyle & wxFRAME_EX_METAL ;
744 int windowStyle = [ m_macWindow styleMask];
745 if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) )
747 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
749 else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) )
751 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
756 void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style )
760 CGWindowLevel level = kCGNormalWindowLevel;
762 if (style & wxSTAY_ON_TOP)
763 level = kCGUtilityWindowLevel;
764 else if (( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ))
765 level = kCGFloatingWindowLevel;
767 [m_macWindow setLevel: level];
768 m_macWindowLevel = level;
772 bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
774 if ( style == wxBG_STYLE_TRANSPARENT )
776 [m_macWindow setOpaque:NO];
777 [m_macWindow setBackgroundColor:[NSColor clearColor]];
783 bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
788 void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
790 NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
791 // do not trigger refreshes upon invisible and possible partly created objects
792 [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()];
795 void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
797 wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
802 void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
804 NSRect rect = [m_macWindow frame];
805 width = (int)rect.size.width;
806 height = (int)rect.size.height;
809 void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
811 NSRect rect = [[m_macWindow contentView] frame];
812 left = (int)rect.origin.x;
813 top = (int)rect.origin.y;
814 width = (int)rect.size.width;
815 height = (int)rect.size.height;
818 bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
820 [m_macWindow setOpaque:NO];
821 [m_macWindow setBackgroundColor:[NSColor clearColor]];
826 void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
828 [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
831 bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
833 if (([m_macWindow styleMask] & NSResizableWindowMask) != 0)
835 return [m_macWindow isZoomed];
839 NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
840 NSRect rectWindow = [m_macWindow frame];
841 return (rectScreen.origin.x == rectWindow.origin.x &&
842 rectScreen.origin.y == rectWindow.origin.y &&
843 rectScreen.size.width == rectWindow.size.width &&
844 rectScreen.size.height == rectWindow.size.height);
848 bool wxNonOwnedWindowCocoaImpl::IsIconized() const
850 return [m_macWindow isMiniaturized];
853 void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
856 [m_macWindow miniaturize:nil];
858 [m_macWindow deminiaturize:nil];
861 void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize))
863 [m_macWindow zoom:nil];
867 // http://cocoadevcentral.com/articles/000028.php
871 NSUInteger m_formerStyleMask;
873 NSRect m_formerFrame;
876 bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
878 return m_macFullScreenData != NULL ;
881 bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
885 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
887 data = new FullScreenData();
889 m_macFullScreenData = data ;
890 data->m_formerLevel = [m_macWindow level];
891 data->m_formerFrame = [m_macWindow frame];
892 data->m_formerStyleMask = [m_macWindow styleMask];
894 // CGDisplayCapture( kCGDirectMainDisplay );
895 //[m_macWindow setLevel:NSMainMenuWindowLevel+1/*CGShieldingWindowLevel()*/];
897 NSRect screenframe = [[NSScreen mainScreen] frame];
898 NSRect frame = NSMakeRect (0, 0, 100, 100);
901 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
902 if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
903 [m_macWindow setStyleMask:data->m_formerStyleMask & ~ NSResizableWindowMask];
906 contentRect = [NSWindow contentRectForFrameRect: frame
907 styleMask: [m_macWindow styleMask]];
908 screenframe.origin.y += (frame.origin.y - contentRect.origin.y);
909 screenframe.size.height += (frame.size.height - contentRect.size.height);
910 [m_macWindow setFrame:screenframe display:YES];
912 SetSystemUIMode(kUIModeAllHidden,
913 kUIOptionDisableAppleMenu
915 | kUIOptionDisableProcessSwitch
916 | kUIOptionDisableForceQuit
919 else if ( m_macFullScreenData != NULL )
921 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
923 // CGDisplayRelease( kCGDirectMainDisplay );
924 // [m_macWindow setLevel:data->m_formerLevel];
927 [m_macWindow setFrame:data->m_formerFrame display:YES];
928 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
929 if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
930 [m_macWindow setStyleMask:data->m_formerStyleMask];
933 m_macFullScreenData = NULL ;
935 SetSystemUIMode(kUIModeNormal, 0);
941 void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX)
943 NSRequestUserAttentionType flagsOSX;
946 case wxUSER_ATTENTION_INFO:
947 flagsOSX = NSInformationalRequest;
950 case wxUSER_ATTENTION_ERROR:
951 flagsOSX = NSCriticalRequest;
955 wxFAIL_MSG( "invalid RequestUserAttention() flags" );
959 [NSApp requestUserAttention:flagsOSX];
962 void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
964 wxPoint p((x ? *x : 0), (y ? *y : 0) );
965 NSPoint nspt = wxToNSPoint( NULL, p );
966 nspt = [m_macWindow convertScreenToBase:nspt];
967 nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil];
968 p = wxFromNSPoint([m_macWindow contentView], nspt);
975 void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
977 wxPoint p((x ? *x : 0), (y ? *y : 0) );
978 NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p );
979 nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil];
980 nspt = [m_macWindow convertBaseToScreen:nspt];
981 p = wxFromNSPoint( NULL, nspt);
988 bool wxNonOwnedWindowCocoaImpl::IsActive()
990 return [m_macWindow isKeyWindow];
993 void wxNonOwnedWindowCocoaImpl::SetModified(bool modified)
995 [m_macWindow setDocumentEdited:modified];
998 bool wxNonOwnedWindowCocoaImpl::IsModified() const
1000 return [m_macWindow isDocumentEdited];
1003 void wxNonOwnedWindowCocoaImpl::SetRepresentedFilename(const wxString& filename)
1005 [m_macWindow setRepresentedFilename:wxCFStringRef(filename).AsNSString()];
1008 void wxNonOwnedWindowCocoaImpl::RestoreWindowLevel()
1010 if ( [m_macWindow level] != m_macWindowLevel )
1011 [m_macWindow setLevel:m_macWindowLevel];
1018 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
1020 wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
1021 now->Create( parent, nativeWindow );
1025 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
1026 long style, long extraStyle, const wxString& name )
1028 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
1029 now->Create( parent, pos, size, style , extraStyle, name );