Update ooo320-m1
[ooovba.git] / slideshow / source / engine / animationnodes / generateevent.cxx
blobe9bc6736df4b8b7fa0820fa73157955c2202cfc6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: generateevent.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
34 // must be first
35 #include <canvas/debug.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <canvas/verbosetrace.hxx>
39 #include <com/sun/star/drawing/XShape.hpp>
40 #include <com/sun/star/animations/XAnimationNode.hpp>
41 #include <com/sun/star/animations/Timing.hpp>
42 #include <com/sun/star/animations/EventTrigger.hpp>
43 #include <com/sun/star/animations/Event.hpp>
45 #include "shape.hxx"
46 #include "subsettableshapemanager.hxx"
47 #include "usereventqueue.hxx"
48 #include "slideshowcontext.hxx"
49 #include "delayevent.hxx"
51 namespace slideshow {
52 namespace internal {
54 using namespace com::sun::star;
56 EventSharedPtr generateEvent(
57 uno::Any const& rEventDescription,
58 Delay::FunctorT const& rFunctor,
59 SlideShowContext const& rContext,
60 double nAdditionalDelay )
62 EventSharedPtr pEvent;
64 if (! rEventDescription.hasValue())
65 return pEvent;
67 animations::Timing eTiming;
68 animations::Event aEvent;
69 uno::Sequence<uno::Any> aSequence;
70 double nDelay1 = 0;
72 if (rEventDescription >>= eTiming) {
73 switch (eTiming) {
74 case animations::Timing_INDEFINITE:
75 break; // don't schedule no event
76 case animations::Timing_MEDIA:
77 OSL_ENSURE( false, "MEDIA timing not yet implemented!" );
78 break;
79 default:
80 ENSURE_OR_THROW( false, "unexpected case!" );
83 else if (rEventDescription >>= aEvent) {
85 // try to extract additional event delay
86 double nDelay2 = 0.0;
87 if (aEvent.Offset.hasValue() && !(aEvent.Offset >>= nDelay2)) {
88 OSL_ENSURE( false, "offset values apart from DOUBLE not "
89 "recognized in animations::Event!" );
92 // common vars used inside switch
93 uno::Reference<animations::XAnimationNode> xNode;
94 uno::Reference<drawing::XShape> xShape;
95 ShapeSharedPtr pShape;
97 // TODO(F1): Respect aEvent.Repeat value
99 switch (aEvent.Trigger) {
100 default:
101 ENSURE_OR_THROW( false, "unexpected event trigger!" );
102 case animations::EventTrigger::NONE:
103 // no event at all
104 break;
105 case animations::EventTrigger::ON_BEGIN:
106 OSL_ENSURE( false, "event trigger ON_BEGIN not yet implemented!" );
107 break;
108 case animations::EventTrigger::ON_END:
109 OSL_ENSURE( false, "event trigger ON_END not yet implemented!" );
110 break;
111 case animations::EventTrigger::BEGIN_EVENT:
112 // try to extract XAnimationNode event source
113 if (aEvent.Source >>= xNode) {
114 pEvent = makeDelay( rFunctor, nDelay2 + nAdditionalDelay );
115 rContext.mrUserEventQueue.registerAnimationStartEvent(
116 pEvent, xNode );
118 else {
119 OSL_ENSURE(false, "could not extract source XAnimationNode "
120 "for BEGIN_EVENT!" );
122 break;
123 case animations::EventTrigger::END_EVENT:
124 // try to extract XAnimationNode event source
125 if (aEvent.Source >>= xNode) {
126 pEvent = makeDelay( rFunctor, nDelay2 + nAdditionalDelay );
127 rContext.mrUserEventQueue.registerAnimationEndEvent(
128 pEvent, xNode );
130 else {
131 OSL_ENSURE( false, "could not extract source XAnimationNode "
132 "for END_EVENT!" );
134 break;
135 case animations::EventTrigger::ON_CLICK:
136 // try to extract XShape event source
137 if ((aEvent.Source >>= xShape) &&
138 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
140 pEvent = makeDelay( rFunctor, nDelay2 + nAdditionalDelay );
141 rContext.mrUserEventQueue.registerShapeClickEvent(
142 pEvent, pShape );
144 else {
145 OSL_ENSURE( false, "could not extract source XAnimationNode "
146 "for ON_CLICK!" );
148 break;
149 case animations::EventTrigger::ON_DBL_CLICK:
150 // try to extract XShape event source
151 if ((aEvent.Source >>= xShape) &&
152 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
154 pEvent = makeDelay( rFunctor, nDelay2 + nAdditionalDelay );
155 rContext.mrUserEventQueue.registerShapeDoubleClickEvent(
156 pEvent, pShape );
158 else {
159 OSL_ENSURE( false, "could not extract source XAnimationNode "
160 "for ON_DBL_CLICK!" );
162 break;
163 case animations::EventTrigger::ON_MOUSE_ENTER:
164 // try to extract XShape event source
165 if ((aEvent.Source >>= xShape) &&
166 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
168 pEvent = makeDelay( rFunctor, nDelay2 + nAdditionalDelay );
169 rContext.mrUserEventQueue.registerMouseEnterEvent(
170 pEvent, pShape );
172 else {
173 OSL_ENSURE( false, "could not extract source XAnimationNode "
174 "for ON_MOUSE_ENTER!" );
176 break;
177 case animations::EventTrigger::ON_MOUSE_LEAVE:
178 // try to extract XShape event source
179 if ((aEvent.Source >>= xShape) &&
180 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
182 pEvent = makeDelay( rFunctor, nDelay2 + nAdditionalDelay );
183 rContext.mrUserEventQueue.registerMouseLeaveEvent(
184 pEvent, pShape );
186 else {
187 OSL_ENSURE( false, "could not extract source XAnimationNode "
188 "for ON_MOUSE_LEAVE!" );
190 break;
191 case animations::EventTrigger::ON_PREV:
192 OSL_ENSURE( false, "event trigger ON_PREV not yet implemented, "
193 "mapped to ON_NEXT!" );
194 // FALLTHROUGH intended
195 case animations::EventTrigger::ON_NEXT:
196 pEvent = makeDelay( rFunctor, nDelay2 + nAdditionalDelay );
197 rContext.mrUserEventQueue.registerNextEffectEvent( pEvent );
198 break;
199 case animations::EventTrigger::ON_STOP_AUDIO:
200 // try to extract XAnimationNode event source
201 if (aEvent.Source >>= xNode) {
202 pEvent = makeDelay( rFunctor, nDelay2 + nAdditionalDelay );
203 rContext.mrUserEventQueue.registerAudioStoppedEvent(
204 pEvent, xNode );
206 else {
207 OSL_ENSURE( false, "could not extract source XAnimationNode "
208 "for ON_STOP_AUDIO!" );
210 break;
211 case animations::EventTrigger::REPEAT:
212 OSL_ENSURE( false, "event trigger REPEAT not yet implemented!" );
213 break;
216 else if (rEventDescription >>= aSequence) {
217 OSL_ENSURE( false, "sequence of timing primitives "
218 "not yet implemented!" );
220 else if (rEventDescription >>= nDelay1) {
221 pEvent = makeDelay( rFunctor, nDelay1 + nAdditionalDelay );
222 // schedule delay event
223 rContext.mrEventQueue.addEvent( pEvent );
226 return pEvent;
229 } // namespace internal
230 } // namespace slideshow