From 2187eef5bb7a81ee3b2738a312f4ecfceb49bded Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Wed, 26 Mar 2003 22:22:55 +0000 Subject: [PATCH] Calling a virtual function from a destructor is not good: rearranged code to avoid it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19826 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/motif/toplevel.h | 2 ++ src/motif/dialog.cpp | 4 ++++ src/motif/frame.cpp | 10 +++++++--- src/motif/toplevel.cpp | 7 ++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/wx/motif/toplevel.h b/include/wx/motif/toplevel.h index 6d16717756..61c26d82e8 100644 --- a/include/wx/motif/toplevel.h +++ b/include/wx/motif/toplevel.h @@ -60,6 +60,8 @@ public: protected: // common part of all constructors void Init(); + // common part of wxDialog/wxFrame destructors + void PreDestroy(); private: // both these functions should be pure virtual diff --git a/src/motif/dialog.cpp b/src/motif/dialog.cpp index def4c93d14..ab5c7eeccc 100644 --- a/src/motif/dialog.cpp +++ b/src/motif/dialog.cpp @@ -208,6 +208,7 @@ void wxDialog::SetModal(bool flag) wxDialog::~wxDialog() { m_isBeingDeleted = TRUE; + delete m_eventLoop; if (m_mainWidget) @@ -221,6 +222,9 @@ wxDialog::~wxDialog() { XtUnmapWidget((Widget) m_mainWidget); } + + PreDestroy(); + DoDestroy(); } void wxDialog::DoDestroy() diff --git a/src/motif/frame.cpp b/src/motif/frame.cpp index 18dc34e554..978b6e6200 100644 --- a/src/motif/frame.cpp +++ b/src/motif/frame.cpp @@ -310,15 +310,19 @@ wxFrame::~wxFrame() delete m_frameStatusBar; m_frameStatusBar = NULL; } + + PreDestroy(); + DoDestroy(); } void wxFrame::DoDestroy() { Widget frameShell = (Widget)GetShellWidget(); - XtRemoveEventHandler( frameShell, StructureNotifyMask, - False, (XtEventHandler)wxFrameMapProc, - (XtPointer)this ); + if( frameShell ) + XtRemoveEventHandler( frameShell, StructureNotifyMask, + False, (XtEventHandler)wxFrameMapProc, + (XtPointer)this ); if( m_clientArea ) { diff --git a/src/motif/toplevel.cpp b/src/motif/toplevel.cpp index 6d1b385573..031a3c23dd 100644 --- a/src/motif/toplevel.cpp +++ b/src/motif/toplevel.cpp @@ -64,7 +64,7 @@ static void wxTLWEventHandler( Widget wid, // wxTopLevelWindowMotif implementation // =========================================================================== -wxTopLevelWindowMotif::~wxTopLevelWindowMotif() +void wxTopLevelWindowMotif::PreDestroy() { wxTopLevelWindows.DeleteObject(this); @@ -85,9 +85,10 @@ wxTopLevelWindowMotif::~wxTopLevelWindowMotif() wxTLWEventHandler, (XtPointer)this ); } +} - DoDestroy(); - +wxTopLevelWindowMotif::~wxTopLevelWindowMotif() +{ SetMainWidget( (WXWidget)0 ); // If this is the last top-level window, exit. -- 2.45.2