FXBaseObject.cpp

Go to the documentation of this file.
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     app=(FXApp*)-1;
00095     target=(FXObject*)-1;
00096 }
00097 
00098 // save object to stream
00099 void FXBaseObject::save(FXStream& store) const {
00100     FXObject::save(store);
00101     store << app;
00102     store << target;
00103     store << message;
00104     store << flags;
00105     store << options;
00106     store << datalen;
00107     store.save((FXuchar*)data,(unsigned long)datalen);
00108 }
00109 
00110 // load object from stream
00111 void FXBaseObject::load(FXStream& store) {
00112     FXObject::load(store);
00113     store >> app;
00114     store >> target;
00115     store >> message;
00116     store >> flags;
00117     store >> options;
00118     store >> datalen;
00119     store.load((FXuchar*)data,(unsigned long)datalen);
00120 }
00121 
00122 // this allows FXBaseObject derived classes to be singletons
00123 FXApp* FXBaseObject::getApp() {
00124     if (app) return app;
00125     return FXApp::instance();
00126 }
00127 
00128 // set the readonly flag
00129 void FXBaseObject::setReadonly(FXbool mode) {
00130     if (mode) flags|=FLAG_READONLY;
00131     else flags&=~FLAG_READONLY;
00132 }
00133 
00134 // handle enable event
00135 long FXBaseObject::onCmdEnable(FXObject*,FXSelector,void*) {
00136     enable();
00137     return 1;
00138 }
00139 
00140 // handle disable event
00141 long FXBaseObject::onCmdDisable(FXObject*,FXSelector,void*) {
00142     disable();
00143     return 1;
00144 }
00145 
00146 // handle update event
00147 long FXBaseObject::onUpdate(FXObject *sender,FXSelector,void*) {
00148     if (flags&FLAG_ENABLED)
00149         sender->handle(this,FXSEL(SEL_UPDATE,FXWindow::ID_ENABLE),NULL);
00150     else
00151         sender->handle(this,FXSEL(SEL_UPDATE,FXWindow::ID_DISABLE),NULL);
00152     return 1;
00153 }
00154 
00155 }
00156 

Generated on Wed May 5 00:06:29 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6