Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/div/GUIPersistentWindowPos.cpp
169684 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file GUIPersistentWindowPos.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Thu, 11.03.2004
19
///
20
// Editor for the list of chosen objects
21
/****************************************************************************/
22
#include <config.h>
23
24
#include <string>
25
#include <vector>
26
#include <iostream>
27
#include <fstream>
28
#include <utils/common/MsgHandler.h>
29
#include <utils/gui/windows/GUIAppEnum.h>
30
#include <utils/gui/globjects/GUIGlObject.h>
31
#include <utils/foxtools/MFXUtils.h>
32
#include "GUIPersistentWindowPos.h"
33
#include <utils/gui/div/GUIGlobalSelection.h>
34
#include <utils/gui/globjects/GUIGlObjectStorage.h>
35
#include <utils/gui/div/GUIIOGlobals.h>
36
#include <utils/gui/div/GUIDesigns.h>
37
#include <utils/gui/windows/GUIMainWindow.h>
38
#include <utils/gui/images/GUIIconSubSys.h>
39
40
41
42
// ===========================================================================
43
// method definitions
44
// ===========================================================================
45
46
GUIPersistentWindowPos::GUIPersistentWindowPos(FXWindow* parent, const std::string& name, bool storeSize,
47
int x, int y,
48
int width, int height,
49
int minSize, int minTitlebarHeight) :
50
myParent(parent),
51
myWindowName(name),
52
myStoreSize(storeSize),
53
myDefaultX(x),
54
myDefaultY(y),
55
myDefaultWidth(width),
56
myDefaultHeight(height),
57
myMinSize(minSize),
58
myMinTitlebarHeight(minTitlebarHeight)
59
{}
60
61
GUIPersistentWindowPos::GUIPersistentWindowPos() :
62
myParent(nullptr)
63
{ }
64
65
GUIPersistentWindowPos::~GUIPersistentWindowPos() {
66
saveWindowPos();
67
}
68
69
70
void
71
GUIPersistentWindowPos::saveWindowPos() {
72
if (myParent != nullptr) {
73
FXRegistry& reg = myParent->getApp()->reg();
74
reg.writeIntEntry(myWindowName.c_str(), "x", myParent->getX());
75
reg.writeIntEntry(myWindowName.c_str(), "y", myParent->getY());
76
if (myStoreSize) {
77
reg.writeIntEntry(myWindowName.c_str(), "width", myParent->getWidth());
78
reg.writeIntEntry(myWindowName.c_str(), "height", myParent->getHeight());
79
}
80
}
81
}
82
83
void
84
GUIPersistentWindowPos::loadWindowPos() {
85
if (myParent != nullptr) {
86
FXRegistry& reg = myParent->getApp()->reg();
87
// ensure window is visible after switching screen resolutions
88
myParent->setX(MAX2(0, MIN2(reg.readIntEntry(myWindowName.c_str(), "x", myDefaultX),
89
myParent->getApp()->getRootWindow()->getWidth() - myMinSize)));
90
myParent->setY(MAX2(myMinTitlebarHeight,
91
MIN2(reg.readIntEntry(myWindowName.c_str(), "y", myDefaultY),
92
myParent->getApp()->getRootWindow()->getHeight() - myMinSize)));
93
if (myStoreSize) {
94
myParent->setWidth(MAX2(reg.readIntEntry(myWindowName.c_str(), "width", myDefaultWidth), myMinSize));
95
myParent->setHeight(MAX2(reg.readIntEntry(myWindowName.c_str(), "height", myDefaultHeight), myMinSize));
96
}
97
}
98
}
99
100
/****************************************************************************/
101
102