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