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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 //
20 /****************************************************************************/
21 
22 
23 /* =========================================================================
24  * included modules
25  * ======================================================================= */
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <fxver.h>
33 #define NOMINMAX
34 #include <xincs.h>
35 #undef NOMINMAX
36 #include <fxdefs.h>
37 #include <fx.h>
38 /*
39 #include <FXString.h>
40 #include <FXHash.h>
41 #include <FXStream.h>
42 #include <FXSize.h>
43 #include <FXPoint.h>
44 #include <FXRectangle.h>
45 #include <FXRegistry.h>
46 #include <FXMutex.h>
47 #include <FXApp.h>
48 #include <FXWindow.h>
49 */
50 using namespace FX;
51 #include "FXBaseObject.h"
52 
53 using namespace FXEX;
54 namespace FXEX {
55 
56 FXDEFMAP(FXBaseObject) FXBaseObjectMap[] = {
57  FXMAPFUNC(SEL_COMMAND, FXWindow::ID_ENABLE, FXBaseObject::onCmdEnable),
58  FXMAPFUNC(SEL_COMMAND, FXWindow::ID_DISABLE, FXBaseObject::onCmdDisable),
59  FXMAPFUNC(SEL_UPDATE, FXWindow::ID_DISABLE, FXBaseObject::onUpdate),
60 };
61 FXIMPLEMENT(FXBaseObject, FXObject, FXBaseObjectMap, ARRAYNUMBER(FXBaseObjectMap))
62 
63 // ctor
64 FXBaseObject::FXBaseObject(FXObject* tgt, FXSelector sel) : FXObject() {
65  data = NULL;
66  target = tgt;
67  message = sel;
68  flags = 0;
69  app = FXApp::instance();
70  if (app == NULL) {
71  fxerror("%s: Cannot create object without FXApp object\n", getClassName());
72  }
73 }
74 
75 // ctor
76 FXBaseObject::FXBaseObject(FXApp* a, FXObject* tgt, FXSelector sel) : FXObject() {
77  data = NULL;
78  target = tgt;
79  message = sel;
80  flags = 0;
81  app = a;
82  if (app == NULL) {
83  app = FXApp::instance();
84  }
85  if (app == NULL) {
86  fxerror("%s: Cannot create object without FXApp object\n", getClassName());
87  }
88 }
89 
90 // free up all resources
92  if (data != NULL && data != (void*) - 1) {
93  fxerror("%s::~%s - user data is not NULL prior to destruction\n", getClassName(), getClassName());
94  }
95  app = (FXApp*) - 1;
96  target = (FXObject*) - 1;
97 }
98 
99 // save object to stream
100 void FXBaseObject::save(FXStream& store) const {
101  FXObject::save(store);
102  store << app;
103  store << target;
104  store << message;
105  store << flags;
106  store << options;
107  store << datalen;
108  store.save((FXuchar*)data, (unsigned long)datalen);
109 }
110 
111 // load object from stream
112 void FXBaseObject::load(FXStream& store) {
113  FXObject::load(store);
114  store >> app;
115  store >> target;
116  store >> message;
117  store >> flags;
118  store >> options;
119  store >> datalen;
120  store.load((FXuchar*)data, (unsigned long)datalen);
121 }
122 
123 // this allows FXBaseObject derived classes to be singletons
125  if (app) {
126  return app;
127  }
128  return FXApp::instance();
129 }
130 
131 // set the readonly flag
132 void FXBaseObject::setReadonly(FXbool mode) {
133  if (mode) {
134  flags |= FLAG_READONLY;
135  } else {
136  flags &= ~FLAG_READONLY;
137  }
138 }
139 
140 // handle enable event
141 long FXBaseObject::onCmdEnable(FXObject*, FXSelector, void*) {
142  enable();
143  return 1;
144 }
145 
146 // handle disable event
147 long FXBaseObject::onCmdDisable(FXObject*, FXSelector, void*) {
148  disable();
149  return 1;
150 }
151 
152 // handle update event
153 long FXBaseObject::onUpdate(FXObject* sender, FXSelector, void*) {
154  if (flags & FLAG_ENABLED) {
155  sender->handle(this, FXSEL(SEL_UPDATE, FXWindow::ID_ENABLE), NULL);
156  } else {
157  sender->handle(this, FXSEL(SEL_UPDATE, FXWindow::ID_DISABLE), NULL);
158  }
159  return 1;
160 }
161 
162 }
163 
long onCmdEnable(FXObject *, FXSelector, void *)
virtual void disable()
disable us
Definition: FXBaseObject.h:181
virtual ~FXBaseObject()
dtor
virtual void enable()
enable us
Definition: FXBaseObject.h:176
FXApp * getApp()
application pointer
virtual void save(FXStream &store) const
save object to stream
FXSelector message
Definition: FXBaseObject.h:85
long onUpdate(FXObject *, FXSelector, void *)
virtual void setReadonly(FXbool mode=TRUE)
set modifiable mode
long onCmdDisable(FXObject *, FXSelector, void *)
virtual void load(FXStream &store)
load object from stream
FXObject * target
Definition: FXBaseObject.h:84
FXDEFMAP(FXRealSpinDialDial) FXSpinDialMap[]