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_sw.hxx" 30 // System - Includes ----------------------------------------------------- 31 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32 #include <com/sun/star/frame/DispatchResultState.hpp> 33 34 #include "swmodule.hxx" 35 #include "swdll.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 SwUnoModule_getImplementationName() throw( uno::RuntimeException ) 46 { 47 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Writer.WriterModule" ) ); 48 } 49 50 uno::Sequence< rtl::OUString > SAL_CALL SwUnoModule_getSupportedServiceNames() throw( uno::RuntimeException ) 51 { 52 uno::Sequence< rtl::OUString > aSeq( 1 ); 53 aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.ModuleDispatcher")); 54 return aSeq; 55 } 56 57 uno::Reference< uno::XInterface > SAL_CALL SwUnoModule_createInstance( 58 const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) 59 { 60 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 61 return uno::Reference< uno::XInterface >( dynamic_cast< frame::XDispatch * >(new SwUnoModule( rSMgr )), uno::UNO_QUERY ); 62 } 63 64 // XNotifyingDispatch 65 void SAL_CALL SwUnoModule::dispatchWithNotification( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs, const uno::Reference< frame::XDispatchResultListener >& xListener ) throw (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 uno::Reference< uno::XInterface > xThis(static_cast< frame::XNotifyingDispatch* >(this)); 71 72 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 73 SwDLL::Init(); 74 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete ); 75 76 sal_Int16 aState = frame::DispatchResultState::DONTKNOW; 77 if ( !pSlot ) 78 aState = frame::DispatchResultState::FAILURE; 79 else 80 { 81 SfxRequest aReq( pSlot, aArgs, SFX_CALLMODE_SYNCHRON, SW_MOD()->GetPool() ); 82 const SfxPoolItem* pResult = SW_MOD()->ExecuteSlot( aReq ); 83 if ( pResult ) 84 aState = frame::DispatchResultState::SUCCESS; 85 else 86 aState = frame::DispatchResultState::FAILURE; 87 } 88 89 if ( xListener.is() ) 90 { 91 xListener->dispatchFinished( 92 frame::DispatchResultEvent( 93 xThis, aState, uno::Any())); 94 } 95 } 96 97 // XDispatch 98 void SAL_CALL SwUnoModule::dispatch( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs ) throw( uno::RuntimeException ) 99 { 100 dispatchWithNotification(aURL, aArgs, uno::Reference< frame::XDispatchResultListener >()); 101 } 102 103 void SAL_CALL SwUnoModule::addStatusListener( 104 const uno::Reference< frame::XStatusListener > & /*xControl*/, 105 const util::URL& /*aURL*/) 106 throw( uno::RuntimeException ) 107 { 108 } 109 110 void SAL_CALL SwUnoModule::removeStatusListener( 111 const uno::Reference< frame::XStatusListener > & /*xControl*/, 112 const util::URL& /*aURL*/) throw( uno::RuntimeException ) 113 { 114 } 115 116 SEQUENCE< REFERENCE< XDISPATCH > > SAL_CALL SwUnoModule::queryDispatches( 117 const SEQUENCE< DISPATCHDESCRIPTOR >& seqDescripts ) throw( uno::RuntimeException ) 118 { 119 sal_Int32 nCount = seqDescripts.getLength(); 120 SEQUENCE< REFERENCE< XDISPATCH > > lDispatcher( nCount ); 121 122 for( sal_Int32 i=0; i<nCount; ++i ) 123 { 124 lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL , 125 seqDescripts[i].FrameName , 126 seqDescripts[i].SearchFlags ); 127 } 128 129 return lDispatcher; 130 } 131 132 // XDispatchProvider 133 REFERENCE< XDISPATCH > SAL_CALL SwUnoModule::queryDispatch( 134 const UNOURL& aURL, const OUSTRING& /*sTargetFrameName*/, 135 sal_Int32 /*eSearchFlags*/ ) throw( uno::RuntimeException ) 136 { 137 REFERENCE< XDISPATCH > xReturn; 138 139 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 140 SwDLL::Init(); 141 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete ); 142 if ( pSlot ) 143 xReturn = REFERENCE< XDISPATCH >(static_cast< XDISPATCH* >(this), uno::UNO_QUERY); 144 145 return xReturn; 146 } 147 148 // XServiceInfo 149 ::rtl::OUString SAL_CALL SwUnoModule::getImplementationName( ) throw(uno::RuntimeException) 150 { 151 return SwUnoModule_getImplementationName(); 152 } 153 154 sal_Bool SAL_CALL SwUnoModule::supportsService( const ::rtl::OUString& sServiceName ) throw(uno::RuntimeException) 155 { 156 UNOSEQUENCE< UNOOUSTRING > seqServiceNames = getSupportedServiceNames(); 157 const UNOOUSTRING* pArray = seqServiceNames.getConstArray(); 158 for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ ) 159 { 160 if ( pArray[nCounter] == sServiceName ) 161 { 162 return sal_True ; 163 } 164 } 165 return sal_False ; 166 } 167 168 uno::Sequence< ::rtl::OUString > SAL_CALL SwUnoModule::getSupportedServiceNames( ) throw(uno::RuntimeException) 169 { 170 return SwUnoModule_getSupportedServiceNames(); 171 } 172 173