diff options
author | Bayram Çiçek <bayram.cicek@collabora.com> | 2024-07-18 16:31:46 +0300 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-08-16 17:04:59 +0200 |
commit | f91d74da5571b877126f4f753c4134054fa606bb (patch) | |
tree | 50fed887ec85fb762404e730bc76b312faf37ea3 | |
parent | ef25059c74b7fd756548da07aec68a71f235b12a (diff) |
tdf#158857: [Power Query] export xl/drawings/drawing*.xml
xl/drawings/drawing*.xml:
- import&export "macro", "textlink", "fLocksText" and "fPublished" attribute of <sp> element (using GrabBag).
- import&export "descr" and "title" attributes of <cNvPr>
- import "r:id", "invalidUrl", "action", "tgtFrame", "tooltip", "history", "highlightClick", "endSnd" attributes of <hlinkClick>
Signed-off-by: Bayram Çiçek <bayram.cicek@collabora.com>
Change-Id: Idd865fc86c3538107e4c9808b0886733c798b01f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170691
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
-rw-r--r-- | include/oox/drawingml/shape.hxx | 31 | ||||
-rw-r--r-- | oox/source/drawingml/hyperlinkcontext.cxx | 28 | ||||
-rw-r--r-- | oox/source/drawingml/shape.cxx | 26 | ||||
-rw-r--r-- | oox/source/drawingml/shapecontext.cxx | 1 | ||||
-rw-r--r-- | oox/source/export/shapes.cxx | 88 | ||||
-rw-r--r-- | oox/source/token/properties.txt | 4 | ||||
-rw-r--r-- | sc/source/filter/oox/drawingfragment.cxx | 6 | ||||
-rw-r--r-- | sc/source/filter/xcl97/xcl97rec.cxx | 1 |
8 files changed, 176 insertions, 9 deletions
diff --git a/include/oox/drawingml/shape.hxx b/include/oox/drawingml/shape.hxx index dbde9abd4bc7..81797757faaf 100644 --- a/include/oox/drawingml/shape.hxx +++ b/include/oox/drawingml/shape.hxx @@ -175,6 +175,11 @@ public: const OUString& getId() const { return msId; } void setDescription( const OUString& rDescr ) { msDescription = rDescr; } void setDecorative(bool const isDecorative) { m_isDecorative = isDecorative; } + void setMacro(const OUString& rMacro) { msMacro = rMacro; } + void setTextLinkAttr(const OUString& rTextLink) { msTextLink = rTextLink; } + void setFLocksText(bool bFLocksText) { mbFLocksText = bFLocksText; } + void setFPublished(bool bFPublished) { mbFPublished = bFPublished; } + void setTitle(const OUString& rTitle) { msTitle = rTitle; } void setHidden( bool bHidden ) { mbHidden = bHidden; } void setHiddenMasterShape( bool bHiddenMasterShape ) { mbHiddenMasterShape = bHiddenMasterShape; } void setLocked( bool bLocked ) { mbLocked = bLocked; } @@ -362,7 +367,33 @@ protected: OUString msInternalName; // used by diagram; not displayed in UI OUString msId; OUString msDescription; + OUString msTitle; bool m_isDecorative = false; + + /* <sp> (Shape) : This element specifies the existence of a single shape. + + Attributes: + - macro (Reference to Custom Function) + - textlink (Text Link) + - fLocksText (Lock Text Flag) + - fPublished (Publish to Server Flag) + + <sp> element can exist as a namespace format like <xdr:sp>, <cdr:sp> etc... + */ + + /* specifies the custom function associated with the object. + "macro" attribute for <sp> element */ + OUString msMacro; + /* specifies a formula linking to spreadsheet cell data. + "textlink" attribute for <sp> element */ + OUString msTextLink; + /* indicates whether to allow text editing within this drawing object when the parent worksheet is protected. + "fLocksText" attribute for <sp> element */ + bool mbFLocksText = true; // default="true" + /* indicates whether the shape shall be published with the worksheet when sent to the server. + "fPublished" attribute for <sp> element */ + bool mbFPublished = false; + sal_Int32 mnSubType; // if this type is not zero, then the shape is a placeholder std::optional< sal_Int32 > moSubTypeIndex; diff --git a/oox/source/drawingml/hyperlinkcontext.cxx b/oox/source/drawingml/hyperlinkcontext.cxx index 320f169e8e13..692ad0f7d8db 100644 --- a/oox/source/drawingml/hyperlinkcontext.cxx +++ b/oox/source/drawingml/hyperlinkcontext.cxx @@ -56,12 +56,14 @@ HyperLinkContext::HyperLinkContext( ContextHandler2Helper const & rParent, sURL = getRelations().getInternalTargetFromRelId( aRelId ); } } - OUString sTooltip = rAttribs.getStringDefaulted( R_TOKEN( tooltip ) ); + OUString sTooltip = rAttribs.getStringDefaulted( XML_tooltip ); if ( !sTooltip.isEmpty() ) maProperties.setProperty(PROP_Representation, sTooltip); - OUString sFrame = rAttribs.getStringDefaulted( R_TOKEN( tgtFrame ) ); + + OUString sFrame = rAttribs.getStringDefaulted( XML_tgtFrame ); if( !sFrame.isEmpty() ) maProperties.setProperty(PROP_TargetFrame, sFrame); + OUString aAction = rAttribs.getStringDefaulted( XML_action ); if ( !aAction.isEmpty() ) { @@ -130,15 +132,27 @@ HyperLinkContext::HyperLinkContext( ContextHandler2Helper const & rParent, } } } + maProperties.setProperty(PROP_Action, aAction); } + if ( !sURL.isEmpty() ) maProperties.setProperty(PROP_URL, sURL); - // TODO unhandled - // XML_invalidUrl - // XML_history - // XML_highlightClick - // XML_endSnd + OUString sInvalidUrl = rAttribs.getStringDefaulted(XML_invalidUrl); + if (!sInvalidUrl.isEmpty()) + maProperties.setProperty(PROP_InvalidUrl, sInvalidUrl); + + bool bHistory = rAttribs.getBool(XML_history, true); // default="true" + if (!bHistory) // set only if it is false + maProperties.setProperty(PROP_History, bHistory); + + bool bHighlightClick = rAttribs.getBool(XML_highlightClick, false); + if (bHighlightClick) + maProperties.setProperty(PROP_HighlightClick, bHighlightClick); + + bool bEndSnd = rAttribs.getBool(XML_endSnd, false); + if (bEndSnd) + maProperties.setProperty(PROP_EndSnd, bEndSnd); } HyperLinkContext::~HyperLinkContext() diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index 496714ec1e1a..e3c08581f624 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -1278,6 +1278,32 @@ Reference< XShape > const & Shape::createAndInsert( { xSet->setPropertyValue(u"Decorative"_ustr, Any(m_isDecorative)); } + if (!msMacro.isEmpty()) + { + putPropertyToGrabBag(u"mso-sp-macro"_ustr, Any(msMacro)); + } + if (!msTextLink.isEmpty()) + { + putPropertyToGrabBag(u"mso-sp-textlink"_ustr, Any(msTextLink)); + } + if (!mbFLocksText) // set only if "false", otherwise it will use "true" by default + { + putPropertyToGrabBag(u"mso-sp-fLocksText"_ustr, Any(mbFLocksText)); + } + if (mbFPublished) + { + putPropertyToGrabBag(u"mso-sp-fPublished"_ustr, Any(mbFPublished)); + } + if (!msTitle.isEmpty()) + { + xSet->setPropertyValue(u"Title"_ustr, Any(msTitle)); + } + + // get tooltip attribute of <hlinkClick> + OUString sTooltip; + getShapeProperties().getProperty(PROP_Representation) >>= sTooltip; + if (!sTooltip.isEmpty()) + putPropertyToGrabBag(u"mso-hlinkClick-tooltip"_ustr, Any(sTooltip)); // Placeholder uses the height set on the slide instead of the height from the master slide, // if it has the "TextAutoGrowHeight" property diff --git a/oox/source/drawingml/shapecontext.cxx b/oox/source/drawingml/shapecontext.cxx index f7bdc9b1c815..1cd22c7cd422 100644 --- a/oox/source/drawingml/shapecontext.cxx +++ b/oox/source/drawingml/shapecontext.cxx @@ -76,6 +76,7 @@ ContextHandlerRef ShapeContext::onCreateContext( sal_Int32 aElementToken, const mpShapePtr->setId( rAttribs.getStringDefaulted( XML_id ) ); mpShapePtr->setName( rAttribs.getStringDefaulted( XML_name ) ); mpShapePtr->setDescription( rAttribs.getStringDefaulted( XML_descr ) ); + mpShapePtr->setTitle(rAttribs.getStringDefaulted(XML_title)); break; } case XML_hlinkMouseOver: diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index e948a352de73..f614b1e003e7 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -90,6 +90,7 @@ #include <frozen/set.h> #include <frozen/unordered_map.h> +#include <sax/fastattribs.hxx> using namespace ::css; using namespace ::css::beans; @@ -840,13 +841,62 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape ) // non visual shape properties if (GetDocumentType() != DOCUMENT_DOCX || mbUserShapes) { + // get InteropGrabBag to export attributes stored in the grabbag + uno::Sequence<beans::PropertyValue> aGrabBagProps; + rXPropSet->getPropertyValue(u"InteropGrabBag"_ustr) >>= aGrabBagProps; + bool bUseBackground = false; if (GetProperty(rXPropSet, u"FillUseSlideBackground"_ustr)) mAny >>= bUseBackground; if (bUseBackground) mpFS->startElementNS(mnXmlNamespace, XML_sp, XML_useBgFill, "1"); else - mpFS->startElementNS(mnXmlNamespace, XML_sp); + { + rtl::Reference<sax_fastparser::FastAttributeList> pAttrListSp + = sax_fastparser::FastSerializerHelper::createAttrList(); + + for (auto const& it : aGrabBagProps) + { + // export macro attribute of <sp> element + if (it.Name == u"mso-sp-macro"_ustr) + { + OUString sMacro; + it.Value >>= sMacro; + + if (!sMacro.isEmpty()) + pAttrListSp->add(XML_macro, sMacro); + } + + // export textlink attribute of <sp> element + if (it.Name == u"mso-sp-textlink"_ustr) + { + OUString sTextLink; + it.Value >>= sTextLink; + + if (!sTextLink.isEmpty()) + pAttrListSp->add(XML_textlink, sTextLink); + } + + // export fLocksText attribute of <sp> element + if (it.Name == u"mso-sp-fLocksText"_ustr) + { + bool bFLocksText = true; // default="true" + it.Value >>= bFLocksText; + pAttrListSp->add(XML_fLocksText, ToPsz10(bFLocksText)); + } + + // export fPublished attribute of <sp> element + if (it.Name == u"mso-sp-fPublished"_ustr) + { + bool bFPublished = false; + it.Value >>= bFPublished; + pAttrListSp->add(XML_fPublished, ToPsz10(bFPublished)); + } + } + + // export <sp> element (with a namespace prefix) + mpFS->startElementNS(mnXmlNamespace, XML_sp, pAttrListSp); + } bool isVisible = true ; if( GetProperty(rXPropSet, u"Visible"_ustr)) @@ -854,10 +904,40 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape ) mAny >>= isVisible; } pFS->startElementNS( mnXmlNamespace, XML_nvSpPr ); + + // export descr attribute of <cNvPr> element + OUString sDescr; + if (GetProperty(rXPropSet, u"Description"_ustr)) + mAny >>= sDescr; + + // export title attribute of <cNvPr> element + OUString sTitle; + if (GetProperty(rXPropSet, u"Title"_ustr)) + mAny >>= sTitle; + + // export <cNvPr> element pFS->startElementNS( mnXmlNamespace, XML_cNvPr, XML_id, OString::number(GetShapeID(xShape) == -1 ? GetNewShapeID(xShape) : GetShapeID(xShape)), - XML_name, GetShapeName(xShape), XML_hidden, sax_fastparser::UseIf("1", !isVisible)); + XML_name, GetShapeName(xShape), XML_hidden, sax_fastparser::UseIf("1", !isVisible), + XML_descr, sax_fastparser::UseIf(sDescr, !sDescr.isEmpty()), XML_title, + sax_fastparser::UseIf(sTitle, !sTitle.isEmpty())); + + rtl::Reference<sax_fastparser::FastAttributeList> pAttrListHlinkClick + = sax_fastparser::FastSerializerHelper::createAttrList(); + + for (auto const& it : aGrabBagProps) + { + // export tooltip attribute of <hlinkClick> element + if (it.Name == u"mso-hlinkClick-tooltip"_ustr) + { + OUString sTooltip; + it.Value >>= sTooltip; + + if (!sTooltip.isEmpty()) + pAttrListHlinkClick->add(XML_tooltip, sTooltip); + } + } if( GetProperty(rXPropSet, u"URL"_ustr) ) { @@ -871,9 +951,13 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape ) mpURLTransformer->isExternalURL(sURL)); mpFS->singleElementNS(XML_a, XML_hlinkClick, FSNS(XML_r, XML_id), sRelId); + // pAttrListHlinkClick->add(FSNS(XML_r, XML_id), sRelId); } } + // // export <hlinkClick> element + // mpFS->singleElementNS(XML_a, XML_hlinkClick, pAttrListHlinkClick); + OUString sBookmark; if (GetProperty(rXPropSet, u"Bookmark"_ustr)) mAny >>= sBookmark; diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt index fd78234fbd0e..f68726957df9 100644 --- a/oox/source/token/properties.txt +++ b/oox/source/token/properties.txt @@ -158,6 +158,7 @@ EchoChar EnableVisible Enabled EndPosition +EndSnd Equations ErrorAlertStyle ErrorBarStyle @@ -269,6 +270,8 @@ HeaderIsShared Height HelpText HideInactiveSelection +HighlightClick +History HoriJustify HoriJustifyMethod HoriOrient @@ -286,6 +289,7 @@ IncludeHiddenCells InputMessage InputTitle InterceptValue +InvalidUrl IsActive IsAdjustHeightEnabled IsCaseSensitive diff --git a/sc/source/filter/oox/drawingfragment.cxx b/sc/source/filter/oox/drawingfragment.cxx index 785ff7012dc6..85e809b55591 100644 --- a/sc/source/filter/oox/drawingfragment.cxx +++ b/sc/source/filter/oox/drawingfragment.cxx @@ -136,6 +136,12 @@ GroupShapeContext::GroupShapeContext( const FragmentHandler2& rParent, { ShapePtr xShape = std::make_shared<Shape>( rHelper, rAttribs, u"com.sun.star.drawing.CustomShape"_ustr ); if( pxShape ) *pxShape = xShape; + + xShape->setMacro(rAttribs.getXString(XML_macro, OUString())); + xShape->setTextLinkAttr(rAttribs.getXString(XML_textlink, OUString())); + xShape->setFLocksText(rAttribs.getBool(XML_fLocksText, true)); // default="true" + xShape->setFPublished(rAttribs.getBool(XML_fPublished, false)); // default="false" + return new ShapeContext( rParent, rxParentShape, std::move(xShape) ); } case XDR_TOKEN( cxnSp ): diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx index 8f166bcb6f27..76b47c43bf10 100644 --- a/sc/source/filter/xcl97/xcl97rec.cxx +++ b/sc/source/filter/xcl97/xcl97rec.cxx @@ -260,6 +260,7 @@ void SaveDrawingMLObjects( XclExpObjList& rList, XclExpXmlStream& rStrm ) sal_Int32 nDrawing = drawingml::DrawingML::getNewDrawingUniqueId(); OUString sId; + // export in [Content_Types].xml sax_fastparser::FSHelperPtr pDrawing = rStrm.CreateOutputStream( XclXmlUtils::GetStreamName( "xl/", "drawings/drawing", nDrawing ), XclXmlUtils::GetStreamName( "../", "drawings/drawing", nDrawing ), |