hook top frame with KIWAY::playerDestroyHandler()
This commit is contained in:
parent
ea66e572a0
commit
f9f3ff22dc
|
@ -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; i<DIM(m_player); ++i )
|
||||
{
|
||||
// if destroying one of our flock, then mark it as diseased.
|
||||
if( (wxWindow*) m_player[i] == w )
|
||||
{
|
||||
// DBG(printf( "%s: marking m_player[%d] as destroyed\n", __func__, i );)
|
||||
m_player[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KIWAY::SetTop( wxFrame* aTop )
|
||||
{
|
||||
if( m_top )
|
||||
{
|
||||
m_top->Disconnect( 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 )
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue