update credits
[LibreOffice.git] / sw / source / ui / uno / unomodule.cxx
blob815a2bb82cc2b5b1e20ee375580b5685b5febc30
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
21 #include <com/sun/star/frame/DispatchResultState.hpp>
23 #include "swmodule.hxx"
24 #include "swdll.hxx"
25 #include "unomodule.hxx"
26 #include <sfx2/objface.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <sfx2/request.hxx>
29 #include <osl/mutex.hxx>
30 #include <vcl/svapp.hxx>
32 using namespace css;
34 OUString SAL_CALL SwUnoModule_getImplementationName() throw( uno::RuntimeException )
36 return OUString( "com.sun.star.comp.Writer.WriterModule" );
39 uno::Sequence< OUString > SAL_CALL SwUnoModule_getSupportedServiceNames() throw( uno::RuntimeException )
41 uno::Sequence< OUString > aSeq( 1 );
42 aSeq[0] = OUString("com.sun.star.text.ModuleDispatcher");
43 return aSeq;
46 uno::Reference< uno::XInterface > SAL_CALL SwUnoModule_createInstance(
47 const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
49 SolarMutexGuard aGuard;
50 return uno::Reference< uno::XInterface >( dynamic_cast< frame::XDispatch * >(new SwUnoModule( rSMgr )), uno::UNO_QUERY );
53 // XNotifyingDispatch
54 void SAL_CALL SwUnoModule::dispatchWithNotification( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs, const uno::Reference< frame::XDispatchResultListener >& xListener ) throw (uno::RuntimeException)
56 // there is no guarantee, that we are holded alive during this method!
57 // May the outside dispatch container will be updated by a CONTEXT_CHANGED
58 // asynchronous ...
59 uno::Reference< uno::XInterface > xThis(static_cast< frame::XNotifyingDispatch* >(this));
61 SolarMutexGuard aGuard;
62 SwGlobals::ensure();
63 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
65 sal_Int16 aState = frame::DispatchResultState::DONTKNOW;
66 if ( !pSlot )
67 aState = frame::DispatchResultState::FAILURE;
68 else
70 SfxRequest aReq( pSlot, aArgs, SFX_CALLMODE_SYNCHRON, SW_MOD()->GetPool() );
71 const SfxPoolItem* pResult = SW_MOD()->ExecuteSlot( aReq );
72 if ( pResult )
73 aState = frame::DispatchResultState::SUCCESS;
74 else
75 aState = frame::DispatchResultState::FAILURE;
78 if ( xListener.is() )
80 xListener->dispatchFinished(
81 frame::DispatchResultEvent(
82 xThis, aState, uno::Any()));
86 // XDispatch
87 void SAL_CALL SwUnoModule::dispatch( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs ) throw( uno::RuntimeException )
89 dispatchWithNotification(aURL, aArgs, uno::Reference< frame::XDispatchResultListener >());
92 void SAL_CALL SwUnoModule::addStatusListener(
93 const uno::Reference< frame::XStatusListener > & /*xControl*/,
94 const util::URL& /*aURL*/)
95 throw( uno::RuntimeException )
99 void SAL_CALL SwUnoModule::removeStatusListener(
100 const uno::Reference< frame::XStatusListener > & /*xControl*/,
101 const util::URL& /*aURL*/) throw( uno::RuntimeException )
105 uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL SwUnoModule::queryDispatches(
106 const uno::Sequence< frame::DispatchDescriptor >& seqDescripts ) throw( uno::RuntimeException )
108 sal_Int32 nCount = seqDescripts.getLength();
109 uno::Sequence< uno::Reference< frame::XDispatch > > lDispatcher( nCount );
111 for( sal_Int32 i=0; i<nCount; ++i )
113 lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL ,
114 seqDescripts[i].FrameName ,
115 seqDescripts[i].SearchFlags );
118 return lDispatcher;
121 // XDispatchProvider
122 uno::Reference< frame::XDispatch > SAL_CALL SwUnoModule::queryDispatch(
123 const util::URL& aURL, const OUString& /*sTargetFrameName*/,
124 sal_Int32 /*eSearchFlags*/ ) throw( uno::RuntimeException )
126 uno::Reference< frame::XDispatch > xReturn;
128 SolarMutexGuard aGuard;
129 SwGlobals::ensure();
130 const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
131 if ( pSlot )
132 xReturn = uno::Reference< frame::XDispatch >(static_cast< frame::XDispatch* >(this), uno::UNO_QUERY);
134 return xReturn;
137 // XServiceInfo
138 OUString SAL_CALL SwUnoModule::getImplementationName( ) throw(uno::RuntimeException)
140 return SwUnoModule_getImplementationName();
143 sal_Bool SAL_CALL SwUnoModule::supportsService( const OUString& sServiceName ) throw(uno::RuntimeException)
145 uno::Sequence< OUString > seqServiceNames = getSupportedServiceNames();
146 const OUString* pArray = seqServiceNames.getConstArray();
147 for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ )
149 if ( pArray[nCounter] == sServiceName )
151 return sal_True ;
154 return sal_False ;
157 uno::Sequence< OUString > SAL_CALL SwUnoModule::getSupportedServiceNames( ) throw(uno::RuntimeException)
159 return SwUnoModule_getSupportedServiceNames();
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */