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