LCOV - code coverage report
Current view: top level - sd/source/ui/tools - EventMultiplexer.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 219 255 85.9 %
Date: 2014-04-11 Functions: 27 27 100.0 %
Legend: Lines: hit not hit

          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             : #include "EventMultiplexer.hxx"
      22             : 
      23             : #include "MutexOwner.hxx"
      24             : #include "ViewShellBase.hxx"
      25             : #include "drawdoc.hxx"
      26             : #include "DrawController.hxx"
      27             : #include "SlideSorterViewShell.hxx"
      28             : #include "framework/FrameworkHelper.hxx"
      29             : 
      30             : #include <com/sun/star/beans/XPropertySet.hpp>
      31             : #include <com/sun/star/frame/XFrame.hpp>
      32             : #include <com/sun/star/lang/DisposedException.hpp>
      33             : #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
      34             : #include <cppuhelper/weak.hxx>
      35             : #include <cppuhelper/compbase4.hxx>
      36             : #include <sfx2/viewfrm.hxx>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : using namespace ::com::sun::star::lang;
      40             : using namespace ::com::sun::star::uno;
      41             : using namespace ::com::sun::star::drawing::framework;
      42             : 
      43             : using ::sd::framework::FrameworkHelper;
      44             : 
      45             : class SdDrawDocument;
      46             : 
      47             : namespace {
      48             : static const sal_Int32 ResourceActivationEvent = 0;
      49             : static const sal_Int32 ResourceDeactivationEvent = 1;
      50             : static const sal_Int32 ConfigurationUpdateEvent = 2;
      51             : }
      52             : 
      53             : namespace sd { namespace tools {
      54             : 
      55             : typedef cppu::WeakComponentImplHelper4<
      56             :       ::com::sun::star::beans::XPropertyChangeListener,
      57             :       ::com::sun::star::frame::XFrameActionListener,
      58             :       ::com::sun::star::view::XSelectionChangeListener,
      59             :       ::com::sun::star::drawing::framework::XConfigurationChangeListener
      60             :     > EventMultiplexerImplementationInterfaceBase;
      61             : 
      62             : class EventMultiplexer::Implementation
      63             :     : protected MutexOwner,
      64             :       public EventMultiplexerImplementationInterfaceBase,
      65             :       public SfxListener
      66             : {
      67             : public:
      68             :     Implementation (ViewShellBase& rBase);
      69             :     virtual ~Implementation (void);
      70             : 
      71             :     void AddEventListener (
      72             :         Link& rCallback,
      73             :         EventMultiplexerEvent::EventId aEventTypes);
      74             : 
      75             :     void RemoveEventListener (
      76             :         Link& rCallback,
      77             :         EventMultiplexerEvent::EventId aEventTypes);
      78             : 
      79             :     void CallListeners (EventMultiplexerEvent& rEvent);
      80             : 
      81          82 :     ViewShellBase& GetViewShellBase() const { return mrBase; }
      82             : 
      83             :     //===== lang::XEventListener ==============================================
      84             :     virtual void SAL_CALL
      85             :         disposing (const ::com::sun::star::lang::EventObject& rEventObject)
      86             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      87             : 
      88             : 
      89             :     //===== beans::XPropertySetListener =======================================
      90             :     virtual void SAL_CALL
      91             :         propertyChange (
      92             :             const com::sun::star::beans::PropertyChangeEvent& rEvent)
      93             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      94             : 
      95             :     //===== view::XSelectionChangeListener ====================================
      96             :     virtual void SAL_CALL
      97             :         selectionChanged (
      98             :             const com::sun::star::lang::EventObject& rEvent)
      99             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     100             : 
     101             :     //===== frame::XFrameActionListener  ======================================
     102             :     /** For certain actions the listener connects to a new controller of the
     103             :         frame it is listening to.  This usually happens when the view shell
     104             :         in the center pane is replaced by another view shell.
     105             :     */
     106             :     virtual void SAL_CALL
     107             :         frameAction (const ::com::sun::star::frame::FrameActionEvent& rEvent)
     108             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     109             : 
     110             :     //===== drawing::framework::XConfigurationChangeListener ==================
     111             :     virtual void SAL_CALL
     112             :         notifyConfigurationChange (
     113             :             const ::com::sun::star::drawing::framework::ConfigurationChangeEvent& rEvent)
     114             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     115             : 
     116             : 
     117             :     virtual void SAL_CALL disposing (void) SAL_OVERRIDE;
     118             : 
     119             : protected:
     120             :     virtual void Notify (
     121             :         SfxBroadcaster& rBroadcaster,
     122             :         const SfxHint& rHint) SAL_OVERRIDE;
     123             : 
     124             : private:
     125             :     ViewShellBase& mrBase;
     126             :     typedef ::std::pair<Link,EventMultiplexerEvent::EventId> ListenerDescriptor;
     127             :     typedef ::std::vector<ListenerDescriptor> ListenerList;
     128             :     ListenerList maListeners;
     129             : 
     130             :     /// Remember whether we are listening to the UNO controller.
     131             :     bool mbListeningToController;
     132             :     /// Remember whether we are listening to the frame.
     133             :     bool mbListeningToFrame;
     134             : 
     135             :     ::com::sun::star::uno::WeakReference<
     136             :         ::com::sun::star::frame::XController> mxControllerWeak;
     137             :     ::com::sun::star::uno::WeakReference<
     138             :         ::com::sun::star::frame::XFrame> mxFrameWeak;
     139             :     ::com::sun::star::uno::WeakReference<
     140             :         ::com::sun::star::view::XSelectionSupplier> mxSlideSorterSelectionWeak;
     141             :     SdDrawDocument* mpDocument;
     142             :     ::com::sun::star::uno::WeakReference<
     143             :         ::com::sun::star::drawing::framework::XConfigurationController>
     144             :         mxConfigurationControllerWeak;
     145             : 
     146             :     void ReleaseListeners (void);
     147             : 
     148             :     void ConnectToController (void);
     149             :     void DisconnectFromController (void);
     150             : 
     151             :     void CallListeners (
     152             :         EventMultiplexerEvent::EventId eId,
     153             :         void* pUserData = NULL);
     154             : 
     155             :     /** This method throws a DisposedException when the object has already been
     156             :         disposed.
     157             :     */
     158             :     void ThrowIfDisposed (void)
     159             :         throw (::com::sun::star::lang::DisposedException);
     160             : 
     161             :     DECL_LINK(SlideSorterSelectionChangeListener, void*);
     162             : };
     163             : 
     164             : 
     165             : const char aCurrentPagePropertyName[] = "CurrentPage";
     166             : const char aEditModePropertyName[] = "IsMasterPageMode";
     167             : 
     168             : 
     169             : //===== EventMultiplexer ======================================================
     170             : 
     171          73 : EventMultiplexer::EventMultiplexer (ViewShellBase& rBase)
     172          73 :     : mpImpl (new EventMultiplexer::Implementation(rBase))
     173             : {
     174          73 :     mpImpl->acquire();
     175          73 : }
     176             : 
     177             : 
     178             : 
     179             : 
     180         146 : EventMultiplexer::~EventMultiplexer (void)
     181             : {
     182             :     try
     183             :     {
     184          73 :         mpImpl->dispose();
     185             :         // Now we call release twice.  One decreases the use count of the
     186             :         // implementation object (if all goes well to zero and thus deletes
     187             :         // it.)  The other releases the auto_ptr and prevents the
     188             :         // implementation object from being deleted a second time.
     189          73 :         mpImpl->release();
     190          73 :         mpImpl.release();
     191             :     }
     192           0 :     catch (const RuntimeException&)
     193             :     {
     194             :     }
     195           0 :     catch (const Exception&)
     196             :     {
     197             :     }
     198          73 : }
     199             : 
     200             : 
     201             : 
     202             : 
     203         358 : void EventMultiplexer::AddEventListener (
     204             :     Link& rCallback,
     205             :     EventMultiplexerEvent::EventId aEventTypes)
     206             : {
     207         358 :     mpImpl->AddEventListener (rCallback, aEventTypes);
     208         358 : }
     209             : 
     210             : 
     211             : 
     212             : 
     213         358 : void EventMultiplexer::RemoveEventListener (
     214             :     Link& rCallback,
     215             :     EventMultiplexerEvent::EventId aEventTypes)
     216             : {
     217         358 :     mpImpl->RemoveEventListener (rCallback, aEventTypes);
     218         358 : }
     219             : 
     220             : 
     221             : 
     222             : 
     223          82 : void EventMultiplexer::MultiplexEvent(
     224             :     EventMultiplexerEvent::EventId eEventId,
     225             :     void* pUserData )
     226             : {
     227          82 :     EventMultiplexerEvent aEvent (mpImpl->GetViewShellBase(), eEventId, pUserData);
     228          82 :     mpImpl->CallListeners(aEvent);
     229          82 : }
     230             : 
     231             : 
     232             : 
     233             : 
     234             : //===== EventMultiplexer::Implementation ======================================
     235             : 
     236          73 : EventMultiplexer::Implementation::Implementation (ViewShellBase& rBase)
     237             :     : MutexOwner(),
     238             :       EventMultiplexerImplementationInterfaceBase(maMutex),
     239             :       SfxListener(),
     240             :       mrBase (rBase),
     241             :       mbListeningToController (false),
     242             :       mbListeningToFrame (false),
     243             :       mxControllerWeak(NULL),
     244             :       mxFrameWeak(NULL),
     245             :       mxSlideSorterSelectionWeak(NULL),
     246             :       mpDocument(NULL),
     247          73 :       mxConfigurationControllerWeak()
     248             : {
     249             :     // Connect to the frame to listen for controllers being exchanged.
     250             :     // Listen to changes of certain properties.
     251             :     Reference<frame::XFrame> xFrame (
     252          73 :         mrBase.GetFrame()->GetTopFrame().GetFrameInterface(),
     253          73 :         uno::UNO_QUERY);
     254          73 :     mxFrameWeak = xFrame;
     255          73 :     if (xFrame.is())
     256             :     {
     257          73 :         xFrame->addFrameActionListener (
     258             :             Reference<frame::XFrameActionListener>(
     259          73 :                static_cast<XWeak*>(this), UNO_QUERY));
     260          73 :         mbListeningToFrame = true;
     261             :     }
     262             : 
     263             :     // Connect to the current controller.
     264          73 :     ConnectToController ();
     265             : 
     266             :     // Listen for document changes.
     267          73 :     mpDocument = mrBase.GetDocument();
     268          73 :     if (mpDocument != NULL)
     269          73 :         StartListening (*mpDocument);
     270             : 
     271             :     // Listen for configuration changes.
     272             :     Reference<XControllerManager> xControllerManager (
     273         146 :         Reference<XWeak>(&mrBase.GetDrawController()), UNO_QUERY);
     274          73 :     if (xControllerManager.is())
     275             :     {
     276             :         Reference<XConfigurationController> xConfigurationController (
     277          73 :             xControllerManager->getConfigurationController());
     278          73 :         mxConfigurationControllerWeak = xConfigurationController;
     279          73 :         if (xConfigurationController.is())
     280             :         {
     281          73 :             Reference<XComponent> xComponent (xConfigurationController, UNO_QUERY);
     282          73 :             if (xComponent.is())
     283          73 :                 xComponent->addEventListener(static_cast<beans::XPropertyChangeListener*>(this));
     284             : 
     285          73 :             xConfigurationController->addConfigurationChangeListener(
     286             :                 this,
     287             :                 FrameworkHelper::msResourceActivationEvent,
     288          73 :                 makeAny(ResourceActivationEvent));
     289          73 :             xConfigurationController->addConfigurationChangeListener(
     290             :                 this,
     291             :                 FrameworkHelper::msResourceDeactivationEvent,
     292          73 :                 makeAny(ResourceDeactivationEvent));
     293          73 :             xConfigurationController->addConfigurationChangeListener(
     294             :                 this,
     295             :                 FrameworkHelper::msConfigurationUpdateEndEvent,
     296          73 :                 makeAny(ConfigurationUpdateEvent));
     297          73 :         }
     298          73 :     }
     299          73 : }
     300             : 
     301             : 
     302             : 
     303             : 
     304         146 : EventMultiplexer::Implementation::~Implementation (void)
     305             : {
     306             :     DBG_ASSERT( !mbListeningToFrame,
     307             :         "sd::EventMultiplexer::Implementation::~Implementation(), disposing was not called!" );
     308         146 : }
     309             : 
     310             : 
     311             : 
     312             : 
     313          73 : void EventMultiplexer::Implementation::ReleaseListeners (void)
     314             : {
     315          73 :     if (mbListeningToFrame)
     316             :     {
     317          73 :         mbListeningToFrame = false;
     318             : 
     319             :         // Stop listening for changes of certain properties.
     320          73 :         Reference<frame::XFrame> xFrame (mxFrameWeak);
     321          73 :         if (xFrame.is())
     322             :         {
     323          73 :             xFrame->removeFrameActionListener (
     324             :                 Reference<frame::XFrameActionListener>(
     325          73 :                     static_cast<XWeak*>(this), UNO_QUERY));
     326          73 :         }
     327             :     }
     328             : 
     329          73 :     DisconnectFromController ();
     330             : 
     331          73 :     if (mpDocument != NULL)
     332             :     {
     333          73 :         EndListening (*mpDocument);
     334          73 :         mpDocument = NULL;
     335             :     }
     336             : 
     337             :     // Stop listening for configuration changes.
     338          73 :     Reference<XConfigurationController> xConfigurationController (mxConfigurationControllerWeak);
     339          73 :     if (xConfigurationController.is())
     340             :     {
     341           0 :         Reference<XComponent> xComponent (xConfigurationController, UNO_QUERY);
     342           0 :         if (xComponent.is())
     343           0 :             xComponent->removeEventListener(static_cast<beans::XPropertyChangeListener*>(this));
     344             : 
     345           0 :         xConfigurationController->removeConfigurationChangeListener(this);
     346          73 :     }
     347          73 : }
     348             : 
     349             : 
     350             : 
     351             : 
     352         358 : void EventMultiplexer::Implementation::AddEventListener (
     353             :     Link& rCallback,
     354             :     EventMultiplexerEvent::EventId aEventTypes)
     355             : {
     356         358 :     ListenerList::iterator iListener (maListeners.begin());
     357         358 :     ListenerList::const_iterator iEnd (maListeners.end());
     358        1083 :     for (;iListener!=iEnd; ++iListener)
     359         725 :         if (iListener->first == rCallback)
     360           0 :             break;
     361         358 :     if (iListener != maListeners.end())
     362             :     {
     363             :         // Listener exists.  Update its event type set.
     364           0 :         iListener->second |= aEventTypes;
     365             :     }
     366             :     else
     367             :     {
     368         358 :         maListeners.push_back (ListenerDescriptor(rCallback,aEventTypes));
     369             :     }
     370         358 : }
     371             : 
     372             : 
     373             : 
     374             : 
     375         358 : void EventMultiplexer::Implementation::RemoveEventListener (
     376             :     Link& rCallback,
     377             :     EventMultiplexerEvent::EventId aEventTypes)
     378             : {
     379         358 :     ListenerList::iterator iListener (maListeners.begin());
     380         358 :     ListenerList::const_iterator iEnd (maListeners.end());
     381         855 :     for (;iListener!=iEnd; ++iListener)
     382         855 :         if (iListener->first == rCallback)
     383         358 :             break;
     384         358 :     if (iListener != maListeners.end())
     385             :     {
     386             :         // Update the event type set.
     387         358 :         iListener->second &= ~aEventTypes;
     388             :         // When no events remain in the set then remove the listener.
     389         358 :         if (iListener->second == EID_EMPTY_SET)
     390         358 :             maListeners.erase (iListener);
     391             :     }
     392         358 : }
     393             : 
     394             : 
     395             : 
     396             : 
     397         146 : void EventMultiplexer::Implementation::ConnectToController (void)
     398             : {
     399             :     // Just in case that we missed some event we now disconnect from the old
     400             :     // controller.
     401         146 :     DisconnectFromController ();
     402             : 
     403             :     // Register at the controller of the main view shell.
     404             : 
     405             :     // We have to store a (weak) reference to the controller so that we can
     406             :     // unregister without having to ask the mrBase member (which at that
     407             :     // time may be destroyed.)
     408         146 :     Reference<frame::XController> xController = mrBase.GetController();
     409         146 :     mxControllerWeak = mrBase.GetController();
     410             : 
     411             :     try
     412             :     {
     413             :         // Listen for disposing events.
     414         146 :         Reference<lang::XComponent> xComponent (xController, UNO_QUERY);
     415         146 :         if (xComponent.is())
     416             :         {
     417         146 :             xComponent->addEventListener (
     418             :                 Reference<lang::XEventListener>(
     419         146 :                     static_cast<XWeak*>(this), UNO_QUERY));
     420         146 :             mbListeningToController = true;
     421             :         }
     422             : 
     423             :         // Listen to changes of certain properties.
     424         292 :         Reference<beans::XPropertySet> xSet (xController, UNO_QUERY);
     425         146 :         if (xSet.is())
     426             :         {
     427             :                 try
     428             :                 {
     429         146 :                     xSet->addPropertyChangeListener(OUString(aCurrentPagePropertyName), this);
     430             :                 }
     431           0 :                 catch (const beans::UnknownPropertyException&)
     432             :                 {
     433             :                     OSL_TRACE("EventMultiplexer::ConnectToController: CurrentPage unknown");
     434             :                 }
     435             : 
     436             :                 try
     437             :                 {
     438         146 :                     xSet->addPropertyChangeListener(OUString(aEditModePropertyName), this);
     439             :                 }
     440           0 :                 catch (const beans::UnknownPropertyException&)
     441             :                 {
     442             :                     OSL_TRACE("EventMultiplexer::ConnectToController: IsMasterPageMode unknown");
     443             :                 }
     444             :         }
     445             : 
     446             :         // Listen for selection change events.
     447         292 :         Reference<view::XSelectionSupplier> xSelection (xController, UNO_QUERY);
     448         146 :         if (xSelection.is())
     449             :         {
     450         146 :             xSelection->addSelectionChangeListener(this);
     451         146 :         }
     452             :     }
     453           0 :     catch (const lang::DisposedException&)
     454             :     {
     455           0 :         mbListeningToController = false;
     456         146 :     }
     457         146 : }
     458             : 
     459             : 
     460             : 
     461             : 
     462         292 : void EventMultiplexer::Implementation::DisconnectFromController (void)
     463             : {
     464         292 :     if (mbListeningToController)
     465             :     {
     466         146 :         mbListeningToController = false;
     467             : 
     468         146 :         Reference<frame::XController> xController = mxControllerWeak;
     469             : 
     470         292 :         Reference<beans::XPropertySet> xSet (xController, UNO_QUERY);
     471             :         // Remove the property listener.
     472         146 :         if (xSet.is())
     473             :         {
     474             :             try
     475             :             {
     476         146 :                 xSet->removePropertyChangeListener(OUString(aCurrentPagePropertyName), this);
     477             :             }
     478           0 :             catch (const beans::UnknownPropertyException&)
     479             :             {
     480             :                 OSL_TRACE ("DisconnectFromController: CurrentPage unknown");
     481             :             }
     482             : 
     483             :             try
     484             :             {
     485         146 :                 xSet->removePropertyChangeListener(OUString(aEditModePropertyName), this);
     486             :             }
     487           0 :             catch (const beans::UnknownPropertyException&)
     488             :             {
     489             :                 OSL_TRACE ("DisconnectFromController: IsMasterPageMode unknown");
     490             :             }
     491             :         }
     492             : 
     493             :         // Remove selection change listener.
     494         292 :         Reference<view::XSelectionSupplier> xSelection (xController, UNO_QUERY);
     495         146 :         if (xSelection.is())
     496             :         {
     497         146 :             xSelection->removeSelectionChangeListener(this);
     498             :         }
     499             : 
     500             :         // Remove listener for disposing events.
     501         292 :         Reference<lang::XComponent> xComponent (xController, UNO_QUERY);
     502         146 :         if (xComponent.is())
     503             :         {
     504         146 :             xComponent->removeEventListener (
     505         146 :                 Reference<lang::XEventListener>(static_cast<XWeak*>(this), UNO_QUERY));
     506         146 :         }
     507             :     }
     508         292 : }
     509             : 
     510             : 
     511             : 
     512             : 
     513             : //=====  lang::XEventListener  ================================================
     514             : 
     515         146 : void SAL_CALL EventMultiplexer::Implementation::disposing (
     516             :     const lang::EventObject& rEventObject)
     517             :     throw (RuntimeException, std::exception)
     518             : {
     519         146 :     if (mbListeningToController)
     520             :     {
     521           0 :         Reference<frame::XController> xController (mxControllerWeak);
     522           0 :         if (rEventObject.Source == xController)
     523             :         {
     524           0 :             mbListeningToController = false;
     525           0 :         }
     526             :     }
     527             : 
     528             :     Reference<XConfigurationController> xConfigurationController (
     529         146 :         mxConfigurationControllerWeak);
     530         292 :     if (xConfigurationController.is()
     531         146 :         && rEventObject.Source == xConfigurationController)
     532             :     {
     533          73 :         mxConfigurationControllerWeak.clear();
     534         146 :     }
     535         146 : }
     536             : 
     537             : 
     538             : 
     539             : 
     540             : //=====  beans::XPropertySetListener  =========================================
     541             : 
     542          77 : void SAL_CALL EventMultiplexer::Implementation::propertyChange (
     543             :     const beans::PropertyChangeEvent& rEvent)
     544             :     throw (RuntimeException, std::exception)
     545             : {
     546          77 :     ThrowIfDisposed();
     547             : 
     548          77 :     if ( rEvent.PropertyName == aCurrentPagePropertyName )
     549             :     {
     550          77 :         CallListeners(EventMultiplexerEvent::EID_CURRENT_PAGE);
     551             :     }
     552           0 :     else if ( rEvent.PropertyName == aEditModePropertyName )
     553             :     {
     554           0 :         bool bIsMasterPageMode (false);
     555           0 :         rEvent.NewValue >>= bIsMasterPageMode;
     556           0 :         if (bIsMasterPageMode)
     557           0 :             CallListeners(EventMultiplexerEvent::EID_EDIT_MODE_MASTER);
     558             :         else
     559           0 :             CallListeners(EventMultiplexerEvent::EID_EDIT_MODE_NORMAL);
     560             :     }
     561          77 : }
     562             : 
     563             : 
     564             : 
     565             : 
     566             : //===== frame::XFrameActionListener  ==========================================
     567             : 
     568         262 : void SAL_CALL EventMultiplexer::Implementation::frameAction (
     569             :     const frame::FrameActionEvent& rEvent)
     570             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     571             : {
     572         262 :     Reference<frame::XFrame> xFrame (mxFrameWeak);
     573         262 :     if (rEvent.Frame == xFrame)
     574         262 :         switch (rEvent.Action)
     575             :         {
     576             :             case frame::FrameAction_COMPONENT_DETACHING:
     577          73 :                 DisconnectFromController();
     578          73 :                 CallListeners (EventMultiplexerEvent::EID_CONTROLLER_DETACHED);
     579          73 :                 break;
     580             : 
     581             :             case frame::FrameAction_COMPONENT_REATTACHED:
     582           0 :                 CallListeners (EventMultiplexerEvent::EID_CONTROLLER_DETACHED);
     583           0 :                 DisconnectFromController();
     584           0 :                 ConnectToController();
     585           0 :                 CallListeners (EventMultiplexerEvent::EID_CONTROLLER_ATTACHED);
     586           0 :                 break;
     587             : 
     588             :             case frame::FrameAction_COMPONENT_ATTACHED:
     589          73 :                 ConnectToController();
     590          73 :                 CallListeners (EventMultiplexerEvent::EID_CONTROLLER_ATTACHED);
     591          73 :                 break;
     592             : 
     593             :             default:
     594         116 :                 break;
     595         262 :         }
     596         262 : }
     597             : 
     598             : 
     599             : 
     600             : 
     601             : //===== view::XSelectionChangeListener ========================================
     602             : 
     603         143 : void SAL_CALL EventMultiplexer::Implementation::selectionChanged (
     604             :     const lang::EventObject& )
     605             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     606             : {
     607         143 :     CallListeners (EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION);
     608         143 : }
     609             : 
     610             : 
     611             : 
     612             : 
     613             : //===== drawing::framework::XConfigurationChangeListener ==================
     614             : 
     615         976 : void SAL_CALL EventMultiplexer::Implementation::notifyConfigurationChange (
     616             :     const ConfigurationChangeEvent& rEvent)
     617             :     throw (RuntimeException, std::exception)
     618             : {
     619         976 :     sal_Int32 nEventType = 0;
     620         976 :     rEvent.UserData >>= nEventType;
     621         976 :     switch (nEventType)
     622             :     {
     623             :         case ResourceActivationEvent:
     624         362 :             if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix))
     625             :             {
     626         132 :                 CallListeners (EventMultiplexerEvent::EID_VIEW_ADDED);
     627             : 
     628         264 :                 if (rEvent.ResourceId->isBoundToURL(
     629         132 :                     FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
     630             :                 {
     631          69 :                     CallListeners (EventMultiplexerEvent::EID_MAIN_VIEW_ADDED);
     632             :                 }
     633             : 
     634             :                 // Add selection change listener at slide sorter.
     635         132 :                 if (rEvent.ResourceId->getResourceURL().equals(FrameworkHelper::msSlideSorterURL))
     636             :                 {
     637             :                     slidesorter::SlideSorterViewShell* pViewShell
     638             :                         = dynamic_cast<slidesorter::SlideSorterViewShell*>(
     639             :                             FrameworkHelper::GetViewShell(
     640          63 :                                 Reference<XView>(rEvent.ResourceObject,UNO_QUERY)).get());
     641          63 :                     if (pViewShell != NULL)
     642             :                         pViewShell->AddSelectionChangeListener (
     643             :                             LINK(this,
     644             :                                 EventMultiplexer::Implementation,
     645          63 :                                 SlideSorterSelectionChangeListener));
     646             :                 }
     647             :             }
     648         362 :             break;
     649             : 
     650             :         case ResourceDeactivationEvent:
     651         362 :             if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix))
     652             :             {
     653         132 :                 CallListeners (EventMultiplexerEvent::EID_VIEW_REMOVED);
     654             : 
     655         264 :                 if (rEvent.ResourceId->isBoundToURL(
     656         132 :                     FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
     657             :                 {
     658          69 :                     CallListeners (EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED);
     659             :                 }
     660             : 
     661             :                 // Remove selection change listener from slide sorter.  Add
     662             :                 // selection change listener at slide sorter.
     663         132 :                 if (rEvent.ResourceId->getResourceURL().equals(FrameworkHelper::msSlideSorterURL))
     664             :                 {
     665             :                     slidesorter::SlideSorterViewShell* pViewShell
     666             :                         = dynamic_cast<slidesorter::SlideSorterViewShell*>(
     667             :                             FrameworkHelper::GetViewShell(
     668          63 :                                 Reference<XView>(rEvent.ResourceObject, UNO_QUERY)).get());
     669          63 :                     if (pViewShell != NULL)
     670             :                         pViewShell->RemoveSelectionChangeListener (
     671             :                             LINK(this,
     672             :                                 EventMultiplexer::Implementation,
     673          63 :                                 SlideSorterSelectionChangeListener));
     674             :                 }
     675             :             }
     676         362 :             break;
     677             : 
     678             :         case ConfigurationUpdateEvent:
     679         252 :             CallListeners (EventMultiplexerEvent::EID_CONFIGURATION_UPDATED);
     680         252 :             break;
     681             :     }
     682             : 
     683         976 : }
     684             : 
     685             : 
     686             : 
     687             : 
     688          73 : void SAL_CALL EventMultiplexer::Implementation::disposing (void)
     689             : {
     690          73 :     CallListeners (EventMultiplexerEvent::EID_DISPOSING);
     691          73 :     ReleaseListeners();
     692          73 : }
     693             : 
     694             : 
     695             : 
     696             : 
     697          77 : void EventMultiplexer::Implementation::ThrowIfDisposed (void)
     698             :     throw (::com::sun::star::lang::DisposedException)
     699             : {
     700          77 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
     701             :     {
     702             :         throw lang::DisposedException (
     703             :             "SlideSorterController object has already been disposed",
     704           0 :             static_cast<uno::XWeak*>(this));
     705             :     }
     706          77 : }
     707             : 
     708             : 
     709             : 
     710             : 
     711        3039 : void EventMultiplexer::Implementation::Notify (
     712             :     SfxBroadcaster&,
     713             :     const SfxHint& rHint)
     714             : {
     715        3039 :     if (rHint.ISA(SdrHint))
     716             :     {
     717        3039 :         SdrHint& rSdrHint (*PTR_CAST(SdrHint,&rHint));
     718        3039 :         switch (rSdrHint.GetKind())
     719             :         {
     720             :             case HINT_MODELCLEARED:
     721             :             case HINT_PAGEORDERCHG:
     722         610 :                 CallListeners (EventMultiplexerEvent::EID_PAGE_ORDER);
     723         610 :                 break;
     724             : 
     725             :             case HINT_SWITCHTOPAGE:
     726           0 :                 CallListeners (EventMultiplexerEvent::EID_CURRENT_PAGE);
     727           0 :                 break;
     728             : 
     729             :             case HINT_OBJCHG:
     730             :                 CallListeners(EventMultiplexerEvent::EID_SHAPE_CHANGED,
     731        1599 :                     const_cast<void*>(static_cast<const void*>(rSdrHint.GetPage())));
     732        1599 :                 break;
     733             : 
     734             :             case HINT_OBJINSERTED:
     735             :                 CallListeners(EventMultiplexerEvent::EID_SHAPE_INSERTED,
     736         705 :                     const_cast<void*>(static_cast<const void*>(rSdrHint.GetPage())));
     737         705 :                 break;
     738             : 
     739             :             case HINT_OBJREMOVED:
     740             :                 CallListeners(EventMultiplexerEvent::EID_SHAPE_REMOVED,
     741         123 :                     const_cast<void*>(static_cast<const void*>(rSdrHint.GetPage())));
     742         123 :                 break;
     743             :             default:
     744           2 :                 break;
     745             :         }
     746             :     }
     747           0 :     else if (rHint.ISA(SfxSimpleHint))
     748             :     {
     749           0 :         SfxSimpleHint& rSimpleHint (*PTR_CAST(SfxSimpleHint, &rHint));
     750           0 :         if (rSimpleHint.GetId() == SFX_HINT_DYING)
     751           0 :             mpDocument = NULL;
     752             :     }
     753        3039 : }
     754             : 
     755             : 
     756             : 
     757             : 
     758        4134 : void EventMultiplexer::Implementation::CallListeners (
     759             :     EventMultiplexerEvent::EventId eId,
     760             :     void* pUserData)
     761             : {
     762        4134 :     EventMultiplexerEvent aEvent (mrBase, eId, pUserData);
     763        4134 :     CallListeners(aEvent);
     764        4134 : }
     765             : 
     766             : 
     767             : 
     768             : 
     769        4216 : void EventMultiplexer::Implementation::CallListeners (EventMultiplexerEvent& rEvent)
     770             : {
     771        4216 :     ListenerList aCopyListeners( maListeners );
     772        4216 :     ListenerList::iterator iListener (aCopyListeners.begin());
     773        4216 :     ListenerList::const_iterator iListenerEnd (aCopyListeners.end());
     774       19183 :     for (; iListener!=iListenerEnd; ++iListener)
     775             :     {
     776       14967 :         if ((iListener->second && rEvent.meEventId))
     777       14967 :             iListener->first.Call(&rEvent);
     778        4216 :     }
     779        4216 : }
     780             : 
     781             : 
     782             : 
     783             : 
     784           8 : IMPL_LINK_NOARG(EventMultiplexer::Implementation, SlideSorterSelectionChangeListener)
     785             : {
     786           4 :     CallListeners (EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION);
     787           4 :     return 0;
     788             : }
     789             : 
     790             : 
     791             : 
     792             : 
     793             : //===== EventMultiplexerEvent =================================================
     794             : 
     795        4216 : EventMultiplexerEvent::EventMultiplexerEvent (
     796             :     const ViewShellBase& rBase,
     797             :     EventId eEventId,
     798             :     const void* pUserData)
     799             :     : mrBase(rBase),
     800             :       meEventId(eEventId),
     801        4216 :       mpUserData(pUserData)
     802             : 
     803             : {
     804        4216 : }
     805             : 
     806             : } } // end of namespace ::sd::tools
     807             : 
     808             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10