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 .
21 #include <sal/config.h>
22 #include <osl/diagnose.h>
24 #include <com/sun/star/awt/XWindow.hpp>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/task/XInteractionHandler2.hpp>
30 #include <comphelper/namedvaluecollection.hxx>
31 #include <cppuhelper/implbase.hxx>
32 #include <cppuhelper/supportsservice.hxx>
34 using namespace com::sun::star
;
38 class UUIInteractionHandler
:
39 public cppu::WeakImplHelper
< css::lang::XServiceInfo
,
40 css::lang::XInitialization
,
41 css::task::XInteractionHandler2
>
44 std::unique_ptr
<UUIInteractionHelper
> m_pImpl
;
47 explicit UUIInteractionHandler(css::uno::Reference
< css::uno::XComponentContext
> const & rxContext
);
49 UUIInteractionHandler(const UUIInteractionHandler
&) = delete;
50 UUIInteractionHandler
& operator=(const UUIInteractionHandler
&) = delete;
52 virtual OUString SAL_CALL
getImplementationName() override
;
54 virtual sal_Bool SAL_CALL
supportsService(OUString
const & rServiceName
) override
;
56 virtual css::uno::Sequence
< OUString
> SAL_CALL
57 getSupportedServiceNames() override
;
61 css::uno::Sequence
< css::uno::Any
> const & rArguments
) override
;
64 handle(css::uno::Reference
< css::task::XInteractionRequest
> const & rRequest
) override
;
66 virtual sal_Bool SAL_CALL
67 handleInteractionRequest(
68 const css::uno::Reference
< css::task::XInteractionRequest
>& Request
72 UUIInteractionHandler::UUIInteractionHandler(
73 uno::Reference
< uno::XComponentContext
> const & rxContext
)
74 : m_pImpl(new UUIInteractionHelper(rxContext
))
78 OUString SAL_CALL
UUIInteractionHandler::getImplementationName()
80 return OUString("com.sun.star.comp.uui.UUIInteractionHandler");
84 UUIInteractionHandler::supportsService(OUString
const & rServiceName
)
86 return cppu::supportsService(this, rServiceName
);
89 uno::Sequence
< OUString
> SAL_CALL
90 UUIInteractionHandler::getSupportedServiceNames()
92 uno::Sequence
< OUString
> aNames(3);
93 aNames
[0] = "com.sun.star.task.InteractionHandler";
94 // added to indicate support for configuration.backend.MergeRecoveryRequest
95 aNames
[1] = "com.sun.star.configuration.backend.InteractionHandler";
96 aNames
[2] = "com.sun.star.uui.InteractionHandler";
97 // for backwards compatibility
102 UUIInteractionHandler::initialize(
103 uno::Sequence
< uno::Any
> const & rArguments
)
105 uno::Reference
<uno::XComponentContext
> xContext
= m_pImpl
->getORB();
108 // The old-style InteractionHandler service supported a sequence of
109 // PropertyValue, while the new-style service now uses constructors to pass
110 // in Parent and Context values; for backwards compatibility, keep support
111 // for a PropertyValue sequence, too:
112 uno::Reference
< awt::XWindow
> xWindow
;
114 if (!((rArguments
.getLength() == 1 && (rArguments
[0] >>= xWindow
)) ||
115 (rArguments
.getLength() == 2 && (rArguments
[0] >>= xWindow
) &&
116 (rArguments
[1] >>= aContext
))))
118 ::comphelper::NamedValueCollection
aProperties( rArguments
);
119 if ( aProperties
.has( "Parent" ) )
121 OSL_VERIFY( aProperties
.get( "Parent" ) >>= xWindow
);
123 if ( aProperties
.has( "Context" ) )
125 OSL_VERIFY( aProperties
.get( "Context" ) >>= aContext
);
129 m_pImpl
.reset( new UUIInteractionHelper(xContext
, xWindow
, aContext
) );
133 UUIInteractionHandler::handle(
134 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
138 m_pImpl
->handleRequest(rRequest
);
140 catch (uno::RuntimeException
const & ex
)
142 throw uno::RuntimeException(ex
.Message
, *this);
146 sal_Bool SAL_CALL
UUIInteractionHandler::handleInteractionRequest(
147 const uno::Reference
< task::XInteractionRequest
>& Request
)
151 return m_pImpl
->handleRequest( Request
);
153 catch (uno::RuntimeException
const & ex
)
155 throw uno::RuntimeException( ex
.Message
, *this );
161 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
162 com_sun_star_comp_uui_UUIInteractionHandler_get_implementation(
163 css::uno::XComponentContext
*context
,
164 css::uno::Sequence
<css::uno::Any
> const &)
166 return cppu::acquire(new UUIInteractionHandler(context
));
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */