build fix
[LibreOffice.git] / slideshow / source / engine / animationnodes / generateevent.cxx
blob513f0bc889b31f4f062cae6d62d3f780b1b1b16b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/diagnose_ex.h>
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 "shape.hxx"
31 #include "subsettableshapemanager.hxx"
32 #include "usereventqueue.hxx"
33 #include "slideshowcontext.hxx"
34 #include "delayevent.hxx"
36 namespace slideshow {
37 namespace internal {
39 using namespace com::sun::star;
41 EventSharedPtr generateEvent(
42 uno::Any const& rEventDescription,
43 Delay::FunctorT const& rFunctor,
44 SlideShowContext const& rContext,
45 double nAdditionalDelay )
47 EventSharedPtr pEvent;
49 if (! rEventDescription.hasValue())
50 return pEvent;
52 animations::Timing eTiming;
53 animations::Event aEvent;
54 uno::Sequence<uno::Any> aSequence;
55 double nDelay1 = 0;
57 if (rEventDescription >>= eTiming) {
58 switch (eTiming) {
59 case animations::Timing_INDEFINITE:
60 break; // don't schedule no event
61 case animations::Timing_MEDIA:
62 OSL_FAIL( "MEDIA timing not yet implemented!" );
63 break;
64 default:
65 ENSURE_OR_THROW( false, "unexpected case!" );
68 else if (rEventDescription >>= aEvent) {
70 // try to extract additional event delay
71 double nDelay2 = 0.0;
72 if (aEvent.Offset.hasValue() && !(aEvent.Offset >>= nDelay2)) {
73 OSL_FAIL( "offset values apart from DOUBLE not "
74 "recognized in animations::Event!" );
77 // common vars used inside switch
78 uno::Reference<animations::XAnimationNode> xNode;
79 uno::Reference<drawing::XShape> xShape;
80 ShapeSharedPtr pShape;
82 // TODO(F1): Respect aEvent.Repeat value
84 switch (aEvent.Trigger) {
85 default:
86 ENSURE_OR_THROW( false, "unexpected event trigger!" );
87 case animations::EventTrigger::NONE:
88 // no event at all
89 break;
90 case animations::EventTrigger::ON_BEGIN:
91 OSL_FAIL( "event trigger ON_BEGIN not yet implemented!" );
92 break;
93 case animations::EventTrigger::ON_END:
94 OSL_FAIL( "event trigger ON_END not yet implemented!" );
95 break;
96 case animations::EventTrigger::BEGIN_EVENT:
97 // try to extract XAnimationNode event source
98 if (aEvent.Source >>= xNode) {
99 pEvent = makeDelay( rFunctor,
100 nDelay2 + nAdditionalDelay,
101 "generateEvent, BEGIN_EVENT");
102 rContext.mrUserEventQueue.registerAnimationStartEvent(
103 pEvent, xNode );
105 else {
106 OSL_FAIL("could not extract source XAnimationNode "
107 "for BEGIN_EVENT!" );
109 break;
110 case animations::EventTrigger::END_EVENT:
111 // try to extract XAnimationNode event source
112 if (aEvent.Source >>= xNode) {
113 pEvent = makeDelay( rFunctor,
114 nDelay2 + nAdditionalDelay,
115 "generateEvent, END_EVENT");
116 rContext.mrUserEventQueue.registerAnimationEndEvent(
117 pEvent, xNode );
119 else {
120 OSL_FAIL( "could not extract source XAnimationNode "
121 "for END_EVENT!" );
123 break;
124 case animations::EventTrigger::ON_CLICK:
125 // try to extract XShape event source
126 if ((aEvent.Source >>= xShape) &&
127 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
129 pEvent = makeDelay( rFunctor,
130 nDelay2 + nAdditionalDelay,
131 "generateEvent, ON_CLICK");
132 rContext.mrUserEventQueue.registerShapeClickEvent(
133 pEvent, pShape );
135 else {
136 OSL_FAIL( "could not extract source XAnimationNode "
137 "for ON_CLICK!" );
139 break;
140 case animations::EventTrigger::ON_DBL_CLICK:
141 // try to extract XShape event source
142 if ((aEvent.Source >>= xShape) &&
143 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
145 pEvent = makeDelay( rFunctor,
146 nDelay2 + nAdditionalDelay,
147 "generateEvent, ON_DBL_CLICK");
148 rContext.mrUserEventQueue.registerShapeDoubleClickEvent(
149 pEvent, pShape );
151 else {
152 OSL_FAIL( "could not extract source XAnimationNode "
153 "for ON_DBL_CLICK!" );
155 break;
156 case animations::EventTrigger::ON_MOUSE_ENTER:
157 // try to extract XShape event source
158 if ((aEvent.Source >>= xShape) &&
159 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
161 pEvent = makeDelay( rFunctor,
162 nDelay2 + nAdditionalDelay,
163 "generateEvent, ON_MOUSE_ENTER");
164 rContext.mrUserEventQueue.registerMouseEnterEvent(
165 pEvent, pShape );
167 else {
168 OSL_FAIL( "could not extract source XAnimationNode "
169 "for ON_MOUSE_ENTER!" );
171 break;
172 case animations::EventTrigger::ON_MOUSE_LEAVE:
173 // try to extract XShape event source
174 if ((aEvent.Source >>= xShape) &&
175 (pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape)).get())
177 pEvent = makeDelay( rFunctor,
178 nDelay2 + nAdditionalDelay,
179 "generateEvent, ON_MOUSE_LEAVE");
180 rContext.mrUserEventQueue.registerMouseLeaveEvent(
181 pEvent, pShape );
183 else {
184 OSL_FAIL( "could not extract source XAnimationNode "
185 "for ON_MOUSE_LEAVE!" );
187 break;
188 case animations::EventTrigger::ON_PREV:
189 OSL_FAIL( "event trigger ON_PREV not yet implemented, "
190 "mapped to ON_NEXT!" );
191 SAL_FALLTHROUGH;
192 case animations::EventTrigger::ON_NEXT:
193 pEvent = makeDelay( rFunctor,
194 nDelay2 + nAdditionalDelay,
195 "generateEvent, ON_NEXT");
196 rContext.mrUserEventQueue.registerNextEffectEvent( pEvent );
197 break;
198 case animations::EventTrigger::ON_STOP_AUDIO:
199 // try to extract XAnimationNode event source
200 if (aEvent.Source >>= xNode) {
201 pEvent = makeDelay( rFunctor,
202 nDelay2 + nAdditionalDelay,
203 "generateEvent, ON_STOP_AUDIO");
204 rContext.mrUserEventQueue.registerAudioStoppedEvent(
205 pEvent, xNode );
207 else {
208 OSL_FAIL( "could not extract source XAnimationNode "
209 "for ON_STOP_AUDIO!" );
211 break;
212 case animations::EventTrigger::REPEAT:
213 OSL_FAIL( "event trigger REPEAT not yet implemented!" );
214 break;
217 else if (rEventDescription >>= aSequence) {
218 OSL_FAIL( "sequence of timing primitives "
219 "not yet implemented!" );
221 else if (rEventDescription >>= nDelay1) {
222 pEvent = makeDelay( rFunctor,
223 nDelay1 + nAdditionalDelay,
224 "generateEvent with delay");
225 // schedule delay event
226 rContext.mrEventQueue.addEvent( pEvent );
229 return pEvent;
232 } // namespace internal
233 } // namespace slideshow
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */