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"
9#include "MyGUI_Gui.h"
10#include "MyGUI_TextIterator.h"
11#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
13#endif
14
15namespace MyGUI
16{
17
19
22 mWindowsClipboardHandler(nullptr),
23#endif
24 mSingletonHolder(this)
25 {
26 }
27
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
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
#define MYGUI_ASSERT(exp, dest)
#define MYGUI_LOG(level, text)
#define MYGUI_PLATFORM
#define MYGUI_PLATFORM_WIN32
#define MYGUI_SINGLETON_DEFINITION(ClassName)
std::string getClipboardData(std::string_view _type) const
void setClipboardData(std::string_view _type, std::string_view _data)
void clearClipboardData(std::string_view _type)
EventPairConvertStringView< delegates::MultiDelegate< const std::string &, const std::string & >, delegates::MultiDelegate< std::string_view, std::string_view > > eventClipboardChanged
static std::string_view getClassTypeName()
EventPairConvertStringView< delegates::MultiDelegate< const std::string &, std::string & >, delegates::MultiDelegate< std::string_view, std::string & > > eventClipboardRequested
void mapSet(Map &map, std::string_view key, const Value &value)