Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / uui / source / interactionhandler.cxx
blobcc5579fd1ed15da534611dc3e24f2102aceb432a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <memory>
21 #include <sal/config.h>
22 #include <osl/diagnose.h>
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>
32 #include "iahndl.hxx"
33 #include <comphelper/namedvaluecollection.hxx>
34 #include <cppuhelper/exc_hlp.hxx>
35 #include <cppuhelper/implbase.hxx>
36 #include <cppuhelper/supportsservice.hxx>
38 using namespace com::sun::star;
40 namespace {
42 class UUIInteractionHandler:
43 public cppu::WeakImplHelper<css::lang::XServiceInfo,
44 css::lang::XInitialization,
45 css::task::XInteractionHandler2,
46 css::beans::XPropertySet>
48 private:
49 std::unique_ptr<UUIInteractionHelper> m_pImpl;
51 public:
52 explicit UUIInteractionHandler(css::uno::Reference< css::uno::XComponentContext > const & rxContext);
54 UUIInteractionHandler(const UUIInteractionHandler&) = delete;
55 UUIInteractionHandler& operator=(const UUIInteractionHandler&) = delete;
57 virtual OUString SAL_CALL getImplementationName() override;
59 virtual sal_Bool SAL_CALL supportsService(OUString const & rServiceName) override;
61 virtual css::uno::Sequence< OUString > SAL_CALL
62 getSupportedServiceNames() override;
64 virtual void SAL_CALL
65 initialize(
66 css::uno::Sequence< css::uno::Any > const & rArguments) override;
68 virtual void SAL_CALL
69 handle(css::uno::Reference< css::task::XInteractionRequest > const & rRequest) override;
71 virtual sal_Bool SAL_CALL
72 handleInteractionRequest(
73 const css::uno::Reference< css::task::XInteractionRequest >& Request
74 ) override;
76 virtual void SAL_CALL
77 addPropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ ) override
79 throw css::uno::RuntimeException(
80 "UUIInteractionHandler addPropertyChangeListener is not supported");
83 virtual void SAL_CALL
84 removePropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ ) override
86 throw css::uno::RuntimeException(
87 "UUIInteractionHandler removePropertyChangeListener is not supported");
90 virtual void SAL_CALL
91 addVetoableChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*xListener*/ ) override
93 throw css::uno::RuntimeException(
94 "UUIInteractionHandler addVetoableChangeListener is not supported");
97 virtual void SAL_CALL
98 removeVetoableChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*xListener*/ ) override
100 throw css::uno::RuntimeException(
101 "UUIInteractionHandler removeVetoableChangeListener is not supported");
104 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
105 getPropertySetInfo() override
107 return nullptr;
110 virtual void SAL_CALL setPropertyValue(const OUString& rPropertyName, const css::uno::Any& rValue) override
112 if (rPropertyName == "ParentWindow")
114 css::uno::Reference<css::awt::XWindow> xWindow;
115 rValue >>= xWindow;
116 m_pImpl->SetParentWindow(xWindow);
117 return;
119 throw css::beans::UnknownPropertyException(rPropertyName);
122 virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& rPropertyName) override
124 if (rPropertyName == "ParentWindow")
126 return uno::Any(m_pImpl->GetParentWindow());
128 throw css::beans::UnknownPropertyException(rPropertyName);
132 UUIInteractionHandler::UUIInteractionHandler(
133 uno::Reference< uno::XComponentContext > const & rxContext)
134 : m_pImpl(new UUIInteractionHelper(rxContext))
138 OUString SAL_CALL UUIInteractionHandler::getImplementationName()
140 return "com.sun.star.comp.uui.UUIInteractionHandler";
143 sal_Bool SAL_CALL
144 UUIInteractionHandler::supportsService(OUString const & rServiceName)
146 return cppu::supportsService(this, rServiceName);
149 uno::Sequence< OUString > SAL_CALL
150 UUIInteractionHandler::getSupportedServiceNames()
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" };
159 void SAL_CALL
160 UUIInteractionHandler::initialize(
161 uno::Sequence< uno::Any > const & rArguments)
163 uno::Reference<uno::XComponentContext> xContext = m_pImpl->getORB();
164 m_pImpl.reset();
166 // The old-style InteractionHandler service supported a sequence of
167 // PropertyValue, while the new-style service now uses constructors to pass
168 // in Parent and Context values; for backwards compatibility, keep support
169 // for a PropertyValue sequence, too:
170 uno::Reference< awt::XWindow > xWindow;
171 OUString aContext;
172 if (!((rArguments.getLength() == 1 && (rArguments[0] >>= xWindow)) ||
173 (rArguments.getLength() == 2 && (rArguments[0] >>= xWindow) &&
174 (rArguments[1] >>= aContext))))
176 ::comphelper::NamedValueCollection aProperties( rArguments );
177 if ( aProperties.has( "Parent" ) )
179 OSL_VERIFY( aProperties.get( "Parent" ) >>= xWindow );
181 if ( aProperties.has( "Context" ) )
183 OSL_VERIFY( aProperties.get( "Context" ) >>= aContext );
187 m_pImpl.reset( new UUIInteractionHelper(xContext, xWindow, aContext) );
190 void SAL_CALL
191 UUIInteractionHandler::handle(
192 uno::Reference< task::XInteractionRequest > const & rRequest)
196 m_pImpl->handleRequest(rRequest);
198 catch (uno::RuntimeException const & ex)
200 css::uno::Any anyEx = cppu::getCaughtException();
201 throw css::lang::WrappedTargetRuntimeException( ex.Message,
202 *this, anyEx );
206 sal_Bool SAL_CALL UUIInteractionHandler::handleInteractionRequest(
207 const uno::Reference< task::XInteractionRequest >& Request )
211 return m_pImpl->handleRequest( Request );
213 catch (uno::RuntimeException const & ex)
215 css::uno::Any anyEx = cppu::getCaughtException();
216 throw css::lang::WrappedTargetRuntimeException( ex.Message,
217 *this, anyEx );
223 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
224 com_sun_star_comp_uui_UUIInteractionHandler_get_implementation(
225 css::uno::XComponentContext *context,
226 css::uno::Sequence<css::uno::Any> const &)
228 return cppu::acquire(new UUIInteractionHandler(context));
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */