From 9a76be53dfb801b754bf55f9d4b8c5f82991a62f Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 23 May 2022 08:39:34 +0200 Subject: sw content controls, picture: add LOK API - send a LOK_CALLBACK_CONTENT_CONTROL callback with action=change-picture when a file picker should be shown - extend lok::Document::sendContentControlEvent() to be able to replace the placeholder with the selected URL - update gtktiledviewer to work with these Change-Id: Ifb3750803885fc09fc82905b0cf85b2b8ca06e77 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134750 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- libreofficekit/source/gtk/lokdocview.cxx | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'libreofficekit') diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index aafaa084be9c..39f2281b0c7d 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -1397,9 +1397,9 @@ callback (gpointer pData) case LOK_CALLBACK_CONTENT_CONTROL: { - std::stringstream aStream(pCallback->m_aPayload); + std::stringstream aPayloadStream(pCallback->m_aPayload); boost::property_tree::ptree aTree; - boost::property_tree::read_json(aStream, aTree); + boost::property_tree::read_json(aPayloadStream, aTree); auto aAction = aTree.get("action"); if (aAction == "show") { @@ -1410,6 +1410,29 @@ callback (gpointer pData) { priv->m_aContentControlRectangles.clear(); } + else if (aAction == "change-picture") + { + GtkWidget* pDialog = gtk_file_chooser_dialog_new( + "Open File", GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))), + GTK_FILE_CHOOSER_ACTION_OPEN, "Cancel", GTK_RESPONSE_CANCEL, "Open", + GTK_RESPONSE_ACCEPT, nullptr); + gint nRet = gtk_dialog_run(GTK_DIALOG(pDialog)); + if (nRet == GTK_RESPONSE_ACCEPT) + { + GtkFileChooser* pChooser = GTK_FILE_CHOOSER(pDialog); + char* pFilename = gtk_file_chooser_get_uri(pChooser); + boost::property_tree::ptree aValues; + aValues.put("type", "picture"); + aValues.put("changed", pFilename); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aValues); + std::string aJson = aStream.str(); + lok_doc_view_send_content_control_event(pDocView, aJson.c_str()); + + g_free(pFilename); + } + gtk_widget_destroy(pDialog); + } g_signal_emit(pCallback->m_pDocView, doc_view_signals[CONTENT_CONTROL], 0, pCallback->m_aPayload.c_str()); gtk_widget_queue_draw(GTK_WIDGET(pDocView)); -- cgit