1*70f497fbSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*70f497fbSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*70f497fbSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*70f497fbSAndrew Rist * distributed with this work for additional information
6*70f497fbSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*70f497fbSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*70f497fbSAndrew Rist * "License"); you may not use this file except in compliance
9*70f497fbSAndrew Rist * with the License. You may obtain a copy of the License at
10*70f497fbSAndrew Rist *
11*70f497fbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*70f497fbSAndrew Rist *
13*70f497fbSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*70f497fbSAndrew Rist * software distributed under the License is distributed on an
15*70f497fbSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*70f497fbSAndrew Rist * KIND, either express or implied. See the License for the
17*70f497fbSAndrew Rist * specific language governing permissions and limitations
18*70f497fbSAndrew Rist * under the License.
19*70f497fbSAndrew Rist *
20*70f497fbSAndrew Rist *************************************************************/
21*70f497fbSAndrew Rist
22*70f497fbSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_slideshow.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // must be first
28cdf0e10cSrcweir #include <canvas/debug.hxx>
29cdf0e10cSrcweir #include <tools/diagnose_ex.h>
30cdf0e10cSrcweir #include <canvas/verbosetrace.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp>
33cdf0e10cSrcweir #include <com/sun/star/animations/XAnimationNode.hpp>
34cdf0e10cSrcweir #include <com/sun/star/animations/Timing.hpp>
35cdf0e10cSrcweir #include <com/sun/star/animations/EventTrigger.hpp>
36cdf0e10cSrcweir #include <com/sun/star/animations/Event.hpp>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include "shape.hxx"
39cdf0e10cSrcweir #include "subsettableshapemanager.hxx"
40cdf0e10cSrcweir #include "usereventqueue.hxx"
41cdf0e10cSrcweir #include "slideshowcontext.hxx"
42cdf0e10cSrcweir #include "delayevent.hxx"
43cdf0e10cSrcweir
44cdf0e10cSrcweir namespace slideshow {
45cdf0e10cSrcweir namespace internal {
46cdf0e10cSrcweir
47cdf0e10cSrcweir using namespace com::sun::star;
48cdf0e10cSrcweir
generateEvent(uno::Any const & rEventDescription,Delay::FunctorT const & rFunctor,SlideShowContext const & rContext,double nAdditionalDelay)49cdf0e10cSrcweir EventSharedPtr generateEvent(
50cdf0e10cSrcweir uno::Any const& rEventDescription,
51cdf0e10cSrcweir Delay::FunctorT const& rFunctor,
52cdf0e10cSrcweir SlideShowContext const& rContext,
53cdf0e10cSrcweir double nAdditionalDelay )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir EventSharedPtr pEvent;
56cdf0e10cSrcweir
57cdf0e10cSrcweir if (! rEventDescription.hasValue())
58cdf0e10cSrcweir return pEvent;
59cdf0e10cSrcweir
60cdf0e10cSrcweir animations::Timing eTiming;
61cdf0e10cSrcweir animations::Event aEvent;
62cdf0e10cSrcweir uno::Sequence<uno::Any> aSequence;
63cdf0e10cSrcweir double nDelay1 = 0;
64cdf0e10cSrcweir
65cdf0e10cSrcweir if (rEventDescription >>= eTiming) {
66cdf0e10cSrcweir switch (eTiming) {
67cdf0e10cSrcweir case animations::Timing_INDEFINITE:
68cdf0e10cSrcweir break; // don't schedule no event
69cdf0e10cSrcweir case animations::Timing_MEDIA:
70cdf0e10cSrcweir OSL_ENSURE( false, "MEDIA timing not yet implemented!" );
71cdf0e10cSrcweir break;
72cdf0e10cSrcweir default:
73cdf0e10cSrcweir ENSURE_OR_THROW( false, "unexpected case!" );
74cdf0e10cSrcweir }
75cdf0e10cSrcweir }
76cdf0e10cSrcweir else if (rEventDescription >>= aEvent) {
77cdf0e10cSrcweir
78cdf0e10cSrcweir // try to extract additional event delay
79cdf0e10cSrcweir double nDelay2 = 0.0;
80cdf0e10cSrcweir if (aEvent.Offset.hasValue() && !(aEvent.Offset >>= nDelay2)) {
81cdf0e10cSrcweir OSL_ENSURE( false, "offset values apart from DOUBLE not "
82cdf0e10cSrcweir "recognized in animations::Event!" );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
85cdf0e10cSrcweir // common vars used inside switch
86cdf0e10cSrcweir uno::Reference<animations::XAnimationNode> xNode;
87cdf0e10cSrcweir uno::Reference<drawing::XShape> xShape;
88cdf0e10cSrcweir ShapeSharedPtr pShape;
89cdf0e10cSrcweir
90cdf0e10cSrcweir // TODO(F1): Respect aEvent.Repeat value
91cdf0e10cSrcweir
92cdf0e10cSrcweir switch (aEvent.Trigger) {
93cdf0e10cSrcweir default:
94cdf0e10cSrcweir ENSURE_OR_THROW( false, "unexpected event trigger!" );
95cdf0e10cSrcweir case animations::EventTrigger::NONE:
96cdf0e10cSrcweir // no event at all
97cdf0e10cSrcweir break;
98cdf0e10cSrcweir case animations::EventTrigger::ON_BEGIN:
99cdf0e10cSrcweir OSL_ENSURE( false, "event trigger ON_BEGIN not yet implemented!" );
100cdf0e10cSrcweir break;
101cdf0e10cSrcweir case animations::EventTrigger::ON_END:
102cdf0e10cSrcweir OSL_ENSURE( false, "event trigger ON_END not yet implemented!" );
103cdf0e10cSrcweir break;
104cdf0e10cSrcweir case animations::EventTrigger::BEGIN_EVENT:
105cdf0e10cSrcweir // try to extract XAnimationNode event source
106cdf0e10cSrcweir if (aEvent.Source >>= xNode) {
107cdf0e10cSrcweir pEvent = makeDelay( rFunctor,
108cdf0e10cSrcweir nDelay2 + nAdditionalDelay,
109cdf0e10cSrcweir "generateEvent, BEGIN_EVENT");
110cdf0e10cSrcweir rContext.mrUserEventQueue.registerAnimationStartEvent(
111cdf0e10cSrcweir pEvent, xNode );
112cdf0e10cSrcweir }
113cdf0e10cSrcweir else {
114cdf0e10cSrcweir OSL_ENSURE(false, "could not extract source XAnimationNode "
115cdf0e10cSrcweir "for BEGIN_EVENT!" );
116cdf0e10cSrcweir }
117cdf0e10cSrcweir break;
118cdf0e10cSrcweir case animations::EventTrigger::END_EVENT:
119cdf0e10cSrcweir // try to extract XAnimationNode event source
120cdf0e10cSrcweir if (aEvent.Source >>= xNode) {
121cdf0e10cSrcweir pEvent = makeDelay( rFunctor,
122cdf0e10cSrcweir nDelay2 + nAdditionalDelay,
123cdf0e10cSrcweir "generateEvent, END_EVENT");
124cdf0e10cSrcweir rContext.mrUserEventQueue.registerAnimationEndEvent(
125cdf0e10cSrcweir pEvent, xNode );
126cdf0e10cSrcweir }
127cdf0e10cSrcweir else {
128cdf0e10cSrcweir OSL_ENSURE( false, "could not extract source XAnimationNode "
129cdf0e10cSrcweir "for END_EVENT!" );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir break;
132cdf0e10cSrcweir case animations::EventTrigger::ON_CLICK:
133cdf0e10cSrcweir // try to extract XShape event source
134cdf0e10cSrcweir if ((aEvent.Source >>= xShape) &&
135cdf0e10cSrcweir (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
136cdf0e10cSrcweir {
137cdf0e10cSrcweir pEvent = makeDelay( rFunctor,
138cdf0e10cSrcweir nDelay2 + nAdditionalDelay,
139cdf0e10cSrcweir "generateEvent, ON_CLICK");
140cdf0e10cSrcweir rContext.mrUserEventQueue.registerShapeClickEvent(
141cdf0e10cSrcweir pEvent, pShape );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir else {
144cdf0e10cSrcweir OSL_ENSURE( false, "could not extract source XAnimationNode "
145cdf0e10cSrcweir "for ON_CLICK!" );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir break;
148cdf0e10cSrcweir case animations::EventTrigger::ON_DBL_CLICK:
149cdf0e10cSrcweir // try to extract XShape event source
150cdf0e10cSrcweir if ((aEvent.Source >>= xShape) &&
151cdf0e10cSrcweir (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
152cdf0e10cSrcweir {
153cdf0e10cSrcweir pEvent = makeDelay( rFunctor,
154cdf0e10cSrcweir nDelay2 + nAdditionalDelay,
155cdf0e10cSrcweir "generateEvent, ON_DBL_CLICK");
156cdf0e10cSrcweir rContext.mrUserEventQueue.registerShapeDoubleClickEvent(
157cdf0e10cSrcweir pEvent, pShape );
158cdf0e10cSrcweir }
159cdf0e10cSrcweir else {
160cdf0e10cSrcweir OSL_ENSURE( false, "could not extract source XAnimationNode "
161cdf0e10cSrcweir "for ON_DBL_CLICK!" );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir break;
164cdf0e10cSrcweir case animations::EventTrigger::ON_MOUSE_ENTER:
165cdf0e10cSrcweir // try to extract XShape event source
166cdf0e10cSrcweir if ((aEvent.Source >>= xShape) &&
167cdf0e10cSrcweir (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
168cdf0e10cSrcweir {
169cdf0e10cSrcweir pEvent = makeDelay( rFunctor,
170cdf0e10cSrcweir nDelay2 + nAdditionalDelay,
171cdf0e10cSrcweir "generateEvent, ON_MOUSE_ENTER");
172cdf0e10cSrcweir rContext.mrUserEventQueue.registerMouseEnterEvent(
173cdf0e10cSrcweir pEvent, pShape );
174cdf0e10cSrcweir }
175cdf0e10cSrcweir else {
176cdf0e10cSrcweir OSL_ENSURE( false, "could not extract source XAnimationNode "
177cdf0e10cSrcweir "for ON_MOUSE_ENTER!" );
178cdf0e10cSrcweir }
179cdf0e10cSrcweir break;
180cdf0e10cSrcweir case animations::EventTrigger::ON_MOUSE_LEAVE:
181cdf0e10cSrcweir // try to extract XShape event source
182cdf0e10cSrcweir if ((aEvent.Source >>= xShape) &&
183cdf0e10cSrcweir (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
184cdf0e10cSrcweir {
185cdf0e10cSrcweir pEvent = makeDelay( rFunctor,
186cdf0e10cSrcweir nDelay2 + nAdditionalDelay,
187cdf0e10cSrcweir "generateEvent, ON_MOUSE_LEAVE");
188cdf0e10cSrcweir rContext.mrUserEventQueue.registerMouseLeaveEvent(
189cdf0e10cSrcweir pEvent, pShape );
190cdf0e10cSrcweir }
191cdf0e10cSrcweir else {
192cdf0e10cSrcweir OSL_ENSURE( false, "could not extract source XAnimationNode "
193cdf0e10cSrcweir "for ON_MOUSE_LEAVE!" );
194cdf0e10cSrcweir }
195cdf0e10cSrcweir break;
196cdf0e10cSrcweir case animations::EventTrigger::ON_PREV:
197cdf0e10cSrcweir OSL_ENSURE( false, "event trigger ON_PREV not yet implemented, "
198cdf0e10cSrcweir "mapped to ON_NEXT!" );
199cdf0e10cSrcweir // FALLTHROUGH intended
200cdf0e10cSrcweir case animations::EventTrigger::ON_NEXT:
201cdf0e10cSrcweir pEvent = makeDelay( rFunctor,
202cdf0e10cSrcweir nDelay2 + nAdditionalDelay,
203cdf0e10cSrcweir "generateEvent, ON_NEXT");
204cdf0e10cSrcweir rContext.mrUserEventQueue.registerNextEffectEvent( pEvent );
205cdf0e10cSrcweir break;
206cdf0e10cSrcweir case animations::EventTrigger::ON_STOP_AUDIO:
207cdf0e10cSrcweir // try to extract XAnimationNode event source
208cdf0e10cSrcweir if (aEvent.Source >>= xNode) {
209cdf0e10cSrcweir pEvent = makeDelay( rFunctor,
210cdf0e10cSrcweir nDelay2 + nAdditionalDelay,
211cdf0e10cSrcweir "generateEvent, ON_STOP_AUDIO");
212cdf0e10cSrcweir rContext.mrUserEventQueue.registerAudioStoppedEvent(
213cdf0e10cSrcweir pEvent, xNode );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir else {
216cdf0e10cSrcweir OSL_ENSURE( false, "could not extract source XAnimationNode "
217cdf0e10cSrcweir "for ON_STOP_AUDIO!" );
218cdf0e10cSrcweir }
219cdf0e10cSrcweir break;
220cdf0e10cSrcweir case animations::EventTrigger::REPEAT:
221cdf0e10cSrcweir OSL_ENSURE( false, "event trigger REPEAT not yet implemented!" );
222cdf0e10cSrcweir break;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir }
225cdf0e10cSrcweir else if (rEventDescription >>= aSequence) {
226cdf0e10cSrcweir OSL_ENSURE( false, "sequence of timing primitives "
227cdf0e10cSrcweir "not yet implemented!" );
228cdf0e10cSrcweir }
229cdf0e10cSrcweir else if (rEventDescription >>= nDelay1) {
230cdf0e10cSrcweir pEvent = makeDelay( rFunctor,
231cdf0e10cSrcweir nDelay1 + nAdditionalDelay,
232cdf0e10cSrcweir "generateEvent with delay");
233cdf0e10cSrcweir // schedule delay event
234cdf0e10cSrcweir rContext.mrEventQueue.addEvent( pEvent );
235cdf0e10cSrcweir }
236cdf0e10cSrcweir
237cdf0e10cSrcweir return pEvent;
238cdf0e10cSrcweir }
239cdf0e10cSrcweir
240cdf0e10cSrcweir } // namespace internal
241cdf0e10cSrcweir } // namespace slideshow
242cdf0e10cSrcweir
243