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 .
21 #include <comphelper/diagnose_ex.hxx>
23 #include <com/sun/star/drawing/XShape.hpp>
24 #include <com/sun/star/animations/XAnimationNode.hpp>
25 #include <com/sun/star/animations/Timing.hpp>
26 #include <com/sun/star/animations/EventTrigger.hpp>
27 #include <com/sun/star/animations/Event.hpp>
29 #include "generateevent.hxx"
30 #include <subsettableshapemanager.hxx>
31 #include <usereventqueue.hxx>
32 #include <slideshowcontext.hxx>
33 #include <delayevent.hxx>
35 namespace slideshow::internal
{
37 using namespace com::sun::star
;
39 EventSharedPtr
generateEvent(
40 uno::Any
const& rEventDescription
,
41 Delay::FunctorT
const& rFunctor
,
42 SlideShowContext
const& rContext
,
43 double nAdditionalDelay
)
45 EventSharedPtr pEvent
;
47 if (! rEventDescription
.hasValue())
50 animations::Timing eTiming
;
51 animations::Event aEvent
;
52 uno::Sequence
<uno::Any
> aSequence
;
55 if (rEventDescription
>>= eTiming
) {
57 case animations::Timing_INDEFINITE
:
58 break; // don't schedule no event
59 case animations::Timing_MEDIA
:
60 OSL_FAIL( "MEDIA timing not yet implemented!" );
63 ENSURE_OR_THROW( false, "unexpected case!" );
66 else if (rEventDescription
>>= aEvent
) {
68 // try to extract additional event delay
70 if (aEvent
.Offset
.hasValue() && !(aEvent
.Offset
>>= nDelay2
)) {
71 OSL_FAIL( "offset values apart from DOUBLE not "
72 "recognized in animations::Event!" );
75 // common vars used inside switch
76 uno::Reference
<animations::XAnimationNode
> xNode
;
77 uno::Reference
<drawing::XShape
> xShape
;
78 ShapeSharedPtr pShape
;
80 // TODO(F1): Respect aEvent.Repeat value
82 auto event2shape
= [&] () {
83 if (aEvent
.Source
>>= xShape
)
84 pShape
= rContext
.mpSubsettableShapeManager
->lookupShape(xShape
);
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 u
"generateEvent, BEGIN_EVENT"_ustr
);
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 u
"generateEvent, END_EVENT"_ustr
);
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
132 pEvent
= makeDelay( rFunctor
,
133 nDelay2
+ nAdditionalDelay
,
134 u
"generateEvent, ON_CLICK"_ustr
);
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
148 pEvent
= makeDelay( rFunctor
,
149 nDelay2
+ nAdditionalDelay
,
150 u
"generateEvent, ON_DBL_CLICK"_ustr
);
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
164 pEvent
= makeDelay( rFunctor
,
165 nDelay2
+ nAdditionalDelay
,
166 u
"generateEvent, ON_MOUSE_ENTER"_ustr
);
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
180 pEvent
= makeDelay( rFunctor
,
181 nDelay2
+ nAdditionalDelay
,
182 u
"generateEvent, ON_MOUSE_LEAVE"_ustr
);
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!" );
195 case animations::EventTrigger::ON_NEXT
:
196 pEvent
= makeDelay( rFunctor
,
197 nDelay2
+ nAdditionalDelay
,
198 u
"generateEvent, ON_NEXT"_ustr
);
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 u
"generateEvent, ON_STOP_AUDIO"_ustr
);
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 u
"generateEvent with delay"_ustr
);
228 // schedule delay event
229 rContext
.mrEventQueue
.addEvent( pEvent
);
235 } // namespace slideshow::internal
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */