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 /sw | |
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 'sw')
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 56 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/wrtsh3.cxx | 18 |
2 files changed, 54 insertions, 20 deletions
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 7f3079c5cf05..57998981f02e 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -117,6 +117,7 @@ #include <comphelper/propertyvalue.hxx> #include <comphelper/storagehelper.hxx> #include <cppuhelper/supportsservice.hxx> +#include <sfx2/dispatch.hxx> #include <swruler.hxx> #include <docufld.hxx> @@ -3360,24 +3361,6 @@ SwXTextDocument::getSearchResultRectangles(const char* pPayload) void SwXTextDocument::executeContentControlEvent(const StringMap& rArguments) { - SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell(); - const SwPosition* pStart = pWrtShell->GetCursor()->Start(); - SwTextNode* pTextNode = pStart->nNode.GetNode().GetTextNode(); - if (!pTextNode) - { - return; - } - - SwTextAttr* pAttr = pTextNode->GetTextAttrAt(pStart->nContent.GetIndex(), - RES_TXTATR_CONTENTCONTROL, SwTextNode::PARENT); - if (!pAttr) - { - return; - } - - auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); - const SwFormatContentControl& rFormatContentControl = pTextContentControl->GetContentControl(); - std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl(); auto it = rArguments.find("type"); if (it == rArguments.end()) { @@ -3386,6 +3369,24 @@ void SwXTextDocument::executeContentControlEvent(const StringMap& rArguments) if (it->second == "drop-down") { + SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell(); + const SwPosition* pStart = pWrtShell->GetCursor()->Start(); + SwTextNode* pTextNode = pStart->nNode.GetNode().GetTextNode(); + if (!pTextNode) + { + return; + } + + SwTextAttr* pAttr = pTextNode->GetTextAttrAt(pStart->nContent.GetIndex(), + RES_TXTATR_CONTENTCONTROL, SwTextNode::PARENT); + if (!pAttr) + { + return; + } + + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + const SwFormatContentControl& rFormatContentControl = pTextContentControl->GetContentControl(); + std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl(); if (!pContentControl->HasListItems()) { return; @@ -3401,6 +3402,25 @@ void SwXTextDocument::executeContentControlEvent(const StringMap& rArguments) pContentControl->SetSelectedListItem(nSelection); pWrtShell->GotoContentControl(rFormatContentControl); } + else if (it->second == "picture") + { + it = rArguments.find("changed"); + if (it == rArguments.end()) + { + return; + } + + SwView* pView = m_pDocShell->GetView(); + if (!pView) + { + return; + } + + // The current placeholder is selected, so this will replace, not insert. + SfxStringItem aItem(SID_INSERT_GRAPHIC, it->second); + pView->GetViewFrame()->GetDispatcher()->ExecuteList(SID_INSERT_GRAPHIC, + SfxCallMode::SYNCHRON, { &aItem }); + } } int SwXTextDocument::getPart() diff --git a/sw/source/uibase/wrtsh/wrtsh3.cxx b/sw/source/uibase/wrtsh/wrtsh3.cxx index 978f95397b52..fcb123662bcf 100644 --- a/sw/source/uibase/wrtsh/wrtsh3.cxx +++ b/sw/source/uibase/wrtsh/wrtsh3.cxx @@ -29,6 +29,9 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <osl/diagnose.h> #include <sfx2/dispatch.hxx> +#include <comphelper/lok.hxx> +#include <tools/json_writer.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <swmodule.hxx> #include <wrtsh.hxx> @@ -100,8 +103,19 @@ bool SwWrtShell::GotoContentControl(const SwFormatContentControl& rContentContro { // Replace the placeholder image with a real one. GetView().StopShellTimer(); - GetView().GetViewFrame()->GetDispatcher()->Execute(SID_CHANGE_PICTURE, - SfxCallMode::SYNCHRON); + if (comphelper::LibreOfficeKit::isActive()) + { + tools::JsonWriter aJson; + aJson.put("action", "change-picture"); + std::unique_ptr<char, o3tl::free_delete> pJson(aJson.extractData()); + GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CONTENT_CONTROL, + pJson.get()); + } + else + { + GetView().GetViewFrame()->GetDispatcher()->Execute(SID_CHANGE_PICTURE, + SfxCallMode::SYNCHRON); + } pContentControl->SetShowingPlaceHolder(false); } return true; |