Coverage Report

Created: 2026-02-14 09:37

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
10.2k
{
48
10.2k
    if( !rNewValue.hasValue() )
49
27
    {
50
27
        return rOldValue;
51
27
    }
52
10.2k
    else if( !rOldValue.hasValue() )
53
10.0k
    {
54
10.0k
        return rNewValue;
55
10.0k
    }
56
191
    else
57
191
    {
58
191
        Sequence< Any > aNewSeq;
59
191
        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
191
        else
66
191
        {
67
191
            aNewSeq = { rOldValue, rNewValue };
68
191
        }
69
191
        return Any( aNewSeq );
70
191
    }
71
10.2k
}
72
73
} // namespace oox
74
75
namespace oox::ppt {
76
77
    void ShapeTargetElement::convert( css::uno::Any & rTarget, sal_Int16 & rSubType ) const
78
309
    {
79
309
        switch(mnType)
80
309
        {
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
18
        case XML_txEl:
88
18
        {
89
18
            ParagraphTarget aParaTarget;
90
18
            Reference< XShape > xShape;
91
18
            rTarget >>= xShape;
92
18
            aParaTarget.Shape = xShape;
93
18
            rSubType = ShapeAnimationSubType::ONLY_TEXT;
94
95
18
            Reference< XText > xText( xShape, UNO_QUERY );
96
18
            if( xText.is() )
97
18
            {
98
18
                switch(mnRangeType)
99
18
                {
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
18
                case XML_pRg:
105
18
                    aParaTarget.Paragraph = static_cast< sal_Int16 >( maRange.start );
106
                    // TODO what to do with more than one.
107
18
                    SAL_INFO("oox.ppt", "OOX: TODO what to do with more than one" );
108
18
                    break;
109
18
                }
110
18
                rTarget <<= aParaTarget;
111
18
            }
112
18
            break;
113
18
        }
114
291
        default:
115
291
            break;
116
309
        }
117
309
    }
118
119
    Any AnimTargetElement::convert(const SlidePersistPtr & pSlide, sal_Int16 & nSubType) const
120
309
    {
121
309
        Any aTarget;
122
        // see sd/source/files/ppt/pptinanimations.cxx:3191 (in importTargetElementContainer())
123
309
        switch(mnType)
124
309
        {
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
309
        case XML_spTgt:
137
309
        {
138
309
            OUString sShapeName = msValue;
139
140
            // bnc#705982 - catch referenced diagram fallback shapes
141
309
            if( maShapeTarget.mnType == XML_dgm )
142
0
                sShapeName = maShapeTarget.msSubShapeId;
143
144
309
            ::oox::drawingml::ShapePtr pShape = pSlide->getShape( sShapeName );
145
309
            SAL_WARN_IF( !pShape, "oox.ppt", "failed to locate Shape" );
146
147
309
            if( !pShape && maShapeTarget.mnType == XML_dgm )
148
0
            {
149
0
                pShape = pSlide->getShape( msValue );
150
0
            }
151
152
309
            if( pShape )
153
309
            {
154
309
                Reference< XShape > xShape( pShape->getXShape() );
155
309
                SAL_WARN_IF( !xShape.is(), "oox.ppt", "fail to get XShape from shape" );
156
309
                if( xShape.is() )
157
309
                {
158
309
                    Any aTmpTarget;
159
309
                    aTmpTarget <<= xShape;
160
309
                    maShapeTarget.convert(aTmpTarget, nSubType);
161
309
                    aTarget = std::move(aTmpTarget);
162
309
                }
163
309
            }
164
309
            break;
165
309
        }
166
309
        default:
167
0
            break;
168
309
        }
169
309
        return aTarget;
170
309
    }
171
172
    // Convert a time node condition to XAnimation.Begin or XAnimation.End
173
    Any AnimationCondition::convert(const SlidePersistPtr & pSlide) const
174
385
    {
175
385
        Any aAny;
176
385
        Event aEvent;
177
385
        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
385
        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
339
        else
198
339
        {
199
339
            aAny = maValue;
200
339
        }
201
385
        return aAny;
202
385
    }
203
204
    Any AnimationCondition::convertList(const SlidePersistPtr & pSlide, const AnimationConditionList & l)
205
341
    {
206
341
        Any aAny;
207
208
341
        if (l.size() == 1)
209
297
            return l[0].convert(pSlide);
210
211
44
        for (auto const& elem : l)
212
88
        {
213
88
            aAny = addToSequence( aAny, elem.convert(pSlide) );
214
88
        }
215
44
        return aAny;
216
341
    }
217
218
}
219
220
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */