MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_WidgetManager.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_WidgetManager.h"
24 #include "MyGUI_Gui.h"
25 #include "MyGUI_Widget.h"
26 #include "MyGUI_FactoryManager.h"
27
28 #include "MyGUI_Button.h"
29 #include "MyGUI_Canvas.h"
30 #include "MyGUI_ComboBox.h"
31 #include "MyGUI_DDContainer.h"
32 #include "MyGUI_EditBox.h"
33 #include "MyGUI_ItemBox.h"
34 #include "MyGUI_ListBox.h"
35 #include "MyGUI_MenuBar.h"
36 #include "MyGUI_MenuControl.h"
37 #include "MyGUI_MenuItem.h"
38 #include "MyGUI_MultiListBox.h"
39 #include "MyGUI_MultiListItem.h"
40 #include "MyGUI_PopupMenu.h"
41 #include "MyGUI_ProgressBar.h"
42 #include "MyGUI_ScrollBar.h"
43 #include "MyGUI_ScrollView.h"
44 #include "MyGUI_ImageBox.h"
45 #include "MyGUI_TextBox.h"
46 #include "MyGUI_TabControl.h"
47 #include "MyGUI_TabItem.h"
48 #include "MyGUI_Widget.h"
49 #include "MyGUI_Window.h"
50
51 #include "MyGUI_BackwardCompatibility.h"
52
53 namespace MyGUI
54 {
55
56 template <> WidgetManager* Singleton<WidgetManager>::msInstance = nullptr;
57 template <> const char* Singleton<WidgetManager>::mClassTypeName("WidgetManager");
58
59 WidgetManager::WidgetManager() :
60 mIsInitialise(false)
61 {
62 }
63
64 void WidgetManager::initialise()
65 {
66 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
67 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
68
69 FactoryManager& factory = FactoryManager::getInstance();
70
71 factory.registerFactory<Button>("Widget");
72 factory.registerFactory<Canvas>("Widget");
73 factory.registerFactory<ComboBox>("Widget");
74 factory.registerFactory<DDContainer>("Widget");
75 factory.registerFactory<EditBox>("Widget");
76 factory.registerFactory<ItemBox>("Widget");
77 factory.registerFactory<ListBox>("Widget");
78 factory.registerFactory<MenuBar>("Widget");
79 factory.registerFactory<MenuControl>("Widget");
80 factory.registerFactory<MenuItem>("Widget");
81 factory.registerFactory<MultiListBox>("Widget");
82 factory.registerFactory<MultiListItem>("Widget");
83 factory.registerFactory<PopupMenu>("Widget");
84 factory.registerFactory<ProgressBar>("Widget");
85 factory.registerFactory<ScrollBar>("Widget");
86 factory.registerFactory<ScrollView>("Widget");
87 factory.registerFactory<ImageBox>("Widget");
88 factory.registerFactory<TextBox>("Widget");
89 factory.registerFactory<TabControl>("Widget");
90 factory.registerFactory<TabItem>("Widget");
91 factory.registerFactory<Widget>("Widget");
92 factory.registerFactory<Window>("Widget");
93
94 BackwardCompatibility::registerWidgetTypes();
95
96 Gui::getInstance().eventFrameStart += newDelegate(this, &WidgetManager::notifyEventFrameStart);
97
98 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
99 mIsInitialise = true;
100 }
101
102 void WidgetManager::shutdown()
103 {
104 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
105 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
106
107 Gui::getInstance().eventFrameStart -= newDelegate(this, &WidgetManager::notifyEventFrameStart);
108 _deleteDelayWidgets();
109
110 mVectorIUnlinkWidget.clear();
111
112 FactoryManager::getInstance().unregisterFactory("Widget");
113
114 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
115 mIsInitialise = false;
116 }
117
118 Widget* WidgetManager::createWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Widget* _parent, ICroppedRectangle* _cropeedParent, const std::string& _name)
119 {
120 IObject* object = FactoryManager::getInstance().createObject("Widget", _type);
121 if (object != nullptr)
122 {
123 Widget* widget = object->castType<Widget>();
124 widget->_initialise(_style, _coord, _skin, _parent, _cropeedParent, _name);
125
126 return widget;
127 }
128
129 MYGUI_EXCEPT("factory '" << _type << "' not found");
130 }
131
132 void WidgetManager::destroyWidget(Widget* _widget)
133 {
134 Gui::getInstance().destroyWidget(_widget);
135 }
136
137 void WidgetManager::destroyWidgets(const VectorWidgetPtr& _widgets)
138 {
139 Gui::getInstance().destroyWidgets(_widgets);
140 }
141
142 void WidgetManager::destroyWidgets(EnumeratorWidgetPtr _widgets)
143 {
144 Gui::getInstance().destroyWidgets(_widgets);
145 }
146
147 void WidgetManager::registerUnlinker(IUnlinkWidget* _unlink)
148 {
149 unregisterUnlinker(_unlink);
150 mVectorIUnlinkWidget.push_back(_unlink);
151 }
152
153 void WidgetManager::unregisterUnlinker(IUnlinkWidget* _unlink)
154 {
155 VectorIUnlinkWidget::iterator iter = std::remove(mVectorIUnlinkWidget.begin(), mVectorIUnlinkWidget.end(), _unlink);
156 if (iter != mVectorIUnlinkWidget.end())
157 mVectorIUnlinkWidget.erase(iter);
158 }
159
160 void WidgetManager::unlinkFromUnlinkers(Widget* _widget)
161 {
162 for (VectorIUnlinkWidget::iterator iter = mVectorIUnlinkWidget.begin(); iter != mVectorIUnlinkWidget.end(); ++iter)
163 {
164 (*iter)->_unlinkWidget(_widget);
165 }
166 }
167
168 bool WidgetManager::isFactoryExist(const std::string& _type)
169 {
170 if (FactoryManager::getInstance().isFactoryExist("Widget", _type))
171 {
172 return true;
173 }
174
175 return false;
176 }
177
178 void WidgetManager::notifyEventFrameStart(float _time)
179 {
180 _deleteDelayWidgets();
181 }
182
183 void WidgetManager::_deleteWidget(Widget* _widget)
184 {
185 _widget->_shutdown();
186
187 for (VectorWidgetPtr::iterator entry = mDestroyWidgets.begin(); entry != mDestroyWidgets.end(); ++entry)
188 {
189 /*if ((*entry) == _widget)
190 return;*/
191 MYGUI_ASSERT((*entry) != _widget, "double delete widget");
192 }
193
194 mDestroyWidgets.push_back(_widget);
195 }
196
197 void WidgetManager::_deleteDelayWidgets()
198 {
199 if (!mDestroyWidgets.empty())
200 {
201 for (VectorWidgetPtr::iterator entry = mDestroyWidgets.begin(); entry != mDestroyWidgets.end(); ++entry)
202 delete (*entry);
203 mDestroyWidgets.clear();
204 }
205 }
206
207 } // namespace MyGUI
MyGUI::types::TCoord< int >
MyGUI::Widget
Definition: MyGUI_Widget.h:41
MyGUI::ComboBox
Definition: MyGUI_ComboBox.h:40
MyGUI::Gui::destroyWidget
void destroyWidget(Widget *_widget)
Definition: MyGUI_Gui.cpp:261
MyGUI_FactoryManager.h
MyGUI::TabItem
Definition: MyGUI_TabItem.h:32
MyGUI_Canvas.h
MyGUI::ImageBox
Definition: MyGUI_ImageBox.h:33
MyGUI_ItemBox.h
MyGUI::Gui::eventFrameStart
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:166
MyGUI::WidgetManager::_deleteDelayWidgets
void _deleteDelayWidgets()
Definition: MyGUI_WidgetManager.cpp:197
MyGUI_TabControl.h
MyGUI_Precompiled.h
MyGUI::WidgetManager::isFactoryExist
bool isFactoryExist(const std::string &_type)
Definition: MyGUI_WidgetManager.cpp:168
MyGUI::ItemBox
Definition: MyGUI_ItemBox.h:41
MyGUI::newDelegate
delegates::IDelegate0 * newDelegate(void(*_func)())
Definition: MyGUI_Delegate.h:150
MyGUI::Singleton< FactoryManager >::getInstance
static FactoryManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI_WidgetManager.h
MyGUI::WidgetManager::shutdown
void shutdown()
Definition: MyGUI_WidgetManager.cpp:102
MyGUI::WidgetManager::destroyWidget
void destroyWidget(Widget *_widget)
Definition: MyGUI_WidgetManager.cpp:132
MyGUI_ListBox.h
MyGUI::Singleton< WidgetManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:64
MyGUI::ListBox
Definition: MyGUI_ListBox.h:37
MyGUI_Button.h
MyGUI::WidgetManager::unlinkFromUnlinkers
void unlinkFromUnlinkers(Widget *_widget)
Definition: MyGUI_WidgetManager.cpp:160
MyGUI::WidgetManager::destroyWidgets
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition: MyGUI_WidgetManager.cpp:137
MyGUI_DDContainer.h
MyGUI::MultiListItem
Definition: MyGUI_MultiListItem.h:33
MyGUI_MultiListBox.h
MyGUI_ProgressBar.h
MyGUI::Button
Definition: MyGUI_Button.h:31
MyGUI::FactoryManager
Definition: MyGUI_FactoryManager.h:33
MyGUI::Enumerator
Definition: MyGUI_Enumerator.h:63
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:38
MyGUI::Widget::_shutdown
void _shutdown()
Definition: MyGUI_Widget.cpp:141
MyGUI::EditBox
Definition: MyGUI_EditBox.h:37
MyGUI_MultiListItem.h
MyGUI::IUnlinkWidget
Definition: MyGUI_IUnlinkWidget.h:31
MYGUI_EXCEPT
#define MYGUI_EXCEPT(dest)
Definition: MyGUI_Diagnostic.h:49
MyGUI::Gui::destroyWidgets
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition: MyGUI_Gui.cpp:270
MyGUI::ProgressBar
Definition: MyGUI_ProgressBar.h:33
MyGUI_ScrollBar.h
MyGUI::ScrollView
Definition: MyGUI_ScrollView.h:32
MyGUI::VectorWidgetPtr
std::vector< Widget * > VectorWidgetPtr
Definition: MyGUI_WidgetDefines.h:33
MyGUI_ScrollView.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI_BackwardCompatibility.h
MyGUI::WidgetManager::_deleteWidget
void _deleteWidget(Widget *_widget)
Definition: MyGUI_WidgetManager.cpp:183
MyGUI::DDContainer
Definition: MyGUI_DDContainer.h:39
MyGUI::IObject::castType
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:33
MyGUI::WidgetManager::registerUnlinker
void registerUnlinker(IUnlinkWidget *_unlink)
Definition: MyGUI_WidgetManager.cpp:147
MyGUI::FactoryManager::unregisterFactory
void unregisterFactory(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:61
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:118
MyGUI_ComboBox.h
MyGUI::IObject
Definition: MyGUI_IObject.h:31
MyGUI::FactoryManager::registerFactory
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
Definition: MyGUI_FactoryManager.cpp:55
MyGUI::WidgetStyle
Definition: MyGUI_WidgetStyle.h:31
MyGUI_TabItem.h
MyGUI::ICroppedRectangle
Definition: MyGUI_ICroppedRectangle.h:31
MyGUI_Widget.h
MyGUI::BackwardCompatibility::registerWidgetTypes
static void registerWidgetTypes()
Definition: MyGUI_BackwardCompatibility.cpp:1139
MyGUI_ImageBox.h
MyGUI::MultiListBox
Definition: MyGUI_MultiListBox.h:44
MyGUI::TextBox
Definition: MyGUI_TextBox.h:31
MyGUI::Canvas
Definition: MyGUI_Canvas.h:36
MyGUI_Gui.h
MyGUI::Window
Definition: MyGUI_Window.h:39
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:66
MyGUI_Window.h
MyGUI::Singleton::mClassTypeName
static const char * mClassTypeName
Definition: MyGUI_Singleton.h:73
MyGUI_EditBox.h
MyGUI::TabControl
Definition: MyGUI_TabControl.h:38
MyGUI::ScrollBar
Definition: MyGUI_ScrollBar.h:33
MyGUI::FactoryManager::createObject
IObject * createObject(const std::string &_category, const std::string &_type)
Definition: MyGUI_FactoryManager.cpp:87
MyGUI::WidgetManager::initialise
void initialise()
Definition: MyGUI_WidgetManager.cpp:64
MyGUI::WidgetManager::WidgetManager
WidgetManager()
Definition: MyGUI_WidgetManager.cpp:59
MyGUI::WidgetManager::unregisterUnlinker
void unregisterUnlinker(IUnlinkWidget *_unlink)
Definition: MyGUI_WidgetManager.cpp:153
MyGUI_TextBox.h