LibreOffice Module uui (master) 1
interactionhandler.cxx
Go to the documentation of this file.
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 <memory>
21#include <sal/config.h>
22#include <osl/diagnose.h>
23
24#include <com/sun/star/awt/XWindow.hpp>
25#include <com/sun/star/beans/XPropertySet.hpp>
26#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
27#include <com/sun/star/lang/XInitialization.hpp>
28#include <com/sun/star/lang/XServiceInfo.hpp>
29#include <com/sun/star/task/XInteractionHandler2.hpp>
30#include <com/sun/star/uno/RuntimeException.hpp>
31
32#include "iahndl.hxx"
37
38using namespace com::sun::star;
39
40namespace {
41
42class UUIInteractionHandler:
43 public cppu::WeakImplHelper<css::lang::XServiceInfo,
44 css::lang::XInitialization,
45 css::task::XInteractionHandler2,
46 css::beans::XPropertySet>
47{
48private:
50
51public:
52 explicit UUIInteractionHandler(css::uno::Reference< css::uno::XComponentContext > const & rxContext);
53
54 UUIInteractionHandler(const UUIInteractionHandler&) = delete;
55 UUIInteractionHandler& operator=(const UUIInteractionHandler&) = delete;
56
57 virtual OUString SAL_CALL getImplementationName() override;
58
59 virtual sal_Bool SAL_CALL supportsService(OUString const & rServiceName) override;
60
61 virtual css::uno::Sequence< OUString > SAL_CALL
62 getSupportedServiceNames() override;
63
64 virtual void SAL_CALL
65 initialize(
66 css::uno::Sequence< css::uno::Any > const & rArguments) override;
67
68 virtual void SAL_CALL
69 handle(css::uno::Reference< css::task::XInteractionRequest > const & rRequest) override;
70
71 virtual sal_Bool SAL_CALL
73 const css::uno::Reference< css::task::XInteractionRequest >& Request
74 ) override;
75
76 virtual void SAL_CALL
77 addPropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ ) override
78 {
79 throw css::uno::RuntimeException(
80 "UUIInteractionHandler addPropertyChangeListener is not supported");
81 }
82
83 virtual void SAL_CALL
84 removePropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ ) override
85 {
86 throw css::uno::RuntimeException(
87 "UUIInteractionHandler removePropertyChangeListener is not supported");
88 }
89
90 virtual void SAL_CALL
91 addVetoableChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*xListener*/ ) override
92 {
93 throw css::uno::RuntimeException(
94 "UUIInteractionHandler addVetoableChangeListener is not supported");
95 }
96
97 virtual void SAL_CALL
98 removeVetoableChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*xListener*/ ) override
99 {
100 throw css::uno::RuntimeException(
101 "UUIInteractionHandler removeVetoableChangeListener is not supported");
102 }
103
104 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
105 getPropertySetInfo() override
106 {
107 return nullptr;
108 }
109
110 virtual void SAL_CALL setPropertyValue(const OUString& rPropertyName, const css::uno::Any& rValue) override
111 {
112 if (rPropertyName == "ParentWindow")
113 {
114 css::uno::Reference<css::awt::XWindow> xWindow;
115 rValue >>= xWindow;
116 m_pImpl.SetParentWindow(xWindow);
117 return;
118 }
119 throw css::beans::UnknownPropertyException(rPropertyName);
120 }
121
122 virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& rPropertyName) override
123 {
124 if (rPropertyName == "ParentWindow")
125 {
126 return uno::Any(m_pImpl.GetParentWindow());
127 }
128 throw css::beans::UnknownPropertyException(rPropertyName);
129 }
130};
131
132UUIInteractionHandler::UUIInteractionHandler(
133 uno::Reference< uno::XComponentContext > const & rxContext)
134 : m_pImpl(rxContext)
135{
136}
137
138OUString SAL_CALL UUIInteractionHandler::getImplementationName()
139{
140 return "com.sun.star.comp.uui.UUIInteractionHandler";
141}
142
143sal_Bool SAL_CALL
144UUIInteractionHandler::supportsService(OUString const & rServiceName)
145{
146 return cppu::supportsService(this, rServiceName);
147}
148
149uno::Sequence< OUString > SAL_CALL
150UUIInteractionHandler::getSupportedServiceNames()
151{
152 return { "com.sun.star.task.InteractionHandler",
153 // added to indicate support for configuration.backend.MergeRecoveryRequest
154 "com.sun.star.configuration.backend.InteractionHandler",
155 // for backwards compatibility
156 "com.sun.star.uui.InteractionHandler" };
157}
158
159void SAL_CALL
160UUIInteractionHandler::initialize(
161 uno::Sequence< uno::Any > const & rArguments)
162{
163 // The old-style InteractionHandler service supported a sequence of
164 // PropertyValue, while the new-style service now uses constructors to pass
165 // in Parent and Context values; for backwards compatibility, keep support
166 // for a PropertyValue sequence, too:
167 uno::Reference< awt::XWindow > xWindow;
168 OUString aContext;
169 if (!((rArguments.getLength() == 1 && (rArguments[0] >>= xWindow)) ||
170 (rArguments.getLength() == 2 && (rArguments[0] >>= xWindow) &&
171 (rArguments[1] >>= aContext))))
172 {
174 if ( aProperties.has( "Parent" ) )
175 {
176 OSL_VERIFY( aProperties.get( "Parent" ) >>= xWindow );
177 }
178 if ( aProperties.has( "Context" ) )
179 {
180 OSL_VERIFY( aProperties.get( "Context" ) >>= aContext );
181 }
182 }
183
184 m_pImpl.SetParentWindow(xWindow);
185 m_pImpl.setContext(aContext);
186}
187
188void SAL_CALL
189UUIInteractionHandler::handle(
190 uno::Reference< task::XInteractionRequest > const & rRequest)
191{
192 try
193 {
194 m_pImpl.handleRequest(rRequest);
195 }
196 catch (uno::RuntimeException const & ex)
197 {
198 css::uno::Any anyEx = cppu::getCaughtException();
199 throw css::lang::WrappedTargetRuntimeException( ex.Message,
200 *this, anyEx );
201 }
202}
203
204sal_Bool SAL_CALL UUIInteractionHandler::handleInteractionRequest(
205 const uno::Reference< task::XInteractionRequest >& Request )
206{
207 try
208 {
209 return m_pImpl.handleRequest( Request );
210 }
211 catch (uno::RuntimeException const & ex)
212 {
213 css::uno::Any anyEx = cppu::getCaughtException();
214 throw css::lang::WrappedTargetRuntimeException( ex.Message,
215 *this, anyEx );
216 }
217}
218
219}
220
221extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
223 css::uno::XComponentContext *context,
224 css::uno::Sequence<css::uno::Any> const &)
225{
226 return cppu::acquire(new UUIInteractionHandler(context));
227}
228
229/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
PropertiesInfo aProperties
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_uui_UUIInteractionHandler_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Any SAL_CALL getCaughtException()
void handleInteractionRequest(const uno::Reference< uno::XComponentContext > &xContext, const uno::Reference< task::XInteractionRequest > &xRequest)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
unsigned char sal_Bool