/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "lokclipboard.hxx" #include using namespace com::sun::star; uno::Reference SAL_CALL LOKClipboard::getContents() { return m_xTransferable; } void SAL_CALL LOKClipboard::setContents(const uno::Reference& xTransferable, const uno::Reference& /*xClipboardOwner*/) { m_xTransferable = xTransferable; } OUString SAL_CALL LOKClipboard::getName() { return OUString(); } LOKTransferable::LOKTransferable(const char* pMimeType, const char* pData, std::size_t nSize) : m_aMimeType(pMimeType), m_aSequence(reinterpret_cast(pData), nSize) { } uno::Any SAL_CALL LOKTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor) { uno::Any aRet; if (rFlavor.DataType == cppu::UnoType::get()) { auto pText = reinterpret_cast(m_aSequence.getArray()); aRet <<= OUString(pText, m_aSequence.getLength(), RTL_TEXTENCODING_UTF8); } else aRet <<= m_aSequence; return aRet; } std::vector LOKTransferable::getTransferDataFlavorsAsVector() { std::vector aRet; datatransfer::DataFlavor aFlavor; aFlavor.MimeType = OUString::fromUtf8(m_aMimeType.getStr()); aFlavor.DataType = cppu::UnoType< uno::Sequence >::get(); sal_Int32 nIndex(0); if (m_aMimeType.getToken(0, ';', nIndex) == "text/plain") { if (m_aMimeType.getToken(0, ';', nIndex) != "charset=utf-16") aFlavor.MimeType = "text/plain;charset=utf-16"; aFlavor.DataType = cppu::UnoType::get(); } aRet.push_back(aFlavor); return aRet; } uno::Sequence SAL_CALL LOKTransferable::getTransferDataFlavors() { return comphelper::containerToSequence(getTransferDataFlavorsAsVector()); } sal_Bool SAL_CALL LOKTransferable::isDataFlavorSupported(const datatransfer::DataFlavor& rFlavor) { const std::vector aFlavors = getTransferDataFlavorsAsVector(); return std::find_if(aFlavors.begin(), aFlavors.end(), [&rFlavor](const datatransfer::DataFlavor& i) { return i.MimeType == rFlavor.MimeType && i.DataType == rFlavor.DataType; }) != aFlavors.end(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */