LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sfx2/source/appl - imagemgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 79 84 94.0 %
Date: 2013-07-09 Functions: 3 3 100.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 "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/ModuleManager.hpp>
      24             : #include <com/sun/star/ui/ModuleUIConfigurationManagerSupplier.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             : 
      53             : typedef boost::unordered_map< OUString,
      54             :                        WeakReference< XImageManager >,
      55             :                        OUStringHash,
      56             :                        ::std::equal_to< OUString > > ModuleIdToImagegMgr;
      57             : 
      58             : 
      59       17145 : Image SAL_CALL GetImage(
      60             :     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
      61             :     const OUString& aURL,
      62             :     bool bBig
      63             : )
      64             : {
      65             :     // TODO/LATeR: shouldn't this become a method at SfxViewFrame?! That would save the UnoTunnel
      66       17145 :     if ( !rFrame.is() )
      67           0 :         return Image();
      68             : 
      69       17145 :     INetURLObject aObj( aURL );
      70       17145 :     INetProtocol  nProtocol = aObj.GetProtocol();
      71             : 
      72       34290 :     Reference < XController > xController;
      73       34290 :     Reference < XModel > xModel;
      74       17145 :     if ( rFrame.is() )
      75       17145 :         xController = rFrame->getController();
      76       17145 :     if ( xController.is() )
      77       17145 :         xModel = xController->getModel();
      78             : 
      79       34290 :     OUString aCommandURL( aURL );
      80       17145 :     if ( nProtocol == INET_PROT_SLOT )
      81             :     {
      82        1650 :         sal_uInt16 nId = ( sal_uInt16 ) String(aURL).Copy(5).ToInt32();
      83        1650 :         const SfxSlot* pSlot = 0;
      84        1650 :         if ( xModel.is() )
      85             :         {
      86        1650 :             Reference < XUnoTunnel > xObj( xModel, UNO_QUERY );
      87        3300 :             Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
      88        1650 :             sal_Int64 nHandle = xObj.is() ? xObj->getSomething( aSeq ) : 0;
      89        1650 :             if ( nHandle )
      90             :             {
      91        1616 :                 SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell*>(sal::static_int_cast<sal_IntPtr>( nHandle ));
      92        1616 :                 SfxModule* pModule = pDoc->GetFactory().GetModule();
      93        1616 :                 pSlot = pModule->GetSlotPool()->GetSlot( nId );
      94        1650 :             }
      95             :         }
      96             :         else
      97           0 :             pSlot = SfxSlotPool::GetSlotPool().GetSlot( nId );
      98             : 
      99        1650 :         if ( pSlot )
     100             :         {
     101        1616 :             aCommandURL = OUString( ".uno:" );
     102        1616 :             aCommandURL += OUString::createFromAscii( pSlot->GetUnoName() );
     103             :         }
     104             :         else
     105          34 :             aCommandURL = OUString();
     106             :     }
     107             : 
     108       34290 :     Reference< XImageManager > xDocImgMgr;
     109       17145 :     if ( xModel.is() )
     110             :     {
     111       17145 :         Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
     112       17145 :         if ( xSupplier.is() )
     113             :         {
     114       16703 :             Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
     115       16703 :             xDocImgMgr = Reference< XImageManager >( xDocUICfgMgr->getImageManager(), UNO_QUERY );
     116       17145 :         }
     117             :     }
     118             : 
     119             :     sal_Int16 nImageType( ::com::sun::star::ui::ImageType::COLOR_NORMAL|
     120       17145 :                             ::com::sun::star::ui::ImageType::SIZE_DEFAULT );
     121       17145 :     if ( bBig )
     122           0 :         nImageType |= ::com::sun::star::ui::ImageType::SIZE_LARGE;
     123             : 
     124       17145 :     if ( xDocImgMgr.is() )
     125             :     {
     126       16703 :         Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq;
     127       33406 :         Sequence< OUString > aImageCmdSeq( 1 );
     128       16703 :         aImageCmdSeq[0] = aCommandURL;
     129             : 
     130             :         try
     131             :         {
     132       16703 :             aGraphicSeq = xDocImgMgr->getImages( nImageType, aImageCmdSeq );
     133       16703 :             Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0];
     134       33406 :             Image aImage( xGraphic );
     135             : 
     136       16703 :             if ( !!aImage )
     137       16703 :                 return aImage;
     138             :         }
     139           0 :         catch (const Exception&)
     140             :         {
     141       16703 :         }
     142             :     }
     143             : 
     144       17145 :     static WeakReference< XModuleManager2 > m_xModuleManager;
     145             : 
     146       34290 :     Reference< XModuleManager2 > xModuleManager = m_xModuleManager;
     147             : 
     148       17145 :     if ( !xModuleManager.is() )
     149             :     {
     150       17145 :         xModuleManager = ModuleManager::create(::comphelper::getProcessComponentContext());
     151       17145 :         m_xModuleManager = xModuleManager;
     152             :     }
     153             : 
     154             :     try
     155             :     {
     156       17145 :         if ( !aCommandURL.isEmpty() )
     157             :         {
     158       17111 :             Reference< XImageManager > xModuleImageManager;
     159       17144 :             OUString aModuleId = xModuleManager->identify( rFrame );
     160             : 
     161       17111 :             static ModuleIdToImagegMgr m_aModuleIdToImageMgrMap;
     162             : 
     163       17111 :             ModuleIdToImagegMgr::iterator pIter = m_aModuleIdToImageMgrMap.find( aModuleId );
     164       17111 :             if ( pIter != m_aModuleIdToImageMgrMap.end() )
     165       17066 :                 xModuleImageManager = pIter->second;
     166             :             else
     167             :             {
     168          45 :                 static WeakReference< XModuleUIConfigurationManagerSupplier > m_xModuleCfgMgrSupplier;
     169             : 
     170          45 :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier = m_xModuleCfgMgrSupplier;
     171             : 
     172          45 :                 if ( !xModuleCfgMgrSupplier.is() )
     173             :                 {
     174          60 :                     xModuleCfgMgrSupplier = ModuleUIConfigurationManagerSupplier::create(
     175          30 :                                               ::comphelper::getProcessComponentContext() );
     176             : 
     177          30 :                     m_xModuleCfgMgrSupplier = xModuleCfgMgrSupplier;
     178             :                 }
     179             : 
     180          90 :                 Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( aModuleId );
     181          45 :                 xModuleImageManager = Reference< XImageManager >( xUICfgMgr->getImageManager(), UNO_QUERY );
     182          90 :                 m_aModuleIdToImageMgrMap.insert( ModuleIdToImagegMgr::value_type( aModuleId, xModuleImageManager ));
     183             :             }
     184             : 
     185       17144 :             Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq;
     186       17144 :             Sequence< OUString > aImageCmdSeq( 1 );
     187       17111 :             aImageCmdSeq[0] = aCommandURL;
     188             : 
     189       17111 :             aGraphicSeq = xModuleImageManager->getImages( nImageType, aImageCmdSeq );
     190             : 
     191       17144 :             Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0];
     192       17144 :             Image aImage( xGraphic );
     193             : 
     194       17111 :             if ( !!aImage )
     195        1715 :                 return aImage;
     196       15396 :             else if ( nProtocol != INET_PROT_UNO && nProtocol != INET_PROT_SLOT )
     197       15396 :                 return SvFileInformationManager::GetImageNoDefault( aObj, bBig );
     198             :         }
     199             :     }
     200           0 :     catch (const Exception&)
     201             :     {
     202             :     }
     203             : 
     204       17212 :     return Image();
     205         408 : }
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10