summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorTibor Nagy <nagy.tibor2@nisz.hu>2021-09-27 16:48:14 +0200
committerLászló Németh <nemeth@numbertext.org>2021-10-13 16:40:05 +0200
commit73f26b73aaf562bf934249460480b4a60937a438 (patch)
tree0542f36624ba25a7bb391ff2b55cc27ac0f5fb02 /oox
parent09c988b80976533562e68ffbfaa5e0eec690073d (diff)
tdf#124232 PPTX export: fix interactions and hyperlinks on images
Follow-up to commit 9bb91441b46d677860530d8bf9597c96561a1b0a "tdf#141704 PPTX import: fix hyperlinks on images" Change-Id: If29241ea06253e503dae27f8dc762574a5a634de Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122717 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/export/shapes.cxx88
1 files changed, 83 insertions, 5 deletions
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index dca1775112bb..1dd77a34b2ab 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -58,6 +58,10 @@
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/drawing/XDrawPages.hpp>
+#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
+#include <com/sun/star/document/XEventsSupplier.hpp>
+#include <com/sun/star/presentation/ClickAction.hpp>
#include <tools/globname.hxx>
#include <comphelper/classids.hxx>
#include <comphelper/propertysequence.hxx>
@@ -696,6 +700,32 @@ static sal_Int32 lcl_CircleAngle2CustomShapeEllipseAngleOOX(const sal_Int32 nInt
return 0;
}
+static OUString lcl_GetTarget(const css::uno::Reference<css::frame::XModel>& xModel,
+ std::u16string_view rURL)
+{
+ Reference<drawing::XDrawPagesSupplier> xDPS(xModel, uno::UNO_QUERY_THROW);
+ Reference<drawing::XDrawPages> xDrawPages(xDPS->getDrawPages(), uno::UNO_SET_THROW);
+ sal_uInt32 nPageCount = xDrawPages->getCount();
+ OUString sTarget;
+
+ for (sal_uInt32 i = 0; i < nPageCount; ++i)
+ {
+ Reference<XDrawPage> xDrawPage;
+ xDrawPages->getByIndex(i) >>= xDrawPage;
+ Reference<container::XNamed> xNamed(xDrawPage, UNO_QUERY);
+ if (!xNamed)
+ continue;
+ OUString sSlideName = "#" + xNamed->getName();
+ if (rURL == sSlideName)
+ {
+ sTarget = "slide" + OUString::number(i + 1) + ".xml";
+ break;
+ }
+ }
+
+ return sTarget;
+}
+
ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape )
{
SAL_INFO("oox.shape", "write custom shape");
@@ -1195,24 +1225,55 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape
pFS->startElementNS(mnXmlNamespace, XML_nvPicPr);
- OUString sDescr, sURL;
+ presentation::ClickAction eClickAction = presentation::ClickAction_NONE;
+ OUString sDescr, sURL, sBookmark, sPPAction;
bool bHaveDesc;
if ( ( bHaveDesc = GetProperty( xShapeProps, "Description" ) ) )
mAny >>= sDescr;
if ( GetProperty( xShapeProps, "URL" ) )
mAny >>= sURL;
+ if (GetProperty(xShapeProps, "Bookmark"))
+ mAny >>= sBookmark;
+ if (GetProperty(xShapeProps, "OnClick"))
+ mAny >>= eClickAction;
pFS->startElementNS( mnXmlNamespace, XML_cNvPr,
XML_id, OString::number(GetNewShapeID(xShape)),
XML_name, GetShapeName(xShape),
XML_descr, sax_fastparser::UseIf(sDescr, bHaveDesc));
+ if (eClickAction != presentation::ClickAction_NONE)
+ {
+ switch (eClickAction)
+ {
+ case presentation::ClickAction_STOPPRESENTATION:
+ sPPAction = "ppaction://hlinkshowjump?jump=endshow";
+ break;
+ case presentation::ClickAction_NEXTPAGE:
+ sPPAction = "ppaction://hlinkshowjump?jump=nextslide";
+ break;
+ case presentation::ClickAction_LASTPAGE:
+ sPPAction = "ppaction://hlinkshowjump?jump=lastslide";
+ break;
+ case presentation::ClickAction_PREVPAGE:
+ sPPAction = "ppaction://hlinkshowjump?jump=previousslide";
+ break;
+ case presentation::ClickAction_FIRSTPAGE:
+ sPPAction = "ppaction://hlinkshowjump?jump=firstslide";
+ break;
+ case presentation::ClickAction_BOOKMARK:
+ sBookmark = "#" + sBookmark;
+ break;
+ default:
+ break;
+ }
+ }
+
// OOXTODO: //cNvPr children: XML_extLst, XML_hlinkHover
- if (bHasMediaURL)
- pFS->singleElementNS(XML_a, XML_hlinkClick,
- FSNS(XML_r, XML_id), "",
- XML_action, "ppaction://media");
+ if (bHasMediaURL || !sPPAction.isEmpty())
+ pFS->singleElementNS(XML_a, XML_hlinkClick, FSNS(XML_r, XML_id), "", XML_action,
+ bHasMediaURL ? "ppaction://media" : sPPAction);
if( !sURL.isEmpty() )
{
OUString sRelId = mpFB->addRelation( mpFS->getOutputStream(),
@@ -1222,6 +1283,23 @@ void ShapeExport::WriteGraphicObjectShapePart( const Reference< XShape >& xShape
mpFS->singleElementNS(XML_a, XML_hlinkClick, FSNS(XML_r, XML_id), sRelId);
}
+
+ if (!sBookmark.isEmpty())
+ {
+ bool bExtURL = URLTransformer().isExternalURL(sBookmark);
+ sBookmark = bExtURL ? sBookmark : lcl_GetTarget(GetFB()->getModel(), sBookmark);
+
+ OUString sRelId = mpFB->addRelation(mpFS->getOutputStream(),
+ bExtURL ? oox::getRelationship(Relationship::HYPERLINK)
+ : oox::getRelationship(Relationship::SLIDE),
+ sBookmark, bExtURL);
+
+ if (bExtURL)
+ mpFS->singleElementNS(XML_a, XML_hlinkClick, FSNS(XML_r, XML_id), sRelId);
+ else
+ mpFS->singleElementNS(XML_a, XML_hlinkClick, FSNS(XML_r, XML_id), sRelId, XML_action,
+ "ppaction://hlinksldjump");
+ }
pFS->endElementNS(mnXmlNamespace, XML_cNvPr);
pFS->singleElementNS(mnXmlNamespace, XML_cNvPicPr