Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / ppt / animationspersist.cxx
blob94cdd9672e393897276557cbfc175f35a3889423
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/ppt/animationspersist.hxx"
22 #include <rtl/ustring.hxx>
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/drawing/XShape.hpp>
25 #include <com/sun/star/text/XText.hpp>
26 #include <com/sun/star/presentation/ParagraphTarget.hpp>
27 #include <com/sun/star/presentation/ShapeAnimationSubType.hpp>
29 #include "oox/drawingml/shape.hxx"
30 #include <oox/helper/attributelist.hxx>
31 #include <oox/helper/addtosequence.hxx>
32 #include <oox/token/namespaces.hxx>
33 #include <oox/token/tokens.hxx>
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::presentation;
37 using namespace ::com::sun::star::drawing;
38 using namespace ::com::sun::star::text;
40 namespace oox
43 Any addToSequence( const Any& rOldValue, const Any& rNewValue )
45 if( !rNewValue.hasValue() )
47 return rOldValue;
49 else if( !rOldValue.hasValue() )
51 return rNewValue;
53 else
55 Sequence< Any > aNewSeq;
56 if( rOldValue >>= aNewSeq )
58 sal_Int32 nSize = aNewSeq.getLength();
59 aNewSeq.realloc(nSize+1);
60 aNewSeq[nSize] = rNewValue;
62 else
64 aNewSeq.realloc(2);
65 aNewSeq[0] = rOldValue;
66 aNewSeq[1] = rNewValue;
68 return makeAny( aNewSeq );
72 } // namespace oox
74 namespace oox { namespace ppt {
76 void ShapeTargetElement::convert( css::uno::Any & rTarget, sal_Int16 & rSubType ) const
78 switch(mnType)
80 case XML_subSp:
81 rSubType = ShapeAnimationSubType::AS_WHOLE;
82 break;
83 case XML_bg:
84 rSubType = ShapeAnimationSubType::ONLY_BACKGROUND;
85 break;
86 case XML_txEl:
88 ParagraphTarget aParaTarget;
89 Reference< XShape > xShape;
90 rTarget >>= xShape;
91 aParaTarget.Shape = xShape;
92 rSubType = ShapeAnimationSubType::ONLY_TEXT;
94 Reference< XText > xText( xShape, UNO_QUERY );
95 if( xText.is() )
97 switch(mnRangeType)
99 case XML_charRg:
100 // TODO calculate the corresponding paragraph for the text range....
101 SAL_INFO("oox.ppt", "OOX: TODO calculate the corresponding paragraph for the text range..." );
102 break;
103 case XML_pRg:
104 aParaTarget.Paragraph = static_cast< sal_Int16 >( maRange.start );
105 // TODO what to do with more than one.
106 SAL_INFO("oox.ppt", "OOX: TODO what to do with more than one" );
107 break;
109 rTarget <<= aParaTarget;
111 break;
113 default:
114 break;
118 Any AnimTargetElement::convert(const SlidePersistPtr & pSlide, sal_Int16 & nSubType) const
120 Any aTarget;
121 // see sd/source/files/ppt/pptinanimations.cxx:3191 (in importTargetElementContainer())
122 switch(mnType)
124 case XML_inkTgt:
125 // TODO
126 SAL_INFO("oox.ppt", "OOX: TODO inkTgt" );
127 break;
128 case XML_sldTgt:
129 // TODO
130 SAL_INFO("oox.ppt", "OOX: TODO sldTgt" );
131 break;
132 case XML_sndTgt:
133 aTarget <<= msValue;
134 break;
135 case XML_spTgt:
137 OUString sShapeName = msValue;
139 // bnc#705982 - catch referenced diagram fallback shapes
140 if( maShapeTarget.mnType == XML_dgm )
141 sShapeName = maShapeTarget.msSubShapeId;
143 Any rTarget;
144 ::oox::drawingml::ShapePtr pShape = pSlide->getShape(sShapeName);
145 SAL_WARN_IF( !pShape, "oox.ppt", "failed to locate Shape");
146 if( pShape )
148 Reference< XShape > xShape( pShape->getXShape() );
149 SAL_WARN_IF( !xShape.is(), "oox.ppt", "fail to get XShape from shape" );
150 if( xShape.is() )
152 rTarget <<= xShape;
153 maShapeTarget.convert(rTarget, nSubType);
154 aTarget = rTarget;
157 break;
159 default:
160 break;
162 return aTarget;
165 Any AnimationCondition::convert(const SlidePersistPtr & pSlide) const
167 Any aAny;
168 if( mpTarget )
170 sal_Int16 nSubType;
171 aAny = mpTarget->convert( pSlide, nSubType );
173 else
175 aAny = maValue;
177 return aAny;
180 Any AnimationCondition::convertList(const SlidePersistPtr & pSlide, const AnimationConditionList & l)
182 Any aAny;
183 for( AnimationConditionList::const_iterator iter = l.begin();
184 iter != l.end(); ++iter)
186 aAny = addToSequence( aAny, iter->convert(pSlide) );
188 return aAny;
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */