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 // must be first
32*cdf0e10cSrcweir #include <canvas/debug.hxx>
33*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
34*cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimationNode.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/animations/Timing.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/animations/EventTrigger.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/animations/Event.hpp>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include "shape.hxx"
43*cdf0e10cSrcweir #include "subsettableshapemanager.hxx"
44*cdf0e10cSrcweir #include "usereventqueue.hxx"
45*cdf0e10cSrcweir #include "slideshowcontext.hxx"
46*cdf0e10cSrcweir #include "delayevent.hxx"
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir namespace slideshow {
49*cdf0e10cSrcweir namespace internal {
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir using namespace com::sun::star;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir EventSharedPtr generateEvent(
54*cdf0e10cSrcweir     uno::Any const& rEventDescription,
55*cdf0e10cSrcweir     Delay::FunctorT const& rFunctor,
56*cdf0e10cSrcweir     SlideShowContext const& rContext,
57*cdf0e10cSrcweir     double nAdditionalDelay )
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir     EventSharedPtr pEvent;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir     if (! rEventDescription.hasValue())
62*cdf0e10cSrcweir         return pEvent;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     animations::Timing eTiming;
65*cdf0e10cSrcweir     animations::Event aEvent;
66*cdf0e10cSrcweir     uno::Sequence<uno::Any> aSequence;
67*cdf0e10cSrcweir     double nDelay1 = 0;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     if (rEventDescription >>= eTiming) {
70*cdf0e10cSrcweir         switch (eTiming) {
71*cdf0e10cSrcweir         case animations::Timing_INDEFINITE:
72*cdf0e10cSrcweir             break; // don't schedule no event
73*cdf0e10cSrcweir         case animations::Timing_MEDIA:
74*cdf0e10cSrcweir             OSL_ENSURE( false, "MEDIA timing not yet implemented!" );
75*cdf0e10cSrcweir             break;
76*cdf0e10cSrcweir         default:
77*cdf0e10cSrcweir             ENSURE_OR_THROW( false, "unexpected case!" );
78*cdf0e10cSrcweir         }
79*cdf0e10cSrcweir     }
80*cdf0e10cSrcweir     else if (rEventDescription >>= aEvent) {
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir         // try to extract additional event delay
83*cdf0e10cSrcweir         double nDelay2 = 0.0;
84*cdf0e10cSrcweir         if (aEvent.Offset.hasValue() && !(aEvent.Offset >>= nDelay2)) {
85*cdf0e10cSrcweir             OSL_ENSURE( false, "offset values apart from DOUBLE not "
86*cdf0e10cSrcweir                         "recognized in animations::Event!" );
87*cdf0e10cSrcweir         }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir         // common vars used inside switch
90*cdf0e10cSrcweir         uno::Reference<animations::XAnimationNode> xNode;
91*cdf0e10cSrcweir         uno::Reference<drawing::XShape> xShape;
92*cdf0e10cSrcweir         ShapeSharedPtr pShape;
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir         // TODO(F1): Respect aEvent.Repeat value
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir         switch (aEvent.Trigger) {
97*cdf0e10cSrcweir         default:
98*cdf0e10cSrcweir             ENSURE_OR_THROW( false, "unexpected event trigger!" );
99*cdf0e10cSrcweir         case animations::EventTrigger::NONE:
100*cdf0e10cSrcweir             // no event at all
101*cdf0e10cSrcweir             break;
102*cdf0e10cSrcweir         case animations::EventTrigger::ON_BEGIN:
103*cdf0e10cSrcweir             OSL_ENSURE( false, "event trigger ON_BEGIN not yet implemented!" );
104*cdf0e10cSrcweir             break;
105*cdf0e10cSrcweir         case animations::EventTrigger::ON_END:
106*cdf0e10cSrcweir             OSL_ENSURE( false, "event trigger ON_END not yet implemented!" );
107*cdf0e10cSrcweir             break;
108*cdf0e10cSrcweir         case animations::EventTrigger::BEGIN_EVENT:
109*cdf0e10cSrcweir             // try to extract XAnimationNode event source
110*cdf0e10cSrcweir             if (aEvent.Source >>= xNode) {
111*cdf0e10cSrcweir                 pEvent = makeDelay( rFunctor,
112*cdf0e10cSrcweir                                     nDelay2 + nAdditionalDelay,
113*cdf0e10cSrcweir                                     "generateEvent, BEGIN_EVENT");
114*cdf0e10cSrcweir                 rContext.mrUserEventQueue.registerAnimationStartEvent(
115*cdf0e10cSrcweir                     pEvent, xNode );
116*cdf0e10cSrcweir             }
117*cdf0e10cSrcweir             else {
118*cdf0e10cSrcweir                 OSL_ENSURE(false, "could not extract source XAnimationNode "
119*cdf0e10cSrcweir                            "for BEGIN_EVENT!" );
120*cdf0e10cSrcweir             }
121*cdf0e10cSrcweir             break;
122*cdf0e10cSrcweir         case animations::EventTrigger::END_EVENT:
123*cdf0e10cSrcweir             // try to extract XAnimationNode event source
124*cdf0e10cSrcweir             if (aEvent.Source >>= xNode) {
125*cdf0e10cSrcweir                 pEvent = makeDelay( rFunctor,
126*cdf0e10cSrcweir                                     nDelay2 + nAdditionalDelay,
127*cdf0e10cSrcweir                                     "generateEvent, END_EVENT");
128*cdf0e10cSrcweir                 rContext.mrUserEventQueue.registerAnimationEndEvent(
129*cdf0e10cSrcweir                     pEvent, xNode );
130*cdf0e10cSrcweir             }
131*cdf0e10cSrcweir             else {
132*cdf0e10cSrcweir                 OSL_ENSURE( false, "could not extract source XAnimationNode "
133*cdf0e10cSrcweir                             "for END_EVENT!" );
134*cdf0e10cSrcweir             }
135*cdf0e10cSrcweir             break;
136*cdf0e10cSrcweir         case animations::EventTrigger::ON_CLICK:
137*cdf0e10cSrcweir             // try to extract XShape event source
138*cdf0e10cSrcweir             if ((aEvent.Source >>= xShape) &&
139*cdf0e10cSrcweir                 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
140*cdf0e10cSrcweir             {
141*cdf0e10cSrcweir                 pEvent = makeDelay( rFunctor,
142*cdf0e10cSrcweir                                     nDelay2 + nAdditionalDelay,
143*cdf0e10cSrcweir                                     "generateEvent, ON_CLICK");
144*cdf0e10cSrcweir                 rContext.mrUserEventQueue.registerShapeClickEvent(
145*cdf0e10cSrcweir                     pEvent, pShape );
146*cdf0e10cSrcweir             }
147*cdf0e10cSrcweir             else {
148*cdf0e10cSrcweir                 OSL_ENSURE( false, "could not extract source XAnimationNode "
149*cdf0e10cSrcweir                             "for ON_CLICK!" );
150*cdf0e10cSrcweir             }
151*cdf0e10cSrcweir             break;
152*cdf0e10cSrcweir         case animations::EventTrigger::ON_DBL_CLICK:
153*cdf0e10cSrcweir             // try to extract XShape event source
154*cdf0e10cSrcweir             if ((aEvent.Source >>= xShape) &&
155*cdf0e10cSrcweir                 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
156*cdf0e10cSrcweir             {
157*cdf0e10cSrcweir                 pEvent = makeDelay( rFunctor,
158*cdf0e10cSrcweir                                     nDelay2 + nAdditionalDelay,
159*cdf0e10cSrcweir                                     "generateEvent, ON_DBL_CLICK");
160*cdf0e10cSrcweir                 rContext.mrUserEventQueue.registerShapeDoubleClickEvent(
161*cdf0e10cSrcweir                     pEvent, pShape );
162*cdf0e10cSrcweir             }
163*cdf0e10cSrcweir             else {
164*cdf0e10cSrcweir                 OSL_ENSURE( false, "could not extract source XAnimationNode "
165*cdf0e10cSrcweir                             "for ON_DBL_CLICK!" );
166*cdf0e10cSrcweir             }
167*cdf0e10cSrcweir             break;
168*cdf0e10cSrcweir         case animations::EventTrigger::ON_MOUSE_ENTER:
169*cdf0e10cSrcweir             // try to extract XShape event source
170*cdf0e10cSrcweir             if ((aEvent.Source >>= xShape) &&
171*cdf0e10cSrcweir                 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
172*cdf0e10cSrcweir             {
173*cdf0e10cSrcweir                 pEvent = makeDelay( rFunctor,
174*cdf0e10cSrcweir                                     nDelay2 + nAdditionalDelay,
175*cdf0e10cSrcweir                                     "generateEvent, ON_MOUSE_ENTER");
176*cdf0e10cSrcweir                 rContext.mrUserEventQueue.registerMouseEnterEvent(
177*cdf0e10cSrcweir                     pEvent, pShape );
178*cdf0e10cSrcweir             }
179*cdf0e10cSrcweir             else {
180*cdf0e10cSrcweir                 OSL_ENSURE( false, "could not extract source XAnimationNode "
181*cdf0e10cSrcweir                             "for ON_MOUSE_ENTER!" );
182*cdf0e10cSrcweir             }
183*cdf0e10cSrcweir             break;
184*cdf0e10cSrcweir         case animations::EventTrigger::ON_MOUSE_LEAVE:
185*cdf0e10cSrcweir             // try to extract XShape event source
186*cdf0e10cSrcweir             if ((aEvent.Source >>= xShape) &&
187*cdf0e10cSrcweir                 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
188*cdf0e10cSrcweir             {
189*cdf0e10cSrcweir                 pEvent = makeDelay( rFunctor,
190*cdf0e10cSrcweir                                     nDelay2 + nAdditionalDelay,
191*cdf0e10cSrcweir                                     "generateEvent, ON_MOUSE_LEAVE");
192*cdf0e10cSrcweir                 rContext.mrUserEventQueue.registerMouseLeaveEvent(
193*cdf0e10cSrcweir                     pEvent, pShape );
194*cdf0e10cSrcweir             }
195*cdf0e10cSrcweir             else {
196*cdf0e10cSrcweir                 OSL_ENSURE( false, "could not extract source XAnimationNode "
197*cdf0e10cSrcweir                             "for ON_MOUSE_LEAVE!" );
198*cdf0e10cSrcweir             }
199*cdf0e10cSrcweir             break;
200*cdf0e10cSrcweir         case animations::EventTrigger::ON_PREV:
201*cdf0e10cSrcweir             OSL_ENSURE( false, "event trigger ON_PREV not yet implemented, "
202*cdf0e10cSrcweir                         "mapped to ON_NEXT!" );
203*cdf0e10cSrcweir             // FALLTHROUGH intended
204*cdf0e10cSrcweir         case animations::EventTrigger::ON_NEXT:
205*cdf0e10cSrcweir             pEvent = makeDelay( rFunctor,
206*cdf0e10cSrcweir                                 nDelay2 + nAdditionalDelay,
207*cdf0e10cSrcweir                                 "generateEvent, ON_NEXT");
208*cdf0e10cSrcweir             rContext.mrUserEventQueue.registerNextEffectEvent( pEvent );
209*cdf0e10cSrcweir             break;
210*cdf0e10cSrcweir         case animations::EventTrigger::ON_STOP_AUDIO:
211*cdf0e10cSrcweir             // try to extract XAnimationNode event source
212*cdf0e10cSrcweir             if (aEvent.Source >>= xNode) {
213*cdf0e10cSrcweir                 pEvent = makeDelay( rFunctor,
214*cdf0e10cSrcweir                                     nDelay2 + nAdditionalDelay,
215*cdf0e10cSrcweir                                     "generateEvent, ON_STOP_AUDIO");
216*cdf0e10cSrcweir                 rContext.mrUserEventQueue.registerAudioStoppedEvent(
217*cdf0e10cSrcweir                     pEvent, xNode );
218*cdf0e10cSrcweir             }
219*cdf0e10cSrcweir             else {
220*cdf0e10cSrcweir                 OSL_ENSURE( false, "could not extract source XAnimationNode "
221*cdf0e10cSrcweir                             "for ON_STOP_AUDIO!" );
222*cdf0e10cSrcweir             }
223*cdf0e10cSrcweir             break;
224*cdf0e10cSrcweir         case animations::EventTrigger::REPEAT:
225*cdf0e10cSrcweir             OSL_ENSURE( false, "event trigger REPEAT not yet implemented!" );
226*cdf0e10cSrcweir             break;
227*cdf0e10cSrcweir         }
228*cdf0e10cSrcweir     }
229*cdf0e10cSrcweir     else if (rEventDescription >>= aSequence) {
230*cdf0e10cSrcweir         OSL_ENSURE( false, "sequence of timing primitives "
231*cdf0e10cSrcweir                     "not yet implemented!" );
232*cdf0e10cSrcweir     }
233*cdf0e10cSrcweir     else if (rEventDescription >>= nDelay1) {
234*cdf0e10cSrcweir         pEvent = makeDelay( rFunctor,
235*cdf0e10cSrcweir                             nDelay1 + nAdditionalDelay,
236*cdf0e10cSrcweir                             "generateEvent with delay");
237*cdf0e10cSrcweir         // schedule delay event
238*cdf0e10cSrcweir         rContext.mrEventQueue.addEvent( pEvent );
239*cdf0e10cSrcweir     }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     return pEvent;
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir } // namespace internal
245*cdf0e10cSrcweir } // namespace slideshow
246*cdf0e10cSrcweir 
247