From 974d6bd827b9b54af1006cc559bc5308272eaabd Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 11 Sep 2018 15:32:13 +0200 Subject: [PATCH] Honor monitor layout and DPI changes when persisting window placement --- ZRCola/stdafx.h | 1 + ZRCola/zrcolachrreq.cpp | 6 +++--- ZRCola/zrcolachrreq.h | 4 +++- ZRCola/zrcolachrslct.cpp | 6 +++--- ZRCola/zrcolachrslct.h | 6 +++--- ZRCola/zrcolafrm.cpp | 18 ++++++++++-------- ZRCola/zrcolafrm.h | 5 +++-- ZRCola/zrcolasettings.cpp | 6 +++--- ZRCola/zrcolasettings.h | 4 ++-- ZRCola/zrcolatranseq.cpp | 6 +++--- ZRCola/zrcolatranseq.h | 4 ++-- lib/wxExtend | 2 +- 12 files changed, 37 insertions(+), 31 deletions(-) diff --git a/ZRCola/stdafx.h b/ZRCola/stdafx.h index 369748d..d05ed05 100644 --- a/ZRCola/stdafx.h +++ b/ZRCola/stdafx.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include diff --git a/ZRCola/zrcolachrreq.cpp b/ZRCola/zrcolachrreq.cpp index 32dfce9..3d3f7d1 100644 --- a/ZRCola/zrcolachrreq.cpp +++ b/ZRCola/zrcolachrreq.cpp @@ -71,14 +71,14 @@ void wxZRColaCharRequest::OnOKButtonClick(wxCommandEvent& event) // wxPersistentZRColaCharRequest ////////////////////////////////////////////////////////////////////////// -wxPersistentZRColaCharRequest::wxPersistentZRColaCharRequest(wxZRColaCharRequest *wnd) : wxPersistentDialog(wnd) +wxPersistentZRColaCharRequest::wxPersistentZRColaCharRequest(wxZRColaCharRequest *wnd) : wxPersistentTLWEx(wnd) { } void wxPersistentZRColaCharRequest::Save() const { - wxPersistentDialog::Save(); + wxPersistentTLWEx::Save(); auto wnd = static_cast(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. @@ -97,5 +97,5 @@ bool wxPersistentZRColaCharRequest::Restore() if (RestoreValue(wxT("context"), &str)) wnd->m_context->SetValue(str); - return wxPersistentDialog::Restore(); + return wxPersistentTLWEx::Restore(); } diff --git a/ZRCola/zrcolachrreq.h b/ZRCola/zrcolachrreq.h index c532a4f..97a8122 100644 --- a/ZRCola/zrcolachrreq.h +++ b/ZRCola/zrcolachrreq.h @@ -21,12 +21,14 @@ /// Forward declarations /// class wxZRColaCharRequest; +class wxPersistentZRColaCharRequest; #pragma once #include "zrcolagui.h" #include "zrcolakeyhndlr.h" +#include /// @@ -49,7 +51,7 @@ protected: /// /// Supports saving/restoring wxZRColaCharRequest state /// -class wxPersistentZRColaCharRequest : public wxPersistentDialog +class wxPersistentZRColaCharRequest : public wxPersistentTLWEx { public: wxPersistentZRColaCharRequest(wxZRColaCharRequest *wnd); diff --git a/ZRCola/zrcolachrslct.cpp b/ZRCola/zrcolachrslct.cpp index 5773207..2356d49 100644 --- a/ZRCola/zrcolachrslct.cpp +++ b/ZRCola/zrcolachrslct.cpp @@ -786,14 +786,14 @@ bool __cdecl wxZRColaCharSelect::SearchThread::TestDestroyS(void *cookie) // wxPersistentZRColaCharSelect ////////////////////////////////////////////////////////////////////////// -wxPersistentZRColaCharSelect::wxPersistentZRColaCharSelect(wxZRColaCharSelect *wnd) : wxPersistentDialog(wnd) +wxPersistentZRColaCharSelect::wxPersistentZRColaCharSelect(wxZRColaCharSelect *wnd) : wxPersistentTLWEx(wnd) { } void wxPersistentZRColaCharSelect::Save() const { - wxPersistentDialog::Save(); + wxPersistentTLWEx::Save(); auto wnd = static_cast(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. auto app = dynamic_cast(wxTheApp); @@ -870,5 +870,5 @@ bool wxPersistentZRColaCharSelect::Restore() wnd->ResetResults(); - return wxPersistentDialog::Restore(); + return wxPersistentTLWEx::Restore(); } diff --git a/ZRCola/zrcolachrslct.h b/ZRCola/zrcolachrslct.h index f928d58..4e7190b 100644 --- a/ZRCola/zrcolachrslct.h +++ b/ZRCola/zrcolachrslct.h @@ -28,8 +28,8 @@ class wxPersistentZRColaCharSelect; #include "zrcolagui.h" #include +#include #include -#include #include #include #include @@ -41,7 +41,7 @@ class wxPersistentZRColaCharSelect; /// /// Validator for Unicode character /// -class WXEXTEND_API wxZRColaUTF16CharValidator : public wxValidator +class wxZRColaUTF16CharValidator : public wxValidator { public: /// @@ -221,7 +221,7 @@ protected: /// /// Supports saving/restoring wxZRColaCharSelect state /// -class wxPersistentZRColaCharSelect : public wxPersistentDialog +class wxPersistentZRColaCharSelect : public wxPersistentTLWEx { public: wxPersistentZRColaCharSelect(wxZRColaCharSelect *wnd); diff --git a/ZRCola/zrcolafrm.cpp b/ZRCola/zrcolafrm.cpp index 60c3815..4bbb168 100644 --- a/ZRCola/zrcolafrm.cpp +++ b/ZRCola/zrcolafrm.cpp @@ -110,17 +110,19 @@ wxZRColaFrame::wxZRColaFrame() : delete m_taskBarIcon; } + wxPersistenceManager &persist_mgr = wxPersistenceManager::Get(); + m_settings = new wxZRColaSettings(this); - wxPersistentRegisterAndRestore(m_settings); + persist_mgr.RegisterAndRestore(m_settings, new wxPersistentZRColaSettings(m_settings)); m_transeq = new wxZRColaTranslationSeq(this); - wxPersistentRegisterAndRestore(m_transeq); + persist_mgr.RegisterAndRestore(m_transeq, new wxPersistentZRColaTranslationSeq(m_transeq)); m_chrSelect = new wxZRColaCharSelect(this); - wxPersistentRegisterAndRestore(m_chrSelect); + persist_mgr.RegisterAndRestore(m_chrSelect, new wxPersistentZRColaCharSelect(m_chrSelect)); m_chrReq = new wxZRColaCharRequest(this); - wxPersistentRegisterAndRestore(m_chrReq); + persist_mgr.RegisterAndRestore(m_chrReq, new wxPersistentZRColaCharRequest(m_chrReq)); // Set focus. m_panel->m_source->SetFocus(); @@ -155,7 +157,7 @@ wxZRColaFrame::wxZRColaFrame() : // 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(); - wxPersistentRegisterAndRestore(this); + persist_mgr.RegisterAndRestore(this, new wxPersistentZRColaFrame(this)); // Populate list of translation sequences. for (unsigned int i = 0, n = m_toolTranslationSeq->GetCount(); ; i++) { @@ -615,14 +617,14 @@ WXLRESULT wxZRColaFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM // wxPersistentZRColaFrame ////////////////////////////////////////////////////////////////////////// -wxPersistentZRColaFrame::wxPersistentZRColaFrame(wxZRColaFrame *wnd) : wxPersistentTLW(wnd) +wxPersistentZRColaFrame::wxPersistentZRColaFrame(wxZRColaFrame *wnd) : wxPersistentTLWEx(wnd) { } void wxPersistentZRColaFrame::Save() const { - wxPersistentTLW::Save(); + wxPersistentTLWEx::Save(); auto wnd = static_cast(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. @@ -644,5 +646,5 @@ bool wxPersistentZRColaFrame::Restore() if (RestoreValue(wxT("transeqId"), &num)) wnd->m_transeq_id = num; - return wxPersistentTLW::Restore(); + return wxPersistentTLWEx::Restore(); } diff --git a/ZRCola/zrcolafrm.h b/ZRCola/zrcolafrm.h index 633fc4f..473691a 100644 --- a/ZRCola/zrcolafrm.h +++ b/ZRCola/zrcolafrm.h @@ -21,6 +21,7 @@ /// Forward declarations /// class wxZRColaFrame; +class wxPersistentZRColaFrame; #pragma once @@ -32,8 +33,8 @@ class wxZRColaFrame; #include "zrcolatranseq.h" #include #include +#include #include -#include #if defined(__WXMSW__) #include #endif @@ -136,7 +137,7 @@ protected: /// /// Supports saving/restoring wxZRColaFrame GUI state /// -class wxPersistentZRColaFrame : public wxPersistentTLW +class wxPersistentZRColaFrame : public wxPersistentTLWEx { public: wxPersistentZRColaFrame(wxZRColaFrame *wnd); diff --git a/ZRCola/zrcolasettings.cpp b/ZRCola/zrcolasettings.cpp index 07a7ad8..b216e4f 100644 --- a/ZRCola/zrcolasettings.cpp +++ b/ZRCola/zrcolasettings.cpp @@ -139,14 +139,14 @@ void wxZRColaSettings::OnOKButtonClick(wxCommandEvent& event) // wxPersistentZRColaSettings ////////////////////////////////////////////////////////////////////////// -wxPersistentZRColaSettings::wxPersistentZRColaSettings(wxZRColaSettings *wnd) : wxPersistentDialog(wnd) +wxPersistentZRColaSettings::wxPersistentZRColaSettings(wxZRColaSettings *wnd) : wxPersistentTLWEx(wnd) { } void wxPersistentZRColaSettings::Save() const { - wxPersistentDialog::Save(); + wxPersistentTLWEx::Save(); auto wnd = static_cast(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. @@ -177,5 +177,5 @@ bool wxPersistentZRColaSettings::Restore() } else wnd->m_lang = ZRCola::langid_t::blank; - return wxPersistentDialog::Restore(); + return wxPersistentTLWEx::Restore(); } diff --git a/ZRCola/zrcolasettings.h b/ZRCola/zrcolasettings.h index 4d0583a..17f3711 100644 --- a/ZRCola/zrcolasettings.h +++ b/ZRCola/zrcolasettings.h @@ -27,7 +27,7 @@ class wxPersistentZRColaSettings; #pragma once #include "zrcolagui.h" -#include +#include #include @@ -56,7 +56,7 @@ public: /// /// Supports saving/restoring wxZRColaSettings state /// -class wxPersistentZRColaSettings : public wxPersistentDialog +class wxPersistentZRColaSettings : public wxPersistentTLWEx { public: wxPersistentZRColaSettings(wxZRColaSettings *wnd); diff --git a/ZRCola/zrcolatranseq.cpp b/ZRCola/zrcolatranseq.cpp index 900fba2..397da72 100644 --- a/ZRCola/zrcolatranseq.cpp +++ b/ZRCola/zrcolatranseq.cpp @@ -208,14 +208,14 @@ void wxZRColaTranslationSeq::OnOKButtonClick(wxCommandEvent& event) // wxPersistentZRColaTranslationSeq ////////////////////////////////////////////////////////////////////////// -wxPersistentZRColaTranslationSeq::wxPersistentZRColaTranslationSeq(wxZRColaTranslationSeq *wnd) : wxPersistentDialog(wnd) +wxPersistentZRColaTranslationSeq::wxPersistentZRColaTranslationSeq(wxZRColaTranslationSeq *wnd) : wxPersistentTLWEx(wnd) { } void wxPersistentZRColaTranslationSeq::Save() const { - wxPersistentDialog::Save(); + wxPersistentTLWEx::Save(); auto wnd = static_cast(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. @@ -249,5 +249,5 @@ bool wxPersistentZRColaTranslationSeq::Restore() wnd->m_transeq = std::move(transet); } - return wxPersistentDialog::Restore(); + return wxPersistentTLWEx::Restore(); } diff --git a/ZRCola/zrcolatranseq.h b/ZRCola/zrcolatranseq.h index f3fdfdc..e64f1ff 100644 --- a/ZRCola/zrcolatranseq.h +++ b/ZRCola/zrcolatranseq.h @@ -28,7 +28,7 @@ class wxPersistentZRColaTranslationSeq; #include "zrcolagui.h" #include -#include +#include #include @@ -64,7 +64,7 @@ public: /// /// Supports saving/restoring wxZRColaTranslationSeq state /// -class wxPersistentZRColaTranslationSeq : public wxPersistentDialog +class wxPersistentZRColaTranslationSeq : public wxPersistentTLWEx { public: wxPersistentZRColaTranslationSeq(wxZRColaTranslationSeq *wnd); diff --git a/lib/wxExtend b/lib/wxExtend index 1b11ccf..5a912eb 160000 --- a/lib/wxExtend +++ b/lib/wxExtend @@ -1 +1 @@ -Subproject commit 1b11ccf4a2abb5c62a2972f554cf6d40e4b71dbc +Subproject commit 5a912ebcc6d5d2887628387eae7fc5c8105d7938