diff options
author | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2021-07-19 08:11:43 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2021-07-26 14:13:53 +0200 |
commit | a23b44fd9f0119f7ea3523e32875f55c1a07c1cd (patch) | |
tree | 2a9ffc63b7186fea9d0cfea8660d95d30a8f6684 /xmloff | |
parent | 3c3b9ad8886da916027f0fb940a2df822d63d4d7 (diff) |
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 <samuel.mehrbrodt@allotropia.de>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/draw/shapeexport.cxx | 28 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextFrameContext.cxx | 4 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextFrameHyperlinkContext.cxx | 12 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextFrameHyperlinkContext.hxx | 1 |
4 files changed, 42 insertions, 3 deletions
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 <a><shape/></a>. 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<xml::sax::XAttributeList> xSaveAttribs( + new SvXMLAttributeList(GetExport().GetAttrList())); + GetExport().ClearAttrList(); if( xSet.is() && (GetExport().GetModelType() == SvtModuleOptions::EFactory::DRAW) ) { + // export hyperlinks with <a><shape/></a>. 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; diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx index 39bbf597f9a5..a4f8cb636ca1 100644 --- a/xmloff/source/text/XMLTextFrameContext.cxx +++ b/xmloff/source/text/XMLTextFrameContext.cxx @@ -1648,6 +1648,10 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextFrameContext::c } xContext = &dynamic_cast<SvXMLImportContext&>(*m_xImplContext->createFastChildContext(nElement, xAttrList)); } + else if (nElement == XML_ELEMENT(DRAW, XML_A)) + { + xContext = &dynamic_cast<SvXMLImportContext&>(*m_xImplContext->createFastChildContext(nElement, xAttrList)); + } else { // the child is a drawing shape diff --git a/xmloff/source/text/XMLTextFrameHyperlinkContext.cxx b/xmloff/source/text/XMLTextFrameHyperlinkContext.cxx index 240d9776b519..f3bf9c66665e 100644 --- a/xmloff/source/text/XMLTextFrameHyperlinkContext.cxx +++ b/xmloff/source/text/XMLTextFrameHyperlinkContext.cxx @@ -20,6 +20,7 @@ #include <sal/log.hxx> #include <sax/tools/converter.hxx> +#include <xmloff/shapeimport.hxx> #include <xmloff/xmlimp.hxx> #include <xmloff/namespacemap.hxx> #include <xmloff/xmlnamespace.hxx> @@ -27,6 +28,9 @@ #include "XMLTextFrameContext.hxx" #include "XMLTextFrameHyperlinkContext.hxx" +#include <com/sun/star/drawing/XShapes.hpp> + +using namespace ::com::sun::star::drawing; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::text; using namespace ::com::sun::star::xml::sax; @@ -106,6 +110,14 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextFrameHyperlinkC pContext = pTextFrameContext; xFrameContext = pContext; } + if (nElement == XML_ELEMENT(DRAW, XML_CUSTOM_SHAPE)) + { + Reference<XShapes> xShapes; + SvXMLShapeContext* pShapeContext + = XMLShapeImportHelper::CreateGroupChildContext(GetImport(), nElement, xAttrList, xShapes); + pShapeContext->setHyperlink(sHRef); + pContext = pShapeContext; + } if (!pContext) XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); diff --git a/xmloff/source/text/XMLTextFrameHyperlinkContext.hxx b/xmloff/source/text/XMLTextFrameHyperlinkContext.hxx index 3b178bb6f835..a76081632a9f 100644 --- a/xmloff/source/text/XMLTextFrameHyperlinkContext.hxx +++ b/xmloff/source/text/XMLTextFrameHyperlinkContext.hxx @@ -29,6 +29,7 @@ namespace com::sun::star { namespace beans { class XPropertySet; } } +/// Used for hyperlinks attached to objects (drawing objects, text boxes, Writer frames) class XMLTextFrameHyperlinkContext : public SvXMLImportContext { OUString sHRef; |