LCOV - code coverage report
Current view: top level - slideshow/source/engine - eventmultiplexer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 411 0.0 %
Date: 2012-08-25 Functions: 0 125 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       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/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      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 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : // must be first
      22                 :            : #include <canvas/debug.hxx>
      23                 :            : #include <tools/diagnose_ex.h>
      24                 :            : 
      25                 :            : #include <rtl/ref.hxx>
      26                 :            : #include <cppuhelper/compbase2.hxx>
      27                 :            : #include <cppuhelper/basemutex.hxx>
      28                 :            : 
      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>
      35                 :            : 
      36                 :            : #include <basegfx/matrix/b2dhommatrix.hxx>
      37                 :            : #include <basegfx/numeric/ftools.hxx>
      38                 :            : 
      39                 :            : #include "tools.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"
      46                 :            : 
      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>
      52                 :            : 
      53                 :            : #include <vector>
      54                 :            : #include <boost/unordered_map.hpp>
      55                 :            : #include <algorithm>
      56                 :            : 
      57                 :            : using namespace ::com::sun::star;
      58                 :            : 
      59                 :            : namespace boost
      60                 :            : {
      61                 :            :     // add operator== for weak_ptr
      62                 :          0 :     template<typename T> bool operator==( weak_ptr<T> const& rLHS,
      63                 :            :                                           weak_ptr<T> const& rRHS )
      64                 :            :     {
      65                 :          0 :         return !(rLHS<rRHS) && !(rRHS<rLHS);
      66                 :            :     }
      67                 :            : }
      68                 :            : 
      69                 :            : namespace slideshow {
      70                 :            : namespace internal {
      71                 :            : 
      72                 :            : template <typename HandlerT>
      73                 :          0 : class PrioritizedHandlerEntry
      74                 :            : {
      75                 :            :     typedef boost::shared_ptr<HandlerT> HandlerSharedPtrT;
      76                 :            :     HandlerSharedPtrT mpHandler;
      77                 :            :     double            mnPrio;
      78                 :            : 
      79                 :            : public:
      80                 :          0 :     PrioritizedHandlerEntry( HandlerSharedPtrT const& pHandler,
      81                 :            :                              double                   nPrio ) :
      82                 :            :         mpHandler(pHandler),
      83                 :          0 :         mnPrio(nPrio)
      84                 :          0 :     {}
      85                 :            : 
      86                 :          0 :     HandlerSharedPtrT const& getHandler() const { return mpHandler; }
      87                 :            : 
      88                 :            :     /// To sort according to priority
      89                 :          0 :     bool operator<( PrioritizedHandlerEntry const& rRHS ) const
      90                 :            :     {
      91                 :            :         // reversed order - high prioritized entries
      92                 :            :         // should be at the beginning of the queue
      93                 :          0 :         return mnPrio > rRHS.mnPrio;
      94                 :            :     }
      95                 :            : 
      96                 :            :     /// To permit std::remove in removeHandler template
      97                 :          0 :     bool operator==( PrioritizedHandlerEntry const& rRHS ) const
      98                 :            :     {
      99                 :            :         // ignore prio, for removal, only the handler ptr matters
     100                 :          0 :         return mpHandler == rRHS.mpHandler;
     101                 :            :     }
     102                 :            : };
     103                 :            : 
     104                 :          0 : template<typename T> inline T* get_pointer(PrioritizedHandlerEntry<T> const& handler)
     105                 :            : {
     106                 :          0 :     return handler.getHandler().get();
     107                 :            : }
     108                 :            : 
     109                 :            : 
     110                 :            : 
     111                 :            : ////////////////////////////////////////////////////////////////////////////
     112                 :            : 
     113                 :            : 
     114                 :            : typedef cppu::WeakComponentImplHelper2<
     115                 :            :     awt::XMouseListener,
     116                 :            :     awt::XMouseMotionListener > Listener_UnoBase;
     117                 :            : 
     118                 :            : /** Listener class, to decouple UNO lifetime from EventMultiplexer
     119                 :            : 
     120                 :            :     This class gets registered as the XMouse(Motion)Listener on the
     121                 :            :     XSlideViews, and passes on the events to the EventMultiplexer (via
     122                 :            :     EventQueue indirection, to force the events into the main thread)
     123                 :            :  */
     124                 :          0 : class EventMultiplexerListener : private cppu::BaseMutex,
     125                 :            :                                  public Listener_UnoBase,
     126                 :            :                                  private ::boost::noncopyable
     127                 :            : {
     128                 :            : public:
     129                 :          0 :     EventMultiplexerListener( EventQueue&           rEventQueue,
     130                 :            :                               EventMultiplexerImpl& rEventMultiplexer ) :
     131                 :            :         Listener_UnoBase( m_aMutex ),
     132                 :            :         mpEventQueue( &rEventQueue ),
     133                 :          0 :         mpEventMultiplexer( &rEventMultiplexer )
     134                 :            :     {
     135                 :          0 :     }
     136                 :            : 
     137                 :            :     // WeakComponentImplHelperBase::disposing
     138                 :            :     virtual void SAL_CALL disposing();
     139                 :            : 
     140                 :            : private:
     141                 :            :     virtual void SAL_CALL disposing( const lang::EventObject& Source )
     142                 :            :         throw (uno::RuntimeException);
     143                 :            : 
     144                 :            :     // XMouseListener implementation
     145                 :            :     virtual void SAL_CALL mousePressed( const awt::MouseEvent& e )
     146                 :            :         throw (uno::RuntimeException);
     147                 :            :     virtual void SAL_CALL mouseReleased( const awt::MouseEvent& e )
     148                 :            :         throw (uno::RuntimeException);
     149                 :            :     virtual void SAL_CALL mouseEntered( const awt::MouseEvent& e )
     150                 :            :         throw (uno::RuntimeException);
     151                 :            :     virtual void SAL_CALL mouseExited( const awt::MouseEvent& e )
     152                 :            :         throw (uno::RuntimeException);
     153                 :            : 
     154                 :            :     // XMouseMotionListener implementation
     155                 :            :     virtual void SAL_CALL mouseDragged( const awt::MouseEvent& e )
     156                 :            :         throw (uno::RuntimeException);
     157                 :            :     virtual void SAL_CALL mouseMoved( const awt::MouseEvent& e )
     158                 :            :         throw (uno::RuntimeException);
     159                 :            : 
     160                 :            : 
     161                 :            :     EventQueue*           mpEventQueue;
     162                 :            :     EventMultiplexerImpl* mpEventMultiplexer;
     163                 :            : };
     164                 :            : 
     165                 :            : 
     166                 :            : ////////////////////////////////////////////////////////////////////////////
     167                 :            : 
     168                 :            : 
     169                 :            : struct EventMultiplexerImpl
     170                 :            : {
     171                 :          0 :     EventMultiplexerImpl( EventQueue&             rEventQueue,
     172                 :            :                           UnoViewContainer const& rViewContainer ) :
     173                 :            :         mrEventQueue(rEventQueue),
     174                 :            :         mrViewContainer(rViewContainer),
     175                 :            :         mxListener( new EventMultiplexerListener(rEventQueue,
     176                 :          0 :                                                  *this) ),
     177                 :            :         maNextEffectHandlers(),
     178                 :            :         maSlideStartHandlers(),
     179                 :            :         maSlideEndHandlers(),
     180                 :            :         maAnimationStartHandlers(),
     181                 :            :         maAnimationEndHandlers(),
     182                 :            :         maSlideAnimationsEndHandlers(),
     183                 :            :         maAudioStoppedHandlers(),
     184                 :            :         maCommandStopAudioHandlers(),
     185                 :            :         maPauseHandlers(),
     186                 :            :         maViewHandlers(),
     187                 :            :         maViewRepaintHandlers(),
     188                 :            :         maShapeListenerHandlers(),
     189                 :            :         maUserPaintEventHandlers(),
     190                 :            :         maShapeCursorHandlers(),
     191                 :            :         maMouseClickHandlers(),
     192                 :            :         maMouseDoubleClickHandlers(),
     193                 :            :         maMouseMoveHandlers(),
     194                 :            :         maHyperlinkHandlers(),
     195                 :            :         mnTimeout(0.0),
     196                 :            :         mpTickEvent(),
     197                 :          0 :         mbIsAutoMode(false)
     198                 :          0 :     {}
     199                 :            : 
     200                 :          0 :     ~EventMultiplexerImpl()
     201                 :          0 :     {
     202                 :          0 :         if( mxListener.is() )
     203                 :          0 :             mxListener->dispose();
     204                 :          0 :     }
     205                 :            : 
     206                 :            :     /// Remove all handlers
     207                 :            :     void clear();
     208                 :            : 
     209                 :            :     // actual handler callbacks (get called from the UNO interface
     210                 :            :     // listeners via event queue)
     211                 :            :     void mousePressed( const awt::MouseEvent& e );
     212                 :            :     void mouseReleased( const awt::MouseEvent& e );
     213                 :            :     void mouseDragged( const awt::MouseEvent& e );
     214                 :            :     void mouseMoved( const awt::MouseEvent& e );
     215                 :            : 
     216                 :            :     bool isMouseListenerRegistered() const;
     217                 :            : 
     218                 :            :     typedef ThreadUnsafeListenerContainer<
     219                 :            :         PrioritizedHandlerEntry<EventHandler>,
     220                 :            :         std::vector<
     221                 :            :             PrioritizedHandlerEntry<EventHandler> > >     ImplNextEffectHandlers;
     222                 :            :     typedef PrioritizedHandlerEntry<MouseEventHandler>    ImplMouseHandlerEntry;
     223                 :            :     typedef ThreadUnsafeListenerContainer<
     224                 :            :         ImplMouseHandlerEntry,
     225                 :            :         std::vector<ImplMouseHandlerEntry> >              ImplMouseHandlers;
     226                 :            :     typedef ThreadUnsafeListenerContainer<
     227                 :            :         EventHandlerSharedPtr,
     228                 :            :         std::vector<EventHandlerSharedPtr> >              ImplEventHandlers;
     229                 :            :     typedef ThreadUnsafeListenerContainer<
     230                 :            :         AnimationEventHandlerSharedPtr,
     231                 :            :         std::vector<AnimationEventHandlerSharedPtr> >     ImplAnimationHandlers;
     232                 :            :     typedef ThreadUnsafeListenerContainer<
     233                 :            :         PauseEventHandlerSharedPtr,
     234                 :            :         std::vector<PauseEventHandlerSharedPtr> >         ImplPauseHandlers;
     235                 :            :     typedef ThreadUnsafeListenerContainer<
     236                 :            :         ViewEventHandlerWeakPtr,
     237                 :            :         std::vector<ViewEventHandlerWeakPtr> >            ImplViewHandlers;
     238                 :            :     typedef ThreadUnsafeListenerContainer<
     239                 :            :         ViewRepaintHandlerSharedPtr,
     240                 :            :         std::vector<ViewRepaintHandlerSharedPtr> >        ImplRepaintHandlers;
     241                 :            :     typedef ThreadUnsafeListenerContainer<
     242                 :            :         ShapeListenerEventHandlerSharedPtr,
     243                 :            :         std::vector<ShapeListenerEventHandlerSharedPtr> > ImplShapeListenerHandlers;
     244                 :            :     typedef ThreadUnsafeListenerContainer<
     245                 :            :         UserPaintEventHandlerSharedPtr,
     246                 :            :         std::vector<UserPaintEventHandlerSharedPtr> >     ImplUserPaintEventHandlers;
     247                 :            :     typedef ThreadUnsafeListenerContainer<
     248                 :            :         ShapeCursorEventHandlerSharedPtr,
     249                 :            :         std::vector<ShapeCursorEventHandlerSharedPtr> >   ImplShapeCursorHandlers;
     250                 :            :     typedef ThreadUnsafeListenerContainer<
     251                 :            :         PrioritizedHandlerEntry<HyperlinkHandler>,
     252                 :            :         std::vector<PrioritizedHandlerEntry<HyperlinkHandler> > > ImplHyperLinkHandlers;
     253                 :            : 
     254                 :            :     template <typename XSlideShowViewFunc>
     255                 :            :     void forEachView( XSlideShowViewFunc pViewMethod );
     256                 :            : 
     257                 :            :     UnoViewSharedPtr findUnoView(const uno::Reference<
     258                 :            :                                    presentation::XSlideShowView>& xView) const;
     259                 :            : 
     260                 :            :     template< typename RegisterFunction >
     261                 :            :     void addMouseHandler( ImplMouseHandlers&                rHandlerContainer,
     262                 :            :                           const MouseEventHandlerSharedPtr& rHandler,
     263                 :            :                           double                            nPriority,
     264                 :            :                           RegisterFunction                  pRegisterListener );
     265                 :            : 
     266                 :            :     bool notifyAllAnimationHandlers( ImplAnimationHandlers const& rContainer,
     267                 :            :                                      AnimationNodeSharedPtr const& rNode );
     268                 :            : 
     269                 :            :     bool notifyMouseHandlers(
     270                 :            :         const ImplMouseHandlers& rQueue,
     271                 :            :         bool (MouseEventHandler::*pHandlerMethod)(
     272                 :            :             const awt::MouseEvent& ),
     273                 :            :         const awt::MouseEvent& e );
     274                 :            : 
     275                 :            :     bool notifyNextEffect();
     276                 :            : 
     277                 :            :     /// Called for automatic nextEffect
     278                 :            :     void tick();
     279                 :            : 
     280                 :            :     /// Schedules a tick event
     281                 :            :     void scheduleTick();
     282                 :            : 
     283                 :            :     /// Schedules tick events, if mbIsAutoMode is true
     284                 :            :     void handleTicks();
     285                 :            : 
     286                 :            : 
     287                 :            :     EventQueue&                         mrEventQueue;
     288                 :            :     UnoViewContainer const&             mrViewContainer;
     289                 :            :     ::rtl::Reference<
     290                 :            :         EventMultiplexerListener>       mxListener;
     291                 :            : 
     292                 :            :     ImplNextEffectHandlers              maNextEffectHandlers;
     293                 :            :     ImplEventHandlers                   maSlideStartHandlers;
     294                 :            :     ImplEventHandlers                   maSlideEndHandlers;
     295                 :            :     ImplAnimationHandlers               maAnimationStartHandlers;
     296                 :            :     ImplAnimationHandlers               maAnimationEndHandlers;
     297                 :            :     ImplEventHandlers                   maSlideAnimationsEndHandlers;
     298                 :            :     ImplAnimationHandlers               maAudioStoppedHandlers;
     299                 :            :     ImplAnimationHandlers               maCommandStopAudioHandlers;
     300                 :            :     ImplPauseHandlers                   maPauseHandlers;
     301                 :            :     ImplViewHandlers                    maViewHandlers;
     302                 :            :     ImplRepaintHandlers                 maViewRepaintHandlers;
     303                 :            :     ImplShapeListenerHandlers           maShapeListenerHandlers;
     304                 :            :     ImplUserPaintEventHandlers          maUserPaintEventHandlers;
     305                 :            :     ImplShapeCursorHandlers             maShapeCursorHandlers;
     306                 :            :     ImplMouseHandlers                   maMouseClickHandlers;
     307                 :            :     ImplMouseHandlers                   maMouseDoubleClickHandlers;
     308                 :            :     ImplMouseHandlers                   maMouseMoveHandlers;
     309                 :            :     ImplHyperLinkHandlers               maHyperlinkHandlers;
     310                 :            : 
     311                 :            :     /// automatic next effect mode timeout
     312                 :            :     double                        mnTimeout;
     313                 :            : 
     314                 :            :     /** Holds ptr to optional tick event weakly
     315                 :            : 
     316                 :            :         When event queue is cleansed, the next
     317                 :            :         setAutomaticMode(true) call is then able to
     318                 :            :         regenerate the event.
     319                 :            :     */
     320                 :            :     ::boost::weak_ptr< Event >    mpTickEvent;
     321                 :            :     bool                          mbIsAutoMode;
     322                 :            : };
     323                 :            : 
     324                 :            : 
     325                 :            : ///////////////////////////////////////////////////////////////////////////
     326                 :            : 
     327                 :            : 
     328                 :          0 : void SAL_CALL EventMultiplexerListener::disposing()
     329                 :            : {
     330                 :          0 :     osl::MutexGuard const guard( m_aMutex );
     331                 :          0 :     mpEventQueue = NULL;
     332                 :          0 :     mpEventMultiplexer = NULL;
     333                 :          0 : }
     334                 :            : 
     335                 :          0 : void SAL_CALL EventMultiplexerListener::disposing(
     336                 :            :     const lang::EventObject& /*rSource*/ ) throw (uno::RuntimeException)
     337                 :            : {
     338                 :            :     // there's no real point in acting on this message - after all,
     339                 :            :     // the event sources are the XSlideShowViews, which must be
     340                 :            :     // explicitly removed from the slideshow via
     341                 :            :     // XSlideShow::removeView(). thus, if a XSlideShowView has
     342                 :            :     // properly removed itself from the slideshow, it will not be
     343                 :            :     // found here. and if it hasn't, there'll be other references at
     344                 :            :     // other places within the slideshow, anyway...
     345                 :          0 : }
     346                 :            : 
     347                 :          0 : void SAL_CALL EventMultiplexerListener::mousePressed(
     348                 :            :     const awt::MouseEvent& e ) throw (uno::RuntimeException)
     349                 :            : {
     350                 :          0 :     osl::MutexGuard const guard( m_aMutex );
     351                 :            : 
     352                 :            :     // notify mouse press. Don't call handlers directly, this
     353                 :            :     // might not be the main thread!
     354                 :          0 :     if( mpEventQueue )
     355                 :            :         mpEventQueue->addEvent(
     356                 :            :             makeEvent( boost::bind( &EventMultiplexerImpl::mousePressed,
     357                 :            :                                     mpEventMultiplexer,
     358                 :            :                                     e ),
     359                 :          0 :                        "EventMultiplexerImpl::mousePressed") );
     360                 :          0 : }
     361                 :            : 
     362                 :          0 : void SAL_CALL EventMultiplexerListener::mouseReleased(
     363                 :            :     const awt::MouseEvent& e ) throw (uno::RuntimeException)
     364                 :            : {
     365                 :          0 :     osl::MutexGuard const guard( m_aMutex );
     366                 :            : 
     367                 :            :     // notify mouse release. Don't call handlers directly,
     368                 :            :     // this might not be the main thread!
     369                 :          0 :     if( mpEventQueue )
     370                 :            :         mpEventQueue->addEvent(
     371                 :            :             makeEvent( boost::bind( &EventMultiplexerImpl::mouseReleased,
     372                 :            :                                     mpEventMultiplexer,
     373                 :            :                                     e ),
     374                 :          0 :                        "EventMultiplexerImpl::mouseReleased") );
     375                 :          0 : }
     376                 :            : 
     377                 :          0 : void SAL_CALL EventMultiplexerListener::mouseEntered(
     378                 :            :     const awt::MouseEvent& /*e*/ ) throw (uno::RuntimeException)
     379                 :            : {
     380                 :            :     // not used here
     381                 :          0 : }
     382                 :            : 
     383                 :          0 : void SAL_CALL EventMultiplexerListener::mouseExited(
     384                 :            :     const awt::MouseEvent& /*e*/ ) throw (uno::RuntimeException)
     385                 :            : {
     386                 :            :     // not used here
     387                 :          0 : }
     388                 :            : 
     389                 :            : // XMouseMotionListener implementation
     390                 :          0 : void SAL_CALL EventMultiplexerListener::mouseDragged(
     391                 :            :     const awt::MouseEvent& e ) throw (uno::RuntimeException)
     392                 :            : {
     393                 :          0 :     osl::MutexGuard const guard( m_aMutex );
     394                 :            : 
     395                 :            :     // notify mouse drag. Don't call handlers directly, this
     396                 :            :     // might not be the main thread!
     397                 :          0 :     if( mpEventQueue )
     398                 :            :         mpEventQueue->addEvent(
     399                 :            :             makeEvent( boost::bind( &EventMultiplexerImpl::mouseDragged,
     400                 :            :                                     mpEventMultiplexer,
     401                 :            :                                     e ),
     402                 :          0 :                        "EventMultiplexerImpl::mouseDragged") );
     403                 :          0 : }
     404                 :            : 
     405                 :          0 : void SAL_CALL EventMultiplexerListener::mouseMoved(
     406                 :            :     const awt::MouseEvent& e ) throw (uno::RuntimeException)
     407                 :            : {
     408                 :          0 :     osl::MutexGuard const guard( m_aMutex );
     409                 :            : 
     410                 :            :     // notify mouse move. Don't call handlers directly, this
     411                 :            :     // might not be the main thread!
     412                 :          0 :     if( mpEventQueue )
     413                 :            :         mpEventQueue->addEvent(
     414                 :            :             makeEvent( boost::bind( &EventMultiplexerImpl::mouseMoved,
     415                 :            :                                     mpEventMultiplexer,
     416                 :            :                                     e ),
     417                 :          0 :                        "EventMultiplexerImpl::mouseMoved") );
     418                 :          0 : }
     419                 :            : 
     420                 :            : 
     421                 :            : ///////////////////////////////////////////////////////////////////////////
     422                 :            : 
     423                 :            : 
     424                 :          0 : bool EventMultiplexerImpl::notifyAllAnimationHandlers( ImplAnimationHandlers const& rContainer,
     425                 :            :                                                        AnimationNodeSharedPtr const& rNode )
     426                 :            : {
     427                 :            :     return rContainer.applyAll(
     428                 :            :         boost::bind( &AnimationEventHandler::handleAnimationEvent,
     429                 :          0 :                      _1, boost::cref(rNode) ) );
     430                 :            : }
     431                 :            : 
     432                 :            : template <typename XSlideShowViewFunc>
     433                 :          0 : void EventMultiplexerImpl::forEachView( XSlideShowViewFunc pViewMethod )
     434                 :            : {
     435                 :          0 :     if( pViewMethod )
     436                 :            :     {
     437                 :            :         // (un)register mouse listener on all views
     438                 :          0 :         for( UnoViewVector::const_iterator aIter( mrViewContainer.begin() ),
     439                 :          0 :                  aEnd( mrViewContainer.end() ); aIter != aEnd; ++aIter )
     440                 :            :         {
     441                 :          0 :             uno::Reference<presentation::XSlideShowView> xView ((*aIter)->getUnoView());
     442                 :          0 :             if (xView.is())
     443                 :            :             {
     444                 :          0 :                 (xView.get()->*pViewMethod)( mxListener.get() );
     445                 :            :             }
     446                 :            :             else
     447                 :            :             {
     448                 :          0 :                 OSL_ASSERT(xView.is());
     449                 :            :             }
     450                 :            :         }
     451                 :            :     }
     452                 :          0 : }
     453                 :            : 
     454                 :          0 : UnoViewSharedPtr EventMultiplexerImpl::findUnoView(
     455                 :            :     const uno::Reference<presentation::XSlideShowView>& xView) const
     456                 :            : {
     457                 :            :     // find view from which the change originated
     458                 :          0 :     UnoViewVector::const_iterator       aIter;
     459                 :          0 :     const UnoViewVector::const_iterator aEnd ( mrViewContainer.end() );
     460                 :          0 :     if( (aIter=std::find_if( mrViewContainer.begin(),
     461                 :            :                              aEnd,
     462                 :            :                              boost::bind(
     463                 :            :                                  std::equal_to<uno::Reference<presentation::XSlideShowView> >(),
     464                 :            :                                  boost::cref( xView ),
     465                 :          0 :                                  boost::bind( &UnoView::getUnoView, _1 )))) == aEnd )
     466                 :            :     {
     467                 :            :         OSL_FAIL("EventMultiplexer::findUnoView(): unexpected message source" );
     468                 :          0 :         return UnoViewSharedPtr();
     469                 :            :     }
     470                 :            : 
     471                 :          0 :     return *aIter;
     472                 :            : }
     473                 :            : 
     474                 :            : template< typename RegisterFunction >
     475                 :          0 : void EventMultiplexerImpl::addMouseHandler(
     476                 :            :     ImplMouseHandlers&                rHandlerContainer,
     477                 :            :     const MouseEventHandlerSharedPtr& rHandler,
     478                 :            :     double                            nPriority,
     479                 :            :     RegisterFunction                  pRegisterListener )
     480                 :            : {
     481                 :          0 :     ENSURE_OR_THROW(
     482                 :            :         rHandler,
     483                 :            :         "EventMultiplexer::addMouseHandler(): Invalid handler" );
     484                 :            : 
     485                 :            :     // register mouse listener on all views
     486                 :          0 :     forEachView( pRegisterListener );
     487                 :            : 
     488                 :            :     // add into sorted container:
     489                 :          0 :     rHandlerContainer.addSorted(
     490                 :            :         typename ImplMouseHandlers::container_type::value_type(
     491                 :            :             rHandler,
     492                 :            :             nPriority ));
     493                 :          0 : }
     494                 :            : 
     495                 :          0 : bool EventMultiplexerImpl::isMouseListenerRegistered() const
     496                 :            : {
     497                 :          0 :     return !(maMouseClickHandlers.isEmpty() &&
     498                 :          0 :              maMouseDoubleClickHandlers.isEmpty());
     499                 :            : }
     500                 :            : 
     501                 :          0 : void EventMultiplexerImpl::tick()
     502                 :            : {
     503                 :          0 :     if( !mbIsAutoMode )
     504                 :          0 :         return; // this event is just a left-over, ignore
     505                 :            : 
     506                 :          0 :     notifyNextEffect();
     507                 :            : 
     508                 :          0 :     if( !maNextEffectHandlers.isEmpty() )
     509                 :            :     {
     510                 :            :         // still handlers left, schedule next timeout
     511                 :            :         // event. Will also set mbIsTickEventOn back to true
     512                 :          0 :         scheduleTick();
     513                 :            :     }
     514                 :            : }
     515                 :            : 
     516                 :          0 : void EventMultiplexerImpl::scheduleTick()
     517                 :            : {
     518                 :            :     EventSharedPtr pEvent(
     519                 :          0 :         makeDelay( boost::bind( &EventMultiplexerImpl::tick,
     520                 :            :                                 this ),
     521                 :            :                    mnTimeout,
     522                 :          0 :                    "EventMultiplexerImpl::tick with delay"));
     523                 :            : 
     524                 :            :     // store weak reference to generated event, to notice when
     525                 :            :     // the event queue gets cleansed (we then have to
     526                 :            :     // regenerate the tick event!)
     527                 :          0 :     mpTickEvent = pEvent;
     528                 :            : 
     529                 :            :     // enabled auto mode: simply schedule a timeout event,
     530                 :            :     // which will eventually call our tick() method
     531                 :          0 :     mrEventQueue.addEventForNextRound( pEvent );
     532                 :          0 : }
     533                 :            : 
     534                 :          0 : void EventMultiplexerImpl::handleTicks()
     535                 :            : {
     536                 :          0 :     if( !mbIsAutoMode )
     537                 :            :         return; // nothing to do, don't need no ticks
     538                 :            : 
     539                 :          0 :     EventSharedPtr pTickEvent( mpTickEvent.lock() );
     540                 :          0 :     if( pTickEvent )
     541                 :            :         return; // nothing to do, there's already a tick
     542                 :            :                 // pending
     543                 :            : 
     544                 :            :     // schedule initial tick (which reschedules itself
     545                 :            :     // after that, all by itself)
     546                 :          0 :     scheduleTick();
     547                 :            : }
     548                 :            : 
     549                 :            : 
     550                 :          0 : void EventMultiplexerImpl::clear()
     551                 :            : {
     552                 :            :     // deregister from all views.
     553                 :          0 :     if( isMouseListenerRegistered() )
     554                 :            :     {
     555                 :          0 :         for( UnoViewVector::const_iterator aIter=mrViewContainer.begin(),
     556                 :          0 :                  aEnd=mrViewContainer.end();
     557                 :            :              aIter!=aEnd;
     558                 :            :              ++aIter )
     559                 :            :         {
     560                 :          0 :             if( (*aIter)->getUnoView().is() )
     561                 :          0 :                 (*aIter)->getUnoView()->removeMouseListener( mxListener.get() );
     562                 :            :         }
     563                 :            :     }
     564                 :            : 
     565                 :          0 :     if( !maMouseMoveHandlers.isEmpty() )
     566                 :            :     {
     567                 :          0 :         for( UnoViewVector::const_iterator aIter=mrViewContainer.begin(),
     568                 :          0 :                  aEnd=mrViewContainer.end();
     569                 :            :              aIter!=aEnd;
     570                 :            :              ++aIter )
     571                 :            :         {
     572                 :          0 :             if( (*aIter)->getUnoView().is() )
     573                 :          0 :                 (*aIter)->getUnoView()->removeMouseMotionListener( mxListener.get() );
     574                 :            :         }
     575                 :            :     }
     576                 :            : 
     577                 :            :     // clear all handlers (releases all references)
     578                 :          0 :     maNextEffectHandlers.clear();
     579                 :          0 :     maSlideStartHandlers.clear();
     580                 :          0 :     maSlideEndHandlers.clear();
     581                 :          0 :     maAnimationStartHandlers.clear();
     582                 :          0 :     maAnimationEndHandlers.clear();
     583                 :          0 :     maSlideAnimationsEndHandlers.clear();
     584                 :          0 :     maAudioStoppedHandlers.clear();
     585                 :          0 :     maCommandStopAudioHandlers.clear();
     586                 :          0 :     maPauseHandlers.clear();
     587                 :          0 :     maViewHandlers.clear();
     588                 :          0 :     maViewRepaintHandlers.clear();
     589                 :          0 :     maMouseClickHandlers.clear();
     590                 :          0 :     maMouseDoubleClickHandlers.clear();
     591                 :          0 :     maMouseMoveHandlers.clear();
     592                 :          0 :     maHyperlinkHandlers.clear();
     593                 :          0 :     mpTickEvent.reset();
     594                 :          0 : }
     595                 :            : 
     596                 :            : // XMouseListener implementation
     597                 :          0 : bool EventMultiplexerImpl::notifyMouseHandlers(
     598                 :            :     const ImplMouseHandlers& rQueue,
     599                 :            :     bool (MouseEventHandler::*pHandlerMethod)( const awt::MouseEvent& ),
     600                 :            :     const awt::MouseEvent& e )
     601                 :            : {
     602                 :            :     uno::Reference<presentation::XSlideShowView> xView(
     603                 :          0 :         e.Source, uno::UNO_QUERY );
     604                 :            : 
     605                 :          0 :     ENSURE_OR_RETURN_FALSE( xView.is(), "EventMultiplexer::notifyHandlers(): "
     606                 :            :                        "event source is not an XSlideShowView" );
     607                 :            : 
     608                 :            :     // find corresponding view (to map mouse position into user
     609                 :            :     // coordinate space)
     610                 :          0 :     UnoViewVector::const_iterator       aIter;
     611                 :          0 :     const UnoViewVector::const_iterator aEnd  ( mrViewContainer.end() );
     612                 :          0 :     if( (aIter=::std::find_if(
     613                 :            :              mrViewContainer.begin(),
     614                 :            :              aEnd,
     615                 :            :              boost::bind( std::equal_to< uno::Reference<
     616                 :            :                           presentation::XSlideShowView > >(),
     617                 :            :                           boost::cref( xView ),
     618                 :          0 :                           boost::bind( &UnoView::getUnoView, _1 ) ) ) ) == aEnd)
     619                 :            :     {
     620                 :          0 :         ENSURE_OR_RETURN_FALSE(
     621                 :            :             false, "EventMultiplexer::notifyHandlers(): "
     622                 :            :             "event source not found under registered views" );
     623                 :            :     }
     624                 :            : 
     625                 :            :     // convert mouse position to user coordinate space
     626                 :          0 :     ::basegfx::B2DPoint     aPosition( e.X, e.Y );
     627                 :          0 :     ::basegfx::B2DHomMatrix aMatrix( (*aIter)->getTransformation() );
     628                 :          0 :     if( !aMatrix.invert() )
     629                 :          0 :         ENSURE_OR_THROW( false, "EventMultiplexer::notifyHandlers():"
     630                 :            :                           " view matrix singular" );
     631                 :          0 :     aPosition *= aMatrix;
     632                 :            : 
     633                 :          0 :     awt::MouseEvent aEvent( e );
     634                 :          0 :     aEvent.X = ::basegfx::fround( aPosition.getX() );
     635                 :          0 :     aEvent.Y = ::basegfx::fround( aPosition.getY() );
     636                 :            : 
     637                 :            :     // fire event on handlers, try in order of precedence. If
     638                 :            :     // one high-priority handler rejects the event
     639                 :            :     // (i.e. returns false), try next handler.
     640                 :            :     return rQueue.apply(
     641                 :            :         boost::bind(
     642                 :            :             pHandlerMethod,
     643                 :            :             boost::bind(
     644                 :            :                 &ImplMouseHandlers::container_type::value_type::getHandler,
     645                 :            :                 _1 ),
     646                 :          0 :             aEvent ));
     647                 :            : }
     648                 :            : 
     649                 :          0 : void EventMultiplexerImpl::mousePressed( const awt::MouseEvent& e )
     650                 :            : {
     651                 :            :     // fire double-click events for every second click
     652                 :          0 :     sal_Int32 nCurrClickCount = e.ClickCount;
     653                 :          0 :     while( nCurrClickCount > 1 &&
     654                 :            :            notifyMouseHandlers( maMouseDoubleClickHandlers,
     655                 :            :                                 &MouseEventHandler::handleMousePressed,
     656                 :          0 :                                 e ))
     657                 :            :     {
     658                 :          0 :         nCurrClickCount -= 2;
     659                 :            :     }
     660                 :            : 
     661                 :            :     // fire single-click events for all remaining clicks
     662                 :          0 :     while( nCurrClickCount > 0 &&
     663                 :            :            notifyMouseHandlers( maMouseClickHandlers,
     664                 :            :                                 &MouseEventHandler::handleMousePressed,
     665                 :          0 :                                 e ))
     666                 :            :     {
     667                 :          0 :         --nCurrClickCount;
     668                 :            :     }
     669                 :          0 : }
     670                 :            : 
     671                 :          0 : void EventMultiplexerImpl::mouseReleased( const awt::MouseEvent& e )
     672                 :            : {
     673                 :            :     // fire double-click events for every second click
     674                 :          0 :     sal_Int32 nCurrClickCount = e.ClickCount;
     675                 :          0 :     while( nCurrClickCount > 1 &&
     676                 :            :            notifyMouseHandlers( maMouseDoubleClickHandlers,
     677                 :            :                                 &MouseEventHandler::handleMouseReleased,
     678                 :          0 :                                 e ))
     679                 :            :     {
     680                 :          0 :         nCurrClickCount -= 2;
     681                 :            :     }
     682                 :            : 
     683                 :            :     // fire single-click events for all remaining clicks
     684                 :          0 :     while( nCurrClickCount > 0 &&
     685                 :            :            notifyMouseHandlers( maMouseClickHandlers,
     686                 :            :                                 &MouseEventHandler::handleMouseReleased,
     687                 :          0 :                                 e ))
     688                 :            :     {
     689                 :          0 :         --nCurrClickCount;
     690                 :            :     }
     691                 :          0 : }
     692                 :            : 
     693                 :          0 : void EventMultiplexerImpl::mouseDragged( const awt::MouseEvent& e )
     694                 :            : {
     695                 :            :     notifyMouseHandlers( maMouseMoveHandlers,
     696                 :            :                          &MouseEventHandler::handleMouseDragged,
     697                 :          0 :                          e );
     698                 :          0 : }
     699                 :            : 
     700                 :          0 : void EventMultiplexerImpl::mouseMoved( const awt::MouseEvent& e )
     701                 :            : {
     702                 :            :     notifyMouseHandlers( maMouseMoveHandlers,
     703                 :            :                          &MouseEventHandler::handleMouseMoved,
     704                 :          0 :                          e );
     705                 :          0 : }
     706                 :            : 
     707                 :          0 : bool EventMultiplexerImpl::notifyNextEffect()
     708                 :            : {
     709                 :            :     // fire event on handlers, try in order of precedence. If one
     710                 :            :     // high-priority handler rejects the event (i.e. returns false),
     711                 :            :     // try next handler.
     712                 :            :     return maNextEffectHandlers.apply(
     713                 :            :         boost::bind(
     714                 :            :             &EventHandler::handleEvent,
     715                 :            :             boost::bind(
     716                 :            :                 &ImplNextEffectHandlers::container_type::value_type::getHandler,
     717                 :          0 :                 _1 )) );
     718                 :            : }
     719                 :            : 
     720                 :            : //////////////////////////////////////////////////////////////////////////
     721                 :            : 
     722                 :            : 
     723                 :          0 : EventMultiplexer::EventMultiplexer( EventQueue&             rEventQueue,
     724                 :            :                                     UnoViewContainer const& rViewContainer ) :
     725                 :          0 :     mpImpl( new EventMultiplexerImpl(rEventQueue, rViewContainer) )
     726                 :            : {
     727                 :          0 : }
     728                 :            : 
     729                 :          0 : EventMultiplexer::~EventMultiplexer()
     730                 :            : {
     731                 :            :     // outline because of EventMultiplexerImpl's incomplete type
     732                 :          0 : }
     733                 :            : 
     734                 :          0 : void EventMultiplexer::clear()
     735                 :            : {
     736                 :          0 :     mpImpl->clear();
     737                 :          0 : }
     738                 :            : 
     739                 :          0 : void EventMultiplexer::setAutomaticMode( bool bIsAuto )
     740                 :            : {
     741                 :          0 :     if( bIsAuto == mpImpl->mbIsAutoMode )
     742                 :          0 :         return; // no change, nothing to do
     743                 :            : 
     744                 :          0 :     mpImpl->mbIsAutoMode = bIsAuto;
     745                 :            : 
     746                 :          0 :     mpImpl->handleTicks();
     747                 :            : }
     748                 :            : 
     749                 :          0 : bool EventMultiplexer::getAutomaticMode() const
     750                 :            : {
     751                 :          0 :     return mpImpl->mbIsAutoMode;
     752                 :            : }
     753                 :            : 
     754                 :          0 : void EventMultiplexer::setAutomaticTimeout( double nTimeout )
     755                 :            : {
     756                 :          0 :     mpImpl->mnTimeout = nTimeout;
     757                 :          0 : }
     758                 :            : 
     759                 :          0 : double EventMultiplexer::getAutomaticTimeout() const
     760                 :            : {
     761                 :          0 :     return mpImpl->mnTimeout;
     762                 :            : }
     763                 :            : 
     764                 :          0 : void EventMultiplexer::addNextEffectHandler(
     765                 :            :     EventHandlerSharedPtr const& rHandler,
     766                 :            :     double                       nPriority )
     767                 :            : {
     768                 :          0 :     mpImpl->maNextEffectHandlers.addSorted(
     769                 :            :         EventMultiplexerImpl::ImplNextEffectHandlers::container_type::value_type(
     770                 :            :             rHandler,
     771                 :          0 :             nPriority) );
     772                 :            : 
     773                 :            :     // Enable tick events, if not done already
     774                 :          0 :     mpImpl->handleTicks();
     775                 :          0 : }
     776                 :            : 
     777                 :          0 : void EventMultiplexer::removeNextEffectHandler(
     778                 :            :     const EventHandlerSharedPtr& rHandler )
     779                 :            : {
     780                 :          0 :     mpImpl->maNextEffectHandlers.remove(
     781                 :            :         EventMultiplexerImpl::ImplNextEffectHandlers::container_type::value_type(
     782                 :            :             rHandler,
     783                 :          0 :             0.0) );
     784                 :          0 : }
     785                 :            : 
     786                 :          0 : void EventMultiplexer::addSlideStartHandler(
     787                 :            :     const EventHandlerSharedPtr& rHandler )
     788                 :            : {
     789                 :          0 :     mpImpl->maSlideStartHandlers.add( rHandler );
     790                 :          0 : }
     791                 :            : 
     792                 :          0 : void EventMultiplexer::removeSlideStartHandler(
     793                 :            :     const EventHandlerSharedPtr& rHandler )
     794                 :            : {
     795                 :          0 :     mpImpl->maSlideStartHandlers.remove( rHandler );
     796                 :          0 : }
     797                 :            : 
     798                 :          0 : void EventMultiplexer::addSlideEndHandler(
     799                 :            :     const EventHandlerSharedPtr& rHandler )
     800                 :            : {
     801                 :          0 :     mpImpl->maSlideEndHandlers.add( rHandler );
     802                 :          0 : }
     803                 :            : 
     804                 :          0 : void EventMultiplexer::removeSlideEndHandler(
     805                 :            :     const EventHandlerSharedPtr& rHandler )
     806                 :            : {
     807                 :          0 :     mpImpl->maSlideEndHandlers.remove( rHandler );
     808                 :          0 : }
     809                 :            : 
     810                 :          0 : void EventMultiplexer::addAnimationStartHandler(
     811                 :            :     const AnimationEventHandlerSharedPtr& rHandler )
     812                 :            : {
     813                 :          0 :     mpImpl->maAnimationStartHandlers.add( rHandler );
     814                 :          0 : }
     815                 :            : 
     816                 :          0 : void EventMultiplexer::removeAnimationStartHandler(
     817                 :            :     const AnimationEventHandlerSharedPtr& rHandler )
     818                 :            : {
     819                 :          0 :     mpImpl->maAnimationStartHandlers.remove( rHandler );
     820                 :          0 : }
     821                 :            : 
     822                 :          0 : void EventMultiplexer::addAnimationEndHandler(
     823                 :            :     const AnimationEventHandlerSharedPtr& rHandler )
     824                 :            : {
     825                 :          0 :     mpImpl->maAnimationEndHandlers.add( rHandler );
     826                 :          0 : }
     827                 :            : 
     828                 :          0 : void EventMultiplexer::removeAnimationEndHandler(
     829                 :            :     const AnimationEventHandlerSharedPtr& rHandler )
     830                 :            : {
     831                 :          0 :     mpImpl->maAnimationEndHandlers.remove( rHandler );
     832                 :          0 : }
     833                 :            : 
     834                 :          0 : void EventMultiplexer::addSlideAnimationsEndHandler(
     835                 :            :     const EventHandlerSharedPtr& rHandler )
     836                 :            : {
     837                 :          0 :     mpImpl->maSlideAnimationsEndHandlers.add( rHandler );
     838                 :          0 : }
     839                 :            : 
     840                 :          0 : void EventMultiplexer::removeSlideAnimationsEndHandler(
     841                 :            :     const EventHandlerSharedPtr& rHandler )
     842                 :            : {
     843                 :          0 :     mpImpl->maSlideAnimationsEndHandlers.remove( rHandler );
     844                 :          0 : }
     845                 :            : 
     846                 :          0 : void EventMultiplexer::addAudioStoppedHandler(
     847                 :            :     const AnimationEventHandlerSharedPtr& rHandler )
     848                 :            : {
     849                 :          0 :     mpImpl->maAudioStoppedHandlers.add( rHandler );
     850                 :          0 : }
     851                 :            : 
     852                 :          0 : void EventMultiplexer::removeAudioStoppedHandler(
     853                 :            :     const AnimationEventHandlerSharedPtr& rHandler )
     854                 :            : {
     855                 :          0 :     mpImpl->maAudioStoppedHandlers.remove( rHandler );
     856                 :          0 : }
     857                 :            : 
     858                 :          0 : void EventMultiplexer::addCommandStopAudioHandler(
     859                 :            :     const AnimationEventHandlerSharedPtr& rHandler )
     860                 :            : {
     861                 :          0 :     mpImpl->maCommandStopAudioHandlers.add( rHandler );
     862                 :          0 : }
     863                 :            : 
     864                 :          0 : void EventMultiplexer::removeCommandStopAudioHandler(
     865                 :            :     const AnimationEventHandlerSharedPtr& rHandler )
     866                 :            : {
     867                 :          0 :     mpImpl->maCommandStopAudioHandlers.remove( rHandler );
     868                 :          0 : }
     869                 :            : 
     870                 :          0 : void EventMultiplexer::addPauseHandler(
     871                 :            :     const PauseEventHandlerSharedPtr& rHandler )
     872                 :            : {
     873                 :          0 :     mpImpl->maPauseHandlers.add( rHandler );
     874                 :          0 : }
     875                 :            : 
     876                 :          0 : void EventMultiplexer::removePauseHandler(
     877                 :            :     const PauseEventHandlerSharedPtr&  rHandler )
     878                 :            : {
     879                 :          0 :     mpImpl->maPauseHandlers.remove( rHandler );
     880                 :          0 : }
     881                 :            : 
     882                 :          0 : void EventMultiplexer::addViewHandler(
     883                 :            :     const ViewEventHandlerWeakPtr& rHandler )
     884                 :            : {
     885                 :          0 :     mpImpl->maViewHandlers.add( rHandler );
     886                 :          0 : }
     887                 :            : 
     888                 :          0 : void EventMultiplexer::removeViewHandler( const ViewEventHandlerWeakPtr& rHandler )
     889                 :            : {
     890                 :          0 :     mpImpl->maViewHandlers.remove( rHandler );
     891                 :          0 : }
     892                 :            : 
     893                 :          0 : void EventMultiplexer::addViewRepaintHandler( const ViewRepaintHandlerSharedPtr& rHandler )
     894                 :            : {
     895                 :          0 :     mpImpl->maViewRepaintHandlers.add( rHandler );
     896                 :          0 : }
     897                 :            : 
     898                 :          0 : void EventMultiplexer::removeViewRepaintHandler( const ViewRepaintHandlerSharedPtr& rHandler )
     899                 :            : {
     900                 :          0 :     mpImpl->maViewRepaintHandlers.remove( rHandler );
     901                 :          0 : }
     902                 :            : 
     903                 :          0 : void EventMultiplexer::addShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr& rHandler )
     904                 :            : {
     905                 :          0 :     mpImpl->maShapeListenerHandlers.add( rHandler );
     906                 :          0 : }
     907                 :            : 
     908                 :          0 : void EventMultiplexer::removeShapeListenerHandler( const ShapeListenerEventHandlerSharedPtr& rHandler )
     909                 :            : {
     910                 :          0 :     mpImpl->maShapeListenerHandlers.remove( rHandler );
     911                 :          0 : }
     912                 :            : 
     913                 :          0 : void EventMultiplexer::addUserPaintHandler( const UserPaintEventHandlerSharedPtr& rHandler )
     914                 :            : {
     915                 :          0 :     mpImpl->maUserPaintEventHandlers.add( rHandler );
     916                 :          0 : }
     917                 :            : 
     918                 :          0 : void EventMultiplexer::addClickHandler(
     919                 :            :     const MouseEventHandlerSharedPtr& rHandler,
     920                 :            :     double                            nPriority )
     921                 :            : {
     922                 :            :     mpImpl->addMouseHandler(
     923                 :          0 :         mpImpl->maMouseClickHandlers,
     924                 :            :         rHandler,
     925                 :            :         nPriority,
     926                 :          0 :         mpImpl->isMouseListenerRegistered()
     927                 :            :         ? NULL
     928                 :          0 :         : &presentation::XSlideShowView::addMouseListener );
     929                 :          0 : }
     930                 :            : 
     931                 :          0 : void EventMultiplexer::removeClickHandler(
     932                 :            :     const MouseEventHandlerSharedPtr&  rHandler )
     933                 :            : {
     934                 :          0 :     mpImpl->maMouseClickHandlers.remove(
     935                 :            :         EventMultiplexerImpl::ImplMouseHandlers::container_type::value_type(
     936                 :            :             rHandler,
     937                 :          0 :             0.0) );
     938                 :            : 
     939                 :          0 :     if( !mpImpl->isMouseListenerRegistered() )
     940                 :          0 :         mpImpl->forEachView( &presentation::XSlideShowView::removeMouseListener );
     941                 :          0 : }
     942                 :            : 
     943                 :          0 : void EventMultiplexer::addDoubleClickHandler(
     944                 :            :     const MouseEventHandlerSharedPtr&   rHandler,
     945                 :            :     double                              nPriority )
     946                 :            : {
     947                 :            :     mpImpl->addMouseHandler(
     948                 :          0 :         mpImpl->maMouseDoubleClickHandlers,
     949                 :            :         rHandler,
     950                 :            :         nPriority,
     951                 :          0 :         mpImpl->isMouseListenerRegistered()
     952                 :            :         ? NULL
     953                 :          0 :         : &presentation::XSlideShowView::addMouseListener );
     954                 :          0 : }
     955                 :            : 
     956                 :          0 : void EventMultiplexer::removeDoubleClickHandler(
     957                 :            :     const MouseEventHandlerSharedPtr&    rHandler )
     958                 :            : {
     959                 :          0 :     mpImpl->maMouseDoubleClickHandlers.remove(
     960                 :            :         EventMultiplexerImpl::ImplMouseHandlers::container_type::value_type(
     961                 :            :             rHandler,
     962                 :          0 :             0.0) );
     963                 :            : 
     964                 :          0 :     if( !mpImpl->isMouseListenerRegistered() )
     965                 :          0 :         mpImpl->forEachView( &presentation::XSlideShowView::removeMouseListener );
     966                 :          0 : }
     967                 :            : 
     968                 :          0 : void EventMultiplexer::addMouseMoveHandler(
     969                 :            :     const MouseEventHandlerSharedPtr& rHandler,
     970                 :            :     double                            nPriority )
     971                 :            : {
     972                 :            :     mpImpl->addMouseHandler(
     973                 :          0 :         mpImpl->maMouseMoveHandlers,
     974                 :            :         rHandler,
     975                 :            :         nPriority,
     976                 :          0 :         mpImpl->maMouseMoveHandlers.isEmpty()
     977                 :            :         ? &presentation::XSlideShowView::addMouseMotionListener
     978                 :          0 :         : NULL );
     979                 :          0 : }
     980                 :            : 
     981                 :          0 : void EventMultiplexer::removeMouseMoveHandler(
     982                 :            :     const MouseEventHandlerSharedPtr&  rHandler )
     983                 :            : {
     984                 :          0 :     mpImpl->maMouseMoveHandlers.remove(
     985                 :            :         EventMultiplexerImpl::ImplMouseHandlers::container_type::value_type(
     986                 :            :             rHandler,
     987                 :          0 :             0.0) );
     988                 :            : 
     989                 :          0 :     if( mpImpl->maMouseMoveHandlers.isEmpty() )
     990                 :            :         mpImpl->forEachView(
     991                 :          0 :             &presentation::XSlideShowView::removeMouseMotionListener );
     992                 :          0 : }
     993                 :            : 
     994                 :          0 : void EventMultiplexer::addHyperlinkHandler( const HyperlinkHandlerSharedPtr& rHandler,
     995                 :            :                                             double                           nPriority )
     996                 :            : {
     997                 :          0 :     mpImpl->maHyperlinkHandlers.addSorted(
     998                 :            :         EventMultiplexerImpl::ImplHyperLinkHandlers::container_type::value_type(
     999                 :            :             rHandler,
    1000                 :          0 :             nPriority) );
    1001                 :          0 : }
    1002                 :            : 
    1003                 :          0 : void EventMultiplexer::removeHyperlinkHandler( const HyperlinkHandlerSharedPtr& rHandler )
    1004                 :            : {
    1005                 :          0 :     mpImpl->maHyperlinkHandlers.remove(
    1006                 :            :         EventMultiplexerImpl::ImplHyperLinkHandlers::container_type::value_type(
    1007                 :            :             rHandler,
    1008                 :          0 :             0.0) );
    1009                 :          0 : }
    1010                 :            : 
    1011                 :          0 : bool EventMultiplexer::notifyShapeListenerAdded(
    1012                 :            :     const uno::Reference<presentation::XShapeEventListener>& xListener,
    1013                 :            :     const uno::Reference<drawing::XShape>&                   xShape )
    1014                 :            : {
    1015                 :          0 :     return mpImpl->maShapeListenerHandlers.applyAll(
    1016                 :            :         boost::bind(&ShapeListenerEventHandler::listenerAdded,
    1017                 :            :                     _1,
    1018                 :            :                     boost::cref(xListener),
    1019                 :          0 :                     boost::cref(xShape)) );
    1020                 :            : }
    1021                 :            : 
    1022                 :          0 : bool EventMultiplexer::notifyShapeListenerRemoved(
    1023                 :            :     const uno::Reference<presentation::XShapeEventListener>& xListener,
    1024                 :            :     const uno::Reference<drawing::XShape>&                   xShape )
    1025                 :            : {
    1026                 :          0 :     return mpImpl->maShapeListenerHandlers.applyAll(
    1027                 :            :         boost::bind(&ShapeListenerEventHandler::listenerRemoved,
    1028                 :            :                     _1,
    1029                 :            :                     boost::cref(xListener),
    1030                 :          0 :                     boost::cref(xShape)) );
    1031                 :            : }
    1032                 :            : 
    1033                 :          0 : bool EventMultiplexer::notifyShapeCursorChange(
    1034                 :            :     const uno::Reference<drawing::XShape>&  xShape,
    1035                 :            :     sal_Int16                               nPointerShape )
    1036                 :            : {
    1037                 :          0 :     return mpImpl->maShapeCursorHandlers.applyAll(
    1038                 :            :         boost::bind(&ShapeCursorEventHandler::cursorChanged,
    1039                 :            :                     _1,
    1040                 :            :                     boost::cref(xShape),
    1041                 :          0 :                     nPointerShape));
    1042                 :            : }
    1043                 :            : 
    1044                 :          0 : bool EventMultiplexer::notifyUserPaintColor( RGBColor const& rUserColor )
    1045                 :            : {
    1046                 :          0 :     return mpImpl->maUserPaintEventHandlers.applyAll(
    1047                 :            :         boost::bind(&UserPaintEventHandler::colorChanged,
    1048                 :            :                     _1,
    1049                 :          0 :                     boost::cref(rUserColor)));
    1050                 :            : }
    1051                 :            : 
    1052                 :          0 : bool EventMultiplexer::notifyUserPaintStrokeWidth( double rUserStrokeWidth )
    1053                 :            : {
    1054                 :          0 :     return mpImpl->maUserPaintEventHandlers.applyAll(
    1055                 :            :         boost::bind(&UserPaintEventHandler::widthChanged,
    1056                 :            :             _1,
    1057                 :          0 :                     rUserStrokeWidth));
    1058                 :            : }
    1059                 :            : 
    1060                 :          0 : bool EventMultiplexer::notifyUserPaintDisabled()
    1061                 :            : {
    1062                 :          0 :     return mpImpl->maUserPaintEventHandlers.applyAll(
    1063                 :          0 :         boost::mem_fn(&UserPaintEventHandler::disable));
    1064                 :            : }
    1065                 :            : 
    1066                 :          0 : bool EventMultiplexer::notifySwitchPenMode(){
    1067                 :          0 :     return mpImpl->maUserPaintEventHandlers.applyAll(
    1068                 :          0 :         boost::mem_fn(&UserPaintEventHandler::switchPenMode));
    1069                 :            : }
    1070                 :            : 
    1071                 :          0 : bool EventMultiplexer::notifySwitchEraserMode(){
    1072                 :          0 :     return mpImpl->maUserPaintEventHandlers.applyAll(
    1073                 :          0 :         boost::mem_fn(&UserPaintEventHandler::switchEraserMode));
    1074                 :            : }
    1075                 :            : 
    1076                 :            : //adding erasing all ink features with UserPaintOverlay
    1077                 :          0 : bool EventMultiplexer::notifyEraseAllInk( bool const& rEraseAllInk )
    1078                 :            : {
    1079                 :          0 :     return mpImpl->maUserPaintEventHandlers.applyAll(
    1080                 :            :         boost::bind(&UserPaintEventHandler::eraseAllInkChanged,
    1081                 :            :                     _1,
    1082                 :          0 :                     boost::cref(rEraseAllInk)));
    1083                 :            : }
    1084                 :            : 
    1085                 :            : //adding erasing features with UserPaintOverlay
    1086                 :          0 : bool EventMultiplexer::notifyEraseInkWidth( sal_Int32 rEraseInkSize )
    1087                 :            : {
    1088                 :          0 :     return mpImpl->maUserPaintEventHandlers.applyAll(
    1089                 :            :         boost::bind(&UserPaintEventHandler::eraseInkWidthChanged,
    1090                 :            :                     _1,
    1091                 :          0 :                     boost::cref(rEraseInkSize)));
    1092                 :            : }
    1093                 :            : 
    1094                 :          0 : bool EventMultiplexer::notifyNextEffect()
    1095                 :            : {
    1096                 :          0 :     return mpImpl->notifyNextEffect();
    1097                 :            : }
    1098                 :            : 
    1099                 :          0 : bool EventMultiplexer::notifySlideStartEvent()
    1100                 :            : {
    1101                 :          0 :     return mpImpl->maSlideStartHandlers.applyAll(
    1102                 :          0 :         boost::mem_fn(&EventHandler::handleEvent) );
    1103                 :            : }
    1104                 :            : 
    1105                 :          0 : bool EventMultiplexer::notifySlideEndEvent()
    1106                 :            : {
    1107                 :          0 :     return mpImpl->maSlideEndHandlers.applyAll(
    1108                 :          0 :         boost::mem_fn(&EventHandler::handleEvent) );
    1109                 :            : }
    1110                 :            : 
    1111                 :          0 : bool EventMultiplexer::notifyAnimationStart(
    1112                 :            :     const AnimationNodeSharedPtr& rNode )
    1113                 :            : {
    1114                 :          0 :     return mpImpl->notifyAllAnimationHandlers( mpImpl->maAnimationStartHandlers,
    1115                 :          0 :                                                rNode );
    1116                 :            : }
    1117                 :            : 
    1118                 :          0 : bool EventMultiplexer::notifyAnimationEnd(
    1119                 :            :     const AnimationNodeSharedPtr& rNode )
    1120                 :            : {
    1121                 :          0 :     return mpImpl->notifyAllAnimationHandlers( mpImpl->maAnimationEndHandlers,
    1122                 :          0 :                                                rNode );
    1123                 :            : }
    1124                 :            : 
    1125                 :          0 : bool EventMultiplexer::notifySlideAnimationsEnd()
    1126                 :            : {
    1127                 :          0 :     return mpImpl->maSlideAnimationsEndHandlers.applyAll(
    1128                 :          0 :         boost::mem_fn(&EventHandler::handleEvent));
    1129                 :            : }
    1130                 :            : 
    1131                 :          0 : bool EventMultiplexer::notifyAudioStopped(
    1132                 :            :     const AnimationNodeSharedPtr& rNode )
    1133                 :            : {
    1134                 :            :     return mpImpl->notifyAllAnimationHandlers(
    1135                 :          0 :         mpImpl->maAudioStoppedHandlers,
    1136                 :          0 :         rNode );
    1137                 :            : }
    1138                 :            : 
    1139                 :          0 : bool EventMultiplexer::notifyCommandStopAudio(
    1140                 :            :     const AnimationNodeSharedPtr& rNode )
    1141                 :            : {
    1142                 :            :     return mpImpl->notifyAllAnimationHandlers(
    1143                 :          0 :         mpImpl->maCommandStopAudioHandlers,
    1144                 :          0 :         rNode );
    1145                 :            : }
    1146                 :            : 
    1147                 :          0 : bool EventMultiplexer::notifyPauseMode( bool bPauseShow )
    1148                 :            : {
    1149                 :          0 :     return mpImpl->maPauseHandlers.applyAll(
    1150                 :            :         boost::bind( &PauseEventHandler::handlePause,
    1151                 :          0 :                      _1, bPauseShow ));
    1152                 :            : }
    1153                 :            : 
    1154                 :          0 : bool EventMultiplexer::notifyViewAdded( const UnoViewSharedPtr& rView )
    1155                 :            : {
    1156                 :          0 :     ENSURE_OR_THROW( rView, "EventMultiplexer::notifyViewAdded(): Invalid view");
    1157                 :            : 
    1158                 :            :     // register event listener
    1159                 :            :     uno::Reference<presentation::XSlideShowView> const rUnoView(
    1160                 :          0 :         rView->getUnoView() );
    1161                 :            : 
    1162                 :          0 :     if( mpImpl->isMouseListenerRegistered() )
    1163                 :          0 :         rUnoView->addMouseListener(
    1164                 :          0 :             mpImpl->mxListener.get() );
    1165                 :            : 
    1166                 :          0 :     if( !mpImpl->maMouseMoveHandlers.isEmpty() )
    1167                 :          0 :         rUnoView->addMouseMotionListener(
    1168                 :          0 :             mpImpl->mxListener.get() );
    1169                 :            : 
    1170                 :          0 :     return mpImpl->maViewHandlers.applyAll(
    1171                 :            :         boost::bind( &ViewEventHandler::viewAdded,
    1172                 :            :                      _1,
    1173                 :          0 :                      boost::cref(rView) ));
    1174                 :            : }
    1175                 :            : 
    1176                 :          0 : bool EventMultiplexer::notifyViewRemoved( const UnoViewSharedPtr& rView )
    1177                 :            : {
    1178                 :          0 :     ENSURE_OR_THROW( rView,
    1179                 :            :                       "EventMultiplexer::removeView(): Invalid view" );
    1180                 :            : 
    1181                 :            :     // revoke event listeners
    1182                 :            :     uno::Reference<presentation::XSlideShowView> const rUnoView(
    1183                 :          0 :         rView->getUnoView() );
    1184                 :            : 
    1185                 :          0 :     if( mpImpl->isMouseListenerRegistered() )
    1186                 :          0 :         rUnoView->removeMouseListener(
    1187                 :          0 :             mpImpl->mxListener.get() );
    1188                 :            : 
    1189                 :          0 :     if( !mpImpl->maMouseMoveHandlers.isEmpty() )
    1190                 :          0 :         rUnoView->removeMouseMotionListener(
    1191                 :          0 :             mpImpl->mxListener.get() );
    1192                 :            : 
    1193                 :          0 :     return mpImpl->maViewHandlers.applyAll(
    1194                 :            :         boost::bind( &ViewEventHandler::viewRemoved,
    1195                 :            :                      _1,
    1196                 :          0 :                      boost::cref(rView) ));
    1197                 :            : }
    1198                 :            : 
    1199                 :          0 : bool EventMultiplexer::notifyViewChanged( const UnoViewSharedPtr& rView )
    1200                 :            : {
    1201                 :          0 :     return mpImpl->maViewHandlers.applyAll(
    1202                 :            :         boost::bind( &ViewEventHandler::viewChanged,
    1203                 :            :                      _1,
    1204                 :          0 :                      boost::cref(rView) ));
    1205                 :            : }
    1206                 :            : 
    1207                 :          0 : bool EventMultiplexer::notifyViewChanged( const uno::Reference<presentation::XSlideShowView>& xView )
    1208                 :            : {
    1209                 :          0 :     UnoViewSharedPtr pView( mpImpl->findUnoView(xView) );
    1210                 :            : 
    1211                 :          0 :     if( !pView )
    1212                 :          0 :         return false; // view not registered here
    1213                 :            : 
    1214                 :          0 :     return notifyViewChanged( pView );
    1215                 :            : }
    1216                 :            : 
    1217                 :          0 : bool EventMultiplexer::notifyViewsChanged()
    1218                 :            : {
    1219                 :          0 :     return mpImpl->maViewHandlers.applyAll(
    1220                 :          0 :         boost::mem_fn( &ViewEventHandler::viewsChanged ));
    1221                 :            : }
    1222                 :            : 
    1223                 :          0 : bool EventMultiplexer::notifyViewClobbered(
    1224                 :            :     const uno::Reference<presentation::XSlideShowView>& xView )
    1225                 :            : {
    1226                 :          0 :     UnoViewSharedPtr pView( mpImpl->findUnoView(xView) );
    1227                 :            : 
    1228                 :          0 :     if( !pView )
    1229                 :          0 :         return false; // view not registered here
    1230                 :            : 
    1231                 :          0 :     return mpImpl->maViewRepaintHandlers.applyAll(
    1232                 :            :         boost::bind( &ViewRepaintHandler::viewClobbered,
    1233                 :            :                      _1,
    1234                 :          0 :                      boost::cref(pView) ));
    1235                 :            : }
    1236                 :            : 
    1237                 :          0 : bool EventMultiplexer::notifyHyperlinkClicked(
    1238                 :            :     rtl::OUString const& hyperLink )
    1239                 :            : {
    1240                 :          0 :     return mpImpl->maHyperlinkHandlers.apply(
    1241                 :            :         boost::bind(&HyperlinkHandler::handleHyperlink,
    1242                 :            :                     _1,
    1243                 :          0 :                     boost::cref(hyperLink)) );
    1244                 :            : }
    1245                 :            : 
    1246                 :          0 : bool EventMultiplexer::notifySlideTransitionStarted()
    1247                 :            : {
    1248                 :          0 :     return true;
    1249                 :            : }
    1250                 :            : 
    1251                 :            : } // namespace internal
    1252                 :          0 : } // namespace presentation
    1253                 :            : 
    1254                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10