summaryrefslogtreecommitdiff
path: root/sfx2/source/appl/imagemgr.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sfx2/source/appl/imagemgr.cxx')
-rw-r--r--sfx2/source/appl/imagemgr.cxx234
1 files changed, 234 insertions, 0 deletions
diff --git a/sfx2/source/appl/imagemgr.cxx b/sfx2/source/appl/imagemgr.cxx
new file mode 100644
index 000000000000..3b26eae1858d
--- /dev/null
+++ b/sfx2/source/appl/imagemgr.cxx
@@ -0,0 +1,234 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sfx2.hxx"
+#include "imagemgr.hxx"
+#include <com/sun/star/frame/XController.hpp>
+#include <com/sun/star/ui/XImageManager.hpp>
+#include <com/sun/star/frame/XModuleManager.hpp>
+#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
+#include <com/sun/star/ui/ImageType.hpp>
+#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
+
+#include <tools/urlobj.hxx>
+#include <svtools/imagemgr.hxx>
+#include <comphelper/processfactory.hxx>
+#include <rtl/ustring.hxx>
+#include <rtl/logfile.hxx>
+
+#include "imgmgr.hxx"
+#include <sfx2/app.hxx>
+#include <sfx2/unoctitm.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/msg.hxx>
+#include <sfx2/msgpool.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/module.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/docfac.hxx>
+
+#include <hash_map>
+
+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 ::com::sun::star::ui;
+using namespace ::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( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, const ::rtl::OUString& aURL, BOOL bBig, BOOL bHiContrast )
+{
+ // TODO/LATeR: shouldn't this become a method at SfxViewFrame?! That would save the UnoTunnel
+ if ( !rFrame.is() )
+ return Image();
+
+ INetURLObject aObj( aURL );
+ INetProtocol nProtocol = aObj.GetProtocol();
+
+ Reference < XController > xController;
+ Reference < XModel > xModel;
+ if ( rFrame.is() )
+ xController = rFrame->getController();
+ if ( xController.is() )
+ xModel = xController->getModel();
+
+ 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 );
+ USHORT nId = ( USHORT ) aTargetURL.Path.toInt32();*/
+ USHORT nId = ( USHORT ) String(aURL).Copy(5).ToInt32();
+ const SfxSlot* pSlot = 0;
+ if ( xModel.is() )
+ {
+ Reference < XUnoTunnel > xObj( xModel, UNO_QUERY );
+ Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
+ sal_Int64 nHandle = xObj.is() ? xObj->getSomething( aSeq ) : 0;
+ if ( nHandle )
+ {
+ SfxObjectShell* pDoc = reinterpret_cast<SfxObjectShell*>(sal::static_int_cast<sal_IntPtr>( nHandle ));
+ SfxModule* pModule = pDoc->GetFactory().GetModule();
+ pSlot = pModule->GetSlotPool()->GetSlot( nId );
+ }
+ }
+ else
+ pSlot = SfxSlotPool::GetSlotPool().GetSlot( nId );
+
+ if ( pSlot )
+ {
+ aCommandURL = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
+ aCommandURL += rtl::OUString::createFromAscii( pSlot->GetUnoName() );
+ }
+ else
+ aCommandURL = rtl::OUString();
+ }
+
+ Reference< XImageManager > xDocImgMgr;
+ 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( ::com::sun::star::ui::ImageType::COLOR_NORMAL|
+ ::com::sun::star::ui::ImageType::SIZE_DEFAULT );
+ if ( bBig )
+ nImageType |= ::com::sun::star::ui::ImageType::SIZE_LARGE;
+ if ( bHiContrast )
+ nImageType |= ::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(
+ "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(
+ "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 ));
+ }
+
+ 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();
+}