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
00026
00027
00028 #ifndef _CEGUIWidgetModule_h_
00029 #define _CEGUIWidgetModule_h_
00030
00031 #include "CEGUIExceptions.h"
00032 #include "CEGUIWindowFactoryManager.h"
00033
00034 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
00035 # ifdef CEGUIWIDGETMODULE_EXPORTS
00036 # define CEGUIWIDGETMODULE_API __declspec(dllexport)
00037 # else
00038 # define CEGUIWIDGETMODULE_API __declspec(dllimport)
00039 # endif
00040 #else
00041 # define CEGUIWIDGETMODULE_API
00042 #endif
00043
00044 #define CEGUI_DECLARE_WIDGET_MODULE( moduleName )\
00045 \
00046 class CEGUI::WindowFactory;\
00047 \
00048 extern "C" CEGUIWIDGETMODULE_API void registerFactory(const CEGUI::String& type_name);\
00049 extern "C" CEGUIWIDGETMODULE_API CEGUI::uint registerAllFactories(void);\
00050 void doSafeFactoryRegistration(CEGUI::WindowFactory* factory);
00051
00052
00053 #define CEGUI_DEFINE_FACTORY( className )\
00054 namespace CEGUI {\
00055 class className ## Factory : public WindowFactory\
00056 {\
00057 public:\
00058 className ## Factory(void) : WindowFactory(className::WidgetTypeName) { }\
00059 Window* createWindow(const String& name)\
00060 { return new className(d_type, name); }\
00061 void destroyWindow(Window* window)\
00062 { delete window; }\
00063 };\
00064 }\
00065 static CEGUI::className ## Factory s_ ## className ## Factory;
00066
00067 #define CEGUI_START_FACTORY_MAP( module )\
00068 struct module ## MapEntry\
00069 {\
00070 const CEGUI::utf8* d_name;\
00071 CEGUI::WindowFactory* d_factory;\
00072 };\
00073 \
00074 module ## MapEntry module ## FactoriesMap[] =\
00075 {\
00076
00077 #define CEGUI_END_FACTORY_MAP {0,0}};
00078
00079 #define CEGUI_FACTORY_MAP_ENTRY( class )\
00080 {CEGUI::class::WidgetTypeName, &s_ ## class ## Factory},
00081
00082 #define CEGUI_DEFINE_WIDGET_MODULE( module )\
00083 extern "C" void registerFactory(const CEGUI::String& type_name)\
00084 {\
00085 module ## MapEntry* entry = module ## FactoriesMap;\
00086 while (entry->d_name)\
00087 {\
00088 if (entry->d_name == type_name)\
00089 {\
00090 doSafeFactoryRegistration(entry->d_factory);\
00091 return;\
00092 }\
00093 ++entry;\
00094 }\
00095 \
00096 throw CEGUI::UnknownObjectException("::registerFactory - The window factory for type '" + type_name + "' is not known in this module.");\
00097 }\
00098 \
00099 extern "C" CEGUI::uint registerAllFactories(void)\
00100 {\
00101 CEGUI::uint count = 0;\
00102 module ## MapEntry* entry = module ## FactoriesMap;\
00103 while (entry->d_name)\
00104 {\
00105 doSafeFactoryRegistration(entry->d_factory);\
00106 ++entry;\
00107 ++count;\
00108 }\
00109 return count;\
00110 }\
00111 \
00112 void doSafeFactoryRegistration(CEGUI::WindowFactory* factory)\
00113 {\
00114 assert(factory != 0);\
00115 \
00116 CEGUI::WindowFactoryManager& wfm = CEGUI::WindowFactoryManager::getSingleton();\
00117 if (wfm.isFactoryPresent(factory->getTypeName()))\
00118 {\
00119 CEGUI::Logger::getSingleton().logEvent(\
00120 "Widget factory '" + factory->getTypeName() + "' appears to be already registered, skipping.",\
00121 CEGUI::Informative);\
00122 }\
00123 else\
00124 {\
00125 wfm.addFactory(factory);\
00126 }\
00127 }
00128
00129 #endif // end of guard _CEGUIWidgetModule_h_