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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_slideshow.hxx"
30 
31 #include <canvas/debug.hxx>
32 #include <canvas/verbosetrace.hxx>
33 
34 #include "animationfactory.hxx"
35 #include "setactivity.hxx"
36 #include "animationsetnode.hxx"
37 #include "nodetools.hxx"
38 #include "tools.hxx"
39 #include "delayevent.hxx"
40 
41 #include <boost/bind.hpp>
42 
43 using namespace com::sun::star;
44 
45 namespace slideshow {
46 namespace internal {
47 
48 void AnimationSetNode::implScheduleDeactivationEvent()
49 {
50     scheduleDeactivationEvent();
51 }
52 
53 AnimationActivitySharedPtr AnimationSetNode::createActivity() const
54 {
55     ActivitiesFactory::CommonParameters aParms( fillCommonParameters() );
56     uno::Reference<animations::XAnimate> const xAnimateNode = getXAnimateNode();
57     rtl::OUString const attrName( xAnimateNode->getAttributeName() );
58     AttributableShapeSharedPtr const pShape( getShape() );
59 
60     // make deactivation a two-step procedure. Normally, we
61     // could solely rely on
62     // BaseNode::scheduleDeactivationEvent() to deactivate()
63     // us. Unfortunately, that method on the one hand ignores
64     // indefinite timing, on the other hand generates
65     // zero-timeout delays, which might get fired _before_ our
66     // set activity has taken place. Therefore, we enforce
67     // sequentiality by letting only the set activity schedule
68     // the deactivation event (and AnimationBaseNode
69     // takes care for the fact when mpActivity should be zero).
70 
71     // AnimationBaseNode::fillCommonParameters() has set up
72     // immediate deactivation as default when activity ends, but
73     if (! isIndefiniteTiming( xAnimateNode->getDuration() )) {
74         boost::shared_ptr<AnimationSetNode> const pSelf(
75             boost::dynamic_pointer_cast<AnimationSetNode>(getSelf()) );
76         ENSURE_OR_THROW(
77             pSelf, "cannot cast getSelf() to my type!" );
78         aParms.mpEndEvent = makeEvent(
79             boost::bind( &AnimationSetNode::implScheduleDeactivationEvent,
80                          pSelf ),
81             "AnimationSetNode::implScheduleDeactivationEvent");
82     }
83 
84     switch (AnimationFactory::classifyAttributeName( attrName )) {
85     default:
86     case AnimationFactory::CLASS_UNKNOWN_PROPERTY:
87         ENSURE_OR_THROW(
88             false, "AnimationSetNode::createSetActivity(): "
89             "Unexpected attribute class" );
90         break;
91 
92     case AnimationFactory::CLASS_NUMBER_PROPERTY:
93     {
94         NumberAnimation::ValueType aValue;
95 
96         ENSURE_OR_THROW(
97             extractValue( aValue,
98                           xAnimateNode->getTo(),
99                           pShape,
100                           getSlideSize() ),
101             "AnimationSetNode::createSetActivity(): "
102             "Could not import numeric to value" );
103 
104         return makeSetActivity(
105             aParms,
106             AnimationFactory::createNumberPropertyAnimation(
107                 attrName,
108                 pShape,
109                 getContext().mpSubsettableShapeManager,
110                 getSlideSize(),
111                 AnimationFactory::FLAG_NO_SPRITE ),
112             aValue );
113     }
114 
115     case AnimationFactory::CLASS_ENUM_PROPERTY:
116     {
117         EnumAnimation::ValueType aValue;
118 
119         ENSURE_OR_THROW(
120             extractValue( aValue,
121                           xAnimateNode->getTo(),
122                           pShape,
123                           getSlideSize() ),
124             "AnimationSetNode::createSetActivity(): "
125             "Could not import enum to value" );
126 
127         return makeSetActivity(
128             aParms,
129             AnimationFactory::createEnumPropertyAnimation(
130                 attrName,
131                 pShape,
132                 getContext().mpSubsettableShapeManager,
133                 getSlideSize(),
134                 AnimationFactory::FLAG_NO_SPRITE ),
135             aValue );
136     }
137 
138     case AnimationFactory::CLASS_COLOR_PROPERTY:
139     {
140         ColorAnimation::ValueType aValue;
141 
142         ENSURE_OR_THROW(
143             extractValue( aValue,
144                           xAnimateNode->getTo(),
145                           pShape,
146                           getSlideSize() ),
147             "AnimationSetNode::createSetActivity(): "
148             "Could not import color to value" );
149 
150         return makeSetActivity(
151             aParms,
152             AnimationFactory::createColorPropertyAnimation(
153                 attrName,
154                 pShape,
155                 getContext().mpSubsettableShapeManager,
156                 getSlideSize(),
157                 AnimationFactory::FLAG_NO_SPRITE ),
158             aValue );
159     }
160 
161     case AnimationFactory::CLASS_STRING_PROPERTY:
162     {
163         StringAnimation::ValueType aValue;
164 
165         ENSURE_OR_THROW(
166             extractValue( aValue,
167                           xAnimateNode->getTo(),
168                           pShape,
169                           getSlideSize() ),
170             "AnimationSetNode::createSetActivity(): "
171             "Could not import string to value" );
172 
173         return makeSetActivity(
174             aParms,
175             AnimationFactory::createStringPropertyAnimation(
176                 attrName,
177                 pShape,
178                 getContext().mpSubsettableShapeManager,
179                 getSlideSize(),
180                 AnimationFactory::FLAG_NO_SPRITE ),
181             aValue );
182     }
183 
184     case AnimationFactory::CLASS_BOOL_PROPERTY:
185     {
186         BoolAnimation::ValueType aValue;
187 
188         ENSURE_OR_THROW(
189             extractValue( aValue,
190                           xAnimateNode->getTo(),
191                           pShape,
192                           getSlideSize() ),
193             "AnimationSetNode::createSetActivity(): "
194             "Could not import bool to value" );
195 
196         return makeSetActivity(
197             aParms,
198             AnimationFactory::createBoolPropertyAnimation(
199                 attrName,
200                 pShape,
201                 getContext().mpSubsettableShapeManager,
202                 getSlideSize(),
203                 AnimationFactory::FLAG_NO_SPRITE ),
204             aValue );
205     }
206     }
207 
208     return AnimationActivitySharedPtr();
209 }
210 
211 } // namespace internal
212 } // namespace slideshow
213 
214