From 963029262b17aa57e78748c7c8ed8a2c27c2a997 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 9 May 2014 20:06:18 +0200 Subject: [PATCH] Fix an annoying behavior of new quasi modal frames on Windows (when closing them, the caller frame was no more on top ) --- common/kiway_player.cpp | 15 +++++++++++++-- include/kiway_player.h | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/common/kiway_player.cpp b/common/kiway_player.cpp index fc0415a702..fda3962d2d 100644 --- a/common/kiway_player.cpp +++ b/common/kiway_player.cpp @@ -45,7 +45,7 @@ KIWAY_PLAYER::KIWAY_PLAYER( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType EDA_BASE_FRAME( aParent, aFrameType, aTitle, aPos, aSize, aStyle, aWdoName ), KIWAY_HOLDER( aKiway ), m_modal( false ), - m_modal_loop( 0 ) + m_modal_loop( 0 ), m_modal_resultant_parent( 0 ) { // DBG( printf("KIWAY_EXPRESS::wxEVENT_ID:%d\n", KIWAY_EXPRESS::wxEVENT_ID );) } @@ -57,7 +57,7 @@ KIWAY_PLAYER::KIWAY_PLAYER( wxWindow* aParent, wxWindowID aId, const wxString& a EDA_BASE_FRAME( aParent, (FRAME_T) aId, aTitle, aPos, aSize, aStyle, aWdoName ), KIWAY_HOLDER( 0 ), m_modal( false ), - m_modal_loop( 0 ) + m_modal_loop( 0 ), m_modal_resultant_parent( 0 ) { // DBG( printf("KIWAY_EXPRESS::wxEVENT_ID:%d\n", KIWAY_EXPRESS::wxEVENT_ID );) } @@ -95,6 +95,7 @@ bool KIWAY_PLAYER::ShowModal( wxString* aResult, wxWindow* aResultantFocusWindow } clear_this( (void*&) m_modal_loop ); + m_modal_resultant_parent = aResultantFocusWindow; Show( true ); SetFocus(); @@ -138,6 +139,16 @@ bool KIWAY_PLAYER::ShowModal( wxString* aResult, wxWindow* aResultantFocusWindow return m_modal_ret_val; } +bool KIWAY_PLAYER::Destroy() +{ + // Needed on Windows to leave the modal parent on top with focus +#ifdef __WINDOWS__ + if( m_modal_resultant_parent && GetParent() != m_modal_resultant_parent ) + Reparent( m_modal_resultant_parent ); +#endif + + return EDA_BASE_FRAME::Destroy(); +} bool KIWAY_PLAYER::IsDismissed() { diff --git a/include/kiway_player.h b/include/kiway_player.h index 48cfeafc4a..0bdc2e8045 100644 --- a/include/kiway_player.h +++ b/include/kiway_player.h @@ -202,6 +202,11 @@ public: */ virtual void KiwayMailIn( KIWAY_EXPRESS& aEvent ); + /** + * Our version of Destroy() which is virtual from wxWidgets + */ + bool Destroy(); + protected: bool IsModal() { return m_modal; } @@ -229,6 +234,7 @@ protected: // variables for modal behavior support, only used by a few derivatives. bool m_modal; // true if frame is intended to be modal, not modeless WX_EVENT_LOOP* m_modal_loop; // points to nested event_loop, NULL means not modal and dismissed + wxWindow* m_modal_resultant_parent; // the window caller in modal mode wxString m_modal_string; bool m_modal_ret_val; // true if a selection was made