LCOV - code coverage report
Current view: top level - framework/source/dispatch - dispatchinformationprovider.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 5 68 7.4 %
Date: 2015-06-13 12:38:46 Functions: 3 6 50.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 <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/sequence.hxx>
      29             : 
      30             : namespace framework{
      31             : 
      32        3283 : DispatchInformationProvider::DispatchInformationProvider(const css::uno::Reference< css::uno::XComponentContext >& xContext ,
      33             :                                                          const css::uno::Reference< css::frame::XFrame >&          xFrame)
      34             :     : m_xContext    (xContext                     )
      35        3283 :     , m_xFrame      (xFrame                       )
      36             : {
      37        3283 : }
      38             : 
      39        5512 : DispatchInformationProvider::~DispatchInformationProvider()
      40             : {
      41        5512 : }
      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 :     ::std::vector< 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             :                   ::std::vector< sal_Int16 >::const_iterator pGroup =
      66           0 :                             ::std::find(lGroups.begin(), lGroups.end(), rGroup);
      67           0 :             if (pGroup == lGroups.end())
      68           0 :                 lGroups.push_back(rGroup);
      69             :         }
      70           0 :     }
      71             : 
      72           0 :     return ::comphelper::containerToSequence(lGroups);
      73             : }
      74             : 
      75           0 : css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL DispatchInformationProvider::getConfigurableDispatchInformation(sal_Int16 nCommandGroup)
      76             :     throw (css::uno::RuntimeException, std::exception)
      77             : {
      78           0 :     css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider = implts_getAllSubProvider();
      79           0 :     sal_Int32                                                                             c1        = lProvider.getLength();
      80           0 :     sal_Int32                                                                             i1        = 0;
      81             : 
      82           0 :     BaseHash< css::frame::DispatchInformation > lInfos;
      83             : 
      84           0 :     for (i1=0; i1<c1; ++i1)
      85             :     {
      86             :         try
      87             :         {
      88             :             // ignore controller, which doesn't implement the right interface
      89           0 :             css::uno::Reference< css::frame::XDispatchInformationProvider > xProvider = lProvider[i1];
      90           0 :             if (!xProvider.is())
      91           0 :                 continue;
      92             : 
      93           0 :             const css::uno::Sequence< css::frame::DispatchInformation > lProviderInfos = xProvider->getConfigurableDispatchInformation(nCommandGroup);
      94           0 :                   sal_Int32                                             c2             = lProviderInfos.getLength();
      95           0 :                   sal_Int32                                             i2             = 0;
      96           0 :             for (i2=0; i2<c2; ++i2)
      97             :             {
      98           0 :                 const css::frame::DispatchInformation&                            rInfo = lProviderInfos[i2];
      99           0 :                       BaseHash< css::frame::DispatchInformation >::const_iterator pInfo = lInfos.find(rInfo.Command);
     100           0 :                 if (pInfo == lInfos.end())
     101           0 :                     lInfos[rInfo.Command] = rInfo;
     102           0 :             }
     103             :         }
     104           0 :         catch(const css::uno::RuntimeException&)
     105           0 :             { throw; }
     106           0 :         catch(const css::uno::Exception&)
     107           0 :             { continue; }
     108             :     }
     109             : 
     110           0 :     c1 = (sal_Int32)lInfos.size();
     111           0 :     i1 = 0;
     112             : 
     113           0 :     css::uno::Sequence< css::frame::DispatchInformation >       lReturn(c1);
     114           0 :     BaseHash< css::frame::DispatchInformation >::const_iterator pStepp;
     115           0 :     for (  pStepp  = lInfos.begin();
     116           0 :            pStepp != lInfos.end  () && i1<c1;
     117             :          ++pStepp, ++i1                      )
     118             :     {
     119           0 :         lReturn[i1] = pStepp->second;
     120             :     }
     121           0 :     return lReturn;
     122             : }
     123             : 
     124           0 : css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > DispatchInformationProvider::implts_getAllSubProvider()
     125             : {
     126           0 :     css::uno::Reference< css::frame::XFrame > xFrame(m_xFrame);
     127           0 :     if (!xFrame.is())
     128           0 :         return css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > >();
     129             : 
     130           0 :     CloseDispatcher* pCloser = new CloseDispatcher(m_xContext, xFrame, OUString("_self")); // explicit "_self" ... not "" ... see implementation of close dispatcher itself!
     131           0 :     css::uno::Reference< css::uno::XInterface > xCloser(static_cast< css::frame::XDispatch* >(pCloser), css::uno::UNO_QUERY);
     132             : 
     133           0 :     css::uno::Reference< css::frame::XDispatchInformationProvider > xCloseDispatch(xCloser                                                      , css::uno::UNO_QUERY);
     134           0 :     css::uno::Reference< css::frame::XDispatchInformationProvider > xController   (xFrame->getController()                                      , css::uno::UNO_QUERY);
     135           0 :     css::uno::Reference< css::frame::XDispatchInformationProvider > xAppDispatcher = css::frame::AppDispatchProvider::create(m_xContext);
     136           0 :     css::uno::Sequence< css::uno::Reference< css::frame::XDispatchInformationProvider > > lProvider(3);
     137           0 :     lProvider[0] = xController;
     138           0 :     lProvider[1] = xCloseDispatch;
     139           0 :     lProvider[2] = xAppDispatcher;
     140             : 
     141           0 :     return lProvider;
     142             : }
     143             : 
     144             : } // namespace framework
     145             : 
     146             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11