Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/animations/animationnodehelper.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#pragma once
21
22
#include <o3tl/any.hxx>
23
#include <rtl/strbuf.hxx>
24
#include <sal/log.hxx>
25
#include <tools/helpers.hxx>
26
27
#include <com/sun/star/uno/Any.hxx>
28
#include <com/sun/star/uno/Reference.hxx>
29
#include <com/sun/star/animations/XAnimate.hpp>
30
#include <com/sun/star/animations/XAnimationNode.hpp>
31
#include <com/sun/star/container/XEnumerationAccess.hpp>
32
#include <com/sun/star/container/XEnumeration.hpp>
33
#include <com/sun/star/presentation/ParagraphTarget.hpp>
34
35
#include <vector>
36
37
/* Declaration and definition of AnimationNode helper */
38
39
namespace anim
40
{
41
    // TODO(Q1): this could possibly be implemented with a somewhat
42
    // more lightweight template, by having the actual worker receive
43
    // only a function pointer, and a thin templated wrapper around
44
    // that which converts member functions into that.
45
46
    /** pushes the given node to the given vector and recursively calls itself for each child node.
47
    */
48
    inline void create_deep_vector( const css::uno::Reference< css::animations::XAnimationNode >& xNode,
49
                                std::vector< css::uno::Reference< css::animations::XAnimationNode > >& rVector )
50
28
    {
51
28
        rVector.push_back( xNode );
52
53
28
        try
54
28
        {
55
            // get an XEnumerationAccess to the children
56
28
            css::uno::Reference< css::container::XEnumerationAccess >
57
28
                  xEnumerationAccess( xNode, css::uno::UNO_QUERY );
58
59
28
            if( xEnumerationAccess.is() )
60
28
            {
61
28
                css::uno::Reference< css::container::XEnumeration >
62
28
                      xEnumeration = xEnumerationAccess->createEnumeration();
63
64
28
                if( xEnumeration.is() )
65
28
                {
66
42
                    while( xEnumeration->hasMoreElements() )
67
14
                    {
68
14
                        css::uno::Reference< css::animations::XAnimationNode >
69
14
                            xChildNode( xEnumeration->nextElement(),
70
14
                                        css::uno::UNO_QUERY_THROW );
71
72
14
                        create_deep_vector( xChildNode, rVector );
73
14
                    }
74
28
                }
75
28
            }
76
28
        }
77
28
        catch( css::uno::Exception& )
78
28
        {
79
0
        }
80
28
    }
81
82
    inline bool getVisibilityPropertyForAny(css::uno::Any const& rAny)
83
0
    {
84
0
        bool bVisible = false;
85
0
        css::uno::Any aAny(rAny);
86
87
        // try to extract bool value
88
0
        if (!(aAny >>= bVisible))
89
0
        {
90
            // try to extract string
91
0
            OUString aString;
92
0
            if (aAny >>= aString)
93
0
            {
94
                // we also take the strings "true" and "false",
95
                // as well as "on" and "off" here
96
0
                if (aString.equalsIgnoreAsciiCase("true") ||
97
0
                    aString.equalsIgnoreAsciiCase("on"))
98
0
                {
99
0
                    bVisible = true;
100
0
                }
101
0
                if (aString.equalsIgnoreAsciiCase("false") ||
102
0
                    aString.equalsIgnoreAsciiCase("off"))
103
0
                {
104
0
                    bVisible = false;
105
0
                }
106
0
            }
107
0
        }
108
0
        return bVisible;
109
0
    }
110
111
    inline bool getVisibilityProperty(
112
        const css::uno::Reference< css::animations::XAnimate >& xAnimateNode, bool& bReturn)
113
0
    {
114
0
        if (xAnimateNode->getAttributeName().equalsIgnoreAsciiCase("visibility"))
115
0
        {
116
0
            css::uno::Any aAny(xAnimateNode->getTo());
117
0
            bReturn = getVisibilityPropertyForAny(aAny);
118
0
            return true;
119
0
        }
120
0
121
0
        return false;
122
0
    }
123
124
    inline void convertTarget(OStringBuffer& aStringBuffer, const css::uno::Any& rTarget)
125
0
    {
126
0
        if (!rTarget.hasValue())
127
0
            return;
128
129
0
        css::uno::Reference<css::uno::XInterface> xRef;
130
0
        if (auto xParagraphTarget = o3tl::tryAccess<css::presentation::ParagraphTarget>(rTarget))
131
0
        {
132
0
            if (xParagraphTarget->Shape.is())
133
0
            {
134
0
                const std::string aIdentifier(GetInterfaceHash(xParagraphTarget->Shape));
135
0
                if (!aIdentifier.empty())
136
0
                {
137
0
                    sal_Int32 nParagraph(xParagraphTarget->Paragraph);
138
0
                    aStringBuffer.append(aIdentifier);
139
0
                    aStringBuffer.append("_");
140
0
                    aStringBuffer.append(nParagraph);
141
0
                }
142
0
            }
143
0
        }
144
0
        else
145
0
        {
146
0
            rTarget >>= xRef;
147
0
            SAL_WARN_IF(!xRef.is(), "animations", "convertTarget(), invalid target type!");
148
0
            if (xRef.is())
149
0
            {
150
0
                const std::string aIdentifier(GetInterfaceHash(xRef));
151
0
                if (!aIdentifier.empty())
152
0
                    aStringBuffer.append(aIdentifier);
153
0
            }
154
0
        }
155
0
    }
156
}
157
158
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */