From d52ded25c12f0a2e705d7d632dc5050287586475 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 12 Jun 2012 18:44:31 +0000 Subject: [PATCH] support for native tlw parents, see #14252 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71719 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/cocoa/nonownedwnd.mm | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index a83bd48ba0..1d5475532b 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -517,6 +517,12 @@ wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl() if ( !m_wxPeer->IsNativeWindowWrapper() ) { [m_macWindow setDelegate:nil]; + + // make sure we remove this first, otherwise the ref count will not lead to the + // native window's destruction + if ([m_macWindow parentWindow] != 0) + [[m_macWindow parentWindow] removeChildWindow: m_macWindow]; + [m_macWindow release]; } } @@ -679,14 +685,34 @@ bool wxNonOwnedWindowCocoaImpl::Show(bool show) if ( show ) { wxNonOwnedWindow* wxpeer = GetWXPeer(); - if (wxpeer && !(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW)) - [m_macWindow makeKeyAndOrderFront:nil]; - else - [m_macWindow orderFront:nil]; + if ( wxpeer ) + { + // add to parent window before showing + if ( wxpeer->GetParent() ) + { + NSView * parentView = wxpeer->GetParent()->GetPeer()->GetWXWidget(); + if ( parentView ) + { + NSWindow* parentNSWindow = [parentView window]; + if ( parentNSWindow ) + [parentNSWindow addChildWindow:m_macWindow ordered:NSWindowAbove]; + } + } + + if (!(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW)) + [m_macWindow makeKeyAndOrderFront:nil]; + else + [m_macWindow orderFront:nil]; + } [[m_macWindow contentView] setNeedsDisplay: YES]; } else + { + // avoid propagation of orderOut to parent + if ([m_macWindow parentWindow] != 0) + [[m_macWindow parentWindow] removeChildWindow: m_macWindow]; [m_macWindow orderOut:nil]; + } return true; } -- 2.45.2