include/animations/animationnodehelper.hxx | 59 ++++++++++++++++++++++++++ sd/source/ui/inc/SlideshowLayerRenderer.hxx | 1 sd/source/ui/tools/SlideshowLayerRenderer.cxx | 10 +++- sd/source/ui/unoidl/unomodel.cxx | 59 ++------------------------ 4 files changed, 74 insertions(+), 55 deletions(-)
New commits: commit 44fea573fec5a415d0488b760c133afe3aabb562 Author: Szymon Kłos <[email protected]> AuthorDate: Thu Sep 12 11:22:10 2024 +0200 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Fri Sep 13 11:20:17 2024 +0200 slideshow: use unified hash for animations and layers Change-Id: I98d048f933469a63295776f689e96ce84d0c4f49 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173253 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/include/animations/animationnodehelper.hxx b/include/animations/animationnodehelper.hxx index 5c03e2341294..3da2e8fa2d39 100644 --- a/include/animations/animationnodehelper.hxx +++ b/include/animations/animationnodehelper.hxx @@ -20,12 +20,18 @@ #ifndef INCLUDED_ANIMATIONS_ANIMATIONNODEHELPER_HXX #define INCLUDED_ANIMATIONS_ANIMATIONNODEHELPER_HXX +#include <o3tl/any.hxx> +#include <rtl/strbuf.hxx> +#include <sal/log.hxx> +#include <tools/helpers.hxx> + #include <com/sun/star/uno/Any.hxx> #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/animations/XAnimate.hpp> #include <com/sun/star/animations/XAnimationNode.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> #include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/presentation/ParagraphTarget.hpp> #include <vector> @@ -109,6 +115,59 @@ 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) + { + if (!rTarget.hasValue()) + return; + + css::uno::Reference<css::uno::XInterface> xRef; + if (!(rTarget >>= xRef)) + { + if (auto pt = o3tl::tryAccess<css::presentation::ParagraphTarget>(rTarget)) + { + xRef = getParagraphTarget(*pt); + } + } + + SAL_WARN_IF(!xRef.is(), "animations", "convertTarget(), invalid target type!"); + if (xRef.is()) + { + const std::string& rIdentifier(GetInterfaceHash(xRef)); + if (!rIdentifier.empty()) + sTmp.append(rIdentifier); + } + } } #endif /* INCLUDED_ANIMATIONS_ANIMATIONNODEHELPER_HXX */ diff --git a/sd/source/ui/inc/SlideshowLayerRenderer.hxx b/sd/source/ui/inc/SlideshowLayerRenderer.hxx index 529eba5ed8ed..e75e6ed40f89 100644 --- a/sd/source/ui/inc/SlideshowLayerRenderer.hxx +++ b/sd/source/ui/inc/SlideshowLayerRenderer.hxx @@ -48,6 +48,7 @@ struct RenderState std::unordered_set<SdrObject*> maObjectsDone; std::unordered_set<SdrObject*> maInAnimation; + std::map<SdrObject*, OString> maAnimationTargetHash; std::map<SdrObject*, bool> maInitiallyVisible; sal_Int32 mnIndex[static_cast<unsigned>(RenderStage::Count)] = { 0, 0, 0, 0 }; SdrObject* mpCurrentTarget = nullptr; diff --git a/sd/source/ui/tools/SlideshowLayerRenderer.cxx b/sd/source/ui/tools/SlideshowLayerRenderer.cxx index 37609858075b..803801a5436e 100644 --- a/sd/source/ui/tools/SlideshowLayerRenderer.cxx +++ b/sd/source/ui/tools/SlideshowLayerRenderer.cxx @@ -292,6 +292,14 @@ void SlideshowLayerRenderer::setupAnimations() maRenderState.maInitiallyVisible[pObject] = bVisible; } + + if (aAny.hasValue()) + { + OStringBuffer sTmp; + anim::convertTarget(sTmp, aAny); + maRenderState.maAnimationTargetHash[pObject] + = static_cast<OString>(sTmp); + } } } } @@ -363,7 +371,7 @@ void SlideshowLayerRenderer::writeJSON(OString& rJsonMsg) aJsonWriter.put("type", "animated"); { ::tools::ScopedJsonWriterNode aContentNode = aJsonWriter.startNode("content"); - aJsonWriter.put("hash", RenderState::getObjectHash(pObject)); + aJsonWriter.put("hash", maRenderState.maAnimationTargetHash.at(pObject)); aJsonWriter.put("initVisible", maRenderState.isObjectInitiallyVisible(pObject)); aJsonWriter.put("type", "bitmap"); writeContentNode(aJsonWriter); diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 6658bbbc5da0..ff70d9074f7c 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -61,6 +61,8 @@ #include <com/sun/star/embed/Aspects.hpp> +#include <animations/animationnodehelper.hxx> + #include <officecfg/Office/Common.hxx> #include <comphelper/dispatchcommand.hxx> #include <comphelper/indexedpropertyvalues.hxx> @@ -590,8 +592,6 @@ private: void exportAnimate(const Reference<XAnimate>& xAnimate); void convertValue(XMLTokenEnum eAttributeName, OStringBuffer& sTmp, const Any& rValue) const; - static void convertTarget(OStringBuffer& sTmp, const Any& rTarget); - static Reference<XInterface> getParagraphTarget( const ParagraphTarget& pTarget ); void convertTiming(OStringBuffer& sTmp, const Any& rValue) const; private: @@ -968,55 +968,6 @@ void AnimationsExporter::exportNodeImpl(const Reference<XAnimationNode>& xNode) } } -Reference<XInterface> AnimationsExporter::getParagraphTarget(const ParagraphTarget& pTarget) -{ - try - { - Reference<XEnumerationAccess> xParaEnumAccess(pTarget.Shape, UNO_QUERY_THROW); - - Reference<XEnumeration> xEnumeration(xParaEnumAccess->createEnumeration(), - css::uno::UNO_SET_THROW); - sal_Int32 nParagraph = pTarget.Paragraph; - - while (xEnumeration->hasMoreElements()) - { - Reference<XInterface> xRef(xEnumeration->nextElement(), UNO_QUERY); - if (nParagraph-- == 0) - return xRef; - } - } - catch (const RuntimeException&) - { - TOOLS_WARN_EXCEPTION("sd", "AnimationsExporter::getParagraphTarget"); - } - - Reference<XInterface> xRef; - return xRef; -} - -void AnimationsExporter::convertTarget(OStringBuffer& sTmp, const Any& rTarget) -{ - if (!rTarget.hasValue()) - return; - - Reference<XInterface> xRef; - if (!(rTarget >>= xRef)) - { - if (auto pt = o3tl::tryAccess<ParagraphTarget>(rTarget)) - { - xRef = getParagraphTarget(*pt); - } - } - - SAL_WARN_IF(!xRef.is(), "sd", "AnimationsExporter::convertTarget(), invalid target type!"); - if (xRef.is()) - { - const std::string& rIdentifier(GetInterfaceHash(xRef)); - if (!rIdentifier.empty()) - sTmp.append(rIdentifier); - } -} - void AnimationsExporter::convertTiming(OStringBuffer& sTmp, const Any& rValue) const { if (!rValue.hasValue()) @@ -1059,7 +1010,7 @@ void AnimationsExporter::convertTiming(OStringBuffer& sTmp, const Any& rValue) c { if (pEvent->Source.hasValue()) { - convertTarget(sTmp, pEvent->Source); + anim::convertTarget(sTmp, pEvent->Source); sTmp.append('.'); } @@ -1222,7 +1173,7 @@ void AnimationsExporter::exportContainer(const Reference<XTimeContainer>& xConta Any aTemp(xIter->getTarget()); if (aTemp.hasValue()) { - convertTarget(sTmp, aTemp); + anim::convertTarget(sTmp, aTemp); mrWriter.put("targetElement", sTmp.makeStringAndClear()); } sal_Int16 nTemp = xIter->getSubItem(); @@ -1276,7 +1227,7 @@ void AnimationsExporter::exportAnimate(const Reference<XAnimate>& xAnimate) Any aTemp(xAnimate->getTarget()); if (aTemp.hasValue()) { - convertTarget(sTmp, aTemp); + anim::convertTarget(sTmp, aTemp); mrWriter.put("targetElement", sTmp.makeStringAndClear()); } nTemp = xAnimate->getSubItem();
