1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/ppt/animationspersist.hxx"
29 
30 #include <rtl/ustring.hxx>
31 #include <com/sun/star/uno/Any.hxx>
32 #include <com/sun/star/drawing/XShape.hpp>
33 #include <com/sun/star/text/XText.hpp>
34 #include <com/sun/star/presentation/ParagraphTarget.hpp>
35 #include <com/sun/star/presentation/ShapeAnimationSubType.hpp>
36 
37 #include "oox/drawingml/shape.hxx"
38 
39 using rtl::OUString;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::presentation;
42 using namespace ::com::sun::star::drawing;
43 using namespace ::com::sun::star::text;
44 
45 namespace oox { namespace ppt {
46 
47 	void ShapeTargetElement::convert( ::com::sun::star::uno::Any & rTarget, sal_Int16 & rSubType ) const
48 	{
49 		switch(mnType)
50 		{
51 		case XML_subSp:
52 			rSubType = ShapeAnimationSubType::AS_WHOLE;
53 			break;
54 		case XML_bg:
55 			rSubType = ShapeAnimationSubType::ONLY_BACKGROUND;
56 			break;
57 		case XML_txEl:
58 		{
59 			ParagraphTarget aParaTarget;
60 			Reference< XShape > xShape;
61 			rTarget >>= xShape;
62 			aParaTarget.Shape = xShape;
63 			rSubType = ShapeAnimationSubType::ONLY_TEXT;
64 
65 			Reference< XText > xText( xShape, UNO_QUERY );
66 			if( xText.is() )
67 			{
68 				switch(mnRangeType)
69 				{
70 				case XML_charRg:
71 					// TODO calculate the corresponding paragraph for the text range....
72 					OSL_TRACE( "OOX: TODO calculate the corresponding paragraph for the text range..." );
73 					break;
74 				case XML_pRg:
75 					aParaTarget.Paragraph = static_cast< sal_Int16 >( maRange.start );
76 					// TODO what to do with more than one.
77 					OSL_TRACE( "OOX: TODO what to do with more than one" );
78 					break;
79 				}
80 				rTarget = makeAny( aParaTarget );
81 			}
82 			break;
83 		}
84 		default:
85 			break;
86 		}
87 	}
88 
89 
90 	Any AnimTargetElement::convert(const SlidePersistPtr & pSlide, sal_Int16 & nSubType) const
91 	{
92 		Any aTarget;
93 		// see sd/source/files/ppt/pptinanimations.cxx:3191 (in importTargetElementContainer())
94 		switch(mnType)
95 		{
96 		case XML_inkTgt:
97 			// TODO
98 			OSL_TRACE( "OOX: TODO inkTgt" );
99 			break;
100 		case XML_sldTgt:
101 			// TODO
102 			OSL_TRACE( "OOX: TODO sldTgt" );
103 			break;
104 		case XML_sndTgt:
105 			aTarget = makeAny(msValue);
106 			break;
107 		case XML_spTgt:
108 		{
109 			Any rTarget;
110 			::oox::drawingml::ShapePtr pShape = pSlide->getShape(msValue);
111 			OSL_ENSURE( pShape, "failed to locate Shape");
112 			if( pShape )
113 			{
114 				Reference< XShape > xShape( pShape->getXShape() );
115 				OSL_ENSURE( xShape.is(), "fail to get XShape from shape" );
116 				if( xShape.is() )
117 				{
118 					rTarget <<= xShape;
119 					maShapeTarget.convert(rTarget, nSubType);
120 					aTarget = rTarget;
121 				}
122 			}
123 			break;
124 		}
125 		default:
126 			break;
127 		}
128 		return aTarget;
129 	}
130 
131 
132 // BEGIN CUT&PASTE from sd/source/filter/ppt/pptinanimations.cxx
133 /** this adds an any to another any.
134 	if rNewValue is empty, rOldValue is returned.
135 	if rOldValue is empty, rNewValue is returned.
136 	if rOldValue contains a value, a sequence with rOldValue and rNewValue is returned.
137 	if rOldValue contains a sequence, a new sequence with the old sequence and rNewValue is returned.
138 */
139 	static Any addToSequence( const Any& rOldValue, const Any& rNewValue )
140 	{
141 		if( !rNewValue.hasValue() )
142 		{
143 			return rOldValue;
144 		}
145 		else if( !rOldValue.hasValue() )
146 		{
147 			return rNewValue;
148 		}
149 		else
150 		{
151 			Sequence< Any > aNewSeq;
152 			if( rOldValue >>= aNewSeq )
153 			{
154 				sal_Int32 nSize = aNewSeq.getLength();
155 				aNewSeq.realloc(nSize+1);
156 				aNewSeq[nSize] = rNewValue;
157 			}
158 			else
159 			{
160 				aNewSeq.realloc(2);
161 				aNewSeq[0] = rOldValue;
162 				aNewSeq[1] = rNewValue;
163 			}
164 			return makeAny( aNewSeq );
165 		}
166 	}
167 // END
168 
169 	Any AnimationCondition::convert(const SlidePersistPtr & pSlide) const
170 	{
171 		Any aAny;
172 		if( mpTarget )
173 		{
174 			sal_Int16 nSubType;
175 			aAny = mpTarget->convert( pSlide, nSubType );
176 		}
177 		else
178 		{
179 			aAny = maValue;
180 		}
181 		return aAny;
182 	}
183 
184 
185 	Any AnimationCondition::convertList(const SlidePersistPtr & pSlide, const AnimationConditionList & l)
186 	{
187 		Any aAny;
188 		for( AnimationConditionList::const_iterator iter = l.begin();
189 			 iter != l.end(); iter++)
190 		{
191 			aAny = addToSequence( aAny, iter->convert(pSlide) );
192 		}
193 		return aAny;
194 	}
195 
196 } }
197 
198 
199