MyGUI 3.2.2

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"
8 #include "MyGUI_ClipboardManager.h"
9 #include "MyGUI_Gui.h"
10 #include "MyGUI_TextIterator.h"
11 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
12 #include "MyGUI_WindowsClipboardHandler.h"
13 #endif
14
15 namespace MyGUI
16 {
17
18 template <> ClipboardManager* Singleton<ClipboardManager>::msInstance = nullptr;
19 template <> const char* Singleton<ClipboardManager>::mClassTypeName = "ClipboardManager";
20
21 ClipboardManager::ClipboardManager() :
22 #if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
23 mWindowsClipboardHandler(nullptr),
24 #endif
25 mIsInitialise(false)
26 {
27 }
28
29 void ClipboardManager::initialise()
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
43 void ClipboardManager::shutdown()
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
MyGUI::ClipboardManager::initialise
void initialise()
Definition: MyGUI_ClipboardManager.cpp:29
MyGUI_ClipboardManager.h
MyGUI::ClipboardManager::eventClipboardRequested
delegates::CMultiDelegate2< const std::string &, std::string & > eventClipboardRequested
Definition: MyGUI_ClipboardManager.h:59
MyGUI_Precompiled.h
MyGUI::ClipboardManager::ClipboardManager
ClipboardManager()
Definition: MyGUI_ClipboardManager.cpp:21
MyGUI::ClipboardManager::eventClipboardChanged
delegates::CMultiDelegate2< const std::string &, const std::string & > eventClipboardChanged
Definition: MyGUI_ClipboardManager.h:51
MyGUI::ClipboardManager::clearClipboardData
void clearClipboardData(const std::string &_type)
Definition: MyGUI_ClipboardManager.cpp:65
MyGUI::Singleton< ClipboardManager >::getClassTypeName
static const char * getClassTypeName()
Definition: MyGUI_Singleton.h:49
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:29
MyGUI::ClipboardManager::getClipboardData
std::string getClipboardData(const std::string &_type)
Definition: MyGUI_ClipboardManager.cpp:71
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition: MyGUI_Diagnostic.h:22
MyGUI_WindowsClipboardHandler.h
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::ClipboardManager::setClipboardData
void setClipboardData(const std::string &_type, const std::string &_data)
Definition: MyGUI_ClipboardManager.cpp:58
MYGUI_PLATFORM_WIN32
#define MYGUI_PLATFORM_WIN32
Definition: MyGUI_Platform.h:11
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:42
MYGUI_PLATFORM
#define MYGUI_PLATFORM
Definition: MyGUI_Platform.h:26
MyGUI_Gui.h
MyGUI_TextIterator.h
MyGUI::ClipboardManager::shutdown
void shutdown()
Definition: MyGUI_ClipboardManager.cpp:43