SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FXBaseObject.cpp
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * Base of lots of non-widgets *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************/
22 /* =========================================================================
23  * included modules
24  * ======================================================================= */
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <fxver.h>
32 #include <xincs.h>
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 #ifdef CHECK_MEMORY_LEAKS
51 #include <foreign/nvwa/debug_new.h>
52 #endif // CHECK_MEMORY_LEAKS
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