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