sd/source/ui/tools/SlideshowLayerRenderer.cxx |    8 ++
 sd/source/ui/unoidl/unomodel.cxx              |   88 ++++++++++++++++++++++++--
 2 files changed, 91 insertions(+), 5 deletions(-)

New commits:
commit 7ff354575462a072f791fe6331a94ec54d742c79
Author:     Marco Cecchetti <marco.cecche...@collabora.com>
AuthorDate: Sun Oct 27 22:10:47 2024 +0100
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Thu Nov 7 10:06:37 2024 +0100

    lok: slideshow: provide support for interactive animations sequence
    
    Change-Id: Ic6ff5f3fe5f7a330e511a33db70f75b77e9b58fa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175821
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sd/source/ui/tools/SlideshowLayerRenderer.cxx 
b/sd/source/ui/tools/SlideshowLayerRenderer.cxx
index 6ec95a2030be..07a9f018a6fd 100644
--- a/sd/source/ui/tools/SlideshowLayerRenderer.cxx
+++ b/sd/source/ui/tools/SlideshowLayerRenderer.cxx
@@ -488,6 +488,14 @@ void SlideshowLayerRenderer::setupAnimations()
     {
         resolveEffect(rEffect);
     }
+
+    for (auto const& rISequence : rMain->getInteractiveSequenceVector())
+    {
+        for (auto const& rEffect : rISequence->getSequence())
+        {
+            resolveEffect(rEffect);
+        }
+    }
 }
 
 Size SlideshowLayerRenderer::calculateAndSetSizePixel(Size const& 
rDesiredSizePixel)
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index b38da6630023..227fd0c67764 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -582,6 +582,7 @@ public:
     AnimationsExporter(::tools::JsonWriter& rWriter,
                        const Reference<drawing::XDrawPage>& xDrawPage);
     void exportAnimations();
+    void exportTriggers() const;
     [[nodiscard]] bool hasEffects() const { return mbHasEffects; }
 
 private:
@@ -592,7 +593,10 @@ private:
     void exportAnimate(const Reference<XAnimate>& xAnimate);
 
     void convertValue(XMLTokenEnum eAttributeName, OStringBuffer& sTmp, const 
Any& rValue) const;
-    void convertTiming(OStringBuffer& sTmp, const Any& rValue) const;
+    void convertTiming(OStringBuffer& sTmp, const Any& rValue);
+
+    void appendTrigger(const css::uno::Any& rTarget, const OString& 
rTriggerHash);
+    void exportTriggersImpl(const uno::Reference<drawing::XShapes>& xShapes) 
const;
 
 private:
     ::tools::JsonWriter& mrWriter;
@@ -600,6 +604,7 @@ private:
     Reference<XPropertySet> mxPageProps;
     Reference<XAnimationNode> mxRootNode;
     bool mbHasEffects;
+    std::unordered_map<SdrObject*, OString> maEventTriggerSet;
 };
 
 AnimationsExporter::AnimationsExporter(::tools::JsonWriter& rWriter,
@@ -968,7 +973,7 @@ void AnimationsExporter::exportNodeImpl(const 
Reference<XAnimationNode>& xNode)
     }
 }
 
-void AnimationsExporter::convertTiming(OStringBuffer& sTmp, const Any& rValue) 
const
+void AnimationsExporter::convertTiming(OStringBuffer& sTmp, const Any& rValue)
 {
     if (!rValue.hasValue())
         return;
@@ -1010,8 +1015,14 @@ void AnimationsExporter::convertTiming(OStringBuffer& 
sTmp, const Any& rValue) c
         {
             if (pEvent->Source.hasValue())
             {
-                anim::convertTarget(sTmp, pEvent->Source);
+                OStringBuffer aTriggerBuffer;
+                // hash must not start with a digit or on client it is parsed 
as a time in seconds
+                aTriggerBuffer.append("id");
+                anim::convertTarget(aTriggerBuffer, pEvent->Source);
+                OString sTriggerHash(aTriggerBuffer.makeStringAndClear());
+                sTmp.append(sTriggerHash);
                 sTmp.append('.');
+                appendTrigger(pEvent->Source, sTriggerHash);
             }
 
             convertEnum(sTmp2, pEvent->Trigger, constEventTriggerToString);
@@ -1037,6 +1048,69 @@ void AnimationsExporter::convertTiming(OStringBuffer& 
sTmp, const Any& rValue) c
     }
 }
 
+void AnimationsExporter::appendTrigger(const css::uno::Any& rTarget, const 
OString& rTriggerHash)
+{
+    css::uno::Reference<css::uno::XInterface> xRef;
+    rTarget >>= xRef;
+
+    uno::Reference<drawing::XShape> xShape(xRef, uno::UNO_QUERY);
+    if (!xShape.is())
+    {
+        if (auto xParagraphTarget = 
o3tl::tryAccess<css::presentation::ParagraphTarget>(rTarget))
+        {
+            xShape = xParagraphTarget->Shape;
+        }
+    }
+    if (xShape.is())
+    {
+        auto* pObject = SdrObject::getSdrObjectFromXShape(xShape);
+        maEventTriggerSet[pObject] = rTriggerHash;
+    }
+}
+
+void AnimationsExporter::exportTriggersImpl(const 
uno::Reference<drawing::XShapes>& xShapes) const
+{
+    if (!xShapes.is())
+        return;
+
+    sal_Int32 nCount = xShapes->getCount();
+    for (sal_Int32 i = 0; i < nCount; ++i)
+    {
+        auto xObject = xShapes->getByIndex(i);
+        uno::Reference<drawing::XShape> xShape(xObject, uno::UNO_QUERY);
+        if (!xShape.is())
+            continue;
+
+        auto* pObject = SdrObject::getSdrObjectFromXShape(xShape);
+        if (maEventTriggerSet.find(pObject) == maEventTriggerSet.end())
+            continue;
+        {
+            ::tools::ScopedJsonWriterStruct aShape = mrWriter.startStruct();
+            mrWriter.put("hash", maEventTriggerSet.at(pObject));
+            {
+                auto const& rRectangle = pObject->GetLogicRect();
+                auto aRectangle
+                    = o3tl::convert(rRectangle, o3tl::Length::mm100, 
o3tl::Length::twip);
+                ::tools::ScopedJsonWriterNode aRect = 
mrWriter.startNode("bounds");
+                mrWriter.put("x", aRectangle.Left());
+                mrWriter.put("y", aRectangle.Top());
+                mrWriter.put("width", aRectangle.GetWidth());
+                mrWriter.put("height", aRectangle.GetHeight());
+            }
+        }
+    }
+}
+
+void AnimationsExporter::exportTriggers() const
+{
+    uno::Reference<drawing::XShapes> const xShapes(mxDrawPage, 
uno::UNO_QUERY_THROW);
+    if (!xShapes.is())
+        return;
+
+    ::tools::ScopedJsonWriterArray aTriggerList = 
mrWriter.startArray("triggers");
+    exportTriggersImpl(xShapes);
+}
+
 void AnimationsExporter::convertValue(XMLTokenEnum eAttributeName, 
OStringBuffer& sTmp,
                                       const Any& rValue) const
 {
@@ -4503,8 +4577,12 @@ OString SdXImpressDocument::getPresentationInfo() const
                             AnimationsExporter aAnimationExporter(aJsonWriter, 
xSlide);
                             if (aAnimationExporter.hasEffects())
                             {
-                                ::tools::ScopedJsonWriterNode aAnimationsNode 
= aJsonWriter.startNode("animations");
-                                aAnimationExporter.exportAnimations();
+                                {
+                                    ::tools::ScopedJsonWriterNode 
aAnimationsNode
+                                        = aJsonWriter.startNode("animations");
+                                    aAnimationExporter.exportAnimations();
+                                }
+                                aAnimationExporter.exportTriggers();
                             }
                         }
                     }

Reply via email to