LCOV - code coverage report
Current view: top level - svx/source/form - formdispatchinterceptor.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 48 71 67.6 %
Date: 2014-11-03 Functions: 9 12 75.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             : #include "formdispatchinterceptor.hxx"
      21             : 
      22             : namespace svxform
      23             : {
      24             :     using ::com::sun::star::uno::Reference;
      25             :     using ::com::sun::star::uno::XInterface;
      26             :     using ::com::sun::star::uno::UNO_QUERY;
      27             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      28             :     using ::com::sun::star::uno::UNO_SET_THROW;
      29             :     using ::com::sun::star::uno::Exception;
      30             :     using ::com::sun::star::uno::RuntimeException;
      31             :     using ::com::sun::star::uno::Any;
      32             :     using ::com::sun::star::uno::makeAny;
      33             :     using ::com::sun::star::uno::Sequence;
      34             :     using ::com::sun::star::uno::Type;
      35             :     using ::com::sun::star::frame::XDispatchProviderInterception;
      36             :     using ::com::sun::star::frame::XDispatchProviderInterceptor;
      37             :     using ::com::sun::star::lang::XComponent;
      38             :     using ::com::sun::star::util::URL;
      39             :     using ::com::sun::star::frame::XDispatch;
      40             :     using ::com::sun::star::frame::DispatchDescriptor;
      41             :     using ::com::sun::star::frame::XDispatchProvider;
      42             :     using ::com::sun::star::lang::EventObject;
      43             : 
      44          60 :     DispatchInterceptionMultiplexer::DispatchInterceptionMultiplexer(
      45             :                 const Reference< XDispatchProviderInterception >& _rxToIntercept, DispatchInterceptor* _pMaster )
      46          60 :         :DispatchInterceptionMultiplexer_BASE(_pMaster && _pMaster->getInterceptorMutex() ? *_pMaster->getInterceptorMutex() : m_aFallback)
      47             :         ,m_aFallback()
      48          60 :         ,m_pMutex( _pMaster && _pMaster->getInterceptorMutex() ? _pMaster->getInterceptorMutex() : &m_aFallback )
      49             :         ,m_xIntercepted(_rxToIntercept)
      50             :         ,m_bListening(false)
      51         180 :         ,m_pMaster(_pMaster)
      52             :     {
      53             : 
      54          60 :         ::osl::MutexGuard aGuard( *m_pMutex );
      55          60 :         ::comphelper::increment(m_refCount);
      56          60 :         if (_rxToIntercept.is())
      57             :         {
      58          60 :             _rxToIntercept->registerDispatchProviderInterceptor((XDispatchProviderInterceptor*)this);
      59             :             // this should make us the top-level dispatch-provider for the component, via a call to our
      60             :             // setDispatchProvider we should have got an fallback for requests we (i.e. our master) cannot fulfill
      61          60 :             Reference< XComponent> xInterceptedComponent(_rxToIntercept, UNO_QUERY);
      62          60 :             if (xInterceptedComponent.is())
      63             :             {
      64          60 :                 xInterceptedComponent->addEventListener(this);
      65          60 :                 m_bListening = true;
      66          60 :             }
      67             :         }
      68          60 :         ::comphelper::decrement(m_refCount);
      69          60 :     }
      70             : 
      71             : 
      72         180 :     DispatchInterceptionMultiplexer::~DispatchInterceptionMultiplexer()
      73             :     {
      74          60 :         if (!rBHelper.bDisposed)
      75           0 :             dispose();
      76             : 
      77         120 :     }
      78             : 
      79             : 
      80           0 :     Reference< XDispatch > SAL_CALL DispatchInterceptionMultiplexer::queryDispatch( const URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags ) throw(RuntimeException, std::exception)
      81             :     {
      82           0 :         ::osl::MutexGuard aGuard( *m_pMutex );
      83           0 :         Reference< XDispatch> xResult;
      84             :         // ask our 'real' interceptor
      85           0 :         if (m_pMaster)
      86           0 :             xResult = m_pMaster->interceptedQueryDispatch( aURL, aTargetFrameName, nSearchFlags);
      87             : 
      88             :         // ask our slave provider
      89           0 :         if (!xResult.is() && m_xSlaveDispatcher.is())
      90           0 :             xResult = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
      91             : 
      92           0 :         return xResult;
      93             :     }
      94             : 
      95             : 
      96             :     Sequence< Reference< XDispatch > > SAL_CALL
      97           0 :     DispatchInterceptionMultiplexer::queryDispatches( const Sequence< DispatchDescriptor >& aDescripts ) throw(RuntimeException, std::exception)
      98             :     {
      99           0 :         ::osl::MutexGuard aGuard( *m_pMutex );
     100           0 :         Sequence< Reference< XDispatch> > aReturn(aDescripts.getLength());
     101           0 :         Reference< XDispatch>* pReturn = aReturn.getArray();
     102           0 :         const DispatchDescriptor* pDescripts = aDescripts.getConstArray();
     103           0 :         for (sal_Int16 i=0; i<aDescripts.getLength(); ++i, ++pReturn, ++pDescripts)
     104             :         {
     105           0 :             *pReturn = queryDispatch(pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags);
     106             :         }
     107           0 :         return aReturn;
     108             :     }
     109             : 
     110             : 
     111         240 :     Reference< XDispatchProvider > SAL_CALL DispatchInterceptionMultiplexer::getSlaveDispatchProvider(  ) throw(RuntimeException, std::exception)
     112             :     {
     113         240 :         ::osl::MutexGuard aGuard( *m_pMutex );
     114         240 :         return m_xSlaveDispatcher;
     115             :     }
     116             : 
     117             : 
     118         120 :     void SAL_CALL DispatchInterceptionMultiplexer::setSlaveDispatchProvider(const Reference< XDispatchProvider>& xNewDispatchProvider) throw( RuntimeException, std::exception )
     119             :     {
     120         120 :         ::osl::MutexGuard aGuard( *m_pMutex );
     121         120 :         m_xSlaveDispatcher = xNewDispatchProvider;
     122         120 :     }
     123             : 
     124             : 
     125         120 :     Reference< XDispatchProvider> SAL_CALL DispatchInterceptionMultiplexer::getMasterDispatchProvider(void) throw( RuntimeException, std::exception )
     126             :     {
     127         120 :         ::osl::MutexGuard aGuard( *m_pMutex );
     128         120 :         return m_xMasterDispatcher;
     129             :     }
     130             : 
     131             : 
     132         240 :     void SAL_CALL DispatchInterceptionMultiplexer::setMasterDispatchProvider(const Reference< XDispatchProvider>& xNewSupplier) throw( RuntimeException, std::exception )
     133             :     {
     134         240 :         ::osl::MutexGuard aGuard( *m_pMutex );
     135         240 :         m_xMasterDispatcher = xNewSupplier;
     136         240 :     }
     137             : 
     138             : 
     139           0 :     void SAL_CALL DispatchInterceptionMultiplexer::disposing(const EventObject& Source) throw( RuntimeException, std::exception )
     140             :     {
     141           0 :         if (m_bListening)
     142             :         {
     143           0 :             Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
     144           0 :             if (Source.Source == xIntercepted)
     145           0 :                 ImplDetach();
     146             :         }
     147           0 :     }
     148             : 
     149             : 
     150          60 :     void DispatchInterceptionMultiplexer::ImplDetach()
     151             :     {
     152          60 :         ::osl::MutexGuard aGuard( *m_pMutex );
     153             :         OSL_ENSURE(m_bListening, "DispatchInterceptionMultiplexer::ImplDetach: invalid call!");
     154             : 
     155             :         // deregister ourself from the interception component
     156         120 :         Reference< XDispatchProviderInterception > xIntercepted(m_xIntercepted.get(), UNO_QUERY);
     157          60 :         if (xIntercepted.is())
     158          60 :             xIntercepted->releaseDispatchProviderInterceptor(static_cast<XDispatchProviderInterceptor*>(this));
     159             : 
     160             :     //  m_xIntercepted = Reference< XDispatchProviderInterception >();
     161             :             // Don't reset m_xIntercepted: It may be needed by our owner to check for which object we were
     162             :             // responsible. As we hold the object with a weak reference only, this should be no problem.
     163             :             // 88936 - 23.07.2001 - frank.schoenheit@sun.com
     164          60 :         m_pMaster = NULL;
     165          60 :         m_pMutex = &m_aFallback;
     166         120 :         m_bListening = false;
     167          60 :     }
     168             : 
     169             : 
     170          60 :     void DispatchInterceptionMultiplexer::disposing()
     171             :     {
     172             :         // remove ourself as event listener from the interception component
     173          60 :         if (m_bListening)
     174             :         {
     175          60 :             Reference< XComponent> xInterceptedComponent(m_xIntercepted.get(), UNO_QUERY);
     176          60 :             if (xInterceptedComponent.is())
     177          60 :                 xInterceptedComponent->removeEventListener(static_cast<XEventListener*>(this));
     178             : 
     179             :             // detach from the interception component
     180          60 :             ImplDetach();
     181             :         }
     182          60 :     }
     183             : 
     184             : 
     185             : } // namespace svxform
     186             : 
     187             : 
     188             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10