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

Generated by: LCOV version 1.10