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] )
270 [super sendEvent: event];
280 @interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>)
284 - (void)windowDidResize:(NSNotification *)notification;
285 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
286 - (void)windowDidResignKey:(NSNotification *)notification;
287 - (void)windowDidBecomeKey:(NSNotification *)notification;
288 - (void)windowDidMove:(NSNotification *)notification;
289 - (BOOL)windowShouldClose:(id)window;
290 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
294 extern int wxOSXGetIdFromSelector(SEL action );
296 @implementation wxNonOwnedWindowController
304 - (BOOL) triggerMenu:(SEL) action
306 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
310 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
311 if ( menu != NULL && menuitem != NULL)
312 return menu->HandleCommandProcess(menuitem);
317 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
319 SEL action = [menuItem action];
321 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
325 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
326 if ( menu != NULL && menuitem != NULL)
328 menu->HandleCommandUpdateStatus(menuitem);
329 return menuitem->IsEnabled();
335 - (void)undo:(id)sender
338 [self triggerMenu:_cmd];
341 - (void)redo:(id)sender
344 [self triggerMenu:_cmd];
347 - (void)cut:(id)sender
350 [self triggerMenu:_cmd];
353 - (void)copy:(id)sender
356 [self triggerMenu:_cmd];
359 - (void)paste:(id)sender
362 [self triggerMenu:_cmd];
365 - (void)delete:(id)sender
368 [self triggerMenu:_cmd];
371 - (void)selectAll:(id)sender
374 [self triggerMenu:_cmd];
377 - (BOOL)windowShouldClose:(id)nwindow
379 wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation];
382 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
389 - (NSSize)windowWillResize:(NSWindow *)window
390 toSize:(NSSize)proposedFrameSize
392 NSRect frame = [window frame];
393 wxRect wxframe = wxFromNSRect( NULL, frame );
394 wxframe.SetWidth( (int)proposedFrameSize.width );
395 wxframe.SetHeight( (int)proposedFrameSize.height );
397 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
400 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
403 wxpeer->HandleResizing( 0, &wxframe );
404 NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight());
409 return proposedFrameSize;
412 - (void)windowDidResize:(NSNotification *)notification
414 NSWindow* window = (NSWindow*) [notification object];
415 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
418 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
420 wxpeer->HandleResized(0);
424 - (void)windowDidMove:(NSNotification *)notification
426 wxNSWindow* window = (wxNSWindow*) [notification object];
427 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
430 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
432 wxpeer->HandleMoved(0);
436 - (void)windowDidBecomeKey:(NSNotification *)notification
438 NSWindow* window = (NSWindow*) [notification object];
439 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
442 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
444 wxpeer->HandleActivated(0, true);
448 - (void)windowDidResignKey:(NSNotification *)notification
450 NSWindow* window = (NSWindow*) [notification object];
451 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
454 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
457 wxpeer->HandleActivated(0, false);
458 // Needed for popup window since the firstResponder
459 // (focus in wx) doesn't change when this
460 // TLW becomes inactive.
461 wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
462 event.SetEventObject(wxpeer);
463 wxpeer->HandleWindowEvent(event);
468 - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
472 if ([anObject isKindOfClass:[wxNSTextField class]])
474 wxNSTextField* tf = (wxNSTextField*) anObject;
475 wxNSTextFieldEditor* editor = [tf fieldEditor];
478 editor = [[wxNSTextFieldEditor alloc] init];
479 [editor setFieldEditor:YES];
480 [tf setFieldEditor:editor];
489 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
491 wxUnusedVar(newFrame);
492 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
495 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
496 wxMaximizeEvent event(wxpeer->GetId());
497 event.SetEventObject(wxpeer);
498 return !wxpeer->HandleWindowEvent(event);
505 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
507 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
508 wxNonOwnedWindowImpl(nonownedwnd)
511 m_macFullScreenData = NULL;
514 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
517 m_macFullScreenData = NULL;
520 wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
522 if ( !m_wxPeer->IsNativeWindowWrapper() )
524 [m_macWindow setDelegate:nil];
525 [m_macWindow release];
529 void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
531 if ( !m_wxPeer->IsNativeWindowWrapper() )
533 [m_macWindow setDelegate:nil];
537 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
538 long style, long extraStyle, const wxString& WXUNUSED(name) )
540 static wxNonOwnedWindowController* controller = NULL;
543 controller =[[wxNonOwnedWindowController alloc] init];
546 int windowstyle = NSBorderlessWindowMask;
548 if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) ||
549 GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
551 m_macWindow = [wxNSPanel alloc];
554 m_macWindow = [wxNSWindow alloc];
556 CGWindowLevel level = kCGNormalWindowLevel;
558 if ( style & wxFRAME_TOOL_WINDOW )
560 windowstyle |= NSUtilityWindowMask;
562 else if ( ( style & wxPOPUP_WINDOW ) )
564 level = kCGPopUpMenuWindowLevel;
566 else if ( ( style & wxFRAME_DRAWER ) )
569 wclass = kDrawerWindowClass;
573 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
574 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) || ( style & wxCAPTION ) )
576 windowstyle |= NSTitledWindowMask ;
577 if ( ( style & wxMINIMIZE_BOX ) )
578 windowstyle |= NSMiniaturizableWindowMask ;
580 if ( ( style & wxMAXIMIZE_BOX ) )
581 windowstyle |= NSResizableWindowMask ;
583 if ( ( style & wxCLOSE_BOX) )
584 windowstyle |= NSClosableWindowMask ;
587 if ( ( style & wxRESIZE_BORDER ) )
588 windowstyle |= NSResizableWindowMask ;
590 if ( extraStyle & wxFRAME_EX_METAL)
591 windowstyle |= NSTexturedBackgroundWindowMask;
593 if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) )
594 level = kCGFloatingWindowLevel;
596 if ( ( style & wxSTAY_ON_TOP ) )
597 level = kCGUtilityWindowLevel;
599 NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
601 r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle];
603 [m_macWindow initWithContentRect:r
604 styleMask:windowstyle
605 backing:NSBackingStoreBuffered
609 // if we just have a title bar with no buttons needed, hide them
610 if ( (windowstyle & NSTitledWindowMask) &&
611 !(style & wxCLOSE_BOX) && !(style & wxMAXIMIZE_BOX) && !(style & wxMINIMIZE_BOX) )
613 [[m_macWindow standardWindowButton:NSWindowZoomButton] setHidden:YES];
614 [[m_macWindow standardWindowButton:NSWindowCloseButton] setHidden:YES];
615 [[m_macWindow standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
618 // If the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
619 // to be in kCGUtilityWindowLevel and not kCGFloatingWindowLevel to stay
621 wxDialog * const parentDialog = wxDynamicCast(parent, wxDialog);
622 if (parentDialog && parentDialog->IsModal())
624 if (level == kCGFloatingWindowLevel)
626 level = kCGUtilityWindowLevel;
629 // Cocoa's modal loop does not process other windows by default, but
630 // don't call this on normal window levels so nested modal dialogs will
631 // still behave modally.
632 if (level != kCGNormalWindowLevel)
634 if ([m_macWindow isKindOfClass:[NSPanel class]])
636 [(NSPanel*)m_macWindow setWorksWhenModal:YES];
641 [m_macWindow setLevel:level];
642 m_macWindowLevel = level;
644 [m_macWindow setDelegate:controller];
646 [m_macWindow setAcceptsMouseMovedEvents: YES];
648 if ( ( style & wxFRAME_SHAPED) )
650 [m_macWindow setOpaque:NO];
651 [m_macWindow setAlphaValue:1.0];
654 if ( !(style & wxFRAME_TOOL_WINDOW) )
655 [m_macWindow setHidesOnDeactivate:NO];
658 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
660 m_macWindow = nativeWindow;
663 WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
668 void wxNonOwnedWindowCocoaImpl::Raise()
670 [m_macWindow makeKeyAndOrderFront:nil];
673 void wxNonOwnedWindowCocoaImpl::Lower()
675 [m_macWindow orderWindow:NSWindowBelow relativeTo:0];
678 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
680 [m_macWindow orderFront:nil];
681 [[m_macWindow contentView] setNeedsDisplay: YES];
684 bool wxNonOwnedWindowCocoaImpl::Show(bool show)
688 wxNonOwnedWindow* wxpeer = GetWXPeer();
689 if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
690 [m_macWindow makeKeyAndOrderFront:nil];
692 [m_macWindow orderFront:nil];
693 [[m_macWindow contentView] setNeedsDisplay: YES];
696 [m_macWindow orderOut:nil];
700 bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show,
704 return wxWidgetCocoaImpl::
705 ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout);
708 void wxNonOwnedWindowCocoaImpl::Update()
710 [m_macWindow displayIfNeeded];
713 bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
715 [m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
719 bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& col )
721 [m_macWindow setBackgroundColor:[NSColor colorWithCalibratedRed:(CGFloat) (col.Red() / 255.0)
722 green:(CGFloat) (col.Green() / 255.0)
723 blue:(CGFloat) (col.Blue() / 255.0)
724 alpha:(CGFloat) (col.Alpha() / 255.0)]];
728 void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle )
732 bool metal = exStyle & wxFRAME_EX_METAL ;
733 int windowStyle = [ m_macWindow styleMask];
734 if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) )
736 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
738 else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) )
740 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
745 void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style )
749 CGWindowLevel level = kCGNormalWindowLevel;
751 if (style & wxSTAY_ON_TOP)
752 level = kCGUtilityWindowLevel;
753 else if (( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ))
754 level = kCGFloatingWindowLevel;
756 [m_macWindow setLevel: level];
757 m_macWindowLevel = level;
761 bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
763 if ( style == wxBG_STYLE_TRANSPARENT )
765 [m_macWindow setOpaque:NO];
766 [m_macWindow setBackgroundColor:[NSColor clearColor]];
772 bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
777 void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
779 NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
780 // do not trigger refreshes upon invisible and possible partly created objects
781 [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()];
784 void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
786 wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
791 void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
793 NSRect rect = [m_macWindow frame];
794 width = (int)rect.size.width;
795 height = (int)rect.size.height;
798 void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
800 NSRect rect = [[m_macWindow contentView] frame];
801 left = (int)rect.origin.x;
802 top = (int)rect.origin.y;
803 width = (int)rect.size.width;
804 height = (int)rect.size.height;
807 bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
809 [m_macWindow setOpaque:NO];
810 [m_macWindow setBackgroundColor:[NSColor clearColor]];
815 void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
817 [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
820 bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
822 if (([m_macWindow styleMask] & NSResizableWindowMask) != 0)
824 return [m_macWindow isZoomed];
828 NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
829 NSRect rectWindow = [m_macWindow frame];
830 return (rectScreen.origin.x == rectWindow.origin.x &&
831 rectScreen.origin.y == rectWindow.origin.y &&
832 rectScreen.size.width == rectWindow.size.width &&
833 rectScreen.size.height == rectWindow.size.height);
837 bool wxNonOwnedWindowCocoaImpl::IsIconized() const
839 return [m_macWindow isMiniaturized];
842 void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
845 [m_macWindow miniaturize:nil];
847 [m_macWindow deminiaturize:nil];
850 void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize))
852 [m_macWindow zoom:nil];
856 // http://cocoadevcentral.com/articles/000028.php
860 NSUInteger m_formerStyleMask;
862 NSRect m_formerFrame;
865 bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
867 return m_macFullScreenData != NULL ;
870 bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
874 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
876 data = new FullScreenData();
878 m_macFullScreenData = data ;
879 data->m_formerLevel = [m_macWindow level];
880 data->m_formerFrame = [m_macWindow frame];
881 data->m_formerStyleMask = [m_macWindow styleMask];
883 // CGDisplayCapture( kCGDirectMainDisplay );
884 //[m_macWindow setLevel:NSMainMenuWindowLevel+1/*CGShieldingWindowLevel()*/];
886 NSRect screenframe = [[NSScreen mainScreen] frame];
887 NSRect frame = NSMakeRect (0, 0, 100, 100);
890 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
891 if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
892 [m_macWindow setStyleMask:data->m_formerStyleMask & ~ NSResizableWindowMask];
895 contentRect = [NSWindow contentRectForFrameRect: frame
896 styleMask: [m_macWindow styleMask]];
897 screenframe.origin.y += (frame.origin.y - contentRect.origin.y);
898 screenframe.size.height += (frame.size.height - contentRect.size.height);
899 [m_macWindow setFrame:screenframe display:YES];
901 SetSystemUIMode(kUIModeAllHidden,
902 kUIOptionDisableAppleMenu
904 | kUIOptionDisableProcessSwitch
905 | kUIOptionDisableForceQuit
908 else if ( m_macFullScreenData != NULL )
910 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
912 // CGDisplayRelease( kCGDirectMainDisplay );
913 // [m_macWindow setLevel:data->m_formerLevel];
916 [m_macWindow setFrame:data->m_formerFrame display:YES];
917 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
918 if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
919 [m_macWindow setStyleMask:data->m_formerStyleMask];
922 m_macFullScreenData = NULL ;
924 SetSystemUIMode(kUIModeNormal, 0);
930 void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX)
932 NSRequestUserAttentionType flagsOSX;
935 case wxUSER_ATTENTION_INFO:
936 flagsOSX = NSInformationalRequest;
939 case wxUSER_ATTENTION_ERROR:
940 flagsOSX = NSCriticalRequest;
944 wxFAIL_MSG( "invalid RequestUserAttention() flags" );
948 [NSApp requestUserAttention:flagsOSX];
951 void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
953 wxPoint p((x ? *x : 0), (y ? *y : 0) );
954 NSPoint nspt = wxToNSPoint( NULL, p );
955 nspt = [m_macWindow convertScreenToBase:nspt];
956 nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil];
957 p = wxFromNSPoint([m_macWindow contentView], nspt);
964 void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
966 wxPoint p((x ? *x : 0), (y ? *y : 0) );
967 NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p );
968 nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil];
969 nspt = [m_macWindow convertBaseToScreen:nspt];
970 p = wxFromNSPoint( NULL, nspt);
977 bool wxNonOwnedWindowCocoaImpl::IsActive()
979 return [m_macWindow isKeyWindow];
982 void wxNonOwnedWindowCocoaImpl::SetModified(bool modified)
984 [m_macWindow setDocumentEdited:modified];
987 bool wxNonOwnedWindowCocoaImpl::IsModified() const
989 return [m_macWindow isDocumentEdited];
992 void wxNonOwnedWindowCocoaImpl::SetRepresentedFilename(const wxString& filename)
994 [m_macWindow setRepresentedFilename:wxCFStringRef(filename).AsNSString()];
997 void wxNonOwnedWindowCocoaImpl::RestoreWindowLevel()
999 if ( [m_macWindow level] != m_macWindowLevel )
1000 [m_macWindow setLevel:m_macWindowLevel];
1007 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
1009 wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
1010 now->Create( parent, nativeWindow );
1014 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
1015 long style, long extraStyle, const wxString& name )
1017 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
1018 now->Create( parent, pos, size, style , extraStyle, name );