From a23b44fd9f0119f7ea3523e32875f55c1a07c1cd Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Mon, 19 Jul 2021 08:11:43 +0200 Subject: tdf#123626 Allow adding hyperlinks to shapes * Support hyperlinks on Shapes in Writer * Add menu items * Add context menu items * ODF import/export + test * OOXML import/export + test Change-Id: I7269064c4cabd16fdb8259a48429c508184d3ccf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119164 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- xmloff/source/draw/shapeexport.cxx | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'xmloff/source/draw') diff --git a/xmloff/source/draw/shapeexport.cxx b/xmloff/source/draw/shapeexport.cxx index 105281b46d0c..2c757e2b2237 100644 --- a/xmloff/source/draw/shapeexport.cxx +++ b/xmloff/source/draw/shapeexport.cxx @@ -167,6 +167,7 @@ constexpr OUStringLiteral gsVerb( u"Verb" ); constexpr OUStringLiteral gsSoundURL( u"SoundURL" ); constexpr OUStringLiteral gsSpeed( u"Speed" ); constexpr OUStringLiteral gsStarBasic( u"StarBasic" ); +constexpr OUStringLiteral gsHyperlink( u"Hyperlink" ); XMLShapeExport::XMLShapeExport(SvXMLExport& rExp, SvXMLExportPropertyMapper *pExtMapper ) @@ -578,17 +579,30 @@ void XMLShapeExport::exportShape(const uno::Reference< drawing::XShape >& xShape } sal_Int32 nZIndex = 0; uno::Reference< beans::XPropertySet > xSet( xShape, uno::UNO_QUERY ); + OUString sHyperlink; + try + { + xSet->getPropertyValue(gsHyperlink) >>= sHyperlink; + } + catch (beans::UnknownPropertyException) + { + } std::unique_ptr< SvXMLElementExport > pHyperlinkElement; - // export hyperlinks with . Currently only in draw since draw - // does not support document events + // Need to stash the attributes that are pre-loaded for the shape export + // (otherwise they will become attributes of the draw:a element) + uno::Reference xSaveAttribs( + new SvXMLAttributeList(GetExport().GetAttrList())); + GetExport().ClearAttrList(); if( xSet.is() && (GetExport().GetModelType() == SvtModuleOptions::EFactory::DRAW) ) { + // export hyperlinks with . Currently only in draw since draw + // does not support document events try { presentation::ClickAction eAction = presentation::ClickAction_NONE; - xSet->getPropertyValue("OnClick") >>= eAction; + xSet->getPropertyValue(gsOnClick) >>= eAction; if( (eAction == presentation::ClickAction_DOCUMENT) || (eAction == presentation::ClickAction_BOOKMARK) ) @@ -610,6 +624,14 @@ void XMLShapeExport::exportShape(const uno::Reference< drawing::XShape >& xShape TOOLS_WARN_EXCEPTION("xmloff", "XMLShapeExport::exportShape(): exception during hyperlink export"); } } + else if (xSet.is() && !sHyperlink.isEmpty()) + { + mrExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sHyperlink ); + mrExport.AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE ); + pHyperlinkElement.reset( new SvXMLElementExport(mrExport, XML_NAMESPACE_DRAW, XML_A, true, true) ); + } + // re-add stashed attributes + GetExport().AddAttributeList(xSaveAttribs); if( xSet.is() ) xSet->getPropertyValue(gsZIndex) >>= nZIndex; -- cgit