Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MFXBaseObject.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2003-2024 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/****************************************************************************/
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*/
44using namespace FX;
45#include "MFXBaseObject.h"
46
47using namespace FXEX;
48namespace FXEX {
49
50FXDEFMAP(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};
55FXIMPLEMENT(MFXBaseObject, FXObject, MFXBaseObjectMap, ARRAYNUMBER(MFXBaseObjectMap))
56
57// ctor
58MFXBaseObject::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
70MFXBaseObject::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
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
94void 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
106void 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
119 if (app) {
120 return app;
121 }
122 return FXApp::instance();
123}
124
125// set the readonly flag
126void MFXBaseObject::setReadonly(FXbool mode) {
127 if (mode) {
129 } else {
130 flags &= ~FLAG_READONLY;
131 }
132}
133
134// handle enable event
135long MFXBaseObject::onCmdEnable(FXObject*, FXSelector, void*) {
136 enable();
137 return 1;
138}
139
140// handle disable event
141long MFXBaseObject::onCmdDisable(FXObject*, FXSelector, void*) {
142 disable();
143 return 1;
144}
145
146// handle update event
147long 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}
virtual ~MFXBaseObject()
dtor
virtual void save(FXStream &store) const
save object to stream
virtual void enable()
enable us
MFXBaseObject(FXObject *tgt=NULL, FXSelector sel=0)
Just supply the target and selector (de-serialisation too)
virtual void setReadonly(FXbool mode=TRUE)
set modifiable mode
long onCmdEnable(FXObject *, FXSelector, void *)
virtual void disable()
disable us
FXApp * getApp()
application pointer
long onUpdate(FXObject *, FXSelector, void *)
long onCmdDisable(FXObject *, FXSelector, void *)
virtual void load(FXStream &store)
load object from stream
FXDEFMAP(MFXBaseObject) MFXBaseObjectMap[]
Definition GUI.h:31