bump product version to 6.3.0.0.beta1
[LibreOffice.git] / uui / source / interactionhandler.cxx
blob850eb59b01064dee77dd234f25ae30816dca8923
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/lang/WrappedTargetRuntimeException.hpp>
26 #include <com/sun/star/lang/XInitialization.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/task/XInteractionHandler2.hpp>
30 #include "iahndl.hxx"
31 #include <comphelper/namedvaluecollection.hxx>
32 #include <cppuhelper/exc_hlp.hxx>
33 #include <cppuhelper/implbase.hxx>
34 #include <cppuhelper/supportsservice.hxx>
36 using namespace com::sun::star;
38 namespace {
40 class UUIInteractionHandler:
41 public cppu::WeakImplHelper< css::lang::XServiceInfo,
42 css::lang::XInitialization,
43 css::task::XInteractionHandler2 >
45 private:
46 std::unique_ptr<UUIInteractionHelper> m_pImpl;
48 public:
49 explicit UUIInteractionHandler(css::uno::Reference< css::uno::XComponentContext > const & rxContext);
51 UUIInteractionHandler(const UUIInteractionHandler&) = delete;
52 UUIInteractionHandler& operator=(const UUIInteractionHandler&) = delete;
54 virtual OUString SAL_CALL getImplementationName() override;
56 virtual sal_Bool SAL_CALL supportsService(OUString const & rServiceName) override;
58 virtual css::uno::Sequence< OUString > SAL_CALL
59 getSupportedServiceNames() override;
61 virtual void SAL_CALL
62 initialize(
63 css::uno::Sequence< css::uno::Any > const & rArguments) override;
65 virtual void SAL_CALL
66 handle(css::uno::Reference< css::task::XInteractionRequest > const & rRequest) override;
68 virtual sal_Bool SAL_CALL
69 handleInteractionRequest(
70 const css::uno::Reference< css::task::XInteractionRequest >& Request
71 ) override;
74 UUIInteractionHandler::UUIInteractionHandler(
75 uno::Reference< uno::XComponentContext > const & rxContext)
76 : m_pImpl(new UUIInteractionHelper(rxContext))
80 OUString SAL_CALL UUIInteractionHandler::getImplementationName()
82 return OUString("com.sun.star.comp.uui.UUIInteractionHandler");
85 sal_Bool SAL_CALL
86 UUIInteractionHandler::supportsService(OUString const & rServiceName)
88 return cppu::supportsService(this, rServiceName);
91 uno::Sequence< OUString > SAL_CALL
92 UUIInteractionHandler::getSupportedServiceNames()
94 uno::Sequence< OUString > aNames(3);
95 aNames[0] = "com.sun.star.task.InteractionHandler";
96 // added to indicate support for configuration.backend.MergeRecoveryRequest
97 aNames[1] = "com.sun.star.configuration.backend.InteractionHandler";
98 aNames[2] = "com.sun.star.uui.InteractionHandler";
99 // for backwards compatibility
100 return aNames;
103 void SAL_CALL
104 UUIInteractionHandler::initialize(
105 uno::Sequence< uno::Any > const & rArguments)
107 uno::Reference<uno::XComponentContext> xContext = m_pImpl->getORB();
108 m_pImpl.reset();
110 // The old-style InteractionHandler service supported a sequence of
111 // PropertyValue, while the new-style service now uses constructors to pass
112 // in Parent and Context values; for backwards compatibility, keep support
113 // for a PropertyValue sequence, too:
114 uno::Reference< awt::XWindow > xWindow;
115 OUString aContext;
116 if (!((rArguments.getLength() == 1 && (rArguments[0] >>= xWindow)) ||
117 (rArguments.getLength() == 2 && (rArguments[0] >>= xWindow) &&
118 (rArguments[1] >>= aContext))))
120 ::comphelper::NamedValueCollection aProperties( rArguments );
121 if ( aProperties.has( "Parent" ) )
123 OSL_VERIFY( aProperties.get( "Parent" ) >>= xWindow );
125 if ( aProperties.has( "Context" ) )
127 OSL_VERIFY( aProperties.get( "Context" ) >>= aContext );
131 m_pImpl.reset( new UUIInteractionHelper(xContext, xWindow, aContext) );
134 void SAL_CALL
135 UUIInteractionHandler::handle(
136 uno::Reference< task::XInteractionRequest > const & rRequest)
140 m_pImpl->handleRequest(rRequest);
142 catch (uno::RuntimeException const & ex)
144 css::uno::Any anyEx = cppu::getCaughtException();
145 throw css::lang::WrappedTargetRuntimeException( ex.Message,
146 *this, anyEx );
150 sal_Bool SAL_CALL UUIInteractionHandler::handleInteractionRequest(
151 const uno::Reference< task::XInteractionRequest >& Request )
155 return m_pImpl->handleRequest( Request );
157 catch (uno::RuntimeException const & ex)
159 css::uno::Any anyEx = cppu::getCaughtException();
160 throw css::lang::WrappedTargetRuntimeException( ex.Message,
161 *this, anyEx );
167 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
168 com_sun_star_comp_uui_UUIInteractionHandler_get_implementation(
169 css::uno::XComponentContext *context,
170 css::uno::Sequence<css::uno::Any> const &)
172 return cppu::acquire(new UUIInteractionHandler(context));
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */