LibreOffice Module slideshow (master) 1
generateevent.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
22
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>
28
29#include "generateevent.hxx"
31#include <usereventqueue.hxx>
32#include <slideshowcontext.hxx>
33#include <delayevent.hxx>
34
35namespace slideshow::internal {
36
37using namespace com::sun::star;
38
40 uno::Any const& rEventDescription,
41 Delay::FunctorT const& rFunctor,
42 SlideShowContext const& rContext,
43 double nAdditionalDelay )
44{
45 EventSharedPtr pEvent;
46
47 if (! rEventDescription.hasValue())
48 return pEvent;
49
50 animations::Timing eTiming;
51 animations::Event aEvent;
53 double nDelay1 = 0;
54
55 if (rEventDescription >>= eTiming) {
56 switch (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!" );
61 break;
62 default:
63 ENSURE_OR_THROW( false, "unexpected case!" );
64 }
65 }
66 else if (rEventDescription >>= aEvent) {
67
68 // try to extract additional event delay
69 double nDelay2 = 0.0;
70 if (aEvent.Offset.hasValue() && !(aEvent.Offset >>= nDelay2)) {
71 OSL_FAIL( "offset values apart from DOUBLE not "
72 "recognized in animations::Event!" );
73 }
74
75 // common vars used inside switch
78 ShapeSharedPtr pShape;
79
80 // TODO(F1): Respect aEvent.Repeat value
81
82 auto event2shape = [&] () {
83 if (aEvent.Source >>= xShape)
84 pShape = rContext.mpSubsettableShapeManager->lookupShape(xShape);
85 };
86
87 switch (aEvent.Trigger) {
88 default:
89 ENSURE_OR_THROW( false, "unexpected event trigger!" );
90 case animations::EventTrigger::NONE:
91 // no event at all
92 break;
93 case animations::EventTrigger::ON_BEGIN:
94 OSL_FAIL( "event trigger ON_BEGIN not yet implemented!" );
95 break;
96 case animations::EventTrigger::ON_END:
97 OSL_FAIL( "event trigger ON_END not yet implemented!" );
98 break;
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");
106 pEvent, xNode );
107 }
108 else {
109 OSL_FAIL("could not extract source XAnimationNode "
110 "for BEGIN_EVENT!" );
111 }
112 break;
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");
120 pEvent, xNode );
121 }
122 else {
123 OSL_FAIL( "could not extract source XAnimationNode "
124 "for END_EVENT!" );
125 }
126 break;
127 case animations::EventTrigger::ON_CLICK:
128 // try to extract XShape event source
129 event2shape();
130 if (pShape)
131 {
132 pEvent = makeDelay( rFunctor,
133 nDelay2 + nAdditionalDelay,
134 "generateEvent, ON_CLICK");
136 pEvent, pShape );
137 }
138 else {
139 OSL_FAIL( "could not extract source XAnimationNode "
140 "for ON_CLICK!" );
141 }
142 break;
143 case animations::EventTrigger::ON_DBL_CLICK:
144 // try to extract XShape event source
145 event2shape();
146 if (pShape)
147 {
148 pEvent = makeDelay( rFunctor,
149 nDelay2 + nAdditionalDelay,
150 "generateEvent, ON_DBL_CLICK");
152 pEvent, pShape );
153 }
154 else {
155 OSL_FAIL( "could not extract source XAnimationNode "
156 "for ON_DBL_CLICK!" );
157 }
158 break;
159 case animations::EventTrigger::ON_MOUSE_ENTER:
160 // try to extract XShape event source
161 event2shape();
162 if (pShape)
163 {
164 pEvent = makeDelay( rFunctor,
165 nDelay2 + nAdditionalDelay,
166 "generateEvent, ON_MOUSE_ENTER");
168 pEvent, pShape );
169 }
170 else {
171 OSL_FAIL( "could not extract source XAnimationNode "
172 "for ON_MOUSE_ENTER!" );
173 }
174 break;
175 case animations::EventTrigger::ON_MOUSE_LEAVE:
176 // try to extract XShape event source
177 event2shape();
178 if (pShape)
179 {
180 pEvent = makeDelay( rFunctor,
181 nDelay2 + nAdditionalDelay,
182 "generateEvent, ON_MOUSE_LEAVE");
184 pEvent, pShape );
185 }
186 else {
187 OSL_FAIL( "could not extract source XAnimationNode "
188 "for ON_MOUSE_LEAVE!" );
189 }
190 break;
191 case animations::EventTrigger::ON_PREV:
192 OSL_FAIL( "event trigger ON_PREV not yet implemented, "
193 "mapped to ON_NEXT!" );
194 [[fallthrough]];
195 case animations::EventTrigger::ON_NEXT:
196 pEvent = makeDelay( rFunctor,
197 nDelay2 + nAdditionalDelay,
198 "generateEvent, ON_NEXT");
199 rContext.mrUserEventQueue.registerNextEffectEvent( pEvent );
200 break;
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");
208 pEvent, xNode );
209 }
210 else {
211 OSL_FAIL( "could not extract source XAnimationNode "
212 "for ON_STOP_AUDIO!" );
213 }
214 break;
215 case animations::EventTrigger::REPEAT:
216 OSL_FAIL( "event trigger REPEAT not yet implemented!" );
217 break;
218 }
219 }
220 else if (rEventDescription >>= aSequence) {
221 OSL_FAIL( "sequence of timing primitives "
222 "not yet implemented!" );
223 }
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 );
230 }
231
232 return pEvent;
233}
234
235} // namespace slideshow::internal
236
237/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
::std::function< void()> FunctorT
Definition: delayevent.hxx:34
bool addEvent(const EventSharedPtr &event)
Add the given event to the queue.
Definition: eventqueue.cxx:79
void registerNextEffectEvent(const EventSharedPtr &rEvent)
Register an event that is fired to show the next event.
void registerShapeClickEvent(const EventSharedPtr &rEvent, const ShapeSharedPtr &rShape)
Register an event that is fired when a shape is clicked.
void registerAnimationStartEvent(const EventSharedPtr &rEvent, const css::uno::Reference< css::animations::XAnimationNode > &xNode)
Register an event that will be fired when the given animation node starts.
void registerMouseLeaveEvent(const EventSharedPtr &rEvent, const ShapeSharedPtr &rShape)
Register an event that is fired when the mouse leaves the area of the given shape.
void registerShapeDoubleClickEvent(const EventSharedPtr &rEvent, const ShapeSharedPtr &rShape)
Register an event that is fired on a double mouse click on a shape.
void registerAudioStoppedEvent(const EventSharedPtr &rEvent, const css::uno::Reference< css::animations::XAnimationNode > &xNode)
Register an event that will be fired when audio output stopped for the given animation node.
void registerMouseEnterEvent(const EventSharedPtr &rEvent, const ShapeSharedPtr &rShape)
Register an event that is fired when the mouse enters the area of the given shape.
void registerAnimationEndEvent(const EventSharedPtr &rEvent, const css::uno::Reference< css::animations::XAnimationNode > &xNode)
Register an event that will be fired when the given animation node ends its active duration.
#define makeDelay(f, t, d)
Definition: delayevent.hxx:128
#define ENSURE_OR_THROW(c, m)
::std::shared_ptr< Event > EventSharedPtr
Definition: event.hxx:76
::std::shared_ptr< Shape > ShapeSharedPtr
EventSharedPtr generateEvent(uno::Any const &rEventDescription, Delay::FunctorT const &rFunctor, SlideShowContext const &rContext, double nAdditionalDelay)
Common arguments for slideshow objects.
std::shared_ptr< SubsettableShapeManager > & mpSubsettableShapeManager
bool hasValue()