1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <recording/dispatchrecordersupplier.hxx>
22 #include <com/sun/star/frame/XRecordableDispatch.hpp>
24 #include <vcl/svapp.hxx>
25 #include <cppuhelper/supportsservice.hxx>
29 // XInterface, XTypeProvider, XServiceInfo
31 OUString SAL_CALL
DispatchRecorderSupplier::getImplementationName()
33 return "com.sun.star.comp.framework.DispatchRecorderSupplier";
36 sal_Bool SAL_CALL
DispatchRecorderSupplier::supportsService( const OUString
& sServiceName
)
38 return cppu::supportsService(this, sServiceName
);
41 css::uno::Sequence
< OUString
> SAL_CALL
DispatchRecorderSupplier::getSupportedServiceNames()
43 return { "com.sun.star.frame.DispatchRecorderSupplier" };
47 DispatchRecorderSupplier::DispatchRecorderSupplier()
52 @short standard destructor
53 @descr We are a helper and not a real service. So we don't provide
54 dispose() functionality. This supplier dies by ref count mechanism
55 and should release all internal used ones too.
57 DispatchRecorderSupplier::~DispatchRecorderSupplier()
59 m_xDispatchRecorder
= nullptr;
63 @short set a new dispatch recorder on this supplier
64 @descr Because there can exist more than one recorder implementations
65 (to generate java/basic/... scripts from recorded data) it must
66 be possible to set it on a supplier.
68 @see getDispatchRecorder()
71 the new recorder to set it
72 <br><NULL/> isn't recommended, because recording without a
73 valid recorder can't work. But it's not checked here. So user
74 of this supplier can decide that without changing this
77 @change 09.04.2002 by Andreas Schluens
79 void SAL_CALL
DispatchRecorderSupplier::setDispatchRecorder( const css::uno::Reference
< css::frame::XDispatchRecorder
>& xRecorder
)
82 m_xDispatchRecorder
=xRecorder
;
86 @short provides access to the dispatch recorder of this supplier
87 @descr Such recorder can be used outside to record dispatches.
88 But normally he is used internally only. Of course he must used
89 from outside to get the recorded data e.g. for saving it as a
92 @see setDispatchRecorder()
94 @return the internal used dispatch recorder
95 <br>May it can be <NULL/> if no one was set before.
97 @change 09.04.2002 by Andreas Schluens
99 css::uno::Reference
< css::frame::XDispatchRecorder
> SAL_CALL
DispatchRecorderSupplier::getDispatchRecorder()
102 return m_xDispatchRecorder
;
106 @short execute a dispatch request and record it
107 @descr If given dispatch object provides right recording interface it
108 will be used. If it's not supported it record the pure dispatch
109 parameters only. There is no code neither the possibility to
110 check if recording is enabled or not.
112 @param aURL the command URL
113 @param lArguments optional arguments (see com.sun.star.document.MediaDescriptor for further information)
114 @param xDispatcher the original dispatch object which should be recorded
116 @change 09.04.2002 by Andreas Schluens
118 void SAL_CALL
DispatchRecorderSupplier::dispatchAndRecord( const css::util::URL
& aURL
,
119 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
120 const css::uno::Reference
< css::frame::XDispatch
>& xDispatcher
)
122 SolarMutexClearableGuard aReadLock
;
123 css::uno::Reference
< css::frame::XDispatchRecorder
> xRecorder
= m_xDispatchRecorder
;
126 // clear unspecific situations
127 if (!xDispatcher
.is())
128 throw css::uno::RuntimeException("specification violation: dispatcher is NULL", static_cast< ::cppu::OWeakObject
* >(this));
131 throw css::uno::RuntimeException("specification violation: no valid dispatch recorder available", static_cast< ::cppu::OWeakObject
* >(this));
133 // check, if given dispatch supports record functionality by itself ...
134 // or must be wrapped.
135 css::uno::Reference
< css::frame::XRecordableDispatch
> xRecordable(
137 css::uno::UNO_QUERY
);
139 if (xRecordable
.is())
140 xRecordable
->dispatchAndRecord(aURL
,lArguments
,xRecorder
);
143 // There is no reason to wait for information about success
144 // of this request. Because status information of a dispatch
145 // are not guaranteed. So we execute it and record used
147 xDispatcher
->dispatch(aURL
,lArguments
);
148 xRecorder
->recordDispatch(aURL
,lArguments
);
152 } // namespace framework
154 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
155 framework_DispatchRecorderSupplier_get_implementation(
156 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const& )
158 return cppu::acquire(new framework::DispatchRecorderSupplier());
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */