• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_DelegateManager.cpp

Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009     
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014     
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019     
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
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         // nothing yet
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 } // namespace MyGUI

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1