Spanked the way refcnt'ing was done for event flow; fixed up destruction code a bunch; cleaned up inheritance of addref/release

git-svn-id: svn://10.0.0.236/trunk@26150 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
kipp%netscape.com 1999-04-03 18:39:52 +00:00
parent 7cea9031d0
commit 7e2b20bc02
28 changed files with 189 additions and 236 deletions

View File

@ -27,8 +27,8 @@
#include "nsString.h"
#include "nsStringUtil.h"
NS_IMPL_ADDREF(nsButton)
NS_IMPL_RELEASE(nsButton)
NS_IMPL_ADDREF_INHERITED(nsButton, nsButtonSuper)
NS_IMPL_RELEASE_INHERITED(nsButton, nsButtonSuper)
//-------------------------------------------------------------------------
//
@ -63,16 +63,17 @@ nsButton::~nsButton()
void nsButton::InitCallbacks(char * aName)
{
nsWidget::InitCallbacks();
/* FIXME: we need to unconnect the signals connected from
* nsWidget::InitCallbacks that we provide here */
gtk_signal_connect(GTK_OBJECT(mWidget),
"button_press_event",
GTK_SIGNAL_FUNC(handle_button_press_event),
this);
"button_press_event",
GTK_SIGNAL_FUNC(handle_button_press_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"button_release_event",
GTK_SIGNAL_FUNC(handle_button_release_event),
this);
"button_release_event",
GTK_SIGNAL_FUNC(handle_button_release_event),
this);
}
/**

View File

@ -25,7 +25,8 @@
/**
* Native GTK+ button wrapper
*/
class nsButton : public nsWidget,
#define nsButtonSuper nsWidget
class nsButton : public nsButtonSuper,
public nsIButton
{

View File

@ -22,8 +22,8 @@
#include "nsString.h"
#include "nsStringUtil.h"
NS_IMPL_ADDREF(nsCheckButton)
NS_IMPL_RELEASE(nsCheckButton)
NS_IMPL_ADDREF_INHERITED(nsCheckButton, nsCheckButtonSuper)
NS_IMPL_RELEASE_INHERITED(nsCheckButton, nsCheckButtonSuper)
//-------------------------------------------------------------------------
//

View File

@ -26,7 +26,9 @@
* Native GTK+ Checkbox wrapper
*/
class nsCheckButton : public nsWidget,
#define nsCheckButtonSuper nsWidget
class nsCheckButton : public nsCheckButtonSuper,
public nsICheckButton
{

View File

@ -30,8 +30,8 @@
#define INITIAL_MAX_ITEMS 128
#define ITEMS_GROWSIZE 128
NS_IMPL_ADDREF(nsComboBox)
NS_IMPL_RELEASE(nsComboBox)
NS_IMPL_ADDREF_INHERITED(nsComboBox, nsComboBoxSuper)
NS_IMPL_RELEASE_INHERITED(nsComboBox, nsComboBoxSuper)
//-------------------------------------------------------------------------
//
@ -60,7 +60,9 @@ nsComboBox::~nsComboBox()
g_free(items->data);
}
g_list_free(mItems);
#if 0
gtk_widget_destroy(mCombo);
#endif
}
//-------------------------------------------------------------------------

View File

@ -26,7 +26,8 @@
* Native GTK+ Listbox wrapper
*/
class nsComboBox : public nsWidget,
#define nsComboBoxSuper nsWidget
class nsComboBox : public nsComboBoxSuper,
public nsIListWidget,
public nsIComboBox
{

View File

@ -26,9 +26,6 @@
#include <gtk/gtk.h>
NS_IMPL_ADDREF(nsDialog)
NS_IMPL_RELEASE(nsDialog)
//-------------------------------------------------------------------------
//
// nsDialog constructor
@ -48,6 +45,23 @@ nsDialog::~nsDialog()
{
}
//-------------------------------------------------------------------------
//
// nsDialog addref, release
//
//-------------------------------------------------------------------------
nsrefcnt
nsDialog::AddRef()
{
return nsWindow::AddRef();
}
nsrefcnt
nsDialog::Release()
{
return nsWindow::Release();
}
//-------------------------------------------------------------------------
//
// Create the native GtkDialog widget

View File

@ -137,7 +137,6 @@ void InitAllocationEvent(GtkAllocation *aAlloc,
{
anEvent.message = aEventType;
anEvent.widget = (nsWidget *) p;
NS_ADDREF(anEvent.widget);
anEvent.eventStructType = NS_SIZE_EVENT;
@ -161,7 +160,6 @@ void InitConfigureEvent(GdkEventConfigure *aConf,
{
anEvent.message = aEventType;
anEvent.widget = (nsWidget *) p;
NS_ADDREF(anEvent.widget);
anEvent.eventStructType = NS_SIZE_EVENT;
@ -187,7 +185,6 @@ void InitMouseEvent(GdkEventButton *aGEB,
{
anEvent.message = aEventType;
anEvent.widget = (nsWidget *) p;
NS_ADDREF(anEvent.widget);
anEvent.eventStructType = NS_MOUSE_EVENT;
@ -234,7 +231,6 @@ void InitDrawEvent(GdkRectangle *area,
{
anEvent.message = aEventType;
anEvent.widget = (nsWidget *) p;
NS_ADDREF(anEvent.widget);
anEvent.eventStructType = NS_PAINT_EVENT;
@ -265,7 +261,6 @@ void InitExposeEvent(GdkEventExpose *aGEE,
{
anEvent.message = aEventType;
anEvent.widget = (nsWidget *) p;
NS_ADDREF(anEvent.widget);
anEvent.eventStructType = NS_PAINT_EVENT;
@ -296,7 +291,6 @@ void InitMotionEvent(GdkEventMotion *aGEM,
{
anEvent.message = aEventType;
anEvent.widget = (nsWidget *) p;
NS_ADDREF(anEvent.widget);
anEvent.eventStructType = NS_MOUSE_EVENT;
@ -323,7 +317,6 @@ void InitCrossingEvent(GdkEventCrossing *aGEC,
{
anEvent.message = aEventType;
anEvent.widget = (nsWidget *) p;
NS_ADDREF(anEvent.widget);
anEvent.eventStructType = NS_MOUSE_EVENT;
@ -350,7 +343,6 @@ void InitKeyEvent(GdkEventKey *aGEK,
{
anEvent.message = aEventType;
anEvent.widget = (nsWidget *) p;
NS_ADDREF(anEvent.widget);
anEvent.eventStructType = NS_KEY_EVENT;
@ -389,7 +381,6 @@ void InitFocusEvent(GdkEventFocus *aGEF,
{
anEvent.message = aEventType;
anEvent.widget = (nsWidget *) p;
NS_ADDREF(anEvent.widget);
anEvent.eventStructType = NS_GUI_EVENT;
@ -487,8 +478,9 @@ gint handle_configure_event(GtkWidget *w, GdkEventConfigure *conf, gpointer p)
InitConfigureEvent(conf, p, sevent, NS_SIZE);
nsWindow *win = (nsWindow *)p;
win->AddRef();
win->OnResize(sevent);
win->Release();
return PR_FALSE;
}
@ -500,8 +492,9 @@ gint handle_draw_event(GtkWidget *w, GdkRectangle *area, gpointer p)
InitDrawEvent(area, p, pevent, NS_PAINT);
nsWindow *win = (nsWindow *)p;
win->AddRef();
win->OnPaint(pevent);
win->Release();
UninitDrawEvent(area, p, pevent, NS_PAINT);
@ -517,8 +510,9 @@ gint handle_expose_event(GtkWidget *w, GdkEventExpose *event, gpointer p)
InitExposeEvent(event, p, pevent, NS_PAINT);
nsWindow *win = (nsWindow *)p;
win->AddRef();
win->OnPaint(pevent);
win->Release();
UninitExposeEvent(event, p, pevent, NS_PAINT);
@ -581,7 +575,9 @@ gint handle_button_press_event(GtkWidget *w, GdkEventButton * event, gpointer p)
InitMouseEvent(event, p, mevent, b);
nsWindow *win = (nsWindow *)p;
win->AddRef();
win->DispatchMouseEvent(mevent);
win->Release();
UninitMouseEvent(event, p, mevent, b);
@ -612,7 +608,9 @@ gint handle_button_release_event(GtkWidget *w, GdkEventButton * event, gpointer
InitMouseEvent(event, p, mevent, b);
nsWindow *win = (nsWindow *)p;
win->AddRef();
win->DispatchMouseEvent(mevent);
win->Release();
UninitMouseEvent(event, p, mevent, b);
@ -626,7 +624,9 @@ gint handle_motion_notify_event(GtkWidget *w, GdkEventMotion * event, gpointer p
InitMotionEvent(event, p, mevent, NS_MOUSE_MOVE);
nsWindow *win = (nsWindow *)p;
win->AddRef();
win->DispatchMouseEvent(mevent);
win->Release();
UninitMotionEvent(event, p, mevent, NS_MOUSE_MOVE);
@ -640,7 +640,9 @@ gint handle_enter_notify_event(GtkWidget *w, GdkEventCrossing * event, gpointer
InitCrossingEvent(event, p, mevent, NS_MOUSE_ENTER);
nsWindow *win = (nsWindow *)p;
win->AddRef();
win->DispatchMouseEvent(mevent);
win->Release();
UninitCrossingEvent(event, p, mevent, NS_MOUSE_ENTER);
@ -654,7 +656,9 @@ gint handle_leave_notify_event(GtkWidget *w, GdkEventCrossing * event, gpointer
InitCrossingEvent(event, p, mevent, NS_MOUSE_EXIT);
nsWindow *win = (nsWindow *)p;
win->AddRef();
win->DispatchMouseEvent(mevent);
win->Release();
return PR_TRUE;
}
@ -662,28 +666,34 @@ gint handle_leave_notify_event(GtkWidget *w, GdkEventCrossing * event, gpointer
//==============================================================
gint handle_focus_in_event(GtkWidget *w, GdkEventFocus * event, gpointer p)
{
nsGUIEvent gevent;
InitFocusEvent(event, p, gevent, NS_GOTFOCUS);
nsWindow *win = (nsWindow *)p;
win->DispatchFocus(gevent);
if (!win->IsDestroying()) {
nsGUIEvent gevent;
InitFocusEvent(event, p, gevent, NS_GOTFOCUS);
UninitFocusEvent(event, p, gevent, NS_GOTFOCUS);
win->AddRef();
win->DispatchFocus(gevent);
win->Release();
UninitFocusEvent(event, p, gevent, NS_GOTFOCUS);
}
return PR_TRUE;
}
//==============================================================
gint handle_focus_out_event(GtkWidget *w, GdkEventFocus * event, gpointer p)
{
nsGUIEvent gevent;
InitFocusEvent(event, p, gevent, NS_LOSTFOCUS);
nsWindow *win = (nsWindow *)p;
win->DispatchFocus(gevent);
if (!win->IsDestroying()) {
nsGUIEvent gevent;
InitFocusEvent(event, p, gevent, NS_LOSTFOCUS);
UninitFocusEvent(event, p, gevent, NS_LOSTFOCUS);
win->AddRef();
win->DispatchFocus(gevent);
win->Release();
UninitFocusEvent(event, p, gevent, NS_LOSTFOCUS);
}
return PR_TRUE;
}
@ -694,8 +704,6 @@ void menu_item_activate_handler(GtkWidget *w, gpointer p)
nsIMenuListener *menuListener = nsnull;
nsIMenuItem *menuItem = (nsIMenuItem *)p;
NS_ADDREF(menuItem);
if (menuItem != NULL) {
nsMenuEvent mevent;
mevent.message = NS_MENU_SELECTED;
@ -721,85 +729,6 @@ void menu_item_activate_handler(GtkWidget *w, gpointer p)
}
}
#if 0
//==============================================================
gint nsGtkWidget_Focus_Callback(GtkWidget *w, gpointer p)
{
nsWindow *widgetWindow = (nsWindow*)gtk_object_get_user_data(GTK_OBJECT(w));
nsWindow * widgetWindow = (nsWindow *) p ;
XmAnyCallbackStruct * cbs = (XmAnyCallbackStruct*)call_data;
nsGUIEvent event;
nsGtkWidget_InitNSEvent(cbs->event, p, event,
cbs->reason == XmCR_FOCUS?NS_GOTFOCUS:NS_LOSTFOCUS);
widgetWindow->DispatchFocus(event);
return PR_FALSE;
}
#endif
#if 0
//==============================================================
gint nsGtkWidget_Toggle_Callback(GtkWidget *w, gpointer p)
{
nsWindow *widgetWindow = (nsWindow*)gtk_object_get_user_data(GTK_OBJECT(w));
nsWindow * widgetWindow = (nsWindow *) p ;
if (DBG) fprintf(stderr, "***************** nsGtkWidget_Scrollbar_Callback\n");
nsScrollbarEvent sevent;
XmToggleButtonCallbackStruct * cbs = (XmToggleButtonCallbackStruct*)call_data;
return PR_FALSE;
}
#endif
#if 0
//==============================================================
gint nsGtkWidget_CheckButton_Toggle_Callback(GtkWidget *w, gpointer p)
{
nsCheckButton *checkBtn = (nsCheckButton*)gtk_object_get_user_data(GTK_OBJECT(w));
if (GTK_TOGGLE_BUTTON(w)->active)
checkBtn->Armed();
else
checkBtn->DisArmed();
return PR_FALSE;
}
#endif
#if 0
//==============================================================
gint nsGtkWidget_RadioButton_ArmCallback(GtkWidget *w, gpointer p)
{
nsWindow *widgetWindow = (nsWindow*)gtk_object_get_user_data(GTK_OBJECT(w));
nsRadioButton * radioBtn = (nsRadioButton *) p ;
XmToggleButtonCallbackStruct * cbs = (XmToggleButtonCallbackStruct*)call_data;
radioBtn->Armed();
nsMouseEvent mevent;
nsGtkWidget_InitNSMouseEvent(cbs->event, p, mevent, NS_MOUSE_LEFT_BUTTON_DOWN);
radioBtn->DispatchMouseEvent(mevent);
return PR_FALSE;
}
#endif
#if 0
//==============================================================
gint nsGtkWidget_RadioButton_DisArmCallback(GtkWidget *w, gpointer p)
{
nsWindow *widgetWindow = (nsWindow*)gtk_object_get_user_data(GTK_OBJECT(w));
nsRadioButton * radioBtn = (nsRadioButton *) p ;
nsScrollbarEvent sevent;
XmToggleButtonCallbackStruct * cbs = (XmToggleButtonCallbackStruct*)call_data;
radioBtn->DisArmed();
nsMouseEvent mevent;
nsGtkWidget_InitNSMouseEvent(cbs->event, p, mevent, NS_MOUSE_LEFT_BUTTON_UP);
radioBtn->DispatchMouseEvent(mevent);
return PR_FALSE;
}
#endif
//==============================================================
void handle_scrollbar_value_changed(GtkAdjustment *adj, gpointer p)
@ -818,7 +747,9 @@ void handle_scrollbar_value_changed(GtkAdjustment *adj, gpointer p)
widget->ReleaseNativeData(NS_NATIVE_WINDOW);
#endif
widget->AddRef();
widget->OnScroll(sevent, adj->value);
widget->Release();
/* FIXME we need to set point.* from the event stuff. */
#if 0
@ -882,7 +813,9 @@ gint handle_key_release_event(GtkWidget *w, GdkEventKey* event, gpointer p)
InitKeyEvent(event, p, kevent, NS_KEY_UP);
nsWindow * win = (nsWindow *) p;
win->AddRef();
win->OnKey(kevent);
win->Release();
return PR_TRUE;
}
@ -903,7 +836,9 @@ gint handle_key_press_event(GtkWidget *w, GdkEventKey* event, gpointer p)
InitKeyEvent(event, p, kevent, NS_KEY_DOWN);
nsWindow * win = (nsWindow *) p;
win->AddRef();
win->OnKey(kevent);
win->Release();
return PR_TRUE;
}

View File

@ -27,8 +27,8 @@
#include "nsGtkEventHandler.h"
NS_IMPL_ADDREF(nsLabel)
NS_IMPL_RELEASE(nsLabel)
NS_IMPL_ADDREF_INHERITED(nsLabel, nsLabelSuper)
NS_IMPL_RELEASE_INHERITED(nsLabel, nsLabelSuper)
//-------------------------------------------------------------------------
//

View File

@ -26,7 +26,8 @@
/**
* Native GTK+ Label wrapper
*/
class nsLabel : public nsWidget,
#define nsLabelSuper nsWidget
class nsLabel : public nsLabelSuper,
public nsILabel
{

View File

@ -24,8 +24,8 @@
#include "nsString.h"
#include "nsStringUtil.h"
NS_IMPL_ADDREF(nsListBox)
NS_IMPL_RELEASE(nsListBox)
NS_IMPL_ADDREF_INHERITED(nsListBox, nsListBoxSuper)
NS_IMPL_RELEASE_INHERITED(nsListBox, nsListBoxSuper)
//-------------------------------------------------------------------------
//
@ -36,6 +36,7 @@ nsListBox::nsListBox() : nsWidget(), nsIListWidget(), nsIListBox()
{
NS_INIT_REFCNT();
mMultiSelect = PR_FALSE;
mCList = nsnull;
// mBackground = NS_RGB(124, 124, 124);
}
@ -46,11 +47,13 @@ nsListBox::nsListBox() : nsWidget(), nsIListWidget(), nsIListBox()
//-------------------------------------------------------------------------
nsListBox::~nsListBox()
{
#if 0
if (mCList)
{
::gtk_widget_destroy(mCList);
mCList = nsnull;
}
#endif
}
//-------------------------------------------------------------------------

View File

@ -25,8 +25,8 @@
/**
* Native GTK+ Listbox wrapper
*/
class nsListBox : public nsWidget,
#define nsListBoxSuper nsWidget
class nsListBox : public nsListBoxSuper,
public nsIListWidget,
public nsIListBox
{

View File

@ -26,8 +26,8 @@
#include "nsGtkEventHandler.h"
NS_IMPL_ADDREF(nsRadioButton)
NS_IMPL_RELEASE(nsRadioButton)
NS_IMPL_ADDREF_INHERITED(nsRadioButton, nsRadioButtonSuper)
NS_IMPL_RELEASE_INHERITED(nsRadioButton, nsRadioButtonSuper)
//-------------------------------------------------------------------------
//
@ -48,8 +48,10 @@ nsRadioButton::nsRadioButton() : nsWidget(), nsIRadioButton()
//-------------------------------------------------------------------------
nsRadioButton::~nsRadioButton()
{
#if 0
if (mLabel)
gtk_widget_destroy(mLabel);
#endif
}

View File

@ -25,7 +25,8 @@
/**
* Native GTK+ Radiobutton wrapper
*/
class nsRadioButton : public nsWidget,
#define nsRadioButtonSuper nsWidget
class nsRadioButton : public nsRadioButtonSuper,
public nsIRadioButton
{

View File

@ -25,8 +25,8 @@
#include "nsGtkEventHandler.h"
NS_IMPL_ADDREF (nsScrollbar);
NS_IMPL_RELEASE (nsScrollbar);
NS_IMPL_ADDREF_INHERITED(nsScrollbar, nsScrollbarSuper);
NS_IMPL_RELEASE_INHERITED(nsScrollbar, nsScrollbarSuper);
//-------------------------------------------------------------------------
//

View File

@ -25,8 +25,8 @@
/**
* Native GTK+ scrollbar wrapper.
*/
class nsScrollbar : public nsWidget,
#define nsScrollbarSuper nsWidget
class nsScrollbar : public nsScrollbarSuper,
public nsIScrollbar
{

View File

@ -24,8 +24,8 @@
#include "nsStringUtil.h"
NS_IMPL_ADDREF(nsTabWidget)
NS_IMPL_RELEASE(nsTabWidget)
NS_IMPL_ADDREF_INHERITED(nsTabWidget, nsTabWidgetSuper)
NS_IMPL_RELEASE_INHERITED(nsTabWidget, nsTabWidgetSuper)
//-------------------------------------------------------------------------
//

View File

@ -26,8 +26,8 @@
/**
* Native Win32 tab control wrapper
*/
class nsTabWidget : public nsWidget,
#define nsTabWidgetSuper nsWidget
class nsTabWidget : public nsTabWidgetSuper,
public nsITabWidget
{
@ -35,10 +35,10 @@ public:
nsTabWidget();
virtual ~nsTabWidget();
// nsISupports
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsITabWidget part
NS_IMETHOD SetTabs(PRUint32 aNumberOfTabs, const nsString aTabLabels[]);

View File

@ -27,9 +27,6 @@
#define DBG 0
NS_IMPL_ADDREF(nsTextAreaWidget)
NS_IMPL_RELEASE(nsTextAreaWidget)
//-------------------------------------------------------------------------
//
// nsTextAreaWidget constructor

View File

@ -34,9 +34,7 @@ public:
nsTextAreaWidget();
virtual ~nsTextAreaWidget();
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
// nsISupports
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
virtual PRBool OnPaint(nsPaintEvent & aEvent);

View File

@ -28,6 +28,9 @@
#define DBG 0
NS_IMPL_ADDREF_INHERITED(nsTextHelper, nsTextHelperSuper)
NS_IMPL_RELEASE_INHERITED(nsTextHelper, nsTextHelperSuper)
//-------------------------------------------------------------------------
//
// nsTextHelper constructor

View File

@ -25,8 +25,8 @@
/**
* Base class for nsTextAreaWidget and nsTextWidget
*/
class nsTextHelper : public nsWidget,
#define nsTextHelperSuper nsWidget
class nsTextHelper : public nsTextHelperSuper,
public nsITextAreaWidget,
public nsITextWidget
{
@ -34,6 +34,11 @@ class nsTextHelper : public nsWidget,
public:
nsTextHelper();
virtual ~nsTextHelper();
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD SelectAll();
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
NS_IMETHOD SetMaxTextLength(PRUint32 aChars);

View File

@ -29,9 +29,6 @@
extern int mIsPasswordCallBacksInstalled;
NS_IMPL_ADDREF(nsTextWidget)
NS_IMPL_RELEASE(nsTextWidget)
//-------------------------------------------------------------------------
//
// nsTextWidget constructor

View File

@ -37,8 +37,6 @@ public:
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnResize(nsSizeEvent &aEvent);

View File

@ -93,6 +93,10 @@ NS_METHOD nsWidget::ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect)
NS_IMETHODIMP nsWidget::Destroy(void)
{
#ifdef NOISY_WIDGET_DESTROY
printf("nsWidget::Destroy:%p: isDestroying=%s widget=%p parent=%p\n",
this, mIsDestroying ? "yes" : "no", mWidget, mParent);
#endif
GtkAllocation *old_size = NULL;
if (!mIsDestroying) {
nsBaseWidget::Destroy();
@ -122,12 +126,13 @@ void nsWidget::OnDestroy()
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();
// 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
nsrefcnt old = mRefCnt;
mRefCnt = 99;
DispatchStandardEvent(NS_DESTROY);
Release();
mRefCnt = old;
}
}
@ -269,13 +274,9 @@ PRBool nsWidget::OnResize(nsRect &aRect)
event.point.y = mWidget->allocation.y;
event.time = 0;
PRBool result = DispatchWindowEvent(&event);
// XXX why does this always crash? maybe we need to add
// a ref in the dispatch code? check the windows
// code for a reference
//NS_RELEASE(event.widget);
return result;
}
return PR_FALSE;
return PR_FALSE;
}
//------
@ -294,7 +295,6 @@ PRBool nsWidget::OnMove(PRInt32 aX, PRInt32 aY)
event.point.y = aY;
event.eventStructType = NS_GUI_EVENT;
PRBool result = DispatchWindowEvent(&event);
// NS_RELEASE(event.widget);
return result;
}
@ -677,6 +677,8 @@ nsresult nsWidget::CreateWidget(nsIWidget *aParent,
BaseCreate(aParent, aRect, aHandleEventFunction, aContext,
aAppShell, aToolkit, aInitData);
mParent = aParent;
NS_IF_ADDREF(mParent);
if (aNativeParent) {
parentWidget = GTK_WIDGET(aNativeParent);
@ -817,7 +819,6 @@ void nsWidget::ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY)
void nsWidget::InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint)
{
event.widget = this;
NS_IF_ADDREF(event.widget);
GdkEventConfigure *ge;
ge = (GdkEventConfigure*)gtk_get_current_event();
@ -880,9 +881,7 @@ PRBool nsWidget::DispatchStandardEvent(PRUint32 aMsg)
nsGUIEvent event;
event.eventStructType = NS_GUI_EVENT;
InitEvent(event, aMsg);
PRBool result = DispatchWindowEvent(&event);
NS_IF_RELEASE(event.widget);
return result;
}
@ -913,6 +912,7 @@ NS_IMETHODIMP nsWidget::DispatchEvent(nsGUIEvent *event,
aStatus = mEventListener->ProcessEvent(*event);
}
NS_RELEASE(event->widget);
return NS_OK;
}

View File

@ -137,7 +137,7 @@ class nsWidget : public nsBaseWidget
PRBool DispatchWindowEvent(nsGUIEvent* event);
GtkWidget *mWidget;
nsWidget *mParent;
nsIWidget *mParent;
// This is the composite update area (union of all the calls to
// Invalidate)

View File

@ -39,10 +39,6 @@
//#define DBG 0
// for nsISupports
NS_IMPL_ADDREF(nsWindow)
NS_IMPL_RELEASE(nsWindow)
/**
* Implement the standard QueryInterface for NS_IWIDGET_IID and NS_ISUPPORTS_IID
* @modify gpk 8/4/98
@ -98,14 +94,16 @@ nsWindow::nsWindow()
nsWindow::~nsWindow()
{
mIsDestroying = PR_TRUE;
if (mShell)
{
if (GTK_IS_WIDGET(mShell))
gtk_widget_destroy(mShell);
mShell = nsnull;
if (nsnull != mShell) {
Destroy();
}
}
PRBool nsWindow::IsChild() const
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
void nsWindow::ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY)
{
@ -146,13 +144,10 @@ NS_METHOD nsWindow::RemoveTooltips()
NS_METHOD nsWindow::Destroy()
{
// disconnect from the parent
// Call base class first...
nsWidget::Destroy();
if (mIsDestroying == PR_TRUE) {
nsBaseWidget::Destroy();
if (PR_FALSE == mOnDestroyCalled)
OnDestroy();
if (mShell) {
if (GTK_IS_WIDGET(mShell))
gtk_widget_destroy(mShell);
@ -163,24 +158,6 @@ NS_METHOD nsWindow::Destroy()
return NS_OK;
}
void nsWindow::OnDestroy()
{
mOnDestroyCalled = PR_TRUE;
// release references to children, device context, toolkit, and app shell
nsBaseWidget::OnDestroy();
// dispatch the event
if (mIsDestroying == PR_TRUE) {
// 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();
DispatchStandardEvent(NS_DESTROY);
Release();
}
}
gint handle_delete_event(GtkWidget *w, GdkEventAny *e, nsWindow *win)
{
@ -287,53 +264,53 @@ NS_METHOD nsWindow::CreateNative(GtkWidget *parentWidget)
void nsWindow::InitCallbacks(char * aName)
{
gtk_signal_connect_after(GTK_OBJECT(mWidget),
"size_allocate",
GTK_SIGNAL_FUNC(handle_size_allocate),
this);
"size_allocate",
GTK_SIGNAL_FUNC(handle_size_allocate),
this);
gtk_signal_connect_after(GTK_OBJECT(mWidget),
"button_press_event",
GTK_SIGNAL_FUNC(handle_button_press_event),
this);
"button_press_event",
GTK_SIGNAL_FUNC(handle_button_press_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"button_release_event",
GTK_SIGNAL_FUNC(handle_button_release_event),
this);
GTK_SIGNAL_FUNC(handle_button_release_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"motion_notify_event",
GTK_SIGNAL_FUNC(handle_motion_notify_event),
this);
GTK_SIGNAL_FUNC(handle_motion_notify_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"enter_notify_event",
GTK_SIGNAL_FUNC(handle_enter_notify_event),
this);
GTK_SIGNAL_FUNC(handle_enter_notify_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"leave_notify_event",
GTK_SIGNAL_FUNC(handle_leave_notify_event),
this);
GTK_SIGNAL_FUNC(handle_leave_notify_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"draw",
GTK_SIGNAL_FUNC(handle_draw_event),
this);
GTK_SIGNAL_FUNC(handle_draw_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"expose_event",
GTK_SIGNAL_FUNC(handle_expose_event),
this);
GTK_SIGNAL_FUNC(handle_expose_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"key_press_event",
GTK_SIGNAL_FUNC(handle_key_press_event),
this);
GTK_SIGNAL_FUNC(handle_key_press_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"key_release_event",
GTK_SIGNAL_FUNC(handle_key_release_event),
this);
GTK_SIGNAL_FUNC(handle_key_release_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"focus_in_event",
GTK_SIGNAL_FUNC(handle_focus_in_event),
this);
GTK_SIGNAL_FUNC(handle_focus_in_event),
this);
gtk_signal_connect(GTK_OBJECT(mWidget),
"focus_out_event",
GTK_SIGNAL_FUNC(handle_focus_out_event),
this);
GTK_SIGNAL_FUNC(handle_focus_out_event),
this);
}
//-------------------------------------------------------------------------
@ -508,3 +485,14 @@ NS_METHOD nsWindow::SetMenuBar(nsIMenuBar * aMenuBar)
return NS_OK;
}
//----------------------------------------------------------------------
ChildWindow::ChildWindow()
{
}
PRBool ChildWindow::IsChild() const
{
return PR_TRUE;
}

View File

@ -45,8 +45,6 @@ public:
virtual ~nsWindow();
// nsIsupports
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
@ -71,8 +69,15 @@ public:
NS_IMETHOD Destroy(void);
virtual PRBool IsChild() { return(PR_FALSE); };
virtual void SetIsDestroying( PRBool val) { mIsDestroying = val; };
virtual PRBool IsChild() const;
void SetIsDestroying(PRBool val) {
mIsDestroying = val;
}
PRBool IsDestroying() const {
return mIsDestroying;
}
// Utility methods
virtual PRBool OnPaint(nsPaintEvent &event);
@ -85,7 +90,6 @@ public:
char gInstanceClassName[256];
protected:
virtual void OnDestroy();
virtual void InitCallbacks(char * aName = nsnull);
NS_IMETHOD CreateNative(GtkWidget *parentWidget);
@ -113,9 +117,9 @@ protected:
// A child window is a window with different style
//
class ChildWindow : public nsWindow {
public:
ChildWindow() {};
virtual PRBool IsChild() { return(PR_TRUE); };
public:
ChildWindow();
virtual PRBool IsChild() const;
};
#endif // Window_h__