Crazy Eddies GUI System 0.7.5
CEGUIWidgetModule.h
00001 /***********************************************************************
00002     filename:   CEGUIWidgetModule.h
00003     created:    Sun Sep 25 2005
00004     author:     Paul D Turner <paul@cegui.org.uk>
00005 *************************************************************************/
00006 /***************************************************************************
00007  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00008  *
00009  *   Permission is hereby granted, free of charge, to any person obtaining
00010  *   a copy of this software and associated documentation files (the
00011  *   "Software"), to deal in the Software without restriction, including
00012  *   without limitation the rights to use, copy, modify, merge, publish,
00013  *   distribute, sublicense, and/or sell copies of the Software, and to
00014  *   permit persons to whom the Software is furnished to do so, subject to
00015  *   the following conditions:
00016  *
00017  *   The above copyright notice and this permission notice shall be
00018  *   included in all copies or substantial portions of the Software.
00019  *
00020  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00021  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00022  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00023  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00024  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00025  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00026  *   OTHER DEALINGS IN THE SOFTWARE.
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     CEGUI_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_