1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unomodule.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 // System - Includes -----------------------------------------------------
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/frame/DispatchResultState.hpp>
39 #include "unomodule.hxx"
40 #include <sfx2/objface.hxx>
41 #include <sfx2/bindings.hxx>
42 #include <sfx2/request.hxx>
43 #include <vos/mutex.hxx>
44 #include <vcl/svapp.hxx>
46 using namespace ::com::sun::star
;
48 ::rtl::OUString SAL_CALL
SdUnoModule_getImplementationName() throw( uno::RuntimeException
)
50 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Draw.DrawingModule" ) );
53 uno::Sequence
< rtl::OUString
> SAL_CALL
SdUnoModule_getSupportedServiceNames() throw( uno::RuntimeException
)
55 uno::Sequence
< rtl::OUString
> aSeq( 1 );
56 aSeq
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ModuleDispatcher"));
60 uno::Reference
< uno::XInterface
> SAL_CALL
SdUnoModule_createInstance(
61 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
63 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
64 return uno::Reference
< uno::XInterface
>( static_cast< cppu::OWeakObject
* >( new SdUnoModule( rSMgr
) ) );
68 void SAL_CALL
SdUnoModule::dispatchWithNotification( const ::com::sun::star::util::URL
& aURL
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
, const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchResultListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
)
70 // there is no guarantee, that we are holded alive during this method!
71 // May the outside dispatch container will be updated by a CONTEXT_CHANGED
73 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> xThis(static_cast< ::com::sun::star::frame::XNotifyingDispatch
* >(this));
75 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
77 const SfxSlot
* pSlot
= SD_MOD()->GetInterface()->GetSlot( aURL
.Complete
);
79 sal_Int16 aState
= ::com::sun::star::frame::DispatchResultState::DONTKNOW
;
81 aState
= ::com::sun::star::frame::DispatchResultState::FAILURE
;
84 SfxRequest
aReq( pSlot
, aArgs
, SFX_CALLMODE_SYNCHRON
, SD_MOD()->GetPool() );
85 const SfxPoolItem
* pResult
= SD_MOD()->ExecuteSlot( aReq
);
87 aState
= ::com::sun::star::frame::DispatchResultState::SUCCESS
;
89 aState
= ::com::sun::star::frame::DispatchResultState::FAILURE
;
94 xListener
->dispatchFinished(
95 ::com::sun::star::frame::DispatchResultEvent(
96 xThis
, aState
, ::com::sun::star::uno::Any()));
100 void SAL_CALL
SdUnoModule::dispatch( const ::com::sun::star::util::URL
& aURL
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
) throw( ::com::sun::star::uno::RuntimeException
)
102 dispatchWithNotification(aURL
, aArgs
, ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatchResultListener
>());
105 void SAL_CALL
SdUnoModule::addStatusListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> &, const ::com::sun::star::util::URL
&) throw( ::com::sun::star::uno::RuntimeException
)
109 void SAL_CALL
SdUnoModule::removeStatusListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XStatusListener
> &, const ::com::sun::star::util::URL
&) throw( ::com::sun::star::uno::RuntimeException
)
113 SEQUENCE
< REFERENCE
< XDISPATCH
> > SAL_CALL
SdUnoModule::queryDispatches( const SEQUENCE
< DISPATCHDESCRIPTOR
>& seqDescripts
) throw( ::com::sun::star::uno::RuntimeException
)
115 sal_Int32 nCount
= seqDescripts
.getLength();
116 SEQUENCE
< REFERENCE
< XDISPATCH
> > lDispatcher( nCount
);
118 for( sal_Int32 i
=0; i
<nCount
; ++i
)
120 lDispatcher
[i
] = queryDispatch( seqDescripts
[i
].FeatureURL
,
121 seqDescripts
[i
].FrameName
,
122 seqDescripts
[i
].SearchFlags
);
129 REFERENCE
< XDISPATCH
> SAL_CALL
SdUnoModule::queryDispatch( const UNOURL
& aURL
, const OUSTRING
&, sal_Int32
) throw( RUNTIMEEXCEPTION
)
131 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
133 const SfxSlot
* pSlot
= SD_MOD()->GetInterface()->GetSlot( aURL
.Complete
);
135 REFERENCE
< XDISPATCH
> xSlot
;
143 ::rtl::OUString SAL_CALL
SdUnoModule::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
)
145 return SdUnoModule_getImplementationName();
148 sal_Bool SAL_CALL
SdUnoModule::supportsService( const ::rtl::OUString
& sServiceName
) throw(::com::sun::star::uno::RuntimeException
)
150 UNOSEQUENCE
< UNOOUSTRING
> seqServiceNames
= getSupportedServiceNames();
151 const UNOOUSTRING
* pArray
= seqServiceNames
.getConstArray();
152 for ( sal_Int32 nCounter
=0; nCounter
<seqServiceNames
.getLength(); nCounter
++ )
154 if ( pArray
[nCounter
] == sServiceName
)
162 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
SdUnoModule::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
)
164 return SdUnoModule_getSupportedServiceNames();