1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sd.hxx" 26 27 // System - Includes ----------------------------------------------------- 28 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 29 #include <com/sun/star/frame/DispatchResultState.hpp> 30 31 #include "sdmod.hxx" 32 #include "unomodule.hxx" 33 #include <sfx2/objface.hxx> 34 #include <sfx2/bindings.hxx> 35 #include <sfx2/request.hxx> 36 #include <vos/mutex.hxx> 37 #include <vcl/svapp.hxx> 38 39 using namespace ::com::sun::star; 40 41 ::rtl::OUString SAL_CALL SdUnoModule_getImplementationName() throw( uno::RuntimeException ) 42 { 43 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Draw.DrawingModule" ) ); 44 } 45 46 uno::Sequence< rtl::OUString > SAL_CALL SdUnoModule_getSupportedServiceNames() throw( uno::RuntimeException ) 47 { 48 uno::Sequence< rtl::OUString > aSeq( 1 ); 49 aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ModuleDispatcher")); 50 return aSeq; 51 } 52 53 uno::Reference< uno::XInterface > SAL_CALL SdUnoModule_createInstance( 54 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) 55 { 56 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 57 return uno::Reference< uno::XInterface >( static_cast< cppu::OWeakObject* >( new SdUnoModule( rSMgr ) ) ); 58 } 59 60 // XNotifyingDispatch 61 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) 62 { 63 // there is no guarantee, that we are holded alive during this method! 64 // May the outside dispatch container will be updated by a CONTEXT_CHANGED 65 // asynchronous ... 66 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xThis(static_cast< ::com::sun::star::frame::XNotifyingDispatch* >(this)); 67 68 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 69 SdDLL::Init(); 70 const SfxSlot* pSlot = SD_MOD()->GetInterface()->GetSlot( aURL.Complete ); 71 72 sal_Int16 aState = ::com::sun::star::frame::DispatchResultState::DONTKNOW; 73 if ( !pSlot ) 74 aState = ::com::sun::star::frame::DispatchResultState::FAILURE; 75 else 76 { 77 SfxRequest aReq( pSlot, aArgs, SFX_CALLMODE_SYNCHRON, SD_MOD()->GetPool() ); 78 const SfxPoolItem* pResult = SD_MOD()->ExecuteSlot( aReq ); 79 if ( pResult ) 80 aState = ::com::sun::star::frame::DispatchResultState::SUCCESS; 81 else 82 aState = ::com::sun::star::frame::DispatchResultState::FAILURE; 83 } 84 85 if ( xListener.is() ) 86 { 87 xListener->dispatchFinished( 88 ::com::sun::star::frame::DispatchResultEvent( 89 xThis, aState, ::com::sun::star::uno::Any())); 90 } 91 } 92 // XDispatch 93 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 ) 94 { 95 dispatchWithNotification(aURL, aArgs, ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchResultListener >()); 96 } 97 98 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 ) 99 { 100 } 101 102 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 ) 103 { 104 } 105 106 SEQUENCE< REFERENCE< XDISPATCH > > SAL_CALL SdUnoModule::queryDispatches( const SEQUENCE< DISPATCHDESCRIPTOR >& seqDescripts ) throw( ::com::sun::star::uno::RuntimeException ) 107 { 108 sal_Int32 nCount = seqDescripts.getLength(); 109 SEQUENCE< REFERENCE< XDISPATCH > > lDispatcher( nCount ); 110 111 for( sal_Int32 i=0; i<nCount; ++i ) 112 { 113 lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL , 114 seqDescripts[i].FrameName , 115 seqDescripts[i].SearchFlags ); 116 } 117 118 return lDispatcher; 119 } 120 121 // XDispatchProvider 122 REFERENCE< XDISPATCH > SAL_CALL SdUnoModule::queryDispatch( const UNOURL& aURL, const OUSTRING&, sal_Int32 ) throw( RUNTIMEEXCEPTION ) 123 { 124 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 125 SdDLL::Init(); 126 const SfxSlot* pSlot = SD_MOD()->GetInterface()->GetSlot( aURL.Complete ); 127 128 REFERENCE< XDISPATCH > xSlot; 129 if ( pSlot ) 130 xSlot = this; 131 132 return xSlot; 133 } 134 135 // XServiceInfo 136 ::rtl::OUString SAL_CALL SdUnoModule::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException) 137 { 138 return SdUnoModule_getImplementationName(); 139 } 140 141 sal_Bool SAL_CALL SdUnoModule::supportsService( const ::rtl::OUString& sServiceName ) throw(::com::sun::star::uno::RuntimeException) 142 { 143 UNOSEQUENCE< UNOOUSTRING > seqServiceNames = getSupportedServiceNames(); 144 const UNOOUSTRING* pArray = seqServiceNames.getConstArray(); 145 for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ ) 146 { 147 if ( pArray[nCounter] == sServiceName ) 148 { 149 return sal_True ; 150 } 151 } 152 return sal_False ; 153 } 154 155 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL SdUnoModule::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) 156 { 157 return SdUnoModule_getSupportedServiceNames(); 158 } 159 160