bump product version to 5.0.4.1
[LibreOffice.git] / slideshow / source / inc / eventmultiplexer.hxx
blob716e0239428147d4d9b030f07f02fb0201f9c249
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 <boost/noncopyable.hpp>
30 #include <boost/scoped_ptr.hpp>
31 #include <boost/shared_ptr.hpp>
32 #include <boost/weak_ptr.hpp>
33 #include <com/sun/star/uno/Reference.hxx>
35 #include "unoview.hxx"
37 namespace com { namespace sun { namespace star { namespace drawing
39 class XShape;
40 } } } }
42 namespace slideshow {
43 namespace internal {
45 class EventQueue;
46 class UnoViewContainer;
47 class AnimationNode;
49 struct EventMultiplexerImpl;
51 class RGBColor;
53 /** Interface for handling view repaint events.
55 Classes implementing this interface can be added to an
56 EventMultiplexer object, and are called from there to
57 handle view repaint events.
59 class ViewRepaintHandler
61 public:
62 virtual ~ViewRepaintHandler() {}
64 /** Notify clobbered view.
66 Reasons for a viewChanged notification can be
67 different view size, transformation, or other device
68 properties (color resolution or profile, etc.)
70 @param rView
71 The changed view
73 virtual void viewClobbered( const UnoViewSharedPtr& rView ) = 0;
76 typedef ::boost::shared_ptr< ViewRepaintHandler > ViewRepaintHandlerSharedPtr;
77 typedef ::boost::weak_ptr< ViewRepaintHandler > ViewRepaintHandlerWeakPtr;
79 /** Interface for handling hyperlink clicks.
81 Classes implementing this interface can be added to an
82 EventMultiplexer object, and are called from there to
83 handle hyperlink events.
85 class HyperlinkHandler
87 public:
88 /** Handle the event.
90 @param rLink
91 The actual hyperlink URI
93 @return true, if this handler has successfully
94 processed the event. When this method returns false,
95 possibly other, less prioritized handlers are called,
96 too.
98 virtual bool handleHyperlink( OUString const& rLink ) = 0;
100 protected:
101 ~HyperlinkHandler() {}
104 typedef ::boost::shared_ptr< HyperlinkHandler > HyperlinkHandlerSharedPtr;
106 /** Interface for handling user paint state changes.
108 Classes implementing this interface can be added to an
109 EventMultiplexer object, and are called from there to
110 handle user paint events.
112 class UserPaintEventHandler
114 public:
115 virtual ~UserPaintEventHandler() {}
116 virtual bool colorChanged( RGBColor const& rUserColor ) = 0;
117 virtual bool widthChanged( double nUserStrokeWidth ) = 0;
118 virtual bool eraseAllInkChanged(bool const& rEraseAllInk) =0;
119 virtual bool eraseInkWidthChanged(sal_Int32 rEraseInkSize) =0;
120 virtual bool switchEraserMode() = 0;
121 virtual bool switchPenMode() = 0;
122 virtual bool disable() = 0;
125 typedef ::boost::shared_ptr< UserPaintEventHandler > UserPaintEventHandlerSharedPtr;
127 /** Interface for handling view events.
129 Classes implementing this interface can be added to an
130 EventMultiplexer object, and are called from there to
131 handle view events.
133 class ShapeCursorEventHandler
135 public:
136 virtual ~ShapeCursorEventHandler() {}
138 virtual bool cursorChanged( const ::com::sun::star::uno::Reference<
139 ::com::sun::star::drawing::XShape>& xShape,
140 sal_Int16 nCursor ) = 0;
143 typedef ::boost::shared_ptr< ShapeCursorEventHandler > ShapeCursorEventHandlerSharedPtr;
145 /** This class multiplexes user-activated and
146 slide-show global events.
148 This class listens at the XSlideShowView and fires events
149 registered for certain user actions. Furthermore, global
150 slide show state changes (such as start or end of a slide)
151 are handled as well. Note that registered events which
152 have a non-zero timeout (i.e. events that return non-zero
153 from getActivationTime()) will not be fired immediately
154 after the user action occurred, but only after the given
155 timeout. Which is actually a feature.
157 class EventMultiplexer : private ::boost::noncopyable
159 public:
160 /** Create an event multiplexer
162 @param rEventQueue
163 Reference to the main event queue. Since we hold this
164 object by plain reference, it must live longer than we
165 do. On the other hand, that queue must not fire events
166 after this object is destroyed, since we might
167 schedule events there which itself contain plain
168 references to this object. Basically, EventQueue and
169 EventMultiplexer should have the same lifetime, and since
170 this is not possible, both must be destructed in a
171 phased mode: first clear both of any remaining events,
172 then destruct them.
174 @param rViewContainer
175 Globally managed list of all registered views. Used to
176 determine event sources, and for registering view listeners
179 EventMultiplexer( EventQueue& rEventQueue,
180 UnoViewContainer const& rViewContainer );
181 ~EventMultiplexer();
183 // Management methods
186 /** Clear all registered handlers.
188 void clear();
191 // Automatic mode methods
194 /** Change automatic mode.
196 @param bIsAuto
197 When true, events will be fired automatically, not
198 only triggered by UI events. When false, auto events
199 will quit.
201 void setAutomaticMode( bool bIsAuto );
203 /** Get automatic mode setting.
205 bool getAutomaticMode() const;
207 /** Set the timeout for automatic mode.
209 @param nTimeout
210 Timeout, between end of effect until start of next
211 effect.
213 void setAutomaticTimeout( double nTimeout );
215 /** Get automatic mode timeout value.
217 double getAutomaticTimeout() const;
219 // Handler registration methods
222 /** Register an event handler that will be called when views are
223 changed.
225 For each view added, viewAdded() will be called on the
226 handler. For each view removed, viewRemoved() will be
227 called. Each modified view will cause a viewChanged() call on
228 each handler.
230 You don't need to deregister the handler, it will be
231 automatically removed, once the pointee becomes stale.
233 @param rHandler
234 Handler to call.
236 void addViewHandler( const ViewEventHandlerWeakPtr& rHandler );
237 void removeViewHandler( const ViewEventHandlerWeakPtr& rHandler );
239 /** Register an event handler that will be called when a view gets
240 clobbered.
242 Note that <em>all</em> registered handlers will be called when
243 the event. This is in contrast to the mouse events below.
245 @param rHandler
246 Handler to call when a view needs a repaint
248 void addViewRepaintHandler( const ViewRepaintHandlerSharedPtr& rHandler );
249 void removeViewRepaintHandler( const ViewRepaintHandlerSharedPtr& rHandler );
251 /** Register an event handler that will be called when
252 XShapeListeners are changed.
254 @param rHandler
255 Handler to call when a shape listener changes
257 void addShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr& rHandler );
258 void removeShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr& rHandler );
260 /** Register an event handler that will be called when
261 user paint parameters change.
263 @param rHandler
264 Handler to call when a shape listener changes
266 void addUserPaintHandler( const UserPaintEventHandlerSharedPtr& rHandler );
268 /** Register an event handler that will be called when the
269 user requests the next effect.
271 For every nextEffect event, only one of the handlers
272 registered here is called. The handlers are considered
273 with decreasing priority, i.e. the handler with the
274 currently highest priority will be called.
276 @param rHandler
277 Handler to call when the next effect should start
279 @param nPriority
280 Priority with which the handlers are called. The
281 higher the priority, the earlier this handler will be
282 tried.
284 void addNextEffectHandler( const EventHandlerSharedPtr& rHandler,
285 double nPriority );
286 void removeNextEffectHandler( const EventHandlerSharedPtr& rHandler );
288 /** Register an event handler that will be called when the
289 slide is just shown.
291 Note that <em>all</em> registered handlers will be called
292 when the slide start occurs. This is in contrast to
293 the mouse events below.
295 @param rHandler
296 Handler to call when the next slide starts
298 void addSlideStartHandler( const EventHandlerSharedPtr& rHandler );
299 void removeSlideStartHandler( const EventHandlerSharedPtr& rHandler );
301 /** Register an event handler that will be called when the
302 slide is about to vanish.
304 Note that <em>all</em> registered handlers will be
305 called when the slide end occurs. This is in contrast
306 to the mouse events below.
308 @param rHandler
309 Handler to call when the current slide ends
311 void addSlideEndHandler( const EventHandlerSharedPtr& rHandler );
312 void removeSlideEndHandler( const EventHandlerSharedPtr& rHandler );
314 /** Register an event handler that will be called when an
315 XAnimationNode starts its active duration.
317 Note that <em>all</em> registered handlers will be called
318 when the animation start occurs. This is in contrast to
319 the mouse events below.
321 @param rHandler
322 Handler to call when the animation start
324 void addAnimationStartHandler(
325 const AnimationEventHandlerSharedPtr& rHandler );
326 void removeAnimationStartHandler(
327 const AnimationEventHandlerSharedPtr& rHandler );
329 /** Register an event handler that will be called when an
330 XAnimationNode ends its active duration.
332 Note that <em>all</em> registered handlers will be called
333 when the animation end occurs. This is in contrast to
334 the mouse events below.
336 @param rHandler
337 Handler to call when the animation ends
339 void addAnimationEndHandler(
340 const AnimationEventHandlerSharedPtr& rHandler );
341 void removeAnimationEndHandler(
342 const AnimationEventHandlerSharedPtr& rHandler );
344 /** Register an event handler that will be called when the
345 main animation sequence of a slide ends its active
346 duration.
348 Note that <em>all</em> registered handlers will be
349 called when the animation end occurs. This is in
350 contrast to the mouse events below.
352 @param rHandler
353 Handler to call when the animation ends
355 void addSlideAnimationsEndHandler(
356 const EventHandlerSharedPtr& rHandler );
357 void removeSlideAnimationsEndHandler(
358 const EventHandlerSharedPtr& rHandler );
360 /** Register an event handler that will be called when an
361 XAudio node's sound stops playing.
363 Note that <em>all</em> registered handlers will be
364 called when the audio stops. This is in contrast to
365 the mouse events below.
367 @param rHandler
368 Handler to call when the audio stops
370 void addAudioStoppedHandler(
371 const AnimationEventHandlerSharedPtr& rHandler );
372 void removeAudioStoppedHandler(
373 const AnimationEventHandlerSharedPtr& rHandler );
375 /** Register an event handler that will be called when an
376 XCommand node's with the command STOPAUDIO is activated.
378 Note that <em>all</em> registered handlers will be
379 called when the audio stops. This is in contrast to
380 the mouse events below.
382 @param rHandler
383 Handler to call when command is activated
385 void addCommandStopAudioHandler(
386 const AnimationEventHandlerSharedPtr& rHandler );
387 void removeCommandStopAudioHandler(
388 const AnimationEventHandlerSharedPtr& rHandler );
390 /** Register a handler that is called when the show enters
391 or exits pause mode.
393 void addPauseHandler( const PauseEventHandlerSharedPtr& rHandler );
394 void removePauseHandler( const PauseEventHandlerSharedPtr& rHandler );
396 /** Register a mouse handler that is called on mouse click
398 For every mouse click, only one of the handlers
399 registered here is called. The handlers are considered
400 with decreasing priority, i.e. the handler with the
401 currently highest priority will be called.
403 Since the handlers can reject down and up events
404 individually, handlers should expect to be called with
405 non-matching down and up-press counts. If your handler
406 cannot cope with that, it must have the highest
407 priority of all added handlers.
409 void addClickHandler( const MouseEventHandlerSharedPtr& rHandler,
410 double nPriority );
411 void removeClickHandler( const MouseEventHandlerSharedPtr& rHandler );
413 /** Register a mouse handler that is called on a double
414 mouse click
416 For every mouse double click, only one of the handlers
417 registered here is called. The handlers are considered
418 with decreasing priority, i.e. the handler with the
419 currently highest priority will be called.
421 Since the handlers can reject down and up events
422 individually, handlers should expect to be called with
423 non-matching down and up-press counts. If your handler
424 cannot cope with that, it must have the highest
425 priority of all added handlers.
427 void addDoubleClickHandler( const MouseEventHandlerSharedPtr& rHandler,
428 double nPriority );
429 void removeDoubleClickHandler( const MouseEventHandlerSharedPtr& rHandler );
431 /** Register a mouse handler that is called for mouse moves.
433 For every mouse move, only one of the handlers
434 registered here is called. The handlers are considered
435 with decreasing priority, i.e. the handler with the
436 currently highest priority will be called.
438 void addMouseMoveHandler( const MouseEventHandlerSharedPtr& rHandler,
439 double nPriority );
440 void removeMouseMoveHandler( const MouseEventHandlerSharedPtr& rHandler );
443 /** Registers a hyperlink click handler.
445 For every hyperlink click, only one of the handlers registered
446 here is called. The handlers are considered with decreasing
447 priority, i.e. the handler with the currently highest priority
448 will be called.
450 @param rHandler
451 @param nPriority
453 void addHyperlinkHandler( const HyperlinkHandlerSharedPtr& rHandler,
454 double nPriority );
455 void removeHyperlinkHandler( const HyperlinkHandlerSharedPtr& rHandler );
458 // External event notifications
461 /** View added.
463 This method adds another view, which the show is
464 displayed on. On every added view, the EventMultiplexer
465 registers mouse and motion event listeners.
467 bool notifyViewAdded( const UnoViewSharedPtr& rView );
469 /** View removed
471 This method removes a view. Registered mouse and
472 motion event listeners are revoked.
474 bool notifyViewRemoved( const UnoViewSharedPtr& rView );
476 /** View changed
478 This method announces a changed view to all view
479 listeners. View changes include size and transformation.
481 @param rView
482 View that has changed
484 bool notifyViewChanged( const UnoViewSharedPtr& rView );
486 /** View changed
488 This method announces a changed view to all view
489 listeners. View changes include size and transformation.
491 @param xView
492 View that has changed
494 bool notifyViewChanged( const ::com::sun::star::uno::Reference<
495 ::com::sun::star::presentation::XSlideShowView>& xView );
497 /** All Views changed
499 This method announces to all view listeners that
500 <em>every</em> known view has changed. View changes include
501 size and transformation.
503 bool notifyViewsChanged();
505 /** View clobbered
507 This method announces that the given view has been clobbered
508 by something external to the slideshow, and needs an update.
510 @param xView
511 View that has been clobbered
513 bool notifyViewClobbered( const ::com::sun::star::uno::Reference<
514 ::com::sun::star::presentation::XSlideShowView>& xView );
516 /** New shape event listener added
518 This method announces that the given listener was added for
519 the specified shape.
521 @return true, if at least one handler successfully processed
522 the notification.
524 bool notifyShapeListenerAdded( const ::com::sun::star::uno::Reference<
525 ::com::sun::star::presentation::XShapeEventListener>& xListener,
526 const ::com::sun::star::uno::Reference<
527 ::com::sun::star::drawing::XShape>& xShape );
529 /** A shape event listener was removed
531 This method announces that the given listener was removed for
532 the specified shape.
534 @return true, if at least one handler successfully processed
535 the notification.
537 bool notifyShapeListenerRemoved( const ::com::sun::star::uno::Reference<
538 ::com::sun::star::presentation::XShapeEventListener>& xListener,
539 const ::com::sun::star::uno::Reference<
540 ::com::sun::star::drawing::XShape>& xShape );
542 /** A new shape cursor was set
544 This method announces that the given cursor was set for the
545 specified shape.
547 @return true, if at least one handler successfully processed
548 the notification.
550 bool notifyShapeCursorChange( const ::com::sun::star::uno::Reference<
551 ::com::sun::star::drawing::XShape>& xShape,
552 sal_Int16 nPointerShape );
554 /** Notify a new user paint color
556 Sending this notification also implies that user paint is
557 enabled. User paint denotes the feature to draw colored lines
558 on top of the slide content.
560 @return true, if this event was processed by
561 anybody. If false is returned, no handler processed
562 this event (and probably, nothing will happen at all)
564 bool notifyUserPaintColor( RGBColor const& rUserColor );
566 /** Notify a new user paint width
568 Sending this notification also implies that user paint is
569 enabled. .
571 @return true, if this event was processed by
572 anybody. If false is returned, no handler processed
573 this event (and probably, nothing will happen at all)
575 bool notifyUserPaintStrokeWidth( double rUserStrokeWidth );
578 /** Notify a new user paint erase all ink mode
580 Sending this notification also implies that user paint is
581 enabled. User paint denotes the feature to draw colored lines
582 on top of the slide content.
584 @return true, if this event was processed by
585 anybody. If false is returned, no handler processed
586 this event (and probably, nothing will happen at all)
588 bool notifyEraseAllInk( bool const& rEraseAllInk );
589 bool notifySwitchPenMode();
590 bool notifySwitchEraserMode();
591 bool notifyEraseInkWidth( sal_Int32 rEraseInkSize );
593 /** Notify that user paint is disabled
595 User paint denotes the feature to draw colored lines on top of
596 the slide content.
598 @return true, if this event was processed by
599 anybody. If false is returned, no handler processed
600 this event (and probably, nothing will happen at all)
602 bool notifyUserPaintDisabled();
604 /** Notify that the user requested the next effect.
606 This requests the slideshow to display the next
607 effect, or move to the next slide, if none are left.
609 @return true, if this event was processed by
610 anybody. If false is returned, no handler processed
611 this event (and probably, nothing will happen at all)
613 bool notifyNextEffect();
615 /** Notify that a new slide has started
617 This method is to be used from the Presentation object
618 to signal that a new slide is starting now. This will
619 invoke all registered slide start handlers.
621 @return true, if this event was processed by
622 anybody. If false is returned, no handler processed
623 this event (and probably, nothing will happen at all)
625 bool notifySlideStartEvent();
627 /** Notify that a slide has ended
629 This method is to be used from the Presentation object
630 to signal that a slide is ending now. This will invoke
631 all registered slide end handlers.
633 @return true, if this event was processed by
634 anybody. If false is returned, no handler processed
635 this event (and probably, nothing will happen at all)
637 bool notifySlideEndEvent();
639 /** Notify that the given node enters its active duration.
641 This method is to be used from the AnimationNode
642 objects to signal that the active duration
643 begins. This will invoke all registered animation
644 start handlers.
646 @param rNode
647 Node which enters active duration.
649 @return true, if this event was processed by
650 anybody. If false is returned, no handler processed
651 this event (and probably, nothing will happen at all)
653 bool notifyAnimationStart( const boost::shared_ptr<AnimationNode>& rNode );
655 /** Notify that the given node leaves its active duration.
657 This method is to be used from the AnimationNode
658 objects to signal that the active duration
659 ends now. This will invoke all registered animation
660 end handlers.
662 @param rNode
663 Node which leaves active duration.
665 @return true, if this event was processed by
666 anybody. If false is returned, no handler processed
667 this event (and probably, nothing will happen at all)
669 bool notifyAnimationEnd( const boost::shared_ptr<AnimationNode>& rNode );
671 /** Notify that the slide animations sequence leaves its
672 active duration.
674 @return true, if this event was processed by
675 anybody. If false is returned, no handler processed
676 this event (and probably, nothing will happen at all)
678 bool notifySlideAnimationsEnd();
680 /** Notify that for the given node, audio output has stopped.
682 This method is to be used from the AnimationNode
683 objects to signal that audio playback has just
684 stopped. This will invoke all registered audio
685 stopped andlers.
687 @param rNode
688 Node for which audio has stopped.
690 @return true, if this event was processed by
691 anybody. If false is returned, no handler processed
692 this event (and probably, nothing will happen at all)
694 bool notifyAudioStopped( const boost::shared_ptr<AnimationNode>& rNode );
696 /** Notify that the show has entered or exited pause mode
698 This method is to be used from the Presentation object
699 to signal that a slide is entering (bPauseShow=true)
700 or exiting (bPauseShow=false) pause mode. This will
701 invoke all registered slide end handlers.
703 @return true, if this event was processed by
704 anybody. If false is returned, no handler processed
705 this event (and probably, nothing will happen at all)
707 bool notifyPauseMode( bool bPauseShow );
709 /** Notify that all audio has to be stopped.
711 This method is used by XCommand nodes and all sound
712 playing nodes should listen for this command and
713 stop theire sounds when its fired.
715 @return true, if this event was processed by
716 anybody. If false is returned, no handler processed
717 this event (and probably, nothing will happen at all)
719 bool notifyCommandStopAudio( const boost::shared_ptr<AnimationNode>& rNode );
721 /** Botifies that a hyperlink has been clicked.
723 @return true, if this event was processed by
724 anybody. If false is returned, no handler processed
725 this event (and probably, nothing will happen at all)
727 bool notifyHyperlinkClicked( OUString const& hyperLink );
729 private:
730 boost::scoped_ptr<EventMultiplexerImpl> mpImpl;
733 } // namespace internal
734 } // namespace Presentation
736 #endif // INCLUDED_SLIDESHOW_SOURCE_INC_EVENTMULTIPLEXER_HXX
738 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */