MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #include "MyGUI_Precompiled.h" 00008 #include "MyGUI_ClipboardManager.h" 00009 #include "MyGUI_Gui.h" 00010 #include "MyGUI_TextIterator.h" 00011 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 00012 #include "MyGUI_WindowsClipboardHandler.h" 00013 #endif 00014 00015 namespace MyGUI 00016 { 00017 00018 template <> ClipboardManager* Singleton<ClipboardManager>::msInstance = nullptr; 00019 template <> const char* Singleton<ClipboardManager>::mClassTypeName = "ClipboardManager"; 00020 00021 ClipboardManager::ClipboardManager() : 00022 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 00023 mWindowsClipboardHandler(nullptr), 00024 #endif 00025 mIsInitialise(false) 00026 { 00027 } 00028 00029 void ClipboardManager::initialise() 00030 { 00031 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice"); 00032 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName()); 00033 00034 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 00035 mWindowsClipboardHandler = new WindowsClipboardHandler(); 00036 mWindowsClipboardHandler->initialise(); 00037 #endif 00038 00039 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized"); 00040 mIsInitialise = true; 00041 } 00042 00043 void ClipboardManager::shutdown() 00044 { 00045 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised"); 00046 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName()); 00047 00048 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32 00049 mWindowsClipboardHandler->shutdown(); 00050 delete mWindowsClipboardHandler; 00051 mWindowsClipboardHandler = nullptr; 00052 #endif 00053 00054 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown"); 00055 mIsInitialise = false; 00056 } 00057 00058 void ClipboardManager::setClipboardData(const std::string& _type, const std::string& _data) 00059 { 00060 mClipboardData[_type] = _data; 00061 00062 eventClipboardChanged(_type, _data); 00063 } 00064 00065 void ClipboardManager::clearClipboardData(const std::string& _type) 00066 { 00067 MapString::iterator iter = mClipboardData.find(_type); 00068 if (iter != mClipboardData.end()) mClipboardData.erase(iter); 00069 } 00070 00071 std::string ClipboardManager::getClipboardData(const std::string& _type) 00072 { 00073 std::string ret; 00074 MapString::iterator iter = mClipboardData.find(_type); 00075 if (iter != mClipboardData.end()) 00076 ret = (*iter).second; 00077 00078 // Give delegates a chance to fill the clipboard with data 00079 eventClipboardRequested(_type, ret); 00080 return ret; 00081 } 00082 00083 } // namespace MyGUI