LCOV - code coverage report
Current view: top level - sw/source/core/uibase/uno - unodispatch.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 213 0.0 %
Date: 2014-04-14 Functions: 0 24 0.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           0 : SwXDispatchProviderInterceptor::SwXDispatchProviderInterceptor(SwView& rVw) :
      41           0 :     m_pView(&rVw)
      42             : {
      43           0 :     uno::Reference< frame::XFrame> xUnoFrame = m_pView->GetViewFrame()->GetFrame().GetFrameInterface();
      44           0 :     m_xIntercepted = uno::Reference< frame::XDispatchProviderInterception>(xUnoFrame, uno::UNO_QUERY);
      45           0 :     if(m_xIntercepted.is())
      46             :     {
      47           0 :         m_refCount++;
      48           0 :         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           0 :         uno::Reference< lang::XComponent> xInterceptedComponent(m_xIntercepted, uno::UNO_QUERY);
      52           0 :         if (xInterceptedComponent.is())
      53           0 :             xInterceptedComponent->addEventListener((lang::XEventListener*)this);
      54           0 :         m_refCount--;
      55           0 :     }
      56           0 : }
      57             : 
      58           0 : SwXDispatchProviderInterceptor::~SwXDispatchProviderInterceptor()
      59             : {
      60           0 : }
      61             : 
      62           0 : 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           0 :     DispatchMutexLock_Impl aLock(*this);
      67           0 :     uno::Reference< frame::XDispatch> xResult;
      68             :     // create some dispatch ...
      69           0 :     if(m_pView && aURL.Complete.startsWith(".uno:DataSourceBrowser/"))
      70             :     {
      71           0 :         if(aURL.Complete.equalsAscii(cURLFormLetter) ||
      72           0 :             aURL.Complete.equalsAscii(cURLInsertContent) ||
      73           0 :                 aURL.Complete.equalsAscii(cURLInsertColumns)||
      74           0 :                     aURL.Complete.equalsAscii(cURLDocumentDataSource))
      75             :         {
      76           0 :             if(!m_xDispatch.is())
      77           0 :                 m_xDispatch = new SwXDispatch(*m_pView);
      78           0 :             xResult = m_xDispatch;
      79             :         }
      80             :     }
      81             : 
      82             :     // ask our slave provider
      83           0 :     if (!xResult.is() && m_xSlaveDispatcher.is())
      84           0 :         xResult = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
      85             : 
      86           0 :     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           0 : uno::Reference< frame::XDispatchProvider > SwXDispatchProviderInterceptor::getSlaveDispatchProvider(  )
     105             :         throw(uno::RuntimeException, std::exception)
     106             : {
     107           0 :     DispatchMutexLock_Impl aLock(*this);
     108           0 :     return m_xSlaveDispatcher;
     109             : }
     110             : 
     111           0 : void SwXDispatchProviderInterceptor::setSlaveDispatchProvider(
     112             :     const uno::Reference< frame::XDispatchProvider >& xNewDispatchProvider ) throw(uno::RuntimeException, std::exception)
     113             : {
     114           0 :     DispatchMutexLock_Impl aLock(*this);
     115           0 :     m_xSlaveDispatcher = xNewDispatchProvider;
     116           0 : }
     117             : 
     118           0 : uno::Reference< frame::XDispatchProvider > SwXDispatchProviderInterceptor::getMasterDispatchProvider(  )
     119             :         throw(uno::RuntimeException, std::exception)
     120             : {
     121           0 :     DispatchMutexLock_Impl aLock(*this);
     122           0 :     return m_xMasterDispatcher;
     123             : }
     124             : 
     125           0 : void SwXDispatchProviderInterceptor::setMasterDispatchProvider(
     126             :     const uno::Reference< frame::XDispatchProvider >& xNewSupplier ) throw(uno::RuntimeException, std::exception)
     127             : {
     128           0 :     DispatchMutexLock_Impl aLock(*this);
     129           0 :     m_xMasterDispatcher = xNewSupplier;
     130           0 : }
     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           0 : const uno::Sequence< sal_Int8 > & SwXDispatchProviderInterceptor::getUnoTunnelId()
     153             : {
     154           0 :     return theSwXDispatchProviderInterceptorUnoTunnelId::get().getSeq();
     155             : }
     156             : 
     157           0 : sal_Int64 SwXDispatchProviderInterceptor::getSomething(
     158             :     const uno::Sequence< sal_Int8 >& aIdentifier )
     159             :         throw(uno::RuntimeException, std::exception)
     160             : {
     161           0 :     if( aIdentifier.getLength() == 16
     162           0 :         && 0 == memcmp( getUnoTunnelId().getConstArray(),
     163           0 :                                         aIdentifier.getConstArray(), 16 ) )
     164             :     {
     165           0 :             return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
     166             :     }
     167           0 :     return 0;
     168             : }
     169             : 
     170           0 : void    SwXDispatchProviderInterceptor::Invalidate()
     171             : {
     172           0 :     DispatchMutexLock_Impl aLock(*this);
     173           0 :     if (m_xIntercepted.is())
     174             :     {
     175           0 :         m_xIntercepted->releaseDispatchProviderInterceptor((frame::XDispatchProviderInterceptor*)this);
     176           0 :         uno::Reference< lang::XComponent> xInterceptedComponent(m_xIntercepted, uno::UNO_QUERY);
     177           0 :         if (xInterceptedComponent.is())
     178           0 :             xInterceptedComponent->removeEventListener((lang::XEventListener*)this);
     179           0 :         m_xDispatch       = 0;
     180             :     }
     181           0 :     m_xIntercepted = NULL;
     182           0 :     m_pView = 0;
     183           0 : }
     184             : 
     185           0 : SwXDispatch::SwXDispatch(SwView& rVw) :
     186             :     m_pView(&rVw),
     187             :     m_bOldEnable(sal_False),
     188           0 :     m_bListenerAdded(sal_False)
     189             : {
     190           0 : }
     191             : 
     192           0 : SwXDispatch::~SwXDispatch()
     193             : {
     194           0 :     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           0 : }
     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           0 : void SwXDispatch::addStatusListener(
     264             :     const uno::Reference< frame::XStatusListener >& xControl, const util::URL& aURL ) throw(uno::RuntimeException, std::exception)
     265             : {
     266           0 :     if(!m_pView)
     267           0 :         throw uno::RuntimeException();
     268           0 :     ShellModes eMode = m_pView->GetShellMode();
     269           0 :     sal_Bool bEnable = SHELL_MODE_TEXT == eMode  ||
     270           0 :                        SHELL_MODE_LIST_TEXT == eMode  ||
     271           0 :                        SHELL_MODE_TABLE_TEXT == eMode  ||
     272           0 :                        SHELL_MODE_TABLE_LIST_TEXT == eMode;
     273             : 
     274           0 :     m_bOldEnable = bEnable;
     275           0 :     frame::FeatureStateEvent aEvent;
     276           0 :     aEvent.IsEnabled = bEnable;
     277           0 :     aEvent.Source = *(cppu::OWeakObject*)this;
     278           0 :     aEvent.FeatureURL = aURL;
     279             : 
     280             :     // one of the URLs requires a special state ....
     281           0 :     if (aURL.Complete.equalsAscii(cURLDocumentDataSource))
     282             :     {
     283           0 :         const SwDBData& rData = m_pView->GetWrtShell().GetDBDesc();
     284             : 
     285           0 :         ::svx::ODataAccessDescriptor aDescriptor;
     286           0 :         aDescriptor.setDataSource(rData.sDataSource);
     287           0 :         aDescriptor[::svx::daCommand]       <<= rData.sCommand;
     288           0 :         aDescriptor[::svx::daCommandType]   <<= rData.nCommandType;
     289             : 
     290           0 :         aEvent.State <<= aDescriptor.createPropertyValueSequence();
     291           0 :         aEvent.IsEnabled = !rData.sDataSource.isEmpty();
     292             :     }
     293             : 
     294           0 :     xControl->statusChanged( aEvent );
     295             : 
     296           0 :     StatusListenerList::iterator aListIter = m_aListenerList.begin();
     297           0 :     StatusStruct_Impl aStatus;
     298           0 :     aStatus.xListener = xControl;
     299           0 :     aStatus.aURL = aURL;
     300           0 :     m_aListenerList.insert(aListIter, aStatus);
     301             : 
     302           0 :     if(!m_bListenerAdded)
     303             :     {
     304           0 :         uno::Reference<view::XSelectionSupplier> xSupplier = m_pView->GetUNOObject();
     305           0 :         uno::Reference<view::XSelectionChangeListener> xThis = this;
     306           0 :         xSupplier->addSelectionChangeListener(xThis);
     307           0 :         m_bListenerAdded = sal_True;
     308           0 :     }
     309           0 : }
     310             : 
     311           0 : void SwXDispatch::removeStatusListener(
     312             :     const uno::Reference< frame::XStatusListener >& xControl, const util::URL&  ) throw(uno::RuntimeException, std::exception)
     313             : {
     314           0 :     StatusListenerList::iterator aListIter = m_aListenerList.begin();
     315           0 :     for(aListIter = m_aListenerList.begin(); aListIter != m_aListenerList.end(); ++aListIter)
     316             :     {
     317           0 :         StatusStruct_Impl aStatus = *aListIter;
     318           0 :         if(aStatus.xListener.get() == xControl.get())
     319             :         {
     320           0 :             m_aListenerList.erase(aListIter);
     321           0 :             break;
     322             :         }
     323           0 :     }
     324           0 :     if(m_aListenerList.empty() && m_pView)
     325             :     {
     326           0 :         uno::Reference<view::XSelectionSupplier> xSupplier = m_pView->GetUNOObject();
     327           0 :         uno::Reference<view::XSelectionChangeListener> xThis = this;
     328           0 :         xSupplier->removeSelectionChangeListener(xThis);
     329           0 :         m_bListenerAdded = sal_False;
     330             :     }
     331           0 : }
     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           0 : SwXDispatchProviderInterceptor::DispatchMutexLock_Impl::DispatchMutexLock_Impl(
     383           0 :                                                  SwXDispatchProviderInterceptor& )
     384             : {
     385           0 : }
     386             : 
     387           0 : SwXDispatchProviderInterceptor::DispatchMutexLock_Impl::~DispatchMutexLock_Impl()
     388             : {
     389           0 : }
     390             : 
     391             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10