From 378e8396223a80b96262d7b638a066eb83ba88d6 Mon Sep 17 00:00:00 2001 From: Tibor Nagy Date: Wed, 6 Oct 2021 09:31:37 +0200 Subject: tdf#144917 PPTX import: fix hyperlinks on grouped shapes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hyperlinks on the shapes of a group shape weren't imported. Now all of them are imported correctly. Change-Id: Ic42892650a3492958600232bd7038585f9aa6ae1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123127 Tested-by: László Németh Reviewed-by: László Németh --- oox/source/ppt/pptshape.cxx | 143 +++++++++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 63 deletions(-) (limited to 'oox') diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx index bbc7d2585fd8..2a134ada4a0c 100644 --- a/oox/source/ppt/pptshape.cxx +++ b/oox/source/ppt/pptshape.cxx @@ -518,6 +518,8 @@ void PPTShape::addShape( } } + OUString sURL; + std::vector>> aURLShapes; // if this is a group shape, we have to add also each child shape Reference xShapes(xShape, UNO_QUERY); if (xShapes.is()) @@ -531,6 +533,15 @@ void PPTShape::addShape( { rFilterBase.setDiagramFontHeights(nullptr); } + for (size_t i = 0; i < this->getChildren().size(); i++) + { + this->getChildren()[i]->getShapeProperties().getProperty(PROP_URL) >>= sURL; + if (!sURL.isEmpty()) + { + Reference xChild = this->getChildren()[i]->getXShape(); + aURLShapes.push_back({ sURL, xChild }); + } + } } if (meFrameType == FRAMETYPE_DIAGRAM) @@ -539,77 +550,83 @@ void PPTShape::addShape( syncDiagramFontHeights(); } - OUString sURL; getShapeProperties().getProperty(PROP_URL) >>= sURL; - if (!sURL.isEmpty()) + if (!sURL.isEmpty() && !xShapes.is()) + aURLShapes.push_back({ sURL, xShape }); + + if (!aURLShapes.empty()) { - Reference xEventsSupplier(xShape, UNO_QUERY); - if (!xEventsSupplier.is()) - return; - - Reference xEvents(xEventsSupplier->getEvents()); - if (!xEvents.is()) - return; - - OUString sAPIEventName; - sal_Int32 nPropertyCount = 2; - css::presentation::ClickAction meClickAction; - uno::Sequence aProperties; - - std::map 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 }, - }; - - std::map::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) + for (auto const& URLShape : aURLShapes) { - if (!sURL.startsWith("#")) - meClickAction = ClickAction_DOCUMENT; - else - sURL = sURL.copy(1); - nPropertyCount += 1; - } + Reference xEventsSupplier(URLShape.second, UNO_QUERY); + if (!xEventsSupplier.is()) + return; + + Reference xEvents(xEventsSupplier->getEvents()); + if (!xEvents.is()) + return; + + OUString sAPIEventName; + sal_Int32 nPropertyCount = 2; + css::presentation::ClickAction meClickAction; + uno::Sequence aProperties; + + std::map 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 }, + }; + + sURL = URLShape.first; + std::map::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(); + 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 = "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++; + 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; - } + 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)); + sAPIEventName = "OnClick"; + xEvents->replaceByName(sAPIEventName, uno::Any(aProperties)); + } } } } -- cgit