set m_isBeingDeleted to true (only) in SendDestroyEvent(); call it as early as possible during the window destruction to ensure that destroy event handlers can still access the full window object

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58246 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-01-20 18:33:33 +00:00
parent 8c2654ce3d
commit c6212a0cb7
42 changed files with 71 additions and 94 deletions

View File

@@ -35,7 +35,6 @@ public:
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxControlNameStr);
virtual ~wxControl();
// Simulates an event
virtual void Command(wxCommandEvent& event) { ProcessCommand(event); }

View File

@@ -32,7 +32,6 @@ public:
{
Create( pParent, vId, rPos, rSize, lStyle, rValidator, rsName );
}
virtual ~wxControl();
bool Create( wxWindow* pParent
,wxWindowID vId

View File

@@ -35,7 +35,6 @@ public:
const wxSize& size = wxDefaultSize, long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxControlNameStr);
virtual ~wxControl();
// Simulates an event
virtual void Command(wxCommandEvent& event) { ProcessCommand(event); }

View File

@@ -1402,7 +1402,8 @@ protected:
void SatisfyConstraints();
#endif // wxUSE_CONSTRAINTS
// Send the wxWindowDestroyEvent
// Send the wxWindowDestroyEvent if not done yet and sets m_isBeingDeleted
// to true
void SendDestroyEvent();
// returns the main window of composite control; this is the window

View File

@@ -2898,7 +2898,7 @@ void wxAuiNotebook::InitNotebook(long style)
wxAuiNotebook::~wxAuiNotebook()
{
// Indicate we're deleting pages
m_isBeingDeleted = true;
SendDestroyEvent();
while ( GetPageCount() > 0 )
DeletePage(0);

View File

@@ -943,7 +943,6 @@ void wxWindowCocoa::Init()
m_cocoaNSView = NULL;
m_cocoaHider = NULL;
m_wxCocoaScrollView = NULL;
m_isBeingDeleted = false;
m_isInPaint = false;
m_visibleTrackingRectManager = NULL;
}

View File

@@ -209,7 +209,9 @@ wxWindowBase::wxWindowBase()
// Whether we're using the current theme for this window (wxGTK only for now)
m_themeEnabled = false;
// VZ: this one shouldn't exist...
// This is set to true by SendDestroyEvent() which should be called by the
// most derived class to ensure that the destruction event is sent as soon
// as possible to allow its handlers to still see the undestroyed window
m_isBeingDeleted = false;
m_freezeCount = 0;
@@ -387,6 +389,16 @@ bool wxWindowBase::IsBeingDeleted() const
void wxWindowBase::SendDestroyEvent()
{
if ( m_isBeingDeleted )
{
// we could have been already called from a more derived class dtor,
// e.g. ~wxTLW calls us and so does ~wxWindow and the latter call
// should be simply ignored
return;
}
m_isBeingDeleted = true;
wxWindowDestroyEvent event;
event.SetEventObject(this);
event.SetId(GetId());

View File

@@ -153,7 +153,7 @@ bool wxNonOwnedWindow::Create(wxWindow *parent,
wxNonOwnedWindow::~wxNonOwnedWindow()
{
m_isBeingDeleted = true;
SendDestroyEvent();
// destroy all children before we destroy the underlying DirectFB window,
// so that if any of them does something with the TLW, it will still work:

View File

@@ -88,8 +88,6 @@ wxWindowDFB::~wxWindowDFB()
{
SendDestroyEvent();
m_isBeingDeleted = true;
if ( gs_mouseCapture == this )
ReleaseMouse();

View File

@@ -85,8 +85,6 @@ bool wxDialog::Show( bool show )
wxDialog::~wxDialog()
{
m_isBeingDeleted = true;
// if the dialog is modal, this will end its event loop
if ( IsModal() )
EndModal(wxID_CANCEL);

View File

@@ -56,7 +56,8 @@ bool wxFrame::Create( wxWindow *parent,
wxFrame::~wxFrame()
{
m_isBeingDeleted = true;
SendDestroyEvent();
DeleteAllBars();
}

View File

@@ -665,7 +665,7 @@ wxTopLevelWindowGTK::~wxTopLevelWindowGTK()
RemoveGrab();
}
m_isBeingDeleted = true;
SendDestroyEvent();
// it may also be GtkScrolledWindow in the case of an MDI child
if (GTK_IS_WINDOW(m_widget))

View File

@@ -2040,9 +2040,8 @@ void wxWindowGTK::Init()
m_height = 0;
m_hasVMT = false;
m_isBeingDeleted = false;
m_showOnIdle= false;
m_showOnIdle = false;
m_noExpose = false;
m_nativeSizeEvent = false;
@@ -2210,7 +2209,6 @@ wxWindowGTK::~wxWindowGTK()
if ( gs_deferredFocusOut == this )
gs_deferredFocusOut = NULL;
m_isBeingDeleted = true;
m_hasVMT = false;
// destroy children before destroying this window itself

View File

@@ -229,7 +229,8 @@ bool wxFrame::Create( wxWindow *parent,
wxFrame::~wxFrame()
{
m_isBeingDeleted = true;
SendDestroyEvent();
DeleteAllBars();
}

View File

@@ -660,7 +660,7 @@ wxTopLevelWindowGTK::~wxTopLevelWindowGTK()
RemoveGrab();
}
m_isBeingDeleted = true;
SendDestroyEvent();
// it may also be GtkScrolledWindow in the case of an MDI child
if (GTK_IS_WINDOW(m_widget))

View File

@@ -2437,7 +2437,6 @@ void wxWindowGTK::Init()
m_sizeSet = false;
m_hasVMT = false;
m_needParent = true;
m_isBeingDeleted = false;
m_noExpose = false;
m_nativeSizeEvent = false;
@@ -2613,7 +2612,6 @@ wxWindowGTK::~wxWindowGTK()
if ( g_delayedFocus == this )
g_delayedFocus = NULL;
m_isBeingDeleted = true;
m_hasVMT = false;
// destroy children before destroying this window itself

View File

@@ -559,8 +559,6 @@ wxWindowMGL::~wxWindowMGL()
{
SendDestroyEvent();
m_isBeingDeleted = true;
if ( gs_mouseCapture == this )
ReleaseMouse();

View File

@@ -181,7 +181,7 @@ void wxDialog::SetModal(bool flag)
wxDialog::~wxDialog()
{
m_isBeingDeleted = true;
SendDestroyEvent();
// if the dialog is modal, this will end its event loop
Show(false);

View File

@@ -253,7 +253,7 @@ bool wxFrame::XmDoCreateTLW(wxWindow* WXUNUSED(parent),
wxFrame::~wxFrame()
{
m_isBeingDeleted = true;
SendDestroyEvent();
if (m_clientArea)
{

View File

@@ -345,11 +345,11 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id,
// Destructor
wxWindow::~wxWindow()
{
SendDestroyEvent();
if (g_captureWindow == this)
g_captureWindow = NULL;
m_isBeingDeleted = true;
// Motif-specific actions first
WXWidget wMain = GetMainWidget();
if ( wMain )

View File

@@ -59,15 +59,6 @@ IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
// wxControl implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxControl ctor/dtor
// ----------------------------------------------------------------------------
wxControl::~wxControl()
{
m_isBeingDeleted = true;
}
// ----------------------------------------------------------------------------
// control window creation
// ----------------------------------------------------------------------------

View File

@@ -192,8 +192,6 @@ bool wxDialog::Create(wxWindow *parent,
wxDialog::~wxDialog()
{
m_isBeingDeleted = true;
// this will also reenable all the other windows for a modal dialog
Show(false);

View File

@@ -209,7 +209,8 @@ bool wxFrame::Create(wxWindow *parent,
wxFrame::~wxFrame()
{
m_isBeingDeleted = true;
SendDestroyEvent();
DeleteAllBars();
}

View File

@@ -254,7 +254,7 @@ bool wxRadioBox::Create(wxWindow *parent,
wxRadioBox::~wxRadioBox()
{
m_isBeingDeleted = true;
SendDestroyEvent();
delete m_radioButtons;
if ( m_dummyHwnd )

View File

@@ -599,6 +599,8 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent,
wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
{
SendDestroyEvent();
#if defined(__SMARTPHONE__) || defined(__POCKETPC__)
SHACTIVATEINFO* info = (SHACTIVATEINFO*) m_activateInfo;
delete info;

View File

@@ -518,7 +518,6 @@ bool wxWindowMSW::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
void wxWindowMSW::Init()
{
// MSW specific
m_isBeingDeleted = false;
m_oldWndProc = NULL;
m_mouseInWindow = false;
m_lastKeydownProcessed = false;
@@ -540,7 +539,7 @@ void wxWindowMSW::Init()
// Destructor
wxWindowMSW::~wxWindowMSW()
{
m_isBeingDeleted = true;
SendDestroyEvent();
#ifndef __WXUNIVERSAL__
// VS: make sure there's no wxFrame with last focus set to us:
@@ -3949,8 +3948,6 @@ bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT WXUNUSED_IN_WINCE(cs),
bool wxWindowMSW::HandleDestroy()
{
SendDestroyEvent();
// delete our drop target if we've got one
#if wxUSE_DRAG_AND_DROP
if ( m_dropTarget != NULL )

View File

@@ -60,11 +60,6 @@ bool wxControl::Create( wxWindow* pParent,
return bRval;
} // end of wxControl::Create
wxControl::~wxControl()
{
m_isBeingDeleted = true;
}
bool wxControl::OS2CreateControl( const wxChar* zClassname,
const wxString& rsLabel,
const wxPoint& rPos,

View File

@@ -147,7 +147,7 @@ void wxDialog::SetModal(bool WXUNUSED(bFlag))
wxDialog::~wxDialog()
{
m_isBeingDeleted = true;
SendDestroyEvent();
// this will also reenable all the other windows for a modal dialog
Show(false);

View File

@@ -127,7 +127,8 @@ bool wxFrame::Create( wxWindow* pParent,
wxFrame::~wxFrame()
{
m_isBeingDeleted = true;
SendDestroyEvent();
DeleteAllBars();
} // end of wxFrame::~wxFrame

View File

@@ -76,7 +76,7 @@ wxRadioBox::wxRadioBox()
wxRadioBox::~wxRadioBox()
{
m_isBeingDeleted = true;
SendDestroyEvent();
if (m_hWnd)
wxRemoveHandleAssociation(this);

View File

@@ -334,7 +334,7 @@ void wxWindowOS2::Init()
//
wxWindowOS2::~wxWindowOS2()
{
m_isBeingDeleted = true;
SendDestroyEvent();
for (wxWindow* pWin = GetParent(); pWin; pWin = pWin->GetParent())
{

View File

@@ -63,11 +63,6 @@ bool wxControl::Create( wxWindow *parent,
return rval;
}
wxControl::~wxControl()
{
m_isBeingDeleted = true;
}
bool wxControl::ProcessCommand( wxCommandEvent &event )
{
// Tries:

View File

@@ -4,7 +4,7 @@
// Drawer windows appear under their parent window and
// behave like a drawer, opening and closing to reveal
// content that does not need to be visible at all times.
// Author: Jason Bagley
// Author: Jason Bagley
// Modified by: Ryan Norton (To make it work :), plus bug fixes)
// Created: 2004-30-01
// RCS-ID: $Id$
@@ -40,17 +40,17 @@ wxDrawerWindow::wxDrawerWindow()
}
wxDrawerWindow::~wxDrawerWindow()
{
m_isBeingDeleted = TRUE;
this->Show(FALSE);
{
SendDestroyEvent();
Show(FALSE);
}
bool wxDrawerWindow::Create(wxWindow *parent,
wxWindowID id, const wxString& title,
wxSize size, wxDirection edge, const wxString& name)
{
wxASSERT_MSG(NULL != parent, wxT("wxDrawerWindows must be attached to a parent window."));
// Constrain the drawer size to the parent window.
const wxSize parentSize(parent->GetClientSize());
if (wxLEFT == edge || wxRIGHT == edge)
@@ -63,25 +63,25 @@ bool wxDrawerWindow::Create(wxWindow *parent,
if (size.GetWidth() > parentSize.GetWidth())
size.SetWidth(parentSize.GetWidth() - (kLeadingOffset + kTrailingOffset));
}
// Create the drawer window.
// Create the drawer window.
const wxPoint pos(0, 0);
const wxSize dummySize(0,0);
const long style = wxFRAME_DRAWER;
bool success = wxNonOwnedWindow::Create(parent, id, pos, size, style, name);
if (success)
{
// this->MacCreateRealWindow(pos, size, style, name);
success = (GetWXWindow() != NULL);
}
if (success)
{
// Use drawer brush.
SetBackgroundColour( wxColour( wxMacCreateCGColorFromHITheme( kThemeBrushDrawerBackground ) ) );
::SetThemeWindowBackground((WindowRef)GetWXWindow(), kThemeBrushDrawerBackground, false);
// Leading and trailing offset are gaps from parent window edges
// to where the drawer starts.
::SetDrawerOffsets((WindowRef)GetWXWindow() , kLeadingOffset, kTrailingOffset);
@@ -90,7 +90,7 @@ bool wxDrawerWindow::Create(wxWindow *parent,
// Is there a better way to get the parent's WindowRef?
wxTopLevelWindow* tlwParent = wxDynamicCast(parent, wxTopLevelWindow);
if (NULL != tlwParent)
{
{
OSStatus status = ::SetDrawerParent((WindowRef) GetWXWindow(),
(WindowRef)tlwParent->GetWXWindow());
success = (noErr == status);
@@ -98,7 +98,7 @@ bool wxDrawerWindow::Create(wxWindow *parent,
else
success = false;
}
return success && SetPreferredEdge(edge);
}
@@ -152,15 +152,15 @@ OptionBits DirectionToWindowEdge(wxDirection direction)
case wxTOP:
edge = kWindowEdgeTop;
break;
case wxBOTTOM:
edge = kWindowEdgeBottom;
break;
case wxRIGHT:
edge = kWindowEdgeRight;
break;
case wxLEFT:
default:
edge = kWindowEdgeLeft;
@@ -177,23 +177,23 @@ wxDirection WindowEdgeToDirection(OptionBits edge)
case kWindowEdgeTop:
direction = wxTOP;
break;
case kWindowEdgeBottom:
direction = wxBOTTOM;
break;
case kWindowEdgeRight:
direction = wxRIGHT;
break;
case kWindowEdgeDefault: // store current preferred and return that here?
case kWindowEdgeLeft:
default:
direction = wxLEFT;
break;
}
return direction;
}
#endif // defined( __WXMAC__ )
#endif // defined( __WXMAC__ )

View File

@@ -61,7 +61,8 @@ bool wxFrame::Create(wxWindow *parent,
wxFrame::~wxFrame()
{
m_isBeingDeleted = true;
SendDestroyEvent();
DeleteAllBars();
}
@@ -362,7 +363,7 @@ void wxFrame::PositionToolBar()
int cw, ch;
GetSize( &cw , &ch ) ;
int statusX = 0 ;
int statusY = 0 ;

View File

@@ -71,7 +71,7 @@ void wxDialog::SetModal( bool flag )
wxDialog::~wxDialog()
{
m_isBeingDeleted = true;
SendDestroyEvent();
// if the dialog is modal, this will end its event loop
Show(false);

View File

@@ -151,7 +151,7 @@ bool wxNonOwnedWindow::Create(wxWindow *parent,
wxNonOwnedWindow::~wxNonOwnedWindow()
{
m_isBeingDeleted = true;
SendDestroyEvent();
wxRemoveWXWindowAssociation( this ) ;

View File

@@ -52,7 +52,7 @@ wxRadioBox::wxRadioBox()
wxRadioBox::~wxRadioBox()
{
m_isBeingDeleted = true;
SendDestroyEvent();
wxRadioButton *next, *current;
@@ -411,7 +411,7 @@ void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
totWidth = GetColumnCount() * (maxWidth + charWidth);
wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) ) ;
// change the width / height only when specified
if ( width == wxDefaultCoord )
{
@@ -502,7 +502,7 @@ wxSize wxRadioBox::DoGetBestSize() const
wxSize sz = DoGetSizeFromClientSize( wxSize( totWidth, totHeight ) );
totWidth = sz.x;
totHeight = sz.y;
// optimum size is an additional 5 pt border to all sides
totWidth += 10;
totHeight += 10;

View File

@@ -141,8 +141,6 @@ wxWindowMac::~wxWindowMac()
{
SendDestroyEvent();
m_isBeingDeleted = true;
MacInvalidateBorders() ;
#ifndef __WXUNIVERSAL__

View File

@@ -77,8 +77,9 @@ void wxControl::Init()
wxControl::~wxControl()
{
SendDestroyEvent();
SetLabel(wxEmptyString);
m_isBeingDeleted = true;
DestroyChildren();

View File

@@ -53,8 +53,6 @@ void wxDialog::Init()
wxDialog::~wxDialog()
{
m_isBeingDeleted = true;
// if the dialog is modal, this will end its event loop
Show(false);

View File

@@ -224,7 +224,7 @@ bool wxWindow::Create(wxWindow *parent,
wxWindow::~wxWindow()
{
m_isBeingDeleted = true;
SendDestroyEvent();
#if wxUSE_SCROLLBAR
// clear pointers to scrollbar before deleting the children: they are

View File

@@ -350,8 +350,6 @@ wxWindowX11::~wxWindowX11()
if (g_captureWindow == this)
g_captureWindow = NULL;
m_isBeingDeleted = true;
DestroyChildren();
if (m_clientWindow != m_mainWindow)