MyGUI: MyGUI_ClipboardManager.cpp Source File

MyGUI 3.4.3

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
15namespace MyGUI
16{
17
18 MYGUI_SINGLETON_DEFINITION(ClipboardManager);
19
20 ClipboardManager::ClipboardManager() :
21#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
22 mWindowsClipboardHandler(nullptr),
23#endif
24 mSingletonHolder(this)
25 {
26 }
27
28 void ClipboardManager::initialise()
29 {
30 MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
31 MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
32
33#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
34 mWindowsClipboardHandler = new WindowsClipboardHandler();
35 mWindowsClipboardHandler->initialise();
36#endif
37
38 MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
39 mIsInitialise = true;
40 }
41
42 void ClipboardManager::shutdown()
43 {
44 MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
45 MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
46
47#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
48 mWindowsClipboardHandler->shutdown();
49 delete mWindowsClipboardHandler;
50 mWindowsClipboardHandler = nullptr;
51#endif
52
53 MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
54 mIsInitialise = false;
55 }
56
57 void ClipboardManager::setClipboardData(std::string_view _type, std::string_view _data)
58 {
59 mapSet(mClipboardData, _type, _data);
60
61 eventClipboardChanged(_type, _data);
62 }
63
64 void ClipboardManager::clearClipboardData(std::string_view _type)
65 {
66 MapString::iterator iter = mClipboardData.find(_type);
67 if (iter != mClipboardData.end())
68 mClipboardData.erase(iter);
69 eventClipboardChanged(_type, std::string_view{});
70 }
71
72 std::string ClipboardManager::getClipboardData(std::string_view _type) const
73 {
74 std::string ret;
75 MapString::const_iterator iter = mClipboardData.find(_type);
76 if (iter != mClipboardData.end())
77 ret = (*iter).second;
78
79 // Give delegates a chance to fill the clipboard with data
80 eventClipboardRequested(_type, ret);
81 return ret;
82 }
83
84} // namespace MyGUI
MyGUI_ClipboardManager.h
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:31
MYGUI_LOG
#define MYGUI_LOG(level, text)
Definition MyGUI_Diagnostic.h:17
MyGUI_Gui.h
MYGUI_PLATFORM
#define MYGUI_PLATFORM
Definition MyGUI_Platform.h:26
MYGUI_PLATFORM_WIN32
#define MYGUI_PLATFORM_WIN32
Definition MyGUI_Platform.h:11
MyGUI_Precompiled.h
MYGUI_SINGLETON_DEFINITION
#define MYGUI_SINGLETON_DEFINITION(ClassName)
Definition MyGUI_Singleton.h:126
MyGUI_TextIterator.h
MyGUI_WindowsClipboardHandler.h
MyGUI::ClipboardManager
Definition MyGUI_ClipboardManager.h:22
MyGUI::ClipboardManager::ClipboardManager
ClipboardManager()
Definition MyGUI_ClipboardManager.cpp:20
MyGUI::ClipboardManager::getClipboardData
std::string getClipboardData(std::string_view _type) const
Definition MyGUI_ClipboardManager.cpp:72
MyGUI::ClipboardManager::setClipboardData
void setClipboardData(std::string_view _type, std::string_view _data)
Definition MyGUI_ClipboardManager.cpp:57
MyGUI::ClipboardManager::clearClipboardData
void clearClipboardData(std::string_view _type)
Definition MyGUI_ClipboardManager.cpp:64
MyGUI::ClipboardManager::eventClipboardChanged
EventPairConvertStringView< delegates::MultiDelegate< const std::string &, const std::string & >, delegates::MultiDelegate< std::string_view, std::string_view > > eventClipboardChanged
Definition MyGUI_ClipboardManager.h:56
MyGUI::ClipboardManager::getClassTypeName
static std::string_view getClassTypeName()
MyGUI::ClipboardManager::shutdown
void shutdown()
Definition MyGUI_ClipboardManager.cpp:42
MyGUI::ClipboardManager::initialise
void initialise()
Definition MyGUI_ClipboardManager.cpp:28
MyGUI::ClipboardManager::eventClipboardRequested
EventPairConvertStringView< delegates::MultiDelegate< const std::string &, std::string & >, delegates::MultiDelegate< std::string_view, std::string & > > eventClipboardRequested
Definition MyGUI_ClipboardManager.h:67
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::mapSet
void mapSet(Map &map, std::string_view key, const Value &value)
Definition MyGUI_Macros.h:36