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

Generated by: LCOV version 1.10