summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranav Kant <pranavk@libreoffice.org>2015-12-09 21:45:21 +0530
committerDavid Tardon <dtardon@redhat.com>2015-12-09 16:36:22 +0000
commit7d7fad258dfde500c5ee99b5f1691172724383bd (patch)
tree2688915c6cf6534d80922f881a712c5a83881492
parentdbc830aecc722d34971d773470da478ef4c38714 (diff)
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>
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitGtk.h29
-rw-r--r--libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx8
-rw-r--r--libreofficekit/source/gtk/lokdocview.cxx33
3 files changed, 64 insertions, 6 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 1b03e4633547..903a74256ffa 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 8d43737a4b7d..875fefc46400 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -561,9 +561,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);
@@ -580,7 +579,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);
@@ -604,7 +602,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;
@@ -612,7 +610,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 3bf4d44c2835..741760214be4 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -343,7 +343,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");
@@ -2668,6 +2668,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)
{