diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-05-23 08:39:34 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-05-23 18:04:09 +0200 |
commit | 9a76be53dfb801b754bf55f9d4b8c5f82991a62f (patch) | |
tree | 89ead80b7d75d8d598f311c961678a23277177d5 /libreofficekit | |
parent | 95c55b40f7670984ba39447bd695c78ac7d6df1f (diff) |
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 <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'libreofficekit')
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 27 |
1 files changed, 25 insertions, 2 deletions
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<std::string>("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)); |