MyGUI 3.2.2

MyGUI_WidgetManager.cpp
Go to the documentation of this file.
1 /*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7 #include "MyGUI_Precompiled.h"
8 #include "MyGUI_WidgetManager.h"
9 #include "MyGUI_Gui.h"
10 #include "MyGUI_Widget.h"
11 #include "MyGUI_FactoryManager.h"
12
13 #include "MyGUI_Button.h"
14 #include "MyGUI_Canvas.h"
15 #include "MyGUI_ComboBox.h"
16 #include "MyGUI_DDContainer.h"
17 #include "MyGUI_EditBox.h"
18 #include "MyGUI_ItemBox.h"
19 #include "MyGUI_ListBox.h"
20 #include "MyGUI_MenuBar.h"
21 #include "MyGUI_MenuControl.h"
22 #include "MyGUI_MenuItem.h"
23 #include "MyGUI_MultiListBox.h"
24 #include "MyGUI_MultiListItem.h"
25 #include "MyGUI_PopupMenu.h"
26 #include "MyGUI_ProgressBar.h"
27 #include "MyGUI_ScrollBar.h"
28 #include "MyGUI_ScrollView.h"
29 #include "MyGUI_ImageBox.h"
30 #include "MyGUI_TextBox.h"
31 #include "MyGUI_TabControl.h"
32 #include "MyGUI_TabItem.h"
33 #include "MyGUI_Widget.h"
34 #include "MyGUI_Window.h"
35
36 #include "MyGUI_BackwardCompatibility.h"
37
38 namespace MyGUI
39 {
40
41 template <> WidgetManager* Singleton<WidgetManager>::msInstance = nullptr;
42 template <> const char* Singleton<WidgetManager>::mClassTypeName = "WidgetManager";
43
44 WidgetManager::WidgetManager() :
45 mIsInitialise(false),
46 mCategoryName("Widget")
47 {
48 }
49
50 void WidgetManager::initialise()
51 {
52 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
53 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
54
55 FactoryManager& factory = FactoryManager::getInstance();
56
57 factory.registerFactory<Button>(mCategoryName);
58 factory.registerFactory<Canvas>(mCategoryName);
59 factory.registerFactory<ComboBox>(mCategoryName);
60 factory.registerFactory<DDContainer>(mCategoryName);
61 factory.registerFactory<EditBox>(mCategoryName);
62 factory.registerFactory<ItemBox>(mCategoryName);
63 factory.registerFactory<ListBox>(mCategoryName);
64 factory.registerFactory<MenuBar>(mCategoryName);
65 factory.registerFactory<MenuControl>(mCategoryName);
66 factory.registerFactory<MenuItem>(mCategoryName);
67 factory.registerFactory<MultiListBox>(mCategoryName);
68 factory.registerFactory<MultiListItem>(mCategoryName);
69 factory.registerFactory<PopupMenu>(mCategoryName);
70 factory.registerFactory<ProgressBar>(mCategoryName);
71 factory.registerFactory<ScrollBar>(mCategoryName);
72 factory.registerFactory<ScrollView>(mCategoryName);
73 factory.registerFactory<ImageBox>(mCategoryName);
74 factory.registerFactory<TextBox>(mCategoryName);
75 factory.registerFactory<TabControl>(mCategoryName);
76 factory.registerFactory<TabItem>(mCategoryName);
77 factory.registerFactory<Widget>(mCategoryName);
78 factory.registerFactory<Window>(mCategoryName);
79
80 BackwardCompatibility::registerWidgetTypes();
81
82 Gui::getInstance().eventFrameStart += newDelegate(this, &WidgetManager::notifyEventFrameStart);
83
84 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
85 mIsInitialise = true;
86 }
87
88 void WidgetManager::shutdown()
89 {
90 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
91 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
92
93 Gui::getInstance().eventFrameStart -= newDelegate(this, &WidgetManager::notifyEventFrameStart);
94 _deleteDelayWidgets();
95
96 mVectorIUnlinkWidget.clear();
97
98 FactoryManager::getInstance().unregisterFactory(mCategoryName);
99
100 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
101 mIsInitialise = false;
102 }
103
104 Widget* WidgetManager::createWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Widget* _parent, ICroppedRectangle* _cropeedParent, const std::string& _name)
105 {
106 IObject* object = FactoryManager::getInstance().createObject(mCategoryName, _type);
107 if (object != nullptr)
108 {
109 Widget* widget = object->castType<Widget>();
110 widget->_initialise(_style, _coord, _skin, _parent, _cropeedParent, _name);
111
112 return widget;
113 }
114
115 MYGUI_EXCEPT("factory '" << _type << "' not found");
116 }
117
118 void WidgetManager::destroyWidget(Widget* _widget)
119 {
120 Gui::getInstance().destroyWidget(_widget);
121 }
122
123 void WidgetManager::destroyWidgets(const VectorWidgetPtr& _widgets)
124 {
125 Gui::getInstance().destroyWidgets(_widgets);
126 }
127
128 void WidgetManager::destroyWidgets(EnumeratorWidgetPtr _widgets)
129 {
130 Gui::getInstance().destroyWidgets(_widgets);
131 }
132
133 void WidgetManager::registerUnlinker(IUnlinkWidget* _unlink)
134 {
135 unregisterUnlinker(_unlink);
136 mVectorIUnlinkWidget.push_back(_unlink);
137 }
138
139 void WidgetManager::unregisterUnlinker(IUnlinkWidget* _unlink)
140 {
141 VectorIUnlinkWidget::iterator iter = std::remove(mVectorIUnlinkWidget.begin(), mVectorIUnlinkWidget.end(), _unlink);
142 if (iter != mVectorIUnlinkWidget.end())
143 mVectorIUnlinkWidget.erase(iter);
144 }
145
146 void WidgetManager::unlinkFromUnlinkers(Widget* _widget)
147 {
148 for (VectorIUnlinkWidget::iterator iter = mVectorIUnlinkWidget.begin(); iter != mVectorIUnlinkWidget.end(); ++iter)
149 {
150 (*iter)->_unlinkWidget(_widget);
151 }
152 }
153
154 bool WidgetManager::isFactoryExist(const std::string& _type)
155 {
156 if (FactoryManager::getInstance().isFactoryExist(mCategoryName, _type))
157 {
158 return true;
159 }
160
161 return false;
162 }
163
164 void WidgetManager::notifyEventFrameStart(float _time)
165 {
166 _deleteDelayWidgets();
167 }
168
169 void WidgetManager::_deleteWidget(Widget* _widget)
170 {
171 _widget->_shutdown();
172
173 for (VectorWidgetPtr::iterator entry = mDestroyWidgets.begin(); entry != mDestroyWidgets.end(); ++entry)
174 {
175 /*if ((*entry) == _widget)
176 return;*/
177 MYGUI_ASSERT((*entry) != _widget, "double delete widget");
178 }
179
180 mDestroyWidgets.push_back(_widget);
181 }
182
183 void WidgetManager::_deleteDelayWidgets()
184 {
185 if (!mDestroyWidgets.empty())
186 {
187 for (VectorWidgetPtr::iterator entry = mDestroyWidgets.begin(); entry != mDestroyWidgets.end(); ++entry)
188 delete (*entry);
189 mDestroyWidgets.clear();
190 }
191 }
192
193 const std::string& WidgetManager::getCategoryName() const
194 {
195 return mCategoryName;
196 }
197
198 } // namespace MyGUI
MyGUI::types::TCoord< int >
MyGUI::Widget
Widget properties. Widget_skin_childs Skin childs. Widget widget description should be here...
Definition: MyGUI_Widget.h:29
MyGUI::ComboBox
ComboBox properties. ComboBox_skin_childs Skin childs. ComboBox widget description should be here...
Definition: MyGUI_ComboBox.h:28
MyGUI::Gui::destroyWidget
void destroyWidget(Widget *_widget)
Definition: MyGUI_Gui.cpp:242
MyGUI_FactoryManager.h
MyGUI::TabItem
TabItem properties. TabItem_skin_childs Skin childs. TabItem widget description should be here...
Definition: MyGUI_TabItem.h:20
MyGUI_Canvas.h
MyGUI::ImageBox
ImageBox properties. ImageBox_skin_childs Skin childs. ImageBox widget description should be here...
Definition: MyGUI_ImageBox.h:21
MyGUI_ItemBox.h
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:150
MyGUI::WidgetManager::_deleteDelayWidgets
void _deleteDelayWidgets()
Definition: MyGUI_WidgetManager.cpp:183
MyGUI_TabControl.h
MyGUI_Precompiled.h
MyGUI::WidgetManager::isFactoryExist
bool isFactoryExist(const std::string &_type)
Definition: MyGUI_WidgetManager.cpp:154
MyGUI::ItemBox
ItemBox properties. ItemBox_skin_childs Skin childs. ItemBox widget description should be here...
Definition: MyGUI_ItemBox.h:29
MyGUI::newDelegate
delegates::IDelegate0 * newDelegate(void(*_func)())
Definition: MyGUI_Delegate.h:118
MyGUI::Singleton< FactoryManager >::getInstance
static FactoryManager & getInstance()
Definition: MyGUI_Singleton.h:38
MyGUI_WidgetManager.h
MyGUI::WidgetManager::shutdown
void shutdown()
Definition: MyGUI_WidgetManager.cpp:88
MyGUI::WidgetManager::destroyWidget
void destroyWidget(Widget *_widget)
Definition: MyGUI_WidgetManager.cpp:118
MyGUI_ListBox.h
MyGUI::Singleton< WidgetManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:49
MyGUI::ListBox
ListBox properties. ListBox_skin_childs Skin childs. ListBox widget description should be here...
Definition: MyGUI_ListBox.h:27
MyGUI_Button.h
MyGUI::WidgetManager::unlinkFromUnlinkers
void unlinkFromUnlinkers(Widget *_widget)
Definition: MyGUI_WidgetManager.cpp:146
MyGUI::WidgetManager::destroyWidgets
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition: MyGUI_WidgetManager.cpp:123
MyGUI_DDContainer.h
MyGUI::MultiListItem
MultiListItem properties. MultiListItem_skin_childs Skin childs. MultiListItem widget description sh...
Definition: MyGUI_MultiListItem.h:21
MyGUI_MultiListBox.h
MyGUI_ProgressBar.h
MyGUI::Button
Button properties. Button_skin_childs Skin childs. Button widget description should be here...
Definition: MyGUI_Button.h:19
MyGUI::FactoryManager
Definition: MyGUI_FactoryManager.h:18
MyGUI::Enumerator
Definition: MyGUI_Enumerator.h:48
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:22
MyGUI::Widget::_shutdown
void _shutdown()
Definition: MyGUI_Widget.cpp:127
MyGUI::EditBox
EditBox properties. EditBox_skin_childs Skin childs. EditBox widget description should be here...
Definition: MyGUI_EditBox.h:25
MyGUI_MultiListItem.h
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::IUnlinkWidget
Definition: MyGUI_IUnlinkWidget.h:16
MyGUI::WidgetManager::getCategoryName
const std::string & getCategoryName() const
Definition: MyGUI_WidgetManager.cpp:193
MYGUI_EXCEPT
#define MYGUI_EXCEPT(dest)
Definition: MyGUI_Diagnostic.h:33
MyGUI::Gui::destroyWidgets
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition: MyGUI_Gui.cpp:251
MyGUI::ProgressBar
ProgressBar properties. ProgressBar_skin_childs Skin childs. ProgressBar widget description should b...
Definition: MyGUI_ProgressBar.h:21
MyGUI_ScrollBar.h
MyGUI::ScrollView
ScrollView properties. ScrollView_skin_childs Skin childs. ScrollView widget description should be h...
Definition: MyGUI_ScrollView.h:20
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition: MyGUI_WidgetDefines.h:19
MyGUI_ScrollView.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:42
MyGUI_BackwardCompatibility.h
MyGUI::WidgetManager::_deleteWidget
void _deleteWidget(Widget *_widget)
Definition: MyGUI_WidgetManager.cpp:169
MyGUI::DDContainer
DDContainer properties. DDContainer_skin_childs Skin childs. DDContainer widget description should b...
Definition: MyGUI_DDContainer.h:27
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:18
MyGUI::WidgetManager::registerUnlinker
void registerUnlinker(IUnlinkWidget *_unlink)
Definition: MyGUI_WidgetManager.cpp:133
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:46
MyGUI::WidgetManager::createWidget
Widget * createWidget(WidgetStyle _style, const std::string &_type, const std::string &_skin, const IntCoord &_coord, Widget *_parent, ICroppedRectangle *_cropeedParent, const std::string &_name)
Definition: MyGUI_WidgetManager.cpp:104
MyGUI_ComboBox.h
MyGUI::IObject
Definition: MyGUI_IObject.h:16
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
Definition: MyGUI_FactoryManager.cpp:40
MyGUI::WidgetStyle
Definition: MyGUI_WidgetStyle.h:16
MyGUI_TabItem.h
MyGUI::ICroppedRectangle
Definition: MyGUI_ICroppedRectangle.h:16
MyGUI_Widget.h
MyGUI::BackwardCompatibility::registerWidgetTypes
static void registerWidgetTypes()
Definition: MyGUI_BackwardCompatibility.cpp:1358
MyGUI_ImageBox.h
MyGUI::MultiListBox
MultiListBox properties. MultiListBox_skin_childs Skin childs. MultiListBox widget description shoul...
Definition: MyGUI_MultiListBox.h:32
MyGUI::TextBox
TextBox properties. TextBox_skin_childs Skin childs. TextBox widget description should be here...
Definition: MyGUI_TextBox.h:19
MyGUI::Canvas
Canvas properties. Canvas_skin_childs Skin childs. Widget wrapper over Texture - shows the texture...
Definition: MyGUI_Canvas.h:21
MyGUI_Gui.h
MyGUI::Window
Window properties. Window_skin_childs Skin childs. Window widget description should be here...
Definition: MyGUI_Window.h:27
MyGUI::Widget::_initialise
void _initialise(WidgetStyle _style, const IntCoord &_coord, const std::string &_skinName, Widget *_parent, ICroppedRectangle *_croppedParent, const std::string &_name)
Definition: MyGUI_Widget.cpp:52
MyGUI_Window.h
MyGUI_EditBox.h
MyGUI::TabControl
TabControl properties. TabControl_skin_childs Skin childs. TabControl widget description should be h...
Definition: MyGUI_TabControl.h:26
MyGUI::ScrollBar
ScrollBar properties. ScrollBar_skin_childs Skin childs. ScrollBar widget description should be here...
Definition: MyGUI_ScrollBar.h:23
MyGUI::FactoryManager::createObject
IObject * createObject(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:72
MyGUI::WidgetManager::initialise
void initialise()
Definition: MyGUI_WidgetManager.cpp:50
MyGUI::WidgetManager::WidgetManager
WidgetManager()
Definition: MyGUI_WidgetManager.cpp:44
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition: MyGUI_WidgetManager.cpp:139
MyGUI_TextBox.h