From ce11c7f4d4dc93443afe196d44b7e8f89451272d Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 25 Sep 2018 13:45:06 +0200 Subject: [PATCH] Do not restore placement and sizing when GUI changes --- ZRCola/zrcolachrreq.cpp | 7 ++++++- ZRCola/zrcolachrreq.h | 3 +++ ZRCola/zrcolachrslct.cpp | 7 ++++++- ZRCola/zrcolachrslct.h | 3 +++ ZRCola/zrcolacomppnl.cpp | 8 ++++++++ ZRCola/zrcolacomppnl.h | 3 +++ ZRCola/zrcolafrm.cpp | 20 ++++++++++++++++---- ZRCola/zrcolafrm.h | 6 ++++++ ZRCola/zrcolasettings.cpp | 7 ++++++- ZRCola/zrcolasettings.h | 3 +++ ZRCola/zrcolatranseq.cpp | 7 ++++++- ZRCola/zrcolatranseq.h | 3 +++ 12 files changed, 69 insertions(+), 8 deletions(-) diff --git a/ZRCola/zrcolachrreq.cpp b/ZRCola/zrcolachrreq.cpp index 3d3f7d1..b6b3060 100644 --- a/ZRCola/zrcolachrreq.cpp +++ b/ZRCola/zrcolachrreq.cpp @@ -71,6 +71,9 @@ void wxZRColaCharRequest::OnOKButtonClick(wxCommandEvent& event) // wxPersistentZRColaCharRequest ////////////////////////////////////////////////////////////////////////// +const int wxPersistentZRColaCharRequest::s_guiLevel = 1; + + wxPersistentZRColaCharRequest::wxPersistentZRColaCharRequest(wxZRColaCharRequest *wnd) : wxPersistentTLWEx(wnd) { } @@ -78,6 +81,7 @@ wxPersistentZRColaCharRequest::wxPersistentZRColaCharRequest(wxZRColaCharRequest void wxPersistentZRColaCharRequest::Save() const { + SaveValue(wxT("guiLevel"), s_guiLevel); wxPersistentTLWEx::Save(); auto wnd = static_cast(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. @@ -97,5 +101,6 @@ bool wxPersistentZRColaCharRequest::Restore() if (RestoreValue(wxT("context"), &str)) wnd->m_context->SetValue(str); - return wxPersistentTLWEx::Restore(); + int guiLevel; + return RestoreValue(wxT("guiLevel"), &guiLevel) && guiLevel == s_guiLevel ? wxPersistentTLWEx::Restore() : true; } diff --git a/ZRCola/zrcolachrreq.h b/ZRCola/zrcolachrreq.h index 97a8122..b09bb42 100644 --- a/ZRCola/zrcolachrreq.h +++ b/ZRCola/zrcolachrreq.h @@ -58,6 +58,9 @@ public: virtual void Save() const; virtual bool Restore(); + +protected: + static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels }; diff --git a/ZRCola/zrcolachrslct.cpp b/ZRCola/zrcolachrslct.cpp index 2356d49..9656b56 100644 --- a/ZRCola/zrcolachrslct.cpp +++ b/ZRCola/zrcolachrslct.cpp @@ -786,6 +786,9 @@ bool __cdecl wxZRColaCharSelect::SearchThread::TestDestroyS(void *cookie) // wxPersistentZRColaCharSelect ////////////////////////////////////////////////////////////////////////// +const int wxPersistentZRColaCharSelect::s_guiLevel = 1; + + wxPersistentZRColaCharSelect::wxPersistentZRColaCharSelect(wxZRColaCharSelect *wnd) : wxPersistentTLWEx(wnd) { } @@ -793,6 +796,7 @@ wxPersistentZRColaCharSelect::wxPersistentZRColaCharSelect(wxZRColaCharSelect *w void wxPersistentZRColaCharSelect::Save() const { + SaveValue(wxT("guiLevel"), s_guiLevel); wxPersistentTLWEx::Save(); auto wnd = static_cast(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. @@ -870,5 +874,6 @@ bool wxPersistentZRColaCharSelect::Restore() wnd->ResetResults(); - return wxPersistentTLWEx::Restore(); + int guiLevel; + return RestoreValue(wxT("guiLevel"), &guiLevel) && guiLevel == s_guiLevel ? wxPersistentTLWEx::Restore() : true; } diff --git a/ZRCola/zrcolachrslct.h b/ZRCola/zrcolachrslct.h index 4e7190b..311d336 100644 --- a/ZRCola/zrcolachrslct.h +++ b/ZRCola/zrcolachrslct.h @@ -228,6 +228,9 @@ public: virtual void Save() const; virtual bool Restore(); + +protected: + static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels }; diff --git a/ZRCola/zrcolacomppnl.cpp b/ZRCola/zrcolacomppnl.cpp index 9a6c87a..95a694a 100644 --- a/ZRCola/zrcolacomppnl.cpp +++ b/ZRCola/zrcolacomppnl.cpp @@ -398,6 +398,9 @@ void wxZRColaComposerPanel::SetHexValue(wxTextCtrl *wnd, std::pair & // wxPersistentZRColaComposerPanel ////////////////////////////////////////////////////////////////////////// +const int wxPersistentZRColaComposerPanel::s_guiLevel = 1; + + wxPersistentZRColaComposerPanel::wxPersistentZRColaComposerPanel(wxZRColaComposerPanel *wnd) : wxPersistentWindow(wnd) { } @@ -413,6 +416,7 @@ void wxPersistentZRColaComposerPanel::Save() const { auto wnd = static_cast(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. + SaveValue(wxT("guiLevel" ), s_guiLevel); SaveValue(wxT("dpiX" ), wxClientDC(wnd).GetPPI().x); SaveValue(wxT("splitDecomposed"), wnd->m_splitterSource ->GetSashPosition()); SaveValue(wxT("splitComposed" ), wnd->m_splitterDestination->GetSashPosition()); @@ -423,6 +427,10 @@ bool wxPersistentZRColaComposerPanel::Restore() { auto wnd = dynamic_cast(GetWindow()); + int guiLevel; + if (!RestoreValue(wxT("guiLevel"), &guiLevel) || guiLevel != s_guiLevel) + return true; + int dpiHorz = wxClientDC(wnd).GetPPI().x; int dpiHorzVal; int sashVal; diff --git a/ZRCola/zrcolacomppnl.h b/ZRCola/zrcolacomppnl.h index 5b920f9..755aaaa 100644 --- a/ZRCola/zrcolacomppnl.h +++ b/ZRCola/zrcolacomppnl.h @@ -88,6 +88,9 @@ public: virtual wxString GetKind() const; virtual void Save() const; virtual bool Restore(); + +protected: + static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels }; diff --git a/ZRCola/zrcolafrm.cpp b/ZRCola/zrcolafrm.cpp index b9f1012..c5c724b 100644 --- a/ZRCola/zrcolafrm.cpp +++ b/ZRCola/zrcolafrm.cpp @@ -64,6 +64,9 @@ wxBEGIN_EVENT_TABLE(wxZRColaFrame, wxZRColaFrameBase) wxEND_EVENT_TABLE() +const int wxZRColaFrame::s_guiLevel = 1; + + wxZRColaFrame::wxZRColaFrame() : m_hWndSource(NULL), m_wasIconised(false), @@ -173,9 +176,12 @@ wxZRColaFrame::wxZRColaFrame() : SetAcceleratorTable(wxAcceleratorTable(_countof(entries), entries)); } - // Restore persistent state of wxAuiManager manually, since m_mgr is not a standalone heap object - // and cannot be registered for persistence. - wxPersistentAuiManager(&m_mgr).Restore(); + int guiLevel; + if (wxConfigBase::Get()->Read(wxT("guiLevel"), &guiLevel) && guiLevel == s_guiLevel) { + // Restore persistent state of wxAuiManager manually, since m_mgr is not a standalone heap object + // and cannot be registered for persistence. + wxPersistentAuiManager(&m_mgr).Restore(); + } persist_mgr.RegisterAndRestore(this, new wxPersistentZRColaFrame(this)); // Update (de)composition selection. @@ -219,6 +225,7 @@ wxZRColaFrame::~wxZRColaFrame() // Save wxAuiManager's state before destructor is finished. // m_mgr is not a standalone heap object and is bound to wxZRColaFrame, which is being destroyed. + wxConfigBase::Get()->Write(wxT("guiLevel"), s_guiLevel); wxPersistentAuiManager(&m_mgr).Save(); wxPersistenceManager::Get().SaveAndUnregister(this); @@ -717,6 +724,9 @@ WXLRESULT wxZRColaFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM // wxPersistentZRColaFrame ////////////////////////////////////////////////////////////////////////// +const int wxPersistentZRColaFrame::s_guiLevel = 1; + + wxPersistentZRColaFrame::wxPersistentZRColaFrame(wxZRColaFrame *wnd) : wxPersistentTLWEx(wnd) { } @@ -724,6 +734,7 @@ wxPersistentZRColaFrame::wxPersistentZRColaFrame(wxZRColaFrame *wnd) : wxPersist void wxPersistentZRColaFrame::Save() const { + SaveValue(wxT("guiLevel"), s_guiLevel); wxPersistentTLWEx::Save(); auto wnd = static_cast(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. @@ -753,5 +764,6 @@ bool wxPersistentZRColaFrame::Restore() else wnd->m_composition = wnd->m_transeq_id == ZRCOLA_TRANSEQID_DEFAULT; - return wxPersistentTLWEx::Restore(); + int guiLevel; + return RestoreValue(wxT("guiLevel"), &guiLevel) && guiLevel == s_guiLevel ? wxPersistentTLWEx::Restore() : true; } diff --git a/ZRCola/zrcolafrm.h b/ZRCola/zrcolafrm.h index d1b8b50..b781560 100644 --- a/ZRCola/zrcolafrm.h +++ b/ZRCola/zrcolafrm.h @@ -130,6 +130,9 @@ protected: virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); #endif +protected: + static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels + protected: WXHWND m_hWndSource; ///< Handle of the active window, when the ZRCola hotkey was pressed bool m_wasIconised; ///< Was the ZRCola window iconized, when the ZRCola hotkey was pressed @@ -153,6 +156,9 @@ public: virtual void Save() const; virtual bool Restore(); + +protected: + static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels }; diff --git a/ZRCola/zrcolasettings.cpp b/ZRCola/zrcolasettings.cpp index b216e4f..9c9a171 100644 --- a/ZRCola/zrcolasettings.cpp +++ b/ZRCola/zrcolasettings.cpp @@ -139,6 +139,9 @@ void wxZRColaSettings::OnOKButtonClick(wxCommandEvent& event) // wxPersistentZRColaSettings ////////////////////////////////////////////////////////////////////////// +const int wxPersistentZRColaSettings::s_guiLevel = 1; + + wxPersistentZRColaSettings::wxPersistentZRColaSettings(wxZRColaSettings *wnd) : wxPersistentTLWEx(wnd) { } @@ -146,6 +149,7 @@ wxPersistentZRColaSettings::wxPersistentZRColaSettings(wxZRColaSettings *wnd) : void wxPersistentZRColaSettings::Save() const { + SaveValue(wxT("guiLevel"), s_guiLevel); wxPersistentTLWEx::Save(); auto wnd = static_cast(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. @@ -177,5 +181,6 @@ bool wxPersistentZRColaSettings::Restore() } else wnd->m_lang = ZRCola::langid_t::blank; - return wxPersistentTLWEx::Restore(); + int guiLevel; + return RestoreValue(wxT("guiLevel"), &guiLevel) && guiLevel == s_guiLevel ? wxPersistentTLWEx::Restore() : true; } diff --git a/ZRCola/zrcolasettings.h b/ZRCola/zrcolasettings.h index 17f3711..b17090d 100644 --- a/ZRCola/zrcolasettings.h +++ b/ZRCola/zrcolasettings.h @@ -63,6 +63,9 @@ public: virtual void Save() const; virtual bool Restore(); + +protected: + static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels }; diff --git a/ZRCola/zrcolatranseq.cpp b/ZRCola/zrcolatranseq.cpp index 397da72..2ecb1c6 100644 --- a/ZRCola/zrcolatranseq.cpp +++ b/ZRCola/zrcolatranseq.cpp @@ -208,6 +208,9 @@ void wxZRColaTranslationSeq::OnOKButtonClick(wxCommandEvent& event) // wxPersistentZRColaTranslationSeq ////////////////////////////////////////////////////////////////////////// +const int wxPersistentZRColaTranslationSeq::s_guiLevel = 1; + + wxPersistentZRColaTranslationSeq::wxPersistentZRColaTranslationSeq(wxZRColaTranslationSeq *wnd) : wxPersistentTLWEx(wnd) { } @@ -215,6 +218,7 @@ wxPersistentZRColaTranslationSeq::wxPersistentZRColaTranslationSeq(wxZRColaTrans void wxPersistentZRColaTranslationSeq::Save() const { + SaveValue(wxT("guiLevel"), s_guiLevel); wxPersistentTLWEx::Save(); auto wnd = static_cast(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. @@ -249,5 +253,6 @@ bool wxPersistentZRColaTranslationSeq::Restore() wnd->m_transeq = std::move(transet); } - return wxPersistentTLWEx::Restore(); + int guiLevel; + return RestoreValue(wxT("guiLevel"), &guiLevel) && guiLevel == s_guiLevel ? wxPersistentTLWEx::Restore() : true; } diff --git a/ZRCola/zrcolatranseq.h b/ZRCola/zrcolatranseq.h index e64f1ff..5d58455 100644 --- a/ZRCola/zrcolatranseq.h +++ b/ZRCola/zrcolatranseq.h @@ -71,6 +71,9 @@ public: virtual void Save() const; virtual bool Restore(); + +protected: + static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels };