1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sd.hxx" 30 31 // System - Includes ----------------------------------------------------- 32 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 33 #include <com/sun/star/frame/DispatchResultState.hpp> 34 35 #include "sdmod.hxx" 36 #include "unomodule.hxx" 37 #include <sfx2/objface.hxx> 38 #include <sfx2/bindings.hxx> 39 #include <sfx2/request.hxx> 40 #include <vos/mutex.hxx> 41 #include <vcl/svapp.hxx> 42 43 using namespace ::com::sun::star; 44 45 ::rtl::OUString SAL_CALL SdUnoModule_getImplementationName() throw( uno::RuntimeException ) 46 { 47 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Draw.DrawingModule" ) ); 48 } 49 50 uno::Sequence< rtl::OUString > SAL_CALL SdUnoModule_getSupportedServiceNames() throw( uno::RuntimeException ) 51 { 52 uno::Sequence< rtl::OUString > aSeq( 1 ); 53 aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ModuleDispatcher")); 54 return aSeq; 55 } 56 57 uno::Reference< uno::XInterface > SAL_CALL SdUnoModule_createInstance( 58 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) 59 { 60 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 61 return uno::Reference< uno::XInterface >( static_cast< cppu::OWeakObject* >( new SdUnoModule( rSMgr ) ) ); 62 } 63 64 // XNotifyingDispatch 65 void SAL_CALL SdUnoModule::dispatchWithNotification( const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 66 { 67 // there is no guarantee, that we are holded alive during this method! 68 // May the outside dispatch container will be updated by a CONTEXT_CHANGED 69 // asynchronous ... 70 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xThis(static_cast< ::com::sun::star::frame::XNotifyingDispatch* >(this)); 71 72 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 73 SdDLL::Init(); 74 const SfxSlot* pSlot = SD_MOD()->GetInterface()->GetSlot( aURL.Complete ); 75 76 sal_Int16 aState = ::com::sun::star::frame::DispatchResultState::DONTKNOW; 77 if ( !pSlot ) 78 aState = ::com::sun::star::frame::DispatchResultState::FAILURE; 79 else 80 { 81 SfxRequest aReq( pSlot, aArgs, SFX_CALLMODE_SYNCHRON, SD_MOD()->GetPool() ); 82 const SfxPoolItem* pResult = SD_MOD()->ExecuteSlot( aReq ); 83 if ( pResult ) 84 aState = ::com::sun::star::frame::DispatchResultState::SUCCESS; 85 else 86 aState = ::com::sun::star::frame::DispatchResultState::FAILURE; 87 } 88 89 if ( xListener.is() ) 90 { 91 xListener->dispatchFinished( 92 ::com::sun::star::frame::DispatchResultEvent( 93 xThis, aState, ::com::sun::star::uno::Any())); 94 } 95 } 96 // XDispatch 97 void SAL_CALL SdUnoModule::dispatch( const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) throw( ::com::sun::star::uno::RuntimeException ) 98 { 99 dispatchWithNotification(aURL, aArgs, ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >()); 100 } 101 102 void SAL_CALL SdUnoModule::addStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > &, const ::com::sun::star::util::URL&) throw( ::com::sun::star::uno::RuntimeException ) 103 { 104 } 105 106 void SAL_CALL SdUnoModule::removeStatusListener(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener > &, const ::com::sun::star::util::URL&) throw( ::com::sun::star::uno::RuntimeException ) 107 { 108 } 109 110 SEQUENCE< REFERENCE< XDISPATCH > > SAL_CALL SdUnoModule::queryDispatches( const SEQUENCE< DISPATCHDESCRIPTOR >& seqDescripts ) throw( ::com::sun::star::uno::RuntimeException ) 111 { 112 sal_Int32 nCount = seqDescripts.getLength(); 113 SEQUENCE< REFERENCE< XDISPATCH > > lDispatcher( nCount ); 114 115 for( sal_Int32 i=0; i<nCount; ++i ) 116 { 117 lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL , 118 seqDescripts[i].FrameName , 119 seqDescripts[i].SearchFlags ); 120 } 121 122 return lDispatcher; 123 } 124 125 // XDispatchProvider 126 REFERENCE< XDISPATCH > SAL_CALL SdUnoModule::queryDispatch( const UNOURL& aURL, const OUSTRING&, sal_Int32 ) throw( RUNTIMEEXCEPTION ) 127 { 128 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 129 SdDLL::Init(); 130 const SfxSlot* pSlot = SD_MOD()->GetInterface()->GetSlot( aURL.Complete ); 131 132 REFERENCE< XDISPATCH > xSlot; 133 if ( pSlot ) 134 xSlot = this; 135 136 return xSlot; 137 } 138 139 // XServiceInfo 140 ::rtl::OUString SAL_CALL SdUnoModule::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException) 141 { 142 return SdUnoModule_getImplementationName(); 143 } 144 145 sal_Bool SAL_CALL SdUnoModule::supportsService( const ::rtl::OUString& sServiceName ) throw(::com::sun::star::uno::RuntimeException) 146 { 147 UNOSEQUENCE< UNOOUSTRING > seqServiceNames = getSupportedServiceNames(); 148 const UNOOUSTRING* pArray = seqServiceNames.getConstArray(); 149 for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ ) 150 { 151 if ( pArray[nCounter] == sServiceName ) 152 { 153 return sal_True ; 154 } 155 } 156 return sal_False ; 157 } 158 159 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL SdUnoModule::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) 160 { 161 return SdUnoModule_getSupportedServiceNames(); 162 } 163 164