Do not restore placement and sizing when GUI changes

This commit is contained in:
Simon Rozman 2018-09-25 13:45:06 +02:00
parent ea5049172d
commit ce11c7f4d4
12 changed files with 69 additions and 8 deletions

View File

@ -71,6 +71,9 @@ void wxZRColaCharRequest::OnOKButtonClick(wxCommandEvent& event)
// wxPersistentZRColaCharRequest // wxPersistentZRColaCharRequest
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
const int wxPersistentZRColaCharRequest::s_guiLevel = 1;
wxPersistentZRColaCharRequest::wxPersistentZRColaCharRequest(wxZRColaCharRequest *wnd) : wxPersistentTLWEx(wnd) wxPersistentZRColaCharRequest::wxPersistentZRColaCharRequest(wxZRColaCharRequest *wnd) : wxPersistentTLWEx(wnd)
{ {
} }
@ -78,6 +81,7 @@ wxPersistentZRColaCharRequest::wxPersistentZRColaCharRequest(wxZRColaCharRequest
void wxPersistentZRColaCharRequest::Save() const void wxPersistentZRColaCharRequest::Save() const
{ {
SaveValue(wxT("guiLevel"), s_guiLevel);
wxPersistentTLWEx::Save(); wxPersistentTLWEx::Save();
auto wnd = static_cast<const wxZRColaCharRequest*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. auto wnd = static_cast<const wxZRColaCharRequest*>(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)) if (RestoreValue(wxT("context"), &str))
wnd->m_context->SetValue(str); wnd->m_context->SetValue(str);
return wxPersistentTLWEx::Restore(); int guiLevel;
return RestoreValue(wxT("guiLevel"), &guiLevel) && guiLevel == s_guiLevel ? wxPersistentTLWEx::Restore() : true;
} }

View File

@ -58,6 +58,9 @@ public:
virtual void Save() const; virtual void Save() const;
virtual bool Restore(); virtual bool Restore();
protected:
static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels
}; };

View File

@ -786,6 +786,9 @@ bool __cdecl wxZRColaCharSelect::SearchThread::TestDestroyS(void *cookie)
// wxPersistentZRColaCharSelect // wxPersistentZRColaCharSelect
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
const int wxPersistentZRColaCharSelect::s_guiLevel = 1;
wxPersistentZRColaCharSelect::wxPersistentZRColaCharSelect(wxZRColaCharSelect *wnd) : wxPersistentTLWEx(wnd) wxPersistentZRColaCharSelect::wxPersistentZRColaCharSelect(wxZRColaCharSelect *wnd) : wxPersistentTLWEx(wnd)
{ {
} }
@ -793,6 +796,7 @@ wxPersistentZRColaCharSelect::wxPersistentZRColaCharSelect(wxZRColaCharSelect *w
void wxPersistentZRColaCharSelect::Save() const void wxPersistentZRColaCharSelect::Save() const
{ {
SaveValue(wxT("guiLevel"), s_guiLevel);
wxPersistentTLWEx::Save(); wxPersistentTLWEx::Save();
auto wnd = static_cast<const wxZRColaCharSelect*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. auto wnd = static_cast<const wxZRColaCharSelect*>(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(); wnd->ResetResults();
return wxPersistentTLWEx::Restore(); int guiLevel;
return RestoreValue(wxT("guiLevel"), &guiLevel) && guiLevel == s_guiLevel ? wxPersistentTLWEx::Restore() : true;
} }

View File

@ -228,6 +228,9 @@ public:
virtual void Save() const; virtual void Save() const;
virtual bool Restore(); virtual bool Restore();
protected:
static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels
}; };

View File

@ -398,6 +398,9 @@ void wxZRColaComposerPanel::SetHexValue(wxTextCtrl *wnd, std::pair<long, long> &
// wxPersistentZRColaComposerPanel // wxPersistentZRColaComposerPanel
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
const int wxPersistentZRColaComposerPanel::s_guiLevel = 1;
wxPersistentZRColaComposerPanel::wxPersistentZRColaComposerPanel(wxZRColaComposerPanel *wnd) : wxPersistentWindow<wxZRColaComposerPanel>(wnd) wxPersistentZRColaComposerPanel::wxPersistentZRColaComposerPanel(wxZRColaComposerPanel *wnd) : wxPersistentWindow<wxZRColaComposerPanel>(wnd)
{ {
} }
@ -413,6 +416,7 @@ void wxPersistentZRColaComposerPanel::Save() const
{ {
auto wnd = static_cast<wxZRColaComposerPanel*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. auto wnd = static_cast<wxZRColaComposerPanel*>(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("dpiX" ), wxClientDC(wnd).GetPPI().x);
SaveValue(wxT("splitDecomposed"), wnd->m_splitterSource ->GetSashPosition()); SaveValue(wxT("splitDecomposed"), wnd->m_splitterSource ->GetSashPosition());
SaveValue(wxT("splitComposed" ), wnd->m_splitterDestination->GetSashPosition()); SaveValue(wxT("splitComposed" ), wnd->m_splitterDestination->GetSashPosition());
@ -423,6 +427,10 @@ bool wxPersistentZRColaComposerPanel::Restore()
{ {
auto wnd = dynamic_cast<wxZRColaComposerPanel*>(GetWindow()); auto wnd = dynamic_cast<wxZRColaComposerPanel*>(GetWindow());
int guiLevel;
if (!RestoreValue(wxT("guiLevel"), &guiLevel) || guiLevel != s_guiLevel)
return true;
int dpiHorz = wxClientDC(wnd).GetPPI().x; int dpiHorz = wxClientDC(wnd).GetPPI().x;
int dpiHorzVal; int dpiHorzVal;
int sashVal; int sashVal;

View File

@ -88,6 +88,9 @@ public:
virtual wxString GetKind() const; virtual wxString GetKind() const;
virtual void Save() const; virtual void Save() const;
virtual bool Restore(); virtual bool Restore();
protected:
static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels
}; };

View File

@ -64,6 +64,9 @@ wxBEGIN_EVENT_TABLE(wxZRColaFrame, wxZRColaFrameBase)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
const int wxZRColaFrame::s_guiLevel = 1;
wxZRColaFrame::wxZRColaFrame() : wxZRColaFrame::wxZRColaFrame() :
m_hWndSource(NULL), m_hWndSource(NULL),
m_wasIconised(false), m_wasIconised(false),
@ -173,9 +176,12 @@ wxZRColaFrame::wxZRColaFrame() :
SetAcceleratorTable(wxAcceleratorTable(_countof(entries), entries)); SetAcceleratorTable(wxAcceleratorTable(_countof(entries), entries));
} }
// Restore persistent state of wxAuiManager manually, since m_mgr is not a standalone heap object int guiLevel;
// and cannot be registered for persistence. if (wxConfigBase::Get()->Read(wxT("guiLevel"), &guiLevel) && guiLevel == s_guiLevel) {
wxPersistentAuiManager(&m_mgr).Restore(); // 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)); persist_mgr.RegisterAndRestore(this, new wxPersistentZRColaFrame(this));
// Update (de)composition selection. // Update (de)composition selection.
@ -219,6 +225,7 @@ wxZRColaFrame::~wxZRColaFrame()
// Save wxAuiManager's state before destructor is finished. // 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. // 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(); wxPersistentAuiManager(&m_mgr).Save();
wxPersistenceManager::Get().SaveAndUnregister(this); wxPersistenceManager::Get().SaveAndUnregister(this);
@ -717,6 +724,9 @@ WXLRESULT wxZRColaFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM
// wxPersistentZRColaFrame // wxPersistentZRColaFrame
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
const int wxPersistentZRColaFrame::s_guiLevel = 1;
wxPersistentZRColaFrame::wxPersistentZRColaFrame(wxZRColaFrame *wnd) : wxPersistentTLWEx(wnd) wxPersistentZRColaFrame::wxPersistentZRColaFrame(wxZRColaFrame *wnd) : wxPersistentTLWEx(wnd)
{ {
} }
@ -724,6 +734,7 @@ wxPersistentZRColaFrame::wxPersistentZRColaFrame(wxZRColaFrame *wnd) : wxPersist
void wxPersistentZRColaFrame::Save() const void wxPersistentZRColaFrame::Save() const
{ {
SaveValue(wxT("guiLevel"), s_guiLevel);
wxPersistentTLWEx::Save(); wxPersistentTLWEx::Save();
auto wnd = static_cast<const wxZRColaFrame*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. auto wnd = static_cast<const wxZRColaFrame*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor.
@ -753,5 +764,6 @@ bool wxPersistentZRColaFrame::Restore()
else else
wnd->m_composition = wnd->m_transeq_id == ZRCOLA_TRANSEQID_DEFAULT; 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;
} }

View File

@ -130,6 +130,9 @@ protected:
virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
#endif #endif
protected:
static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels
protected: protected:
WXHWND m_hWndSource; ///< Handle of the active window, when the ZRCola hotkey was pressed 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 bool m_wasIconised; ///< Was the ZRCola window iconized, when the ZRCola hotkey was pressed
@ -153,6 +156,9 @@ public:
virtual void Save() const; virtual void Save() const;
virtual bool Restore(); virtual bool Restore();
protected:
static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels
}; };

View File

@ -139,6 +139,9 @@ void wxZRColaSettings::OnOKButtonClick(wxCommandEvent& event)
// wxPersistentZRColaSettings // wxPersistentZRColaSettings
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
const int wxPersistentZRColaSettings::s_guiLevel = 1;
wxPersistentZRColaSettings::wxPersistentZRColaSettings(wxZRColaSettings *wnd) : wxPersistentTLWEx(wnd) wxPersistentZRColaSettings::wxPersistentZRColaSettings(wxZRColaSettings *wnd) : wxPersistentTLWEx(wnd)
{ {
} }
@ -146,6 +149,7 @@ wxPersistentZRColaSettings::wxPersistentZRColaSettings(wxZRColaSettings *wnd) :
void wxPersistentZRColaSettings::Save() const void wxPersistentZRColaSettings::Save() const
{ {
SaveValue(wxT("guiLevel"), s_guiLevel);
wxPersistentTLWEx::Save(); wxPersistentTLWEx::Save();
auto wnd = static_cast<const wxZRColaSettings*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. auto wnd = static_cast<const wxZRColaSettings*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor.
@ -177,5 +181,6 @@ bool wxPersistentZRColaSettings::Restore()
} else } else
wnd->m_lang = ZRCola::langid_t::blank; wnd->m_lang = ZRCola::langid_t::blank;
return wxPersistentTLWEx::Restore(); int guiLevel;
return RestoreValue(wxT("guiLevel"), &guiLevel) && guiLevel == s_guiLevel ? wxPersistentTLWEx::Restore() : true;
} }

View File

@ -63,6 +63,9 @@ public:
virtual void Save() const; virtual void Save() const;
virtual bool Restore(); virtual bool Restore();
protected:
static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels
}; };

View File

@ -208,6 +208,9 @@ void wxZRColaTranslationSeq::OnOKButtonClick(wxCommandEvent& event)
// wxPersistentZRColaTranslationSeq // wxPersistentZRColaTranslationSeq
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
const int wxPersistentZRColaTranslationSeq::s_guiLevel = 1;
wxPersistentZRColaTranslationSeq::wxPersistentZRColaTranslationSeq(wxZRColaTranslationSeq *wnd) : wxPersistentTLWEx(wnd) wxPersistentZRColaTranslationSeq::wxPersistentZRColaTranslationSeq(wxZRColaTranslationSeq *wnd) : wxPersistentTLWEx(wnd)
{ {
} }
@ -215,6 +218,7 @@ wxPersistentZRColaTranslationSeq::wxPersistentZRColaTranslationSeq(wxZRColaTrans
void wxPersistentZRColaTranslationSeq::Save() const void wxPersistentZRColaTranslationSeq::Save() const
{ {
SaveValue(wxT("guiLevel"), s_guiLevel);
wxPersistentTLWEx::Save(); wxPersistentTLWEx::Save();
auto wnd = static_cast<const wxZRColaTranslationSeq*>(GetWindow()); // dynamic_cast is not reliable as we are typically called late in the wxTopLevelWindowMSW destructor. auto wnd = static_cast<const wxZRColaTranslationSeq*>(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); wnd->m_transeq = std::move(transet);
} }
return wxPersistentTLWEx::Restore(); int guiLevel;
return RestoreValue(wxT("guiLevel"), &guiLevel) && guiLevel == s_guiLevel ? wxPersistentTLWEx::Restore() : true;
} }

View File

@ -71,6 +71,9 @@ public:
virtual void Save() const; virtual void Save() const;
virtual bool Restore(); virtual bool Restore();
protected:
static const int s_guiLevel; ///< Persisted placements/sizing are considered incompatible between different GUI levels
}; };