Kaydet (Commit) 7d7fad25 authored tarafından Pranav Kant's avatar Pranav Kant Kaydeden (comit) David Tardon

tdf#96317: Add API for copy/paste from/to the widget

Change-Id: Iac869ddb65cbdd2227f96d047d83159ca7819f11
Reviewed-on: https://gerrit.libreoffice.org/20534Reviewed-by: 's avatarDavid Tardon <dtardon@redhat.com>
Tested-by: 's avatarDavid Tardon <dtardon@redhat.com>
üst dbc830ae
...@@ -234,6 +234,35 @@ void lok_doc_view_find_prev (LOKDocView* ...@@ -234,6 +234,35 @@ void lok_doc_view_find_prev (LOKDocView*
void lok_doc_view_highlight_all (LOKDocView* pDocView, void lok_doc_view_highlight_all (LOKDocView* pDocView,
const gchar* pText); 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: * lok_doc_view_pixel_to_twip:
* @pDocView: The #LOKDocView instance * @pDocView: The #LOKDocView instance
......
...@@ -561,9 +561,8 @@ static void doCopy(GtkWidget* pButton, gpointer /*pItem*/) ...@@ -561,9 +561,8 @@ static void doCopy(GtkWidget* pButton, gpointer /*pItem*/)
{ {
TiledWindow& rWindow = lcl_getTiledWindow(pButton); TiledWindow& rWindow = lcl_getTiledWindow(pButton);
LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView); LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView);
char* pUsedFormat = nullptr; 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); GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(rWindow.m_pDocView), GDK_SELECTION_CLIPBOARD);
std::string aUsedFormat(pUsedFormat); std::string aUsedFormat(pUsedFormat);
...@@ -580,7 +579,6 @@ static void doPaste(GtkWidget* pButton, gpointer /*pItem*/) ...@@ -580,7 +579,6 @@ static void doPaste(GtkWidget* pButton, gpointer /*pItem*/)
{ {
TiledWindow& rWindow = lcl_getTiledWindow(pButton); TiledWindow& rWindow = lcl_getTiledWindow(pButton);
LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView); 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); 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*/) ...@@ -604,7 +602,7 @@ static void doPaste(GtkWidget* pButton, gpointer /*pItem*/)
GtkSelectionData* pSelectionData = gtk_clipboard_wait_for_contents(pClipboard, *oTarget); GtkSelectionData* pSelectionData = gtk_clipboard_wait_for_contents(pClipboard, *oTarget);
gint nLength; gint nLength;
const guchar* pData = gtk_selection_data_get_data_with_length(pSelectionData, &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); gtk_selection_data_free(pSelectionData);
if (bSuccess) if (bSuccess)
return; return;
...@@ -612,7 +610,7 @@ static void doPaste(GtkWidget* pButton, gpointer /*pItem*/) ...@@ -612,7 +610,7 @@ static void doPaste(GtkWidget* pButton, gpointer /*pItem*/)
gchar* pText = gtk_clipboard_wait_for_text(pClipboard); gchar* pText = gtk_clipboard_wait_for_text(pClipboard);
if (pText) 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. /// Click handler for the search next button.
......
...@@ -343,7 +343,7 @@ doSearch(LOKDocView* pDocView, const char* pText, bool bBackwards, bool highligh ...@@ -343,7 +343,7 @@ doSearch(LOKDocView* pDocView, const char* pText, bool bBackwards, bool highligh
cairo_region_get_rectangle(cairoVisRegion, 0, &cairoVisRect); cairo_region_get_rectangle(cairoVisRegion, 0, &cairoVisRect);
x = pixelToTwip (cairoVisRect.x, priv->m_fZoom); x = pixelToTwip (cairoVisRect.x, priv->m_fZoom);
y = pixelToTwip (cairoVisRect.y, 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/type", '/'), "string");
aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchString/value", '/'), pText); aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchString/value", '/'), pText);
aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/type", '/'), "boolean"); aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/type", '/'), "boolean");
...@@ -2668,6 +2668,37 @@ lok_doc_view_highlight_all (LOKDocView* pDocView, ...@@ -2668,6 +2668,37 @@ lok_doc_view_highlight_all (LOKDocView* pDocView,
doSearch(pDocView, pText, false, true); 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 SAL_DLLPUBLIC_EXPORT float
lok_doc_view_pixel_to_twip (LOKDocView* pDocView, float fInput) lok_doc_view_pixel_to_twip (LOKDocView* pDocView, float fInput)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment