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