include/animations/animationnodehelper.hxx |   60 +++++++++--------------------
 1 file changed, 20 insertions(+), 40 deletions(-)

New commits:
commit e13c4edfd94b2ee1b3d3992993763670bfcab244
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Oct 2 11:43:50 2024 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Jan 3 13:16:22 2025 +0100

    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 <vmik...@collabora.com>
    Tested-by: Jenkins

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<css::uno::XInterface> getParagraphTarget(
-        const css::presentation::ParagraphTarget& pTarget)
-    {
-        try
-        {
-            css::uno::Reference<css::container::XEnumerationAccess> 
xParaEnumAccess(
-                pTarget.Shape, css::uno::UNO_QUERY_THROW);
-
-            css::uno::Reference<css::container::XEnumeration> xEnumeration(
-                                                
xParaEnumAccess->createEnumeration(),
-                                                css::uno::UNO_SET_THROW);
-            sal_Int32 nParagraph = pTarget.Paragraph;
-
-            while (xEnumeration->hasMoreElements())
-            {
-                css::uno::Reference<css::uno::XInterface> xRef(
-                    xEnumeration->nextElement(), css::uno::UNO_QUERY);
-                if (nParagraph-- == 0)
-                    return xRef;
-            }
-        }
-        catch (const css::uno::RuntimeException&)
-        {
-            SAL_WARN("animations", "getParagraphTarget");
-        }
-
-        css::uno::Reference<css::uno::XInterface> 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<css::uno::XInterface> xRef;
-        if (!(rTarget >>= xRef))
+        if (auto xParagraphTarget = 
o3tl::tryAccess<css::presentation::ParagraphTarget>(rTarget))
         {
-            if (auto pt = 
o3tl::tryAccess<css::presentation::ParagraphTarget>(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);
+            }
         }
     }
 }

Reply via email to