// This file is part of VSTGUI. It is subject to the license terms // in the LICENSE file found in the top-level directory of this // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE #include "cclipboard.h" #include "platform/platformfactory.h" #include namespace VSTGUI { namespace CClipboardDetail { //----------------------------------------------------------------------------- template struct StringDataPackage : IDataPackage { StringDataPackage (std::string_view str) : str (str) {} uint32_t getCount () const final { return 1; } uint32_t getDataSize (uint32_t index) const final { return static_cast (str.size ()); } Type getDataType (uint32_t index) const final { return AsFile ? Type::kFilePath : Type::kText; } uint32_t getData (uint32_t index, const void*& buffer, Type& type) const final { buffer = str.data (); type = getDataType (index); return getDataSize (index); } std::string str; }; //----------------------------------------------------------------------------- template Optional getString (IDataPackage* cb) { for (auto i = 0u, count = cb->getCount (); i < count; i++) { if (cb->getDataType (i) == (AsFile ? IDataPackage::Type::kFilePath : IDataPackage::Type::kText)) { IDataPackage::Type type; const void* data = nullptr; auto size = cb->getData (i, data, type); if (size > 0) { return {UTF8String (std::string (static_cast (data), size))}; } } } return {}; } } // CClipboardDetail //----------------------------------------------------------------------------- SharedPointer CClipboard::get () { return getPlatformFactory ().getClipboard (); } //----------------------------------------------------------------------------- bool CClipboard::set (const SharedPointer& data) { return getPlatformFactory ().setClipboard (data); } //----------------------------------------------------------------------------- bool CClipboard::setString (UTF8StringPtr str) { return set (makeOwned> ( std::string_view (str, strlen (str)))); } //----------------------------------------------------------------------------- bool CClipboard::setFilePath (UTF8StringPtr str) { return set (makeOwned> ( std::string_view (str, strlen (str)))); } //----------------------------------------------------------------------------- Optional CClipboard::getString () { if (auto cb = get ()) { return CClipboardDetail::getString (cb); } return {}; } //----------------------------------------------------------------------------- Optional CClipboard::getFilePath () { if (auto cb = get ()) { return CClipboardDetail::getString (cb); } return {}; } } // VSTGUI