From 2a4bd85f53687af3f76b611ea02bc2f9b12dc449 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Thu, 25 Jun 2015 16:46:20 +0100 Subject: [PATCH] gui: Fix looping dialog event handling The dialog event handling is a bit messed up. An ok/cancel event sends a close event, which sends a cancel event and repeats. This would actually be an infinite loop if wxWidgets didn't detect a loop. Rework the event handling to avoid the loop and to remember the positions of modal dialogs as well. --- common/include/Utilities/wxGuiTools.h | 3 +-- common/src/Utilities/wxHelpers.cpp | 21 ++++++++----------- pcsx2/gui/Dialogs/BaseConfigurationDialog.cpp | 11 ---------- pcsx2/gui/Dialogs/ConfigurationDialog.h | 1 - 4 files changed, 10 insertions(+), 26 deletions(-) diff --git a/common/include/Utilities/wxGuiTools.h b/common/include/Utilities/wxGuiTools.h index 8068558ab9..1f15ceda55 100644 --- a/common/include/Utilities/wxGuiTools.h +++ b/common/include/Utilities/wxGuiTools.h @@ -512,11 +512,11 @@ public: void Init( const pxDialogCreationFlags& cflags ); void AddOkCancel( wxSizer& sizer, bool hasApply=false ); void AddOkCancel( wxSizer* sizer=NULL, bool hasApply=false ); + void RememberPosition(); virtual void SmartCenterFit(); virtual int ShowModal(); virtual bool Show( bool show=true ); - virtual bool Destroy(); // Must return the same thing as GetNameStatic; a name ideal for use in uniquely // identifying dialogs. (this version is the 'instance' version, which is called @@ -536,7 +536,6 @@ public: protected: void OnDialogCreated( wxCommandEvent& evt ); void OnOkCancel(wxCommandEvent& evt); - void OnCloseWindow(wxCloseEvent& event); bool ShouldPreventAppExit() const { return false; } diff --git a/common/src/Utilities/wxHelpers.cpp b/common/src/Utilities/wxHelpers.cpp index 578e035af2..dbb2bd1f0b 100644 --- a/common/src/Utilities/wxHelpers.cpp +++ b/common/src/Utilities/wxHelpers.cpp @@ -171,7 +171,6 @@ void wxDialogWithHelpers::Init( const pxDialogCreationFlags& cflags ) Connect( wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (wxDialogWithHelpers::OnOkCancel) ); Connect( wxID_CANCEL, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (wxDialogWithHelpers::OnOkCancel) ); - Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler (wxDialogWithHelpers::OnCloseWindow) ); wxCommandEvent createEvent( pxEvt_OnDialogCreated ); createEvent.SetId( GetId() ); @@ -287,7 +286,7 @@ pxStaticText& wxDialogWithHelpers::Heading( const wxString& label ) return *new pxStaticHeading( this, label ); } -bool wxDialogWithHelpers::Destroy() +void wxDialogWithHelpers::RememberPosition() { // Save the dialog position if the dialog is named... // FIXME : This doesn't get called if the app is exited by alt-f4'ing the main app window. @@ -312,20 +311,18 @@ bool wxDialogWithHelpers::Destroy() saver.Entry( dlgName + L"_Pos", pos, screenRect.GetPosition() ); } } - - return _parent::Destroy(); -} - -void wxDialogWithHelpers::OnCloseWindow( wxCloseEvent& evt ) -{ - if( !IsModal() ) Destroy(); - evt.Skip(); } void wxDialogWithHelpers::OnOkCancel( wxCommandEvent& evt ) { - Close(); - evt.Skip(); + RememberPosition(); + + // Modal dialogs should be destroyed after ShowModal returns, otherwise there + // might be double delete problems if the dialog was declared on the stack. + if (!IsModal()) + Destroy(); + else + evt.Skip(); } void wxDialogWithHelpers::AddOkCancel( wxSizer &sizer, bool hasApply ) diff --git a/pcsx2/gui/Dialogs/BaseConfigurationDialog.cpp b/pcsx2/gui/Dialogs/BaseConfigurationDialog.cpp index 977ea86bcf..d6846c5510 100644 --- a/pcsx2/gui/Dialogs/BaseConfigurationDialog.cpp +++ b/pcsx2/gui/Dialogs/BaseConfigurationDialog.cpp @@ -144,8 +144,6 @@ Dialogs::BaseConfigurationDialog::BaseConfigurationDialog( wxWindow* parent, con Connect( wxID_APPLY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BaseConfigurationDialog::OnApply_Click ) ); Connect( wxID_SAVE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BaseConfigurationDialog::OnScreenshot_Click ) ); - Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler(BaseConfigurationDialog::OnCloseWindow) ); - Connect( pxEvt_SetSettingsPage, wxCommandEventHandler( BaseConfigurationDialog::OnSetSettingsPage ) ); // ---------------------------------------------------------------------------- @@ -230,14 +228,6 @@ void Dialogs::BaseConfigurationDialog::OnSomethingChanged( wxCommandEvent& evt ) SomethingChanged(); } - -void Dialogs::BaseConfigurationDialog::OnCloseWindow( wxCloseEvent& evt ) -{ - if( !IsModal() ) Destroy(); - evt.Skip(); -} - - void Dialogs::BaseConfigurationDialog::AllowApplyActivation( bool allow ) { m_allowApplyActivation = allow; @@ -280,7 +270,6 @@ void Dialogs::BaseConfigurationDialog::OnApply_Click( wxCommandEvent& evt ) SomethingChanged_StateModified_IsChanged(); } -//avih: FIXME: ? for some reason, this OnCancel_Click is called twice when clicking cancel or closing the dialog (Jake's code?). void Dialogs::BaseConfigurationDialog::OnCancel_Click( wxCommandEvent& evt ) { //same as for Ok/Apply: let SysConfigDialog clean-up the presets and derivatives (menu system) if needed. diff --git a/pcsx2/gui/Dialogs/ConfigurationDialog.h b/pcsx2/gui/Dialogs/ConfigurationDialog.h index f8a34ae669..ea044e4135 100644 --- a/pcsx2/gui/Dialogs/ConfigurationDialog.h +++ b/pcsx2/gui/Dialogs/ConfigurationDialog.h @@ -76,7 +76,6 @@ namespace Dialogs void OnCancel_Click( wxCommandEvent& evt ); void OnApply_Click( wxCommandEvent& evt ); void OnScreenshot_Click( wxCommandEvent& evt ); - void OnCloseWindow( wxCloseEvent& evt ); void OnSetSettingsPage( wxCommandEvent& evt ); void OnSomethingChanged( wxCommandEvent& evt );