LCOV - code coverage report
Current view: top level - forms/source/helper - commanddescriptionprovider.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 25 84.0 %
Date: 2012-08-25 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 20 44 45.5 %

           Branch data     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                 :            : 
      21                 :            : #include "commanddescriptionprovider.hxx"
      22                 :            : 
      23                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      24                 :            : #include <com/sun/star/frame/XModuleManager.hpp>
      25                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      26                 :            : 
      27                 :            : #include <comphelper/namedvaluecollection.hxx>
      28                 :            : #include <tools/diagnose_ex.h>
      29                 :            : 
      30                 :            : //........................................................................
      31                 :            : namespace frm
      32                 :            : {
      33                 :            : //........................................................................
      34                 :            : 
      35                 :            :     /** === begin UNO using === **/
      36                 :            :     using ::com::sun::star::uno::Reference;
      37                 :            :     using ::com::sun::star::uno::XInterface;
      38                 :            :     using ::com::sun::star::uno::UNO_QUERY;
      39                 :            :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      40                 :            :     using ::com::sun::star::uno::UNO_SET_THROW;
      41                 :            :     using ::com::sun::star::uno::Exception;
      42                 :            :     using ::com::sun::star::uno::RuntimeException;
      43                 :            :     using ::com::sun::star::uno::Any;
      44                 :            :     using ::com::sun::star::uno::makeAny;
      45                 :            :     using ::com::sun::star::uno::Sequence;
      46                 :            :     using ::com::sun::star::uno::Type;
      47                 :            :     using ::com::sun::star::frame::XModel;
      48                 :            :     using ::com::sun::star::container::XNameAccess;
      49                 :            :     using ::com::sun::star::frame::XModuleManager;
      50                 :            :     using ::com::sun::star::beans::PropertyValue;
      51                 :            :     /** === end UNO using === **/
      52                 :            : 
      53                 :            :     //====================================================================
      54                 :            :     //= DefaultCommandDescriptionProvider
      55                 :            :     //====================================================================
      56                 :            :     class DefaultCommandDescriptionProvider : public ICommandDescriptionProvider
      57                 :            :     {
      58                 :            :     public:
      59                 :         36 :         DefaultCommandDescriptionProvider( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
      60                 :         36 :         {
      61         [ +  - ]:         36 :             impl_init_nothrow( _rContext, _rxDocument );
      62                 :         36 :         }
      63                 :            : 
      64                 :         72 :         ~DefaultCommandDescriptionProvider()
      65                 :         36 :         {
      66         [ -  + ]:         72 :         }
      67                 :            : 
      68                 :            :         // ICommandDescriptionProvider
      69                 :            :         virtual ::rtl::OUString getCommandDescription( const ::rtl::OUString& _rCommandURL ) const;
      70                 :            : 
      71                 :            :     private:
      72                 :            :         void    impl_init_nothrow( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument );
      73                 :            : 
      74                 :            :     private:
      75                 :            :         Reference< XNameAccess >    m_xCommandAccess;
      76                 :            :     };
      77                 :            : 
      78                 :            : 
      79                 :            :     //--------------------------------------------------------------------
      80                 :         36 :     void DefaultCommandDescriptionProvider::impl_init_nothrow( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
      81                 :            :     {
      82                 :            :         OSL_ENSURE( _rxDocument.is(), "DefaultCommandDescriptionProvider::impl_init_nothrow: no document => no command descriptions!" );
      83         [ -  + ]:         36 :         if ( !_rxDocument.is() )
      84                 :         36 :             return;
      85                 :            : 
      86                 :            :         try
      87                 :            :         {
      88 [ +  - ][ +  - ]:         36 :             Reference< XModuleManager > xModuleManager( _rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW );
      89 [ +  - ][ +  - ]:         36 :             ::rtl::OUString sModuleID = xModuleManager->identify( _rxDocument );
      90                 :            : 
      91 [ +  - ][ +  - ]:         36 :             Reference< XNameAccess > xUICommandDescriptions( _rContext.createComponent( "com.sun.star.frame.UICommandDescription" ), UNO_QUERY_THROW );
      92 [ +  - ][ +  - ]:         36 :             m_xCommandAccess.set( xUICommandDescriptions->getByName( sModuleID ), UNO_QUERY_THROW );
         [ #  # ][ +  - ]
      93                 :            :         }
      94                 :          0 :         catch( const Exception& )
      95                 :            :         {
      96                 :            :             DBG_UNHANDLED_EXCEPTION();
      97                 :            :         }
      98                 :            :     }
      99                 :            : 
     100                 :            :     //--------------------------------------------------------------------
     101                 :        684 :     ::rtl::OUString DefaultCommandDescriptionProvider::getCommandDescription( const ::rtl::OUString& _rCommandURL ) const
     102                 :            :     {
     103         [ -  + ]:        684 :         if ( !m_xCommandAccess.is() )
     104                 :          0 :             return ::rtl::OUString();
     105                 :            : 
     106                 :            :         try
     107                 :            :         {
     108 [ +  - ][ +  - ]:        684 :             ::comphelper::NamedValueCollection aCommandProperties( m_xCommandAccess->getByName( _rCommandURL ) );
                 [ +  - ]
     109 [ +  - ][ #  # ]:        684 :             return aCommandProperties.getOrDefault( "Name", ::rtl::OUString() );
                 [ +  - ]
     110                 :            :         }
     111                 :          0 :         catch( const Exception& )
     112                 :            :         {
     113                 :            :             DBG_UNHANDLED_EXCEPTION();
     114                 :            :         }
     115                 :            : 
     116                 :          0 :         return ::rtl::OUString();
     117                 :            :     }
     118                 :            : 
     119                 :            :     //--------------------------------------------------------------------
     120                 :         36 :     PCommandDescriptionProvider createDocumentCommandDescriptionProvider(
     121                 :            :         const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
     122                 :            :     {
     123 [ +  - ][ +  - ]:         36 :         PCommandDescriptionProvider pDescriptionProvider( new DefaultCommandDescriptionProvider( _rContext, _rxDocument ) );
     124                 :         36 :         return pDescriptionProvider;
     125                 :            :     }
     126                 :            : 
     127                 :            : //........................................................................
     128                 :            : } // namespace frm
     129                 :            : //........................................................................
     130                 :            : 
     131                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10