LCOV - code coverage report
Current view: top level - embeddedobj/source/general - intercept.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 2 157 1.3 %
Date: 2015-06-13 12:38:46 Functions: 2 18 11.1 %
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 <com/sun/star/embed/EmbedStates.hpp>
      21             : #include <cppuhelper/weak.hxx>
      22             : 
      23             : #include "intercept.hxx"
      24             : #include "docholder.hxx"
      25             : #include "commonembobj.hxx"
      26             : 
      27             : using namespace ::com::sun::star;
      28             : 
      29             : #define IUL 6
      30             : 
      31          32 : uno::Sequence< OUString > Interceptor::m_aInterceptedURL(IUL);
      32             : 
      33           0 : class StatusChangeListenerContainer
      34             :     : public cppu::OMultiTypeInterfaceContainerHelperVar<OUString>
      35             : {
      36             : public:
      37           0 :     StatusChangeListenerContainer( ::osl::Mutex& aMutex )
      38           0 :         :  cppu::OMultiTypeInterfaceContainerHelperVar<OUString>(aMutex)
      39             :     {
      40           0 :     }
      41             : };
      42             : 
      43           0 : void Interceptor::DisconnectDocHolder()
      44             : {
      45           0 :     osl::MutexGuard aGuard( m_aMutex );
      46           0 :     m_pDocHolder = NULL;
      47           0 : }
      48             : 
      49           0 : Interceptor::Interceptor( DocumentHolder* pDocHolder )
      50             :     : m_pDocHolder( pDocHolder ),
      51             :       m_pDisposeEventListeners(0),
      52           0 :       m_pStatCL(0)
      53             : {
      54           0 :     m_aInterceptedURL[0] = ".uno:Save";
      55           0 :     m_aInterceptedURL[1] = ".uno:SaveAll";
      56           0 :     m_aInterceptedURL[2] = ".uno:CloseDoc";
      57           0 :     m_aInterceptedURL[3] = ".uno:CloseWin";
      58           0 :     m_aInterceptedURL[4] = ".uno:CloseFrame";
      59           0 :     m_aInterceptedURL[5] = ".uno:SaveAs";
      60             : 
      61           0 : }
      62             : 
      63           0 : Interceptor::~Interceptor()
      64             : {
      65           0 :     if( m_pDisposeEventListeners )
      66           0 :         delete m_pDisposeEventListeners;
      67             : 
      68           0 :     if(m_pStatCL)
      69           0 :         delete m_pStatCL;
      70           0 : }
      71             : 
      72             : //XDispatch
      73             : void SAL_CALL
      74           0 : Interceptor::dispatch(
      75             :     const util::URL& URL,
      76             :     const uno::Sequence<
      77             :     beans::PropertyValue >& Arguments )
      78             :     throw (uno::RuntimeException, std::exception)
      79             : {
      80           0 :     osl::MutexGuard aGuard(m_aMutex);
      81           0 :     if( m_pDocHolder )
      82             :     {
      83           0 :         if(URL.Complete == m_aInterceptedURL[0])
      84           0 :             m_pDocHolder->GetEmbedObject()->SaveObject_Impl();
      85           0 :         else if(URL.Complete == m_aInterceptedURL[2] ||
      86           0 :                 URL.Complete == m_aInterceptedURL[3] ||
      87           0 :                 URL.Complete == m_aInterceptedURL[4])
      88             :         {
      89             :             try {
      90           0 :                 m_pDocHolder->GetEmbedObject()->changeState( embed::EmbedStates::RUNNING );
      91             :             }
      92           0 :             catch( const uno::Exception& )
      93             :             {
      94             :             }
      95             :         }
      96           0 :         else if ( URL.Complete == m_aInterceptedURL[5] )
      97             :         {
      98           0 :             uno::Sequence< beans::PropertyValue > aNewArgs = Arguments;
      99           0 :             sal_Int32 nInd = 0;
     100             : 
     101           0 :             while( nInd < aNewArgs.getLength() )
     102             :             {
     103           0 :                 if ( aNewArgs[nInd].Name == "SaveTo" )
     104             :                 {
     105           0 :                     aNewArgs[nInd].Value <<= sal_True;
     106           0 :                     break;
     107             :                 }
     108           0 :                 nInd++;
     109             :             }
     110             : 
     111           0 :             if ( nInd == aNewArgs.getLength() )
     112             :             {
     113           0 :                 aNewArgs.realloc( nInd + 1 );
     114           0 :                 aNewArgs[nInd].Name = "SaveTo";
     115           0 :                 aNewArgs[nInd].Value <<= sal_True;
     116             :             }
     117             : 
     118           0 :             uno::Reference< frame::XDispatch > xDispatch = m_xSlaveDispatchProvider->queryDispatch(
     119           0 :                 URL, OUString( "_self" ), 0 );
     120           0 :             if ( xDispatch.is() )
     121           0 :                 xDispatch->dispatch( URL, aNewArgs );
     122             :         }
     123           0 :     }
     124           0 : }
     125             : 
     126             : void SAL_CALL
     127           0 : Interceptor::addStatusListener(
     128             :     const uno::Reference<
     129             :     frame::XStatusListener >& Control,
     130             :     const util::URL& URL )
     131             :     throw (
     132             :         uno::RuntimeException, std::exception
     133             :     )
     134             : {
     135           0 :     if(!Control.is())
     136           0 :         return;
     137             : 
     138           0 :     if(URL.Complete == m_aInterceptedURL[0])
     139             :     {   // Save
     140           0 :         frame::FeatureStateEvent aStateEvent;
     141           0 :         aStateEvent.FeatureURL.Complete = m_aInterceptedURL[0];
     142           0 :         aStateEvent.FeatureDescriptor = "Update";
     143           0 :         aStateEvent.IsEnabled = sal_True;
     144           0 :         aStateEvent.Requery = sal_False;
     145           0 :         aStateEvent.State <<= ( "($1) " + m_pDocHolder->GetTitle() );
     146           0 :         Control->statusChanged(aStateEvent);
     147             : 
     148             :         {
     149           0 :             osl::MutexGuard aGuard(m_aMutex);
     150           0 :             if(!m_pStatCL)
     151             :                 m_pStatCL =
     152           0 :                     new StatusChangeListenerContainer(m_aMutex);
     153             :         }
     154             : 
     155           0 :         m_pStatCL->addInterface(URL.Complete,Control);
     156           0 :         return;
     157             :     }
     158             : 
     159           0 :     sal_Int32 i = 2;
     160           0 :     if(URL.Complete == m_aInterceptedURL[i] ||
     161           0 :        URL.Complete == m_aInterceptedURL[++i] ||
     162           0 :        URL.Complete == m_aInterceptedURL[++i] )
     163             :     {   // Close and return
     164           0 :         frame::FeatureStateEvent aStateEvent;
     165           0 :         aStateEvent.FeatureURL.Complete = m_aInterceptedURL[i];
     166           0 :         aStateEvent.FeatureDescriptor = "Close and Return";
     167           0 :         aStateEvent.IsEnabled = sal_True;
     168           0 :         aStateEvent.Requery = sal_False;
     169           0 :         aStateEvent.State <<= ( "($2) " + m_pDocHolder->GetTitle() );
     170           0 :         Control->statusChanged(aStateEvent);
     171             : 
     172             : 
     173             :         {
     174           0 :             osl::MutexGuard aGuard(m_aMutex);
     175           0 :             if(!m_pStatCL)
     176             :                 m_pStatCL =
     177           0 :                     new StatusChangeListenerContainer(m_aMutex);
     178             :         }
     179             : 
     180           0 :         m_pStatCL->addInterface(URL.Complete,Control);
     181           0 :         return;
     182             :     }
     183             : 
     184           0 :     if(URL.Complete == m_aInterceptedURL[5])
     185             :     {   // SaveAs
     186           0 :         frame::FeatureStateEvent aStateEvent;
     187           0 :         aStateEvent.FeatureURL.Complete = m_aInterceptedURL[5];
     188           0 :         aStateEvent.FeatureDescriptor = "SaveCopyTo";
     189           0 :         aStateEvent.IsEnabled = sal_True;
     190           0 :         aStateEvent.Requery = sal_False;
     191           0 :         aStateEvent.State <<= (OUString( "($3)"));
     192           0 :         Control->statusChanged(aStateEvent);
     193             : 
     194             :         {
     195           0 :             osl::MutexGuard aGuard(m_aMutex);
     196           0 :             if(!m_pStatCL)
     197             :                 m_pStatCL =
     198           0 :                     new StatusChangeListenerContainer(m_aMutex);
     199             :         }
     200             : 
     201           0 :         m_pStatCL->addInterface(URL.Complete,Control);
     202           0 :         return;
     203             :     }
     204             : 
     205             : }
     206             : 
     207             : 
     208             : void SAL_CALL
     209           0 : Interceptor::removeStatusListener(
     210             :     const uno::Reference<
     211             :     frame::XStatusListener >& Control,
     212             :     const util::URL& URL )
     213             :     throw (
     214             :         uno::RuntimeException, std::exception
     215             :     )
     216             : {
     217           0 :     if(!(Control.is() && m_pStatCL))
     218           0 :         return;
     219             :     else {
     220           0 :         m_pStatCL->removeInterface(URL.Complete,Control);
     221           0 :         return;
     222             :     }
     223             : }
     224             : 
     225             : 
     226             : //XInterceptorInfo
     227             : uno::Sequence< OUString >
     228             : SAL_CALL
     229           0 : Interceptor::getInterceptedURLs(  )
     230             :     throw (
     231             :         uno::RuntimeException, std::exception
     232             :     )
     233             : {
     234             :     // now implemented as update
     235             : 
     236           0 :     return m_aInterceptedURL;
     237             : }
     238             : 
     239             : 
     240             : // XDispatchProvider
     241             : 
     242             : uno::Reference< frame::XDispatch > SAL_CALL
     243           0 : Interceptor::queryDispatch(
     244             :     const util::URL& URL,
     245             :     const OUString& TargetFrameName,
     246             :     sal_Int32 SearchFlags )
     247             :     throw (
     248             :         uno::RuntimeException, std::exception
     249             :     )
     250             : {
     251           0 :     osl::MutexGuard aGuard(m_aMutex);
     252           0 :     if(URL.Complete == m_aInterceptedURL[0])
     253           0 :         return static_cast<frame::XDispatch*>(this);
     254           0 :     else if(URL.Complete == m_aInterceptedURL[1])
     255           0 :         return nullptr   ;
     256           0 :     else if(URL.Complete == m_aInterceptedURL[2])
     257           0 :         return static_cast<frame::XDispatch*>(this);
     258           0 :     else if(URL.Complete == m_aInterceptedURL[3])
     259           0 :         return static_cast<frame::XDispatch*>(this);
     260           0 :     else if(URL.Complete == m_aInterceptedURL[4])
     261           0 :         return static_cast<frame::XDispatch*>(this);
     262           0 :     else if(URL.Complete == m_aInterceptedURL[5])
     263           0 :         return static_cast<frame::XDispatch*>(this);
     264             :     else {
     265           0 :         if(m_xSlaveDispatchProvider.is())
     266           0 :             return m_xSlaveDispatchProvider->queryDispatch(
     267           0 :                 URL,TargetFrameName,SearchFlags);
     268             :         else
     269           0 :             return uno::Reference<frame::XDispatch>(0);
     270           0 :     }
     271             : }
     272             : 
     273             : uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL
     274           0 : Interceptor::queryDispatches(
     275             :     const uno::Sequence<frame::DispatchDescriptor >& Requests )
     276             :     throw (
     277             :         uno::RuntimeException, std::exception
     278             :     )
     279             : {
     280           0 :     uno::Sequence< uno::Reference< frame::XDispatch > > aRet;
     281           0 :     osl::MutexGuard aGuard(m_aMutex);
     282           0 :     if(m_xSlaveDispatchProvider.is())
     283           0 :         aRet = m_xSlaveDispatchProvider->queryDispatches(Requests);
     284             :     else
     285           0 :         aRet.realloc(Requests.getLength());
     286             : 
     287           0 :     for(sal_Int32 i = 0; i < Requests.getLength(); ++i)
     288           0 :         if(m_aInterceptedURL[0] == Requests[i].FeatureURL.Complete)
     289           0 :             aRet[i] = static_cast<frame::XDispatch*>(this);
     290           0 :         else if(m_aInterceptedURL[1] == Requests[i].FeatureURL.Complete)
     291           0 :             aRet[i] = nullptr;
     292           0 :         else if(m_aInterceptedURL[2] == Requests[i].FeatureURL.Complete)
     293           0 :             aRet[i] = static_cast<frame::XDispatch*>(this);
     294           0 :         else if(m_aInterceptedURL[3] == Requests[i].FeatureURL.Complete)
     295           0 :             aRet[i] = static_cast<frame::XDispatch*>(this);
     296           0 :         else if(m_aInterceptedURL[4] == Requests[i].FeatureURL.Complete)
     297           0 :             aRet[i] = static_cast<frame::XDispatch*>(this);
     298           0 :         else if(m_aInterceptedURL[5] == Requests[i].FeatureURL.Complete)
     299           0 :             aRet[i] = static_cast<frame::XDispatch*>(this);
     300             : 
     301           0 :     return aRet;
     302             : }
     303             : 
     304             : 
     305             : 
     306             : //XDispatchProviderInterceptor
     307             : 
     308             : uno::Reference< frame::XDispatchProvider > SAL_CALL
     309           0 : Interceptor::getSlaveDispatchProvider(  )
     310             :     throw (
     311             :         uno::RuntimeException, std::exception
     312             :     )
     313             : {
     314           0 :     osl::MutexGuard aGuard(m_aMutex);
     315           0 :     return m_xSlaveDispatchProvider;
     316             : }
     317             : 
     318             : void SAL_CALL
     319           0 : Interceptor::setSlaveDispatchProvider(
     320             :     const uno::Reference< frame::XDispatchProvider >& NewDispatchProvider )
     321             :     throw (
     322             :         uno::RuntimeException, std::exception
     323             :     )
     324             : {
     325           0 :     osl::MutexGuard aGuard(m_aMutex);
     326           0 :     m_xSlaveDispatchProvider = NewDispatchProvider;
     327           0 : }
     328             : 
     329             : 
     330             : uno::Reference< frame::XDispatchProvider > SAL_CALL
     331           0 : Interceptor::getMasterDispatchProvider(  )
     332             :     throw (
     333             :         uno::RuntimeException, std::exception
     334             :     )
     335             : {
     336           0 :     osl::MutexGuard aGuard(m_aMutex);
     337           0 :     return m_xMasterDispatchProvider;
     338             : }
     339             : 
     340             : 
     341             : void SAL_CALL
     342           0 : Interceptor::setMasterDispatchProvider(
     343             :     const uno::Reference< frame::XDispatchProvider >& NewSupplier )
     344             :     throw (
     345             :         uno::RuntimeException, std::exception
     346             :     )
     347             : {
     348           0 :     osl::MutexGuard aGuard(m_aMutex);
     349           0 :     m_xMasterDispatchProvider = NewSupplier;
     350          96 : }
     351             : 
     352             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11