MyGUI  3.2.1
MyGUI_ClipboardManager.cpp
Go to the documentation of this file.
1 /*
2  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3  * Distributed under the MIT License
4  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5  */
6 
7 #include "MyGUI_Precompiled.h"
9 #include "MyGUI_Gui.h"
10 #include "MyGUI_TextIterator.h"
11 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
13 #endif
14 
15 namespace MyGUI
16 {
17 
18  template <> ClipboardManager* Singleton<ClipboardManager>::msInstance = nullptr;
19  template <> const char* Singleton<ClipboardManager>::mClassTypeName = "ClipboardManager";
20 
23  mWindowsClipboardHandler(nullptr),
24 #endif
25  mIsInitialise(false)
26  {
27  }
28 
30  {
31  MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
32  MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
33 
34 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
35  mWindowsClipboardHandler = new WindowsClipboardHandler();
36  mWindowsClipboardHandler->initialise();
37 #endif
38 
39  MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
40  mIsInitialise = true;
41  }
42 
44  {
45  MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
46  MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
47 
48 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
49  mWindowsClipboardHandler->shutdown();
50  delete mWindowsClipboardHandler;
51  mWindowsClipboardHandler = nullptr;
52 #endif
53 
54  MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
55  mIsInitialise = false;
56  }
57 
58  void ClipboardManager::setClipboardData(const std::string& _type, const std::string& _data)
59  {
60  mClipboardData[_type] = _data;
61 
62  eventClipboardChanged(_type, _data);
63  }
64 
65  void ClipboardManager::clearClipboardData(const std::string& _type)
66  {
67  MapString::iterator iter = mClipboardData.find(_type);
68  if (iter != mClipboardData.end()) mClipboardData.erase(iter);
69  }
70 
71  std::string ClipboardManager::getClipboardData(const std::string& _type)
72  {
73  std::string ret;
74  MapString::iterator iter = mClipboardData.find(_type);
75  if (iter != mClipboardData.end())
76  ret = (*iter).second;
77 
78  // Give delegates a chance to fill the clipboard with data
79  eventClipboardRequested(_type, ret);
80  return ret;
81  }
82 
83 } // namespace MyGUI