Blame SOURCES/0370-tdf-96317-Add-API-for-copy-paste-from-to-the-widget.patch

f325b2
From 3014df80526ebd05cd12707363db42e552f17686 Mon Sep 17 00:00:00 2001
f325b2
From: Pranav Kant <pranavk@libreoffice.org>
f325b2
Date: Wed, 9 Dec 2015 21:45:21 +0530
f325b2
Subject: [PATCH 370/398] tdf#96317: Add API for copy/paste from/to the widget
f325b2
f325b2
Change-Id: Iac869ddb65cbdd2227f96d047d83159ca7819f11
f325b2
Reviewed-on: https://gerrit.libreoffice.org/20534
f325b2
Reviewed-by: David Tardon <dtardon@redhat.com>
f325b2
Tested-by: David Tardon <dtardon@redhat.com>
f325b2
(cherry picked from commit 7d7fad258dfde500c5ee99b5f1691172724383bd)
f325b2
(cherry picked from commit 9c01ac05618875e812c9f6a18edf5cc6a7909b5e)
f325b2
---
f325b2
 include/LibreOfficeKit/LibreOfficeKitGtk.h         | 29 +++++++++++++++++++
f325b2
 .../qa/gtktiledviewer/gtktiledviewer.cxx           |  8 ++----
f325b2
 libreofficekit/source/gtk/lokdocview.cxx           | 33 +++++++++++++++++++++-
f325b2
 3 files changed, 64 insertions(+), 6 deletions(-)
f325b2
f325b2
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
f325b2
index 1b03e4633547..903a74256ffa 100644
f325b2
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
f325b2
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
f325b2
@@ -235,6 +235,35 @@ void                           lok_doc_view_highlight_all          (LOKDocView*
f325b2
                                                                     const gchar* pText);
f325b2
 
f325b2
 /**
f325b2
+ * lok_doc_view_copy_selection:
f325b2
+ * @pDocView: The #LOKDocView instance
f325b2
+ * @pMimeType: suggests the return format, for example text/plain;charset=utf-8
f325b2
+ * @pUsedMimeType: (out): output parameter to inform about the determined format
f325b2
+ * (suggested or plain text).
f325b2
+ *
f325b2
+ * Returns: Selected text. The caller must free the returned buffer after use.
f325b2
+ */
f325b2
+gchar*                          lok_doc_view_copy_selection        (LOKDocView* pDocView,
f325b2
+                                                                    const gchar* pMimeType,
f325b2
+                                                                    gchar** pUsedMimeType);
f325b2
+
f325b2
+/**
f325b2
+ * lok_doc_view_paste:
f325b2
+ * @pDocView: The #LOKDocView instance
f325b2
+ * @pMimeType: format of pData, for example text/plain;charset=utf-8
f325b2
+ * @pData: the data to be pasted
f325b2
+ * @nSize: length of data to be pasted
f325b2
+ *
f325b2
+ * Pastes the content at the current cursor position
f325b2
+ *
f325b2
+ * Returns: if pData was pasted successfully.
f325b2
+ */
f325b2
+gboolean                        lok_doc_view_paste                 (LOKDocView* pDocView,
f325b2
+                                                                    const gchar* pMimeType,
f325b2
+                                                                    const gchar* pData,
f325b2
+                                                                    gsize nSize);
f325b2
+
f325b2
+/**
f325b2
  * lok_doc_view_pixel_to_twip:
f325b2
  * @pDocView: The #LOKDocView instance
f325b2
  * @fInput: The value in pixels to convert to twips
f325b2
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
f325b2
index 2416e1c6dbcf..d064c4ce3e47 100644
f325b2
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
f325b2
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
f325b2
@@ -548,9 +548,8 @@ static void doCopy(GtkWidget* pButton, gpointer /*pItem*/)
f325b2
 {
f325b2
     TiledWindow& rWindow = lcl_getTiledWindow(pButton);
f325b2
     LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
f325b2
-    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView);
f325b2
     char* pUsedFormat = nullptr;
f325b2
-    char* pSelection = pDocument->pClass->getTextSelection(pDocument, "text/html", &pUsedFormat);
f325b2
+    char* pSelection = lok_doc_view_copy_selection(pLOKDocView, "text/html", &pUsedFormat);
f325b2
 
f325b2
     GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(rWindow.m_pDocView), GDK_SELECTION_CLIPBOARD);
f325b2
     std::string aUsedFormat(pUsedFormat);
f325b2
@@ -566,7 +565,6 @@ static void doPaste(GtkWidget* pButton, gpointer /*pItem*/)
f325b2
 {
f325b2
     TiledWindow& rWindow = lcl_getTiledWindow(pButton);
f325b2
     LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
f325b2
-    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView);
f325b2
 
f325b2
     GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(rWindow.m_pDocView), GDK_SELECTION_CLIPBOARD);
f325b2
 
f325b2
@@ -590,7 +588,7 @@ static void doPaste(GtkWidget* pButton, gpointer /*pItem*/)
f325b2
         GtkSelectionData* pSelectionData = gtk_clipboard_wait_for_contents(pClipboard, *oTarget);
f325b2
         gint nLength;
f325b2
         const guchar* pData = gtk_selection_data_get_data_with_length(pSelectionData, &nLength);
f325b2
-        bool bSuccess = pDocument->pClass->paste(pDocument, "text/html", reinterpret_cast<const char*>(pData), nLength);
f325b2
+        bool bSuccess = lok_doc_view_paste(pLOKDocView, "text/html", reinterpret_cast<const char*>(pData), nLength);
f325b2
         gtk_selection_data_free(pSelectionData);
f325b2
         if (bSuccess)
f325b2
             return;
f325b2
@@ -598,7 +596,7 @@ static void doPaste(GtkWidget* pButton, gpointer /*pItem*/)
f325b2
 
f325b2
     gchar* pText = gtk_clipboard_wait_for_text(pClipboard);
f325b2
     if (pText)
f325b2
-        pDocument->pClass->paste(pDocument, "text/plain;charset=utf-8", pText, strlen(pText));
f325b2
+        lok_doc_view_paste(pLOKDocView, "text/plain;charset=utf-8", pText, strlen(pText));
f325b2
 }
f325b2
 
f325b2
 /// Click handler for the search next button.
f325b2
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
index 34823437e6ad..99ad819f6e5c 100644
f325b2
--- a/libreofficekit/source/gtk/lokdocview.cxx
f325b2
+++ b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
@@ -344,7 +344,7 @@ doSearch(LOKDocView* pDocView, const char* pText, bool bBackwards, bool highligh
f325b2
     cairo_region_get_rectangle(cairoVisRegion, 0, &cairoVisRect);
f325b2
     x = pixelToTwip (cairoVisRect.x, priv->m_fZoom);
f325b2
     y = pixelToTwip (cairoVisRect.y, priv->m_fZoom);
f325b2
-    
f325b2
+
f325b2
     aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchString/type", '/'), "string");
f325b2
     aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchString/value", '/'), pText);
f325b2
     aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/type", '/'), "boolean");
f325b2
@@ -2667,6 +2667,37 @@ lok_doc_view_highlight_all (LOKDocView* pDocView,
f325b2
     doSearch(pDocView, pText, false, true);
f325b2
 }
f325b2
 
f325b2
+SAL_DLLPUBLIC_EXPORT gchar*
f325b2
+lok_doc_view_copy_selection (LOKDocView* pDocView,
f325b2
+                             const gchar* pMimeType,
f325b2
+                             gchar** pUsedMimeType)
f325b2
+{
f325b2
+    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pDocView);
f325b2
+    return pDocument->pClass->getTextSelection(pDocument, pMimeType, pUsedMimeType);
f325b2
+}
f325b2
+
f325b2
+SAL_DLLPUBLIC_EXPORT gboolean
f325b2
+lok_doc_view_paste (LOKDocView* pDocView,
f325b2
+                    const gchar* pMimeType,
f325b2
+                    const gchar* pData,
f325b2
+                    gsize nSize)
f325b2
+{
f325b2
+    LOKDocViewPrivate& priv = getPrivate(pDocView);
f325b2
+    LibreOfficeKitDocument* pDocument = priv->m_pDocument;
f325b2
+    gboolean ret = 0;
f325b2
+
f325b2
+    if (!priv->m_bEdit)
f325b2
+    {
f325b2
+        g_info ("ignoring paste in view-only mode");
f325b2
+        return ret;
f325b2
+    }
f325b2
+
f325b2
+    if (pData)
f325b2
+        ret = pDocument->pClass->paste(pDocument, pMimeType, pData, nSize);
f325b2
+
f325b2
+    return ret;
f325b2
+}
f325b2
+
f325b2
 SAL_DLLPUBLIC_EXPORT float
f325b2
 lok_doc_view_pixel_to_twip (LOKDocView* pDocView, float fInput)
f325b2
 {
f325b2
-- 
f325b2
2.12.0
f325b2