LCOV - code coverage report
Current view: top level - sfx2/source/appl - imagemgr.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 77 83 92.8 %
Date: 2015-06-13 12:38:46 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/theModuleUIConfigurationManagerSupplier.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             : 
      33             : #include <sfx2/imgmgr.hxx>
      34             : #include <sfx2/app.hxx>
      35             : #include <sfx2/unoctitm.hxx>
      36             : #include <sfx2/dispatch.hxx>
      37             : #include <sfx2/msg.hxx>
      38             : #include <sfx2/msgpool.hxx>
      39             : #include <sfx2/viewfrm.hxx>
      40             : #include <sfx2/module.hxx>
      41             : #include <sfx2/objsh.hxx>
      42             : #include <sfx2/docfac.hxx>
      43             : 
      44             : #include <unordered_map>
      45             : 
      46             : using namespace ::com::sun::star::uno;
      47             : using namespace ::com::sun::star::frame;
      48             : using namespace ::com::sun::star::lang;
      49             : using namespace ::com::sun::star::util;
      50             : using namespace ::com::sun::star::ui;
      51             : 
      52             : typedef std::unordered_map< OUString,
      53             :                        WeakReference< XImageManager >,
      54             :                        OUStringHash,
      55             :                        ::std::equal_to< OUString > > ModuleIdToImagegMgr;
      56             : 
      57             : 
      58       17367 : Image SAL_CALL GetImage(
      59             :     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
      60             :     const OUString& aURL,
      61             :     bool bBig
      62             : )
      63             : {
      64             :     // TODO/LATeR: shouldn't this become a method at SfxViewFrame?! That would save the UnoTunnel
      65       17367 :     if ( !rFrame.is() )
      66           0 :         return Image();
      67             : 
      68       17367 :     INetURLObject aObj( aURL );
      69       17367 :     INetProtocol  nProtocol = aObj.GetProtocol();
      70             : 
      71       34734 :     Reference < XController > xController;
      72       34734 :     Reference < XModel > xModel;
      73       17367 :     if ( rFrame.is() )
      74       17367 :         xController = rFrame->getController();
      75       17367 :     if ( xController.is() )
      76       17367 :         xModel = xController->getModel();
      77             : 
      78       34734 :     OUString aCommandURL( aURL );
      79       17367 :     if ( nProtocol == INetProtocol::Slot )
      80             :     {
      81         489 :         sal_uInt16 nId = ( sal_uInt16 ) aURL.copy(5).toInt32();
      82         489 :         const SfxSlot* pSlot = 0;
      83         489 :         if ( xModel.is() )
      84             :         {
      85         489 :             Reference < XUnoTunnel > xObj( xModel, UNO_QUERY );
      86         978 :             Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
      87         489 :             sal_Int64 nHandle = xObj.is() ? xObj->getSomething( aSeq ) : 0;
      88         489 :             if ( nHandle )
      89             :             {
      90         489 :                 SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell*>(sal::static_int_cast<sal_IntPtr>( nHandle ));
      91         489 :                 SfxModule* pModule = pDoc->GetFactory().GetModule();
      92         489 :                 pSlot = pModule->GetSlotPool()->GetSlot( nId );
      93         489 :             }
      94             :         }
      95             :         else
      96           0 :             pSlot = SfxSlotPool::GetSlotPool().GetSlot( nId );
      97             : 
      98         489 :         if ( pSlot )
      99             :         {
     100         489 :             aCommandURL = ".uno:";
     101         489 :             aCommandURL += OUString::createFromAscii( pSlot->GetUnoName() );
     102             :         }
     103             :         else
     104           0 :             aCommandURL.clear();
     105             :     }
     106             : 
     107       34734 :     Reference< XImageManager > xDocImgMgr;
     108       17367 :     if ( xModel.is() )
     109             :     {
     110       17367 :         Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY );
     111       17367 :         if ( xSupplier.is() )
     112             :         {
     113       16942 :             Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY );
     114       16942 :             xDocImgMgr = Reference< XImageManager >( xDocUICfgMgr->getImageManager(), UNO_QUERY );
     115       17367 :         }
     116             :     }
     117             : 
     118             :     sal_Int16 nImageType( ::com::sun::star::ui::ImageType::COLOR_NORMAL|
     119       17367 :                             ::com::sun::star::ui::ImageType::SIZE_DEFAULT );
     120       17367 :     if ( bBig )
     121           0 :         nImageType |= ::com::sun::star::ui::ImageType::SIZE_LARGE;
     122             : 
     123       17367 :     if ( xDocImgMgr.is() )
     124             :     {
     125       16942 :         Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq;
     126       33884 :         Sequence< OUString > aImageCmdSeq( 1 );
     127       16942 :         aImageCmdSeq[0] = aCommandURL;
     128             : 
     129             :         try
     130             :         {
     131       16942 :             aGraphicSeq = xDocImgMgr->getImages( nImageType, aImageCmdSeq );
     132       16942 :             Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0];
     133       33884 :             Image aImage( xGraphic );
     134             : 
     135       16942 :             if ( !!aImage )
     136       16942 :                 return aImage;
     137             :         }
     138           0 :         catch (const Exception&)
     139             :         {
     140       16942 :         }
     141             :     }
     142             : 
     143       17367 :     static WeakReference< XModuleManager2 > m_xModuleManager;
     144             : 
     145       34734 :     Reference< XModuleManager2 > xModuleManager = m_xModuleManager;
     146             : 
     147       17367 :     if ( !xModuleManager.is() )
     148             :     {
     149          44 :         xModuleManager = ModuleManager::create(::comphelper::getProcessComponentContext());
     150          44 :         m_xModuleManager = xModuleManager;
     151             :     }
     152             : 
     153             :     try
     154             :     {
     155       17367 :         if ( !aCommandURL.isEmpty() )
     156             :         {
     157       17367 :             Reference< XImageManager > xModuleImageManager;
     158       17399 :             OUString aModuleId = xModuleManager->identify( rFrame );
     159             : 
     160       17367 :             static ModuleIdToImagegMgr m_aModuleIdToImageMgrMap;
     161             : 
     162       17367 :             ModuleIdToImagegMgr::iterator pIter = m_aModuleIdToImageMgrMap.find( aModuleId );
     163       17367 :             if ( pIter != m_aModuleIdToImageMgrMap.end() )
     164       17308 :                 xModuleImageManager = pIter->second;
     165             :             else
     166             :             {
     167          59 :                 static WeakReference< XModuleUIConfigurationManagerSupplier > m_xModuleCfgMgrSupplier;
     168             : 
     169          59 :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier = m_xModuleCfgMgrSupplier;
     170             : 
     171          59 :                 if ( !xModuleCfgMgrSupplier.is() )
     172             :                 {
     173          88 :                     xModuleCfgMgrSupplier = theModuleUIConfigurationManagerSupplier::get(
     174          44 :                                               ::comphelper::getProcessComponentContext() );
     175             : 
     176          44 :                     m_xModuleCfgMgrSupplier = xModuleCfgMgrSupplier;
     177             :                 }
     178             : 
     179         118 :                 Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( aModuleId );
     180          59 :                 xModuleImageManager = Reference< XImageManager >( xUICfgMgr->getImageManager(), UNO_QUERY );
     181         118 :                 m_aModuleIdToImageMgrMap.insert( ModuleIdToImagegMgr::value_type( aModuleId, xModuleImageManager ));
     182             :             }
     183             : 
     184       17399 :             Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq;
     185       17399 :             Sequence< OUString > aImageCmdSeq( 1 );
     186       17367 :             aImageCmdSeq[0] = aCommandURL;
     187             : 
     188       17367 :             aGraphicSeq = xModuleImageManager->getImages( nImageType, aImageCmdSeq );
     189             : 
     190       17399 :             Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0];
     191       17399 :             Image aImage( xGraphic );
     192             : 
     193       17367 :             if ( !!aImage )
     194        3394 :                 return aImage;
     195       13973 :             else if ( nProtocol != INetProtocol::Uno && nProtocol != INetProtocol::Slot )
     196       13973 :                 return SvFileInformationManager::GetImageNoDefault( aObj, bBig );
     197             :         }
     198             :     }
     199           0 :     catch (const Exception&)
     200             :     {
     201             :     }
     202             : 
     203       17399 :     return Image();
     204             : }
     205             : 
     206             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11