diff options
author | Tibor Nagy <nagy.tibor2@nisz.hu> | 2021-08-31 13:15:01 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-09-14 15:23:27 +0200 |
commit | 9bb91441b46d677860530d8bf9597c96561a1b0a (patch) | |
tree | 11933133dfac527d1a77adad04997c8bbcfbdeb8 /oox | |
parent | 431c8411b446528ba45ac76e8c39726ff4c0a4df (diff) |
tdf#141704 PPTX import: fix hyperlinks on images
Hyperlinks on images pointing to the "first/last/
previous/next" slides and "exit presentation/go to
the website/go to the slide" weren't imported.
Note: images added via the Content placeholder
will be fixed later.
Change-Id: Idda1ff6fd3243b06262637c7c8e579e78309e317
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121369
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/ppt/pptshape.cxx | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx index 80f165d6f085..757aab1bb3e0 100644 --- a/oox/source/ppt/pptshape.cxx +++ b/oox/source/ppt/pptshape.cxx @@ -34,10 +34,14 @@ #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> #include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/text/XText.hpp> +#include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/container/XNameReplace.hpp> +#include <com/sun/star/presentation/ClickAction.hpp> #include <basegfx/matrix/b2dhommatrix.hxx> #include <sal/log.hxx> #include <oox/ppt/slidepersist.hxx> #include <oox/token/tokens.hxx> +#include <oox/token/properties.hxx> using namespace ::oox::core; using namespace ::oox::drawingml; @@ -47,6 +51,9 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::text; using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::presentation; namespace oox::ppt { @@ -531,6 +538,79 @@ void PPTShape::addShape( keepDiagramCompatibilityInfo(); syncDiagramFontHeights(); } + + if (getShapeProperties().hasProperty(PROP_URL)) + { + Reference<XEventsSupplier> xEventsSupplier(xShape, UNO_QUERY); + if (!xEventsSupplier.is()) + return; + + Reference<XNameReplace> xEvents(xEventsSupplier->getEvents()); + if (!xEvents.is()) + return; + + OUString sURL; + OUString sAPIEventName; + sal_Int32 nPropertyCount = 2; + css::presentation::ClickAction meClickAction; + uno::Sequence<beans::PropertyValue> aProperties; + + std::map<OUString, css::presentation::ClickAction> ActionMap = { + { "#action?jump=nextslide", ClickAction_NEXTPAGE }, + { "#action?jump=previousslide", ClickAction_PREVPAGE }, + { "#action?jump=firstslide", ClickAction_FIRSTPAGE }, + { "#action?jump=lastslide", ClickAction_LASTPAGE }, + { "#action?jump=endshow", ClickAction_STOPPRESENTATION }, + }; + + getShapeProperties().getProperty(PROP_URL) >>= sURL; + std::map<OUString, css::presentation::ClickAction>::const_iterator aIt + = ActionMap.find(sURL); + aIt != ActionMap.end() ? meClickAction = aIt->second + : meClickAction = ClickAction_BOOKMARK; + + // ClickAction_BOOKMARK and ClickAction_DOCUMENT share the same event + // so check here if it's a bookmark or a document + if (meClickAction == ClickAction_BOOKMARK) + { + if (!sURL.startsWith("#")) + meClickAction = ClickAction_DOCUMENT; + else + sURL = sURL.copy(1); + nPropertyCount += 1; + } + + aProperties.realloc(nPropertyCount); + beans::PropertyValue* pProperties = aProperties.getArray(); + + pProperties->Name = "EventType"; + pProperties->Handle = -1; + pProperties->Value <<= OUString("Presentation"); + pProperties->State = beans::PropertyState_DIRECT_VALUE; + pProperties++; + + pProperties->Name = "ClickAction"; + pProperties->Handle = -1; + pProperties->Value <<= meClickAction; + pProperties->State = beans::PropertyState_DIRECT_VALUE; + pProperties++; + + switch (meClickAction) + { + case ClickAction_BOOKMARK: + case ClickAction_DOCUMENT: + pProperties->Name = "Bookmark"; + pProperties->Handle = -1; + pProperties->Value <<= sURL; + pProperties->State = beans::PropertyState_DIRECT_VALUE; + break; + default: + break; + } + + sAPIEventName = "OnClick"; + xEvents->replaceByName(sAPIEventName, uno::Any(aProperties)); + } } } catch (const Exception&) |