Bug 168117 - "Need to implement nsIWidget::SetParent on the Mac" [r=pink sr=bryner]

This commit is contained in:
Simon Fraser 2008-10-20 21:23:22 -05:00
parent b01ff42ba2
commit 43eb45f980
2 changed files with 33 additions and 2 deletions

View File

@ -292,6 +292,7 @@ public:
NS_IMETHOD Show(PRBool aState);
NS_IMETHOD IsVisible(PRBool& outState);
NS_IMETHOD SetParent(nsIWidget* aNewParent);
virtual nsIWidget* GetParent(void);
NS_IMETHOD ModalEventFilter(PRBool aRealEvent, void *aEvent,

View File

@ -972,8 +972,38 @@ NS_IMETHODIMP nsChildView::Show(PRBool aState)
}
nsIWidget*
nsChildView::GetParent(void)
//-------------------------------------------------------------------------
//
// Reset the parent of this widget
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsChildView::SetParent(nsIWidget* aNewParent)
{
NS_ENSURE_ARG(aNewParent);
// make sure we stay alive
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
// remove us from our existing parent
if (mParentWidget)
mParentWidget->RemoveChild(this);
[mView removeFromSuperview]; // we hold a ref to mView, so this is OK
// add us to the new parent
aNewParent->AddChild(this);
mParentWidget = aNewParent;
mParentView = (NSView*)aNewParent->GetNativeData(NS_NATIVE_WIDGET);
[mParentView addSubview:mView];
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get this widget's parent
//
//-------------------------------------------------------------------------
nsIWidget* nsChildView::GetParent(void)
{
return mParentWidget;
}