From 03c4145fa8962c804c2047698d1cad07139e5a8d Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Sat, 19 Apr 2014 14:44:59 -0500 Subject: [PATCH] hook top frame with KIWAY::playerDestroyHandler() --- common/kiway.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- include/kiway.h | 11 +++++++---- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/common/kiway.cpp b/common/kiway.cpp index e0ff171aaa..6e48c92dc5 100644 --- a/common/kiway.cpp +++ b/common/kiway.cpp @@ -38,11 +38,50 @@ int KIWAY::m_kiface_version[KIWAY_FACE_COUNT]; KIWAY::KIWAY( PGM_BASE* aProgram, wxFrame* aTop ): m_program( aProgram ), - m_top( aTop ) + m_top( 0 ) { + SetTop( aTop ); // hook playerDestroyHandler() into aTop. + memset( m_player, 0, sizeof( m_player ) ); } +// Any event types derived from wxCommandEvt, like wxWindowDestroyEvent, are +// propogated upwards to parent windows if not handled below. Therefor the +// m_top window should receive all wxWindowDestroyEvents from originating +// from KIWAY_PLAYERs. It does anyways, but now playerDestroyHandler eavesdrops +// on that event stream looking for KIWAY_PLAYERs being closed. + +void KIWAY::playerDestroyHandler( wxWindowDestroyEvent& event ) +{ + wxWindow* w = event.GetWindow(); + + for( unsigned i=0; iDisconnect( wxEVT_DESTROY, wxWindowDestroyEventHandler( KIWAY::playerDestroyHandler ), NULL, this ); + } + + if( aTop ) + { + aTop->Connect( wxEVT_DESTROY, wxWindowDestroyEventHandler( KIWAY::playerDestroyHandler ), NULL, this ); + } + + m_top = aTop; +} + const wxString KIWAY::dso_full_path( FACE_T aFaceId ) { diff --git a/include/kiway.h b/include/kiway.h index f4f40ca980..7908990ffc 100644 --- a/include/kiway.h +++ b/include/kiway.h @@ -331,22 +331,25 @@ public: KIWAY( PGM_BASE* aProgram, wxFrame* aTop = NULL ); /// In case aTop may not be known at time of KIWAY construction: - void SetTop( wxFrame* aTop ) { m_top = aTop; } + void SetTop( wxFrame* aTop ); private: /// Get the full path & name of the DSO holding the requested FACE_T. static const wxString dso_full_path( FACE_T aFaceId ); + /// hooked into m_top in SetTop(), marks child frame as closed. + void playerDestroyHandler( wxWindowDestroyEvent& event ); + static KIFACE* m_kiface[KIWAY_FACE_COUNT]; static int m_kiface_version[KIWAY_FACE_COUNT]; + PGM_BASE* m_program; + wxFrame* m_top; + KIWAY_PLAYER* m_player[KIWAY_PLAYER_COUNT]; // from frame_type.h PROJECT m_project; // do not assume this is here, use Prj(). - - PGM_BASE* m_program; - wxFrame* m_top; };