From f239aee1ad755672942f3007ba31118a4cab9fe9 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 11 Apr 2016 19:39:43 -0400 Subject: [PATCH] Fix quasi-modal dialog mode in DIALOG_SHIM class. * Add event handler to check all button clicks for default command event IDs and handle them appropriately by either calling EndQuasiModal() or passing the event up the event handler chain to allow the default dialog handlers to perform their magic. * Add event handler to handle the close window event properly. * Add scope brackets so the wxBusyCursor will stop being displayed when the footprint library loading is complete in CvPcb. --- common/dialog_shim.cpp | 51 ++++++++++++++++++++++++++++++++++++++- cvpcb/cvpcb_mainframe.cpp | 2 ++ include/dialog_shim.h | 18 +++++++++++++- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/common/dialog_shim.cpp b/common/dialog_shim.cpp index d969902066..774520ccb4 100644 --- a/common/dialog_shim.cpp +++ b/common/dialog_shim.cpp @@ -3,7 +3,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2012-2016 KiCad Developers, see CHANGELOG.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -70,6 +70,9 @@ DIALOG_SHIM::DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& titl if( h ) SetKiway( this, &h->Kiway() ); + Bind( wxEVT_CLOSE_WINDOW, &DIALOG_SHIM::OnCloseWindow, this ); + Bind( wxEVT_BUTTON, &DIALOG_SHIM::OnButton, this ); + #ifdef __WINDOWS__ // On Windows, the app top windows can be brought to the foreground // (at least temporary) in certain circumstances, @@ -535,3 +538,49 @@ void DIALOG_SHIM::EndQuasiModal( int retCode ) Show( false ); } + + +void DIALOG_SHIM::OnCloseWindow( wxCloseEvent& aEvent ) +{ + if( IsQuasiModal() ) + { + EndQuasiModal( wxID_CANCEL ); + return; + } + + // This is mandatory to allow wxDialogBase::OnCloseWindow() to be called. + aEvent.Skip(); +} + + +void DIALOG_SHIM::OnButton( wxCommandEvent& aEvent ) +{ + if( IsQuasiModal() ) + { + const int id = aEvent.GetId(); + + if( id == GetAffirmativeId() ) + { + EndQuasiModal( id ); + } + else if( id == wxID_APPLY ) + { + if( Validate() ) + TransferDataFromWindow(); + } + else if( id == GetEscapeId() || + (id == wxID_CANCEL && GetEscapeId() == wxID_ANY) ) + { + EndQuasiModal( wxID_CANCEL ); + } + else // not a standard button + { + aEvent.Skip(); + } + + return; + } + + // This is mandatory to allow wxDialogBase::OnButton() to be called. + aEvent.Skip(); +} diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index 31bd3b2e06..76e76f547c 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -725,9 +725,11 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles() return false; } + { wxBusyCursor dummy; // Let the user know something is happening. m_FootprintsList.ReadFootprintFiles( fptbl ); + } if( m_FootprintsList.GetErrorCount() ) { diff --git a/include/dialog_shim.h b/include/dialog_shim.h index 4e5222a93e..7f294d3148 100644 --- a/include/dialog_shim.h +++ b/include/dialog_shim.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors. + * Copyright (C) 2012-2016 KiCad Developers, see CHANGELOG.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -52,6 +52,22 @@ class EVENT_LOOP; **/ class DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER { + /** + * Function OnCloseWindow + * + * properly handles the wxCloseEvent when in the quasimodal mode when not calling + * EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM. + */ + void OnCloseWindow( wxCloseEvent& aEvent ); + + /** + * Function OnCloseWindow + * + * properly handles the default button events when in the quasimodal mode when not + * calling EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM. + */ + void OnButton( wxCommandEvent& aEvent ); + public: DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,