LCOV - code coverage report
Current view: top level - sw/source/core/uibase/uno - unodispatch.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 116 213 54.5 %
Date: 2014-04-11 Functions: 18 24 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 <vcl/svapp.hxx>
      21             : #include <sfx2/viewfrm.hxx>
      22             : #include <sfx2/dispatch.hxx>
      23             : #include <svx/dataaccessdescriptor.hxx>
      24             : #include <comphelper/servicehelper.hxx>
      25             : #include <unodispatch.hxx>
      26             : #include <unobaseclass.hxx>
      27             : #include <view.hxx>
      28             : #include <cmdid.h>
      29             : #include "wrtsh.hxx"
      30             : #include "dbmgr.hxx"
      31             : 
      32             : using namespace ::com::sun::star;
      33             : 
      34             : static const char* cURLFormLetter      = ".uno:DataSourceBrowser/FormLetter";
      35             : static const char* cURLInsertContent   = ".uno:DataSourceBrowser/InsertContent";//data into fields
      36             : static const char* cURLInsertColumns   = ".uno:DataSourceBrowser/InsertColumns";//data into text
      37             : static const char* cURLDocumentDataSource  = ".uno:DataSourceBrowser/DocumentDataSource";//current data source of the document
      38             : static const sal_Char* cInternalDBChangeNotification = ".uno::Writer/DataSourceChanged";
      39             : 
      40        1732 : SwXDispatchProviderInterceptor::SwXDispatchProviderInterceptor(SwView& rVw) :
      41        1732 :     m_pView(&rVw)
      42             : {
      43        1732 :     uno::Reference< frame::XFrame> xUnoFrame = m_pView->GetViewFrame()->GetFrame().GetFrameInterface();
      44        1732 :     m_xIntercepted = uno::Reference< frame::XDispatchProviderInterception>(xUnoFrame, uno::UNO_QUERY);
      45        1732 :     if(m_xIntercepted.is())
      46             :     {
      47        1732 :         m_refCount++;
      48        1732 :         m_xIntercepted->registerDispatchProviderInterceptor((frame::XDispatchProviderInterceptor*)this);
      49             :         // this should make us the top-level dispatch-provider for the component, via a call to our
      50             :         // setDispatchProvider we should have got an fallback for requests we (i.e. our master) cannot fullfill
      51        1732 :         uno::Reference< lang::XComponent> xInterceptedComponent(m_xIntercepted, uno::UNO_QUERY);
      52        1732 :         if (xInterceptedComponent.is())
      53        1732 :             xInterceptedComponent->addEventListener((lang::XEventListener*)this);
      54        1732 :         m_refCount--;
      55        1732 :     }
      56        1732 : }
      57             : 
      58        3462 : SwXDispatchProviderInterceptor::~SwXDispatchProviderInterceptor()
      59             : {
      60        3462 : }
      61             : 
      62       93671 : uno::Reference< frame::XDispatch > SwXDispatchProviderInterceptor::queryDispatch(
      63             :     const util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags )
      64             :         throw(uno::RuntimeException, std::exception)
      65             : {
      66       93671 :     DispatchMutexLock_Impl aLock(*this);
      67       93671 :     uno::Reference< frame::XDispatch> xResult;
      68             :     // create some dispatch ...
      69       93671 :     if(m_pView && aURL.Complete.startsWith(".uno:DataSourceBrowser/"))
      70             :     {
      71          11 :         if(aURL.Complete.equalsAscii(cURLFormLetter) ||
      72           5 :             aURL.Complete.equalsAscii(cURLInsertContent) ||
      73           7 :                 aURL.Complete.equalsAscii(cURLInsertColumns)||
      74           1 :                     aURL.Complete.equalsAscii(cURLDocumentDataSource))
      75             :         {
      76           4 :             if(!m_xDispatch.is())
      77           1 :                 m_xDispatch = new SwXDispatch(*m_pView);
      78           4 :             xResult = m_xDispatch;
      79             :         }
      80             :     }
      81             : 
      82             :     // ask our slave provider
      83       93671 :     if (!xResult.is() && m_xSlaveDispatcher.is())
      84       93667 :         xResult = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
      85             : 
      86       93671 :     return xResult;
      87             : }
      88             : 
      89           0 : uno::Sequence< uno::Reference< frame::XDispatch > > SwXDispatchProviderInterceptor::queryDispatches(
      90             :     const uno::Sequence< frame::DispatchDescriptor >& aDescripts ) throw(uno::RuntimeException, std::exception)
      91             : {
      92           0 :     DispatchMutexLock_Impl aLock(*this);
      93           0 :     uno::Sequence< uno::Reference< frame::XDispatch> > aReturn(aDescripts.getLength());
      94           0 :     uno::Reference< frame::XDispatch>* pReturn = aReturn.getArray();
      95           0 :     const frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
      96           0 :     for (sal_Int16 i=0; i<aDescripts.getLength(); ++i, ++pReturn, ++pDescripts)
      97             :     {
      98           0 :         *pReturn = queryDispatch(pDescripts->FeatureURL,
      99           0 :                 pDescripts->FrameName, pDescripts->SearchFlags);
     100             :     }
     101           0 :     return aReturn;
     102             : }
     103             : 
     104        1731 : uno::Reference< frame::XDispatchProvider > SwXDispatchProviderInterceptor::getSlaveDispatchProvider(  )
     105             :         throw(uno::RuntimeException, std::exception)
     106             : {
     107        1731 :     DispatchMutexLock_Impl aLock(*this);
     108        1731 :     return m_xSlaveDispatcher;
     109             : }
     110             : 
     111        3463 : void SwXDispatchProviderInterceptor::setSlaveDispatchProvider(
     112             :     const uno::Reference< frame::XDispatchProvider >& xNewDispatchProvider ) throw(uno::RuntimeException, std::exception)
     113             : {
     114        3463 :     DispatchMutexLock_Impl aLock(*this);
     115        3463 :     m_xSlaveDispatcher = xNewDispatchProvider;
     116        3463 : }
     117             : 
     118        1731 : uno::Reference< frame::XDispatchProvider > SwXDispatchProviderInterceptor::getMasterDispatchProvider(  )
     119             :         throw(uno::RuntimeException, std::exception)
     120             : {
     121        1731 :     DispatchMutexLock_Impl aLock(*this);
     122        1731 :     return m_xMasterDispatcher;
     123             : }
     124             : 
     125        3463 : void SwXDispatchProviderInterceptor::setMasterDispatchProvider(
     126             :     const uno::Reference< frame::XDispatchProvider >& xNewSupplier ) throw(uno::RuntimeException, std::exception)
     127             : {
     128        3463 :     DispatchMutexLock_Impl aLock(*this);
     129        3463 :     m_xMasterDispatcher = xNewSupplier;
     130        3463 : }
     131             : 
     132           0 : void SwXDispatchProviderInterceptor::disposing( const lang::EventObject& )
     133             :     throw(uno::RuntimeException, std::exception)
     134             : {
     135           0 :     DispatchMutexLock_Impl aLock(*this);
     136           0 :     if (m_xIntercepted.is())
     137             :     {
     138           0 :         m_xIntercepted->releaseDispatchProviderInterceptor((frame::XDispatchProviderInterceptor*)this);
     139           0 :         uno::Reference< lang::XComponent> xInterceptedComponent(m_xIntercepted, uno::UNO_QUERY);
     140           0 :         if (xInterceptedComponent.is())
     141           0 :             xInterceptedComponent->removeEventListener((lang::XEventListener*)this);
     142           0 :         m_xDispatch       = 0;
     143             :     }
     144           0 :     m_xIntercepted = NULL;
     145           0 : }
     146             : 
     147             : namespace
     148             : {
     149             :     class theSwXDispatchProviderInterceptorUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXDispatchProviderInterceptorUnoTunnelId > {};
     150             : }
     151             : 
     152        3462 : const uno::Sequence< sal_Int8 > & SwXDispatchProviderInterceptor::getUnoTunnelId()
     153             : {
     154        3462 :     return theSwXDispatchProviderInterceptorUnoTunnelId::get().getSeq();
     155             : }
     156             : 
     157        1731 : sal_Int64 SwXDispatchProviderInterceptor::getSomething(
     158             :     const uno::Sequence< sal_Int8 >& aIdentifier )
     159             :         throw(uno::RuntimeException, std::exception)
     160             : {
     161        3462 :     if( aIdentifier.getLength() == 16
     162        5193 :         && 0 == memcmp( getUnoTunnelId().getConstArray(),
     163        3462 :                                         aIdentifier.getConstArray(), 16 ) )
     164             :     {
     165        1731 :             return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
     166             :     }
     167           0 :     return 0;
     168             : }
     169             : 
     170        1731 : void    SwXDispatchProviderInterceptor::Invalidate()
     171             : {
     172        1731 :     DispatchMutexLock_Impl aLock(*this);
     173        1731 :     if (m_xIntercepted.is())
     174             :     {
     175        1731 :         m_xIntercepted->releaseDispatchProviderInterceptor((frame::XDispatchProviderInterceptor*)this);
     176        1731 :         uno::Reference< lang::XComponent> xInterceptedComponent(m_xIntercepted, uno::UNO_QUERY);
     177        1731 :         if (xInterceptedComponent.is())
     178        1731 :             xInterceptedComponent->removeEventListener((lang::XEventListener*)this);
     179        1731 :         m_xDispatch       = 0;
     180             :     }
     181        1731 :     m_xIntercepted = NULL;
     182        1731 :     m_pView = 0;
     183        1731 : }
     184             : 
     185           1 : SwXDispatch::SwXDispatch(SwView& rVw) :
     186             :     m_pView(&rVw),
     187             :     m_bOldEnable(sal_False),
     188           1 :     m_bListenerAdded(sal_False)
     189             : {
     190           1 : }
     191             : 
     192           3 : SwXDispatch::~SwXDispatch()
     193             : {
     194           1 :     if(m_bListenerAdded && m_pView)
     195             :     {
     196           0 :         uno::Reference<view::XSelectionSupplier> xSupplier = m_pView->GetUNOObject();
     197           0 :         uno::Reference<view::XSelectionChangeListener> xThis = this;
     198           0 :         xSupplier->removeSelectionChangeListener(xThis);
     199             :     }
     200           2 : }
     201             : 
     202           0 : void SwXDispatch::dispatch(const util::URL& aURL,
     203             :     const uno::Sequence< beans::PropertyValue >& aArgs)
     204             :         throw (uno::RuntimeException, std::exception)
     205             : {
     206           0 :     if(!m_pView)
     207           0 :         throw uno::RuntimeException();
     208           0 :     SwWrtShell& rSh = m_pView->GetWrtShell();
     209           0 :     SwNewDBMgr* pNewDBMgr = rSh.GetNewDBMgr();
     210           0 :     if(aURL.Complete.equalsAscii(cURLInsertContent))
     211             :     {
     212           0 :         ::svx::ODataAccessDescriptor aDescriptor(aArgs);
     213           0 :         SwMergeDescriptor aMergeDesc( DBMGR_MERGE, rSh, aDescriptor );
     214           0 :         pNewDBMgr->MergeNew(aMergeDesc);
     215             :     }
     216           0 :     else if(aURL.Complete.equalsAscii(cURLInsertColumns))
     217             :     {
     218           0 :         pNewDBMgr->InsertText(rSh, aArgs);
     219             :     }
     220           0 :     else if(aURL.Complete.equalsAscii(cURLFormLetter))
     221             :     {
     222           0 :         SfxUsrAnyItem aDBProperties(FN_PARAM_DATABASE_PROPERTIES, uno::makeAny(aArgs));
     223             :         m_pView->GetViewFrame()->GetDispatcher()->Execute(
     224             :             FN_MAILMERGE_WIZARD,
     225             :             SFX_CALLMODE_ASYNCHRON,
     226           0 :             &aDBProperties, 0L);
     227             :     }
     228           0 :     else if(aURL.Complete.equalsAscii(cURLDocumentDataSource))
     229             :     {
     230             :         OSL_FAIL("SwXDispatch::dispatch: this URL is not to be dispatched!");
     231             :     }
     232           0 :     else if(aURL.Complete.equalsAscii(cInternalDBChangeNotification))
     233             :     {
     234           0 :         frame::FeatureStateEvent aEvent;
     235           0 :         aEvent.IsEnabled = sal_True;
     236           0 :         aEvent.Source = *(cppu::OWeakObject*)this;
     237             : 
     238           0 :         const SwDBData& rData = m_pView->GetWrtShell().GetDBDesc();
     239           0 :         ::svx::ODataAccessDescriptor aDescriptor;
     240           0 :         aDescriptor.setDataSource(rData.sDataSource);
     241           0 :         aDescriptor[::svx::daCommand]       <<= rData.sCommand;
     242           0 :         aDescriptor[::svx::daCommandType]   <<= rData.nCommandType;
     243             : 
     244           0 :         aEvent.State <<= aDescriptor.createPropertyValueSequence();
     245           0 :         aEvent.IsEnabled = !rData.sDataSource.isEmpty();
     246             : 
     247           0 :         StatusListenerList::iterator aListIter = m_aListenerList.begin();
     248           0 :         for(aListIter = m_aListenerList.begin(); aListIter != m_aListenerList.end(); ++aListIter)
     249             :         {
     250           0 :             StatusStruct_Impl aStatus = *aListIter;
     251           0 :             if(aStatus.aURL.Complete.equalsAscii(cURLDocumentDataSource))
     252             :             {
     253           0 :                 aEvent.FeatureURL = aStatus.aURL;
     254           0 :                 aStatus.xListener->statusChanged( aEvent );
     255             :             }
     256           0 :         }
     257             :     }
     258             :     else
     259           0 :         throw uno::RuntimeException();
     260             : 
     261           0 : }
     262             : 
     263           4 : void SwXDispatch::addStatusListener(
     264             :     const uno::Reference< frame::XStatusListener >& xControl, const util::URL& aURL ) throw(uno::RuntimeException, std::exception)
     265             : {
     266           4 :     if(!m_pView)
     267           0 :         throw uno::RuntimeException();
     268           4 :     ShellModes eMode = m_pView->GetShellMode();
     269           0 :     sal_Bool bEnable = SHELL_MODE_TEXT == eMode  ||
     270           0 :                        SHELL_MODE_LIST_TEXT == eMode  ||
     271           4 :                        SHELL_MODE_TABLE_TEXT == eMode  ||
     272           4 :                        SHELL_MODE_TABLE_LIST_TEXT == eMode;
     273             : 
     274           4 :     m_bOldEnable = bEnable;
     275           4 :     frame::FeatureStateEvent aEvent;
     276           4 :     aEvent.IsEnabled = bEnable;
     277           4 :     aEvent.Source = *(cppu::OWeakObject*)this;
     278           4 :     aEvent.FeatureURL = aURL;
     279             : 
     280             :     // one of the URLs requires a special state ....
     281           4 :     if (aURL.Complete.equalsAscii(cURLDocumentDataSource))
     282             :     {
     283           1 :         const SwDBData& rData = m_pView->GetWrtShell().GetDBDesc();
     284             : 
     285           1 :         ::svx::ODataAccessDescriptor aDescriptor;
     286           1 :         aDescriptor.setDataSource(rData.sDataSource);
     287           1 :         aDescriptor[::svx::daCommand]       <<= rData.sCommand;
     288           1 :         aDescriptor[::svx::daCommandType]   <<= rData.nCommandType;
     289             : 
     290           1 :         aEvent.State <<= aDescriptor.createPropertyValueSequence();
     291           1 :         aEvent.IsEnabled = !rData.sDataSource.isEmpty();
     292             :     }
     293             : 
     294           4 :     xControl->statusChanged( aEvent );
     295             : 
     296           4 :     StatusListenerList::iterator aListIter = m_aListenerList.begin();
     297           8 :     StatusStruct_Impl aStatus;
     298           4 :     aStatus.xListener = xControl;
     299           4 :     aStatus.aURL = aURL;
     300           4 :     m_aListenerList.insert(aListIter, aStatus);
     301             : 
     302           4 :     if(!m_bListenerAdded)
     303             :     {
     304           1 :         uno::Reference<view::XSelectionSupplier> xSupplier = m_pView->GetUNOObject();
     305           2 :         uno::Reference<view::XSelectionChangeListener> xThis = this;
     306           1 :         xSupplier->addSelectionChangeListener(xThis);
     307           2 :         m_bListenerAdded = sal_True;
     308           4 :     }
     309           4 : }
     310             : 
     311           4 : void SwXDispatch::removeStatusListener(
     312             :     const uno::Reference< frame::XStatusListener >& xControl, const util::URL&  ) throw(uno::RuntimeException, std::exception)
     313             : {
     314           4 :     StatusListenerList::iterator aListIter = m_aListenerList.begin();
     315           4 :     for(aListIter = m_aListenerList.begin(); aListIter != m_aListenerList.end(); ++aListIter)
     316             :     {
     317           4 :         StatusStruct_Impl aStatus = *aListIter;
     318           4 :         if(aStatus.xListener.get() == xControl.get())
     319             :         {
     320           4 :             m_aListenerList.erase(aListIter);
     321           4 :             break;
     322             :         }
     323           0 :     }
     324           4 :     if(m_aListenerList.empty() && m_pView)
     325             :     {
     326           1 :         uno::Reference<view::XSelectionSupplier> xSupplier = m_pView->GetUNOObject();
     327           2 :         uno::Reference<view::XSelectionChangeListener> xThis = this;
     328           1 :         xSupplier->removeSelectionChangeListener(xThis);
     329           2 :         m_bListenerAdded = sal_False;
     330             :     }
     331           4 : }
     332             : 
     333           0 : void SwXDispatch::selectionChanged( const lang::EventObject&  ) throw(uno::RuntimeException, std::exception)
     334             : {
     335           0 :     ShellModes eMode = m_pView->GetShellMode();
     336           0 :     sal_Bool bEnable = SHELL_MODE_TEXT == eMode  ||
     337           0 :                        SHELL_MODE_LIST_TEXT == eMode  ||
     338           0 :                        SHELL_MODE_TABLE_TEXT == eMode  ||
     339           0 :                        SHELL_MODE_TABLE_LIST_TEXT == eMode;
     340           0 :     if(bEnable != m_bOldEnable)
     341             :     {
     342           0 :         m_bOldEnable = bEnable;
     343           0 :         frame::FeatureStateEvent aEvent;
     344           0 :         aEvent.IsEnabled = bEnable;
     345           0 :         aEvent.Source = *(cppu::OWeakObject*)this;
     346             : 
     347           0 :         StatusListenerList::iterator aListIter = m_aListenerList.begin();
     348           0 :         for(aListIter = m_aListenerList.begin(); aListIter != m_aListenerList.end(); ++aListIter)
     349             :         {
     350           0 :             StatusStruct_Impl aStatus = *aListIter;
     351           0 :             aEvent.FeatureURL = aStatus.aURL;
     352           0 :             if (!aStatus.aURL.Complete.equalsAscii(cURLDocumentDataSource))
     353             :                 // the document's data source does not depend on the selection, so it's state does not change here
     354           0 :                 aStatus.xListener->statusChanged( aEvent );
     355           0 :         }
     356             :     }
     357           0 : }
     358             : 
     359           0 : void SwXDispatch::disposing( const lang::EventObject& rSource ) throw(uno::RuntimeException, std::exception)
     360             : {
     361           0 :     uno::Reference<view::XSelectionSupplier> xSupplier(rSource.Source, uno::UNO_QUERY);
     362           0 :     uno::Reference<view::XSelectionChangeListener> xThis = this;
     363           0 :     xSupplier->removeSelectionChangeListener(xThis);
     364           0 :     m_bListenerAdded = sal_False;
     365             : 
     366           0 :     lang::EventObject aObject;
     367           0 :     aObject.Source = (cppu::OWeakObject*)this;
     368           0 :     StatusListenerList::iterator aListIter = m_aListenerList.begin();
     369           0 :     for(; aListIter != m_aListenerList.end(); ++aListIter)
     370             :     {
     371           0 :         StatusStruct_Impl aStatus = *aListIter;
     372           0 :         aStatus.xListener->disposing(aObject);
     373           0 :     }
     374           0 :     m_pView = 0;
     375           0 : }
     376             : 
     377           0 : const sal_Char* SwXDispatch::GetDBChangeURL()
     378             : {
     379           0 :     return cInternalDBChangeNotification;
     380             : }
     381             : 
     382      105790 : SwXDispatchProviderInterceptor::DispatchMutexLock_Impl::DispatchMutexLock_Impl(
     383      105790 :                                                  SwXDispatchProviderInterceptor& )
     384             : {
     385      105790 : }
     386             : 
     387      105790 : SwXDispatchProviderInterceptor::DispatchMutexLock_Impl::~DispatchMutexLock_Impl()
     388             : {
     389      105790 : }
     390             : 
     391             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10