MyGUI  3.0.3
MyGUI_IWidgetFactory.h
Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009 
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #ifndef __MYGUI_I_WIDGET_FACTORY_H__
00024 #define __MYGUI_I_WIDGET_FACTORY_H__
00025 
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Types.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     //OBSOLETE
00039     class MYGUI_EXPORT IWidgetFactory
00040     {
00041     public:
00042         virtual ~IWidgetFactory() { }
00043 
00044         virtual const std::string& getTypeName() = 0;
00045         virtual Widget* createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name) = 0;
00046     };
00047 
00048     namespace factory
00049     {
00050 
00051         //OBSOLETE
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             Widget* createWidget(WidgetStyle _style, const std::string& _skin, const IntCoord& _coord, Align _align, Widget* _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(Widget* _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     } // namespace factory
00093 } // namespace MyGUI
00094 
00095 #endif // __MYGUI_I_WIDGET_FACTORY_H__