1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/nonownedwnd.mm
3 // Purpose: non owned window for cocoa
4 // Author: DavidStefan Csomor
7 // RCS-ID: $Id: nonownedwnd.mm 48805 2007-09-19 14:52:25Z SC $
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"
20 #include "wx/osx/private.h"
22 NSScreen* wxOSXGetMenuScreen()
24 if ( [NSScreen screens] == nil )
25 return [NSScreen mainScreen];
28 return [[NSScreen screens] objectAtIndex:0];
32 NSRect wxToNSRect( NSView* parent, const wxRect& r )
34 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
37 if ( parent == NULL || ![ parent isFlipped ] )
38 y = (int)(frame.size.height - ( r.y + r.height ));
39 return NSMakeRect(x, y, r.width , r.height);
42 wxRect wxFromNSRect( NSView* parent, const NSRect& rect )
44 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
45 int y = (int)rect.origin.y;
46 int x = (int)rect.origin.x;
47 if ( parent == NULL || ![ parent isFlipped ] )
48 y = (int)(frame.size.height - (rect.origin.y + rect.size.height));
49 return wxRect( x, y, (int)rect.size.width, (int)rect.size.height );
52 NSPoint wxToNSPoint( NSView* parent, const wxPoint& p )
54 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
57 if ( parent == NULL || ![ parent isFlipped ] )
58 y = (int)(frame.size.height - ( p.y ));
59 return NSMakePoint(x, y);
62 wxPoint wxFromNSPoint( NSView* parent, const NSPoint& p )
64 NSRect frame = parent ? [parent bounds] : [wxOSXGetMenuScreen() frame];
67 if ( parent == NULL || ![ parent isFlipped ] )
68 y = (int)(frame.size.height - ( p.y ));
69 return wxPoint( x, y);
72 bool shouldHandleSelector(SEL selector)
74 if (selector == @selector(noop:)
75 || selector == @selector(complete:)
76 || selector == @selector(deleteBackward:)
77 || selector == @selector(deleteForward:)
78 || selector == @selector(insertNewline:)
79 || selector == @selector(insertTab:)
80 || selector == @selector(insertBacktab:)
81 || selector == @selector(keyDown:)
82 || selector == @selector(keyUp:)
83 || selector == @selector(scrollPageUp:)
84 || selector == @selector(scrollPageDown:)
85 || selector == @selector(scrollToBeginningOfDocument:)
86 || selector == @selector(scrollToEndOfDocument:))
94 // wx category for NSWindow (our own and wrapped instances)
97 @interface NSWindow (wxNSWindowSupport)
99 - (wxNonOwnedWindowCocoaImpl*) WX_implementation;
101 - (bool) WX_filterSendEvent:(NSEvent *) event;
105 @implementation NSWindow (wxNSWindowSupport)
107 - (wxNonOwnedWindowCocoaImpl*) WX_implementation
109 return (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
112 // TODO in cocoa everything during a drag is sent to the NSWindow the mouse down occured,
113 // this does not conform to the wx behaviour if the window is not captured, so try to resend
114 // or capture all wx mouse event handling at the tlw as we did for carbon
116 - (bool) WX_filterSendEvent:(NSEvent *) event
118 bool handled = false;
119 if ( ([event type] >= NSLeftMouseDown) && ([event type] <= NSMouseExited) )
121 wxWindow* cw = wxWindow::GetCapture();
124 ((wxWidgetCocoaImpl*)cw->GetPeer())->DoHandleMouseEvent( event);
133 // wx native implementation
136 @interface wxNSWindow : NSWindow
140 - (void) sendEvent:(NSEvent *)event;
141 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
142 - (void)noResponderFor: (SEL) selector;
145 @implementation wxNSWindow
147 - (void)sendEvent:(NSEvent *) event
149 if ( ![self WX_filterSendEvent: event] )
151 WXEVENTREF formerEvent = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEvent();
152 WXEVENTHANDLERCALLREF formerHandler = wxTheApp == NULL ? NULL : wxTheApp->MacGetCurrentEventHandlerCallRef();
155 wxTheApp->MacSetCurrentEvent(event, NULL);
157 [super sendEvent: event];
160 wxTheApp->MacSetCurrentEvent(formerEvent , formerHandler);
164 // The default implementation always moves the window back onto the screen,
165 // even when the programmer explicitly wants to hide it.
166 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
172 - (void)doCommandBySelector:(SEL)selector
174 if (shouldHandleSelector(selector) &&
175 !(selector == @selector(cancel:) || selector == @selector(cancelOperation:)) )
176 [super doCommandBySelector:selector];
180 // NB: if we don't do this, all key downs that get handled lead to a NSBeep
181 - (void)noResponderFor: (SEL) selector
183 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
185 [super noResponderFor:selector];
189 // We need this for borderless windows, i.e. shaped windows or windows without
190 // a title bar. For more info, see:
191 // http://lists.apple.com/archives/cocoa-dev/2008/May/msg02091.html
192 - (BOOL)canBecomeKeyWindow
199 @interface wxNSPanel : NSPanel
203 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen;
204 - (void)noResponderFor: (SEL) selector;
205 - (void)sendEvent:(NSEvent *)event;
208 @implementation wxNSPanel
210 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
212 wxNonOwnedWindowCocoaImpl* impl = (wxNonOwnedWindowCocoaImpl*) wxNonOwnedWindowImpl::FindFromWXWindow( self );
213 if (impl && impl->IsFullScreen())
216 return [super constrainFrameRect:frameRect toScreen:screen];
219 - (BOOL)canBecomeKeyWindow
224 - (void)doCommandBySelector:(SEL)selector
226 if (shouldHandleSelector(selector))
227 [super doCommandBySelector:selector];
230 // NB: if we don't do this, it seems that all events that end here lead to a NSBeep
231 - (void)noResponderFor: (SEL) selector
233 if (selector != @selector(keyDown:) && selector != @selector(keyUp:))
235 [super noResponderFor:selector];
239 - (void)sendEvent:(NSEvent *) event
241 if ( ![self WX_filterSendEvent: event] )
242 [super sendEvent: event];
252 @interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER(<NSWindowDelegate>)
256 - (void)windowDidResize:(NSNotification *)notification;
257 - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
258 - (void)windowDidResignKey:(NSNotification *)notification;
259 - (void)windowDidBecomeKey:(NSNotification *)notification;
260 - (void)windowDidMove:(NSNotification *)notification;
261 - (BOOL)windowShouldClose:(id)window;
262 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
266 extern int wxOSXGetIdFromSelector(SEL action );
268 @implementation wxNonOwnedWindowController
276 - (BOOL) triggerMenu:(SEL) action
278 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
282 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
283 if ( menu != NULL && menuitem != NULL)
284 return menu->HandleCommandProcess(menuitem);
289 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
291 SEL action = [menuItem action];
293 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
297 wxMenuItem* menuitem = mbar->FindItem(wxOSXGetIdFromSelector(action), &menu);
298 if ( menu != NULL && menuitem != NULL)
300 if ( menu->HandleCommandUpdateStatus(menuitem) )
301 return menuitem->IsEnabled();
307 - (void)undo:(id)sender
309 [self triggerMenu:_cmd];
312 - (void)redo:(id)sender
314 [self triggerMenu:_cmd];
317 - (void)cut:(id)sender
319 [self triggerMenu:_cmd];
322 - (void)copy:(id)sender
324 [self triggerMenu:_cmd];
327 - (void)paste:(id)sender
329 [self triggerMenu:_cmd];
332 - (void)delete:(id)sender
334 [self triggerMenu:_cmd];
337 - (void)selectAll:(id)sender
339 [self triggerMenu:_cmd];
342 - (BOOL)windowShouldClose:(id)nwindow
344 wxNonOwnedWindowCocoaImpl* windowimpl = [(NSWindow*) nwindow WX_implementation];
347 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
354 - (NSSize)windowWillResize:(NSWindow *)window
355 toSize:(NSSize)proposedFrameSize
357 NSRect frame = [window frame];
358 wxRect wxframe = wxFromNSRect( NULL, frame );
359 wxframe.SetWidth( (int)proposedFrameSize.width );
360 wxframe.SetHeight( (int)proposedFrameSize.height );
362 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
365 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
368 wxpeer->HandleResizing( 0, &wxframe );
369 NSSize newSize = NSMakeSize(wxframe.GetWidth(), wxframe.GetHeight());
374 return proposedFrameSize;
377 - (void)windowDidResize:(NSNotification *)notification
379 NSWindow* window = (NSWindow*) [notification object];
380 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
383 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
385 wxpeer->HandleResized(0);
389 - (void)windowDidMove:(NSNotification *)notification
391 wxNSWindow* window = (wxNSWindow*) [notification object];
392 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
395 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
397 wxpeer->HandleMoved(0);
401 - (void)windowDidBecomeKey:(NSNotification *)notification
403 NSWindow* window = (NSWindow*) [notification object];
404 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
407 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
409 wxpeer->HandleActivated(0, true);
413 - (void)windowDidResignKey:(NSNotification *)notification
415 NSWindow* window = (NSWindow*) [notification object];
416 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
419 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
422 wxpeer->HandleActivated(0, false);
423 // Needed for popup window since the firstResponder
424 // (focus in wx) doesn't change when this
425 // TLW becomes inactive.
426 wxFocusEvent event( wxEVT_KILL_FOCUS, wxpeer->GetId());
427 event.SetEventObject(wxpeer);
428 wxpeer->HandleWindowEvent(event);
433 - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
437 if ([anObject isKindOfClass:[wxNSTextField class]])
439 wxNSTextField* tf = (wxNSTextField*) anObject;
440 wxNSTextFieldEditor* editor = [tf fieldEditor];
443 editor = [[wxNSTextFieldEditor alloc] init];
444 [editor setFieldEditor:YES];
445 [tf setFieldEditor:editor];
453 - (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
455 wxUnusedVar(newFrame);
456 wxNonOwnedWindowCocoaImpl* windowimpl = [window WX_implementation];
459 wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer();
460 wxMaximizeEvent event(wxpeer->GetId());
461 event.SetEventObject(wxpeer);
462 return !wxpeer->HandleWindowEvent(event);
469 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl )
471 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl( wxNonOwnedWindow* nonownedwnd) :
472 wxNonOwnedWindowImpl(nonownedwnd)
475 m_macFullScreenData = NULL;
478 wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl()
481 m_macFullScreenData = NULL;
484 wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl()
486 if ( !m_wxPeer->IsNativeWindowWrapper() )
488 [m_macWindow setDelegate:nil];
489 [m_macWindow release];
493 void wxNonOwnedWindowCocoaImpl::WillBeDestroyed()
495 if ( !m_wxPeer->IsNativeWindowWrapper() )
497 [m_macWindow setDelegate:nil];
501 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
502 long style, long extraStyle, const wxString& WXUNUSED(name) )
504 static wxNonOwnedWindowController* controller = NULL;
507 controller =[[wxNonOwnedWindowController alloc] init];
510 int windowstyle = NSBorderlessWindowMask;
512 if ( style & wxFRAME_TOOL_WINDOW || ( style & wxPOPUP_WINDOW ) ||
513 GetWXPeer()->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
515 m_macWindow = [wxNSPanel alloc];
518 m_macWindow = [wxNSWindow alloc];
520 CGWindowLevel level = kCGNormalWindowLevel;
522 if ( style & wxFRAME_TOOL_WINDOW )
524 windowstyle |= NSUtilityWindowMask;
525 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
526 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
528 windowstyle |= NSTitledWindowMask ;
531 else if ( ( style & wxPOPUP_WINDOW ) )
533 level = kCGPopUpMenuWindowLevel;
535 if ( ( style & wxBORDER_NONE ) )
537 wclass = kHelpWindowClass ; // has no border
538 attr |= kWindowNoShadowAttribute;
542 wclass = kPlainWindowClass ; // has a single line border, it will have to do for now
546 else if ( ( style & wxCAPTION ) )
548 windowstyle |= NSTitledWindowMask ;
550 else if ( ( style & wxFRAME_DRAWER ) )
553 wclass = kDrawerWindowClass;
558 // set these even if we have no title, otherwise the controls won't be visible
559 if ( ( style & wxMINIMIZE_BOX ) || ( style & wxMAXIMIZE_BOX ) ||
560 ( style & wxCLOSE_BOX ) || ( style & wxSYSTEM_MENU ) )
562 windowstyle |= NSTitledWindowMask ;
565 else if ( ( style & wxNO_BORDER ) )
567 wclass = kSimpleWindowClass ;
571 wclass = kPlainWindowClass ;
576 if ( windowstyle & NSTitledWindowMask )
578 if ( ( style & wxMINIMIZE_BOX ) )
579 windowstyle |= NSMiniaturizableWindowMask ;
581 if ( ( style & wxMAXIMIZE_BOX ) )
582 windowstyle |= NSResizableWindowMask ; // TODO showing ZOOM ?
584 if ( ( style & wxRESIZE_BORDER ) )
585 windowstyle |= NSResizableWindowMask ;
587 if ( ( style & wxCLOSE_BOX) )
588 windowstyle |= NSClosableWindowMask ;
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 the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
610 // to be in kCGUtilityWindowLevel and not kCGFloatingWindowLevel to stay
612 wxDialog * const parentDialog = wxDynamicCast(parent, wxDialog);
613 if (parentDialog && parentDialog->IsModal())
615 if (level == kCGFloatingWindowLevel)
617 level = kCGUtilityWindowLevel;
620 // Cocoa's modal loop does not process other windows by default, but
621 // don't call this on normal window levels so nested modal dialogs will
622 // still behave modally.
623 if (level != kCGNormalWindowLevel)
625 if ([m_macWindow isKindOfClass:[NSPanel class]])
627 [(NSPanel*)m_macWindow setWorksWhenModal:YES];
632 [m_macWindow setLevel:level];
634 [m_macWindow setDelegate:controller];
636 [m_macWindow setAcceptsMouseMovedEvents: YES];
638 if ( ( style & wxFRAME_SHAPED) )
640 [m_macWindow setOpaque:NO];
641 [m_macWindow setAlphaValue:1.0];
644 if ( !(style & wxFRAME_TOOL_WINDOW) )
645 [m_macWindow setHidesOnDeactivate:NO];
648 void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
650 m_macWindow = nativeWindow;
653 WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const
658 void wxNonOwnedWindowCocoaImpl::Raise()
660 [m_macWindow makeKeyAndOrderFront:nil];
663 void wxNonOwnedWindowCocoaImpl::Lower()
665 [m_macWindow orderWindow:NSWindowBelow relativeTo:0];
668 void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
670 [m_macWindow orderFront:nil];
671 [[m_macWindow contentView] setNeedsDisplay: YES];
674 bool wxNonOwnedWindowCocoaImpl::Show(bool show)
678 wxNonOwnedWindow* wxpeer = GetWXPeer();
679 if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
680 [m_macWindow makeKeyAndOrderFront:nil];
682 [m_macWindow orderFront:nil];
683 [[m_macWindow contentView] setNeedsDisplay: YES];
686 [m_macWindow orderOut:nil];
690 bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show,
694 return wxWidgetCocoaImpl::
695 ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout);
698 void wxNonOwnedWindowCocoaImpl::Update()
700 [m_macWindow displayIfNeeded];
703 bool wxNonOwnedWindowCocoaImpl::SetTransparent(wxByte alpha)
705 [m_macWindow setAlphaValue:(CGFloat) alpha/255.0];
709 bool wxNonOwnedWindowCocoaImpl::SetBackgroundColour(const wxColour& WXUNUSED(col) )
714 void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle )
718 bool metal = exStyle & wxFRAME_EX_METAL ;
719 int windowStyle = [ m_macWindow styleMask];
720 if ( metal && !(windowStyle & NSTexturedBackgroundWindowMask) )
722 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
724 else if ( !metal && (windowStyle & NSTexturedBackgroundWindowMask ) )
726 wxFAIL_MSG( wxT("Metal Style cannot be changed after creation") );
731 void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style )
735 CGWindowLevel level = kCGNormalWindowLevel;
737 if (style & wxSTAY_ON_TOP)
738 level = kCGUtilityWindowLevel;
739 else if (( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW ))
740 level = kCGFloatingWindowLevel;
742 [m_macWindow setLevel: level];
746 bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style)
748 if ( style == wxBG_STYLE_TRANSPARENT )
750 [m_macWindow setOpaque:NO];
751 [m_macWindow setBackgroundColor:[NSColor clearColor]];
757 bool wxNonOwnedWindowCocoaImpl::CanSetTransparent()
762 void wxNonOwnedWindowCocoaImpl::MoveWindow(int x, int y, int width, int height)
764 NSRect r = wxToNSRect( NULL, wxRect(x,y,width, height) );
765 // do not trigger refreshes upon invisible and possible partly created objects
766 [m_macWindow setFrame:r display:GetWXPeer()->IsShownOnScreen()];
769 void wxNonOwnedWindowCocoaImpl::GetPosition( int &x, int &y ) const
771 wxRect r = wxFromNSRect( NULL, [m_macWindow frame] );
776 void wxNonOwnedWindowCocoaImpl::GetSize( int &width, int &height ) const
778 NSRect rect = [m_macWindow frame];
779 width = (int)rect.size.width;
780 height = (int)rect.size.height;
783 void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
785 NSRect outer = NSMakeRect(100,100,100,100);
786 NSRect content = [NSWindow contentRectForFrameRect:outer styleMask:[m_macWindow styleMask] ];
787 NSRect rect = [[m_macWindow contentView] frame];
788 left = (int)rect.origin.x;
789 top = (int)rect.origin.y;
790 width = (int)rect.size.width;
791 height = (int)rect.size.height;
794 bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region))
796 [m_macWindow setOpaque:NO];
797 [m_macWindow setBackgroundColor:[NSColor clearColor]];
802 void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
804 [m_macWindow setTitle:wxCFStringRef( title , encoding ).AsNSString()];
807 bool wxNonOwnedWindowCocoaImpl::IsMaximized() const
809 if (([m_macWindow styleMask] & NSResizableWindowMask) != 0)
811 return [m_macWindow isZoomed];
815 NSRect rectScreen = [[NSScreen mainScreen] visibleFrame];
816 NSRect rectWindow = [m_macWindow frame];
817 return (rectScreen.origin.x == rectWindow.origin.x &&
818 rectScreen.origin.y == rectWindow.origin.y &&
819 rectScreen.size.width == rectWindow.size.width &&
820 rectScreen.size.height == rectWindow.size.height);
824 bool wxNonOwnedWindowCocoaImpl::IsIconized() const
826 return [m_macWindow isMiniaturized];
829 void wxNonOwnedWindowCocoaImpl::Iconize( bool iconize )
832 [m_macWindow miniaturize:nil];
834 [m_macWindow deminiaturize:nil];
837 void wxNonOwnedWindowCocoaImpl::Maximize(bool WXUNUSED(maximize))
839 [m_macWindow zoom:nil];
843 // http://cocoadevcentral.com/articles/000028.php
848 NSRect m_formerFrame;
851 bool wxNonOwnedWindowCocoaImpl::IsFullScreen() const
853 return m_macFullScreenData != NULL ;
856 bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style))
860 FullScreenData *data = (FullScreenData *)m_macFullScreenData ;
862 data = new FullScreenData();
864 m_macFullScreenData = data ;
865 data->m_formerLevel = [m_macWindow level];
866 data->m_formerFrame = [m_macWindow frame];
867 CGDisplayCapture( kCGDirectMainDisplay );
868 [m_macWindow setLevel:CGShieldingWindowLevel()];
869 NSRect screenframe = [[NSScreen mainScreen] frame];
870 NSRect frame = NSMakeRect (0, 0, 100, 100);
872 contentRect = [NSWindow contentRectForFrameRect: frame
873 styleMask: NSTitledWindowMask];
874 screenframe.origin.y += (frame.origin.y - contentRect.origin.y);
875 screenframe.size.height += (frame.size.height - contentRect.size.height);
876 [m_macWindow setFrame:screenframe display:YES];
878 else if ( m_macFullScreenData != NULL )
880 FullScreenData *data = (FullScreenData *) m_macFullScreenData ;
881 CGDisplayRelease( kCGDirectMainDisplay );
882 [m_macWindow setLevel:data->m_formerLevel];
883 [m_macWindow setFrame:data->m_formerFrame display:YES];
885 m_macFullScreenData = NULL ;
891 void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX)
893 NSRequestUserAttentionType flagsOSX;
896 case wxUSER_ATTENTION_INFO:
897 flagsOSX = NSInformationalRequest;
900 case wxUSER_ATTENTION_ERROR:
901 flagsOSX = NSCriticalRequest;
905 wxFAIL_MSG( "invalid RequestUserAttention() flags" );
909 [NSApp requestUserAttention:flagsOSX];
912 void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y )
914 wxPoint p((x ? *x : 0), (y ? *y : 0) );
915 NSPoint nspt = wxToNSPoint( NULL, p );
916 nspt = [m_macWindow convertScreenToBase:nspt];
917 nspt = [[m_macWindow contentView] convertPoint:nspt fromView:nil];
918 p = wxFromNSPoint([m_macWindow contentView], nspt);
925 void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y )
927 wxPoint p((x ? *x : 0), (y ? *y : 0) );
928 NSPoint nspt = wxToNSPoint( [m_macWindow contentView], p );
929 nspt = [[m_macWindow contentView] convertPoint:nspt toView:nil];
930 nspt = [m_macWindow convertBaseToScreen:nspt];
931 p = wxFromNSPoint( NULL, nspt);
938 bool wxNonOwnedWindowCocoaImpl::IsActive()
940 return [m_macWindow isKeyWindow];
943 void wxNonOwnedWindowCocoaImpl::SetModified(bool modified)
945 [m_macWindow setDocumentEdited:modified];
948 bool wxNonOwnedWindowCocoaImpl::IsModified() const
950 return [m_macWindow isDocumentEdited];
953 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
955 wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
956 now->Create( parent, nativeWindow );
960 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
961 long style, long extraStyle, const wxString& name )
963 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer );
964 now->Create( parent, pos, size, style , extraStyle, name );