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

Generated by: LCOV version 1.10