Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / eventmultiplexer.cxx
blob88b64ddd8143a12b94b6d75b599176f69ae78ea2
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 .
21 #include <tools/diagnose_ex.h>
23 #include <rtl/ref.hxx>
24 #include <cppuhelper/compbase.hxx>
25 #include <cppuhelper/basemutex.hxx>
27 #include <com/sun/star/awt/XMouseListener.hpp>
28 #include <com/sun/star/awt/XMouseMotionListener.hpp>
29 #include <com/sun/star/awt/SystemPointer.hpp>
30 #include <com/sun/star/awt/XWindow.hpp>
31 #include <com/sun/star/awt/MouseButton.hpp>
32 #include <com/sun/star/presentation/XSlideShowView.hpp>
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 #include <basegfx/numeric/ftools.hxx>
37 #include <tools.hxx>
38 #include <eventqueue.hxx>
39 #include <eventmultiplexer.hxx>
40 #include <listenercontainer.hxx>
41 #include <delayevent.hxx>
42 #include <unoview.hxx>
43 #include <unoviewcontainer.hxx>
45 #include <functional>
46 #include <memory>
47 #include <algorithm>
48 #include <vector>
50 using namespace ::com::sun::star;
53 namespace std
55 // add operator== for weak_ptr, so we can use std::find over lists of them
56 template<typename T> bool operator==( weak_ptr<T> const& rLHS,
57 weak_ptr<T> const& rRHS )
59 return rLHS.lock().get() == rRHS.lock().get();
63 namespace slideshow {
64 namespace internal {
66 template <typename HandlerT>
67 class PrioritizedHandlerEntry
69 typedef std::shared_ptr<HandlerT> HandlerSharedPtrT;
70 HandlerSharedPtrT mpHandler;
71 double mnPrio;
73 public:
74 PrioritizedHandlerEntry( HandlerSharedPtrT const& pHandler,
75 double nPrio ) :
76 mpHandler(pHandler),
77 mnPrio(nPrio)
80 HandlerSharedPtrT const& getHandler() const { return mpHandler; }
82 /// To sort according to priority
83 bool operator<( PrioritizedHandlerEntry const& rRHS ) const
85 // reversed order - high prioritized entries
86 // should be at the beginning of the queue
87 return mnPrio > rRHS.mnPrio;
90 /// To permit std::remove in removeHandler template
91 bool operator==( PrioritizedHandlerEntry const& rRHS ) const
93 // ignore prio, for removal, only the handler ptr matters
94 return mpHandler == rRHS.mpHandler;
99 typedef cppu::WeakComponentImplHelper<
100 awt::XMouseListener,
101 awt::XMouseMotionListener > Listener_UnoBase;
103 /** Listener class, to decouple UNO lifetime from EventMultiplexer
105 This class gets registered as the XMouse(Motion)Listener on the
106 XSlideViews, and passes on the events to the EventMultiplexer (via
107 EventQueue indirection, to force the events into the main thread)
109 class EventMultiplexerListener : private cppu::BaseMutex,
110 public Listener_UnoBase
112 public:
113 EventMultiplexerListener( EventQueue& rEventQueue,
114 EventMultiplexerImpl& rEventMultiplexer ) :
115 Listener_UnoBase( m_aMutex ),
116 mpEventQueue( &rEventQueue ),
117 mpEventMultiplexer( &rEventMultiplexer )
121 EventMultiplexerListener( const EventMultiplexerListener& ) = delete;
122 EventMultiplexerListener& operator=( const EventMultiplexerListener& ) = delete;
124 // WeakComponentImplHelperBase::disposing
125 virtual void SAL_CALL disposing() override;
127 private:
128 virtual void SAL_CALL disposing( const lang::EventObject& Source ) override;
130 // XMouseListener implementation
131 virtual void SAL_CALL mousePressed( const awt::MouseEvent& e ) override;
132 virtual void SAL_CALL mouseReleased( const awt::MouseEvent& e ) override;
133 virtual void SAL_CALL mouseEntered( const awt::MouseEvent& e ) override;
134 virtual void SAL_CALL mouseExited( const awt::MouseEvent& e ) override;
136 // XMouseMotionListener implementation
137 virtual void SAL_CALL mouseDragged( const awt::MouseEvent& e ) override;
138 virtual void SAL_CALL mouseMoved( const awt::MouseEvent& e ) override;
141 EventQueue* mpEventQueue;
142 EventMultiplexerImpl* mpEventMultiplexer;
146 struct EventMultiplexerImpl
148 EventMultiplexerImpl( EventQueue& rEventQueue,
149 UnoViewContainer const& rViewContainer ) :
150 mrEventQueue(rEventQueue),
151 mrViewContainer(rViewContainer),
152 mxListener( new EventMultiplexerListener(rEventQueue,
153 *this) ),
154 maNextEffectHandlers(),
155 maSlideStartHandlers(),
156 maSlideEndHandlers(),
157 maAnimationStartHandlers(),
158 maAnimationEndHandlers(),
159 maSlideAnimationsEndHandlers(),
160 maAudioStoppedHandlers(),
161 maCommandStopAudioHandlers(),
162 maPauseHandlers(),
163 maViewHandlers(),
164 maViewRepaintHandlers(),
165 maShapeListenerHandlers(),
166 maUserPaintEventHandlers(),
167 maMouseClickHandlers(),
168 maMouseDoubleClickHandlers(),
169 maMouseMoveHandlers(),
170 maHyperlinkHandlers(),
171 mnTimeout(0.0),
172 mpTickEvent(),
173 mbIsAutoMode(false)
176 ~EventMultiplexerImpl()
178 if( mxListener.is() )
179 mxListener->dispose();
182 /// Remove all handlers
183 void clear();
185 // actual handler callbacks (get called from the UNO interface
186 // listeners via event queue)
187 void mousePressed( const awt::MouseEvent& e );
188 void mouseReleased( const awt::MouseEvent& e );
189 void mouseDragged( const awt::MouseEvent& e );
190 void mouseMoved( const awt::MouseEvent& e );
192 bool isMouseListenerRegistered() const;
194 typedef ThreadUnsafeListenerContainer<
195 PrioritizedHandlerEntry<EventHandler>,
196 std::vector<
197 PrioritizedHandlerEntry<EventHandler> > > ImplNextEffectHandlers;
198 typedef PrioritizedHandlerEntry<MouseEventHandler> ImplMouseHandlerEntry;
199 typedef ThreadUnsafeListenerContainer<
200 ImplMouseHandlerEntry,
201 std::vector<ImplMouseHandlerEntry> > ImplMouseHandlers;
202 typedef ThreadUnsafeListenerContainer<
203 EventHandlerSharedPtr,
204 std::vector<EventHandlerSharedPtr> > ImplEventHandlers;
205 typedef ThreadUnsafeListenerContainer<
206 AnimationEventHandlerSharedPtr,
207 std::vector<AnimationEventHandlerSharedPtr> > ImplAnimationHandlers;
208 typedef ThreadUnsafeListenerContainer<
209 PauseEventHandlerSharedPtr,
210 std::vector<PauseEventHandlerSharedPtr> > ImplPauseHandlers;
211 typedef ThreadUnsafeListenerContainer<
212 ViewEventHandlerWeakPtr,
213 std::vector<ViewEventHandlerWeakPtr> > ImplViewHandlers;
214 typedef ThreadUnsafeListenerContainer<
215 ViewRepaintHandlerSharedPtr,
216 std::vector<ViewRepaintHandlerSharedPtr> > ImplRepaintHandlers;
217 typedef ThreadUnsafeListenerContainer<
218 ShapeListenerEventHandlerSharedPtr,
219 std::vector<ShapeListenerEventHandlerSharedPtr> > ImplShapeListenerHandlers;
220 typedef ThreadUnsafeListenerContainer<
221 UserPaintEventHandlerSharedPtr,
222 std::vector<UserPaintEventHandlerSharedPtr> > ImplUserPaintEventHandlers;
223 typedef ThreadUnsafeListenerContainer<
224 PrioritizedHandlerEntry<HyperlinkHandler>,
225 std::vector<PrioritizedHandlerEntry<HyperlinkHandler> > > ImplHyperLinkHandlers;
227 template <typename XSlideShowViewFunc>
228 void forEachView( XSlideShowViewFunc pViewMethod );
230 UnoViewSharedPtr findUnoView(const uno::Reference<
231 presentation::XSlideShowView>& xView) const;
233 template< typename RegisterFunction >
234 void addMouseHandler( ImplMouseHandlers& rHandlerContainer,
235 const MouseEventHandlerSharedPtr& rHandler,
236 double nPriority,
237 RegisterFunction pRegisterListener );
239 static bool notifyAllAnimationHandlers( ImplAnimationHandlers const& rContainer,
240 AnimationNodeSharedPtr const& rNode );
242 bool notifyMouseHandlers(
243 const ImplMouseHandlers& rQueue,
244 bool (MouseEventHandler::*pHandlerMethod)(
245 const awt::MouseEvent& ),
246 const awt::MouseEvent& e );
248 bool notifyNextEffect();
250 /// Called for automatic nextEffect
251 void tick();
253 /// Schedules a tick event
254 void scheduleTick();
256 /// Schedules tick events, if mbIsAutoMode is true
257 void handleTicks();
260 EventQueue& mrEventQueue;
261 UnoViewContainer const& mrViewContainer;
262 ::rtl::Reference<
263 EventMultiplexerListener> mxListener;
265 ImplNextEffectHandlers maNextEffectHandlers;
266 ImplEventHandlers maSlideStartHandlers;
267 ImplEventHandlers maSlideEndHandlers;
268 ImplAnimationHandlers maAnimationStartHandlers;
269 ImplAnimationHandlers maAnimationEndHandlers;
270 ImplEventHandlers maSlideAnimationsEndHandlers;
271 ImplAnimationHandlers maAudioStoppedHandlers;
272 ImplAnimationHandlers maCommandStopAudioHandlers;
273 ImplPauseHandlers maPauseHandlers;
274 ImplViewHandlers maViewHandlers;
275 ImplRepaintHandlers maViewRepaintHandlers;
276 ImplShapeListenerHandlers maShapeListenerHandlers;
277 ImplUserPaintEventHandlers maUserPaintEventHandlers;
278 ImplMouseHandlers maMouseClickHandlers;
279 ImplMouseHandlers maMouseDoubleClickHandlers;
280 ImplMouseHandlers maMouseMoveHandlers;
281 ImplHyperLinkHandlers maHyperlinkHandlers;
283 /// automatic next effect mode timeout
284 double mnTimeout;
286 /** Holds ptr to optional tick event weakly
288 When event queue is cleansed, the next
289 setAutomaticMode(true) call is then able to
290 regenerate the event.
292 ::std::weak_ptr< Event > mpTickEvent;
293 bool mbIsAutoMode;
297 void SAL_CALL EventMultiplexerListener::disposing()
299 osl::MutexGuard const guard( m_aMutex );
300 mpEventQueue = nullptr;
301 mpEventMultiplexer = nullptr;
304 void SAL_CALL EventMultiplexerListener::disposing(
305 const lang::EventObject& /*rSource*/ )
307 // there's no real point in acting on this message - after all,
308 // the event sources are the XSlideShowViews, which must be
309 // explicitly removed from the slideshow via
310 // XSlideShow::removeView(). thus, if a XSlideShowView has
311 // properly removed itself from the slideshow, it will not be
312 // found here. and if it hasn't, there'll be other references at
313 // other places within the slideshow, anyway...
316 void SAL_CALL EventMultiplexerListener::mousePressed(
317 const awt::MouseEvent& e )
319 osl::MutexGuard const guard( m_aMutex );
321 // notify mouse press. Don't call handlers directly, this
322 // might not be the main thread!
323 if( mpEventQueue )
324 mpEventQueue->addEvent(
325 makeEvent( std::bind( &EventMultiplexerImpl::mousePressed,
326 mpEventMultiplexer,
327 e ),
328 "EventMultiplexerImpl::mousePressed") );
331 void SAL_CALL EventMultiplexerListener::mouseReleased(
332 const awt::MouseEvent& e )
334 osl::MutexGuard const guard( m_aMutex );
336 // notify mouse release. Don't call handlers directly,
337 // this might not be the main thread!
338 if( mpEventQueue )
339 mpEventQueue->addEvent(
340 makeEvent( std::bind( &EventMultiplexerImpl::mouseReleased,
341 mpEventMultiplexer,
342 e ),
343 "EventMultiplexerImpl::mouseReleased") );
346 void SAL_CALL EventMultiplexerListener::mouseEntered(
347 const awt::MouseEvent& /*e*/ )
349 // not used here
352 void SAL_CALL EventMultiplexerListener::mouseExited(
353 const awt::MouseEvent& /*e*/ )
355 // not used here
358 // XMouseMotionListener implementation
359 void SAL_CALL EventMultiplexerListener::mouseDragged(
360 const awt::MouseEvent& e )
362 osl::MutexGuard const guard( m_aMutex );
364 // notify mouse drag. Don't call handlers directly, this
365 // might not be the main thread!
366 if( mpEventQueue )
367 mpEventQueue->addEvent(
368 makeEvent( std::bind( &EventMultiplexerImpl::mouseDragged,
369 mpEventMultiplexer,
370 e ),
371 "EventMultiplexerImpl::mouseDragged") );
374 void SAL_CALL EventMultiplexerListener::mouseMoved(
375 const awt::MouseEvent& e )
377 osl::MutexGuard const guard( m_aMutex );
379 // notify mouse move. Don't call handlers directly, this
380 // might not be the main thread!
381 if( mpEventQueue )
382 mpEventQueue->addEvent(
383 makeEvent( std::bind( &EventMultiplexerImpl::mouseMoved,
384 mpEventMultiplexer,
385 e ),
386 "EventMultiplexerImpl::mouseMoved") );
390 bool EventMultiplexerImpl::notifyAllAnimationHandlers( ImplAnimationHandlers const& rContainer,
391 AnimationNodeSharedPtr const& rNode )
393 return rContainer.applyAll(
394 [&rNode]( const AnimationEventHandlerSharedPtr& pEventHandler )
395 { return pEventHandler->handleAnimationEvent( rNode ); } );
398 template <typename XSlideShowViewFunc>
399 void EventMultiplexerImpl::forEachView( XSlideShowViewFunc pViewMethod )
401 if( pViewMethod )
403 // (un)register mouse listener on all views
404 for( UnoViewVector::const_iterator aIter( mrViewContainer.begin() ),
405 aEnd( mrViewContainer.end() ); aIter != aEnd; ++aIter )
407 uno::Reference<presentation::XSlideShowView> xView ((*aIter)->getUnoView());
408 if (xView.is())
410 (xView.get()->*pViewMethod)( mxListener.get() );
412 else
414 OSL_ASSERT(xView.is());
420 UnoViewSharedPtr EventMultiplexerImpl::findUnoView(
421 const uno::Reference<presentation::XSlideShowView>& xView) const
423 // find view from which the change originated
424 UnoViewVector::const_iterator aIter;
425 const UnoViewVector::const_iterator aEnd ( mrViewContainer.end() );
426 if( (aIter=std::find_if( mrViewContainer.begin(),
427 aEnd,
428 [&xView]( const UnoViewSharedPtr& pView )
429 { return xView == pView->getUnoView(); } )) == aEnd )
431 OSL_FAIL("EventMultiplexer::findUnoView(): unexpected message source" );
432 return UnoViewSharedPtr();
435 return *aIter;
438 template< typename RegisterFunction >
439 void EventMultiplexerImpl::addMouseHandler(
440 ImplMouseHandlers& rHandlerContainer,
441 const MouseEventHandlerSharedPtr& rHandler,
442 double nPriority,
443 RegisterFunction pRegisterListener )
445 ENSURE_OR_THROW(
446 rHandler,
447 "EventMultiplexer::addMouseHandler(): Invalid handler" );
449 // register mouse listener on all views
450 forEachView( pRegisterListener );
452 // add into sorted container:
453 rHandlerContainer.addSorted(
454 typename ImplMouseHandlers::container_type::value_type(
455 rHandler,
456 nPriority ));
459 bool EventMultiplexerImpl::isMouseListenerRegistered() const
461 return !(maMouseClickHandlers.isEmpty() &&
462 maMouseDoubleClickHandlers.isEmpty());
465 void EventMultiplexerImpl::tick()
467 if( !mbIsAutoMode )
468 return; // this event is just a left-over, ignore
470 notifyNextEffect();
472 if( !maNextEffectHandlers.isEmpty() )
474 // still handlers left, schedule next timeout
475 // event. Will also set mbIsTickEventOn back to true
476 scheduleTick();
480 void EventMultiplexerImpl::scheduleTick()
482 EventSharedPtr pEvent(
483 makeDelay( [this] () { this->tick(); },
484 mnTimeout,
485 "EventMultiplexerImpl::tick with delay"));
487 // store weak reference to generated event, to notice when
488 // the event queue gets cleansed (we then have to
489 // regenerate the tick event!)
490 mpTickEvent = pEvent;
492 // enabled auto mode: simply schedule a timeout event,
493 // which will eventually call our tick() method
494 mrEventQueue.addEventForNextRound( pEvent );
497 void EventMultiplexerImpl::handleTicks()
499 if( !mbIsAutoMode )
500 return; // nothing to do, don't need no ticks
502 EventSharedPtr pTickEvent( mpTickEvent.lock() );
503 if( pTickEvent )
504 return; // nothing to do, there's already a tick
505 // pending
507 // schedule initial tick (which reschedules itself
508 // after that, all by itself)
509 scheduleTick();
513 void EventMultiplexerImpl::clear()
515 // deregister from all views.
516 if( isMouseListenerRegistered() )
518 for( UnoViewVector::const_iterator aIter=mrViewContainer.begin(),
519 aEnd=mrViewContainer.end();
520 aIter!=aEnd;
521 ++aIter )
523 if( (*aIter)->getUnoView().is() )
524 (*aIter)->getUnoView()->removeMouseListener( mxListener.get() );
528 if( !maMouseMoveHandlers.isEmpty() )
530 for( UnoViewVector::const_iterator aIter=mrViewContainer.begin(),
531 aEnd=mrViewContainer.end();
532 aIter!=aEnd;
533 ++aIter )
535 if( (*aIter)->getUnoView().is() )
536 (*aIter)->getUnoView()->removeMouseMotionListener( mxListener.get() );
540 // clear all handlers (releases all references)
541 maNextEffectHandlers.clear();
542 maSlideStartHandlers.clear();
543 maSlideEndHandlers.clear();
544 maAnimationStartHandlers.clear();
545 maAnimationEndHandlers.clear();
546 maSlideAnimationsEndHandlers.clear();
547 maAudioStoppedHandlers.clear();
548 maCommandStopAudioHandlers.clear();
549 maPauseHandlers.clear();
550 maViewHandlers.clear();
551 maViewRepaintHandlers.clear();
552 maMouseClickHandlers.clear();
553 maMouseDoubleClickHandlers.clear();
554 maMouseMoveHandlers.clear();
555 maHyperlinkHandlers.clear();
556 mpTickEvent.reset();
559 // XMouseListener implementation
560 bool EventMultiplexerImpl::notifyMouseHandlers(
561 const ImplMouseHandlers& rQueue,
562 bool (MouseEventHandler::*pHandlerMethod)( const awt::MouseEvent& ),
563 const awt::MouseEvent& e )
565 uno::Reference<presentation::XSlideShowView> xView(
566 e.Source, uno::UNO_QUERY );
568 ENSURE_OR_RETURN_FALSE( xView.is(), "EventMultiplexer::notifyHandlers(): "
569 "event source is not an XSlideShowView" );
571 // find corresponding view (to map mouse position into user
572 // coordinate space)
573 UnoViewVector::const_iterator aIter;
574 const UnoViewVector::const_iterator aEnd ( mrViewContainer.end() );
575 if( (aIter=::std::find_if(
576 mrViewContainer.begin(),
577 aEnd,
578 [&xView]( const UnoViewSharedPtr& pView )
579 { return xView == pView->getUnoView(); } )) == aEnd )
581 ENSURE_OR_RETURN_FALSE(
582 false, "EventMultiplexer::notifyHandlers(): "
583 "event source not found under registered views" );
586 // convert mouse position to user coordinate space
587 ::basegfx::B2DPoint aPosition( e.X, e.Y );
588 ::basegfx::B2DHomMatrix aMatrix( (*aIter)->getTransformation() );
589 if( !aMatrix.invert() )
590 ENSURE_OR_THROW( false, "EventMultiplexer::notifyHandlers():"
591 " view matrix singular" );
592 aPosition *= aMatrix;
594 awt::MouseEvent aEvent( e );
595 aEvent.X = ::basegfx::fround( aPosition.getX() );
596 aEvent.Y = ::basegfx::fround( aPosition.getY() );
598 // fire event on handlers, try in order of precedence. If
599 // one high-priority handler rejects the event
600 // (i.e. returns false), try next handler.
601 return rQueue.apply(
602 [&pHandlerMethod, &aEvent]( const ImplMouseHandlerEntry& rMouseHandler )
603 { return ( ( *rMouseHandler.getHandler() ).*pHandlerMethod )( aEvent ); } );
606 void EventMultiplexerImpl::mousePressed( const awt::MouseEvent& e )
608 // fire double-click events for every second click
609 sal_Int32 nCurrClickCount = e.ClickCount;
610 while( nCurrClickCount > 1 &&
611 notifyMouseHandlers( maMouseDoubleClickHandlers,
612 &MouseEventHandler::handleMousePressed,
613 e ))
615 nCurrClickCount -= 2;
618 // fire single-click events for all remaining clicks
619 while( nCurrClickCount > 0 &&
620 notifyMouseHandlers( maMouseClickHandlers,
621 &MouseEventHandler::handleMousePressed,
622 e ))
624 --nCurrClickCount;
628 void EventMultiplexerImpl::mouseReleased( const awt::MouseEvent& e )
630 // fire double-click events for every second click
631 sal_Int32 nCurrClickCount = e.ClickCount;
632 while( nCurrClickCount > 1 &&
633 notifyMouseHandlers( maMouseDoubleClickHandlers,
634 &MouseEventHandler::handleMouseReleased,
635 e ))
637 nCurrClickCount -= 2;
640 // fire single-click events for all remaining clicks
641 while( nCurrClickCount > 0 &&
642 notifyMouseHandlers( maMouseClickHandlers,
643 &MouseEventHandler::handleMouseReleased,
644 e ))
646 --nCurrClickCount;
650 void EventMultiplexerImpl::mouseDragged( const awt::MouseEvent& e )
652 notifyMouseHandlers( maMouseMoveHandlers,
653 &MouseEventHandler::handleMouseDragged,
654 e );
657 void EventMultiplexerImpl::mouseMoved( const awt::MouseEvent& e )
659 notifyMouseHandlers( maMouseMoveHandlers,
660 &MouseEventHandler::handleMouseMoved,
661 e );
664 bool EventMultiplexerImpl::notifyNextEffect()
666 // fire event on handlers, try in order of precedence. If one
667 // high-priority handler rejects the event (i.e. returns false),
668 // try next handler.
669 return maNextEffectHandlers.apply(
670 []( const PrioritizedHandlerEntry< EventHandler >& pHandler )
671 { return pHandler.getHandler()->handleEvent(); } );
675 EventMultiplexer::EventMultiplexer( EventQueue& rEventQueue,
676 UnoViewContainer const& rViewContainer ) :
677 mpImpl( new EventMultiplexerImpl(rEventQueue, rViewContainer) )
681 EventMultiplexer::~EventMultiplexer()
683 // outline because of EventMultiplexerImpl's incomplete type
686 void EventMultiplexer::clear()
688 mpImpl->clear();
691 void EventMultiplexer::setAutomaticMode( bool bIsAuto )
693 if( bIsAuto == mpImpl->mbIsAutoMode )
694 return; // no change, nothing to do
696 mpImpl->mbIsAutoMode = bIsAuto;
698 mpImpl->handleTicks();
701 bool EventMultiplexer::getAutomaticMode() const
703 return mpImpl->mbIsAutoMode;
706 void EventMultiplexer::setAutomaticTimeout( double nTimeout )
708 mpImpl->mnTimeout = nTimeout;
711 double EventMultiplexer::getAutomaticTimeout() const
713 return mpImpl->mnTimeout;
716 void EventMultiplexer::addNextEffectHandler(
717 EventHandlerSharedPtr const& rHandler,
718 double nPriority )
720 mpImpl->maNextEffectHandlers.addSorted(
721 EventMultiplexerImpl::ImplNextEffectHandlers::container_type::value_type(
722 rHandler,
723 nPriority) );
725 // Enable tick events, if not done already
726 mpImpl->handleTicks();
729 void EventMultiplexer::removeNextEffectHandler(
730 const EventHandlerSharedPtr& rHandler )
732 mpImpl->maNextEffectHandlers.remove(
733 EventMultiplexerImpl::ImplNextEffectHandlers::container_type::value_type(
734 rHandler,
735 0.0) );
738 void EventMultiplexer::addSlideStartHandler(
739 const EventHandlerSharedPtr& rHandler )
741 mpImpl->maSlideStartHandlers.add( rHandler );
744 void EventMultiplexer::removeSlideStartHandler(
745 const EventHandlerSharedPtr& rHandler )
747 mpImpl->maSlideStartHandlers.remove( rHandler );
750 void EventMultiplexer::addSlideEndHandler(
751 const EventHandlerSharedPtr& rHandler )
753 mpImpl->maSlideEndHandlers.add( rHandler );
756 void EventMultiplexer::removeSlideEndHandler(
757 const EventHandlerSharedPtr& rHandler )
759 mpImpl->maSlideEndHandlers.remove( rHandler );
762 void EventMultiplexer::addAnimationStartHandler(
763 const AnimationEventHandlerSharedPtr& rHandler )
765 mpImpl->maAnimationStartHandlers.add( rHandler );
768 void EventMultiplexer::removeAnimationStartHandler(
769 const AnimationEventHandlerSharedPtr& rHandler )
771 mpImpl->maAnimationStartHandlers.remove( rHandler );
774 void EventMultiplexer::addAnimationEndHandler(
775 const AnimationEventHandlerSharedPtr& rHandler )
777 mpImpl->maAnimationEndHandlers.add( rHandler );
780 void EventMultiplexer::removeAnimationEndHandler(
781 const AnimationEventHandlerSharedPtr& rHandler )
783 mpImpl->maAnimationEndHandlers.remove( rHandler );
786 void EventMultiplexer::addSlideAnimationsEndHandler(
787 const EventHandlerSharedPtr& rHandler )
789 mpImpl->maSlideAnimationsEndHandlers.add( rHandler );
792 void EventMultiplexer::removeSlideAnimationsEndHandler(
793 const EventHandlerSharedPtr& rHandler )
795 mpImpl->maSlideAnimationsEndHandlers.remove( rHandler );
798 void EventMultiplexer::addAudioStoppedHandler(
799 const AnimationEventHandlerSharedPtr& rHandler )
801 mpImpl->maAudioStoppedHandlers.add( rHandler );
804 void EventMultiplexer::removeAudioStoppedHandler(
805 const AnimationEventHandlerSharedPtr& rHandler )
807 mpImpl->maAudioStoppedHandlers.remove( rHandler );
810 void EventMultiplexer::addCommandStopAudioHandler(
811 const AnimationEventHandlerSharedPtr& rHandler )
813 mpImpl->maCommandStopAudioHandlers.add( rHandler );
816 void EventMultiplexer::removeCommandStopAudioHandler(
817 const AnimationEventHandlerSharedPtr& rHandler )
819 mpImpl->maCommandStopAudioHandlers.remove( rHandler );
822 void EventMultiplexer::addPauseHandler(
823 const PauseEventHandlerSharedPtr& rHandler )
825 mpImpl->maPauseHandlers.add( rHandler );
828 void EventMultiplexer::removePauseHandler(
829 const PauseEventHandlerSharedPtr& rHandler )
831 mpImpl->maPauseHandlers.remove( rHandler );
834 void EventMultiplexer::addViewHandler(
835 const ViewEventHandlerWeakPtr& rHandler )
837 mpImpl->maViewHandlers.add( rHandler );
840 void EventMultiplexer::removeViewHandler( const ViewEventHandlerWeakPtr& rHandler )
842 mpImpl->maViewHandlers.remove( rHandler );
845 void EventMultiplexer::addViewRepaintHandler( const ViewRepaintHandlerSharedPtr& rHandler )
847 mpImpl->maViewRepaintHandlers.add( rHandler );
850 void EventMultiplexer::removeViewRepaintHandler( const ViewRepaintHandlerSharedPtr& rHandler )
852 mpImpl->maViewRepaintHandlers.remove( rHandler );
855 void EventMultiplexer::addShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr& rHandler )
857 mpImpl->maShapeListenerHandlers.add( rHandler );
860 void EventMultiplexer::removeShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr& rHandler )
862 mpImpl->maShapeListenerHandlers.remove( rHandler );
865 void EventMultiplexer::addUserPaintHandler( const UserPaintEventHandlerSharedPtr& rHandler )
867 mpImpl->maUserPaintEventHandlers.add( rHandler );
870 void EventMultiplexer::addClickHandler(
871 const MouseEventHandlerSharedPtr& rHandler,
872 double nPriority )
874 mpImpl->addMouseHandler(
875 mpImpl->maMouseClickHandlers,
876 rHandler,
877 nPriority,
878 mpImpl->isMouseListenerRegistered()
879 ? nullptr
880 : &presentation::XSlideShowView::addMouseListener );
883 void EventMultiplexer::removeClickHandler(
884 const MouseEventHandlerSharedPtr& rHandler )
886 mpImpl->maMouseClickHandlers.remove(
887 EventMultiplexerImpl::ImplMouseHandlers::container_type::value_type(
888 rHandler,
889 0.0) );
891 if( !mpImpl->isMouseListenerRegistered() )
892 mpImpl->forEachView( &presentation::XSlideShowView::removeMouseListener );
895 void EventMultiplexer::addDoubleClickHandler(
896 const MouseEventHandlerSharedPtr& rHandler,
897 double nPriority )
899 mpImpl->addMouseHandler(
900 mpImpl->maMouseDoubleClickHandlers,
901 rHandler,
902 nPriority,
903 mpImpl->isMouseListenerRegistered()
904 ? nullptr
905 : &presentation::XSlideShowView::addMouseListener );
908 void EventMultiplexer::removeDoubleClickHandler(
909 const MouseEventHandlerSharedPtr& rHandler )
911 mpImpl->maMouseDoubleClickHandlers.remove(
912 EventMultiplexerImpl::ImplMouseHandlers::container_type::value_type(
913 rHandler,
914 0.0) );
916 if( !mpImpl->isMouseListenerRegistered() )
917 mpImpl->forEachView( &presentation::XSlideShowView::removeMouseListener );
920 void EventMultiplexer::addMouseMoveHandler(
921 const MouseEventHandlerSharedPtr& rHandler,
922 double nPriority )
924 mpImpl->addMouseHandler(
925 mpImpl->maMouseMoveHandlers,
926 rHandler,
927 nPriority,
928 mpImpl->maMouseMoveHandlers.isEmpty()
929 ? &presentation::XSlideShowView::addMouseMotionListener
930 : nullptr );
933 void EventMultiplexer::removeMouseMoveHandler(
934 const MouseEventHandlerSharedPtr& rHandler )
936 mpImpl->maMouseMoveHandlers.remove(
937 EventMultiplexerImpl::ImplMouseHandlers::container_type::value_type(
938 rHandler,
939 0.0) );
941 if( mpImpl->maMouseMoveHandlers.isEmpty() )
942 mpImpl->forEachView(
943 &presentation::XSlideShowView::removeMouseMotionListener );
946 void EventMultiplexer::addHyperlinkHandler( const HyperlinkHandlerSharedPtr& rHandler,
947 double nPriority )
949 mpImpl->maHyperlinkHandlers.addSorted(
950 EventMultiplexerImpl::ImplHyperLinkHandlers::container_type::value_type(
951 rHandler,
952 nPriority) );
955 void EventMultiplexer::removeHyperlinkHandler( const HyperlinkHandlerSharedPtr& rHandler )
957 mpImpl->maHyperlinkHandlers.remove(
958 EventMultiplexerImpl::ImplHyperLinkHandlers::container_type::value_type(
959 rHandler,
960 0.0) );
963 void EventMultiplexer::notifyShapeListenerAdded(
964 const uno::Reference<presentation::XShapeEventListener>& xListener,
965 const uno::Reference<drawing::XShape>& xShape )
967 mpImpl->maShapeListenerHandlers.applyAll(
968 [&xListener, &xShape]( const ShapeListenerEventHandlerSharedPtr& pHandler )
969 { return pHandler->listenerAdded( xListener, xShape ); } );
972 void EventMultiplexer::notifyShapeListenerRemoved(
973 const uno::Reference<presentation::XShapeEventListener>& xListener,
974 const uno::Reference<drawing::XShape>& xShape )
976 mpImpl->maShapeListenerHandlers.applyAll(
977 [&xListener, &xShape]( const ShapeListenerEventHandlerSharedPtr& pHandler )
978 { return pHandler->listenerRemoved( xListener, xShape ); } );
981 void EventMultiplexer::notifyUserPaintColor( RGBColor const& rUserColor )
983 mpImpl->maUserPaintEventHandlers.applyAll(
984 [&rUserColor]( const UserPaintEventHandlerSharedPtr& pHandler )
985 { return pHandler->colorChanged( rUserColor ); } );
988 void EventMultiplexer::notifyUserPaintStrokeWidth( double rUserStrokeWidth )
990 mpImpl->maUserPaintEventHandlers.applyAll(
991 [&rUserStrokeWidth]( const UserPaintEventHandlerSharedPtr& pHandler )
992 { return pHandler->widthChanged( rUserStrokeWidth ); } );
995 void EventMultiplexer::notifyUserPaintDisabled()
997 mpImpl->maUserPaintEventHandlers.applyAll(
998 std::mem_fn(&UserPaintEventHandler::disable));
1001 void EventMultiplexer::notifySwitchPenMode(){
1002 mpImpl->maUserPaintEventHandlers.applyAll(
1003 std::mem_fn(&UserPaintEventHandler::switchPenMode));
1006 void EventMultiplexer::notifySwitchEraserMode(){
1007 mpImpl->maUserPaintEventHandlers.applyAll(
1008 std::mem_fn(&UserPaintEventHandler::switchEraserMode));
1011 //adding erasing all ink features with UserPaintOverlay
1012 void EventMultiplexer::notifyEraseAllInk( bool bEraseAllInk )
1014 mpImpl->maUserPaintEventHandlers.applyAll(
1015 [&bEraseAllInk]( const UserPaintEventHandlerSharedPtr& pHandler )
1016 { return pHandler->eraseAllInkChanged( bEraseAllInk ); } );
1019 //adding erasing features with UserPaintOverlay
1020 void EventMultiplexer::notifyEraseInkWidth( sal_Int32 rEraseInkSize )
1022 mpImpl->maUserPaintEventHandlers.applyAll(
1023 [&rEraseInkSize]( const UserPaintEventHandlerSharedPtr& pHandler )
1024 { return pHandler->eraseInkWidthChanged( rEraseInkSize ); } );
1027 bool EventMultiplexer::notifyNextEffect()
1029 return mpImpl->notifyNextEffect();
1032 void EventMultiplexer::notifySlideStartEvent()
1034 mpImpl->maSlideStartHandlers.applyAll(
1035 std::mem_fn(&EventHandler::handleEvent) );
1038 bool EventMultiplexer::notifySlideEndEvent()
1040 return mpImpl->maSlideEndHandlers.applyAll(
1041 std::mem_fn(&EventHandler::handleEvent) );
1044 bool EventMultiplexer::notifyAnimationStart(
1045 const AnimationNodeSharedPtr& rNode )
1047 return EventMultiplexerImpl::notifyAllAnimationHandlers( mpImpl->maAnimationStartHandlers,
1048 rNode );
1051 bool EventMultiplexer::notifyAnimationEnd(
1052 const AnimationNodeSharedPtr& rNode )
1054 return EventMultiplexerImpl::notifyAllAnimationHandlers( mpImpl->maAnimationEndHandlers,
1055 rNode );
1058 bool EventMultiplexer::notifySlideAnimationsEnd()
1060 return mpImpl->maSlideAnimationsEndHandlers.applyAll(
1061 std::mem_fn(&EventHandler::handleEvent));
1064 bool EventMultiplexer::notifyAudioStopped(
1065 const AnimationNodeSharedPtr& rNode )
1067 return EventMultiplexerImpl::notifyAllAnimationHandlers(
1068 mpImpl->maAudioStoppedHandlers,
1069 rNode );
1072 bool EventMultiplexer::notifyCommandStopAudio(
1073 const AnimationNodeSharedPtr& rNode )
1075 return EventMultiplexerImpl::notifyAllAnimationHandlers(
1076 mpImpl->maCommandStopAudioHandlers,
1077 rNode );
1080 void EventMultiplexer::notifyPauseMode( bool bPauseShow )
1082 mpImpl->maPauseHandlers.applyAll(
1083 [&bPauseShow]( const PauseEventHandlerSharedPtr& pHandler )
1084 { return pHandler->handlePause( bPauseShow ); } );
1087 void EventMultiplexer::notifyViewAdded( const UnoViewSharedPtr& rView )
1089 ENSURE_OR_THROW( rView, "EventMultiplexer::notifyViewAdded(): Invalid view");
1091 // register event listener
1092 uno::Reference<presentation::XSlideShowView> const rUnoView(
1093 rView->getUnoView() );
1095 if( mpImpl->isMouseListenerRegistered() )
1096 rUnoView->addMouseListener(
1097 mpImpl->mxListener.get() );
1099 if( !mpImpl->maMouseMoveHandlers.isEmpty() )
1100 rUnoView->addMouseMotionListener(
1101 mpImpl->mxListener.get() );
1103 mpImpl->maViewHandlers.applyAll(
1104 [&rView]( const ViewEventHandlerWeakPtr& pHandler )
1105 { return pHandler.lock()->viewAdded( rView ); } );
1108 void EventMultiplexer::notifyViewRemoved( const UnoViewSharedPtr& rView )
1110 ENSURE_OR_THROW( rView,
1111 "EventMultiplexer::removeView(): Invalid view" );
1113 // revoke event listeners
1114 uno::Reference<presentation::XSlideShowView> const rUnoView(
1115 rView->getUnoView() );
1117 if( mpImpl->isMouseListenerRegistered() )
1118 rUnoView->removeMouseListener(
1119 mpImpl->mxListener.get() );
1121 if( !mpImpl->maMouseMoveHandlers.isEmpty() )
1122 rUnoView->removeMouseMotionListener(
1123 mpImpl->mxListener.get() );
1125 mpImpl->maViewHandlers.applyAll(
1126 [&rView]( const ViewEventHandlerWeakPtr& pHandler )
1127 { return pHandler.lock()->viewRemoved( rView ); } );
1130 bool EventMultiplexer::notifyViewChanged( const UnoViewSharedPtr& rView )
1132 return mpImpl->maViewHandlers.applyAll(
1133 [&rView]( const ViewEventHandlerWeakPtr& pHandler )
1134 { return pHandler.lock()->viewChanged( rView ); } );
1137 void EventMultiplexer::notifyViewChanged( const uno::Reference<presentation::XSlideShowView>& xView )
1139 UnoViewSharedPtr pView( mpImpl->findUnoView(xView) );
1141 if( !pView )
1142 return; // view not registered here
1144 notifyViewChanged( pView );
1147 void EventMultiplexer::notifyViewsChanged()
1149 mpImpl->maViewHandlers.applyAll(
1150 std::mem_fn( &ViewEventHandler::viewsChanged ));
1153 void EventMultiplexer::notifyViewClobbered(
1154 const uno::Reference<presentation::XSlideShowView>& xView )
1156 UnoViewSharedPtr pView( mpImpl->findUnoView(xView) );
1158 if( !pView )
1159 return; // view not registered here
1161 mpImpl->maViewRepaintHandlers.applyAll(
1162 [&pView]( const ViewRepaintHandlerSharedPtr& pHandler )
1163 { return pHandler->viewClobbered( pView ); } );
1166 void EventMultiplexer::notifyHyperlinkClicked(
1167 OUString const& hyperLink )
1169 mpImpl->maHyperlinkHandlers.apply(
1170 [&hyperLink]( const PrioritizedHandlerEntry< HyperlinkHandler >& pHandler )
1171 { return pHandler.getHandler()->handleHyperlink( hyperLink ); } );
1174 } // namespace internal
1175 } // namespace presentation
1177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */