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

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