Fix re-parenting TLWs in wxMSW

We need to set the new owner for the TLW, instead of using the new
parent as the actual parent, in the MSW sense, as this results in a
weird situation in which the TLW becomes a child (i.e. non-TLW) window.

Closes #18785.
This commit is contained in:
Danail Stoychev 2020-07-09 00:34:44 +02:00 committed by Vadim Zeitlin
parent 8f4ebb4bdc
commit 5e7e89de16
2 changed files with 19 additions and 0 deletions

View File

@ -22,6 +22,7 @@ public:
wxNonOwnedWindow();
virtual ~wxNonOwnedWindow();
virtual bool Reparent(wxWindowBase* newParent);
virtual void InheritAttributes() wxOVERRIDE;
protected:

View File

@ -157,6 +157,24 @@ wxNonOwnedWindow::~wxNonOwnedWindow()
#endif // wxUSE_GRAPHICS_CONTEXT
}
bool wxNonOwnedWindow::Reparent(wxWindowBase* newParent)
{
// ::SetParent() can't be used for non-owned windows, as they don't have
// any parent, only the owner, so use a different function for them even
// if, confusingly, the owner is stored at the same location as the parent
// and so uses the same GWLP_HWNDPARENT offset.
// Do not call the base class function here to skip wxWindow reparenting.
if ( !wxWindowBase::Reparent(newParent) )
return false;
const HWND hwndOwner = GetParent() ? GetHwndOf(GetParent()) : 0;
::SetWindowLongPtr(GetHwnd(), GWLP_HWNDPARENT, (LONG_PTR)hwndOwner);
return true;
}
namespace
{