Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/ppt/animationspersist.cxx
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
#include <oox/ppt/animationspersist.hxx>
21
22
#include <rtl/ustring.hxx>
23
#include <sal/log.hxx>
24
#include <com/sun/star/uno/Any.hxx>
25
#include <com/sun/star/drawing/XShape.hpp>
26
#include <com/sun/star/text/XText.hpp>
27
#include <com/sun/star/presentation/ParagraphTarget.hpp>
28
#include <com/sun/star/presentation/ShapeAnimationSubType.hpp>
29
#include <com/sun/star/animations/Event.hpp>
30
#include <com/sun/star/animations/XAnimationNode.hpp>
31
32
#include <oox/drawingml/shape.hxx>
33
#include <oox/helper/addtosequence.hxx>
34
#include <oox/token/namespaces.hxx>
35
#include <oox/token/tokens.hxx>
36
37
using namespace ::com::sun::star::uno;
38
using namespace ::com::sun::star::presentation;
39
using namespace ::com::sun::star::animations;
40
using namespace ::com::sun::star::drawing;
41
using namespace ::com::sun::star::text;
42
43
namespace oox
44
{
45
46
Any addToSequence( const Any& rOldValue, const Any& rNewValue )
47
13.0k
{
48
13.0k
    if( !rNewValue.hasValue() )
49
61
    {
50
61
        return rOldValue;
51
61
    }
52
13.0k
    else if( !rOldValue.hasValue() )
53
12.7k
    {
54
12.7k
        return rNewValue;
55
12.7k
    }
56
295
    else
57
295
    {
58
295
        Sequence< Any > aNewSeq;
59
295
        if( rOldValue >>= aNewSeq )
60
0
        {
61
0
            sal_Int32 nSize = aNewSeq.getLength();
62
0
            aNewSeq.realloc(nSize+1);
63
0
            aNewSeq.getArray()[nSize] = rNewValue;
64
0
        }
65
295
        else
66
295
        {
67
295
            aNewSeq = { rOldValue, rNewValue };
68
295
        }
69
295
        return Any( aNewSeq );
70
295
    }
71
13.0k
}
72
73
} // namespace oox
74
75
namespace oox::ppt {
76
77
    void ShapeTargetElement::convert( css::uno::Any & rTarget, sal_Int16 & rSubType ) const
78
337
    {
79
337
        switch(mnType)
80
337
        {
81
0
        case XML_subSp:
82
0
            rSubType = ShapeAnimationSubType::AS_WHOLE;
83
0
            break;
84
0
        case XML_bg:
85
0
            rSubType = ShapeAnimationSubType::ONLY_BACKGROUND;
86
0
            break;
87
26
        case XML_txEl:
88
26
        {
89
26
            ParagraphTarget aParaTarget;
90
26
            Reference< XShape > xShape;
91
26
            rTarget >>= xShape;
92
26
            aParaTarget.Shape = xShape;
93
26
            rSubType = ShapeAnimationSubType::ONLY_TEXT;
94
95
26
            Reference< XText > xText( xShape, UNO_QUERY );
96
26
            if( xText.is() )
97
26
            {
98
26
                switch(mnRangeType)
99
26
                {
100
0
                case XML_charRg:
101
                    // TODO calculate the corresponding paragraph for the text range...
102
0
                    SAL_INFO("oox.ppt", "OOX: TODO calculate the corresponding paragraph for the text range..." );
103
0
                    break;
104
26
                case XML_pRg:
105
26
                    aParaTarget.Paragraph = static_cast< sal_Int16 >( maRange.start );
106
                    // TODO what to do with more than one.
107
26
                    SAL_INFO("oox.ppt", "OOX: TODO what to do with more than one" );
108
26
                    break;
109
26
                }
110
26
                rTarget <<= aParaTarget;
111
26
            }
112
26
            break;
113
26
        }
114
311
        default:
115
311
            break;
116
337
        }
117
337
    }
118
119
    Any AnimTargetElement::convert(const SlidePersistPtr & pSlide, sal_Int16 & nSubType) const
120
337
    {
121
337
        Any aTarget;
122
        // see sd/source/files/ppt/pptinanimations.cxx:3191 (in importTargetElementContainer())
123
337
        switch(mnType)
124
337
        {
125
0
        case XML_inkTgt:
126
            // TODO
127
0
            SAL_INFO("oox.ppt", "OOX: TODO inkTgt" );
128
0
            break;
129
0
        case XML_sldTgt:
130
            // TODO
131
0
            SAL_INFO("oox.ppt", "OOX: TODO sldTgt" );
132
0
            break;
133
0
        case XML_sndTgt:
134
0
            aTarget <<= msValue;
135
0
            break;
136
337
        case XML_spTgt:
137
337
        {
138
337
            OUString sShapeName = msValue;
139
140
            // bnc#705982 - catch referenced diagram fallback shapes
141
337
            if( maShapeTarget.mnType == XML_dgm )
142
0
                sShapeName = maShapeTarget.msSubShapeId;
143
144
337
            ::oox::drawingml::ShapePtr pShape = pSlide->getShape( sShapeName );
145
337
            SAL_WARN_IF( !pShape, "oox.ppt", "failed to locate Shape" );
146
147
337
            if( !pShape && maShapeTarget.mnType == XML_dgm )
148
0
            {
149
0
                pShape = pSlide->getShape( msValue );
150
0
            }
151
152
337
            if( pShape )
153
337
            {
154
337
                Reference< XShape > xShape( pShape->getXShape() );
155
337
                SAL_WARN_IF( !xShape.is(), "oox.ppt", "fail to get XShape from shape" );
156
337
                if( xShape.is() )
157
337
                {
158
337
                    Any aTmpTarget;
159
337
                    aTmpTarget <<= xShape;
160
337
                    maShapeTarget.convert(aTmpTarget, nSubType);
161
337
                    aTarget = std::move(aTmpTarget);
162
337
                }
163
337
            }
164
337
            break;
165
337
        }
166
337
        default:
167
0
            break;
168
337
        }
169
337
        return aTarget;
170
337
    }
171
172
    // Convert a time node condition to XAnimation.Begin or XAnimation.End
173
    Any AnimationCondition::convert(const SlidePersistPtr & pSlide) const
174
414
    {
175
414
        Any aAny;
176
414
        Event aEvent;
177
414
        if(mpTarget && (maValue >>= aEvent))
178
0
        {
179
0
            sal_Int16 nSubType;
180
0
            aAny = mpTarget->convert( pSlide, nSubType );
181
0
            aEvent.Source = aAny;
182
0
            aAny <<= aEvent;
183
0
        }
184
414
        else if (mnType == PPT_TOKEN(tn) && (maValue >>= aEvent))
185
46
        {
186
46
            OUString sId;
187
46
            aEvent.Source >>= sId;
188
46
            css::uno::Reference<XAnimationNode> xNode = pSlide->getAnimationNode(sId);
189
46
            if (xNode.is())
190
46
            {
191
46
                aEvent.Source <<= xNode;
192
46
            }
193
0
            else
194
0
                aEvent.Source.clear();
195
46
            aAny <<= aEvent;
196
46
        }
197
368
        else
198
368
        {
199
368
            aAny = maValue;
200
368
        }
201
414
        return aAny;
202
414
    }
203
204
    Any AnimationCondition::convertList(const SlidePersistPtr & pSlide, const AnimationConditionList & l)
205
372
    {
206
372
        Any aAny;
207
208
372
        if (l.size() == 1)
209
330
            return l[0].convert(pSlide);
210
211
42
        for (auto const& elem : l)
212
84
        {
213
84
            aAny = addToSequence( aAny, elem.convert(pSlide) );
214
84
        }
215
42
        return aAny;
216
372
    }
217
218
}
219
220
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */