Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
21 : #include <com/sun/star/frame/DispatchResultState.hpp>
22 :
23 : #include "swmodule.hxx"
24 : #include "swdll.hxx"
25 : #include "unomodule.hxx"
26 : #include <cppuhelper/supportsservice.hxx>
27 : #include <sfx2/objface.hxx>
28 : #include <sfx2/bindings.hxx>
29 : #include <sfx2/request.hxx>
30 : #include <osl/mutex.hxx>
31 : #include <vcl/svapp.hxx>
32 :
33 : using namespace css;
34 :
35 0 : OUString SAL_CALL SwUnoModule_getImplementationName() throw( uno::RuntimeException )
36 : {
37 0 : return OUString( "com.sun.star.comp.Writer.WriterModule" );
38 : }
39 :
40 0 : uno::Sequence< OUString > SAL_CALL SwUnoModule_getSupportedServiceNames() throw( uno::RuntimeException )
41 : {
42 0 : uno::Sequence< OUString > aSeq( 1 );
43 0 : aSeq[0] = "com.sun.star.text.ModuleDispatcher";
44 0 : return aSeq;
45 : }
46 :
47 0 : uno::Reference< uno::XInterface > SAL_CALL SwUnoModule_createInstance(
48 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
49 : {
50 0 : SolarMutexGuard aGuard;
51 0 : return uno::Reference< uno::XInterface >( dynamic_cast< frame::XDispatch * >(new SwUnoModule( rSMgr )), uno::UNO_QUERY );
52 : }
53 :
54 : // XNotifyingDispatch
55 0 : void SAL_CALL SwUnoModule::dispatchWithNotification( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs, const uno::Reference< frame::XDispatchResultListener >& xListener ) throw (uno::RuntimeException, std::exception)
56 : {
57 : // there is no guarantee, that we are holded alive during this method!
58 : // May the outside dispatch container will be updated by a CONTEXT_CHANGED
59 : // asynchronous ...
60 0 : uno::Reference< uno::XInterface > xThis(static_cast< frame::XNotifyingDispatch* >(this));
61 :
62 0 : SolarMutexGuard aGuard;
63 0 : SwGlobals::ensure();
64 0 : const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
65 :
66 0 : sal_Int16 aState = frame::DispatchResultState::DONTKNOW;
67 0 : if ( !pSlot )
68 0 : aState = frame::DispatchResultState::FAILURE;
69 : else
70 : {
71 0 : SfxRequest aReq( pSlot, aArgs, SFX_CALLMODE_SYNCHRON, SW_MOD()->GetPool() );
72 0 : const SfxPoolItem* pResult = SW_MOD()->ExecuteSlot( aReq );
73 0 : if ( pResult )
74 0 : aState = frame::DispatchResultState::SUCCESS;
75 : else
76 0 : aState = frame::DispatchResultState::FAILURE;
77 : }
78 :
79 0 : if ( xListener.is() )
80 : {
81 0 : xListener->dispatchFinished(
82 : frame::DispatchResultEvent(
83 0 : xThis, aState, uno::Any()));
84 0 : }
85 0 : }
86 :
87 : // XDispatch
88 0 : void SAL_CALL SwUnoModule::dispatch( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs ) throw( uno::RuntimeException, std::exception )
89 : {
90 0 : dispatchWithNotification(aURL, aArgs, uno::Reference< frame::XDispatchResultListener >());
91 0 : }
92 :
93 0 : void SAL_CALL SwUnoModule::addStatusListener(
94 : const uno::Reference< frame::XStatusListener > & /*xControl*/,
95 : const util::URL& /*aURL*/)
96 : throw( uno::RuntimeException, std::exception )
97 : {
98 0 : }
99 :
100 0 : void SAL_CALL SwUnoModule::removeStatusListener(
101 : const uno::Reference< frame::XStatusListener > & /*xControl*/,
102 : const util::URL& /*aURL*/) throw( uno::RuntimeException, std::exception )
103 : {
104 0 : }
105 :
106 0 : uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL SwUnoModule::queryDispatches(
107 : const uno::Sequence< frame::DispatchDescriptor >& seqDescripts ) throw( uno::RuntimeException, std::exception )
108 : {
109 0 : sal_Int32 nCount = seqDescripts.getLength();
110 0 : uno::Sequence< uno::Reference< frame::XDispatch > > lDispatcher( nCount );
111 :
112 0 : for( sal_Int32 i=0; i<nCount; ++i )
113 : {
114 0 : lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL ,
115 0 : seqDescripts[i].FrameName ,
116 0 : seqDescripts[i].SearchFlags );
117 : }
118 :
119 0 : return lDispatcher;
120 : }
121 :
122 : // XDispatchProvider
123 0 : uno::Reference< frame::XDispatch > SAL_CALL SwUnoModule::queryDispatch(
124 : const util::URL& aURL, const OUString& /*sTargetFrameName*/,
125 : sal_Int32 /*eSearchFlags*/ ) throw( uno::RuntimeException, std::exception )
126 : {
127 0 : uno::Reference< frame::XDispatch > xReturn;
128 :
129 0 : SolarMutexGuard aGuard;
130 0 : SwGlobals::ensure();
131 0 : const SfxSlot* pSlot = SW_MOD()->GetInterface()->GetSlot( aURL.Complete );
132 0 : if ( pSlot )
133 0 : xReturn = uno::Reference< frame::XDispatch >(static_cast< frame::XDispatch* >(this), uno::UNO_QUERY);
134 :
135 0 : return xReturn;
136 : }
137 :
138 : // XServiceInfo
139 0 : OUString SAL_CALL SwUnoModule::getImplementationName( ) throw(uno::RuntimeException, std::exception)
140 : {
141 0 : return SwUnoModule_getImplementationName();
142 : }
143 :
144 0 : sal_Bool SAL_CALL SwUnoModule::supportsService( const OUString& sServiceName ) throw(uno::RuntimeException, std::exception)
145 : {
146 0 : return cppu::supportsService(this, sServiceName);
147 : }
148 :
149 0 : uno::Sequence< OUString > SAL_CALL SwUnoModule::getSupportedServiceNames( ) throw(uno::RuntimeException, std::exception)
150 : {
151 0 : return SwUnoModule_getSupportedServiceNames();
152 : }
153 :
154 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|