From d32c8b79dcad2c371c19e3940ec1294f992bd6fd Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Tue, 3 May 2016 13:17:15 +0200 Subject: [PATCH] wxPersistentAuiManager class for wxAuiManager state save and restore support added --- build/wxExtend.vcxproj | 1 + build/wxExtend.vcxproj.filters | 6 +++ include/wxex/persist/auimanager.h | 89 +++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 include/wxex/persist/auimanager.h diff --git a/build/wxExtend.vcxproj b/build/wxExtend.vcxproj index 6522d3d..c2cf806 100644 --- a/build/wxExtend.vcxproj +++ b/build/wxExtend.vcxproj @@ -37,6 +37,7 @@ + diff --git a/build/wxExtend.vcxproj.filters b/build/wxExtend.vcxproj.filters index 97b2904..afc9104 100644 --- a/build/wxExtend.vcxproj.filters +++ b/build/wxExtend.vcxproj.filters @@ -17,6 +17,9 @@ {e43059ae-37ac-4b28-84fb-18d1b3972b30} po;pot + + {33d4709f-47d3-42c1-9562-bc4743799b49} + @@ -60,6 +63,9 @@ Header Files + + Header Files\persist + diff --git a/include/wxex/persist/auimanager.h b/include/wxex/persist/auimanager.h new file mode 100644 index 0000000..6eb1054 --- /dev/null +++ b/include/wxex/persist/auimanager.h @@ -0,0 +1,89 @@ +/* + Copyright 2015-2016 Amebis + + This file is part of wxExtend. + + wxExtend is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + wxExtend is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with wxExtend. If not, see . +*/ + +#pragma once + +#include "../common.h" + +#include +#include + + +// ---------------------------------------------------------------------------- +// string constants used by wxPersistentAuiManager +// ---------------------------------------------------------------------------- + +#define wxPERSIST_AUIMGR_KIND "AuiManager" + +// names for persistent options +#define wxPERSIST_AUIMGR_PERSPECTIVE "perspective" + + +/// +/// Supports saving/restoring wxAuiManager state +/// +class wxPersistentAuiManager : public wxPersistentObject +{ +public: + wxPersistentAuiManager(wxAuiManager *mgr) : wxPersistentObject(mgr) + { + } + + virtual wxString GetKind() const + { + return wxT(wxPERSIST_AUIMGR_KIND); + } + + virtual wxString GetName() const + { + // Borrow the name of wxAguiManager from its window. + return GetManager()->GetManagedWindow()->GetName(); + } + + virtual void Save() const + { + // Save perspective string to configuration. + SaveValue(wxT(wxPERSIST_AUIMGR_PERSPECTIVE), GetManager()->SavePerspective()); + } + + virtual bool Restore() + { + // Load perspective string from configuration. + wxString persp; + return RestoreValue(wxT(wxPERSIST_AUIMGR_PERSPECTIVE), &persp) && GetManager()->LoadPerspective(persp); + } + +protected: + wxAuiManager *GetManager() const + { + return static_cast(GetObject()); + } + +private: + wxDECLARE_NO_COPY_CLASS(wxPersistentAuiManager); +}; + + +/// +/// wxAuiManager's instantiation of wxCreatePersistentObject template +/// +inline wxPersistentObject *wxCreatePersistentObject(wxAuiManager *mgr) +{ + return new wxPersistentAuiManager(mgr); +}