Update ooo320-m1
[ooovba.git] / sw / source / ui / uno / unomodule.cxx
blob43a3e0995be99a3e5c6463e65ff356ef62b5ccfd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unomodule.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 // System - Includes -----------------------------------------------------
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/frame/DispatchResultState.hpp>
37 #include "swmodule.hxx"
38 #include "swdll.hxx"
39 #include "unomodule.hxx"
40 #include <sfx2/objface.hxx>
41 #include <sfx2/bindings.hxx>
42 #include <sfx2/request.hxx>
43 #include <vos/mutex.hxx>
44 #include <vcl/svapp.hxx>
46 using namespace ::com::sun::star;
48 ::rtl::OUString SAL_CALL SwUnoModule_getImplementationName() throw( uno::RuntimeException )
50 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Writer.WriterModule" ) );
53 uno::Sequence< rtl::OUString > SAL_CALL SwUnoModule_getSupportedServiceNames() throw( uno::RuntimeException )
55 uno::Sequence< rtl::OUString > aSeq( 1 );
56 aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.ModuleDispatcher"));
57 return aSeq;
60 uno::Reference< uno::XInterface > SAL_CALL SwUnoModule_createInstance(
61 const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
63 ::vos::OGuard aGuard( Application::GetSolarMutex() );
64 return uno::Reference< uno::XInterface >( dynamic_cast< frame::XDispatch * >(new SwUnoModule( rSMgr )), uno::UNO_QUERY );
67 // XNotifyingDispatch
68 void SAL_CALL SwUnoModule::dispatchWithNotification( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs, const uno::Reference< frame::XDispatchResultListener >& xListener ) throw (uno::RuntimeException)
70 // there is no guarantee, that we are holded alive during this method!
71 // May the outside dispatch container will be updated by a CONTEXT_CHANGED
72 // asynchronous ...
73 uno::Reference< uno::XInterface > xThis(static_cast< frame::XNotifyingDispatch* >(this));
75 ::vos::OGuard aGuard( Application::GetSolarMutex() );
76 SwDLL::Init();
77 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
79 sal_Int16 aState = frame::DispatchResultState::DONTKNOW;
80 if ( !pSlot )
81 aState = frame::DispatchResultState::FAILURE;
82 else
84 SfxRequest aReq( pSlot, aArgs, SFX_CALLMODE_SYNCHRON, SW_MOD()->GetPool() );
85 const SfxPoolItem* pResult = SW_MOD()->ExecuteSlot( aReq );
86 if ( pResult )
87 aState = frame::DispatchResultState::SUCCESS;
88 else
89 aState = frame::DispatchResultState::FAILURE;
92 if ( xListener.is() )
94 xListener->dispatchFinished(
95 frame::DispatchResultEvent(
96 xThis, aState, uno::Any()));
100 // XDispatch
101 void SAL_CALL SwUnoModule::dispatch( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs ) throw( uno::RuntimeException )
103 dispatchWithNotification(aURL, aArgs, uno::Reference< frame::XDispatchResultListener >());
106 void SAL_CALL SwUnoModule::addStatusListener(
107 const uno::Reference< frame::XStatusListener > & /*xControl*/,
108 const util::URL& /*aURL*/)
109 throw( uno::RuntimeException )
113 void SAL_CALL SwUnoModule::removeStatusListener(
114 const uno::Reference< frame::XStatusListener > & /*xControl*/,
115 const util::URL& /*aURL*/) throw( uno::RuntimeException )
119 SEQUENCE< REFERENCE< XDISPATCH > > SAL_CALL SwUnoModule::queryDispatches(
120 const SEQUENCE< DISPATCHDESCRIPTOR >& seqDescripts ) throw( uno::RuntimeException )
122 sal_Int32 nCount = seqDescripts.getLength();
123 SEQUENCE< REFERENCE< XDISPATCH > > lDispatcher( nCount );
125 for( sal_Int32 i=0; i<nCount; ++i )
127 lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL ,
128 seqDescripts[i].FrameName ,
129 seqDescripts[i].SearchFlags );
132 return lDispatcher;
135 // XDispatchProvider
136 REFERENCE< XDISPATCH > SAL_CALL SwUnoModule::queryDispatch(
137 const UNOURL& aURL, const OUSTRING& /*sTargetFrameName*/,
138 sal_Int32 /*eSearchFlags*/ ) throw( uno::RuntimeException )
140 REFERENCE< XDISPATCH > xReturn;
142 ::vos::OGuard aGuard( Application::GetSolarMutex() );
143 SwDLL::Init();
144 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
145 if ( pSlot )
146 xReturn = REFERENCE< XDISPATCH >(static_cast< XDISPATCH* >(this), uno::UNO_QUERY);
148 return xReturn;
151 // XServiceInfo
152 ::rtl::OUString SAL_CALL SwUnoModule::getImplementationName( ) throw(uno::RuntimeException)
154 return SwUnoModule_getImplementationName();
157 sal_Bool SAL_CALL SwUnoModule::supportsService( const ::rtl::OUString& sServiceName ) throw(uno::RuntimeException)
159 UNOSEQUENCE< UNOOUSTRING > seqServiceNames = getSupportedServiceNames();
160 const UNOOUSTRING* pArray = seqServiceNames.getConstArray();
161 for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ )
163 if ( pArray[nCounter] == sServiceName )
165 return sal_True ;
168 return sal_False ;
171 uno::Sequence< ::rtl::OUString > SAL_CALL SwUnoModule::getSupportedServiceNames( ) throw(uno::RuntimeException)
173 return SwUnoModule_getSupportedServiceNames();