MyGUI  3.2.0
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 
52 
53 namespace MyGUI
54 {
55 
56  template <> WidgetManager* Singleton<WidgetManager>::msInstance = nullptr;
57  template <> const char* Singleton<WidgetManager>::mClassTypeName("WidgetManager");
58 
60  mIsInitialise(false)
61  {
62  }
63 
65  {
66  MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
67  MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
68 
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 
95 
96  Gui::getInstance().eventFrameStart += newDelegate(this, &WidgetManager::notifyEventFrameStart);
97 
98  MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
99  mIsInitialise = true;
100  }
101 
103  {
104  MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
105  MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
106 
107  Gui::getInstance().eventFrameStart -= newDelegate(this, &WidgetManager::notifyEventFrameStart);
109 
110  mVectorIUnlinkWidget.clear();
111 
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 
133  {
134  Gui::getInstance().destroyWidget(_widget);
135  }
136 
138  {
139  Gui::getInstance().destroyWidgets(_widgets);
140  }
141 
143  {
144  Gui::getInstance().destroyWidgets(_widgets);
145  }
146 
148  {
149  unregisterUnlinker(_unlink);
150  mVectorIUnlinkWidget.push_back(_unlink);
151  }
152 
154  {
155  VectorIUnlinkWidget::iterator iter = std::remove(mVectorIUnlinkWidget.begin(), mVectorIUnlinkWidget.end(), _unlink);
156  if (iter != mVectorIUnlinkWidget.end())
157  mVectorIUnlinkWidget.erase(iter);
158  }
159 
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  {
181  }
182 
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 
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
void destroyWidget(Widget *_widget)
Definition: MyGUI_Gui.cpp:261
EventHandle_FrameEventDelegate eventFrameStart
Definition: MyGUI_Gui.h:166
bool isFactoryExist(const std::string &_type)
delegates::IDelegate0 * newDelegate(void(*_func)())
static FactoryManager & getInstance()
void destroyWidget(Widget *_widget)
static const char * getClassTypeName()
void unlinkFromUnlinkers(Widget *_widget)
void destroyWidgets(const VectorWidgetPtr &_widgets)
#define MYGUI_LOG(level, text)
#define MYGUI_EXCEPT(dest)
void destroyWidgets(const VectorWidgetPtr &_widgets)
Definition: MyGUI_Gui.cpp:270
std::vector< Widget * > VectorWidgetPtr
#define MYGUI_ASSERT(exp, dest)
void _deleteWidget(Widget *_widget)
Type * castType(bool _throw=true)
Definition: MyGUI_IObject.h:33
void registerUnlinker(IUnlinkWidget *_unlink)
void unregisterFactory(const std::string &_category, const std::string &_type)
Widget * createWidget(WidgetStyle _style, const std::string &_type, const std::string &_skin, const IntCoord &_coord, Widget *_parent, ICroppedRectangle *_cropeedParent, const std::string &_name)
void registerFactory(const std::string &_category, const std::string &_type, Delegate::IDelegate *_delegate)
void _initialise(WidgetStyle _style, const IntCoord &_coord, const std::string &_skinName, Widget *_parent, ICroppedRectangle *_croppedParent, const std::string &_name)
IObject * createObject(const std::string &_category, const std::string &_type)
void unregisterUnlinker(IUnlinkWidget *_unlink)