Path: blob/main/src/utils/gui/div/GUIPersistentWindowPos.cpp
169684 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GUIPersistentWindowPos.cpp14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Thu, 11.03.200418///19// Editor for the list of chosen objects20/****************************************************************************/21#include <config.h>2223#include <string>24#include <vector>25#include <iostream>26#include <fstream>27#include <utils/common/MsgHandler.h>28#include <utils/gui/windows/GUIAppEnum.h>29#include <utils/gui/globjects/GUIGlObject.h>30#include <utils/foxtools/MFXUtils.h>31#include "GUIPersistentWindowPos.h"32#include <utils/gui/div/GUIGlobalSelection.h>33#include <utils/gui/globjects/GUIGlObjectStorage.h>34#include <utils/gui/div/GUIIOGlobals.h>35#include <utils/gui/div/GUIDesigns.h>36#include <utils/gui/windows/GUIMainWindow.h>37#include <utils/gui/images/GUIIconSubSys.h>38394041// ===========================================================================42// method definitions43// ===========================================================================4445GUIPersistentWindowPos::GUIPersistentWindowPos(FXWindow* parent, const std::string& name, bool storeSize,46int x, int y,47int width, int height,48int minSize, int minTitlebarHeight) :49myParent(parent),50myWindowName(name),51myStoreSize(storeSize),52myDefaultX(x),53myDefaultY(y),54myDefaultWidth(width),55myDefaultHeight(height),56myMinSize(minSize),57myMinTitlebarHeight(minTitlebarHeight)58{}5960GUIPersistentWindowPos::GUIPersistentWindowPos() :61myParent(nullptr)62{ }6364GUIPersistentWindowPos::~GUIPersistentWindowPos() {65saveWindowPos();66}676869void70GUIPersistentWindowPos::saveWindowPos() {71if (myParent != nullptr) {72FXRegistry& reg = myParent->getApp()->reg();73reg.writeIntEntry(myWindowName.c_str(), "x", myParent->getX());74reg.writeIntEntry(myWindowName.c_str(), "y", myParent->getY());75if (myStoreSize) {76reg.writeIntEntry(myWindowName.c_str(), "width", myParent->getWidth());77reg.writeIntEntry(myWindowName.c_str(), "height", myParent->getHeight());78}79}80}8182void83GUIPersistentWindowPos::loadWindowPos() {84if (myParent != nullptr) {85FXRegistry& reg = myParent->getApp()->reg();86// ensure window is visible after switching screen resolutions87myParent->setX(MAX2(0, MIN2(reg.readIntEntry(myWindowName.c_str(), "x", myDefaultX),88myParent->getApp()->getRootWindow()->getWidth() - myMinSize)));89myParent->setY(MAX2(myMinTitlebarHeight,90MIN2(reg.readIntEntry(myWindowName.c_str(), "y", myDefaultY),91myParent->getApp()->getRootWindow()->getHeight() - myMinSize)));92if (myStoreSize) {93myParent->setWidth(MAX2(reg.readIntEntry(myWindowName.c_str(), "width", myDefaultWidth), myMinSize));94myParent->setHeight(MAX2(reg.readIntEntry(myWindowName.c_str(), "height", myDefaultHeight), myMinSize));95}96}97}9899/****************************************************************************/100101102