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

Generated by: LCOV version 1.10