SUMO - Simulation of Urban MObility
|
00001 /******************************************************************************** 00002 * * 00003 * Base of lots of non-widgets * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 *********************************************************************************/ 00022 /* ========================================================================= 00023 * included modules 00024 * ======================================================================= */ 00025 #ifdef _MSC_VER 00026 #include <windows_config.h> 00027 #else 00028 #include <config.h> 00029 #endif 00030 00031 #include <fxver.h> 00032 #include <xincs.h> 00033 #include <fxdefs.h> 00034 #include <fx.h> 00035 /* 00036 #include <FXString.h> 00037 #include <FXHash.h> 00038 #include <FXStream.h> 00039 #include <FXSize.h> 00040 #include <FXPoint.h> 00041 #include <FXRectangle.h> 00042 #include <FXRegistry.h> 00043 #include <FXMutex.h> 00044 #include <FXApp.h> 00045 #include <FXWindow.h> 00046 */ 00047 using namespace FX; 00048 #include "FXBaseObject.h" 00049 00050 #ifdef CHECK_MEMORY_LEAKS 00051 #include <foreign/nvwa/debug_new.h> 00052 #endif // CHECK_MEMORY_LEAKS 00053 using namespace FXEX; 00054 namespace FXEX { 00055 00056 FXDEFMAP(FXBaseObject) FXBaseObjectMap[] = { 00057 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_ENABLE, FXBaseObject::onCmdEnable), 00058 FXMAPFUNC(SEL_COMMAND, FXWindow::ID_DISABLE, FXBaseObject::onCmdDisable), 00059 FXMAPFUNC(SEL_UPDATE, FXWindow::ID_DISABLE, FXBaseObject::onUpdate), 00060 }; 00061 FXIMPLEMENT(FXBaseObject, FXObject, FXBaseObjectMap, ARRAYNUMBER(FXBaseObjectMap)) 00062 00063 // ctor 00064 FXBaseObject::FXBaseObject(FXObject* tgt, FXSelector sel) : FXObject() { 00065 data = NULL; 00066 target = tgt; 00067 message = sel; 00068 flags = 0; 00069 app = FXApp::instance(); 00070 if (app == NULL) { 00071 fxerror("%s: Cannot create object without FXApp object\n", getClassName()); 00072 } 00073 } 00074 00075 // ctor 00076 FXBaseObject::FXBaseObject(FXApp* a, FXObject* tgt, FXSelector sel) : FXObject() { 00077 data = NULL; 00078 target = tgt; 00079 message = sel; 00080 flags = 0; 00081 app = a; 00082 if (app == NULL) { 00083 app = FXApp::instance(); 00084 } 00085 if (app == NULL) { 00086 fxerror("%s: Cannot create object without FXApp object\n", getClassName()); 00087 } 00088 } 00089 00090 // free up all resources 00091 FXBaseObject::~FXBaseObject() { 00092 if (data != NULL && data != (void*) - 1) { 00093 fxerror("%s::~%s - user data is not NULL prior to destruction\n", getClassName(), getClassName()); 00094 } 00095 app = (FXApp*) - 1; 00096 target = (FXObject*) - 1; 00097 } 00098 00099 // save object to stream 00100 void FXBaseObject::save(FXStream& store) const { 00101 FXObject::save(store); 00102 store << app; 00103 store << target; 00104 store << message; 00105 store << flags; 00106 store << options; 00107 store << datalen; 00108 store.save((FXuchar*)data, (unsigned long)datalen); 00109 } 00110 00111 // load object from stream 00112 void FXBaseObject::load(FXStream& store) { 00113 FXObject::load(store); 00114 store >> app; 00115 store >> target; 00116 store >> message; 00117 store >> flags; 00118 store >> options; 00119 store >> datalen; 00120 store.load((FXuchar*)data, (unsigned long)datalen); 00121 } 00122 00123 // this allows FXBaseObject derived classes to be singletons 00124 FXApp* FXBaseObject::getApp() { 00125 if (app) { 00126 return app; 00127 } 00128 return FXApp::instance(); 00129 } 00130 00131 // set the readonly flag 00132 void FXBaseObject::setReadonly(FXbool mode) { 00133 if (mode) { 00134 flags |= FLAG_READONLY; 00135 } else { 00136 flags &= ~FLAG_READONLY; 00137 } 00138 } 00139 00140 // handle enable event 00141 long FXBaseObject::onCmdEnable(FXObject*, FXSelector, void*) { 00142 enable(); 00143 return 1; 00144 } 00145 00146 // handle disable event 00147 long FXBaseObject::onCmdDisable(FXObject*, FXSelector, void*) { 00148 disable(); 00149 return 1; 00150 } 00151 00152 // handle update event 00153 long FXBaseObject::onUpdate(FXObject* sender, FXSelector, void*) { 00154 if (flags & FLAG_ENABLED) { 00155 sender->handle(this, FXSEL(SEL_UPDATE, FXWindow::ID_ENABLE), NULL); 00156 } else { 00157 sender->handle(this, FXSEL(SEL_UPDATE, FXWindow::ID_DISABLE), NULL); 00158 } 00159 return 1; 00160 } 00161 00162 } 00163