MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #include "MyGUI_Precompiled.h" 00023 #include "MyGUI_WidgetManager.h" 00024 #include "MyGUI_Gui.h" 00025 #include "MyGUI_Widget.h" 00026 #include "MyGUI_FactoryManager.h" 00027 00028 #include "MyGUI_Button.h" 00029 #include "MyGUI_Canvas.h" 00030 #include "MyGUI_ComboBox.h" 00031 #include "MyGUI_DDContainer.h" 00032 #include "MyGUI_EditBox.h" 00033 #include "MyGUI_ItemBox.h" 00034 #include "MyGUI_ListBox.h" 00035 #include "MyGUI_MenuBar.h" 00036 #include "MyGUI_MenuControl.h" 00037 #include "MyGUI_MenuItem.h" 00038 #include "MyGUI_MultiListBox.h" 00039 #include "MyGUI_MultiListItem.h" 00040 #include "MyGUI_PopupMenu.h" 00041 #include "MyGUI_ProgressBar.h" 00042 #include "MyGUI_ScrollBar.h" 00043 #include "MyGUI_ScrollView.h" 00044 #include "MyGUI_ImageBox.h" 00045 #include "MyGUI_TextBox.h" 00046 #include "MyGUI_TabControl.h" 00047 #include "MyGUI_TabItem.h" 00048 #include "MyGUI_Widget.h" 00049 #include "MyGUI_Window.h" 00050 00051 #include "MyGUI_BackwardCompatibility.h" 00052 00053 namespace MyGUI 00054 { 00055 00056 template <> WidgetManager* Singleton<WidgetManager>::msInstance = nullptr; 00057 template <> const char* Singleton<WidgetManager>::mClassTypeName("WidgetManager"); 00058 00059 WidgetManager::WidgetManager() : 00060 mIsInitialise(false) 00061 { 00062 } 00063 00064 void WidgetManager::initialise() 00065 { 00066 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice"); 00067 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName()); 00068 00069 FactoryManager& factory = FactoryManager::getInstance(); 00070 00071 factory.registerFactory<Button>("Widget"); 00072 factory.registerFactory<Canvas>("Widget"); 00073 factory.registerFactory<ComboBox>("Widget"); 00074 factory.registerFactory<DDContainer>("Widget"); 00075 factory.registerFactory<EditBox>("Widget"); 00076 factory.registerFactory<ItemBox>("Widget"); 00077 factory.registerFactory<ListBox>("Widget"); 00078 factory.registerFactory<MenuBar>("Widget"); 00079 factory.registerFactory<MenuControl>("Widget"); 00080 factory.registerFactory<MenuItem>("Widget"); 00081 factory.registerFactory<MultiListBox>("Widget"); 00082 factory.registerFactory<MultiListItem>("Widget"); 00083 factory.registerFactory<PopupMenu>("Widget"); 00084 factory.registerFactory<ProgressBar>("Widget"); 00085 factory.registerFactory<ScrollBar>("Widget"); 00086 factory.registerFactory<ScrollView>("Widget"); 00087 factory.registerFactory<ImageBox>("Widget"); 00088 factory.registerFactory<TextBox>("Widget"); 00089 factory.registerFactory<TabControl>("Widget"); 00090 factory.registerFactory<TabItem>("Widget"); 00091 factory.registerFactory<Widget>("Widget"); 00092 factory.registerFactory<Window>("Widget"); 00093 00094 BackwardCompatibility::registerWidgetTypes(); 00095 00096 Gui::getInstance().eventFrameStart += newDelegate(this, &WidgetManager::notifyEventFrameStart); 00097 00098 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized"); 00099 mIsInitialise = true; 00100 } 00101 00102 void WidgetManager::shutdown() 00103 { 00104 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised"); 00105 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName()); 00106 00107 Gui::getInstance().eventFrameStart -= newDelegate(this, &WidgetManager::notifyEventFrameStart); 00108 _deleteDelayWidgets(); 00109 00110 mVectorIUnlinkWidget.clear(); 00111 00112 FactoryManager::getInstance().unregisterFactory("Widget"); 00113 00114 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown"); 00115 mIsInitialise = false; 00116 } 00117 00118 Widget* WidgetManager::createWidget(WidgetStyle _style, const std::string& _type, const std::string& _skin, const IntCoord& _coord, Widget* _parent, ICroppedRectangle* _cropeedParent, const std::string& _name) 00119 { 00120 IObject* object = FactoryManager::getInstance().createObject("Widget", _type); 00121 if (object != nullptr) 00122 { 00123 Widget* widget = object->castType<Widget>(); 00124 widget->_initialise(_style, _coord, _skin, _parent, _cropeedParent, _name); 00125 00126 return widget; 00127 } 00128 00129 MYGUI_EXCEPT("factory '" << _type << "' not found"); 00130 } 00131 00132 void WidgetManager::destroyWidget(Widget* _widget) 00133 { 00134 Gui::getInstance().destroyWidget(_widget); 00135 } 00136 00137 void WidgetManager::destroyWidgets(const VectorWidgetPtr& _widgets) 00138 { 00139 Gui::getInstance().destroyWidgets(_widgets); 00140 } 00141 00142 void WidgetManager::destroyWidgets(EnumeratorWidgetPtr _widgets) 00143 { 00144 Gui::getInstance().destroyWidgets(_widgets); 00145 } 00146 00147 void WidgetManager::registerUnlinker(IUnlinkWidget* _unlink) 00148 { 00149 unregisterUnlinker(_unlink); 00150 mVectorIUnlinkWidget.push_back(_unlink); 00151 } 00152 00153 void WidgetManager::unregisterUnlinker(IUnlinkWidget* _unlink) 00154 { 00155 VectorIUnlinkWidget::iterator iter = std::remove(mVectorIUnlinkWidget.begin(), mVectorIUnlinkWidget.end(), _unlink); 00156 if (iter != mVectorIUnlinkWidget.end()) 00157 mVectorIUnlinkWidget.erase(iter); 00158 } 00159 00160 void WidgetManager::unlinkFromUnlinkers(Widget* _widget) 00161 { 00162 for (VectorIUnlinkWidget::iterator iter = mVectorIUnlinkWidget.begin(); iter != mVectorIUnlinkWidget.end(); ++iter) 00163 { 00164 (*iter)->_unlinkWidget(_widget); 00165 } 00166 } 00167 00168 bool WidgetManager::isFactoryExist(const std::string& _type) 00169 { 00170 if (FactoryManager::getInstance().isFactoryExist("Widget", _type)) 00171 { 00172 return true; 00173 } 00174 00175 return false; 00176 } 00177 00178 void WidgetManager::notifyEventFrameStart(float _time) 00179 { 00180 _deleteDelayWidgets(); 00181 } 00182 00183 void WidgetManager::_deleteWidget(Widget* _widget) 00184 { 00185 _widget->_shutdown(); 00186 00187 for (VectorWidgetPtr::iterator entry = mDestroyWidgets.begin(); entry != mDestroyWidgets.end(); ++entry) 00188 { 00189 /*if ((*entry) == _widget) 00190 return;*/ 00191 MYGUI_ASSERT((*entry) != _widget, "double delete widget"); 00192 } 00193 00194 mDestroyWidgets.push_back(_widget); 00195 } 00196 00197 void WidgetManager::_deleteDelayWidgets() 00198 { 00199 if (!mDestroyWidgets.empty()) 00200 { 00201 for (VectorWidgetPtr::iterator entry = mDestroyWidgets.begin(); entry != mDestroyWidgets.end(); ++entry) 00202 delete (*entry); 00203 mDestroyWidgets.clear(); 00204 } 00205 } 00206 00207 } // namespace MyGUI