From 0ec0b63ad29029412a09a275161343bbbace953e Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Sun, 2 Feb 2014 14:18:10 -0600 Subject: [PATCH] Another attempt at wxFrame::SaveSettings() standard infrastructure. --- common/basicframe.cpp | 30 ++++++++++++++---------------- cvpcb/cvframe.cpp | 3 --- eeschema/schframe.cpp | 2 -- gerbview/gerbview_frame.cpp | 3 --- include/wxstruct.h | 29 +++++++++++++++++------------ kicad/mainframe.cpp | 2 -- pcbnew/footprint_wizard_frame.cpp | 1 - 7 files changed, 31 insertions(+), 39 deletions(-) diff --git a/common/basicframe.cpp b/common/basicframe.cpp index 98238b78df..d1616dd722 100644 --- a/common/basicframe.cpp +++ b/common/basicframe.cpp @@ -99,6 +99,18 @@ EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, Connect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER, wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) ); + + // hook wxEVT_CLOSE_WINDOW so we can call SaveSettings(). This function seems + // to be called before any other hook for wxCloseEvent, which is necessary. + Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( EDA_BASE_FRAME::windowClosing ) ); +} + + +void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event ) +{ + SaveSettings(); // virtual, wxFrame specific + + event.Skip(); // we did not "handle" the event, only eavesdropped on it. } @@ -109,9 +121,8 @@ EDA_BASE_FRAME::~EDA_BASE_FRAME() delete m_autoSaveTimer; - /* This needed for OSX: avoids further OnDraw processing after this - * destructor and before the native window is destroyed - */ + // This is needed for OSX: avoids further OnDraw processing after this + // destructor and before the native window is destroyed this->Freeze(); } @@ -141,19 +152,6 @@ bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent ) } -bool EDA_BASE_FRAME::Show( bool show ) -{ - if( !show ) // closing - { - SaveSettings(); // virtual, wxFrame specific - } - - int ret = wxFrame::Show( show ); - - return ret; -} - - void EDA_BASE_FRAME::onAutoSaveTimer( wxTimerEvent& aEvent ) { if( !doAutoSave() ) diff --git a/cvpcb/cvframe.cpp b/cvpcb/cvframe.cpp index 47b3143717..307ee5829b 100644 --- a/cvpcb/cvframe.cpp +++ b/cvpcb/cvframe.cpp @@ -338,9 +338,6 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) m_modified = false; - // hide main frame, which also forces saving curr pos and size in config - Show( false ); - Destroy(); return; } diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index e5bbf58089..f69760a292 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -505,8 +505,6 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent ) // all sub sheets are deleted, only the main sheet is usable m_CurrentSheet->Clear(); - // hide main frame, which also forces saving curr pos and size in config - Show( false ); Destroy(); } diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 31bd8f2352..62fdf0c130 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -177,9 +177,6 @@ GERBVIEW_FRAME::~GERBVIEW_FRAME() void GERBVIEW_FRAME::OnCloseWindow( wxCloseEvent& Event ) { - // hide main frame, which also forces saving curr pos and size in config - Show( false ); - Destroy(); } diff --git a/include/wxstruct.h b/include/wxstruct.h index 96476b363c..69a24fa7a0 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -107,10 +107,26 @@ extern const wxChar traceAutoSave[]; /** * Class EDA_BASE_FRAME * is the base frame for deriving all KiCad main window classes. This class is not - * intended to be used directly. + * intended to be used directly. It provides support for automatic calls to + * a virtual SaveSettings() function. SaveSettings() for a derived class can choose + * to do nothing, or rely on basic SaveSettings() support in this base class to do + * most of the work by calling it from the derived class's SaveSettings(). */ class EDA_BASE_FRAME : public wxFrame { + /** + * Function windowClosing + * (with its unexpected name so it does not collide with the real OnWindowClose() + * function provided in derived classes) is called just before a window + * closing, and is used to call a derivation specific + * SaveSettings(). SaveSettings() is called for all derived wxFrames in this + * base class overload. (Calling it from a destructor is deprecated since the + * wxFrame's position is not available in the destructor on linux.) In other words, + * you should not need to call call SaveSettings() anywhere, except in this + * one function found only in this class. + */ + void windowClosing( wxCloseEvent& event ); + protected: ID_DRAWFRAME_TYPE m_Ident; ///< Id Type (pcb, schematic, library..) wxPoint m_FramePos; @@ -177,17 +193,6 @@ public: */ bool ProcessEvent( wxEvent& aEvent ); // overload wxFrame::ProcessEvent() - /** - * Function Show - * hooks the wxFrame close scenario so we can grab the window size and position - * in the wxFrame specific SaveSettings() function. SaveSettings() is - * called for all derived wxFrames in this base class overload. Calling it - * from a destructor is deprecated since the wxFrame's position is not available - * in the destructor on linux. In other words, don't call SaveSettings() anywhere, - * except in this one function. - */ - bool Show( bool show ); // overload wxFrame::Show() - void SetAutoSaveInterval( int aInterval ) { m_autoSaveInterval = aInterval; } int GetAutoSaveInterval() const { return m_autoSaveInterval; } diff --git a/kicad/mainframe.cpp b/kicad/mainframe.cpp index 677b4b5e9a..1dc1e0cade 100644 --- a/kicad/mainframe.cpp +++ b/kicad/mainframe.cpp @@ -159,8 +159,6 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event ) } m_LeftWin->Show( false ); - // hide main frame, which also forces saving curr pos and size in config - Show( false ); Destroy(); } diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index d20c4b228c..23ee998473 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -258,7 +258,6 @@ void FOOTPRINT_WIZARD_FRAME::OnCloseWindow( wxCloseEvent& Event ) } else { - Show( false ); Destroy(); } }