LCOV - code coverage report
Current view: top level - sfx2/source/appl - appdispatchprovider.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 42 89 47.2 %
Date: 2015-06-13 12:38:46 Functions: 11 14 78.6 %
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 <sal/config.h>
      21             : 
      22             : #include <com/sun/star/frame/XAppDispatchProvider.hpp>
      23             : #include <com/sun/star/frame/XDispatch.hpp>
      24             : #include <com/sun/star/frame/XFrame.hpp>
      25             : #include <com/sun/star/frame/DispatchDescriptor.hpp>
      26             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      27             : #include <com/sun/star/lang/XInitialization.hpp>
      28             : #include <com/sun/star/lang/XServiceInfo.hpp>
      29             : #include <com/sun/star/uno/Exception.hpp>
      30             : #include <com/sun/star/util/URL.hpp>
      31             : 
      32             : #include <basic/basmgr.hxx>
      33             : #include <basic/sbuno.hxx>
      34             : #include <comphelper/sequence.hxx>
      35             : #include <cppuhelper/implbase3.hxx>
      36             : #include <cppuhelper/supportsservice.hxx>
      37             : #include <rtl/ref.hxx>
      38             : #include <sfx2/app.hxx>
      39             : #include <sfx2/dispatch.hxx>
      40             : #include <sfx2/docfile.hxx>
      41             : #include <sfx2/fcontnr.hxx>
      42             : #include <sfx2/frame.hxx>
      43             : #include <sfx2/module.hxx>
      44             : #include <sfx2/msg.hxx>
      45             : #include <sfx2/msgpool.hxx>
      46             : #include <sfx2/objsh.hxx>
      47             : #include <sfx2/request.hxx>
      48             : #include <sfx2/sfxbasecontroller.hxx>
      49             : #include <sfx2/sfxsids.hrc>
      50             : #include <sfx2/sfxuno.hxx>
      51             : #include <sfx2/unoctitm.hxx>
      52             : #include <svl/intitem.hxx>
      53             : #include <tools/urlobj.hxx>
      54             : #include <vcl/svapp.hxx>
      55             : 
      56             : using namespace ::com::sun::star;
      57             : using namespace ::com::sun::star::frame;
      58             : using namespace ::com::sun::star::uno;
      59             : 
      60             : namespace {
      61             : 
      62        8506 : class SfxAppDispatchProvider : public ::cppu::WeakImplHelper3< css::frame::XAppDispatchProvider,
      63             :                                                                css::lang::XServiceInfo,
      64             :                                                                css::lang::XInitialization >
      65             : {
      66             :     css::uno::WeakReference < css::frame::XFrame > m_xFrame;
      67             : public:
      68        4253 :     SfxAppDispatchProvider() {}
      69             : 
      70             :     virtual void SAL_CALL initialize(
      71             :         css::uno::Sequence<css::uno::Any> const & aArguments)
      72             :         throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      73             : 
      74             :     virtual OUString SAL_CALL getImplementationName()
      75             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      76             : 
      77             :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
      78             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      79             : 
      80             :     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
      81             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      82             : 
      83             :     virtual css::uno::Reference < css::frame::XDispatch > SAL_CALL queryDispatch(
      84             :             const css::util::URL& aURL, const OUString& sTargetFrameName,
      85             :             FrameSearchFlags eSearchFlags )
      86             :         throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      87             : 
      88             :     virtual css::uno::Sequence< css::uno::Reference < css::frame::XDispatch > > SAL_CALL queryDispatches(
      89             :             const css::uno::Sequence < css::frame::DispatchDescriptor >& seqDescriptor )
      90             :         throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      91             : 
      92             :     virtual css::uno::Sequence< sal_Int16 > SAL_CALL getSupportedCommandGroups()
      93             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      94             : 
      95             :     virtual css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation( sal_Int16 )
      96             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      97             : };
      98             : 
      99        4251 : void SfxAppDispatchProvider::initialize(
     100             :     css::uno::Sequence<css::uno::Any> const & aArguments)
     101             :     throw (css::uno::Exception, css::uno::RuntimeException, std::exception)
     102             : {
     103        4251 :     css::uno::Reference<css::frame::XFrame> f;
     104        4251 :     if (aArguments.getLength() != 1 || !(aArguments[0] >>= f)) {
     105             :         throw css::lang::IllegalArgumentException(
     106             :             "SfxAppDispatchProvider::initialize expects one XFrame argument",
     107           0 :             static_cast<OWeakObject *>(this), 0);
     108             :     }
     109        4251 :     m_xFrame = f;
     110        4251 : }
     111             : 
     112           3 : OUString SAL_CALL SfxAppDispatchProvider::getImplementationName() throw( css::uno::RuntimeException, std::exception )
     113             : {
     114           3 :     return OUString( "com.sun.star.comp.sfx2.AppDispatchProvider" );
     115             : }
     116             : 
     117           0 : sal_Bool SAL_CALL SfxAppDispatchProvider::supportsService( const OUString& sServiceName ) throw( css::uno::RuntimeException, std::exception )
     118             : {
     119           0 :     return cppu::supportsService(this, sServiceName);
     120             : }
     121             : 
     122           1 : css::uno::Sequence< OUString > SAL_CALL SfxAppDispatchProvider::getSupportedServiceNames() throw( css::uno::RuntimeException, std::exception )
     123             : {
     124           1 :     css::uno::Sequence< OUString > seqServiceNames( 2 );
     125           1 :     seqServiceNames.getArray()[0] = "com.sun.star.frame.ProtocolHandler";
     126           1 :     seqServiceNames.getArray()[1] = "com.sun.star.frame.AppDispatchProvider";
     127           1 :     return seqServiceNames;
     128             : }
     129             : 
     130        4253 : Reference < XDispatch > SAL_CALL SfxAppDispatchProvider::queryDispatch(
     131             :     const util::URL& aURL,
     132             :     const OUString& /*sTargetFrameName*/,
     133             :     FrameSearchFlags /*eSearchFlags*/ ) throw( RuntimeException, std::exception )
     134             : {
     135        4253 :     sal_uInt16                  nId( 0 );
     136        4253 :     bool                bMasterCommand( false );
     137        4253 :     Reference < XDispatch > xDisp;
     138        4253 :     const SfxSlot* pSlot = 0;
     139        4253 :     SfxDispatcher* pAppDisp = SfxGetpApp()->GetAppDispatcher_Impl();
     140        4253 :     if ( aURL.Protocol == "slot:" || aURL.Protocol == "commandId:" )
     141             :     {
     142           0 :         nId = (sal_uInt16) aURL.Path.toInt32();
     143             :         SfxShell* pShell;
     144           0 :         pAppDisp->GetShellAndSlot_Impl( nId, &pShell, &pSlot, true, true );
     145             :     }
     146        4253 :     else if ( aURL.Protocol == ".uno:" )
     147             :     {
     148             :         // Support ".uno" commands. Map commands to slotid
     149        4253 :         bMasterCommand = SfxOfficeDispatch::IsMasterUnoCommand( aURL );
     150        4253 :         if ( bMasterCommand )
     151           0 :             pSlot = pAppDisp->GetSlot( SfxOfficeDispatch::GetMasterUnoCommand( aURL ) );
     152             :         else
     153        4253 :             pSlot = pAppDisp->GetSlot( aURL.Main );
     154             :     }
     155             : 
     156        4253 :     if ( pSlot )
     157             :     {
     158          73 :         SfxOfficeDispatch* pDispatch = new SfxOfficeDispatch( pAppDisp, pSlot, aURL ) ;
     159          73 :         pDispatch->SetFrame(m_xFrame);
     160          73 :         pDispatch->SetMasterUnoCommand( bMasterCommand );
     161          73 :         xDisp = pDispatch;
     162             :     }
     163             : 
     164        4253 :     return xDisp;
     165             : }
     166             : 
     167           1 : Sequence< Reference < XDispatch > > SAL_CALL SfxAppDispatchProvider::queryDispatches( const Sequence < DispatchDescriptor >& seqDescriptor )
     168             : throw( RuntimeException, std::exception )
     169             : {
     170           1 :     sal_Int32 nCount = seqDescriptor.getLength();
     171           1 :     uno::Sequence< uno::Reference < frame::XDispatch > > lDispatcher(nCount);
     172           3 :     for( sal_Int32 i=0; i<nCount; ++i )
     173           6 :         lDispatcher[i] = this->queryDispatch( seqDescriptor[i].FeatureURL,
     174           2 :                                               seqDescriptor[i].FrameName,
     175           4 :                                               seqDescriptor[i].SearchFlags );
     176           1 :     return lDispatcher;
     177             : }
     178             : 
     179           0 : Sequence< sal_Int16 > SAL_CALL SfxAppDispatchProvider::getSupportedCommandGroups()
     180             : throw (uno::RuntimeException, std::exception)
     181             : {
     182           0 :     SolarMutexGuard aGuard;
     183             : 
     184           0 :     std::list< sal_Int16 > aGroupList;
     185           0 :     SfxSlotPool* pAppSlotPool = &SfxGetpApp()->GetAppSlotPool_Impl();
     186             : 
     187           0 :     const SfxSlotMode nMode( SfxSlotMode::TOOLBOXCONFIG|SfxSlotMode::ACCELCONFIG|SfxSlotMode::MENUCONFIG );
     188             : 
     189             :     // Gruppe anw"ahlen ( Gruppe 0 ist intern )
     190           0 :     for ( sal_uInt16 i=0; i<pAppSlotPool->GetGroupCount(); i++ )
     191             :     {
     192           0 :         pAppSlotPool->SeekGroup( i );
     193           0 :         const SfxSlot* pSfxSlot = pAppSlotPool->FirstSlot();
     194           0 :         while ( pSfxSlot )
     195             :         {
     196           0 :             if ( pSfxSlot->GetMode() & nMode )
     197             :             {
     198           0 :                 sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
     199           0 :                 aGroupList.push_back( nCommandGroup );
     200           0 :                 break;
     201             :             }
     202           0 :             pSfxSlot = pAppSlotPool->NextSlot();
     203             :         }
     204             :     }
     205             : 
     206             :     uno::Sequence< sal_Int16 > aSeq =
     207           0 :         comphelper::containerToSequence< sal_Int16, std::list< sal_Int16 > >( aGroupList );
     208             : 
     209           0 :     return aSeq;
     210             : }
     211             : 
     212           0 : Sequence< frame::DispatchInformation > SAL_CALL SfxAppDispatchProvider::getConfigurableDispatchInformation( sal_Int16 nCmdGroup )
     213             : throw (uno::RuntimeException, std::exception)
     214             : {
     215           0 :     std::list< frame::DispatchInformation > aCmdList;
     216             : 
     217           0 :     SolarMutexGuard aGuard;
     218           0 :     SfxSlotPool* pAppSlotPool = &SfxGetpApp()->GetAppSlotPool_Impl();
     219             : 
     220           0 :     if ( pAppSlotPool )
     221             :     {
     222           0 :         const SfxSlotMode nMode( SfxSlotMode::TOOLBOXCONFIG|SfxSlotMode::ACCELCONFIG|SfxSlotMode::MENUCONFIG );
     223           0 :         OUString aCmdPrefix( ".uno:" );
     224             : 
     225             :         // Gruppe anw"ahlen ( Gruppe 0 ist intern )
     226           0 :         for ( sal_uInt16 i=0; i<pAppSlotPool->GetGroupCount(); i++ )
     227             :         {
     228           0 :             pAppSlotPool->SeekGroup( i );
     229           0 :             const SfxSlot* pSfxSlot = pAppSlotPool->FirstSlot();
     230           0 :             if ( pSfxSlot )
     231             :             {
     232           0 :                 sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
     233           0 :                 if ( nCommandGroup == nCmdGroup )
     234             :                 {
     235           0 :                     while ( pSfxSlot )
     236             :                     {
     237           0 :                         if ( pSfxSlot->GetMode() & nMode )
     238             :                         {
     239           0 :                             frame::DispatchInformation aCmdInfo;
     240           0 :                             OUStringBuffer aBuf( aCmdPrefix );
     241           0 :                             aBuf.appendAscii( pSfxSlot->GetUnoName() );
     242           0 :                             aCmdInfo.Command = aBuf.makeStringAndClear();
     243           0 :                             aCmdInfo.GroupId = nCommandGroup;
     244           0 :                             aCmdList.push_back( aCmdInfo );
     245             :                         }
     246           0 :                         pSfxSlot = pAppSlotPool->NextSlot();
     247             :                     }
     248             :                 }
     249             :             }
     250           0 :         }
     251             :     }
     252             : 
     253             :     uno::Sequence< frame::DispatchInformation > aSeq =
     254           0 :         comphelper::containerToSequence< frame::DispatchInformation, std::list< frame::DispatchInformation > >( aCmdList );
     255             : 
     256           0 :     return aSeq;
     257             : }
     258             : 
     259             : }
     260             : 
     261             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     262        4253 : com_sun_star_comp_sfx2_AppDispatchProvider_get_implementation(
     263             :     css::uno::XComponentContext *,
     264             :     css::uno::Sequence<css::uno::Any> const &)
     265             : {
     266        4253 :     return cppu::acquire(new SfxAppDispatchProvider);
     267         648 : }
     268             : 
     269             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11