diff options
author | Oliver Bolte <obo@openoffice.org> | 2004-07-06 12:32:36 +0000 |
---|---|---|
committer | Oliver Bolte <obo@openoffice.org> | 2004-07-06 12:32:36 +0000 |
commit | d82b6f0e9f883720c6bd4a765223f3584fec00d1 (patch) | |
tree | 5716b40ddc562c10978567509997858c373f82c3 /sfx2/source/appl/imagemgr.cxx | |
parent | 239a400c582a4bd30e6d35092d71739ffdcfd95c (diff) |
INTEGRATION: CWS docking1 (1.7.386); FILE MERGED
2004/06/22 10:05:21 cd 1.7.386.4: #i30169# Support retrieving images with slot URLs
2004/06/22 06:11:36 cd 1.7.386.3: #i30169# Support slot URLs to retrieve images
2004/06/20 20:05:07 cd 1.7.386.2: #i30169# Use new image manager implementation and new layout manager methods
2004/06/16 13:53:16 cd 1.7.386.1: #i30169# First implementation of an UNO based module image manager
Diffstat (limited to 'sfx2/source/appl/imagemgr.cxx')
-rw-r--r-- | sfx2/source/appl/imagemgr.cxx | 224 |
1 files changed, 221 insertions, 3 deletions
diff --git a/sfx2/source/appl/imagemgr.cxx b/sfx2/source/appl/imagemgr.cxx index 728fc4f0dc0d..4af3eb968d19 100644 --- a/sfx2/source/appl/imagemgr.cxx +++ b/sfx2/source/appl/imagemgr.cxx @@ -2,9 +2,9 @@ * * $RCSfile: imagemgr.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: cd $ $Date: 2002-08-01 11:32:19 $ + * last change: $Author: obo $ $Date: 2004-07-06 13:32:36 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -69,10 +69,26 @@ #ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_ #include <com/sun/star/frame/XFrame.hpp> #endif +#ifndef _DRAFTS_COM_SUN_STAR_UI_XIMAGEMANAGER_HPP_ +#include <drafts/com/sun/star/ui/XImageManager.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_FRAME_XMODULEMANAGER_HPP_ +#include <drafts/com/sun/star/frame/XModuleManager.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_UI_XMODULEUICONFIGURATIONMANAGERSUPPLIER_HPP_ +#include <drafts/com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_UI_IMAGETYPE_HPP_ +#include <drafts/com/sun/star/ui/ImageType.hpp> +#endif +#ifndef _DRAFTS_COM_SUN_STAR_UI_XUICONFIGURATIONMANAGERSUPPLIER_HPP_ +#include <drafts/com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> +#endif #include <tools/urlobj.hxx> #include <svtools/imagemgr.hxx> #include <comphelper/processfactory.hxx> +#include <rtl/ustring.hxx> #include "imgmgr.hxx" #include "app.hxx" @@ -88,9 +104,211 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::frame; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::util; +using namespace ::drafts::com::sun::star::ui; +using namespace ::drafts::com::sun::star::frame; + +typedef std::hash_map< ::rtl::OUString, + WeakReference< XImageManager >, + ::rtl::OUStringHash, + ::std::equal_to< ::rtl::OUString > > ModuleIdToImagegMgr; + +static WeakReference< XModuleManager > m_xModuleManager; +static WeakReference< XModuleUIConfigurationManagerSupplier > m_xModuleCfgMgrSupplier; +static WeakReference< XURLTransformer > m_xURLTransformer; +static ModuleIdToImagegMgr m_aModuleIdToImageMgrMap; Image SAL_CALL GetImage( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, const ::rtl::OUString& aURL, BOOL bBig, BOOL bHiContrast ) { + if ( !rFrame.is() ) + return Image(); + + INetURLObject aObj( aURL ); + INetProtocol nProtocol = aObj.GetProtocol(); + + rtl::OUString aCommandURL( aURL ); + if ( nProtocol == INET_PROT_SLOT ) + { + // Support old way to retrieve image via slot URL + Reference< XURLTransformer > xURLTransformer = m_xURLTransformer; + if ( !xURLTransformer.is() ) + { + xURLTransformer = Reference< XURLTransformer >( + ::comphelper::getProcessServiceFactory()->createInstance( + rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), + UNO_QUERY ); + m_xURLTransformer = xURLTransformer; + } + + URL aTargetURL; + aTargetURL.Complete = aURL; + xURLTransformer->parseStrict( aTargetURL ); + + SfxViewFrame* pViewFrame = NULL; + Reference < XController > xController; + if ( rFrame.is() ) + xController = rFrame->getController(); + + Reference < XDispatchProvider > xProvider( xController, UNO_QUERY ); + if ( xProvider.is() ) + { + Reference < XDispatch > xDisp = xProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); + if ( xDisp.is() ) + { + Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY ); + SfxOfficeDispatch* pDisp = NULL; + if ( xTunnel.is() ) + { + sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier()); + pDisp = (SfxOfficeDispatch*)(nImplementation); + } + + if ( pDisp ) + pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame(); + } + } + + USHORT nId = ( USHORT ) aTargetURL.Path.toInt32(); + SfxSlotPool& rPool = SFX_APP()->GetSlotPool( pViewFrame ); + const SfxSlot* pSlot = rPool.GetSlot( nId ); + if ( pSlot ) + { + aCommandURL = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" )); + aCommandURL += rtl::OUString::createFromAscii( pSlot->GetUnoName() ); + } + else + aCommandURL = rtl::OUString(); + } + + Reference< XImageManager > xDocImgMgr; + Reference< XController > xController = rFrame->getController(); + Reference< XModel > xModel; + if ( xController.is() ) + { + xModel = xController->getModel(); + if ( xModel.is() ) + { + Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY ); + if ( xSupplier.is() ) + { + Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY ); + xDocImgMgr = Reference< XImageManager >( xDocUICfgMgr->getImageManager(), UNO_QUERY ); + } + } + } + + sal_Int16 nImageType( ::drafts::com::sun::star::ui::ImageType::COLOR_NORMAL| + ::drafts::com::sun::star::ui::ImageType::SIZE_DEFAULT ); + if ( bBig ) + nImageType |= ::drafts::com::sun::star::ui::ImageType::SIZE_LARGE; + if ( bHiContrast ) + nImageType |= ::drafts::com::sun::star::ui::ImageType::COLOR_HIGHCONTRAST; + + if ( xDocImgMgr.is() ) + { + Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq; + Sequence< rtl::OUString > aImageCmdSeq( 1 ); + aImageCmdSeq[0] = aCommandURL; + + try + { + aGraphicSeq = xDocImgMgr->getImages( nImageType, aImageCmdSeq ); + Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0]; + Image aImage( xGraphic ); + + if ( !!aImage ) + return aImage; + } + catch ( Exception& ) + { + } + } + + Reference< XModuleManager > xModuleManager = m_xModuleManager; + + if ( !xModuleManager.is() ) + { + xModuleManager = Reference< XModuleManager >( + ::comphelper::getProcessServiceFactory()->createInstance( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "drafts.com.sun.star.frame.ModuleManager" ))), + UNO_QUERY ); + m_xModuleManager = xModuleManager; + } + + try + { + if ( aCommandURL.getLength() > 0 ) + { + Reference< XImageManager > xModuleImageManager; + rtl::OUString aModuleId = xModuleManager->identify( rFrame ); + ModuleIdToImagegMgr::iterator pIter = m_aModuleIdToImageMgrMap.find( aModuleId ); + if ( pIter != m_aModuleIdToImageMgrMap.end() ) + xModuleImageManager = pIter->second; + else + { + Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier = m_xModuleCfgMgrSupplier; + + if ( !xModuleCfgMgrSupplier.is() ) + { + xModuleCfgMgrSupplier = Reference< XModuleUIConfigurationManagerSupplier >( + ::comphelper::getProcessServiceFactory()->createInstance( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "drafts.com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ))), + UNO_QUERY ); + + m_xModuleCfgMgrSupplier = xModuleCfgMgrSupplier; + } + + Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( aModuleId ); + xModuleImageManager = Reference< XImageManager >( xUICfgMgr->getImageManager(), UNO_QUERY ); + m_aModuleIdToImageMgrMap.insert( ModuleIdToImagegMgr::value_type( aModuleId, xModuleImageManager )); + } + + sal_Int16 nImageType( ::drafts::com::sun::star::ui::ImageType::COLOR_NORMAL| + ::drafts::com::sun::star::ui::ImageType::SIZE_DEFAULT ); + if ( bBig ) + nImageType |= ::drafts::com::sun::star::ui::ImageType::SIZE_LARGE; + if ( bHiContrast ) + nImageType |= ::drafts::com::sun::star::ui::ImageType::COLOR_HIGHCONTRAST; + + Sequence< Reference< ::com::sun::star::graphic::XGraphic > > aGraphicSeq; + Sequence< rtl::OUString > aImageCmdSeq( 1 ); + aImageCmdSeq[0] = aCommandURL; + + aGraphicSeq = xModuleImageManager->getImages( nImageType, aImageCmdSeq ); + + Reference< ::com::sun::star::graphic::XGraphic > xGraphic = aGraphicSeq[0]; + Image aImage( xGraphic ); + + if ( !!aImage ) + return aImage; + else if ( nProtocol != INET_PROT_UNO && nProtocol != INET_PROT_SLOT ) + return SvFileInformationManager::GetImageNoDefault( aObj, bBig, bHiContrast ); + } + } + catch ( Exception& ) + { + } + + return Image(); +} +/* + Reference< XController > xController = rFrame->getController(); + if ( xController.is() ) + { + Reference< XModel > xModel = xController->getModel(); + if ( xModel ) + { + } + } +*/ +/* + m_aModuleIdToImageMgrMap + + + + Reference< XImageManager > + INetURLObject aObj( aURL ); INetProtocol nProtocol = aObj.GetProtocol(); switch ( nProtocol ) @@ -160,4 +378,4 @@ Image SAL_CALL GetImage( ::com::sun::star::uno::Reference< ::com::sun::star::fra return SvFileInformationManager::GetImageNoDefault( aObj, bBig, bHiContrast ); } - +*/ |