1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <canvas/debug.hxx>
23 #include <tools/diagnose_ex.h>
24 #include <canvas/verbosetrace.hxx>
26 #include <com/sun/star/drawing/XShape.hpp>
27 #include <com/sun/star/animations/XAnimationNode.hpp>
28 #include <com/sun/star/animations/Timing.hpp>
29 #include <com/sun/star/animations/EventTrigger.hpp>
30 #include <com/sun/star/animations/Event.hpp>
32 #include "generateevent.hxx"
34 #include "subsettableshapemanager.hxx"
35 #include "usereventqueue.hxx"
36 #include "slideshowcontext.hxx"
37 #include "delayevent.hxx"
42 using namespace com::sun::star
;
44 EventSharedPtr
generateEvent(
45 uno::Any
const& rEventDescription
,
46 Delay::FunctorT
const& rFunctor
,
47 SlideShowContext
const& rContext
,
48 double nAdditionalDelay
)
50 EventSharedPtr pEvent
;
52 if (! rEventDescription
.hasValue())
55 animations::Timing eTiming
;
56 animations::Event aEvent
;
57 uno::Sequence
<uno::Any
> aSequence
;
60 if (rEventDescription
>>= eTiming
) {
62 case animations::Timing_INDEFINITE
:
63 break; // don't schedule no event
64 case animations::Timing_MEDIA
:
65 OSL_FAIL( "MEDIA timing not yet implemented!" );
68 ENSURE_OR_THROW( false, "unexpected case!" );
71 else if (rEventDescription
>>= aEvent
) {
73 // try to extract additional event delay
75 if (aEvent
.Offset
.hasValue() && !(aEvent
.Offset
>>= nDelay2
)) {
76 OSL_FAIL( "offset values apart from DOUBLE not "
77 "recognized in animations::Event!" );
80 // common vars used inside switch
81 uno::Reference
<animations::XAnimationNode
> xNode
;
82 uno::Reference
<drawing::XShape
> xShape
;
83 ShapeSharedPtr pShape
;
85 // TODO(F1): Respect aEvent.Repeat value
87 switch (aEvent
.Trigger
) {
89 ENSURE_OR_THROW( false, "unexpected event trigger!" );
90 case animations::EventTrigger::NONE
:
93 case animations::EventTrigger::ON_BEGIN
:
94 OSL_FAIL( "event trigger ON_BEGIN not yet implemented!" );
96 case animations::EventTrigger::ON_END
:
97 OSL_FAIL( "event trigger ON_END not yet implemented!" );
99 case animations::EventTrigger::BEGIN_EVENT
:
100 // try to extract XAnimationNode event source
101 if (aEvent
.Source
>>= xNode
) {
102 pEvent
= makeDelay( rFunctor
,
103 nDelay2
+ nAdditionalDelay
,
104 "generateEvent, BEGIN_EVENT");
105 rContext
.mrUserEventQueue
.registerAnimationStartEvent(
109 OSL_FAIL("could not extract source XAnimationNode "
110 "for BEGIN_EVENT!" );
113 case animations::EventTrigger::END_EVENT
:
114 // try to extract XAnimationNode event source
115 if (aEvent
.Source
>>= xNode
) {
116 pEvent
= makeDelay( rFunctor
,
117 nDelay2
+ nAdditionalDelay
,
118 "generateEvent, END_EVENT");
119 rContext
.mrUserEventQueue
.registerAnimationEndEvent(
123 OSL_FAIL( "could not extract source XAnimationNode "
127 case animations::EventTrigger::ON_CLICK
:
128 // try to extract XShape event source
129 if ((aEvent
.Source
>>= xShape
) &&
130 (pShape
= rContext
.mpSubsettableShapeManager
->lookupShape(xShape
)).get())
132 pEvent
= makeDelay( rFunctor
,
133 nDelay2
+ nAdditionalDelay
,
134 "generateEvent, ON_CLICK");
135 rContext
.mrUserEventQueue
.registerShapeClickEvent(
139 OSL_FAIL( "could not extract source XAnimationNode "
143 case animations::EventTrigger::ON_DBL_CLICK
:
144 // try to extract XShape event source
145 if ((aEvent
.Source
>>= xShape
) &&
146 (pShape
= rContext
.mpSubsettableShapeManager
->lookupShape(xShape
)).get())
148 pEvent
= makeDelay( rFunctor
,
149 nDelay2
+ nAdditionalDelay
,
150 "generateEvent, ON_DBL_CLICK");
151 rContext
.mrUserEventQueue
.registerShapeDoubleClickEvent(
155 OSL_FAIL( "could not extract source XAnimationNode "
156 "for ON_DBL_CLICK!" );
159 case animations::EventTrigger::ON_MOUSE_ENTER
:
160 // try to extract XShape event source
161 if ((aEvent
.Source
>>= xShape
) &&
162 (pShape
= rContext
.mpSubsettableShapeManager
->lookupShape(xShape
)).get())
164 pEvent
= makeDelay( rFunctor
,
165 nDelay2
+ nAdditionalDelay
,
166 "generateEvent, ON_MOUSE_ENTER");
167 rContext
.mrUserEventQueue
.registerMouseEnterEvent(
171 OSL_FAIL( "could not extract source XAnimationNode "
172 "for ON_MOUSE_ENTER!" );
175 case animations::EventTrigger::ON_MOUSE_LEAVE
:
176 // try to extract XShape event source
177 if ((aEvent
.Source
>>= xShape
) &&
178 (pShape
= rContext
.mpSubsettableShapeManager
->lookupShape(xShape
)).get())
180 pEvent
= makeDelay( rFunctor
,
181 nDelay2
+ nAdditionalDelay
,
182 "generateEvent, ON_MOUSE_LEAVE");
183 rContext
.mrUserEventQueue
.registerMouseLeaveEvent(
187 OSL_FAIL( "could not extract source XAnimationNode "
188 "for ON_MOUSE_LEAVE!" );
191 case animations::EventTrigger::ON_PREV
:
192 OSL_FAIL( "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
,
197 nDelay2
+ nAdditionalDelay
,
198 "generateEvent, ON_NEXT");
199 rContext
.mrUserEventQueue
.registerNextEffectEvent( pEvent
);
201 case animations::EventTrigger::ON_STOP_AUDIO
:
202 // try to extract XAnimationNode event source
203 if (aEvent
.Source
>>= xNode
) {
204 pEvent
= makeDelay( rFunctor
,
205 nDelay2
+ nAdditionalDelay
,
206 "generateEvent, ON_STOP_AUDIO");
207 rContext
.mrUserEventQueue
.registerAudioStoppedEvent(
211 OSL_FAIL( "could not extract source XAnimationNode "
212 "for ON_STOP_AUDIO!" );
215 case animations::EventTrigger::REPEAT
:
216 OSL_FAIL( "event trigger REPEAT not yet implemented!" );
220 else if (rEventDescription
>>= aSequence
) {
221 OSL_FAIL( "sequence of timing primitives "
222 "not yet implemented!" );
224 else if (rEventDescription
>>= nDelay1
) {
225 pEvent
= makeDelay( rFunctor
,
226 nDelay1
+ nAdditionalDelay
,
227 "generateEvent with delay");
228 // schedule delay event
229 rContext
.mrEventQueue
.addEvent( pEvent
);
235 } // namespace internal
236 } // namespace slideshow
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */