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 occurred,
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);
137 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
145 // wx native implementation
148 @interface wxNSWindow : NSWindow
152 - (void) sendEvent:(NSEvent *)event;
153 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
154 - (void)noResponderFor: (SEL) selector;
157 @implementation wxNSWindow
159 - (void)sendEvent:(NSEvent *) event
161 if ( ![self WX_filterSendEvent: event] )
163 WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
164 WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
167 wxTheApp->MacSetCurrentEvent(event, NULL);
169 [super sendEvent: event];
172 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
176 // The default implementation always moves the window back onto the screen,
177 // even when the programmer explicitly wants to hide it.
178 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
184 - (void)doCommandBySelector:(SEL)selector
186 if (shouldHandleSelector(selector) &&
187 !(selector == @selector(cancel:) || selector == @selector(cancelOperation:)) )
188 [super doCommandBySelector:selector];
192 // NB: if we don't do this, all key downs that get handled lead to a NSBeep
193 - (void)noResponderFor: (SEL) selector
195 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
197 [super noResponderFor:selector];
201 // We need this for borderless windows, i.e. shaped windows or windows without
202 // a title bar. For more info, see:
203 // http://lists.apple.com/archives/cocoa-dev/2008/May/msg02091.html
204 - (BOOL)canBecomeKeyWindow
211 @interface wxNSPanel : NSPanel
215 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
216 - (void)noResponderFor: (SEL) selector;
217 - (void)sendEvent:(NSEvent *)event;
220 @implementation wxNSPanel
222 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
224 wxNonOwnedWindowCocoaImpl* impl = (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
225 if (impl && impl->IsFullScreen())
228 return [super constrainFrameRect:frameRect toScreen:screen];
231 - (BOOL)canBecomeKeyWindow
236 - (void)doCommandBySelector:(SEL)selector
238 if (shouldHandleSelector(selector))
239 [super doCommandBySelector:selector];
242 // NB: if we don't do this, it seems that all events that end here lead to a NSBeep
243 - (void)noResponderFor: (SEL) selector
245 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
247 [super noResponderFor:selector];
251 - (void)sendEvent:(NSEvent *) event
253 if ( ![self WX_filterSendEvent: event] )
255 WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
256 WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
259 wxTheApp->MacSetCurrentEvent(event, NULL);
261 [super sendEvent: event];
264 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
275 @interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>)
279 - (void)windowDidResize:(NSNotification *)notification;
280 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
281 - (void)windowDidResignKey:(NSNotification *)notification;
282 - (void)windowDidBecomeKey:(NSNotification *)notification;
283 - (void)windowDidMove:(NSNotification *)notification;
284 - (BOOL)windowShouldClose:(id)window;
285 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
289 extern int wxOSXGetIdFromSelector(SEL action );
291 @implementation wxNonOwnedWindowController
299 - (BOOL) triggerMenu:(SEL) action
301 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
305 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
306 if ( menu != NULL && menuitem != NULL)
307 return menu->HandleCommandProcess(menuitem);
312 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
314 SEL action = [menuItem action];
316 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
320 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
321 if ( menu != NULL && menuitem != NULL)
323 menu->HandleCommandUpdateStatus(menuitem);
324 return menuitem->IsEnabled();
330 - (void)undo:(id)sender
333 [self triggerMenu:_cmd];
336 - (void)redo:(id)sender
339 [self triggerMenu:_cmd];
342 - (void)cut:(id)sender
345 [self triggerMenu:_cmd];
348 - (void)copy:(id)sender
351 [self triggerMenu:_cmd];
354 - (void)paste:(id)sender
357 [self triggerMenu:_cmd];
360 - (void)delete:(id)sender
363 [self triggerMenu:_cmd];
366 - (void)selectAll:(id)sender
369 [self triggerMenu:_cmd];
372 - (BOOL)windowShouldClose:(id)nwindow
374 wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation];
377 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
384 - (NSSize)windowWillResize:(NSWindow *)window
385 toSize:(NSSize)proposedFrameSize
387 NSRect frame = [window frame];
388 wxRect wxframe = wxFromNSRect( NULL, frame );
389 wxframe.SetWidth( (int)proposedFrameSize.width );
390 wxframe.SetHeight( (int)proposedFrameSize.height );
392 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
395 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
398 wxpeer->HandleResizing( 0, &wxframe );
399 NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight());
404 return proposedFrameSize;
407 - (void)windowDidResize:(NSNotification *)notification
409 NSWindow* window = (NSWindow*) [notification object];
410 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
413 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
415 wxpeer->HandleResized(0);
419 - (void)windowDidMove:(NSNotification *)notification
421 wxNSWindow* window = (wxNSWindow*) [notification object];
422 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
425 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
427 wxpeer->HandleMoved(0);
431 - (void)windowDidBecomeKey:(NSNotification *)notification
433 NSWindow* window = (NSWindow*) [notification object];
434 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
437 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
439 wxpeer->HandleActivated(0, true);
443 - (void)windowDidResignKey:(NSNotification *)notification
445 NSWindow* window = (NSWindow*) [notification object];
446 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
449 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
452 wxpeer->HandleActivated(0, false);
453 // as for wx the deactivation also means losing focus we
454 // must trigger this manually
455 [window makeFirstResponder:nil];
457 // TODO Remove if no problems arise with Popup Windows
459 // Needed for popup window since the firstResponder
460 // (focus in wx) doesn't change when this
461 // TLW becomes inactive.
462 wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
463 event.SetEventObject(wxpeer);
464 wxpeer->HandleWindowEvent(event);
470 - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
474 if ([anObject isKindOfClass:[wxNSTextField class]])
476 wxNSTextField* tf = (wxNSTextField*) anObject;
477 wxNSTextFieldEditor* editor = [tf fieldEditor];
480 editor = [[wxNSTextFieldEditor alloc] init];
481 [editor setFieldEditor:YES];
482 [tf setFieldEditor:editor];
487 else if ([anObject isKindOfClass:[wxNSComboBox class]])
489 wxNSComboBox * cb = (wxNSComboBox*) anObject;
490 wxNSTextFieldEditor* editor = [cb fieldEditor];
493 editor = [[wxNSTextFieldEditor alloc] init];
494 [editor setFieldEditor:YES];
495 [cb setFieldEditor:editor];
504 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
506 wxUnusedVar(newFrame);
507 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
510 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
511 wxMaximizeEvent event(wxpeer->GetId());
512 event.SetEventObject(wxpeer);
513 return !wxpeer->HandleWindowEvent(event);
520 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
522 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
523 wxNonOwnedWindowImpl(nonownedwnd)
526 m_macFullScreenData = NULL;
529 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
532 m_macFullScreenData = NULL;
535 wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
537 if ( !m_wxPeer->IsNativeWindowWrapper() )
539 [m_macWindow setDelegate:nil];
541 // make sure we remove this first, otherwise the ref count will not lead to the
542 // native window's destruction
543 if ([m_macWindow parentWindow] != 0)
544 [[m_macWindow parentWindow] removeChildWindow: m_macWindow];
546 [m_macWindow release];
550 void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
552 if ( !m_wxPeer->IsNativeWindowWrapper() )
554 [m_macWindow setDelegate:nil];
558 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
559 long style, long extraStyle, const wxString& WXUNUSED(name) )
561 static wxNonOwnedWindowController* controller = NULL;
564 controller =[[wxNonOwnedWindowController alloc] init];
567 int windowstyle = NSBorderlessWindowMask;
569 if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) ||
570 GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
572 m_macWindow = [wxNSPanel alloc];
575 m_macWindow = [wxNSWindow alloc];
577 CGWindowLevel level = kCGNormalWindowLevel;
579 if ( style & wxFRAME_TOOL_WINDOW )
581 windowstyle |= NSUtilityWindowMask;
583 else if ( ( style & wxPOPUP_WINDOW ) )
585 level = kCGPopUpMenuWindowLevel;
587 else if ( ( style & wxFRAME_DRAWER ) )
590 wclass = kDrawerWindowClass;
594 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
595 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) || ( style & wxCAPTION ) )
597 windowstyle |= NSTitledWindowMask ;
598 if ( ( style & wxMINIMIZE_BOX ) )
599 windowstyle |= NSMiniaturizableWindowMask ;
601 if ( ( style & wxMAXIMIZE_BOX ) )
602 windowstyle |= NSResizableWindowMask ;
604 if ( ( style & wxCLOSE_BOX) )
605 windowstyle |= NSClosableWindowMask ;
608 if ( ( style & wxRESIZE_BORDER ) )
609 windowstyle |= NSResizableWindowMask ;
611 if ( extraStyle & wxFRAME_EX_METAL)
612 windowstyle |= NSTexturedBackgroundWindowMask;
614 if ( ( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ) )
615 level = kCGFloatingWindowLevel;
617 if ( ( style & wxSTAY_ON_TOP ) )
618 level = kCGUtilityWindowLevel;
620 NSRect r = wxToNSRect( NULL, wxRect( pos, size) );
622 r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle];
624 [m_macWindow initWithContentRect:r
625 styleMask:windowstyle
626 backing:NSBackingStoreBuffered
630 // if we just have a title bar with no buttons needed, hide them
631 if ( (windowstyle & NSTitledWindowMask) &&
632 !(style & wxCLOSE_BOX) && !(style & wxMAXIMIZE_BOX) && !(style & wxMINIMIZE_BOX) )
634 [[m_macWindow standardWindowButton:NSWindowZoomButton] setHidden:YES];
635 [[m_macWindow standardWindowButton:NSWindowCloseButton] setHidden:YES];
636 [[m_macWindow standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
639 // If the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
640 // to be in kCGUtilityWindowLevel and not kCGFloatingWindowLevel to stay
642 wxDialog * const parentDialog = wxDynamicCast(parent, wxDialog);
643 if (parentDialog && parentDialog->IsModal())
645 if (level == kCGFloatingWindowLevel)
647 level = kCGUtilityWindowLevel;
650 // Cocoa's modal loop does not process other windows by default, but
651 // don't call this on normal window levels so nested modal dialogs will
652 // still behave modally.
653 if (level != kCGNormalWindowLevel)
655 if ([m_macWindow isKindOfClass:[NSPanel class]])
657 [(NSPanel*)m_macWindow setWorksWhenModal:YES];
662 [m_macWindow setLevel:level];
663 m_macWindowLevel = level;
665 [m_macWindow setDelegate:controller];
667 if ( ( style & wxFRAME_SHAPED) )
669 [m_macWindow setOpaque:NO];
670 [m_macWindow setAlphaValue:1.0];
673 if ( !(style & wxFRAME_TOOL_WINDOW) )
674 [m_macWindow setHidesOnDeactivate:NO];
677 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
679 m_macWindow = nativeWindow;
682 WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
687 void wxNonOwnedWindowCocoaImpl::Raise()
689 [m_macWindow makeKeyAndOrderFront:nil];
692 void wxNonOwnedWindowCocoaImpl::Lower()
694 [m_macWindow orderWindow:NSWindowBelow relativeTo:0];
697 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
699 [m_macWindow orderFront:nil];
700 [[m_macWindow contentView] setNeedsDisplay: YES];
703 bool wxNonOwnedWindowCocoaImpl::Show(bool show)
707 wxNonOwnedWindow* wxpeer = GetWXPeer();
710 // add to parent window before showing
711 wxDialog * const dialog = wxDynamicCast(wxpeer, wxDialog);
712 if ( wxpeer->GetParent() && dialog && dialog->IsModal())
714 NSView * parentView = wxpeer->GetParent()->GetPeer()->GetWXWidget();
717 NSWindow* parentNSWindow = [parentView window];
718 if ( parentNSWindow )
719 [parentNSWindow addChildWindow:m_macWindow ordered:NSWindowAbove];
723 if (!(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
724 [m_macWindow makeKeyAndOrderFront:nil];
726 [m_macWindow orderFront:nil];
728 [[m_macWindow contentView] setNeedsDisplay: YES];
732 // avoid propagation of orderOut to parent
733 if ([m_macWindow parentWindow] != 0)
734 [[m_macWindow parentWindow] removeChildWindow: m_macWindow];
735 [m_macWindow orderOut:nil];
740 bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show,
744 return wxWidgetCocoaImpl::
745 ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout);
748 void wxNonOwnedWindowCocoaImpl::Update()
750 [m_macWindow displayIfNeeded];
753 bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
755 [m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
759 bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& col )
761 [m_macWindow setBackgroundColor:[NSColor colorWithCalibratedRed:(CGFloat) (col.Red() / 255.0)
762 green:(CGFloat) (col.Green() / 255.0)
763 blue:(CGFloat) (col.Blue() / 255.0)
764 alpha:(CGFloat) (col.Alpha() / 255.0)]];
768 void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle )
772 bool metal = exStyle & wxFRAME_EX_METAL ;
773 int windowStyle = [ m_macWindow styleMask];
774 if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) )
776 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
778 else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) )
780 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
785 void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style )
789 CGWindowLevel level = kCGNormalWindowLevel;
791 if (style & wxSTAY_ON_TOP)
792 level = kCGUtilityWindowLevel;
793 else if (( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ))
794 level = kCGFloatingWindowLevel;
796 [m_macWindow setLevel: level];
797 m_macWindowLevel = level;
801 bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
803 if ( style == wxBG_STYLE_TRANSPARENT )
805 [m_macWindow setOpaque:NO];
806 [m_macWindow setBackgroundColor:[NSColor clearColor]];
812 bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
817 void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
819 NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
820 // do not trigger refreshes upon invisible and possible partly created objects
821 [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()];
824 void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
826 wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
831 void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
833 NSRect rect = [m_macWindow frame];
834 width = (int)rect.size.width;
835 height = (int)rect.size.height;
838 void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
840 NSRect rect = [[m_macWindow contentView] frame];
841 left = (int)rect.origin.x;
842 top = (int)rect.origin.y;
843 width = (int)rect.size.width;
844 height = (int)rect.size.height;
847 bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
849 [m_macWindow setOpaque:NO];
850 [m_macWindow setBackgroundColor:[NSColor clearColor]];
855 void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
857 [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
860 bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
862 if (([m_macWindow styleMask] & NSResizableWindowMask) != 0)
864 return [m_macWindow isZoomed];
868 NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
869 NSRect rectWindow = [m_macWindow frame];
870 return (rectScreen.origin.x == rectWindow.origin.x &&
871 rectScreen.origin.y == rectWindow.origin.y &&
872 rectScreen.size.width == rectWindow.size.width &&
873 rectScreen.size.height == rectWindow.size.height);
877 bool wxNonOwnedWindowCocoaImpl::IsIconized() const
879 return [m_macWindow isMiniaturized];
882 void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
885 [m_macWindow miniaturize:nil];
887 [m_macWindow deminiaturize:nil];
890 void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize))
892 [m_macWindow zoom:nil];
896 // http://cocoadevcentral.com/articles/000028.php
900 NSUInteger m_formerStyleMask;
902 NSRect m_formerFrame;
905 bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
907 return m_macFullScreenData != NULL ;
910 bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
914 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
916 data = new FullScreenData();
918 m_macFullScreenData = data ;
919 data->m_formerLevel = [m_macWindow level];
920 data->m_formerFrame = [m_macWindow frame];
921 data->m_formerStyleMask = [m_macWindow styleMask];
923 // CGDisplayCapture( kCGDirectMainDisplay );
924 //[m_macWindow setLevel:NSMainMenuWindowLevel+1/*CGShieldingWindowLevel()*/];
926 NSRect screenframe = [[NSScreen mainScreen] frame];
927 NSRect frame = NSMakeRect (0, 0, 100, 100);
930 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
931 if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
932 [m_macWindow setStyleMask:data->m_formerStyleMask & ~ NSResizableWindowMask];
935 contentRect = [NSWindow contentRectForFrameRect: frame
936 styleMask: [m_macWindow styleMask]];
937 screenframe.origin.y += (frame.origin.y - contentRect.origin.y);
938 screenframe.size.height += (frame.size.height - contentRect.size.height);
939 [m_macWindow setFrame:screenframe display:YES];
941 SetSystemUIMode(kUIModeAllHidden,
942 kUIOptionDisableAppleMenu
944 | kUIOptionDisableProcessSwitch
945 | kUIOptionDisableForceQuit
948 else if ( m_macFullScreenData != NULL )
950 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
952 // CGDisplayRelease( kCGDirectMainDisplay );
953 // [m_macWindow setLevel:data->m_formerLevel];
956 [m_macWindow setFrame:data->m_formerFrame display:YES];
957 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
958 if ( [ m_macWindow respondsToSelector:@selector(setStyleMask:) ] )
959 [m_macWindow setStyleMask:data->m_formerStyleMask];
962 m_macFullScreenData = NULL ;
964 SetSystemUIMode(kUIModeNormal, 0);
970 void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX)
972 NSRequestUserAttentionType flagsOSX;
975 case wxUSER_ATTENTION_INFO:
976 flagsOSX = NSInformationalRequest;
979 case wxUSER_ATTENTION_ERROR:
980 flagsOSX = NSCriticalRequest;
984 wxFAIL_MSG( "invalid RequestUserAttention() flags" );
988 [NSApp requestUserAttention:flagsOSX];
991 void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
993 wxPoint p((x ? *x : 0), (y ? *y : 0) );
994 NSPoint nspt = wxToNSPoint( NULL, p );
995 nspt = [m_macWindow convertScreenToBase:nspt];
996 nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil];
997 p = wxFromNSPoint([m_macWindow contentView], nspt);
1004 void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
1006 wxPoint p((x ? *x : 0), (y ? *y : 0) );
1007 NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p );
1008 nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil];
1009 nspt = [m_macWindow convertBaseToScreen:nspt];
1010 p = wxFromNSPoint( NULL, nspt);
1017 bool wxNonOwnedWindowCocoaImpl::IsActive()
1019 return [m_macWindow isKeyWindow];
1022 void wxNonOwnedWindowCocoaImpl::SetModified(bool modified)
1024 [m_macWindow setDocumentEdited:modified];
1027 bool wxNonOwnedWindowCocoaImpl::IsModified() const
1029 return [m_macWindow isDocumentEdited];
1032 void wxNonOwnedWindowCocoaImpl::SetRepresentedFilename(const wxString& filename)
1034 [m_macWindow setRepresentedFilename:wxCFStringRef(filename).AsNSString()];
1037 void wxNonOwnedWindowCocoaImpl::RestoreWindowLevel()
1039 if ( [m_macWindow level] != m_macWindowLevel )
1040 [m_macWindow setLevel:m_macWindowLevel];
1047 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
1049 wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
1050 now->Create( parent, nativeWindow );
1054 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
1055 long style, long extraStyle, const wxString& name )
1057 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
1058 now->Create( parent, pos, size, style , extraStyle, name );