From bbe16db5240011f4e37bf613bc5e563c9be7324b Mon Sep 17 00:00:00 2001 From: "ramiro%netscape.com" Date: Tue, 6 Apr 1999 12:45:23 +0000 Subject: [PATCH] Backout pavlov refcount/cleanup changes. They are causing core dumps in strange places. git-svn-id: svn://10.0.0.236/trunk@26474 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/gtk/nsWidget.cpp | 47 +++++++++++++++-------------- mozilla/widget/src/gtk/nsWindow.cpp | 22 +++++++++----- mozilla/widget/src/gtk/nsWindow.h | 1 + 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/mozilla/widget/src/gtk/nsWidget.cpp b/mozilla/widget/src/gtk/nsWidget.cpp index 4ab50c6c3d5..643154e4f28 100644 --- a/mozilla/widget/src/gtk/nsWidget.cpp +++ b/mozilla/widget/src/gtk/nsWidget.cpp @@ -56,6 +56,8 @@ nsWidget::nsWidget() mBounds.y = 0; mBounds.width = 0; mBounds.height = 0; + mIsDestroying = PR_FALSE; + mOnDestroyCalled = PR_FALSE; mIsToplevel = PR_FALSE; mUpdateArea.SetRect(0, 0, 0, 0); } @@ -96,30 +98,22 @@ NS_IMETHODIMP nsWidget::Destroy(void) this, mIsDestroying ? "yes" : "no", mWidget, mParent); #endif GtkAllocation *old_size = NULL; - if (!mIsDestroying) { nsBaseWidget::Destroy(); } - if (mWidget) { // see if we need to destroy the old size information old_size = (GtkAllocation *) gtk_object_get_data(GTK_OBJECT(mWidget), "mozilla.old_size"); if (old_size) { g_free(old_size); } - // prevent the widget from causing additional events mEventCallback = nsnull; - - // destroy the gtk widget ::gtk_widget_destroy(mWidget); mWidget = nsnull; - - if (!mOnDestroyCalled) + if (PR_FALSE == mOnDestroyCalled) OnDestroy(); - } - return NS_OK; } @@ -130,17 +124,15 @@ void nsWidget::OnDestroy() mOnDestroyCalled = PR_TRUE; // release references to children, device context, toolkit + app shell nsBaseWidget::OnDestroy(); - // dispatch the event if (!mIsDestroying) { - // dispatching of the event may cause the reference count to drop // to 0 and result in this object being destroyed. To avoid that, // add a reference and then release it after dispatching the event - - AddRef(); + nsrefcnt old = mRefCnt; + mRefCnt = 99; DispatchStandardEvent(NS_DESTROY); - Release(); + mRefCnt = old; } } @@ -153,7 +145,6 @@ void nsWidget::OnDestroy() nsIWidget *nsWidget::GetParent(void) { // NS_NOTYETIMPLEMENTED("nsWidget::GetParent"); - NS_ADDREF(mParent); return mParent; } @@ -188,14 +179,26 @@ NS_METHOD nsWidget::Show(PRBool bState) NS_METHOD nsWidget::IsVisible(PRBool &aState) { - if (mWidget) - { - aState = GTK_WIDGET_VISIBLE(mWidget); + if (mWidget) { + gint RealVis = GTK_WIDGET_VISIBLE(mWidget); + aState = mShown; + g_return_val_if_fail(RealVis == mShown, NS_ERROR_FAILURE); } else - { - aState = PR_FALSE; - } + aState = PR_TRUE; + +// +// Why isnt the following good enough ? -ramiro +// +// if (nsnull != mWidget) +// { +// aState = GTK_WIDGET_VISIBLE(mWidget); +// } +// else +// { +// aState = PR_FALSE; +// } + return NS_OK; } @@ -675,7 +678,7 @@ nsresult nsWidget::CreateWidget(nsIWidget *aParent, BaseCreate(aParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData); mParent = aParent; - //NS_IF_ADDREF(mParent); + NS_IF_ADDREF(mParent); if (aNativeParent) { parentWidget = GTK_WIDGET(aNativeParent); diff --git a/mozilla/widget/src/gtk/nsWindow.cpp b/mozilla/widget/src/gtk/nsWindow.cpp index ad5aeb52d52..165d686d7cf 100644 --- a/mozilla/widget/src/gtk/nsWindow.cpp +++ b/mozilla/widget/src/gtk/nsWindow.cpp @@ -80,6 +80,8 @@ nsWindow::nsWindow() mDisplayed = PR_FALSE; mLowerLeft = PR_FALSE; mBorderStyle = GTK_WINDOW_TOPLEVEL; + mIsDestroying = PR_FALSE; + mOnDestroyCalled = PR_FALSE; mFont = nsnull; } @@ -91,7 +93,9 @@ nsWindow::nsWindow() nsWindow::~nsWindow() { mIsDestroying = PR_TRUE; - Destroy(); + if (nsnull != mShell) { + Destroy(); + } } PRBool nsWindow::IsChild() const @@ -102,7 +106,7 @@ PRBool nsWindow::IsChild() const //------------------------------------------------------------------------- void nsWindow::ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY) { - g_print("nsWindow::ConvertToDeviceCoordinates called\n"); + } //------------------------------------------------------------------------- @@ -141,19 +145,23 @@ NS_METHOD nsWindow::Destroy() { // Call base class first... nsWidget::Destroy(); - if (mShell) { - gtk_widget_destroy(mShell); - mShell = nsnull; + + if (mIsDestroying == PR_TRUE) { + if (mShell) { + if (GTK_IS_WIDGET(mShell)) + gtk_widget_destroy(mShell); + mShell = nsnull; + } } + return NS_OK; } gint handle_delete_event(GtkWidget *w, GdkEventAny *e, nsWindow *win) { - win->SetIsDestroying(PR_TRUE); + win->SetIsDestroying( PR_TRUE ); win->Destroy(); - return TRUE; } diff --git a/mozilla/widget/src/gtk/nsWindow.h b/mozilla/widget/src/gtk/nsWindow.h index 9b4a78020f5..e69b8b416e1 100644 --- a/mozilla/widget/src/gtk/nsWindow.h +++ b/mozilla/widget/src/gtk/nsWindow.h @@ -99,6 +99,7 @@ protected: nsIFontMetrics *mFontMetrics; PRBool mVisible; PRBool mDisplayed; + PRBool mIsDestroying; GtkWindowType mBorderStyle;