MyGUI_ClipboardManager.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_ClipboardManager.h"
#include "MyGUI_Gui.h"
#include "MyGUI_TextIterator.h"
#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
#include "MyGUI_WindowsClipboardHandler.h"
#endif
namespace MyGUI
{
MYGUI_SINGLETON_DEFINITION(ClipboardManager);
ClipboardManager::ClipboardManager() :
#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
mWindowsClipboardHandler(nullptr),
#endif
mSingletonHolder(this)
{
}
void ClipboardManager::initialise()
{
MYGUI_ASSERT(!mIsInitialise, getClassTypeName() << " initialised twice");
MYGUI_LOG(Info, "* Initialise: " << getClassTypeName());
#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
mWindowsClipboardHandler = new WindowsClipboardHandler();
mWindowsClipboardHandler->initialise();
#endif
MYGUI_LOG(Info, getClassTypeName() << " successfully initialized");
mIsInitialise = true;
}
void ClipboardManager::shutdown()
{
MYGUI_ASSERT(mIsInitialise, getClassTypeName() << " is not initialised");
MYGUI_LOG(Info, "* Shutdown: " << getClassTypeName());
#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
mWindowsClipboardHandler->shutdown();
delete mWindowsClipboardHandler;
mWindowsClipboardHandler = nullptr;
#endif
MYGUI_LOG(Info, getClassTypeName() << " successfully shutdown");
mIsInitialise = false;
}
void ClipboardManager::setClipboardData(std::string_view _type, std::string_view _data)
{
mapSet(mClipboardData, _type, _data);
eventClipboardChanged(_type, _data);
}
void ClipboardManager::clearClipboardData(std::string_view _type)
{
MapString::iterator iter = mClipboardData.find(_type);
if (iter != mClipboardData.end())
mClipboardData.erase(iter);
eventClipboardChanged(_type, std::string_view{});
}
std::string ClipboardManager::getClipboardData(std::string_view _type) const
{
std::string ret;
MapString::const_iterator iter = mClipboardData.find(_type);
if (iter != mClipboardData.end())
ret = (*iter).second;
// Give delegates a chance to fill the clipboard with data
eventClipboardRequested(_type, ret);
return ret;
}
} // 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