1*aaef562fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*aaef562fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*aaef562fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*aaef562fSAndrew Rist  * distributed with this work for additional information
6*aaef562fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*aaef562fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*aaef562fSAndrew Rist  * "License"); you may not use this file except in compliance
9*aaef562fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*aaef562fSAndrew Rist  *
11*aaef562fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*aaef562fSAndrew Rist  *
13*aaef562fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*aaef562fSAndrew Rist  * software distributed under the License is distributed on an
15*aaef562fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*aaef562fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*aaef562fSAndrew Rist  * specific language governing permissions and limitations
18*aaef562fSAndrew Rist  * under the License.
19*aaef562fSAndrew Rist  *
20*aaef562fSAndrew Rist  *************************************************************/
21*aaef562fSAndrew Rist 
22*aaef562fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_USEREVENTQUEUE_HXX
25cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_USEREVENTQUEUE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/animations/XAnimationNode.hpp>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "eventmultiplexer.hxx"
30cdf0e10cSrcweir #include "eventqueue.hxx"
31cdf0e10cSrcweir #include "shape.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <boost/noncopyable.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /* Definition of UserEventQueue class */
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace slideshow {
38cdf0e10cSrcweir namespace internal {
39cdf0e10cSrcweir 
40cdf0e10cSrcweir class PlainEventHandler;
41cdf0e10cSrcweir class AllAnimationEventHandler;
42cdf0e10cSrcweir class ShapeClickEventHandler;
43cdf0e10cSrcweir class ClickEventHandler;
44cdf0e10cSrcweir class CursorManager;
45cdf0e10cSrcweir class SkipEffectEventHandler;
46cdf0e10cSrcweir class RewindEffectEventHandler;
47cdf0e10cSrcweir class MouseEnterHandler;
48cdf0e10cSrcweir class MouseLeaveHandler;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir /** This class schedules user-activated events.
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     This class registeres at the EventMultiplexer and fires
53cdf0e10cSrcweir     events registered for certain user actions. Note that all
54cdf0e10cSrcweir     events will not be fired immediately after the user action
55cdf0e10cSrcweir     occured, but always added to the EventQueue (and fired the
56cdf0e10cSrcweir     next time that queue is processed). Which is actually a
57cdf0e10cSrcweir     feature.
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     Conceptually, an event is an object that typically is
60cdf0e10cSrcweir     fired only once. After that, the event is exhausted, and
61cdf0e10cSrcweir     should be discarded. Therefore, all events registered on
62cdf0e10cSrcweir     this object are fired and then all references to them are
63cdf0e10cSrcweir     removed.
64cdf0e10cSrcweir */
65cdf0e10cSrcweir class UserEventQueue : private ::boost::noncopyable
66cdf0e10cSrcweir {
67cdf0e10cSrcweir public:
68cdf0e10cSrcweir     /** Create a user event queue
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         @param rEventMultiplexer
71cdf0e10cSrcweir         The slideshow-global event source, where this class
72cdf0e10cSrcweir         registeres its event handlers.
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         @param rEventQueue
75cdf0e10cSrcweir         Reference to the main event queue. Since we hold this
76cdf0e10cSrcweir         object by plain reference, it must live longer than we
77cdf0e10cSrcweir         do. On the other hand, that queue must not fire events
78cdf0e10cSrcweir         after this object is destroyed, since we might
79cdf0e10cSrcweir         schedule events there which itself contain plain
80cdf0e10cSrcweir         references to this object. Basically, EventQueue and
81cdf0e10cSrcweir         UserEventQueue should have the same lifetime, and since
82cdf0e10cSrcweir         this is not possible, both must be destructed in a
83cdf0e10cSrcweir         phased mode: first clear both of any remaining events,
84cdf0e10cSrcweir         then destruct them.
85cdf0e10cSrcweir     */
86cdf0e10cSrcweir     UserEventQueue( EventMultiplexer&   rMultiplexer,
87cdf0e10cSrcweir                     EventQueue&         rEventQueue,
88cdf0e10cSrcweir                     CursorManager&      rCursorManager );
89cdf0e10cSrcweir     ~UserEventQueue();
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     /** Query whether there are any events still pending.
92cdf0e10cSrcweir      */
93cdf0e10cSrcweir     bool isEmpty() const;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     /** Clear all registered events.
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         This method clears all registered, but
98cdf0e10cSrcweir         not-yet-executed events. This comes in handy when
99cdf0e10cSrcweir         force-ending a slide, to avoid interference with the
100cdf0e10cSrcweir         next slide's event registration.
101cdf0e10cSrcweir     */
102cdf0e10cSrcweir     void clear();
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     /** Set advance on click behaviour.
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         @param bAdvanceOnClick
107cdf0e10cSrcweir         When true, a click somewhere on the slide will also
108cdf0e10cSrcweir         generate next effect event.  In this case, it is
109cdf0e10cSrcweir         irrelevant where on the slide the mouse is clicked,
110cdf0e10cSrcweir         i.e. the shape need not be hit by the mouse.
111cdf0e10cSrcweir     */
112cdf0e10cSrcweir     void setAdvanceOnClick( bool bAdvanceOnClick );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     /** Register an event that will be fired when the slide is
115cdf0e10cSrcweir         just shown.
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         Note that <em>all</em> registered events will be fired
118cdf0e10cSrcweir         when the slide start occurs. This is in contrast to
119cdf0e10cSrcweir         the mouse events below.
120cdf0e10cSrcweir     */
121cdf0e10cSrcweir     void registerSlideStartEvent( const EventSharedPtr& rEvent );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     /** Register an event that will be fired when the slide is
124cdf0e10cSrcweir         about to vanish.
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         Note that <em>all</em> registered events will be fired
127cdf0e10cSrcweir         when the slide end occurs. This is in contrast to
128cdf0e10cSrcweir         the mouse events below.
129cdf0e10cSrcweir     */
130cdf0e10cSrcweir     void registerSlideEndEvent( const EventSharedPtr& rEvent );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     /** Register an event that will be fired when the given
133cdf0e10cSrcweir         animation node starts.
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         Note that <em>all</em> registered events will be fired
136cdf0e10cSrcweir         when the animation start occurs. This is in contrast to
137cdf0e10cSrcweir         the mouse events below.
138cdf0e10cSrcweir     */
139cdf0e10cSrcweir     void registerAnimationStartEvent(
140cdf0e10cSrcweir         const EventSharedPtr&                             rEvent,
141cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
142cdf0e10cSrcweir         ::com::sun::star::animations::XAnimationNode>&    xNode );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     /** Register an event that will be fired when the given
145cdf0e10cSrcweir         animation node ends its active duration.
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         Note that <em>all</em> registered events will be fired
148cdf0e10cSrcweir         when the animation end occurs. This is in contrast to
149cdf0e10cSrcweir         the mouse events below.
150cdf0e10cSrcweir     */
151cdf0e10cSrcweir     void registerAnimationEndEvent(
152cdf0e10cSrcweir         const EventSharedPtr&                               rEvent,
153cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
154cdf0e10cSrcweir         ::com::sun::star::animations::XAnimationNode>&      xNode );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     /** Register an event that will be fired when audio output
157cdf0e10cSrcweir         stopped for the given animation node.
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         Note that <em>all</em> registered events will be fired
160cdf0e10cSrcweir         when the audio stopping occurs. This is in contrast to
161cdf0e10cSrcweir         the mouse events below.
162cdf0e10cSrcweir     */
163cdf0e10cSrcweir     void registerAudioStoppedEvent(
164cdf0e10cSrcweir         const EventSharedPtr&                               rEvent,
165cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
166cdf0e10cSrcweir         ::com::sun::star::animations::XAnimationNode>&      xNode );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     /** Register an event that is fired when a shape is clicked
169cdf0e10cSrcweir 
170cdf0e10cSrcweir         For every mouse click, only one of the events
171cdf0e10cSrcweir         registered here is fired. The order of fired events is
172cdf0e10cSrcweir         the order of registration, i.e. the first event
173cdf0e10cSrcweir         registered will be the one fired for the first mouse
174cdf0e10cSrcweir         click on the given shape.
175cdf0e10cSrcweir     */
176cdf0e10cSrcweir     void registerShapeClickEvent( const EventSharedPtr& rEvent,
177cdf0e10cSrcweir                                   const ShapeSharedPtr& rShape );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     /** Registes an event that is fired when the current effects(s)
180cdf0e10cSrcweir         are skipped, .e.g. when the left mouse button is pressed.
181cdf0e10cSrcweir         Then, all registered events are fired and removed from this
182cdf0e10cSrcweir         queue.  After firing, a next effect event is issued to this
183cdf0e10cSrcweir         queue to start the next effect.
184cdf0e10cSrcweir         @param pEvent
185cdf0e10cSrcweir             The event to execute when skipping the current effect.
186cdf0e10cSrcweir         @param bSkipTriggersNextEffect
187cdf0e10cSrcweir             When <TRUE/> then after skipping the current effect the next
188cdf0e10cSrcweir             effect is triggered.  When <FALSE/> then the next effect is not
189cdf0e10cSrcweir             triggered.
190cdf0e10cSrcweir     */
191cdf0e10cSrcweir     void registerSkipEffectEvent(
192cdf0e10cSrcweir         EventSharedPtr const& pEvent,
193cdf0e10cSrcweir         const bool bSkipTriggersNextEffect);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     /** Registes an event that is fired when the current effects(s)
196cdf0e10cSrcweir         are rewound, .e.g. when the right mouse button is pressed.
197cdf0e10cSrcweir         Then, all registered events are fired and removed from this
198cdf0e10cSrcweir         queue.
199cdf0e10cSrcweir     */
200cdf0e10cSrcweir     void registerRewindEffectEvent( EventSharedPtr const& rEvent );
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     /** Register an event that is fired to show the next event
203cdf0e10cSrcweir 
204cdf0e10cSrcweir         For every next effect event, only one of the events
205cdf0e10cSrcweir         registered here is fired. The order of fired events is
206cdf0e10cSrcweir         the order of registration, i.e. the first event
207cdf0e10cSrcweir         registered will be the one fired for the first mouse
208cdf0e10cSrcweir         click. When advance-on-click (see method
209cdf0e10cSrcweir         setAdvanceOnClick()) is enabled, a mouse click
210cdf0e10cSrcweir         somewhere on the slide will also generate a next
211cdf0e10cSrcweir         effect event. In this case, it is irrelevant where on
212cdf0e10cSrcweir         the slide the mouse is clicked, i.e. the shape need
213cdf0e10cSrcweir         not be hit by the mouse.
214cdf0e10cSrcweir     */
215cdf0e10cSrcweir     void registerNextEffectEvent( const EventSharedPtr& rEvent );
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     /** Register an event that is fired on a double mouse
218cdf0e10cSrcweir         click on a shape
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         For every mouse double click, only one of the events
221cdf0e10cSrcweir         registered here is fired. The order of fired events is
222cdf0e10cSrcweir         the order of registration, i.e. the first event
223cdf0e10cSrcweir         registered will be the one fired for the first mouse
224cdf0e10cSrcweir         double click. It is irrelevant where on the slide the
225cdf0e10cSrcweir         mouse is clicked, i.e. the shape need not be hit by
226cdf0e10cSrcweir         the mouse.
227cdf0e10cSrcweir     */
228cdf0e10cSrcweir     void registerShapeDoubleClickEvent( const EventSharedPtr& rEvent,
229cdf0e10cSrcweir                                         const ShapeSharedPtr& rShape );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     /** Register an event that is fired on a double mouse click
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         For every mouse double click, only one of the events
234cdf0e10cSrcweir         registered here is fired. The order of fired events is
235cdf0e10cSrcweir         the order of registration, i.e. the first event
236cdf0e10cSrcweir         registered will be the one fired for the first mouse
237cdf0e10cSrcweir         double click. It is irrelevant where on the slide the
238cdf0e10cSrcweir         mouse is clicked, i.e. the shape need not be hit by
239cdf0e10cSrcweir         the mouse.
240cdf0e10cSrcweir     */
241cdf0e10cSrcweir     void registerDoubleClickEvent( const EventSharedPtr& rEvent );
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     /** Register an event that is fired when the mouse enters
244cdf0e10cSrcweir         the area of the given shape
245cdf0e10cSrcweir 
246cdf0e10cSrcweir         For every enter, only one of the events registered
247cdf0e10cSrcweir         here is fired. The order of fired events is the order
248cdf0e10cSrcweir         of registration, i.e. the first event registered will
249cdf0e10cSrcweir         be the one fired for the first time the mouse enters
250cdf0e10cSrcweir         the given shape.
251cdf0e10cSrcweir     */
252cdf0e10cSrcweir     void registerMouseEnterEvent( const EventSharedPtr& rEvent,
253cdf0e10cSrcweir                                   const ShapeSharedPtr& rShape );
254cdf0e10cSrcweir 
255cdf0e10cSrcweir     /** Register an event that is fired when the mouse leaves
256cdf0e10cSrcweir         the area of the given shape
257cdf0e10cSrcweir 
258cdf0e10cSrcweir         For every leave, only one of the events registered
259cdf0e10cSrcweir         here is fired. The order of fired events is the order
260cdf0e10cSrcweir         of registration, i.e. the first event registered will
261cdf0e10cSrcweir         be the one fired for the first time the mouse leaves
262cdf0e10cSrcweir         the given shape area.
263cdf0e10cSrcweir     */
264cdf0e10cSrcweir     void registerMouseLeaveEvent( const EventSharedPtr& rEvent,
265cdf0e10cSrcweir                                   const ShapeSharedPtr& rShape );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     /** Typically skipping the current effect is triggered by mouse clicks
268cdf0e10cSrcweir         or key presses that trigger the next effect.  This method allows the
269cdf0e10cSrcweir         skipping of effects to be triggered programatically.
270cdf0e10cSrcweir     */
271cdf0e10cSrcweir     void callSkipEffectEventHandler (void);
272cdf0e10cSrcweir 
273cdf0e10cSrcweir private:
274cdf0e10cSrcweir     /** Generically register an event on one of the handlers.
275cdf0e10cSrcweir 
276cdf0e10cSrcweir         If the handler is not yet created, do that and
277cdf0e10cSrcweir         register it via the Functor
278cdf0e10cSrcweir     */
279cdf0e10cSrcweir     template< typename Handler, typename Functor >
280cdf0e10cSrcweir     void registerEvent( ::boost::shared_ptr< Handler >& rHandler,
281cdf0e10cSrcweir                         const EventSharedPtr&           rEvent,
282cdf0e10cSrcweir                         const Functor&                  rRegistrationFunctor );
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     /** Generically register an event on one of the handlers.
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         If the handler is not yet created, do that and
287cdf0e10cSrcweir         register it via the Functor. This version of the
288cdf0e10cSrcweir         registerEvent method takes an additional parameter
289cdf0e10cSrcweir         rArg, which is passed as the second argument to
290cdf0e10cSrcweir         rHandler's addEvent() method.
291cdf0e10cSrcweir     */
292cdf0e10cSrcweir     template< typename Handler, typename Arg, typename Functor >
293cdf0e10cSrcweir     void registerEvent( ::boost::shared_ptr< Handler >& rHandler,
294cdf0e10cSrcweir                         const EventSharedPtr&           rEvent,
295cdf0e10cSrcweir                         const Arg&                      rArg,
296cdf0e10cSrcweir                         const Functor&                  rRegistrationFunctor );
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     EventMultiplexer&                               mrMultiplexer;
299cdf0e10cSrcweir     EventQueue&                                     mrEventQueue;
300cdf0e10cSrcweir     CursorManager&                                  mrCursorManager;
301cdf0e10cSrcweir 
302cdf0e10cSrcweir     ::boost::shared_ptr<PlainEventHandler>          mpStartEventHandler;
303cdf0e10cSrcweir     ::boost::shared_ptr<PlainEventHandler>          mpEndEventHandler;
304cdf0e10cSrcweir     ::boost::shared_ptr<AllAnimationEventHandler>   mpAnimationStartEventHandler;
305cdf0e10cSrcweir     ::boost::shared_ptr<AllAnimationEventHandler>   mpAnimationEndEventHandler;
306cdf0e10cSrcweir     ::boost::shared_ptr<AllAnimationEventHandler>   mpAudioStoppedEventHandler;
307cdf0e10cSrcweir     ::boost::shared_ptr<ShapeClickEventHandler>     mpShapeClickEventHandler;
308cdf0e10cSrcweir     ::boost::shared_ptr<ClickEventHandler>          mpClickEventHandler;
309cdf0e10cSrcweir     ::boost::shared_ptr<SkipEffectEventHandler>     mpSkipEffectEventHandler;
310cdf0e10cSrcweir     ::boost::shared_ptr<RewindEffectEventHandler>   mpRewindEffectEventHandler;
311cdf0e10cSrcweir     ::boost::shared_ptr<ShapeClickEventHandler>     mpShapeDoubleClickEventHandler;
312cdf0e10cSrcweir     ::boost::shared_ptr<ClickEventHandler>          mpDoubleClickEventHandler;
313cdf0e10cSrcweir     ::boost::shared_ptr<MouseEnterHandler>          mpMouseEnterHandler;
314cdf0e10cSrcweir     ::boost::shared_ptr<MouseLeaveHandler>          mpMouseLeaveHandler;
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     bool                                            mbAdvanceOnClick;
317cdf0e10cSrcweir };
318cdf0e10cSrcweir 
319cdf0e10cSrcweir } // namespace internal
320cdf0e10cSrcweir } // namespace presentation
321cdf0e10cSrcweir 
322cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_USEREVENTQUEUE_HXX */
323cdf0e10cSrcweir 
324