LCOV - code coverage report
Current view: top level - framework/source/dispatch - dispatchinformationprovider.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 6 69 8.7 %
Date: 2014-11-03 Functions: 5 8 62.5 %
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 <stdtypes.h>
      23             : #include <services.h>
      24             : 
      25             : #include <com/sun/star/frame/CommandGroup.hpp>
      26             : #include <com/sun/star/frame/AppDispatchProvider.hpp>
      27             : 
      28             : #include <comphelper/sequenceasvector.hxx>
      29             : 
      30             : namespace framework{
      31             : 
      32        5574 : DispatchInformationProvider::DispatchInformationProvider(const css::uno::Reference< css::uno::XComponentContext >& xContext ,
      33             :                                                          const css::uno::Reference< css::frame::XFrame >&          xFrame)
      34             :     : m_xContext    (xContext                     )
      35        5574 :     , m_xFrame      (xFrame                       )
      36             : {
      37        5574 : }
      38             : 
      39       11056 : DispatchInformationProvider::~DispatchInformationProvider()
      40             : {
      41       11056 : }
      42             : 
      43           0 : css::uno::Sequence< sal_Int16 > SAL_CALL DispatchInformationProvider::getSupportedCommandGroups()
      44             :     throw (css::uno::RuntimeException, std::exception)
      45             : {
      46           0 :     css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
      47           0 :     sal_Int32                                                                             c1        = lProvider.getLength();
      48           0 :     sal_Int32                                                                             i1        = 0;
      49             : 
      50           0 :     ::comphelper::SequenceAsVector< sal_Int16 > lGroups;
      51             : 
      52           0 :     for (i1=0; i1<c1; ++i1)
      53             :     {
      54             :         // ignore controller, which doesn't implement the right interface
      55           0 :         css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider = lProvider[i1];
      56           0 :         if (!xProvider.is())
      57           0 :             continue;
      58             : 
      59           0 :         const css::uno::Sequence< sal_Int16 > lProviderGroups = xProvider->getSupportedCommandGroups();
      60           0 :               sal_Int32                       c2              = lProviderGroups.getLength();
      61           0 :               sal_Int32                       i2              = 0;
      62           0 :         for (i2=0; i2<c2; ++i2)
      63             :         {
      64           0 :             const sal_Int16&                                                  rGroup = lProviderGroups[i2];
      65           0 :                   ::comphelper::SequenceAsVector< sal_Int16 >::const_iterator pGroup = ::std::find(lGroups.begin(), lGroups.end(), rGroup);
      66           0 :             if (pGroup == lGroups.end())
      67           0 :                 lGroups.push_back(rGroup);
      68             :         }
      69           0 :     }
      70             : 
      71           0 :     return lGroups.getAsConstList();
      72             : }
      73             : 
      74           0 : css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL DispatchInformationProvider::getConfigurableDispatchInformation(sal_Int16 nCommandGroup)
      75             :     throw (css::uno::RuntimeException, std::exception)
      76             : {
      77           0 :     css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
      78           0 :     sal_Int32                                                                             c1        = lProvider.getLength();
      79           0 :     sal_Int32                                                                             i1        = 0;
      80             : 
      81           0 :     BaseHash< css::frame::DispatchInformation > lInfos;
      82             : 
      83           0 :     for (i1=0; i1<c1; ++i1)
      84             :     {
      85             :         try
      86             :         {
      87             :             // ignore controller, which doesn't implement the right interface
      88           0 :             css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider = lProvider[i1];
      89           0 :             if (!xProvider.is())
      90           0 :                 continue;
      91             : 
      92           0 :             const css::uno::Sequence< css::frame::DispatchInformation > lProviderInfos = xProvider->getConfigurableDispatchInformation(nCommandGroup);
      93           0 :                   sal_Int32                                             c2             = lProviderInfos.getLength();
      94           0 :                   sal_Int32                                             i2             = 0;
      95           0 :             for (i2=0; i2<c2; ++i2)
      96             :             {
      97           0 :                 const css::frame::DispatchInformation&                            rInfo = lProviderInfos[i2];
      98           0 :                       BaseHash< css::frame::DispatchInformation >::const_iterator pInfo = lInfos.find(rInfo.Command);
      99           0 :                 if (pInfo == lInfos.end())
     100           0 :                     lInfos[rInfo.Command] = rInfo;
     101           0 :             }
     102             :         }
     103           0 :         catch(const css::uno::RuntimeException&)
     104           0 :             { throw; }
     105           0 :         catch(const css::uno::Exception&)
     106           0 :             { continue; }
     107             :     }
     108             : 
     109           0 :     c1 = (sal_Int32)lInfos.size();
     110           0 :     i1 = 0;
     111             : 
     112           0 :     css::uno::Sequence< css::frame::DispatchInformation >       lReturn(c1);
     113           0 :     BaseHash< css::frame::DispatchInformation >::const_iterator pStepp;
     114           0 :     for (  pStepp  = lInfos.begin();
     115           0 :            pStepp != lInfos.end  () && i1<c1;
     116             :          ++pStepp, ++i1                      )
     117             :     {
     118           0 :         lReturn[i1] = pStepp->second;
     119             :     }
     120           0 :     return lReturn;
     121             : }
     122             : 
     123           0 : css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > DispatchInformationProvider::implts_getAllSubProvider()
     124             : {
     125           0 :     css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame);
     126           0 :     if (!xFrame.is())
     127           0 :         return css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > >();
     128             : 
     129           0 :     CloseDispatcher* pCloser = new CloseDispatcher(m_xContext, xFrame, OUString("_self")); // explicit "_self" ... not "" ... see implementation of close dispatcher itself!
     130           0 :     css::uno::Reference< css::uno::XInterface > xCloser(static_cast< css::frame::XDispatch* >(pCloser), css::uno::UNO_QUERY);
     131             : 
     132           0 :     css::uno::Reference< css::frame::XDispatchInformationProvider > xCloseDispatch(xCloser                                                      , css::uno::UNO_QUERY);
     133           0 :     css::uno::Reference< css::frame::XDispatchInformationProvider > xController   (xFrame->getController()                                      , css::uno::UNO_QUERY);
     134           0 :     css::uno::Reference< css::frame::XDispatchInformationProvider > xAppDispatcher = css::frame::AppDispatchProvider::create(m_xContext);
     135           0 :     css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider(3);
     136           0 :     lProvider[0] = xController;
     137           0 :     lProvider[1] = xCloseDispatch;
     138           0 :     lProvider[2] = xAppDispatcher;
     139             : 
     140           0 :     return lProvider;
     141             : }
     142             : 
     143         951 : } // namespace framework
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10