void window_geometry_saver_c::restore() { int x = 0, y = 0; bool valid = false; auto cfg = wxConfigBase::Get(); cfg->SetPath(get_config_group()); // Position if (cfg->Read(wxT("x"), &x, 0) && cfg->Read(wxT("y"), &y, 0) && (0 <= x) && (0 <= y)) valid = true; else if (m_x && m_y) { x = *m_x; y = *m_y; valid = true; } if (valid) { x = std::min<int>(x, wxSystemSettings::GetMetric(wxSYS_SCREEN_X) - 50); y = std::min<int>(y, wxSystemSettings::GetMetric(wxSYS_SCREEN_Y) - 32); m_window->Move(x, y); } // Size valid = false; if (cfg->Read(wxT("width"), &x, 0) && cfg->Read(wxT("height"), &y, 0)) valid = true; else if (m_width && m_height) { x = *m_width; y = *m_height; valid = true; } if (m_width && m_height && m_set_as_min_size) m_window->SetMinSize(wxSize{static_cast<int>(*m_width), static_cast<int>(*m_height)}); if (valid) { x = std::max(std::min<int>(x, wxSystemSettings::GetMetric(wxSYS_SCREEN_X)), 100); y = std::max(std::min<int>(y, wxSystemSettings::GetMetric(wxSYS_SCREEN_Y)), 100); m_restored_width = x; m_restored_height = y; m_window->SetSize(x, y); } }
void window_geometry_saver_c::save() const { auto rect = m_window->GetRect(); auto cfg = wxConfigBase::Get(); cfg->SetPath(get_config_group()); if ((rect.GetX() >= 0) && (rect.GetY() >= 0)) { cfg->Write(wxT("x"), rect.GetX()); cfg->Write(wxT("y"), rect.GetY()); } if ((rect.GetWidth() > 0) && (rect.GetHeight() > 0)) { cfg->Write(wxT("width"), rect.GetWidth()); cfg->Write(wxT("height"), rect.GetHeight()); } }