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