Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members

FXBaseObject.h

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 #ifndef FXBASEOBJECT_H
00023 #define FXBASEOBJECT_H
00024 
00025 #ifndef FXOBJECT_H
00026 #include <fox/FXObject.h>
00027 using namespace FX;
00028 #endif
00029 namespace FXEX {
00030 
00031 /**
00032  * Define so that all types and all id's can go to a specific function.
00033  * This is particularily useful if you just want to forward the event to a target
00034  * but not specifically use the onDefault method.
00035  *
00036  * Note: if FXApp* is not specified, then FXApp::Instance() is used.
00037  */
00038 #define FXMAPALL(func) {MKUINT(MINKEY,MINTYPE),MKUINT(MAXKEY,MAXTYPE),&func}
00039 
00040 /**
00041  * Define so that we can use it to 'redirect' all unhandled events, of a specific key/ID
00042  */
00043 #define FXMAPKEY(key,func)  {MKUINT(key,MINTYPE),MKUINT(key,MAXTYPE),&func}
00044 
00045 
00046 /**
00047  * This is a base class for ojects which can send messages to the application
00048  */
00049 class FXAPI FXBaseObject : public FXObject {
00050   FXDECLARE (FXBaseObject)
00051     
00052   protected:
00053     /// flags defined are the same as those defined in FXWindow, etc.
00054     enum {
00055       FLAG_ENABLED  = 0x00000002,   // enabled
00056       FLAG_UPDATE   = 0x00000004,   // needs update
00057       FLAG_FOCUSED  = 0x00000010,   // has focus
00058       FLAG_DIRTY    = 0x00000020,   // dirty
00059       FLAG_RECALC   = 0x00000040,   // needs recalculation
00060       FLAG_DEFAULT  = 0x00000200,   // set to default
00061       FLAG_INITIAL  = 0x00000400,   // set to initial value
00062       FLAG_ACTIVE   = 0x00001000,   // active
00063       FLAG_CHANGED  = 0x00010000,   // changed
00064       FLAG_READONLY = 0x10000000    // read only 
00065       };
00066 
00067   private:
00068     FXApp        *app;             // application pointer
00069 
00070   protected:
00071     FXObject     *target;          // application target
00072     FXSelector    message;         // application message
00073     void         *data;            // user data
00074     FXuint        datalen;         // length of user data
00075     FXuint        flags;           // state flags
00076     FXuint        options;         // option flags
00077 
00078   public:
00079     enum {
00080       ID_NONE=0,
00081       ID_DELETE=6,
00082       ID_DISABLE,
00083       ID_ENABLE,
00084       ID_SETVALUE=17,
00085       ID_SETINTVALUE,
00086       ID_SETREALVALUE,
00087       ID_SETSTRINGVALUE,
00088       ID_SETINTRANGE,
00089       ID_SETREALRANGE,
00090       ID_GETINTVALUE,
00091       ID_GETREALVALUE,
00092       ID_GETSTRINGVALUE,
00093       ID_XML,
00094       ID_META,
00095       ID_COMMENT,
00096       ID_DOCUMENT,
00097       ID_TAG,
00098       ID_CONTENT,
00099       ID_LAST,
00100       };
00101 
00102   public:
00103     long onCmdEnable(FXObject*,FXSelector,void*);
00104     long onCmdDisable(FXObject*,FXSelector,void*);
00105     long onUpdate(FXObject*,FXSelector,void*);
00106 
00107   public:
00108     /// Just supply the target and selector (de-serialisation too)
00109     FXBaseObject(FXObject *tgt=NULL,FXSelector sel=0);
00110 
00111     /// Alternnatively, supply the app object as well
00112     FXBaseObject(FXApp *a,FXObject *tgt=NULL,FXSelector sel=0);
00113 
00114     /// application pointer
00115     FXApp* getApp();
00116 
00117     /// get the target
00118     FXObject* getTarget() { return target; }
00119 
00120     /// set the target
00121     void setTarget(FXObject* tgt) { target=tgt; }
00122 
00123     /// get the message
00124     FXSelector getSelector() { return message; }
00125 
00126     /// set the selector
00127     void setSelector(FXSelector sel) { message=sel; }
00128 
00129     /// get user data
00130     void* getUserData() { return data; }
00131 
00132     /// set user data
00133     void setUserData(void *d) { data=d; }
00134 
00135     /// get user daat length
00136     FXuint getUserDataLen() { return datalen; }
00137 
00138     /// set the user data length
00139     void setUserDataLen(FXuint len) { datalen=len; }
00140 
00141     /// are we enabled?
00142     FXbool isEnabled() { return (flags&FLAG_ENABLED)!=0; }
00143 
00144     /// enable us
00145     virtual void enable() { flags|=FLAG_ENABLED; }
00146 
00147     /// disable us
00148     virtual void disable() { flags&=~FLAG_ENABLED; }
00149 
00150     /// are we modifiable
00151     virtual FXbool isReadonly() { return (flags&FLAG_READONLY)!=0; }
00152 
00153     /// set modifiable mode
00154     virtual void setReadonly(FXbool mode=TRUE);
00155 
00156     /// create resource
00157     virtual void create(){}
00158 
00159     /// detach resource
00160     virtual void detach(){}
00161 
00162     /// destroy resource
00163     virtual void destroy(){}
00164 
00165     /// save object to stream
00166     virtual void save(FXStream& store) const;
00167 
00168     /// load object from stream
00169     virtual void load(FXStream& store);
00170 
00171     /// dtor
00172     virtual ~FXBaseObject();
00173   };
00174 
00175 } // namespace FXEX
00176 #endif // FXBASEOBJECT_H
00177