Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/foxtools/MFXBaseObject.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2003-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 MFXBaseObject.cpp
15
/// @author Mathew Robertson
16
/// @author Daniel Krajzewicz
17
/// @author Michael Behrisch
18
/// @date 2004-03-19
19
///
20
//
21
/****************************************************************************/
22
23
24
/* =========================================================================
25
* included modules
26
* ======================================================================= */
27
#include <config.h>
28
29
#define NOMINMAX
30
#undef NOMINMAX
31
#include "fxheader.h"
32
/*
33
#include <FXString.h>
34
#include <FXHash.h>
35
#include <FXStream.h>
36
#include <FXSize.h>
37
#include <FXPoint.h>
38
#include <FXRectangle.h>
39
#include <FXRegistry.h>
40
#include <FXMutex.h>
41
#include <FXApp.h>
42
#include <FXWindow.h>
43
*/
44
using namespace FX;
45
#include "MFXBaseObject.h"
46
47
using namespace FXEX;
48
namespace FXEX {
49
50
FXDEFMAP(MFXBaseObject) MFXBaseObjectMap[] = {
51
FXMAPFUNC(SEL_COMMAND, FXWindow::ID_ENABLE, MFXBaseObject::onCmdEnable),
52
FXMAPFUNC(SEL_COMMAND, FXWindow::ID_DISABLE, MFXBaseObject::onCmdDisable),
53
FXMAPFUNC(SEL_UPDATE, FXWindow::ID_DISABLE, MFXBaseObject::onUpdate),
54
};
55
FXIMPLEMENT(MFXBaseObject, FXObject, MFXBaseObjectMap, ARRAYNUMBER(MFXBaseObjectMap))
56
57
// ctor
58
MFXBaseObject::MFXBaseObject(FXObject* tgt, FXSelector sel) : FXObject() {
59
data = nullptr;
60
target = tgt;
61
message = sel;
62
flags = 0;
63
app = FXApp::instance();
64
if (app == nullptr) {
65
fxerror("%s: Cannot create object without FXApp object\n", getClassName());
66
}
67
}
68
69
// ctor
70
MFXBaseObject::MFXBaseObject(FXApp* a, FXObject* tgt, FXSelector sel) : FXObject() {
71
data = nullptr;
72
target = tgt;
73
message = sel;
74
flags = 0;
75
app = a;
76
if (app == nullptr) {
77
app = FXApp::instance();
78
}
79
if (app == nullptr) {
80
fxerror("%s: Cannot create object without FXApp object\n", getClassName());
81
}
82
}
83
84
// free up all resources
85
MFXBaseObject::~MFXBaseObject() {
86
if (data != nullptr && data != (void*) - 1) {
87
fxerror("%s::~%s - user data is not NULL prior to destruction\n", getClassName(), getClassName());
88
}
89
app = (FXApp*) - 1;
90
target = (FXObject*) - 1;
91
}
92
93
// save object to stream
94
void MFXBaseObject::save(FXStream& store) const {
95
FXObject::save(store);
96
store << app;
97
store << target;
98
store << message;
99
store << flags;
100
store << options;
101
store << datalen;
102
store.save((FXuchar*)data, (unsigned long)datalen);
103
}
104
105
// load object from stream
106
void MFXBaseObject::load(FXStream& store) {
107
FXObject::load(store);
108
store >> app;
109
store >> target;
110
store >> message;
111
store >> flags;
112
store >> options;
113
store >> datalen;
114
store.load((FXuchar*)data, (unsigned long)datalen);
115
}
116
117
// this allows MFXBaseObject derived classes to be singletons
118
FXApp* MFXBaseObject::getApp() {
119
if (app) {
120
return app;
121
}
122
return FXApp::instance();
123
}
124
125
// set the readonly flag
126
void MFXBaseObject::setReadonly(FXbool mode) {
127
if (mode) {
128
flags |= FLAG_READONLY;
129
} else {
130
flags &= ~FLAG_READONLY;
131
}
132
}
133
134
// handle enable event
135
long MFXBaseObject::onCmdEnable(FXObject*, FXSelector, void*) {
136
enable();
137
return 1;
138
}
139
140
// handle disable event
141
long MFXBaseObject::onCmdDisable(FXObject*, FXSelector, void*) {
142
disable();
143
return 1;
144
}
145
146
// handle update event
147
long MFXBaseObject::onUpdate(FXObject* sender, FXSelector, void*) {
148
if (flags & FLAG_ENABLED) {
149
sender->handle(this, FXSEL(SEL_UPDATE, FXWindow::ID_ENABLE), nullptr);
150
} else {
151
sender->handle(this, FXSEL(SEL_UPDATE, FXWindow::ID_DISABLE), nullptr);
152
}
153
return 1;
154
}
155
156
}
157
158