summaryrefslogtreecommitdiff
path: root/xmloff/source/draw
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>2021-07-19 08:11:43 +0200
committerSamuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>2021-07-26 14:13:53 +0200
commita23b44fd9f0119f7ea3523e32875f55c1a07c1cd (patch)
tree2a9ffc63b7186fea9d0cfea8660d95d30a8f6684 /xmloff/source/draw
parent3c3b9ad8886da916027f0fb940a2df822d63d4d7 (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/source/draw')
-rw-r--r--xmloff/source/draw/shapeexport.cxx28
1 files changed, 25 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;