bump product version to 5.0.4.1
[LibreOffice.git] / uui / source / interactionhandler.cxx
blob4cb9c523f4580824d13ffc52409db31ee9088d47
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 <sal/config.h>
22 #include <boost/noncopyable.hpp>
23 #include <com/sun/star/awt/XWindow.hpp>
24 #include <com/sun/star/lang/XInitialization.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/task/XInteractionHandler2.hpp>
28 #include "iahndl.hxx"
29 #include <comphelper/namedvaluecollection.hxx>
30 #include <cppuhelper/implbase3.hxx>
31 #include <cppuhelper/supportsservice.hxx>
33 using namespace com::sun::star;
35 namespace {
37 class UUIInteractionHandler:
38 public cppu::WeakImplHelper3< com::sun::star::lang::XServiceInfo,
39 com::sun::star::lang::XInitialization,
40 com::sun::star::task::XInteractionHandler2 >,
41 private boost::noncopyable
43 private:
44 UUIInteractionHelper * m_pImpl;
46 public:
47 UUIInteractionHandler(com::sun::star::uno::Reference<
48 com::sun::star::uno::XComponentContext >
49 const & rxContext);
51 virtual ~UUIInteractionHandler();
53 virtual OUString SAL_CALL getImplementationName()
54 throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
56 virtual sal_Bool SAL_CALL supportsService(OUString const &
57 rServiceName)
58 throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
60 virtual com::sun::star::uno::Sequence< OUString > SAL_CALL
61 getSupportedServiceNames()
62 throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
64 virtual void SAL_CALL
65 initialize(
66 com::sun::star::uno::Sequence< com::sun::star::uno::Any > const &
67 rArguments)
68 throw (com::sun::star::uno::Exception, std::exception) SAL_OVERRIDE;
70 virtual void SAL_CALL
71 handle(com::sun::star::uno::Reference<
72 com::sun::star::task::XInteractionRequest > const &
73 rRequest)
74 throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
76 virtual sal_Bool SAL_CALL
77 handleInteractionRequest(
78 const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& _Request
79 ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
82 UUIInteractionHandler::UUIInteractionHandler(
83 uno::Reference< uno::XComponentContext > const &
84 rxContext)
85 : m_pImpl(new UUIInteractionHelper(rxContext))
89 UUIInteractionHandler::~UUIInteractionHandler()
91 delete m_pImpl;
94 OUString SAL_CALL UUIInteractionHandler::getImplementationName()
95 throw (uno::RuntimeException, std::exception)
97 return OUString("com.sun.star.comp.uui.UUIInteractionHandler");
100 sal_Bool SAL_CALL
101 UUIInteractionHandler::supportsService(OUString const & rServiceName)
102 throw (uno::RuntimeException, std::exception)
104 return cppu::supportsService(this, rServiceName);
107 uno::Sequence< OUString > SAL_CALL
108 UUIInteractionHandler::getSupportedServiceNames()
109 throw (uno::RuntimeException, std::exception)
111 uno::Sequence< OUString > aNames(3);
112 aNames[0] = "com.sun.star.task.InteractionHandler";
113 // added to indicate support for configuration.backend.MergeRecoveryRequest
114 aNames[1] = "com.sun.star.configuration.backend.InteractionHandler";
115 aNames[2] = "com.sun.star.uui.InteractionHandler";
116 // for backwards compatibility
117 return aNames;
120 void SAL_CALL
121 UUIInteractionHandler::initialize(
122 uno::Sequence< uno::Any > const & rArguments)
123 throw (uno::Exception, std::exception)
125 uno::Reference<uno::XComponentContext> xContext = m_pImpl->getORB();
126 delete m_pImpl;
128 // The old-style InteractionHandler service supported a sequence of
129 // PropertyValue, while the new-style service now uses constructors to pass
130 // in Parent and Context values; for backwards compatibility, keep support
131 // for a PropertyValue sequence, too:
132 uno::Reference< awt::XWindow > xWindow;
133 OUString aContext;
134 if (!((rArguments.getLength() == 1 && (rArguments[0] >>= xWindow)) ||
135 (rArguments.getLength() == 2 && (rArguments[0] >>= xWindow) &&
136 (rArguments[1] >>= aContext))))
138 ::comphelper::NamedValueCollection aProperties( rArguments );
139 if ( aProperties.has( "Parent" ) )
141 OSL_VERIFY( aProperties.get( "Parent" ) >>= xWindow );
143 if ( aProperties.has( "Context" ) )
145 OSL_VERIFY( aProperties.get( "Context" ) >>= aContext );
149 m_pImpl = new UUIInteractionHelper(xContext, xWindow, aContext);
152 void SAL_CALL
153 UUIInteractionHandler::handle(
154 uno::Reference< task::XInteractionRequest > const & rRequest)
155 throw (uno::RuntimeException, std::exception)
159 m_pImpl->handleRequest(rRequest);
161 catch (uno::RuntimeException const & ex)
163 throw uno::RuntimeException(ex.Message, *this);
167 sal_Bool SAL_CALL UUIInteractionHandler::handleInteractionRequest(
168 const uno::Reference< task::XInteractionRequest >& _Request ) throw ( uno::RuntimeException, std::exception )
172 return m_pImpl->handleRequest( _Request );
174 catch (uno::RuntimeException const & ex)
176 throw uno::RuntimeException( ex.Message, *this );
182 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
183 com_sun_star_comp_uui_UUIInteractionHandler_get_implementation(
184 css::uno::XComponentContext *context,
185 css::uno::Sequence<css::uno::Any> const &)
187 return cppu::acquire(new UUIInteractionHandler(context));
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */