From e13c4edfd94b2ee1b3d3992993763670bfcab244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Vajngerl?= Date: Wed, 2 Oct 2024 11:43:50 +0200 Subject: [PATCH] slideshow: Fix "calculating" the hash for the object's paragraphs Using the createEnumeration on the UNO object and finding the UNO object that representing the paragraph, and using that pointer as a unique identifier has doesn't work reliably. The reason for this is probably that the createEnumeration call creates new UNO objects that represent the paragraph, so the pointers change all the time. This changes the "calculation" of the paragraphs so that the hash is actually combined using the hash of the object (which is always of the XShape type and the hash is consistent with those) and the paragraph index. This works well for the slideshow where we don't edit the objects, but it can be a problem in the future if we will allow editing. Change-Id: I6dc9486a1e5d7c4ceb3d609613b60603886063c8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179698 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- include/animations/animationnodehelper.hxx | 60 ++++++++-------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/include/animations/animationnodehelper.hxx b/include/animations/animationnodehelper.hxx index 11ac2abd4ef8..f47048cbd7ef 100644 --- a/include/animations/animationnodehelper.hxx +++ b/include/animations/animationnodehelper.hxx @@ -121,56 +121,36 @@ namespace anim return false; } - inline css::uno::Reference getParagraphTarget( - const css::presentation::ParagraphTarget& pTarget) - { - try - { - css::uno::Reference xParaEnumAccess( - pTarget.Shape, css::uno::UNO_QUERY_THROW); - - css::uno::Reference xEnumeration( - xParaEnumAccess->createEnumeration(), - css::uno::UNO_SET_THROW); - sal_Int32 nParagraph = pTarget.Paragraph; - - while (xEnumeration->hasMoreElements()) - { - css::uno::Reference xRef( - xEnumeration->nextElement(), css::uno::UNO_QUERY); - if (nParagraph-- == 0) - return xRef; - } - } - catch (const css::uno::RuntimeException&) - { - SAL_WARN("animations", "getParagraphTarget"); - } - - css::uno::Reference xRef; - return xRef; - } - - inline void convertTarget(OStringBuffer& sTmp, const css::uno::Any& rTarget) + inline void convertTarget(OStringBuffer& aStringBuffer, const css::uno::Any& rTarget) { if (!rTarget.hasValue()) return; css::uno::Reference xRef; - if (!(rTarget >>= xRef)) + if (auto xParagraphTarget = o3tl::tryAccess(rTarget)) { - if (auto pt = o3tl::tryAccess(rTarget)) + if (xParagraphTarget->Shape.is()) { - xRef = getParagraphTarget(*pt); + const std::string aIdentifier(GetInterfaceHash(xParagraphTarget->Shape)); + if (!aIdentifier.empty()) + { + sal_Int32 nParagraph(xParagraphTarget->Paragraph); + aStringBuffer.append(aIdentifier); + aStringBuffer.append("_"); + aStringBuffer.append(nParagraph); + } } } - - SAL_WARN_IF(!xRef.is(), "animations", "convertTarget(), invalid target type!"); - if (xRef.is()) + else { - const std::string aIdentifier(GetInterfaceHash(xRef)); - if (!aIdentifier.empty()) - sTmp.append(aIdentifier); + rTarget >>= xRef; + SAL_WARN_IF(!xRef.is(), "animations", "convertTarget(), invalid target type!"); + if (xRef.is()) + { + const std::string aIdentifier(GetInterfaceHash(xRef)); + if (!aIdentifier.empty()) + aStringBuffer.append(aIdentifier); + } } } }