1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <canvas/debug.hxx>
23 #include <tools/diagnose_ex.h>
25 #include <rtl/ref.hxx>
26 #include <cppuhelper/compbase2.hxx>
27 #include <cppuhelper/basemutex.hxx>
29 #include <com/sun/star/awt/XMouseListener.hpp>
30 #include <com/sun/star/awt/XMouseMotionListener.hpp>
31 #include <com/sun/star/awt/SystemPointer.hpp>
32 #include <com/sun/star/awt/XWindow.hpp>
33 #include <com/sun/star/awt/MouseButton.hpp>
34 #include <com/sun/star/presentation/XSlideShowView.hpp>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <basegfx/numeric/ftools.hxx>
40 #include "eventqueue.hxx"
41 #include "eventmultiplexer.hxx"
42 #include "listenercontainer.hxx"
43 #include "delayevent.hxx"
44 #include "unoview.hxx"
45 #include "unoviewcontainer.hxx"
47 #include <boost/shared_ptr.hpp>
48 #include <boost/weak_ptr.hpp>
49 #include <boost/function.hpp>
50 #include <boost/noncopyable.hpp>
51 #include <boost/bind.hpp>
56 using namespace ::com::sun::star
;
60 // add operator== for weak_ptr
61 template<typename T
> bool operator==( weak_ptr
<T
> const& rLHS
,
62 weak_ptr
<T
> const& rRHS
)
64 return !(rLHS
<rRHS
) && !(rRHS
<rLHS
);
71 template <typename HandlerT
>
72 class PrioritizedHandlerEntry
74 typedef boost::shared_ptr
<HandlerT
> HandlerSharedPtrT
;
75 HandlerSharedPtrT mpHandler
;
79 PrioritizedHandlerEntry( HandlerSharedPtrT
const& pHandler
,
85 HandlerSharedPtrT
const& getHandler() const { return mpHandler
; }
87 /// To sort according to priority
88 bool operator<( PrioritizedHandlerEntry
const& rRHS
) const
90 // reversed order - high prioritized entries
91 // should be at the beginning of the queue
92 return mnPrio
> rRHS
.mnPrio
;
95 /// To permit std::remove in removeHandler template
96 bool operator==( PrioritizedHandlerEntry
const& rRHS
) const
98 // ignore prio, for removal, only the handler ptr matters
99 return mpHandler
== rRHS
.mpHandler
;
103 template<typename T
> inline T
* get_pointer(PrioritizedHandlerEntry
<T
> const& handler
)
105 return handler
.getHandler().get();
113 typedef cppu::WeakComponentImplHelper2
<
115 awt::XMouseMotionListener
> Listener_UnoBase
;
117 /** Listener class, to decouple UNO lifetime from EventMultiplexer
119 This class gets registered as the XMouse(Motion)Listener on the
120 XSlideViews, and passes on the events to the EventMultiplexer (via
121 EventQueue indirection, to force the events into the main thread)
123 class EventMultiplexerListener
: private cppu::BaseMutex
,
124 public Listener_UnoBase
,
125 private ::boost::noncopyable
128 EventMultiplexerListener( EventQueue
& rEventQueue
,
129 EventMultiplexerImpl
& rEventMultiplexer
) :
130 Listener_UnoBase( m_aMutex
),
131 mpEventQueue( &rEventQueue
),
132 mpEventMultiplexer( &rEventMultiplexer
)
136 // WeakComponentImplHelperBase::disposing
137 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
140 virtual void SAL_CALL
disposing( const lang::EventObject
& Source
)
141 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
143 // XMouseListener implementation
144 virtual void SAL_CALL
mousePressed( const awt::MouseEvent
& e
)
145 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
146 virtual void SAL_CALL
mouseReleased( const awt::MouseEvent
& e
)
147 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
148 virtual void SAL_CALL
mouseEntered( const awt::MouseEvent
& e
)
149 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
150 virtual void SAL_CALL
mouseExited( const awt::MouseEvent
& e
)
151 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
153 // XMouseMotionListener implementation
154 virtual void SAL_CALL
mouseDragged( const awt::MouseEvent
& e
)
155 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
156 virtual void SAL_CALL
mouseMoved( const awt::MouseEvent
& e
)
157 throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
160 EventQueue
* mpEventQueue
;
161 EventMultiplexerImpl
* mpEventMultiplexer
;
168 struct EventMultiplexerImpl
170 EventMultiplexerImpl( EventQueue
& rEventQueue
,
171 UnoViewContainer
const& rViewContainer
) :
172 mrEventQueue(rEventQueue
),
173 mrViewContainer(rViewContainer
),
174 mxListener( new EventMultiplexerListener(rEventQueue
,
176 maNextEffectHandlers(),
177 maSlideStartHandlers(),
178 maSlideEndHandlers(),
179 maAnimationStartHandlers(),
180 maAnimationEndHandlers(),
181 maSlideAnimationsEndHandlers(),
182 maAudioStoppedHandlers(),
183 maCommandStopAudioHandlers(),
186 maViewRepaintHandlers(),
187 maShapeListenerHandlers(),
188 maUserPaintEventHandlers(),
189 maShapeCursorHandlers(),
190 maMouseClickHandlers(),
191 maMouseDoubleClickHandlers(),
192 maMouseMoveHandlers(),
193 maHyperlinkHandlers(),
199 ~EventMultiplexerImpl()
201 if( mxListener
.is() )
202 mxListener
->dispose();
205 /// Remove all handlers
208 // actual handler callbacks (get called from the UNO interface
209 // listeners via event queue)
210 void mousePressed( const awt::MouseEvent
& e
);
211 void mouseReleased( const awt::MouseEvent
& e
);
212 void mouseDragged( const awt::MouseEvent
& e
);
213 void mouseMoved( const awt::MouseEvent
& e
);
215 bool isMouseListenerRegistered() const;
217 typedef ThreadUnsafeListenerContainer
<
218 PrioritizedHandlerEntry
<EventHandler
>,
220 PrioritizedHandlerEntry
<EventHandler
> > > ImplNextEffectHandlers
;
221 typedef PrioritizedHandlerEntry
<MouseEventHandler
> ImplMouseHandlerEntry
;
222 typedef ThreadUnsafeListenerContainer
<
223 ImplMouseHandlerEntry
,
224 std::vector
<ImplMouseHandlerEntry
> > ImplMouseHandlers
;
225 typedef ThreadUnsafeListenerContainer
<
226 EventHandlerSharedPtr
,
227 std::vector
<EventHandlerSharedPtr
> > ImplEventHandlers
;
228 typedef ThreadUnsafeListenerContainer
<
229 AnimationEventHandlerSharedPtr
,
230 std::vector
<AnimationEventHandlerSharedPtr
> > ImplAnimationHandlers
;
231 typedef ThreadUnsafeListenerContainer
<
232 PauseEventHandlerSharedPtr
,
233 std::vector
<PauseEventHandlerSharedPtr
> > ImplPauseHandlers
;
234 typedef ThreadUnsafeListenerContainer
<
235 ViewEventHandlerWeakPtr
,
236 std::vector
<ViewEventHandlerWeakPtr
> > ImplViewHandlers
;
237 typedef ThreadUnsafeListenerContainer
<
238 ViewRepaintHandlerSharedPtr
,
239 std::vector
<ViewRepaintHandlerSharedPtr
> > ImplRepaintHandlers
;
240 typedef ThreadUnsafeListenerContainer
<
241 ShapeListenerEventHandlerSharedPtr
,
242 std::vector
<ShapeListenerEventHandlerSharedPtr
> > ImplShapeListenerHandlers
;
243 typedef ThreadUnsafeListenerContainer
<
244 UserPaintEventHandlerSharedPtr
,
245 std::vector
<UserPaintEventHandlerSharedPtr
> > ImplUserPaintEventHandlers
;
246 typedef ThreadUnsafeListenerContainer
<
247 ShapeCursorEventHandlerSharedPtr
,
248 std::vector
<ShapeCursorEventHandlerSharedPtr
> > ImplShapeCursorHandlers
;
249 typedef ThreadUnsafeListenerContainer
<
250 PrioritizedHandlerEntry
<HyperlinkHandler
>,
251 std::vector
<PrioritizedHandlerEntry
<HyperlinkHandler
> > > ImplHyperLinkHandlers
;
253 template <typename XSlideShowViewFunc
>
254 void forEachView( XSlideShowViewFunc pViewMethod
);
256 UnoViewSharedPtr
findUnoView(const uno::Reference
<
257 presentation::XSlideShowView
>& xView
) const;
259 template< typename RegisterFunction
>
260 void addMouseHandler( ImplMouseHandlers
& rHandlerContainer
,
261 const MouseEventHandlerSharedPtr
& rHandler
,
263 RegisterFunction pRegisterListener
);
265 static bool notifyAllAnimationHandlers( ImplAnimationHandlers
const& rContainer
,
266 AnimationNodeSharedPtr
const& rNode
);
268 bool notifyMouseHandlers(
269 const ImplMouseHandlers
& rQueue
,
270 bool (MouseEventHandler::*pHandlerMethod
)(
271 const awt::MouseEvent
& ),
272 const awt::MouseEvent
& e
);
274 bool notifyNextEffect();
276 /// Called for automatic nextEffect
279 /// Schedules a tick event
282 /// Schedules tick events, if mbIsAutoMode is true
286 EventQueue
& mrEventQueue
;
287 UnoViewContainer
const& mrViewContainer
;
289 EventMultiplexerListener
> mxListener
;
291 ImplNextEffectHandlers maNextEffectHandlers
;
292 ImplEventHandlers maSlideStartHandlers
;
293 ImplEventHandlers maSlideEndHandlers
;
294 ImplAnimationHandlers maAnimationStartHandlers
;
295 ImplAnimationHandlers maAnimationEndHandlers
;
296 ImplEventHandlers maSlideAnimationsEndHandlers
;
297 ImplAnimationHandlers maAudioStoppedHandlers
;
298 ImplAnimationHandlers maCommandStopAudioHandlers
;
299 ImplPauseHandlers maPauseHandlers
;
300 ImplViewHandlers maViewHandlers
;
301 ImplRepaintHandlers maViewRepaintHandlers
;
302 ImplShapeListenerHandlers maShapeListenerHandlers
;
303 ImplUserPaintEventHandlers maUserPaintEventHandlers
;
304 ImplShapeCursorHandlers maShapeCursorHandlers
;
305 ImplMouseHandlers maMouseClickHandlers
;
306 ImplMouseHandlers maMouseDoubleClickHandlers
;
307 ImplMouseHandlers maMouseMoveHandlers
;
308 ImplHyperLinkHandlers maHyperlinkHandlers
;
310 /// automatic next effect mode timeout
313 /** Holds ptr to optional tick event weakly
315 When event queue is cleansed, the next
316 setAutomaticMode(true) call is then able to
317 regenerate the event.
319 ::boost::weak_ptr
< Event
> mpTickEvent
;
327 void SAL_CALL
EventMultiplexerListener::disposing()
329 osl::MutexGuard
const guard( m_aMutex
);
331 mpEventMultiplexer
= NULL
;
334 void SAL_CALL
EventMultiplexerListener::disposing(
335 const lang::EventObject
& /*rSource*/ ) throw (uno::RuntimeException
, std::exception
)
337 // there's no real point in acting on this message - after all,
338 // the event sources are the XSlideShowViews, which must be
339 // explicitly removed from the slideshow via
340 // XSlideShow::removeView(). thus, if a XSlideShowView has
341 // properly removed itself from the slideshow, it will not be
342 // found here. and if it hasn't, there'll be other references at
343 // other places within the slideshow, anyway...
346 void SAL_CALL
EventMultiplexerListener::mousePressed(
347 const awt::MouseEvent
& e
) throw (uno::RuntimeException
, std::exception
)
349 osl::MutexGuard
const guard( m_aMutex
);
351 // notify mouse press. Don't call handlers directly, this
352 // might not be the main thread!
354 mpEventQueue
->addEvent(
355 makeEvent( boost::bind( &EventMultiplexerImpl::mousePressed
,
358 "EventMultiplexerImpl::mousePressed") );
361 void SAL_CALL
EventMultiplexerListener::mouseReleased(
362 const awt::MouseEvent
& e
) throw (uno::RuntimeException
, std::exception
)
364 osl::MutexGuard
const guard( m_aMutex
);
366 // notify mouse release. Don't call handlers directly,
367 // this might not be the main thread!
369 mpEventQueue
->addEvent(
370 makeEvent( boost::bind( &EventMultiplexerImpl::mouseReleased
,
373 "EventMultiplexerImpl::mouseReleased") );
376 void SAL_CALL
EventMultiplexerListener::mouseEntered(
377 const awt::MouseEvent
& /*e*/ ) throw (uno::RuntimeException
, std::exception
)
382 void SAL_CALL
EventMultiplexerListener::mouseExited(
383 const awt::MouseEvent
& /*e*/ ) throw (uno::RuntimeException
, std::exception
)
388 // XMouseMotionListener implementation
389 void SAL_CALL
EventMultiplexerListener::mouseDragged(
390 const awt::MouseEvent
& e
) throw (uno::RuntimeException
, std::exception
)
392 osl::MutexGuard
const guard( m_aMutex
);
394 // notify mouse drag. Don't call handlers directly, this
395 // might not be the main thread!
397 mpEventQueue
->addEvent(
398 makeEvent( boost::bind( &EventMultiplexerImpl::mouseDragged
,
401 "EventMultiplexerImpl::mouseDragged") );
404 void SAL_CALL
EventMultiplexerListener::mouseMoved(
405 const awt::MouseEvent
& e
) throw (uno::RuntimeException
, std::exception
)
407 osl::MutexGuard
const guard( m_aMutex
);
409 // notify mouse move. Don't call handlers directly, this
410 // might not be the main thread!
412 mpEventQueue
->addEvent(
413 makeEvent( boost::bind( &EventMultiplexerImpl::mouseMoved
,
416 "EventMultiplexerImpl::mouseMoved") );
423 bool EventMultiplexerImpl::notifyAllAnimationHandlers( ImplAnimationHandlers
const& rContainer
,
424 AnimationNodeSharedPtr
const& rNode
)
426 return rContainer
.applyAll(
427 boost::bind( &AnimationEventHandler::handleAnimationEvent
,
428 _1
, boost::cref(rNode
) ) );
431 template <typename XSlideShowViewFunc
>
432 void EventMultiplexerImpl::forEachView( XSlideShowViewFunc pViewMethod
)
436 // (un)register mouse listener on all views
437 for( UnoViewVector::const_iterator
aIter( mrViewContainer
.begin() ),
438 aEnd( mrViewContainer
.end() ); aIter
!= aEnd
; ++aIter
)
440 uno::Reference
<presentation::XSlideShowView
> xView ((*aIter
)->getUnoView());
443 (xView
.get()->*pViewMethod
)( mxListener
.get() );
447 OSL_ASSERT(xView
.is());
453 UnoViewSharedPtr
EventMultiplexerImpl::findUnoView(
454 const uno::Reference
<presentation::XSlideShowView
>& xView
) const
456 // find view from which the change originated
457 UnoViewVector::const_iterator aIter
;
458 const UnoViewVector::const_iterator
aEnd ( mrViewContainer
.end() );
459 if( (aIter
=std::find_if( mrViewContainer
.begin(),
462 std::equal_to
<uno::Reference
<presentation::XSlideShowView
> >(),
463 boost::cref( xView
),
464 boost::bind( &UnoView::getUnoView
, _1
)))) == aEnd
)
466 OSL_FAIL("EventMultiplexer::findUnoView(): unexpected message source" );
467 return UnoViewSharedPtr();
473 template< typename RegisterFunction
>
474 void EventMultiplexerImpl::addMouseHandler(
475 ImplMouseHandlers
& rHandlerContainer
,
476 const MouseEventHandlerSharedPtr
& rHandler
,
478 RegisterFunction pRegisterListener
)
482 "EventMultiplexer::addMouseHandler(): Invalid handler" );
484 // register mouse listener on all views
485 forEachView( pRegisterListener
);
487 // add into sorted container:
488 rHandlerContainer
.addSorted(
489 typename
ImplMouseHandlers::container_type::value_type(
494 bool EventMultiplexerImpl::isMouseListenerRegistered() const
496 return !(maMouseClickHandlers
.isEmpty() &&
497 maMouseDoubleClickHandlers
.isEmpty());
500 void EventMultiplexerImpl::tick()
503 return; // this event is just a left-over, ignore
507 if( !maNextEffectHandlers
.isEmpty() )
509 // still handlers left, schedule next timeout
510 // event. Will also set mbIsTickEventOn back to true
515 void EventMultiplexerImpl::scheduleTick()
517 EventSharedPtr
pEvent(
518 makeDelay( boost::bind( &EventMultiplexerImpl::tick
,
521 "EventMultiplexerImpl::tick with delay"));
523 // store weak reference to generated event, to notice when
524 // the event queue gets cleansed (we then have to
525 // regenerate the tick event!)
526 mpTickEvent
= pEvent
;
528 // enabled auto mode: simply schedule a timeout event,
529 // which will eventually call our tick() method
530 mrEventQueue
.addEventForNextRound( pEvent
);
533 void EventMultiplexerImpl::handleTicks()
536 return; // nothing to do, don't need no ticks
538 EventSharedPtr
pTickEvent( mpTickEvent
.lock() );
540 return; // nothing to do, there's already a tick
543 // schedule initial tick (which reschedules itself
544 // after that, all by itself)
549 void EventMultiplexerImpl::clear()
551 // deregister from all views.
552 if( isMouseListenerRegistered() )
554 for( UnoViewVector::const_iterator aIter
=mrViewContainer
.begin(),
555 aEnd
=mrViewContainer
.end();
559 if( (*aIter
)->getUnoView().is() )
560 (*aIter
)->getUnoView()->removeMouseListener( mxListener
.get() );
564 if( !maMouseMoveHandlers
.isEmpty() )
566 for( UnoViewVector::const_iterator aIter
=mrViewContainer
.begin(),
567 aEnd
=mrViewContainer
.end();
571 if( (*aIter
)->getUnoView().is() )
572 (*aIter
)->getUnoView()->removeMouseMotionListener( mxListener
.get() );
576 // clear all handlers (releases all references)
577 maNextEffectHandlers
.clear();
578 maSlideStartHandlers
.clear();
579 maSlideEndHandlers
.clear();
580 maAnimationStartHandlers
.clear();
581 maAnimationEndHandlers
.clear();
582 maSlideAnimationsEndHandlers
.clear();
583 maAudioStoppedHandlers
.clear();
584 maCommandStopAudioHandlers
.clear();
585 maPauseHandlers
.clear();
586 maViewHandlers
.clear();
587 maViewRepaintHandlers
.clear();
588 maMouseClickHandlers
.clear();
589 maMouseDoubleClickHandlers
.clear();
590 maMouseMoveHandlers
.clear();
591 maHyperlinkHandlers
.clear();
595 // XMouseListener implementation
596 bool EventMultiplexerImpl::notifyMouseHandlers(
597 const ImplMouseHandlers
& rQueue
,
598 bool (MouseEventHandler::*pHandlerMethod
)( const awt::MouseEvent
& ),
599 const awt::MouseEvent
& e
)
601 uno::Reference
<presentation::XSlideShowView
> xView(
602 e
.Source
, uno::UNO_QUERY
);
604 ENSURE_OR_RETURN_FALSE( xView
.is(), "EventMultiplexer::notifyHandlers(): "
605 "event source is not an XSlideShowView" );
607 // find corresponding view (to map mouse position into user
609 UnoViewVector::const_iterator aIter
;
610 const UnoViewVector::const_iterator
aEnd ( mrViewContainer
.end() );
611 if( (aIter
=::std::find_if(
612 mrViewContainer
.begin(),
614 boost::bind( std::equal_to
< uno::Reference
<
615 presentation::XSlideShowView
> >(),
616 boost::cref( xView
),
617 boost::bind( &UnoView::getUnoView
, _1
) ) ) ) == aEnd
)
619 ENSURE_OR_RETURN_FALSE(
620 false, "EventMultiplexer::notifyHandlers(): "
621 "event source not found under registered views" );
624 // convert mouse position to user coordinate space
625 ::basegfx::B2DPoint
aPosition( e
.X
, e
.Y
);
626 ::basegfx::B2DHomMatrix
aMatrix( (*aIter
)->getTransformation() );
627 if( !aMatrix
.invert() )
628 ENSURE_OR_THROW( false, "EventMultiplexer::notifyHandlers():"
629 " view matrix singular" );
630 aPosition
*= aMatrix
;
632 awt::MouseEvent
aEvent( e
);
633 aEvent
.X
= ::basegfx::fround( aPosition
.getX() );
634 aEvent
.Y
= ::basegfx::fround( aPosition
.getY() );
636 // fire event on handlers, try in order of precedence. If
637 // one high-priority handler rejects the event
638 // (i.e. returns false), try next handler.
643 &ImplMouseHandlers::container_type::value_type::getHandler
,
648 void EventMultiplexerImpl::mousePressed( const awt::MouseEvent
& e
)
650 // fire double-click events for every second click
651 sal_Int32 nCurrClickCount
= e
.ClickCount
;
652 while( nCurrClickCount
> 1 &&
653 notifyMouseHandlers( maMouseDoubleClickHandlers
,
654 &MouseEventHandler::handleMousePressed
,
657 nCurrClickCount
-= 2;
660 // fire single-click events for all remaining clicks
661 while( nCurrClickCount
> 0 &&
662 notifyMouseHandlers( maMouseClickHandlers
,
663 &MouseEventHandler::handleMousePressed
,
670 void EventMultiplexerImpl::mouseReleased( const awt::MouseEvent
& e
)
672 // fire double-click events for every second click
673 sal_Int32 nCurrClickCount
= e
.ClickCount
;
674 while( nCurrClickCount
> 1 &&
675 notifyMouseHandlers( maMouseDoubleClickHandlers
,
676 &MouseEventHandler::handleMouseReleased
,
679 nCurrClickCount
-= 2;
682 // fire single-click events for all remaining clicks
683 while( nCurrClickCount
> 0 &&
684 notifyMouseHandlers( maMouseClickHandlers
,
685 &MouseEventHandler::handleMouseReleased
,
692 void EventMultiplexerImpl::mouseDragged( const awt::MouseEvent
& e
)
694 notifyMouseHandlers( maMouseMoveHandlers
,
695 &MouseEventHandler::handleMouseDragged
,
699 void EventMultiplexerImpl::mouseMoved( const awt::MouseEvent
& e
)
701 notifyMouseHandlers( maMouseMoveHandlers
,
702 &MouseEventHandler::handleMouseMoved
,
706 bool EventMultiplexerImpl::notifyNextEffect()
708 // fire event on handlers, try in order of precedence. If one
709 // high-priority handler rejects the event (i.e. returns false),
711 return maNextEffectHandlers
.apply(
713 &EventHandler::handleEvent
,
715 &ImplNextEffectHandlers::container_type::value_type::getHandler
,
722 EventMultiplexer::EventMultiplexer( EventQueue
& rEventQueue
,
723 UnoViewContainer
const& rViewContainer
) :
724 mpImpl( new EventMultiplexerImpl(rEventQueue
, rViewContainer
) )
728 EventMultiplexer::~EventMultiplexer()
730 // outline because of EventMultiplexerImpl's incomplete type
733 void EventMultiplexer::clear()
738 void EventMultiplexer::setAutomaticMode( bool bIsAuto
)
740 if( bIsAuto
== mpImpl
->mbIsAutoMode
)
741 return; // no change, nothing to do
743 mpImpl
->mbIsAutoMode
= bIsAuto
;
745 mpImpl
->handleTicks();
748 bool EventMultiplexer::getAutomaticMode() const
750 return mpImpl
->mbIsAutoMode
;
753 void EventMultiplexer::setAutomaticTimeout( double nTimeout
)
755 mpImpl
->mnTimeout
= nTimeout
;
758 double EventMultiplexer::getAutomaticTimeout() const
760 return mpImpl
->mnTimeout
;
763 void EventMultiplexer::addNextEffectHandler(
764 EventHandlerSharedPtr
const& rHandler
,
767 mpImpl
->maNextEffectHandlers
.addSorted(
768 EventMultiplexerImpl::ImplNextEffectHandlers::container_type::value_type(
772 // Enable tick events, if not done already
773 mpImpl
->handleTicks();
776 void EventMultiplexer::removeNextEffectHandler(
777 const EventHandlerSharedPtr
& rHandler
)
779 mpImpl
->maNextEffectHandlers
.remove(
780 EventMultiplexerImpl::ImplNextEffectHandlers::container_type::value_type(
785 void EventMultiplexer::addSlideStartHandler(
786 const EventHandlerSharedPtr
& rHandler
)
788 mpImpl
->maSlideStartHandlers
.add( rHandler
);
791 void EventMultiplexer::removeSlideStartHandler(
792 const EventHandlerSharedPtr
& rHandler
)
794 mpImpl
->maSlideStartHandlers
.remove( rHandler
);
797 void EventMultiplexer::addSlideEndHandler(
798 const EventHandlerSharedPtr
& rHandler
)
800 mpImpl
->maSlideEndHandlers
.add( rHandler
);
803 void EventMultiplexer::removeSlideEndHandler(
804 const EventHandlerSharedPtr
& rHandler
)
806 mpImpl
->maSlideEndHandlers
.remove( rHandler
);
809 void EventMultiplexer::addAnimationStartHandler(
810 const AnimationEventHandlerSharedPtr
& rHandler
)
812 mpImpl
->maAnimationStartHandlers
.add( rHandler
);
815 void EventMultiplexer::removeAnimationStartHandler(
816 const AnimationEventHandlerSharedPtr
& rHandler
)
818 mpImpl
->maAnimationStartHandlers
.remove( rHandler
);
821 void EventMultiplexer::addAnimationEndHandler(
822 const AnimationEventHandlerSharedPtr
& rHandler
)
824 mpImpl
->maAnimationEndHandlers
.add( rHandler
);
827 void EventMultiplexer::removeAnimationEndHandler(
828 const AnimationEventHandlerSharedPtr
& rHandler
)
830 mpImpl
->maAnimationEndHandlers
.remove( rHandler
);
833 void EventMultiplexer::addSlideAnimationsEndHandler(
834 const EventHandlerSharedPtr
& rHandler
)
836 mpImpl
->maSlideAnimationsEndHandlers
.add( rHandler
);
839 void EventMultiplexer::removeSlideAnimationsEndHandler(
840 const EventHandlerSharedPtr
& rHandler
)
842 mpImpl
->maSlideAnimationsEndHandlers
.remove( rHandler
);
845 void EventMultiplexer::addAudioStoppedHandler(
846 const AnimationEventHandlerSharedPtr
& rHandler
)
848 mpImpl
->maAudioStoppedHandlers
.add( rHandler
);
851 void EventMultiplexer::removeAudioStoppedHandler(
852 const AnimationEventHandlerSharedPtr
& rHandler
)
854 mpImpl
->maAudioStoppedHandlers
.remove( rHandler
);
857 void EventMultiplexer::addCommandStopAudioHandler(
858 const AnimationEventHandlerSharedPtr
& rHandler
)
860 mpImpl
->maCommandStopAudioHandlers
.add( rHandler
);
863 void EventMultiplexer::removeCommandStopAudioHandler(
864 const AnimationEventHandlerSharedPtr
& rHandler
)
866 mpImpl
->maCommandStopAudioHandlers
.remove( rHandler
);
869 void EventMultiplexer::addPauseHandler(
870 const PauseEventHandlerSharedPtr
& rHandler
)
872 mpImpl
->maPauseHandlers
.add( rHandler
);
875 void EventMultiplexer::removePauseHandler(
876 const PauseEventHandlerSharedPtr
& rHandler
)
878 mpImpl
->maPauseHandlers
.remove( rHandler
);
881 void EventMultiplexer::addViewHandler(
882 const ViewEventHandlerWeakPtr
& rHandler
)
884 mpImpl
->maViewHandlers
.add( rHandler
);
887 void EventMultiplexer::removeViewHandler( const ViewEventHandlerWeakPtr
& rHandler
)
889 mpImpl
->maViewHandlers
.remove( rHandler
);
892 void EventMultiplexer::addViewRepaintHandler( const ViewRepaintHandlerSharedPtr
& rHandler
)
894 mpImpl
->maViewRepaintHandlers
.add( rHandler
);
897 void EventMultiplexer::removeViewRepaintHandler( const ViewRepaintHandlerSharedPtr
& rHandler
)
899 mpImpl
->maViewRepaintHandlers
.remove( rHandler
);
902 void EventMultiplexer::addShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr
& rHandler
)
904 mpImpl
->maShapeListenerHandlers
.add( rHandler
);
907 void EventMultiplexer::removeShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr
& rHandler
)
909 mpImpl
->maShapeListenerHandlers
.remove( rHandler
);
912 void EventMultiplexer::addUserPaintHandler( const UserPaintEventHandlerSharedPtr
& rHandler
)
914 mpImpl
->maUserPaintEventHandlers
.add( rHandler
);
917 void EventMultiplexer::addClickHandler(
918 const MouseEventHandlerSharedPtr
& rHandler
,
921 mpImpl
->addMouseHandler(
922 mpImpl
->maMouseClickHandlers
,
925 mpImpl
->isMouseListenerRegistered()
927 : &presentation::XSlideShowView::addMouseListener
);
930 void EventMultiplexer::removeClickHandler(
931 const MouseEventHandlerSharedPtr
& rHandler
)
933 mpImpl
->maMouseClickHandlers
.remove(
934 EventMultiplexerImpl::ImplMouseHandlers::container_type::value_type(
938 if( !mpImpl
->isMouseListenerRegistered() )
939 mpImpl
->forEachView( &presentation::XSlideShowView::removeMouseListener
);
942 void EventMultiplexer::addDoubleClickHandler(
943 const MouseEventHandlerSharedPtr
& rHandler
,
946 mpImpl
->addMouseHandler(
947 mpImpl
->maMouseDoubleClickHandlers
,
950 mpImpl
->isMouseListenerRegistered()
952 : &presentation::XSlideShowView::addMouseListener
);
955 void EventMultiplexer::removeDoubleClickHandler(
956 const MouseEventHandlerSharedPtr
& rHandler
)
958 mpImpl
->maMouseDoubleClickHandlers
.remove(
959 EventMultiplexerImpl::ImplMouseHandlers::container_type::value_type(
963 if( !mpImpl
->isMouseListenerRegistered() )
964 mpImpl
->forEachView( &presentation::XSlideShowView::removeMouseListener
);
967 void EventMultiplexer::addMouseMoveHandler(
968 const MouseEventHandlerSharedPtr
& rHandler
,
971 mpImpl
->addMouseHandler(
972 mpImpl
->maMouseMoveHandlers
,
975 mpImpl
->maMouseMoveHandlers
.isEmpty()
976 ? &presentation::XSlideShowView::addMouseMotionListener
980 void EventMultiplexer::removeMouseMoveHandler(
981 const MouseEventHandlerSharedPtr
& rHandler
)
983 mpImpl
->maMouseMoveHandlers
.remove(
984 EventMultiplexerImpl::ImplMouseHandlers::container_type::value_type(
988 if( mpImpl
->maMouseMoveHandlers
.isEmpty() )
990 &presentation::XSlideShowView::removeMouseMotionListener
);
993 void EventMultiplexer::addHyperlinkHandler( const HyperlinkHandlerSharedPtr
& rHandler
,
996 mpImpl
->maHyperlinkHandlers
.addSorted(
997 EventMultiplexerImpl::ImplHyperLinkHandlers::container_type::value_type(
1002 void EventMultiplexer::removeHyperlinkHandler( const HyperlinkHandlerSharedPtr
& rHandler
)
1004 mpImpl
->maHyperlinkHandlers
.remove(
1005 EventMultiplexerImpl::ImplHyperLinkHandlers::container_type::value_type(
1010 bool EventMultiplexer::notifyShapeListenerAdded(
1011 const uno::Reference
<presentation::XShapeEventListener
>& xListener
,
1012 const uno::Reference
<drawing::XShape
>& xShape
)
1014 return mpImpl
->maShapeListenerHandlers
.applyAll(
1015 boost::bind(&ShapeListenerEventHandler::listenerAdded
,
1017 boost::cref(xListener
),
1018 boost::cref(xShape
)) );
1021 bool EventMultiplexer::notifyShapeListenerRemoved(
1022 const uno::Reference
<presentation::XShapeEventListener
>& xListener
,
1023 const uno::Reference
<drawing::XShape
>& xShape
)
1025 return mpImpl
->maShapeListenerHandlers
.applyAll(
1026 boost::bind(&ShapeListenerEventHandler::listenerRemoved
,
1028 boost::cref(xListener
),
1029 boost::cref(xShape
)) );
1032 bool EventMultiplexer::notifyShapeCursorChange(
1033 const uno::Reference
<drawing::XShape
>& xShape
,
1034 sal_Int16 nPointerShape
)
1036 return mpImpl
->maShapeCursorHandlers
.applyAll(
1037 boost::bind(&ShapeCursorEventHandler::cursorChanged
,
1039 boost::cref(xShape
),
1043 bool EventMultiplexer::notifyUserPaintColor( RGBColor
const& rUserColor
)
1045 return mpImpl
->maUserPaintEventHandlers
.applyAll(
1046 boost::bind(&UserPaintEventHandler::colorChanged
,
1048 boost::cref(rUserColor
)));
1051 bool EventMultiplexer::notifyUserPaintStrokeWidth( double rUserStrokeWidth
)
1053 return mpImpl
->maUserPaintEventHandlers
.applyAll(
1054 boost::bind(&UserPaintEventHandler::widthChanged
,
1059 bool EventMultiplexer::notifyUserPaintDisabled()
1061 return mpImpl
->maUserPaintEventHandlers
.applyAll(
1062 boost::mem_fn(&UserPaintEventHandler::disable
));
1065 bool EventMultiplexer::notifySwitchPenMode(){
1066 return mpImpl
->maUserPaintEventHandlers
.applyAll(
1067 boost::mem_fn(&UserPaintEventHandler::switchPenMode
));
1070 bool EventMultiplexer::notifySwitchEraserMode(){
1071 return mpImpl
->maUserPaintEventHandlers
.applyAll(
1072 boost::mem_fn(&UserPaintEventHandler::switchEraserMode
));
1075 //adding erasing all ink features with UserPaintOverlay
1076 bool EventMultiplexer::notifyEraseAllInk( bool const& rEraseAllInk
)
1078 return mpImpl
->maUserPaintEventHandlers
.applyAll(
1079 boost::bind(&UserPaintEventHandler::eraseAllInkChanged
,
1081 boost::cref(rEraseAllInk
)));
1084 //adding erasing features with UserPaintOverlay
1085 bool EventMultiplexer::notifyEraseInkWidth( sal_Int32 rEraseInkSize
)
1087 return mpImpl
->maUserPaintEventHandlers
.applyAll(
1088 boost::bind(&UserPaintEventHandler::eraseInkWidthChanged
,
1090 boost::cref(rEraseInkSize
)));
1093 bool EventMultiplexer::notifyNextEffect()
1095 return mpImpl
->notifyNextEffect();
1098 bool EventMultiplexer::notifySlideStartEvent()
1100 return mpImpl
->maSlideStartHandlers
.applyAll(
1101 boost::mem_fn(&EventHandler::handleEvent
) );
1104 bool EventMultiplexer::notifySlideEndEvent()
1106 return mpImpl
->maSlideEndHandlers
.applyAll(
1107 boost::mem_fn(&EventHandler::handleEvent
) );
1110 bool EventMultiplexer::notifyAnimationStart(
1111 const AnimationNodeSharedPtr
& rNode
)
1113 return EventMultiplexerImpl::notifyAllAnimationHandlers( mpImpl
->maAnimationStartHandlers
,
1117 bool EventMultiplexer::notifyAnimationEnd(
1118 const AnimationNodeSharedPtr
& rNode
)
1120 return EventMultiplexerImpl::notifyAllAnimationHandlers( mpImpl
->maAnimationEndHandlers
,
1124 bool EventMultiplexer::notifySlideAnimationsEnd()
1126 return mpImpl
->maSlideAnimationsEndHandlers
.applyAll(
1127 boost::mem_fn(&EventHandler::handleEvent
));
1130 bool EventMultiplexer::notifyAudioStopped(
1131 const AnimationNodeSharedPtr
& rNode
)
1133 return EventMultiplexerImpl::notifyAllAnimationHandlers(
1134 mpImpl
->maAudioStoppedHandlers
,
1138 bool EventMultiplexer::notifyCommandStopAudio(
1139 const AnimationNodeSharedPtr
& rNode
)
1141 return EventMultiplexerImpl::notifyAllAnimationHandlers(
1142 mpImpl
->maCommandStopAudioHandlers
,
1146 bool EventMultiplexer::notifyPauseMode( bool bPauseShow
)
1148 return mpImpl
->maPauseHandlers
.applyAll(
1149 boost::bind( &PauseEventHandler::handlePause
,
1153 bool EventMultiplexer::notifyViewAdded( const UnoViewSharedPtr
& rView
)
1155 ENSURE_OR_THROW( rView
, "EventMultiplexer::notifyViewAdded(): Invalid view");
1157 // register event listener
1158 uno::Reference
<presentation::XSlideShowView
> const rUnoView(
1159 rView
->getUnoView() );
1161 if( mpImpl
->isMouseListenerRegistered() )
1162 rUnoView
->addMouseListener(
1163 mpImpl
->mxListener
.get() );
1165 if( !mpImpl
->maMouseMoveHandlers
.isEmpty() )
1166 rUnoView
->addMouseMotionListener(
1167 mpImpl
->mxListener
.get() );
1169 return mpImpl
->maViewHandlers
.applyAll(
1170 boost::bind( &ViewEventHandler::viewAdded
,
1172 boost::cref(rView
) ));
1175 bool EventMultiplexer::notifyViewRemoved( const UnoViewSharedPtr
& rView
)
1177 ENSURE_OR_THROW( rView
,
1178 "EventMultiplexer::removeView(): Invalid view" );
1180 // revoke event listeners
1181 uno::Reference
<presentation::XSlideShowView
> const rUnoView(
1182 rView
->getUnoView() );
1184 if( mpImpl
->isMouseListenerRegistered() )
1185 rUnoView
->removeMouseListener(
1186 mpImpl
->mxListener
.get() );
1188 if( !mpImpl
->maMouseMoveHandlers
.isEmpty() )
1189 rUnoView
->removeMouseMotionListener(
1190 mpImpl
->mxListener
.get() );
1192 return mpImpl
->maViewHandlers
.applyAll(
1193 boost::bind( &ViewEventHandler::viewRemoved
,
1195 boost::cref(rView
) ));
1198 bool EventMultiplexer::notifyViewChanged( const UnoViewSharedPtr
& rView
)
1200 return mpImpl
->maViewHandlers
.applyAll(
1201 boost::bind( &ViewEventHandler::viewChanged
,
1203 boost::cref(rView
) ));
1206 bool EventMultiplexer::notifyViewChanged( const uno::Reference
<presentation::XSlideShowView
>& xView
)
1208 UnoViewSharedPtr
pView( mpImpl
->findUnoView(xView
) );
1211 return false; // view not registered here
1213 return notifyViewChanged( pView
);
1216 bool EventMultiplexer::notifyViewsChanged()
1218 return mpImpl
->maViewHandlers
.applyAll(
1219 boost::mem_fn( &ViewEventHandler::viewsChanged
));
1222 bool EventMultiplexer::notifyViewClobbered(
1223 const uno::Reference
<presentation::XSlideShowView
>& xView
)
1225 UnoViewSharedPtr
pView( mpImpl
->findUnoView(xView
) );
1228 return false; // view not registered here
1230 return mpImpl
->maViewRepaintHandlers
.applyAll(
1231 boost::bind( &ViewRepaintHandler::viewClobbered
,
1233 boost::cref(pView
) ));
1236 bool EventMultiplexer::notifyHyperlinkClicked(
1237 OUString
const& hyperLink
)
1239 return mpImpl
->maHyperlinkHandlers
.apply(
1240 boost::bind(&HyperlinkHandler::handleHyperlink
,
1242 boost::cref(hyperLink
)) );
1245 } // namespace internal
1246 } // namespace presentation
1248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */