Eclipse SUMO - Simulation of Urban MObility
FXBaseObject.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2003-2020 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 #include <fxver.h>
30 #define NOMINMAX
31 #include <xincs.h>
32 #undef NOMINMAX
33 #include <fxdefs.h>
34 #include <fx.h>
35 /*
36 #include <FXString.h>
37 #include <FXHash.h>
38 #include <FXStream.h>
39 #include <FXSize.h>
40 #include <FXPoint.h>
41 #include <FXRectangle.h>
42 #include <FXRegistry.h>
43 #include <FXMutex.h>
44 #include <FXApp.h>
45 #include <FXWindow.h>
46 */
47 using namespace FX;
48 #include "FXBaseObject.h"
49 
50 using namespace FXEX;
51 namespace FXEX {
52 
53 FXDEFMAP(FXBaseObject) FXBaseObjectMap[] = {
54  FXMAPFUNC(SEL_COMMAND, FXWindow::ID_ENABLE, FXBaseObject::onCmdEnable),
55  FXMAPFUNC(SEL_COMMAND, FXWindow::ID_DISABLE, FXBaseObject::onCmdDisable),
56  FXMAPFUNC(SEL_UPDATE, FXWindow::ID_DISABLE, FXBaseObject::onUpdate),
57 };
58 FXIMPLEMENT(FXBaseObject, FXObject, FXBaseObjectMap, ARRAYNUMBER(FXBaseObjectMap))
59 
60 // ctor
61 FXBaseObject::FXBaseObject(FXObject* tgt, FXSelector sel) : FXObject() {
62  data = nullptr;
63  target = tgt;
64  message = sel;
65  flags = 0;
66  app = FXApp::instance();
67  if (app == nullptr) {
68  fxerror("%s: Cannot create object without FXApp object\n", getClassName());
69  }
70 }
71 
72 // ctor
73 FXBaseObject::FXBaseObject(FXApp* a, FXObject* tgt, FXSelector sel) : FXObject() {
74  data = nullptr;
75  target = tgt;
76  message = sel;
77  flags = 0;
78  app = a;
79  if (app == nullptr) {
80  app = FXApp::instance();
81  }
82  if (app == nullptr) {
83  fxerror("%s: Cannot create object without FXApp object\n", getClassName());
84  }
85 }
86 
87 // free up all resources
89  if (data != nullptr && data != (void*) - 1) {
90  fxerror("%s::~%s - user data is not NULL prior to destruction\n", getClassName(), getClassName());
91  }
92  app = (FXApp*) - 1;
93  target = (FXObject*) - 1;
94 }
95 
96 // save object to stream
97 void FXBaseObject::save(FXStream& store) const {
98  FXObject::save(store);
99  store << app;
100  store << target;
101  store << message;
102  store << flags;
103  store << options;
104  store << datalen;
105  store.save((FXuchar*)data, (unsigned long)datalen);
106 }
107 
108 // load object from stream
109 void FXBaseObject::load(FXStream& store) {
110  FXObject::load(store);
111  store >> app;
112  store >> target;
113  store >> message;
114  store >> flags;
115  store >> options;
116  store >> datalen;
117  store.load((FXuchar*)data, (unsigned long)datalen);
118 }
119 
120 // this allows FXBaseObject derived classes to be singletons
122  if (app) {
123  return app;
124  }
125  return FXApp::instance();
126 }
127 
128 // set the readonly flag
129 void FXBaseObject::setReadonly(FXbool mode) {
130  if (mode) {
131  flags |= FLAG_READONLY;
132  } else {
133  flags &= ~FLAG_READONLY;
134  }
135 }
136 
137 // handle enable event
138 long FXBaseObject::onCmdEnable(FXObject*, FXSelector, void*) {
139  enable();
140  return 1;
141 }
142 
143 // handle disable event
144 long FXBaseObject::onCmdDisable(FXObject*, FXSelector, void*) {
145  disable();
146  return 1;
147 }
148 
149 // handle update event
150 long FXBaseObject::onUpdate(FXObject* sender, FXSelector, void*) {
151  if (flags & FLAG_ENABLED) {
152  sender->handle(this, FXSEL(SEL_UPDATE, FXWindow::ID_ENABLE), nullptr);
153  } else {
154  sender->handle(this, FXSEL(SEL_UPDATE, FXWindow::ID_DISABLE), nullptr);
155  }
156  return 1;
157 }
158 
159 }
160 
FXSelector message
Definition: FXBaseObject.h:77
virtual void load(FXStream &store)
load object from stream
long onCmdDisable(FXObject *, FXSelector, void *)
long onCmdEnable(FXObject *, FXSelector, void *)
FXObject * target
Definition: FXBaseObject.h:76
FXApp * getApp()
application pointer
virtual ~FXBaseObject()
dtor
virtual void enable()
enable us
Definition: FXBaseObject.h:168
virtual void setReadonly(FXbool mode=TRUE)
set modifiable mode
virtual void disable()
disable us
Definition: FXBaseObject.h:173
long onUpdate(FXObject *, FXSelector, void *)
virtual void save(FXStream &store) const
save object to stream
FXDEFMAP(FXBaseObject) FXBaseObjectMap[]