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 : #include <cppuhelper/supportsservice.hxx>
23 :
24 : #include "facreg.hxx"
25 : #include "sddll.hxx"
26 : #include "sdmod.hxx"
27 : #include "unomodule.hxx"
28 : #include <sfx2/objface.hxx>
29 : #include <sfx2/bindings.hxx>
30 : #include <sfx2/request.hxx>
31 : #include <osl/mutex.hxx>
32 : #include <vcl/svapp.hxx>
33 :
34 : using namespace ::com::sun::star;
35 :
36 36 : OUString SAL_CALL SdUnoModule_getImplementationName() throw( uno::RuntimeException )
37 : {
38 36 : return OUString( "com.sun.star.comp.Draw.DrawingModule" );
39 : }
40 :
41 2 : uno::Sequence< OUString > SAL_CALL SdUnoModule_getSupportedServiceNames() throw( uno::RuntimeException )
42 : {
43 2 : uno::Sequence< OUString > aSeq( 1 );
44 2 : aSeq[0] = "com.sun.star.drawing.ModuleDispatcher";
45 2 : return aSeq;
46 : }
47 :
48 2 : uno::Reference< uno::XInterface > SAL_CALL SdUnoModule_createInstance(
49 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr )
50 : {
51 2 : SolarMutexGuard aGuard;
52 2 : return uno::Reference< uno::XInterface >( static_cast< cppu::OWeakObject* >( new SdUnoModule( rSMgr ) ) );
53 : }
54 :
55 : // XNotifyingDispatch
56 0 : void SAL_CALL SdUnoModule::dispatchWithNotification( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs, const uno::Reference< frame::XDispatchResultListener >& xListener )
57 : throw (uno::RuntimeException, std::exception)
58 : {
59 : // there is no guarantee, that we are holded alive during this method!
60 : // May the outside dispatch container will be updated by a CONTEXT_CHANGED
61 : // asynchronous ...
62 0 : uno::Reference< uno::XInterface > xThis(static_cast< frame::XNotifyingDispatch* >(this));
63 :
64 0 : SolarMutexGuard aGuard;
65 0 : SdDLL::Init();
66 0 : const SfxSlot* pSlot = SD_MOD()->GetInterface()->GetSlot( aURL.Complete );
67 :
68 0 : sal_Int16 aState = frame::DispatchResultState::DONTKNOW;
69 0 : if ( !pSlot )
70 0 : aState = frame::DispatchResultState::FAILURE;
71 : else
72 : {
73 0 : SfxRequest aReq( pSlot, aArgs, SfxCallMode::SYNCHRON, SD_MOD()->GetPool() );
74 0 : const SfxPoolItem* pResult = SD_MOD()->ExecuteSlot( aReq );
75 0 : if ( pResult )
76 0 : aState = frame::DispatchResultState::SUCCESS;
77 : else
78 0 : aState = frame::DispatchResultState::FAILURE;
79 : }
80 :
81 0 : if ( xListener.is() )
82 : {
83 0 : xListener->dispatchFinished(
84 : frame::DispatchResultEvent(
85 0 : xThis, aState, uno::Any()));
86 0 : }
87 0 : }
88 : // XDispatch
89 0 : void SAL_CALL SdUnoModule::dispatch( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& aArgs ) throw( uno::RuntimeException, std::exception )
90 : {
91 0 : dispatchWithNotification(aURL, aArgs, uno::Reference< frame::XDispatchResultListener >());
92 0 : }
93 :
94 0 : void SAL_CALL SdUnoModule::addStatusListener(const uno::Reference< frame::XStatusListener > &, const util::URL&) throw( uno::RuntimeException, std::exception )
95 : {
96 0 : }
97 :
98 0 : void SAL_CALL SdUnoModule::removeStatusListener(const uno::Reference< frame::XStatusListener > &, const util::URL&) throw( uno::RuntimeException, std::exception )
99 : {
100 0 : }
101 :
102 0 : uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL SdUnoModule::queryDispatches( const uno::Sequence< frame::DispatchDescriptor >& seqDescripts ) throw( uno::RuntimeException, std::exception )
103 : {
104 0 : sal_Int32 nCount = seqDescripts.getLength();
105 0 : uno::Sequence< uno::Reference< frame::XDispatch > > lDispatcher( nCount );
106 :
107 0 : for( sal_Int32 i=0; i<nCount; ++i )
108 : {
109 0 : lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL ,
110 0 : seqDescripts[i].FrameName ,
111 0 : seqDescripts[i].SearchFlags );
112 : }
113 :
114 0 : return lDispatcher;
115 : }
116 :
117 : // XDispatchProvider
118 0 : uno::Reference< frame::XDispatch > SAL_CALL SdUnoModule::queryDispatch( const util::URL& aURL, const OUString&, sal_Int32 )
119 : throw (uno::RuntimeException, std::exception)
120 : {
121 0 : SolarMutexGuard aGuard;
122 0 : SdDLL::Init();
123 0 : const SfxSlot* pSlot = SD_MOD()->GetInterface()->GetSlot( aURL.Complete );
124 :
125 0 : uno::Reference< frame::XDispatch > xSlot;
126 0 : if ( pSlot )
127 0 : xSlot = this;
128 :
129 0 : return xSlot;
130 : }
131 :
132 : // XServiceInfo
133 0 : OUString SAL_CALL SdUnoModule::getImplementationName( ) throw(uno::RuntimeException, std::exception)
134 : {
135 0 : return SdUnoModule_getImplementationName();
136 : }
137 :
138 0 : sal_Bool SAL_CALL SdUnoModule::supportsService( const OUString& sServiceName ) throw(uno::RuntimeException, std::exception)
139 : {
140 0 : return cppu::supportsService(this, sServiceName);
141 : }
142 :
143 0 : uno::Sequence< OUString > SAL_CALL SdUnoModule::getSupportedServiceNames( ) throw(uno::RuntimeException, std::exception)
144 : {
145 0 : return SdUnoModule_getSupportedServiceNames();
146 114 : }
147 :
148 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|