MyGUI  3.0.1
MyGUI_WidgetManager.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_WIDGET_MANAGER_H__
00024 #define __MYGUI_WIDGET_MANAGER_H__
00025 
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Instance.h"
00028 #include "MyGUI_IWidgetCreator.h"
00029 #include "MyGUI_IUnlinkWidget.h"
00030 #include "MyGUI_ICroppedRectangle.h"
00031 #include "MyGUI_Widget.h"
00032 #include <set>
00033 
00034 namespace MyGUI
00035 {
00036 
00037     //OBSOLETE
00038     typedef delegates::CDelegate3<Widget*,  const std::string &, const std::string &> ParseDelegate;
00039 
00040     class MYGUI_EXPORT WidgetManager
00041     {
00042         MYGUI_INSTANCE_HEADER( WidgetManager )
00043 
00044     public:
00045         //OBSOLETE
00046         typedef std::map<std::string, ParseDelegate> MapDelegate;
00047         //OBSOLETE
00048         typedef std::set<IWidgetFactory*> SetWidgetFactory;
00049 
00050     public:
00051         void initialise();
00052         void shutdown();
00053 
00054         Widget* createWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Align _align, Widget* _parent, ICroppedRectangle * _cropeedParent, IWidgetCreator * _creator, const std::string& _name);
00055 
00057         void destroyWidget(Widget* _widget);
00059         void destroyWidgets(const VectorWidgetPtr &_widgets);
00061         void destroyWidgets(EnumeratorWidgetPtr _widgets);
00062 
00064         void registerUnlinker(IUnlinkWidget * _unlink);
00066         void unregisterUnlinker(IUnlinkWidget * _unlink);
00068         void unlinkFromUnlinkers(Widget* _widget);
00069 
00070         // добавляет виджет в список для анлинка
00071         void addWidgetToUnlink(Widget* _widget);
00072 
00073         // проверяет, и если надо обнуляет виджет из списка анликнутых
00074         void removeWidgetFromUnlink(Widget*& _widget);
00075 
00076         bool isFactoryExist(const std::string& _type);
00077 
00078     /*obsolete:*/
00079 #ifndef MYGUI_DONT_USE_OBSOLETE
00080 
00081         MYGUI_OBSOLETE("use : void WidgetManager::destroyWidgets(VectorWidgetPtr &_widgets)")
00082         void destroyWidgetsVector(VectorWidgetPtr &_widgets) { destroyWidgets(_widgets); }
00083         MYGUI_OBSOLETE("")
00084         Widget* findWidgetT(const std::string& _name, bool _throw = true);
00085         MYGUI_OBSOLETE("")
00086         Widget* findWidgetT(const std::string& _name, const std::string& _prefix, bool _throw = true);
00087         MYGUI_OBSOLETE("")
00088         void registerFactory(IWidgetFactory * _factory);
00089         MYGUI_OBSOLETE("")
00090         void unregisterFactory(IWidgetFactory * _factory);
00091         MYGUI_OBSOLETE("use : void Widget::setProperty(const std::string &_key, const std::string &_value)")
00092         void parse(Widget* _widget, const std::string &_key, const std::string &_value);
00093         MYGUI_OBSOLETE("")
00094         ParseDelegate& registerDelegate(const std::string& _key);
00095         MYGUI_OBSOLETE("")
00096         void unregisterDelegate(const std::string& _key);
00097 
00098         template <typename T>
00099         MYGUI_OBSOLETE("")
00100         T* findWidget(const std::string& _name, bool _throw = true)
00101         {
00102             Widget* widget = findWidgetT(_name, _throw);
00103             if (nullptr == widget) return nullptr;
00104             return widget->castType<T>(_throw);
00105         }
00106 
00107         template <typename T>
00108         MYGUI_OBSOLETE("")
00109         T* findWidget(const std::string& _name, const std::string& _prefix, bool _throw = true)
00110         {
00111             return findWidget<T>(_prefix + _name, _throw);
00112         }
00113 
00114 #endif // MYGUI_DONT_USE_OBSOLETE
00115 
00116     protected:
00117         SetWidgetFactory mFactoryList;
00118         //MapWidgetPtr mWidgets;
00119         MapDelegate mDelegates;
00120 
00121         // список менеджеров для отписки при удалении
00122         VectorIUnlinkWidget mVectorIUnlinkWidget;
00123 
00124         // список виджетов для отписки
00125         VectorWidgetPtr mUnlinkWidgets;
00126     };
00127 
00128 } // namespace MyGUI
00129 
00130 #endif // __MYGUI_WIDGET_MANAGER_H__