LCOV - code coverage report
Current view: top level - libreoffice/framework/source/dispatch - dispatchinformationprovider.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 73 9.6 %
Date: 2012-12-27 Functions: 6 9 66.7 %
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 <dispatch/dispatchinformationprovider.hxx>
      21             : #include <dispatch/closedispatcher.hxx>
      22             : #include <threadhelp/readguard.hxx>
      23             : #include <threadhelp/writeguard.hxx>
      24             : #include <stdtypes.h>
      25             : #include <services.h>
      26             : 
      27             : #include <com/sun/star/frame/CommandGroup.hpp>
      28             : 
      29             : #include <comphelper/sequenceasvector.hxx>
      30             : 
      31             : namespace framework{
      32             : 
      33        1023 : DEFINE_XINTERFACE_1(DispatchInformationProvider                               ,
      34             :                     OWeakObject                                               ,
      35             :                     DIRECT_INTERFACE(css::frame::XDispatchInformationProvider))
      36             : 
      37             : //_________________________________________________________________________________________________________________
      38         240 : DispatchInformationProvider::DispatchInformationProvider(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
      39             :                                                          const css::uno::Reference< css::frame::XFrame >&              xFrame)
      40         240 :     : ThreadHelpBase(&Application::GetSolarMutex())
      41             :     , m_xSMGR       (xSMGR                        )
      42         480 :     , m_xFrame      (xFrame                       )
      43             : {
      44         240 : }
      45             : 
      46             : //_________________________________________________________________________________________________________________
      47         126 : DispatchInformationProvider::~DispatchInformationProvider()
      48             : {
      49         126 : }
      50             : 
      51             : //_________________________________________________________________________________________________________________
      52           0 : css::uno::Sequence< sal_Int16 > SAL_CALL DispatchInformationProvider::getSupportedCommandGroups()
      53             :     throw (css::uno::RuntimeException)
      54             : {
      55           0 :     css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
      56           0 :     sal_Int32                                                                             c1        = lProvider.getLength();
      57           0 :     sal_Int32                                                                             i1        = 0;
      58             : 
      59           0 :     ::comphelper::SequenceAsVector< sal_Int16 > lGroups;
      60             : 
      61           0 :     for (i1=0; i1<c1; ++i1)
      62             :     {
      63             :         // ignore controller, which doesnt implement the right interface
      64           0 :         css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider = lProvider[i1];
      65           0 :         if (!xProvider.is())
      66           0 :             continue;
      67             : 
      68           0 :         const css::uno::Sequence< sal_Int16 > lProviderGroups = xProvider->getSupportedCommandGroups();
      69           0 :               sal_Int32                       c2              = lProviderGroups.getLength();
      70           0 :               sal_Int32                       i2              = 0;
      71           0 :         for (i2=0; i2<c2; ++i2)
      72             :         {
      73           0 :             const sal_Int16&                                                  rGroup = lProviderGroups[i2];
      74           0 :                   ::comphelper::SequenceAsVector< sal_Int16 >::const_iterator pGroup = ::std::find(lGroups.begin(), lGroups.end(), rGroup);
      75           0 :             if (pGroup == lGroups.end())
      76           0 :                 lGroups.push_back(rGroup);
      77             :         }
      78           0 :     }
      79             : 
      80           0 :     return lGroups.getAsConstList();
      81             : }
      82             : 
      83             : //_________________________________________________________________________________________________________________
      84           0 : css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL DispatchInformationProvider::getConfigurableDispatchInformation(sal_Int16 nCommandGroup)
      85             :     throw (css::uno::RuntimeException)
      86             : {
      87           0 :     css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
      88           0 :     sal_Int32                                                                             c1        = lProvider.getLength();
      89           0 :     sal_Int32                                                                             i1        = 0;
      90             : 
      91           0 :     BaseHash< css::frame::DispatchInformation > lInfos;
      92             : 
      93           0 :     for (i1=0; i1<c1; ++i1)
      94             :     {
      95             :         try
      96             :         {
      97             :             // ignore controller, which doesnt implement the right interface
      98           0 :             css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider = lProvider[i1];
      99           0 :             if (!xProvider.is())
     100           0 :                 continue;
     101             : 
     102           0 :             const css::uno::Sequence< css::frame::DispatchInformation > lProviderInfos = xProvider->getConfigurableDispatchInformation(nCommandGroup);
     103           0 :                   sal_Int32                                             c2             = lProviderInfos.getLength();
     104           0 :                   sal_Int32                                             i2             = 0;
     105           0 :             for (i2=0; i2<c2; ++i2)
     106             :             {
     107           0 :                 const css::frame::DispatchInformation&                            rInfo = lProviderInfos[i2];
     108           0 :                       BaseHash< css::frame::DispatchInformation >::const_iterator pInfo = lInfos.find(rInfo.Command);
     109           0 :                 if (pInfo == lInfos.end())
     110           0 :                     lInfos[rInfo.Command] = rInfo;
     111           0 :             }
     112             :         }
     113           0 :         catch(const css::uno::RuntimeException&)
     114           0 :             { throw; }
     115           0 :         catch(const css::uno::Exception&)
     116           0 :             { continue; }
     117             :     }
     118             : 
     119           0 :     c1 = (sal_Int32)lInfos.size();
     120           0 :     i1 = 0;
     121             : 
     122           0 :     css::uno::Sequence< css::frame::DispatchInformation >       lReturn(c1);
     123           0 :     BaseHash< css::frame::DispatchInformation >::const_iterator pStepp ;
     124           0 :     for (  pStepp  = lInfos.begin()          ;
     125           0 :            pStepp != lInfos.end  () && i1<c1 ;
     126             :          ++pStepp, ++i1                      )
     127             :     {
     128           0 :         lReturn[i1] = pStepp->second;
     129             :     }
     130           0 :     return lReturn;
     131             : }
     132             : 
     133             : //_________________________________________________________________________________________________________________
     134           0 : css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > DispatchInformationProvider::implts_getAllSubProvider()
     135             : {
     136             :     // SAFE -> ----------------------------------
     137           0 :     ReadGuard aReadLock(m_aLock);
     138           0 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
     139           0 :     css::uno::Reference< css::frame::XFrame >              xFrame(m_xFrame.get(), css::uno::UNO_QUERY);
     140           0 :     aReadLock.unlock();
     141             :     // <- SAFE ----------------------------------
     142             : 
     143           0 :     if (!xFrame.is())
     144           0 :         return css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > >();
     145             : 
     146           0 :     CloseDispatcher* pCloser = new CloseDispatcher(xSMGR, xFrame, ::rtl::OUString("_self")); // explicit "_self" ... not "" ... see implementation of close dispatcher itself!
     147           0 :     css::uno::Reference< css::uno::XInterface > xCloser(static_cast< css::frame::XDispatch* >(pCloser), css::uno::UNO_QUERY);
     148             : 
     149           0 :     css::uno::Reference< css::frame::XDispatchInformationProvider > xCloseDispatch(xCloser                                                      , css::uno::UNO_QUERY);
     150           0 :     css::uno::Reference< css::frame::XDispatchInformationProvider > xController   (xFrame->getController()                                      , css::uno::UNO_QUERY);
     151           0 :     css::uno::Reference< css::frame::XDispatchInformationProvider > xAppDispatcher(xSMGR->createInstance(IMPLEMENTATIONNAME_APPDISPATCHPROVIDER), css::uno::UNO_QUERY);
     152             : 
     153           0 :     css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider(3);
     154           0 :     lProvider[0] = xController   ;
     155           0 :     lProvider[1] = xCloseDispatch;
     156           0 :     lProvider[2] = xAppDispatcher;
     157             : 
     158           0 :     return lProvider;
     159             : }
     160             : 
     161             : } // namespace framework
     162             : 
     163             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10