Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __MYGUI_I_WIDGET_FACTORY_H__
00024 #define __MYGUI_I_WIDGET_FACTORY_H__
00025
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Align.h"
00028 #include "MyGUI_WidgetStyle.h"
00029 #include "MyGUI_WidgetDefines.h"
00030 #include "MyGUI_ICroppedRectangle.h"
00031
00032 #include "MyGUI_WidgetManager.h"
00033 #include "MyGUI_SkinManager.h"
00034
00035 namespace MyGUI
00036 {
00037
00038
00039 class MYGUI_EXPORT IWidgetFactory
00040 {
00041 public:
00042 virtual ~IWidgetFactory() { }
00043
00044 virtual const std::string& getTypeName() = 0;
00045 virtual WidgetPtr createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, WidgetPtr _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name) = 0;
00046 };
00047
00048 namespace factory
00049 {
00050
00051
00052 template <typename T>
00053 class MYGUI_EXPORT BaseWidgetFactory : public IWidgetFactory
00054 {
00055 public:
00056 BaseWidgetFactory()
00057 {
00058
00059 MyGUI::WidgetManager& manager = MyGUI::WidgetManager::getInstance();
00060 manager.registerFactory(this);
00061 }
00062
00063 ~BaseWidgetFactory()
00064 {
00065
00066 MyGUI::WidgetManager& manager = MyGUI::WidgetManager::getInstance();
00067 manager.unregisterFactory(this);
00068 }
00069
00070 const std::string& getTypeName()
00071 {
00072 return T::getClassTypeName();
00073 }
00074
00075 WidgetPtr createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, WidgetPtr _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name)
00076 {
00077 T* instance = new T(_style, _coord, _align, SkinManager::getInstance().getByName(_skin), _parent, _croppedParent, _creator, _name);
00078 return instance;
00079 }
00080
00081 bool isFalseType(WidgetPtr _ptr, const std::string &_key)
00082 {
00083 if (!_ptr->isType<T>())
00084 {
00085 MYGUI_LOG(Error, "Property '" << _key << "' is not supported by '" << _ptr->getTypeName() << "' widget");
00086 return true;
00087 }
00088 return false;
00089 }
00090 };
00091
00092 }
00093 }
00094
00095 #endif // __MYGUI_I_WIDGET_FACTORY_H__