Save window maximized state

This commit is contained in:
Charles J. Cliffe 2015-07-16 18:57:03 -04:00
parent 291ec7038a
commit 9c9e82cffc
3 changed files with 37 additions and 0 deletions

View File

@ -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);

View File

@ -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<std::string, DeviceConfig *> deviceConfig;
std::atomic_int winX,winY,winW,winH;
std::atomic_bool winMax;
std::atomic_int themeId;
};

View File

@ -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();