diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 4d0d6ce85a..dc9c50fcd8 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -48,6 +48,7 @@ #include "wx/dcclient.h" #include "wx/rawbmp.h" #include "wx/scopedarray.h" +#include "wx/stack.h" #include // needed by GET_X_LPARAM and GET_Y_LPARAM macros @@ -132,9 +133,12 @@ wxEND_EVENT_TABLE() // module globals // ---------------------------------------------------------------------------- -// This is used to check if the toolbar itself doesn't get destroyed while -// handling its event. -static wxToolBar* gs_liveToolbar = NULL; +namespace +{ + // Global stack used to track all active toolbars in the chain to check if + // the toolbar itself doesn't get destroyed while handling its event. + wxStack gs_liveToolbars; +} // anonymous namespace // ---------------------------------------------------------------------------- // private classes @@ -526,8 +530,8 @@ void wxToolBar::Recreate() wxToolBar::~wxToolBar() { // Indicate to the code in MSWCommand() that the toolbar is destroyed. - if ( gs_liveToolbar == this ) - gs_liveToolbar = NULL; + if ( !gs_liveToolbars.empty() && gs_liveToolbars.top() == this ) + gs_liveToolbars.pop(); // we must refresh the frame size when the toolbar is deleted but the frame // is not - otherwise toolbar leaves a hole in the place it used to occupy @@ -1503,18 +1507,18 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id_) // global variable: if it gets reset from our dtor, we will know that the // toolbar was destroyed by this handler and that we can't use this object // any more. - gs_liveToolbar = this; + gs_liveToolbars.push(this); bool allowLeftClick = OnLeftClick(id, toggled); - if ( gs_liveToolbar != this ) + if ( gs_liveToolbars.empty() || gs_liveToolbars.top() != this ) { // Bail out, we can't touch any member fields in the already // destroyed object anyhow. return true; } - gs_liveToolbar = NULL; + gs_liveToolbars.pop(); // Check if the tool hasn't been deleted in the event handler (notice that // it's also possible that this tool was deleted and a new tool with the