From 9c9e82cffc9ae8332ecf7a59a715e433f4e58b99 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 16 Jul 2015 18:57:03 -0400 Subject: [PATCH] Save window maximized state --- src/AppConfig.cpp | 26 ++++++++++++++++++++++++++ src/AppConfig.h | 5 +++++ src/AppFrame.cpp | 6 ++++++ 3 files changed, 37 insertions(+) diff --git a/src/AppConfig.cpp b/src/AppConfig.cpp index 8fb6d92..d6db8dc 100644 --- a/src/AppConfig.cpp +++ b/src/AppConfig.cpp @@ -114,6 +114,16 @@ void DeviceConfig::load(DataNode *node) { busy_lock.unlock(); } +AppConfig::AppConfig() { + winX.store(0); + winY.store(0); + winW.store(0); + winH.store(0); + winMax.store(false); + themeId.store(0); +} + + DeviceConfig *AppConfig::getDevice(std::string deviceId) { if (deviceConfig.find(deviceId) == deviceConfig.end()) { @@ -150,6 +160,14 @@ void AppConfig::setWindow(wxPoint winXY, wxSize winWH) { winH.store(winWH.y); } +void AppConfig::setWindowMaximized(bool max) { + winMax.store(max); +} + +bool AppConfig::getWindowMaximized() { + return winMax.load(); +} + wxRect *AppConfig::getWindow() { wxRect *r = NULL; if (winH.load() && winW.load()) { @@ -181,6 +199,8 @@ bool AppConfig::save() { *window_node->newChild("w") = winW.load(); *window_node->newChild("h") = winH.load(); + *window_node->newChild("max") = winMax.load(); + *window_node->newChild("theme") = themeId.load(); } @@ -228,6 +248,7 @@ bool AppConfig::load() { if (cfg.rootNode()->hasAnother("window")) { int x,y,w,h; + int max; DataNode *win_node = cfg.rootNode()->getNext("window"); @@ -243,6 +264,11 @@ bool AppConfig::load() { winH.store(h); } + if (win_node->hasAnother("max")) { + win_node->getNext("max")->element()->get(max); + winMax.store(max?true:false); + } + if (win_node->hasAnother("theme")) { int theme; win_node->getNext("theme")->element()->get(theme); diff --git a/src/AppConfig.h b/src/AppConfig.h index 9d98957..debc640 100644 --- a/src/AppConfig.h +++ b/src/AppConfig.h @@ -43,12 +43,16 @@ private: class AppConfig { public: + AppConfig(); std::string getConfigDir(); DeviceConfig *getDevice(std::string deviceId); void setWindow(wxPoint winXY, wxSize winWH); wxRect *getWindow(); + void setWindowMaximized(bool max); + bool getWindowMaximized(); + void setTheme(int themeId); int getTheme(); @@ -59,5 +63,6 @@ public: private: std::map deviceConfig; std::atomic_int winX,winY,winW,winH; + std::atomic_bool winMax; std::atomic_int themeId; }; diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 363e304..eab1a5b 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -313,6 +313,11 @@ AppFrame::AppFrame() : SetClientSize(1280, 600); Centre(); } + bool max = wxGetApp().getConfig()->getWindowMaximized(); + + if (max) { + this->Maximize(); + } ThemeMgr::mgr.setTheme(wxGetApp().getConfig()->getTheme()); @@ -520,6 +525,7 @@ void AppFrame::OnMenu(wxCommandEvent& event) { void AppFrame::OnClose(wxCloseEvent& event) { wxGetApp().getConfig()->setWindow(this->GetPosition(), this->GetClientSize()); + wxGetApp().getConfig()->setWindowMaximized(this->IsMaximized()); wxGetApp().getConfig()->setTheme(ThemeMgr::mgr.getTheme()); wxGetApp().getConfig()->save(); event.Skip();