Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / inc / eventmultiplexer.hxx
blob5a34fc08bcd03f45514441d1ceb54b0fad132efa
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 .
19 #ifndef INCLUDED_SLIDESHOW_SOURCE_INC_EVENTMULTIPLEXER_HXX
20 #define INCLUDED_SLIDESHOW_SOURCE_INC_EVENTMULTIPLEXER_HXX
22 #include "eventhandler.hxx"
23 #include "mouseeventhandler.hxx"
24 #include "animationeventhandler.hxx"
25 #include "pauseeventhandler.hxx"
26 #include "shapelistenereventhandler.hxx"
27 #include "vieweventhandler.hxx"
29 #include <memory>
30 #include <com/sun/star/uno/Reference.hxx>
32 #include "unoview.hxx"
34 namespace com { namespace sun { namespace star { namespace drawing
36 class XShape;
37 } } } }
39 namespace slideshow {
40 namespace internal {
42 class EventQueue;
43 class UnoViewContainer;
44 class AnimationNode;
46 struct EventMultiplexerImpl;
48 class RGBColor;
50 /** Interface for handling view repaint events.
52 Classes implementing this interface can be added to an
53 EventMultiplexer object, and are called from there to
54 handle view repaint events.
56 class ViewRepaintHandler
58 public:
59 virtual ~ViewRepaintHandler() {}
61 /** Notify clobbered view.
63 Reasons for a viewChanged notification can be
64 different view size, transformation, or other device
65 properties (color resolution or profile, etc.)
67 @param rView
68 The changed view
70 virtual void viewClobbered( const UnoViewSharedPtr& rView ) = 0;
73 typedef ::std::shared_ptr< ViewRepaintHandler > ViewRepaintHandlerSharedPtr;
75 /** Interface for handling hyperlink clicks.
77 Classes implementing this interface can be added to an
78 EventMultiplexer object, and are called from there to
79 handle hyperlink events.
81 class HyperlinkHandler
83 public:
84 /** Handle the event.
86 @param rLink
87 The actual hyperlink URI
89 @return true, if this handler has successfully
90 processed the event. When this method returns false,
91 possibly other, less prioritized handlers are called,
92 too.
94 virtual bool handleHyperlink( OUString const& rLink ) = 0;
96 protected:
97 ~HyperlinkHandler() {}
100 typedef ::std::shared_ptr< HyperlinkHandler > HyperlinkHandlerSharedPtr;
102 /** Interface for handling user paint state changes.
104 Classes implementing this interface can be added to an
105 EventMultiplexer object, and are called from there to
106 handle user paint events.
108 class UserPaintEventHandler
110 public:
111 virtual ~UserPaintEventHandler() {}
112 virtual bool colorChanged( RGBColor const& rUserColor ) = 0;
113 virtual bool widthChanged( double nUserStrokeWidth ) = 0;
114 virtual bool eraseAllInkChanged(bool bEraseAllInk) =0;
115 virtual bool eraseInkWidthChanged(sal_Int32 rEraseInkSize) =0;
116 virtual bool switchEraserMode() = 0;
117 virtual bool switchPenMode() = 0;
118 virtual bool disable() = 0;
121 typedef ::std::shared_ptr< UserPaintEventHandler > UserPaintEventHandlerSharedPtr;
123 /** This class multiplexes user-activated and
124 slide-show global events.
126 This class listens at the XSlideShowView and fires events
127 registered for certain user actions. Furthermore, global
128 slide show state changes (such as start or end of a slide)
129 are handled as well. Note that registered events which
130 have a non-zero timeout (i.e. events that return non-zero
131 from getActivationTime()) will not be fired immediately
132 after the user action occurred, but only after the given
133 timeout. Which is actually a feature.
135 class EventMultiplexer
137 public:
138 /** Create an event multiplexer
140 @param rEventQueue
141 Reference to the main event queue. Since we hold this
142 object by plain reference, it must live longer than we
143 do. On the other hand, that queue must not fire events
144 after this object is destroyed, since we might
145 schedule events there which itself contain plain
146 references to this object. Basically, EventQueue and
147 EventMultiplexer should have the same lifetime, and since
148 this is not possible, both must be destructed in a
149 phased mode: first clear both of any remaining events,
150 then destruct them.
152 @param rViewContainer
153 Globally managed list of all registered views. Used to
154 determine event sources, and for registering view listeners
157 EventMultiplexer( EventQueue& rEventQueue,
158 UnoViewContainer const& rViewContainer );
159 ~EventMultiplexer();
160 EventMultiplexer(const EventMultiplexer&) = delete;
161 EventMultiplexer& operator=(const EventMultiplexer&) = delete;
163 // Management methods
166 /** Clear all registered handlers.
168 void clear();
171 // Automatic mode methods
174 /** Change automatic mode.
176 @param bIsAuto
177 When true, events will be fired automatically, not
178 only triggered by UI events. When false, auto events
179 will quit.
181 void setAutomaticMode( bool bIsAuto );
183 /** Get automatic mode setting.
185 bool getAutomaticMode() const;
187 /** Set the timeout for automatic mode.
189 @param nTimeout
190 Timeout, between end of effect until start of next
191 effect.
193 void setAutomaticTimeout( double nTimeout );
195 /** Get automatic mode timeout value.
197 double getAutomaticTimeout() const;
199 // Handler registration methods
202 /** Register an event handler that will be called when views are
203 changed.
205 For each view added, viewAdded() will be called on the
206 handler. For each view removed, viewRemoved() will be
207 called. Each modified view will cause a viewChanged() call on
208 each handler.
210 You don't need to deregister the handler, it will be
211 automatically removed, once the pointee becomes stale.
213 @param rHandler
214 Handler to call.
216 void addViewHandler( const ViewEventHandlerWeakPtr& rHandler );
217 void removeViewHandler( const ViewEventHandlerWeakPtr& rHandler );
219 /** Register an event handler that will be called when a view gets
220 clobbered.
222 Note that <em>all</em> registered handlers will be called when
223 the event. This is in contrast to the mouse events below.
225 @param rHandler
226 Handler to call when a view needs a repaint
228 void addViewRepaintHandler( const ViewRepaintHandlerSharedPtr& rHandler );
229 void removeViewRepaintHandler( const ViewRepaintHandlerSharedPtr& rHandler );
231 /** Register an event handler that will be called when
232 XShapeListeners are changed.
234 @param rHandler
235 Handler to call when a shape listener changes
237 void addShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr& rHandler );
238 void removeShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr& rHandler );
240 /** Register an event handler that will be called when
241 user paint parameters change.
243 @param rHandler
244 Handler to call when a shape listener changes
246 void addUserPaintHandler( const UserPaintEventHandlerSharedPtr& rHandler );
248 /** Register an event handler that will be called when the
249 user requests the next effect.
251 For every nextEffect event, only one of the handlers
252 registered here is called. The handlers are considered
253 with decreasing priority, i.e. the handler with the
254 currently highest priority will be called.
256 @param rHandler
257 Handler to call when the next effect should start
259 @param nPriority
260 Priority with which the handlers are called. The
261 higher the priority, the earlier this handler will be
262 tried.
264 void addNextEffectHandler( const EventHandlerSharedPtr& rHandler,
265 double nPriority );
266 void removeNextEffectHandler( const EventHandlerSharedPtr& rHandler );
268 /** Register an event handler that will be called when the
269 slide is just shown.
271 Note that <em>all</em> registered handlers will be called
272 when the slide start occurs. This is in contrast to
273 the mouse events below.
275 @param rHandler
276 Handler to call when the next slide starts
278 void addSlideStartHandler( const EventHandlerSharedPtr& rHandler );
279 void removeSlideStartHandler( const EventHandlerSharedPtr& rHandler );
281 /** Register an event handler that will be called when the
282 slide is about to vanish.
284 Note that <em>all</em> registered handlers will be
285 called when the slide end occurs. This is in contrast
286 to the mouse events below.
288 @param rHandler
289 Handler to call when the current slide ends
291 void addSlideEndHandler( const EventHandlerSharedPtr& rHandler );
292 void removeSlideEndHandler( const EventHandlerSharedPtr& rHandler );
294 /** Register an event handler that will be called when an
295 XAnimationNode starts its active duration.
297 Note that <em>all</em> registered handlers will be called
298 when the animation start occurs. This is in contrast to
299 the mouse events below.
301 @param rHandler
302 Handler to call when the animation start
304 void addAnimationStartHandler(
305 const AnimationEventHandlerSharedPtr& rHandler );
306 void removeAnimationStartHandler(
307 const AnimationEventHandlerSharedPtr& rHandler );
309 /** Register an event handler that will be called when an
310 XAnimationNode ends its active duration.
312 Note that <em>all</em> registered handlers will be called
313 when the animation end occurs. This is in contrast to
314 the mouse events below.
316 @param rHandler
317 Handler to call when the animation ends
319 void addAnimationEndHandler(
320 const AnimationEventHandlerSharedPtr& rHandler );
321 void removeAnimationEndHandler(
322 const AnimationEventHandlerSharedPtr& rHandler );
324 /** Register an event handler that will be called when the
325 main animation sequence of a slide ends its active
326 duration.
328 Note that <em>all</em> registered handlers will be
329 called when the animation end occurs. This is in
330 contrast to the mouse events below.
332 @param rHandler
333 Handler to call when the animation ends
335 void addSlideAnimationsEndHandler(
336 const EventHandlerSharedPtr& rHandler );
337 void removeSlideAnimationsEndHandler(
338 const EventHandlerSharedPtr& rHandler );
340 /** Register an event handler that will be called when an
341 XAudio node's sound stops playing.
343 Note that <em>all</em> registered handlers will be
344 called when the audio stops. This is in contrast to
345 the mouse events below.
347 @param rHandler
348 Handler to call when the audio stops
350 void addAudioStoppedHandler(
351 const AnimationEventHandlerSharedPtr& rHandler );
352 void removeAudioStoppedHandler(
353 const AnimationEventHandlerSharedPtr& rHandler );
355 /** Register an event handler that will be called when an
356 XCommand node's with the command STOPAUDIO is activated.
358 Note that <em>all</em> registered handlers will be
359 called when the audio stops. This is in contrast to
360 the mouse events below.
362 @param rHandler
363 Handler to call when command is activated
365 void addCommandStopAudioHandler(
366 const AnimationEventHandlerSharedPtr& rHandler );
367 void removeCommandStopAudioHandler(
368 const AnimationEventHandlerSharedPtr& rHandler );
370 /** Register a handler that is called when the show enters
371 or exits pause mode.
373 void addPauseHandler( const PauseEventHandlerSharedPtr& rHandler );
374 void removePauseHandler( const PauseEventHandlerSharedPtr& rHandler );
376 /** Register a mouse handler that is called on mouse click
378 For every mouse click, only one of the handlers
379 registered here is called. The handlers are considered
380 with decreasing priority, i.e. the handler with the
381 currently highest priority will be called.
383 Since the handlers can reject down and up events
384 individually, handlers should expect to be called with
385 non-matching down and up-press counts. If your handler
386 cannot cope with that, it must have the highest
387 priority of all added handlers.
389 void addClickHandler( const MouseEventHandlerSharedPtr& rHandler,
390 double nPriority );
391 void removeClickHandler( const MouseEventHandlerSharedPtr& rHandler );
393 /** Register a mouse handler that is called on a double
394 mouse click
396 For every mouse double click, only one of the handlers
397 registered here is called. The handlers are considered
398 with decreasing priority, i.e. the handler with the
399 currently highest priority will be called.
401 Since the handlers can reject down and up events
402 individually, handlers should expect to be called with
403 non-matching down and up-press counts. If your handler
404 cannot cope with that, it must have the highest
405 priority of all added handlers.
407 void addDoubleClickHandler( const MouseEventHandlerSharedPtr& rHandler,
408 double nPriority );
409 void removeDoubleClickHandler( const MouseEventHandlerSharedPtr& rHandler );
411 /** Register a mouse handler that is called for mouse moves.
413 For every mouse move, only one of the handlers
414 registered here is called. The handlers are considered
415 with decreasing priority, i.e. the handler with the
416 currently highest priority will be called.
418 void addMouseMoveHandler( const MouseEventHandlerSharedPtr& rHandler,
419 double nPriority );
420 void removeMouseMoveHandler( const MouseEventHandlerSharedPtr& rHandler );
423 /** Registers a hyperlink click handler.
425 For every hyperlink click, only one of the handlers registered
426 here is called. The handlers are considered with decreasing
427 priority, i.e. the handler with the currently highest priority
428 will be called.
430 @param rHandler
431 @param nPriority
433 void addHyperlinkHandler( const HyperlinkHandlerSharedPtr& rHandler,
434 double nPriority );
435 void removeHyperlinkHandler( const HyperlinkHandlerSharedPtr& rHandler );
438 // External event notifications
441 /** View added.
443 This method adds another view, which the show is
444 displayed on. On every added view, the EventMultiplexer
445 registers mouse and motion event listeners.
447 void notifyViewAdded( const UnoViewSharedPtr& rView );
449 /** View removed
451 This method removes a view. Registered mouse and
452 motion event listeners are revoked.
454 void notifyViewRemoved( const UnoViewSharedPtr& rView );
456 /** View changed
458 This method announces a changed view to all view
459 listeners. View changes include size and transformation.
461 @param rView
462 View that has changed
464 bool notifyViewChanged( const UnoViewSharedPtr& rView );
466 /** View changed
468 This method announces a changed view to all view
469 listeners. View changes include size and transformation.
471 @param xView
472 View that has changed
474 void notifyViewChanged( const css::uno::Reference<css::presentation::XSlideShowView>& xView );
476 /** All Views changed
478 This method announces to all view listeners that
479 <em>every</em> known view has changed. View changes include
480 size and transformation.
482 void notifyViewsChanged();
484 /** View clobbered
486 This method announces that the given view has been clobbered
487 by something external to the slideshow, and needs an update.
489 @param xView
490 View that has been clobbered
492 void notifyViewClobbered( const css::uno::Reference<css::presentation::XSlideShowView>& xView );
494 /** New shape event listener added
496 This method announces that the given listener was added for
497 the specified shape.
499 void notifyShapeListenerAdded( const css::uno::Reference<css::presentation::XShapeEventListener>& xListener,
500 const css::uno::Reference<css::drawing::XShape>& xShape );
502 /** A shape event listener was removed
504 This method announces that the given listener was removed for
505 the specified shape.
507 void notifyShapeListenerRemoved( const css::uno::Reference<css::presentation::XShapeEventListener>& xListener,
508 const css::uno::Reference<css::drawing::XShape>& xShape );
510 /** Notify a new user paint color
512 Sending this notification also implies that user paint is
513 enabled. User paint denotes the feature to draw colored lines
514 on top of the slide content.
516 void notifyUserPaintColor( RGBColor const& rUserColor );
518 /** Notify a new user paint width
520 Sending this notification also implies that user paint is
521 enabled. .
523 void notifyUserPaintStrokeWidth( double rUserStrokeWidth );
526 /** Notify a new user paint erase all ink mode
528 Sending this notification also implies that user paint is
529 enabled. User paint denotes the feature to draw colored lines
530 on top of the slide content.
532 void notifyEraseAllInk( bool bEraseAllInk );
533 void notifySwitchPenMode();
534 void notifySwitchEraserMode();
535 void notifyEraseInkWidth( sal_Int32 rEraseInkSize );
537 /** Notify that user paint is disabled
539 User paint denotes the feature to draw colored lines on top of
540 the slide content.
542 void notifyUserPaintDisabled();
544 /** Notify that the user requested the next effect.
546 This requests the slideshow to display the next
547 effect, or move to the next slide, if none are left.
549 @return true, if this event was processed by
550 anybody. If false is returned, no handler processed
551 this event (and probably, nothing will happen at all)
553 bool notifyNextEffect();
555 /** Notify that a new slide has started
557 This method is to be used from the Presentation object
558 to signal that a new slide is starting now. This will
559 invoke all registered slide start handlers.
561 void notifySlideStartEvent();
563 /** Notify that a slide has ended
565 This method is to be used from the Presentation object
566 to signal that a slide is ending now. This will invoke
567 all registered slide end handlers.
569 @return true, if this event was processed by
570 anybody. If false is returned, no handler processed
571 this event (and probably, nothing will happen at all)
573 bool notifySlideEndEvent();
575 /** Notify that the given node enters its active duration.
577 This method is to be used from the AnimationNode
578 objects to signal that the active duration
579 begins. This will invoke all registered animation
580 start handlers.
582 @param rNode
583 Node which enters active duration.
585 @return true, if this event was processed by
586 anybody. If false is returned, no handler processed
587 this event (and probably, nothing will happen at all)
589 bool notifyAnimationStart( const std::shared_ptr<AnimationNode>& rNode );
591 /** Notify that the given node leaves its active duration.
593 This method is to be used from the AnimationNode
594 objects to signal that the active duration
595 ends now. This will invoke all registered animation
596 end handlers.
598 @param rNode
599 Node which leaves active duration.
601 @return true, if this event was processed by
602 anybody. If false is returned, no handler processed
603 this event (and probably, nothing will happen at all)
605 bool notifyAnimationEnd( const std::shared_ptr<AnimationNode>& rNode );
607 /** Notify that the slide animations sequence leaves its
608 active duration.
610 @return true, if this event was processed by
611 anybody. If false is returned, no handler processed
612 this event (and probably, nothing will happen at all)
614 bool notifySlideAnimationsEnd();
616 /** Notify that for the given node, audio output has stopped.
618 This method is to be used from the AnimationNode
619 objects to signal that audio playback has just
620 stopped. This will invoke all registered audio
621 stopped handlers.
623 @param rNode
624 Node for which audio has stopped.
626 @return true, if this event was processed by
627 anybody. If false is returned, no handler processed
628 this event (and probably, nothing will happen at all)
630 bool notifyAudioStopped( const std::shared_ptr<AnimationNode>& rNode );
632 /** Notify that the show has entered or exited pause mode
634 This method is to be used from the Presentation object
635 to signal that a slide is entering (bPauseShow=true)
636 or exiting (bPauseShow=false) pause mode. This will
637 invoke all registered slide end handlers.
639 void notifyPauseMode( bool bPauseShow );
641 /** Notify that all audio has to be stopped.
643 This method is used by XCommand nodes and all sound
644 playing nodes should listen for this command and
645 stop theire sounds when its fired.
647 @return true, if this event was processed by
648 anybody. If false is returned, no handler processed
649 this event (and probably, nothing will happen at all)
651 bool notifyCommandStopAudio( const std::shared_ptr<AnimationNode>& rNode );
653 /** Notifies that a hyperlink has been clicked.
655 void notifyHyperlinkClicked( OUString const& hyperLink );
657 private:
658 std::unique_ptr<EventMultiplexerImpl> mpImpl;
661 } // namespace internal
662 } // namespace Presentation
664 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_EVENTMULTIPLEXER_HXX
666 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */