X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f83c63111596f19a2247e1d1be0eb96b8dc5ddc..ea412ac4eb9f19e3c28dfa32aa9099a81ac7c74c:/src/osx/cocoa/nonownedwnd.mm diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index 6e617f9bfd..ce605c4161 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -88,6 +88,7 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector wxNonOwnedWindowCocoaImpl* impl; } +- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen; - (void)setImplementation: (wxNonOwnedWindowCocoaImpl *) theImplementation; - (wxNonOwnedWindowCocoaImpl*) implementation; - (void)noResponderFor: (SEL) selector; @@ -95,6 +96,14 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector @implementation wxNSWindow +// The default implementation always moves the window back onto the screen, +// even when the programmer explicitly wants to hide it. +- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen +{ + wxUnusedVar(screen); + return frameRect; +} + - (void)setImplementation: (wxNonOwnedWindowCocoaImpl *) theImplementation { impl = theImplementation; @@ -124,6 +133,14 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector } } +// We need this for borderless windows, i.e. shaped windows or windows without +// a title bar. For more info, see: +// http://lists.apple.com/archives/cocoa-dev/2008/May/msg02091.html +- (BOOL)canBecomeKeyWindow +{ + return YES; +} + @end @interface wxNSPanel : NSPanel @@ -178,7 +195,7 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector // controller // -@interface wxNonOwnedWindowController : NSObject +@interface wxNonOwnedWindowController : NSObject wxOSX_10_6_AND_LATER() { } @@ -188,6 +205,7 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector - (void)windowDidBecomeKey:(NSNotification *)notification; - (void)windowDidMove:(NSNotification *)notification; - (BOOL)windowShouldClose:(id)window; +- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame; @end @@ -311,6 +329,19 @@ typedef void (*wxOSX_NoResponderHandlerPtr)(NSView* self, SEL _cmd, SEL selector return nil; } +- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame +{ + wxNonOwnedWindowCocoaImpl* windowimpl = [(wxNSWindow*)window implementation]; + if ( windowimpl ) + { + wxNonOwnedWindow* wxpeer = windowimpl->GetWXPeer(); + wxMaximizeEvent event(wxpeer->GetId()); + event.SetEventObject(wxpeer); + return !wxpeer->HandleWindowEvent(event); + } + return true; +} + @end IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowCocoaImpl , wxNonOwnedWindowImpl ) @@ -330,14 +361,20 @@ wxNonOwnedWindowCocoaImpl::wxNonOwnedWindowCocoaImpl() wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl() { - [m_macWindow setImplementation:nil]; - [m_macWindow setDelegate:nil]; - [m_macWindow release]; + if ( !m_wxPeer->IsNativeWindowWrapper() ) + { + [m_macWindow setImplementation:nil]; + [m_macWindow setDelegate:nil]; + [m_macWindow release]; + } } -void wxNonOwnedWindowCocoaImpl::Destroy() +void wxNonOwnedWindowCocoaImpl::WillBeDestroyed() { - wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) ); + if ( !m_wxPeer->IsNativeWindowWrapper() ) + { + [m_macWindow setDelegate:nil]; + } } void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), const wxPoint& pos, const wxSize& size, @@ -441,6 +478,7 @@ long style, long extraStyle, const wxString& WXUNUSED(name) ) NSRect r = wxToNSRect( NULL, wxRect( pos, size) ); [m_macWindow setImplementation:this]; + r = [NSWindow contentRectForFrameRect:r styleMask:windowstyle]; [m_macWindow initWithContentRect:r styleMask:windowstyle @@ -453,8 +491,18 @@ long style, long extraStyle, const wxString& WXUNUSED(name) ) [m_macWindow setDelegate:controller]; [m_macWindow setAcceptsMouseMovedEvents: YES]; + + if ( ( style & wxFRAME_SHAPED) ) + { + [m_macWindow setOpaque:NO]; + [m_macWindow setAlphaValue:1.0]; + } } +void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow ) +{ + m_macWindow = nativeWindow; +} WXWindow wxNonOwnedWindowCocoaImpl::GetWXWindow() const { @@ -471,26 +519,34 @@ void wxNonOwnedWindowCocoaImpl::Lower() [m_macWindow orderWindow:NSWindowBelow relativeTo:0]; } +void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating() +{ + [m_macWindow orderFront:nil]; + [[m_macWindow contentView] setNeedsDisplay: YES]; +} + bool wxNonOwnedWindowCocoaImpl::Show(bool show) { if ( show ) { wxNonOwnedWindow* wxpeer = GetWXPeer(); if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW)) - [m_macWindow makeKeyAndOrderFront:nil]; + [m_macWindow makeKeyAndOrderFront:nil]; else [m_macWindow orderFront:nil]; - - [[m_macWindow contentView] setNeedsDisplay:YES]; + [[m_macWindow contentView] setNeedsDisplay: YES]; } else [m_macWindow orderOut:nil]; return true; } -bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show, wxShowEffect WXUNUSED(effect), unsigned WXUNUSED(timeout)) +bool wxNonOwnedWindowCocoaImpl::ShowWithEffect(bool show, + wxShowEffect effect, + unsigned timeout) { - return Show(show); + return wxWidgetCocoaImpl:: + ShowViewOrWindowWithEffect(m_wxPeer, show, effect, timeout); } void wxNonOwnedWindowCocoaImpl::Update() @@ -526,8 +582,29 @@ void wxNonOwnedWindowCocoaImpl::SetExtraStyle( long exStyle ) } } -bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle WXUNUSED(style)) +void wxNonOwnedWindowCocoaImpl::SetWindowStyleFlag( long style ) { + if (m_macWindow) + { + CGWindowLevel level = kCGNormalWindowLevel; + + if (style & wxSTAY_ON_TOP) + level = kCGUtilityWindowLevel; + else if (( style & wxFRAME_FLOAT_ON_PARENT ) || ( style & wxFRAME_TOOL_WINDOW )) + level = kCGFloatingWindowLevel; + + [m_macWindow setLevel: level]; + } +} + +bool wxNonOwnedWindowCocoaImpl::SetBackgroundStyle(wxBackgroundStyle style) +{ + if ( style == wxBG_STYLE_TRANSPARENT ) + { + [m_macWindow setOpaque:NO]; + [m_macWindow setBackgroundColor:[NSColor clearColor]]; + } + return true; } @@ -570,7 +647,10 @@ void wxNonOwnedWindowCocoaImpl::GetContentArea( int& left, int &top, int &width, bool wxNonOwnedWindowCocoaImpl::SetShape(const wxRegion& WXUNUSED(region)) { - return false; + [m_macWindow setOpaque:NO]; + [m_macWindow setBackgroundColor:[NSColor clearColor]]; + + return true; } void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding encoding ) @@ -580,7 +660,19 @@ void wxNonOwnedWindowCocoaImpl::SetTitle( const wxString& title, wxFontEncoding bool wxNonOwnedWindowCocoaImpl::IsMaximized() const { - return [m_macWindow isZoomed]; + if (([m_macWindow styleMask] & NSResizableWindowMask) != 0) + { + return [m_macWindow isZoomed]; + } + else + { + NSRect rectScreen = [[NSScreen mainScreen] visibleFrame]; + NSRect rectWindow = [m_macWindow frame]; + return (rectScreen.origin.x == rectWindow.origin.x && + rectScreen.origin.y == rectWindow.origin.y && + rectScreen.size.width == rectWindow.size.width && + rectScreen.size.height == rectWindow.size.height); + } } bool wxNonOwnedWindowCocoaImpl::IsIconized() const @@ -643,8 +735,25 @@ bool wxNonOwnedWindowCocoaImpl::ShowFullScreen(bool show, long WXUNUSED(style)) return true; } -void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int WXUNUSED(flags)) +void wxNonOwnedWindowCocoaImpl::RequestUserAttention(int flagsWX) { + NSRequestUserAttentionType flagsOSX; + switch ( flagsWX ) + { + case wxUSER_ATTENTION_INFO: + flagsOSX = NSInformationalRequest; + break; + + case wxUSER_ATTENTION_ERROR: + flagsOSX = NSCriticalRequest; + break; + + default: + wxFAIL_MSG( "invalid RequestUserAttention() flags" ); + return; + } + + [NSApp requestUserAttention:flagsOSX]; } void wxNonOwnedWindowCocoaImpl::ScreenToWindow( int *x, int *y ) @@ -673,6 +782,28 @@ void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y ) *y = p.y; } +bool wxNonOwnedWindowCocoaImpl::IsActive() +{ + return [m_macWindow isKeyWindow]; +} + +void wxNonOwnedWindowCocoaImpl::SetModified(bool modified) +{ + [m_macWindow setDocumentEdited:modified]; +} + +bool wxNonOwnedWindowCocoaImpl::IsModified() const +{ + return [m_macWindow isDocumentEdited]; +} + +wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow) +{ + wxNonOwnedWindowCocoaImpl* now = new wxNonOwnedWindowCocoaImpl( wxpeer ); + now->Create( parent, nativeWindow ); + return now; +} + wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size, long style, long extraStyle, const wxString& name ) {