FXBaseObject.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00037
00038
00039
00040
00041
00042
00043
00044
00045
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
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
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
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
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
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
00123 FXApp* FXBaseObject::getApp() {
00124 if (app) return app;
00125 return FXApp::instance();
00126 }
00127
00128
00129 void FXBaseObject::setReadonly(FXbool mode) {
00130 if (mode) flags|=FLAG_READONLY;
00131 else flags&=~FLAG_READONLY;
00132 }
00133
00134
00135 long FXBaseObject::onCmdEnable(FXObject*,FXSelector,void*) {
00136 enable();
00137 return 1;
00138 }
00139
00140
00141 long FXBaseObject::onCmdDisable(FXObject*,FXSelector,void*) {
00142 disable();
00143 return 1;
00144 }
00145
00146
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