1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <canvas/debug.hxx>
32*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include "animationfactory.hxx"
35*cdf0e10cSrcweir #include "setactivity.hxx"
36*cdf0e10cSrcweir #include "animationsetnode.hxx"
37*cdf0e10cSrcweir #include "nodetools.hxx"
38*cdf0e10cSrcweir #include "tools.hxx"
39*cdf0e10cSrcweir #include "delayevent.hxx"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <boost/bind.hpp>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir using namespace com::sun::star;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace slideshow {
46*cdf0e10cSrcweir namespace internal {
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir void AnimationSetNode::implScheduleDeactivationEvent()
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir     scheduleDeactivationEvent();
51*cdf0e10cSrcweir }
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir AnimationActivitySharedPtr AnimationSetNode::createActivity() const
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir     ActivitiesFactory::CommonParameters aParms( fillCommonParameters() );
56*cdf0e10cSrcweir     uno::Reference<animations::XAnimate> const xAnimateNode = getXAnimateNode();
57*cdf0e10cSrcweir     rtl::OUString const attrName( xAnimateNode->getAttributeName() );
58*cdf0e10cSrcweir     AttributableShapeSharedPtr const pShape( getShape() );
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     // make deactivation a two-step procedure. Normally, we
61*cdf0e10cSrcweir     // could solely rely on
62*cdf0e10cSrcweir     // BaseNode::scheduleDeactivationEvent() to deactivate()
63*cdf0e10cSrcweir     // us. Unfortunately, that method on the one hand ignores
64*cdf0e10cSrcweir     // indefinite timing, on the other hand generates
65*cdf0e10cSrcweir     // zero-timeout delays, which might get fired _before_ our
66*cdf0e10cSrcweir     // set activity has taken place. Therefore, we enforce
67*cdf0e10cSrcweir     // sequentiality by letting only the set activity schedule
68*cdf0e10cSrcweir     // the deactivation event (and AnimationBaseNode
69*cdf0e10cSrcweir     // takes care for the fact when mpActivity should be zero).
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     // AnimationBaseNode::fillCommonParameters() has set up
72*cdf0e10cSrcweir     // immediate deactivation as default when activity ends, but
73*cdf0e10cSrcweir     if (! isIndefiniteTiming( xAnimateNode->getDuration() )) {
74*cdf0e10cSrcweir         boost::shared_ptr<AnimationSetNode> const pSelf(
75*cdf0e10cSrcweir             boost::dynamic_pointer_cast<AnimationSetNode>(getSelf()) );
76*cdf0e10cSrcweir         ENSURE_OR_THROW(
77*cdf0e10cSrcweir             pSelf, "cannot cast getSelf() to my type!" );
78*cdf0e10cSrcweir         aParms.mpEndEvent = makeEvent(
79*cdf0e10cSrcweir             boost::bind( &AnimationSetNode::implScheduleDeactivationEvent,
80*cdf0e10cSrcweir                          pSelf ),
81*cdf0e10cSrcweir             "AnimationSetNode::implScheduleDeactivationEvent");
82*cdf0e10cSrcweir     }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir     switch (AnimationFactory::classifyAttributeName( attrName )) {
85*cdf0e10cSrcweir     default:
86*cdf0e10cSrcweir     case AnimationFactory::CLASS_UNKNOWN_PROPERTY:
87*cdf0e10cSrcweir         ENSURE_OR_THROW(
88*cdf0e10cSrcweir             false, "AnimationSetNode::createSetActivity(): "
89*cdf0e10cSrcweir             "Unexpected attribute class" );
90*cdf0e10cSrcweir         break;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     case AnimationFactory::CLASS_NUMBER_PROPERTY:
93*cdf0e10cSrcweir     {
94*cdf0e10cSrcweir         NumberAnimation::ValueType aValue;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir         ENSURE_OR_THROW(
97*cdf0e10cSrcweir             extractValue( aValue,
98*cdf0e10cSrcweir                           xAnimateNode->getTo(),
99*cdf0e10cSrcweir                           pShape,
100*cdf0e10cSrcweir                           getSlideSize() ),
101*cdf0e10cSrcweir             "AnimationSetNode::createSetActivity(): "
102*cdf0e10cSrcweir             "Could not import numeric to value" );
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir         return makeSetActivity(
105*cdf0e10cSrcweir             aParms,
106*cdf0e10cSrcweir             AnimationFactory::createNumberPropertyAnimation(
107*cdf0e10cSrcweir                 attrName,
108*cdf0e10cSrcweir                 pShape,
109*cdf0e10cSrcweir                 getContext().mpSubsettableShapeManager,
110*cdf0e10cSrcweir                 getSlideSize(),
111*cdf0e10cSrcweir                 AnimationFactory::FLAG_NO_SPRITE ),
112*cdf0e10cSrcweir             aValue );
113*cdf0e10cSrcweir     }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     case AnimationFactory::CLASS_ENUM_PROPERTY:
116*cdf0e10cSrcweir     {
117*cdf0e10cSrcweir         EnumAnimation::ValueType aValue;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir         ENSURE_OR_THROW(
120*cdf0e10cSrcweir             extractValue( aValue,
121*cdf0e10cSrcweir                           xAnimateNode->getTo(),
122*cdf0e10cSrcweir                           pShape,
123*cdf0e10cSrcweir                           getSlideSize() ),
124*cdf0e10cSrcweir             "AnimationSetNode::createSetActivity(): "
125*cdf0e10cSrcweir             "Could not import enum to value" );
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir         return makeSetActivity(
128*cdf0e10cSrcweir             aParms,
129*cdf0e10cSrcweir             AnimationFactory::createEnumPropertyAnimation(
130*cdf0e10cSrcweir                 attrName,
131*cdf0e10cSrcweir                 pShape,
132*cdf0e10cSrcweir                 getContext().mpSubsettableShapeManager,
133*cdf0e10cSrcweir                 getSlideSize(),
134*cdf0e10cSrcweir                 AnimationFactory::FLAG_NO_SPRITE ),
135*cdf0e10cSrcweir             aValue );
136*cdf0e10cSrcweir     }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir     case AnimationFactory::CLASS_COLOR_PROPERTY:
139*cdf0e10cSrcweir     {
140*cdf0e10cSrcweir         ColorAnimation::ValueType aValue;
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         ENSURE_OR_THROW(
143*cdf0e10cSrcweir             extractValue( aValue,
144*cdf0e10cSrcweir                           xAnimateNode->getTo(),
145*cdf0e10cSrcweir                           pShape,
146*cdf0e10cSrcweir                           getSlideSize() ),
147*cdf0e10cSrcweir             "AnimationSetNode::createSetActivity(): "
148*cdf0e10cSrcweir             "Could not import color to value" );
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir         return makeSetActivity(
151*cdf0e10cSrcweir             aParms,
152*cdf0e10cSrcweir             AnimationFactory::createColorPropertyAnimation(
153*cdf0e10cSrcweir                 attrName,
154*cdf0e10cSrcweir                 pShape,
155*cdf0e10cSrcweir                 getContext().mpSubsettableShapeManager,
156*cdf0e10cSrcweir                 getSlideSize(),
157*cdf0e10cSrcweir                 AnimationFactory::FLAG_NO_SPRITE ),
158*cdf0e10cSrcweir             aValue );
159*cdf0e10cSrcweir     }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     case AnimationFactory::CLASS_STRING_PROPERTY:
162*cdf0e10cSrcweir     {
163*cdf0e10cSrcweir         StringAnimation::ValueType aValue;
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir         ENSURE_OR_THROW(
166*cdf0e10cSrcweir             extractValue( aValue,
167*cdf0e10cSrcweir                           xAnimateNode->getTo(),
168*cdf0e10cSrcweir                           pShape,
169*cdf0e10cSrcweir                           getSlideSize() ),
170*cdf0e10cSrcweir             "AnimationSetNode::createSetActivity(): "
171*cdf0e10cSrcweir             "Could not import string to value" );
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir         return makeSetActivity(
174*cdf0e10cSrcweir             aParms,
175*cdf0e10cSrcweir             AnimationFactory::createStringPropertyAnimation(
176*cdf0e10cSrcweir                 attrName,
177*cdf0e10cSrcweir                 pShape,
178*cdf0e10cSrcweir                 getContext().mpSubsettableShapeManager,
179*cdf0e10cSrcweir                 getSlideSize(),
180*cdf0e10cSrcweir                 AnimationFactory::FLAG_NO_SPRITE ),
181*cdf0e10cSrcweir             aValue );
182*cdf0e10cSrcweir     }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     case AnimationFactory::CLASS_BOOL_PROPERTY:
185*cdf0e10cSrcweir     {
186*cdf0e10cSrcweir         BoolAnimation::ValueType aValue;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir         ENSURE_OR_THROW(
189*cdf0e10cSrcweir             extractValue( aValue,
190*cdf0e10cSrcweir                           xAnimateNode->getTo(),
191*cdf0e10cSrcweir                           pShape,
192*cdf0e10cSrcweir                           getSlideSize() ),
193*cdf0e10cSrcweir             "AnimationSetNode::createSetActivity(): "
194*cdf0e10cSrcweir             "Could not import bool to value" );
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir         return makeSetActivity(
197*cdf0e10cSrcweir             aParms,
198*cdf0e10cSrcweir             AnimationFactory::createBoolPropertyAnimation(
199*cdf0e10cSrcweir                 attrName,
200*cdf0e10cSrcweir                 pShape,
201*cdf0e10cSrcweir                 getContext().mpSubsettableShapeManager,
202*cdf0e10cSrcweir                 getSlideSize(),
203*cdf0e10cSrcweir                 AnimationFactory::FLAG_NO_SPRITE ),
204*cdf0e10cSrcweir             aValue );
205*cdf0e10cSrcweir     }
206*cdf0e10cSrcweir     }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir     return AnimationActivitySharedPtr();
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir } // namespace internal
212*cdf0e10cSrcweir } // namespace slideshow
213*cdf0e10cSrcweir 
214