Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_DelegateManager.h"
00025
00026 namespace MyGUI
00027 {
00028
00029 MYGUI_INSTANCE_IMPLEMENT(DelegateManager);
00030
00031 void DelegateManager::initialise()
00032 {
00033 MYGUI_ASSERT(false == mIsInitialise, INSTANCE_TYPE_NAME << " initialised twice");
00034 MYGUI_LOG(Info, "* Initialise: " << INSTANCE_TYPE_NAME);
00035
00036 mDefaultDelegate = nullptr;
00037
00038 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully initialized");
00039 mIsInitialise = true;
00040 }
00041
00042 void DelegateManager::shutdown()
00043 {
00044 if (false == mIsInitialise) return;
00045 MYGUI_LOG(Info, "* Shutdown: " << INSTANCE_TYPE_NAME);
00046
00047
00048
00049 MYGUI_LOG(Info, INSTANCE_TYPE_NAME << " successfully shutdown");
00050 mIsInitialise = false;
00051 }
00052
00053 void DelegateManager::addDelegate(const std::string& _key, HandleEvent::IDelegate * _delegate)
00054 {
00055 MapDelegate::iterator iter = mDelegates.find(_key);
00056 if (iter != mDelegates.end())
00057 {
00058 MYGUI_LOG(Warning, "Delegate '" << _key << "' already exist");
00059 }
00060 mDelegates[_key] = _delegate;
00061 }
00062
00063 void DelegateManager::removeDelegate(const std::string& _key)
00064 {
00065 MapDelegate::iterator iter = mDelegates.find(_key);
00066 if (iter == mDelegates.end())
00067 {
00068 MYGUI_LOG(Warning, "Delegate '" << _key << "' not found");
00069 }
00070 mDelegates.erase(iter);
00071 }
00072
00073 void DelegateManager::addDefaultDelegate(HandleEvent::IDelegate * _delegate)
00074 {
00075 mDefaultDelegate = _delegate;
00076 }
00077
00078 void DelegateManager::callDelegate(WidgetPtr _sender, const std::string& _key, const std::string& _event)
00079 {
00080 MapDelegate::iterator iter = mDelegates.find(_key);
00081 if (iter != mDelegates.end())
00082 {
00083 iter->second(_sender, _key, _event);
00084 }
00085 else
00086 {
00087 if (mDefaultDelegate.empty())
00088 {
00089 mDefaultDelegate(_sender, _key, _event);
00090 }
00091 else
00092 {
00093 MYGUI_LOG(Warning, "Delegate '" << _key << "' not found");
00094 }
00095 }
00096 }
00097
00098 }