LCOV - code coverage report
Current view: top level - sfx2/source/appl - imagemgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 81 86 94.2 %
Date: 2012-08-25 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 151 284 53.2 %

           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                 :            : #include "sfx2/imagemgr.hxx"
      21                 :            : #include <com/sun/star/frame/XController.hpp>
      22                 :            : #include <com/sun/star/ui/XImageManager.hpp>
      23                 :            : #include <com/sun/star/frame/XModuleManager.hpp>
      24                 :            : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
      25                 :            : #include <com/sun/star/ui/ImageType.hpp>
      26                 :            : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
      27                 :            : 
      28                 :            : #include <tools/urlobj.hxx>
      29                 :            : #include <svtools/imagemgr.hxx>
      30                 :            : #include <comphelper/processfactory.hxx>
      31                 :            : #include <rtl/ustring.hxx>
      32                 :            : #include <rtl/logfile.hxx>
      33                 :            : 
      34                 :            : #include "sfx2/imgmgr.hxx"
      35                 :            : #include <sfx2/app.hxx>
      36                 :            : #include <sfx2/unoctitm.hxx>
      37                 :            : #include <sfx2/dispatch.hxx>
      38                 :            : #include <sfx2/msg.hxx>
      39                 :            : #include <sfx2/msgpool.hxx>
      40                 :            : #include <sfx2/viewfrm.hxx>
      41                 :            : #include <sfx2/module.hxx>
      42                 :            : #include <sfx2/objsh.hxx>
      43                 :            : #include <sfx2/docfac.hxx>
      44                 :            : 
      45                 :            : #include <boost/unordered_map.hpp>
      46                 :            : 
      47                 :            : using namespace ::com::sun::star::uno;
      48                 :            : using namespace ::com::sun::star::frame;
      49                 :            : using namespace ::com::sun::star::lang;
      50                 :            : using namespace ::com::sun::star::util;
      51                 :            : using namespace ::com::sun::star::ui;
      52                 :            : using namespace ::com::sun::star::frame;
      53                 :            : 
      54                 :            : typedef boost::unordered_map< ::rtl::OUString,
      55                 :            :                        WeakReference< XImageManager >,
      56                 :            :                        ::rtl::OUStringHash,
      57                 :            :                        ::std::equal_to< ::rtl::OUString > > ModuleIdToImagegMgr;
      58                 :            : 
      59                 :            : 
      60                 :      15298 : Image SAL_CALL GetImage(
      61                 :            :     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
      62                 :            :     const ::rtl::OUString& aURL,
      63                 :            :     bool bBig
      64                 :            : )
      65                 :            : {
      66                 :            :     // TODO/LATeR: shouldn't this become a method at SfxViewFrame?! That would save the UnoTunnel
      67         [ -  + ]:      15298 :     if ( !rFrame.is() )
      68         [ #  # ]:          0 :         return Image();
      69                 :            : 
      70         [ +  - ]:      15298 :     INetURLObject aObj( aURL );
      71                 :      15298 :     INetProtocol  nProtocol = aObj.GetProtocol();
      72                 :            : 
      73                 :      15298 :     Reference < XController > xController;
      74                 :      15298 :     Reference < XModel > xModel;
      75         [ +  - ]:      15298 :     if ( rFrame.is() )
      76 [ +  - ][ +  - ]:      15298 :         xController = rFrame->getController();
                 [ +  - ]
      77         [ +  - ]:      15298 :     if ( xController.is() )
      78 [ +  - ][ +  - ]:      15298 :         xModel = xController->getModel();
                 [ +  - ]
      79                 :            : 
      80                 :      15298 :     rtl::OUString aCommandURL( aURL );
      81         [ +  + ]:      15298 :     if ( nProtocol == INET_PROT_SLOT )
      82                 :            :     {
      83 [ +  - ][ +  - ]:       1780 :         sal_uInt16 nId = ( sal_uInt16 ) String(aURL).Copy(5).ToInt32();
         [ +  - ][ +  - ]
                 [ +  - ]
      84                 :       1780 :         const SfxSlot* pSlot = 0;
      85         [ +  - ]:       1780 :         if ( xModel.is() )
      86                 :            :         {
      87         [ +  - ]:       1780 :             Reference < XUnoTunnel > xObj( xModel, UNO_QUERY );
      88 [ +  - ][ +  - ]:       1780 :             Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
                 [ +  - ]
      89 [ +  - ][ +  - ]:       1780 :             sal_Int64 nHandle = xObj.is() ? xObj->getSomething( aSeq ) : 0;
                 [ +  - ]
      90         [ +  + ]:       1780 :             if ( nHandle )
      91                 :            :             {
      92                 :       1778 :                 SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell*>(sal::static_int_cast<sal_IntPtr>( nHandle ));
      93 [ +  - ][ +  - ]:       1778 :                 SfxModule* pModule = pDoc->GetFactory().GetModule();
      94 [ +  - ][ +  - ]:       1778 :                 pSlot = pModule->GetSlotPool()->GetSlot( nId );
      95         [ +  - ]:       1780 :             }
      96                 :            :         }
      97                 :            :         else
      98 [ #  # ][ #  # ]:          0 :             pSlot = SfxSlotPool::GetSlotPool().GetSlot( nId );
      99                 :            : 
     100         [ +  + ]:       1780 :         if ( pSlot )
     101                 :            :         {
     102         [ +  - ]:       1778 :             aCommandURL = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
     103                 :       1778 :             aCommandURL += rtl::OUString::createFromAscii( pSlot->GetUnoName() );
     104                 :            :         }
     105                 :            :         else
     106                 :          2 :             aCommandURL = rtl::OUString();
     107                 :            :     }
     108                 :            : 
     109                 :      15298 :     Reference< XImageManager > xDocImgMgr;
     110         [ +  - ]:      15298 :     if ( xModel.is() )
     111                 :            :     {
     112         [ +  - ]:      15298 :         Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
     113         [ +  + ]:      15298 :         if ( xSupplier.is() )
     114                 :            :         {
     115 [ +  - ][ +  - ]:      15272 :             Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
                 [ +  - ]
     116 [ +  - ][ +  - ]:      15272 :             xDocImgMgr = Reference< XImageManager >( xDocUICfgMgr->getImageManager(), UNO_QUERY );
         [ +  - ][ +  - ]
     117                 :      15298 :         }
     118                 :            :     }
     119                 :            : 
     120                 :            :     sal_Int16 nImageType( ::com::sun::star::ui::ImageType::COLOR_NORMAL|
     121                 :      15298 :                             ::com::sun::star::ui::ImageType::SIZE_DEFAULT );
     122         [ -  + ]:      15298 :     if ( bBig )
     123                 :          0 :         nImageType |= ::com::sun::star::ui::ImageType::SIZE_LARGE;
     124                 :            : 
     125         [ +  + ]:      15298 :     if ( xDocImgMgr.is() )
     126                 :            :     {
     127         [ +  - ]:      15272 :         Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq;
     128         [ +  - ]:      15272 :         Sequence< rtl::OUString > aImageCmdSeq( 1 );
     129         [ +  - ]:      15272 :         aImageCmdSeq[0] = aCommandURL;
     130                 :            : 
     131                 :            :         try
     132                 :            :         {
     133 [ +  - ][ +  - ]:      15272 :             aGraphicSeq = xDocImgMgr->getImages( nImageType, aImageCmdSeq );
         [ +  - ][ +  - ]
     134         [ +  - ]:      15272 :             Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0];
     135         [ +  - ]:      15272 :             Image aImage( xGraphic );
     136                 :            : 
     137         [ -  + ]:      15272 :             if ( !!aImage )
     138 [ #  # ][ +  - ]:      15272 :                 return aImage;
         [ -  + ][ +  - ]
                 [ #  # ]
     139                 :            :         }
     140         [ #  # ]:          0 :         catch (const Exception&)
     141                 :            :         {
     142 [ +  - ][ -  + ]:      15272 :         }
         [ +  - ][ +  - ]
     143                 :            :     }
     144                 :            : 
     145 [ +  + ][ +  - ]:      15298 :     static WeakReference< XModuleManager > m_xModuleManager;
         [ +  - ][ #  # ]
     146                 :            : 
     147         [ +  - ]:      15298 :     Reference< XModuleManager > xModuleManager = m_xModuleManager;
     148                 :            : 
     149         [ +  + ]:      15298 :     if ( !xModuleManager.is() )
     150                 :            :     {
     151                 :            :         xModuleManager = Reference< XModuleManager >(
     152 [ +  - ][ +  - ]:        120 :                             ::comphelper::getProcessServiceFactory()->createInstance(
     153                 :            :                                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
     154                 :         60 :                                     "com.sun.star.frame.ModuleManager" ))),
     155 [ +  - ][ +  - ]:         60 :                             UNO_QUERY );
         [ +  - ][ +  - ]
     156         [ +  - ]:         60 :         m_xModuleManager = xModuleManager;
     157                 :            :     }
     158                 :            : 
     159                 :            :     try
     160                 :            :     {
     161         [ +  + ]:      15298 :         if ( !aCommandURL.isEmpty() )
     162                 :            :         {
     163                 :      15296 :             Reference< XImageManager > xModuleImageManager;
     164 [ +  - ][ +  - ]:      15296 :             rtl::OUString aModuleId = xModuleManager->identify( rFrame );
     165                 :            : 
     166 [ +  + ][ +  - ]:      15296 :             static ModuleIdToImagegMgr m_aModuleIdToImageMgrMap;
         [ +  - ][ #  # ]
     167                 :            : 
     168         [ +  - ]:      15296 :             ModuleIdToImagegMgr::iterator pIter = m_aModuleIdToImageMgrMap.find( aModuleId );
     169 [ +  - ][ +  + ]:      15296 :             if ( pIter != m_aModuleIdToImageMgrMap.end() )
     170 [ +  - ][ +  - ]:      15209 :                 xModuleImageManager = pIter->second;
                 [ +  - ]
     171                 :            :             else
     172                 :            :             {
     173 [ +  + ][ +  - ]:         87 :                 static WeakReference< XModuleUIConfigurationManagerSupplier > m_xModuleCfgMgrSupplier;
         [ +  - ][ #  # ]
     174                 :            : 
     175         [ +  - ]:         87 :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier = m_xModuleCfgMgrSupplier;
     176                 :            : 
     177         [ +  + ]:         87 :                 if ( !xModuleCfgMgrSupplier.is() )
     178                 :            :                 {
     179                 :            :                     xModuleCfgMgrSupplier = Reference< XModuleUIConfigurationManagerSupplier >(
     180 [ +  - ][ +  - ]:        120 :                                                 ::comphelper::getProcessServiceFactory()->createInstance(
     181                 :            :                                                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
     182                 :         60 :                                                         "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ))),
     183 [ +  - ][ +  - ]:         60 :                                                 UNO_QUERY );
         [ +  - ][ +  - ]
     184                 :            : 
     185         [ +  - ]:         60 :                     m_xModuleCfgMgrSupplier = xModuleCfgMgrSupplier;
     186                 :            :                 }
     187                 :            : 
     188 [ +  - ][ +  - ]:         87 :                 Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( aModuleId );
     189 [ +  - ][ +  - ]:         87 :                 xModuleImageManager = Reference< XImageManager >( xUICfgMgr->getImageManager(), UNO_QUERY );
         [ +  - ][ +  - ]
     190 [ +  - ][ +  - ]:         87 :                 m_aModuleIdToImageMgrMap.insert( ModuleIdToImagegMgr::value_type( aModuleId, xModuleImageManager ));
                 [ +  - ]
     191                 :            :             }
     192                 :            : 
     193         [ +  - ]:      15296 :             Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq;
     194         [ +  - ]:      15296 :             Sequence< rtl::OUString > aImageCmdSeq( 1 );
     195         [ +  - ]:      15296 :             aImageCmdSeq[0] = aCommandURL;
     196                 :            : 
     197 [ +  - ][ +  - ]:      15296 :             aGraphicSeq = xModuleImageManager->getImages( nImageType, aImageCmdSeq );
         [ +  - ][ +  - ]
     198                 :            : 
     199         [ +  - ]:      15296 :             Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0];
     200         [ +  - ]:      15296 :             Image aImage( xGraphic );
     201                 :            : 
     202         [ +  + ]:      15296 :             if ( !!aImage )
     203         [ +  - ]:       1976 :                 return aImage;
     204 [ +  + ][ +  - ]:      13320 :             else if ( nProtocol != INET_PROT_UNO && nProtocol != INET_PROT_SLOT )
     205 [ +  - ][ +  - ]:      15296 :                 return SvFileInformationManager::GetImageNoDefault( aObj, bBig );
         [ +  + ][ +  + ]
         [ +  - ][ +  + ]
         [ +  - ][ +  + ]
         [ +  + ][ +  + ]
                 [ #  # ]
     206                 :            :         }
     207                 :            :     }
     208         [ #  # ]:          0 :     catch (const Exception&)
     209                 :            :     {
     210                 :            :     }
     211                 :            : 
     212 [ +  - ][ +  - ]:      15298 :     return Image();
     213                 :            : }
     214                 :            : 
     215                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10