Kaydet (Commit) 6552767a authored tarafından Miklos Vajna's avatar Miklos Vajna

LOK: add Document::paste()

Change-Id: I34998229e7f5cac4c62c859861783be3c161f9bf
üst 981a9748
......@@ -122,6 +122,7 @@ ifneq ($(filter $(OS),ANDROID IOS MACOSX),)
$(eval $(call gb_Library_add_exception_objects,sofficeapp,\
desktop/source/lib/init \
desktop/source/lib/lokinteractionhandler \
desktop/source/lib/lokclipboard \
$(if $(filter $(OS),ANDROID), \
desktop/source/lib/lokandroid) \
))
......@@ -130,6 +131,7 @@ ifeq ($(USING_X11),TRUE)
$(eval $(call gb_Library_add_exception_objects,sofficeapp,\
desktop/source/lib/init \
desktop/source/lib/lokinteractionhandler \
desktop/source/lib/lokclipboard \
))
endif
endif
......
......@@ -44,6 +44,7 @@
#include <com/sun/star/ucb/XContentProvider.hpp>
#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
#include <editeng/fontitem.hxx>
#include <editeng/flstitem.hxx>
......@@ -79,6 +80,7 @@
#include "../../inc/lib/init.hxx"
#include "lokinteractionhandler.hxx"
#include <lokclipboard.hxx>
using namespace css;
using namespace vcl;
......@@ -247,6 +249,10 @@ static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
static char* doc_getTextSelection(LibreOfficeKitDocument* pThis,
const char* pMimeType,
char** pUsedMimeType);
static bool doc_paste(LibreOfficeKitDocument* pThis,
const char* pMimeType,
const char* pData,
size_t nSize);
static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
int nType,
int nX,
......@@ -287,6 +293,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->postUnoCommand = doc_postUnoCommand;
m_pDocumentClass->setTextSelection = doc_setTextSelection;
m_pDocumentClass->getTextSelection = doc_getTextSelection;
m_pDocumentClass->paste = doc_paste;
m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
m_pDocumentClass->resetSelection = doc_resetSelection;
m_pDocumentClass->getCommandValues = doc_getCommandValues;
......@@ -990,6 +997,37 @@ static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMi
return pMemory;
}
static bool doc_paste(LibreOfficeKitDocument* pThis, const char* pMimeType, const char* pData, size_t nSize)
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
return false;
}
uno::Reference<datatransfer::XTransferable> xTransferable(new LOKTransferable(pMimeType, pData, nSize));
uno::Reference<datatransfer::clipboard::XClipboard> xClipboard(new LOKClipboard());
xClipboard->setContents(xTransferable, uno::Reference<datatransfer::clipboard::XClipboardOwner>());
vcl::Window* pWindow = pDoc->getWindow();
if (!pWindow)
{
gImpl->maLastExceptionMsg = "Document did not provide a window";
return false;
}
pWindow->SetClipboard(xClipboard);
OUString aCommand(".uno:Paste");
uno::Sequence<beans::PropertyValue> aPropertyValues;
if (!comphelper::dispatchCommand(aCommand, aPropertyValues))
{
gImpl->maLastExceptionMsg = "Failed to dispatch the .uno: command";
return false;
}
return true;
}
static void doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY)
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
......
/* -*- 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 <comphelper/sequence.hxx>
using namespace com::sun::star;
uno::Reference<datatransfer::XTransferable> SAL_CALL LOKClipboard::getContents()
throw (uno::RuntimeException, std::exception)
{
return m_xTransferable;
}
void SAL_CALL LOKClipboard::setContents(const uno::Reference<datatransfer::XTransferable>& xTransferable,
const uno::Reference<datatransfer::clipboard::XClipboardOwner>& /*xClipboardOwner*/)
throw (uno::RuntimeException, std::exception)
{
m_xTransferable = xTransferable;
}
OUString SAL_CALL LOKClipboard::getName() throw (uno::RuntimeException, std::exception)
{
return OUString();
}
LOKTransferable::LOKTransferable(const char* pMimeType, const char* pData, size_t nSize)
: m_aMimeType(pMimeType),
m_aText(pData, nSize)
{
}
uno::Any SAL_CALL LOKTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor)
throw(datatransfer::UnsupportedFlavorException, io::IOException, uno::RuntimeException, std::exception)
{
uno::Any aRet;
if (m_aMimeType == "text/plain;charset=utf-8" && rFlavor.MimeType == "text/plain;charset=utf-16")
aRet <<= OStringToOUString(m_aText, RTL_TEXTENCODING_UTF8);
return aRet;
}
std::vector<datatransfer::DataFlavor> LOKTransferable::getTransferDataFlavorsAsVector()
{
std::vector<datatransfer::DataFlavor> aRet;
datatransfer::DataFlavor aFlavor;
aFlavor.MimeType = OUString::fromUtf8(m_aMimeType.getStr());
aFlavor.DataType = cppu::UnoType< uno::Sequence<sal_Int8> >::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<OUString>::get();
}
aRet.push_back(aFlavor);
return aRet;
}
uno::Sequence<datatransfer::DataFlavor> SAL_CALL LOKTransferable::getTransferDataFlavors()
throw(uno::RuntimeException, std::exception)
{
return comphelper::containerToSequence(getTransferDataFlavorsAsVector());
}
sal_Bool SAL_CALL LOKTransferable::isDataFlavorSupported(const datatransfer::DataFlavor& rFlavor)
throw(uno::RuntimeException, std::exception)
{
const std::vector<datatransfer::DataFlavor> 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: */
/* -*- 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/.
*/
#ifndef INCLUDED_DESKTOP_SOURCE_LIB_LOKCLIPBOARD_HXX
#define INCLUDED_DESKTOP_SOURCE_LIB_LOKCLIPBOARD_HXX
#include <vector>
#include <cppuhelper/implbase.hxx>
#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
/// A clipboard implementation for LibreOfficeKit.
class LOKClipboard : public cppu::WeakImplHelper<css::datatransfer::clipboard::XClipboard>
{
css::uno::Reference<css::datatransfer::XTransferable> m_xTransferable;
public:
virtual css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getContents()
throw(css::uno::RuntimeException, std::exception) override;
virtual void SAL_CALL setContents(const css::uno::Reference<css::datatransfer::XTransferable>& xTransferable,
const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& xClipboardOwner)
throw(css::uno::RuntimeException, std::exception) override;
virtual OUString SAL_CALL getName() throw(css::uno::RuntimeException, std::exception) override;
};
/// Represents the contents of LOKClipboard.
class LOKTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
{
OString m_aMimeType;
OString m_aText;
/// Provides a list of flavors, used by getTransferDataFlavors() and isDataFlavorSupported().
std::vector<css::datatransfer::DataFlavor> getTransferDataFlavorsAsVector();
public:
LOKTransferable(const char* pMimeType, const char* pData, size_t nSize);
virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor)
throw(css::datatransfer::UnsupportedFlavorException, css::io::IOException, css::uno::RuntimeException, std::exception) override;
virtual css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors()
throw(css::uno::RuntimeException, std::exception) override;
virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& rFlavor)
throw(css::uno::RuntimeException, std::exception) override;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -157,6 +157,12 @@ struct _LibreOfficeKitDocumentClass
const char* pMimeType,
char** pUsedMimeType);
/// @see lok::Document::paste().
bool (*paste) (LibreOfficeKitDocument* pThis,
const char* pMimeType,
const char* pData,
size_t nSize);
/// @see lok::Document::setGraphicSelection
void (*setGraphicSelection) (LibreOfficeKitDocument* pThis,
int nType,
......
......@@ -246,6 +246,18 @@ public:
return mpDoc->pClass->getTextSelection(mpDoc, pMimeType, pUsedMimeType);
}
/**
* Pastes content at the current cursor position.
*
* @param pMimeType format of pData, for example text/plain;charset=utf-8.
* @param pData the actual data to be pasted.
* @return if the supplied data was pasted successfully.
*/
inline bool paste(const char* pMimeType, const char* pData, size_t nSize)
{
return mpDoc->pClass->paste(mpDoc, pMimeType, pData, nSize);
}
/**
* Adjusts the graphic selection.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment