LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/appl - imagemgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 37 82 45.1 %
Date: 2012-12-27 Functions: 1 1 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             : 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        2360 : 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        2360 :     if ( !rFrame.is() )
      68           0 :         return Image();
      69             : 
      70        2360 :     INetURLObject aObj( aURL );
      71        2360 :     INetProtocol  nProtocol = aObj.GetProtocol();
      72             : 
      73        2360 :     Reference < XController > xController;
      74        2360 :     Reference < XModel > xModel;
      75        2360 :     if ( rFrame.is() )
      76        2360 :         xController = rFrame->getController();
      77        2360 :     if ( xController.is() )
      78        2360 :         xModel = xController->getModel();
      79             : 
      80        2360 :     rtl::OUString aCommandURL( aURL );
      81        2360 :     if ( nProtocol == INET_PROT_SLOT )
      82             :     {
      83           0 :         sal_uInt16 nId = ( sal_uInt16 ) String(aURL).Copy(5).ToInt32();
      84           0 :         const SfxSlot* pSlot = 0;
      85           0 :         if ( xModel.is() )
      86             :         {
      87           0 :             Reference < XUnoTunnel > xObj( xModel, UNO_QUERY );
      88           0 :             Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
      89           0 :             sal_Int64 nHandle = xObj.is() ? xObj->getSomething( aSeq ) : 0;
      90           0 :             if ( nHandle )
      91             :             {
      92           0 :                 SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell*>(sal::static_int_cast<sal_IntPtr>( nHandle ));
      93           0 :                 SfxModule* pModule = pDoc->GetFactory().GetModule();
      94           0 :                 pSlot = pModule->GetSlotPool()->GetSlot( nId );
      95           0 :             }
      96             :         }
      97             :         else
      98           0 :             pSlot = SfxSlotPool::GetSlotPool().GetSlot( nId );
      99             : 
     100           0 :         if ( pSlot )
     101             :         {
     102           0 :             aCommandURL = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
     103           0 :             aCommandURL += rtl::OUString::createFromAscii( pSlot->GetUnoName() );
     104             :         }
     105             :         else
     106           0 :             aCommandURL = rtl::OUString();
     107             :     }
     108             : 
     109        2360 :     Reference< XImageManager > xDocImgMgr;
     110        2360 :     if ( xModel.is() )
     111             :     {
     112        2360 :         Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
     113        2360 :         if ( xSupplier.is() )
     114             :         {
     115        2360 :             Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
     116        2360 :             xDocImgMgr = Reference< XImageManager >( xDocUICfgMgr->getImageManager(), UNO_QUERY );
     117        2360 :         }
     118             :     }
     119             : 
     120             :     sal_Int16 nImageType( ::com::sun::star::ui::ImageType::COLOR_NORMAL|
     121        2360 :                             ::com::sun::star::ui::ImageType::SIZE_DEFAULT );
     122        2360 :     if ( bBig )
     123           0 :         nImageType |= ::com::sun::star::ui::ImageType::SIZE_LARGE;
     124             : 
     125        2360 :     if ( xDocImgMgr.is() )
     126             :     {
     127        2360 :         Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq;
     128        2360 :         Sequence< rtl::OUString > aImageCmdSeq( 1 );
     129        2360 :         aImageCmdSeq[0] = aCommandURL;
     130             : 
     131             :         try
     132             :         {
     133        2360 :             aGraphicSeq = xDocImgMgr->getImages( nImageType, aImageCmdSeq );
     134        2360 :             Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0];
     135        2360 :             Image aImage( xGraphic );
     136             : 
     137        2360 :             if ( !!aImage )
     138           0 :                 return aImage;
     139             :         }
     140           0 :         catch (const Exception&)
     141             :         {
     142        2360 :         }
     143             :     }
     144             : 
     145        2360 :     static WeakReference< XModuleManager2 > m_xModuleManager;
     146             : 
     147        2360 :     Reference< XModuleManager2 > xModuleManager = m_xModuleManager;
     148             : 
     149        2360 :     if ( !xModuleManager.is() )
     150             :     {
     151        2360 :         xModuleManager = ModuleManager::create(::comphelper::getProcessComponentContext());
     152        2360 :         m_xModuleManager = xModuleManager;
     153             :     }
     154             : 
     155             :     try
     156             :     {
     157        2360 :         if ( !aCommandURL.isEmpty() )
     158             :         {
     159           0 :             Reference< XImageManager > xModuleImageManager;
     160           0 :             rtl::OUString aModuleId = xModuleManager->identify( rFrame );
     161             : 
     162           0 :             static ModuleIdToImagegMgr m_aModuleIdToImageMgrMap;
     163             : 
     164           0 :             ModuleIdToImagegMgr::iterator pIter = m_aModuleIdToImageMgrMap.find( aModuleId );
     165           0 :             if ( pIter != m_aModuleIdToImageMgrMap.end() )
     166           0 :                 xModuleImageManager = pIter->second;
     167             :             else
     168             :             {
     169           0 :                 static WeakReference< XModuleUIConfigurationManagerSupplier > m_xModuleCfgMgrSupplier;
     170             : 
     171           0 :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier = m_xModuleCfgMgrSupplier;
     172             : 
     173           0 :                 if ( !xModuleCfgMgrSupplier.is() )
     174             :                 {
     175             :                     xModuleCfgMgrSupplier = ModuleUIConfigurationManagerSupplier::create(
     176           0 :                                               ::comphelper::getProcessComponentContext() );
     177             : 
     178           0 :                     m_xModuleCfgMgrSupplier = xModuleCfgMgrSupplier;
     179             :                 }
     180             : 
     181           0 :                 Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( aModuleId );
     182           0 :                 xModuleImageManager = Reference< XImageManager >( xUICfgMgr->getImageManager(), UNO_QUERY );
     183           0 :                 m_aModuleIdToImageMgrMap.insert( ModuleIdToImagegMgr::value_type( aModuleId, xModuleImageManager ));
     184             :             }
     185             : 
     186           0 :             Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq;
     187           0 :             Sequence< rtl::OUString > aImageCmdSeq( 1 );
     188           0 :             aImageCmdSeq[0] = aCommandURL;
     189             : 
     190           0 :             aGraphicSeq = xModuleImageManager->getImages( nImageType, aImageCmdSeq );
     191             : 
     192           0 :             Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0];
     193           0 :             Image aImage( xGraphic );
     194             : 
     195           0 :             if ( !!aImage )
     196           0 :                 return aImage;
     197           0 :             else if ( nProtocol != INET_PROT_UNO && nProtocol != INET_PROT_SLOT )
     198           0 :                 return SvFileInformationManager::GetImageNoDefault( aObj, bBig );
     199             :         }
     200             :     }
     201           0 :     catch (const Exception&)
     202             :     {
     203             :     }
     204             : 
     205        2360 :     return Image();
     206             : }
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10