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