LCOV - code coverage report
Current view: top level - forms/source/helper - commandimageprovider.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 42 0.0 %
Date: 2014-04-14 Functions: 0 6 0.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             : 
      21             : #include "commandimageprovider.hxx"
      22             : 
      23             : #include <com/sun/star/ui/XImageManager.hpp>
      24             : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
      25             : #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
      26             : #include <com/sun/star/frame/ModuleManager.hpp>
      27             : #include <com/sun/star/ui/ImageType.hpp>
      28             : 
      29             : #include <tools/diagnose_ex.h>
      30             : 
      31             : 
      32             : namespace frm
      33             : {
      34             : 
      35             : 
      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::uno::XComponentContext;
      48             :     using ::com::sun::star::frame::XModel;
      49             :     using ::com::sun::star::ui::XImageManager;
      50             :     using ::com::sun::star::ui::XUIConfigurationManagerSupplier;
      51             :     using ::com::sun::star::ui::XUIConfigurationManager;
      52             :     using ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier;
      53             :     using ::com::sun::star::ui::theModuleUIConfigurationManagerSupplier;
      54             :     using ::com::sun::star::frame::ModuleManager;
      55             :     using ::com::sun::star::frame::XModuleManager2;
      56             :     using ::com::sun::star::graphic::XGraphic;
      57             : 
      58             :     namespace ImageType = ::com::sun::star::ui::ImageType;
      59             : 
      60             : 
      61             :     //= DocumentCommandImageProvider
      62             : 
      63             :     class DocumentCommandImageProvider : public ICommandImageProvider
      64             :     {
      65             :     public:
      66           0 :         DocumentCommandImageProvider( const Reference<XComponentContext>& _rContext, const Reference< XModel >& _rxDocument )
      67           0 :         {
      68           0 :             impl_init_nothrow( _rContext, _rxDocument );
      69           0 :         }
      70           0 :         virtual ~DocumentCommandImageProvider()
      71           0 :         {
      72           0 :         }
      73             : 
      74             :         // ICommandImageProvider
      75             :         virtual CommandImages getCommandImages( const CommandURLs& _rCommandURLs, const bool _bLarge ) const SAL_OVERRIDE;
      76             : 
      77             :     private:
      78             :         void    impl_init_nothrow( const Reference<XComponentContext>& _rContext, const Reference< XModel >& _rxDocument );
      79             : 
      80             :     private:
      81             :         Reference< XImageManager >    m_xDocumentImageManager;
      82             :         Reference< XImageManager >    m_xModuleImageManager;
      83             :     };
      84             : 
      85             : 
      86           0 :     void DocumentCommandImageProvider::impl_init_nothrow( const Reference<XComponentContext>& _rContext, const Reference< XModel >& _rxDocument )
      87             :     {
      88             :         OSL_ENSURE( _rxDocument.is(), "DocumentCommandImageProvider::impl_init_nothrow: no document => no images!" );
      89           0 :         if ( !_rxDocument.is() )
      90           0 :             return;
      91             : 
      92             :         // obtain the image manager of the document
      93             :         try
      94             :         {
      95           0 :             Reference< XUIConfigurationManagerSupplier > xSuppUIConfig( _rxDocument, UNO_QUERY_THROW );
      96           0 :             Reference< XUIConfigurationManager > xUIConfig( xSuppUIConfig->getUIConfigurationManager(), UNO_QUERY );
      97           0 :             m_xDocumentImageManager.set( xUIConfig->getImageManager(), UNO_QUERY_THROW );
      98             :         }
      99           0 :         catch( const Exception& )
     100             :         {
     101             :             DBG_UNHANDLED_EXCEPTION();
     102             :         }
     103             : 
     104             :         // obtain the image manager or the module
     105             :         try
     106             :         {
     107           0 :             Reference< XModuleManager2 > xModuleManager( ModuleManager::create(_rContext) );
     108           0 :             OUString sModuleID = xModuleManager->identify( _rxDocument );
     109             : 
     110             :             Reference< XModuleUIConfigurationManagerSupplier > xSuppUIConfig(
     111           0 :                 theModuleUIConfigurationManagerSupplier::get(_rContext) );
     112             :             Reference< XUIConfigurationManager > xUIConfig(
     113           0 :                 xSuppUIConfig->getUIConfigurationManager( sModuleID ), UNO_SET_THROW );
     114           0 :             m_xModuleImageManager.set( xUIConfig->getImageManager(), UNO_QUERY_THROW );
     115             :         }
     116           0 :         catch( const Exception& )
     117             :         {
     118             :             DBG_UNHANDLED_EXCEPTION();
     119             :         }
     120             :     }
     121             : 
     122             : 
     123           0 :     CommandImages DocumentCommandImageProvider::getCommandImages( const CommandURLs& _rCommandURLs, const bool _bLarge ) const
     124             :     {
     125           0 :         const size_t nCommandCount = _rCommandURLs.getLength();
     126           0 :         CommandImages aImages( nCommandCount );
     127             :         try
     128             :         {
     129             :             const sal_Int16 nImageType = ImageType::COLOR_NORMAL
     130           0 :                                        +  ( _bLarge ? ImageType::SIZE_LARGE : ImageType::SIZE_DEFAULT );
     131             : 
     132           0 :             Sequence< Reference< XGraphic > > aDocImages( nCommandCount );
     133           0 :             Sequence< Reference< XGraphic > > aModImages( nCommandCount );
     134             : 
     135             :             // first try the document image manager
     136           0 :             if ( m_xDocumentImageManager.is() )
     137           0 :                 aDocImages = m_xDocumentImageManager->getImages( nImageType, _rCommandURLs );
     138             : 
     139             :             // then the module's image manager
     140           0 :             if ( m_xModuleImageManager.is() )
     141           0 :                 aModImages = m_xModuleImageManager->getImages( nImageType, _rCommandURLs );
     142             : 
     143           0 :             ENSURE_OR_THROW( (size_t)aDocImages.getLength() == nCommandCount, "illegal array size returned by getImages (document image manager)" );
     144           0 :             ENSURE_OR_THROW( (size_t)aModImages.getLength() == nCommandCount, "illegal array size returned by getImages (module image manager)" );
     145             : 
     146           0 :             for ( size_t i=0; i<nCommandCount; ++i )
     147             :             {
     148           0 :                 if ( aDocImages[i].is() )
     149           0 :                     aImages[i] = Image( aDocImages[i] );
     150             :                 else
     151           0 :                     aImages[i] = Image( aModImages[i] );
     152           0 :             }
     153             :         }
     154           0 :         catch( const Exception& )
     155             :         {
     156             :             DBG_UNHANDLED_EXCEPTION();
     157             :         }
     158           0 :         return aImages;
     159             :     }
     160             : 
     161             : 
     162           0 :     PCommandImageProvider createDocumentCommandImageProvider(
     163             :         const Reference<XComponentContext>& _rContext, const Reference< XModel >& _rxDocument )
     164             :     {
     165           0 :         PCommandImageProvider pImageProvider( new DocumentCommandImageProvider( _rContext, _rxDocument ) );
     166           0 :         return pImageProvider;
     167             :     }
     168             : 
     169             : 
     170             : } // namespace frm
     171             : 
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10