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

FXObjectLoader.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *               Dynamically linked FXObject derived loader                      *
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 FXOBJECTLOADER_H
00023 #define FXOBJECTLOADER_H
00024 
00025 #ifndef FXBASEOBJECT_H
00026 #include "FXBaseObject.h"
00027 #endif
00028 namespace FXEX {
00029 
00030 /**
00031  * Call the appropriate macro, in the interface file of your dynamic class
00032  * (ie in classname.h).   Note that your class must use default values for its
00033  * constructor parameters.  In all cases the dynamically loaded classes can handle
00034  * generic FOX event processing...
00035  */
00036 
00037 /// load an FXWindow derived class - takes an FXComposite (parent widget) as an argument
00038 #define FXDLL_FXWINDOW(classname) \
00039   extern "C" classname* open(FXComposite *p) { return new classname(p); }
00040 
00041 /// load a FXBaseObject derived class - takes an FXApp (application pointer) as an argument
00042 #define FXDLL_FXBASEOBJECT(classname) \
00043   extern "C" classname* open(FXApp *a) { return new classname(a); }
00044 
00045 /// load an FXObject derived class - this is the fallback case... 
00046 #define FXDLL_FXOBJECT(classname) \
00047   extern "C" classname* open() { return new classname(); }
00048 
00049 
00050 /**
00051  * Dynamically load an FXObject based object.
00052  * Dont forget to call create() on the returned object...
00053  *
00054  * You may be wondering why there are three functions to choose from..??
00055  * Well, its because FXWindow derived widget can be automatically attached to a parent widget.
00056  * FXBaseObject's can also be create()d into a working object...
00057  * FXObject is the fallback case...
00058  * 
00059  * To derive from this class, just define your 'get object' method, which simply casts
00060  * the return result from one of these functions. eg:
00061  *
00062  * class MyWidgetLoader : public FXObjectLoader {
00063  *   FXDECLARE(MyWidgetLoader)
00064  *   public:
00065  *     MyWidetLoader(const FXString& filename) : FXObjectLoader(filename) { open(); }
00066  *     MyWidget* getMyWidget(FXComposite *p) { return (MyWidget*) getFXWindow("MyWidget");
00067  *   };
00068  */
00069 class FXAPI FXObjectLoader : public FXBaseObject {
00070   FXDECLARE(FXObjectLoader)
00071 
00072 private:
00073   FXDLL *dll;  // handle to library
00074 
00075 protected:
00076   FXObjectLoader();
00077 
00078 public:
00079 
00080   /// load from library
00081   FXObjectLoader(FXApp *a,const FXString& filename="");
00082 
00083   /// alternate method of loading (this object becomes owner of dll pointer)
00084   FXObjectLoader(FXApp *a,FXDLL *d);
00085 
00086   /// create resources
00087   virtual void create();
00088 
00089   /// returns an FXWindow derived object, takes parent window as argument
00090   FXWindow* getFXWindow(FXComposite *p);
00091 
00092   /// returns an FXBaseObject derived object, takes an application pointer as argument
00093   FXBaseObject* getFXBaseObject();
00094 
00095   /// returns an FXObject derived object
00096   FXObject* getFXObject();
00097 
00098   /// save resources
00099   virtual void save(FXStream& store) const;
00100 
00101   /// load resources
00102   virtual void load(FXStream& load);
00103 
00104   /// dtor
00105   virtual ~FXObjectLoader();
00106   };
00107 
00108 } // namespace FXEX
00109 #endif // FXOBJECTLOADER_H