[Libreoffice-commits] core.git: 4 commits - desktop/Library_sofficeapp.mk desktop/source include/LibreOfficeKit include/vcl libreofficekit/qa sw/inc sw/source vcl/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Oct 22 04:38:39 PDT 2015


 desktop/Library_sofficeapp.mk                       |    2 
 desktop/source/lib/init.cxx                         |   38 +++++++++
 desktop/source/lib/lokclipboard.cxx                 |   83 ++++++++++++++++++++
 desktop/source/lib/lokclipboard.hxx                 |   58 +++++++++++++
 include/LibreOfficeKit/LibreOfficeKit.h             |    6 +
 include/LibreOfficeKit/LibreOfficeKit.hxx           |   12 ++
 include/vcl/ITiledRenderable.hxx                    |    6 +
 include/vcl/window.hxx                              |    2 
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |   18 ++++
 sw/inc/unotxdoc.hxx                                 |    2 
 sw/source/uibase/uno/unotxdoc.cxx                   |    7 +
 vcl/source/window/window.cxx                        |    6 +
 12 files changed, 240 insertions(+)

New commits:
commit 173fc95b3551c1e69c49626211be8422cb29fb3e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Oct 22 13:32:31 2015 +0200

    gtktiledviewer: initial paste support
    
    Change-Id: I50b4dfa456d3518f5ef7faf5f634642973441a3e

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 289a999..f7c4d5c 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -12,6 +12,7 @@
 #include <string.h>
 #include <string>
 #include <map>
+#include <iostream>
 
 #include <boost/property_tree/json_parser.hpp>
 #include <gdk/gdkkeysyms.h>
@@ -280,6 +281,17 @@ static void doCopy(GtkWidget* pButton, gpointer /*pItem*/)
     free(pUsedFormat);
 }
 
+static void doPaste(GtkWidget* pButton, gpointer /*pItem*/)
+{
+    TiledWindow& rWindow = lcl_getTiledWindow(pButton);
+    LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
+    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView);
+
+    GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(rWindow.m_pDocView), GDK_SELECTION_CLIPBOARD);
+    gchar* pText = gtk_clipboard_wait_for_text(pClipboard);
+    if (pText)
+        pDocument->pClass->paste(pDocument, "text/plain;charset=utf-8", pText, strlen(pText));
+}
 
 /// Searches for the next or previous text of TiledWindow::m_pFindbarEntry.
 static void doSearch(GtkWidget* pButton, bool bBackwards)
@@ -662,6 +674,12 @@ static GtkWidget* createWindow(TiledWindow& rWindow)
     gtk_tool_item_set_tooltip_text(pCopyButton, "Copy");
     gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pCopyButton, -1);
     g_signal_connect(G_OBJECT(pCopyButton), "clicked", G_CALLBACK(doCopy), NULL);
+
+    GtkToolItem* pPasteButton = gtk_tool_button_new( NULL, NULL);
+    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(pPasteButton), "edit-paste-symbolic");
+    gtk_tool_item_set_tooltip_text(pPasteButton, "Paste");
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pPasteButton, -1);
+    g_signal_connect(G_OBJECT(pPasteButton), "clicked", G_CALLBACK(doPaste), NULL);
     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
 
     GtkToolItem* pEnableEditing = gtk_toggle_tool_button_new();
commit 6552767aa5ed61215eb64dac0cc026a5f7a9aad1
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Oct 22 11:26:13 2015 +0200

    LOK: add Document::paste()
    
    Change-Id: I34998229e7f5cac4c62c859861783be3c161f9bf

diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk
index 1b8c5f7..0254b74 100644
--- a/desktop/Library_sofficeapp.mk
+++ b/desktop/Library_sofficeapp.mk
@@ -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
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 405e5ff..9ac9347 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -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);
diff --git a/desktop/source/lib/lokclipboard.cxx b/desktop/source/lib/lokclipboard.cxx
new file mode 100644
index 0000000..a81902b
--- /dev/null
+++ b/desktop/source/lib/lokclipboard.cxx
@@ -0,0 +1,83 @@
+/* -*- 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: */
diff --git a/desktop/source/lib/lokclipboard.hxx b/desktop/source/lib/lokclipboard.hxx
new file mode 100644
index 0000000..b982e1c
--- /dev/null
+++ b/desktop/source/lib/lokclipboard.hxx
@@ -0,0 +1,58 @@
+/* -*- 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: */
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 83dcc98..d83717b 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -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,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 72231ad..4055250 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -247,6 +247,18 @@ public:
     }
 
     /**
+     * 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.
      *
      * @param nType @see LibreOfficeKitSetGraphicSelectionType
commit 981a974824642a81f86c526dea682cd27cd437db
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Oct 22 10:15:34 2015 +0200

    vcl: add ITiledRenderable::getWindow() and implement in sw
    
    Change-Id: I9d0fad3904e74b44b0b126974ace4025f7a4fc5b

diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index c294d20..bb891ab 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -147,6 +147,12 @@ public:
     {
         return OUString();
     }
+
+    /// Returns the current vcl::Window of the component.
+    virtual vcl::Window* getWindow()
+    {
+        return 0;
+    }
 };
 
 } // namespace vcl
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 92f8f6f..31ef514 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -431,6 +431,8 @@ public:
     virtual void resetSelection() override;
     /// @see vcl::ITiledRenderable::getPartPageRectangles().
     virtual OUString getPartPageRectangles() override;
+    /// @see vcl::ITiledRenderable::getWindow().
+    virtual vcl::Window* getWindow() override;
 
     // ::com::sun::star::tiledrendering::XTiledRenderable
     virtual void SAL_CALL paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) throw (::css::uno::RuntimeException, ::std::exception) override;
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 3cd15f0..d7e7b3f 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3182,6 +3182,13 @@ OUString SwXTextDocument::getPartPageRectangles()
     return pWrtShell->getPageRectangles();
 }
 
+vcl::Window* SwXTextDocument::getWindow()
+{
+    SolarMutexGuard aGuard;
+
+    return &pDocShell->GetView()->GetEditWin();
+}
+
 int SwXTextDocument::getPart()
 {
     SolarMutexGuard aGuard;
commit 98cdb563c1c63e93b4722721354d86848d2cd2c2
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Oct 22 09:41:29 2015 +0200

    vcl: add Window::SetClipboard()
    
    Change-Id: I385f64b7d5015c9a34f34a436b0ee2ce6b3a83d3

diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index 308760b..0123c3b 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -1387,6 +1387,8 @@ public:
 
     // Clipboard/Selection interfaces
     ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > GetClipboard();
+    /// Sets a custom clipboard for the window's frame, instead of creating it on-demand using css::datatransfer::clipboard::SystemClipboard.
+    void SetClipboard(css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard);
     ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboard > GetPrimarySelection();
 
     /*
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index f770bda..f44f1a2 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -3376,6 +3376,12 @@ void Window::ImplCallActivateListeners( vcl::Window *pOld )
     }
 }
 
+void Window::SetClipboard(Reference<XClipboard> xClipboard)
+{
+    if (mpWindowImpl->mpFrameData)
+        mpWindowImpl->mpFrameData->mxClipboard = xClipboard;
+}
+
 Reference< XClipboard > Window::GetClipboard()
 {
 


More information about the Libreoffice-commits mailing list