Line data Source code
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 <com/sun/star/awt/XWindow.hpp>
21 : #include <com/sun/star/lang/XInitialization.hpp>
22 : #include <com/sun/star/lang/XServiceInfo.hpp>
23 : #include <com/sun/star/task/XInteractionHandler2.hpp>
24 :
25 : #include <iahndl.hxx>
26 : #include <comphelper/namedvaluecollection.hxx>
27 : #include <cppuhelper/implbase3.hxx>
28 : #include <cppuhelper/supportsservice.hxx>
29 :
30 : using namespace com::sun::star;
31 :
32 : namespace {
33 :
34 : class UUIInteractionHandler:
35 : public cppu::WeakImplHelper3< com::sun::star::lang::XServiceInfo,
36 : com::sun::star::lang::XInitialization,
37 : com::sun::star::task::XInteractionHandler2 >
38 : {
39 : private:
40 : UUIInteractionHelper * m_pImpl;
41 :
42 : UUIInteractionHandler(UUIInteractionHandler &); // not implemented
43 : void operator =(UUIInteractionHandler); // not implemented
44 :
45 : public:
46 : UUIInteractionHandler(com::sun::star::uno::Reference<
47 : com::sun::star::uno::XComponentContext >
48 : const & rxContext)
49 : SAL_THROW(());
50 :
51 : virtual ~UUIInteractionHandler() SAL_THROW(());
52 :
53 : virtual OUString SAL_CALL getImplementationName()
54 : throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
55 :
56 : virtual sal_Bool SAL_CALL supportsService(OUString const &
57 : rServiceName)
58 : throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
59 :
60 : virtual com::sun::star::uno::Sequence< OUString > SAL_CALL
61 : getSupportedServiceNames()
62 : throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
63 :
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;
69 :
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;
75 :
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;
80 : };
81 :
82 0 : UUIInteractionHandler::UUIInteractionHandler(
83 : uno::Reference< uno::XComponentContext > const &
84 : rxContext)
85 : SAL_THROW(())
86 0 : : m_pImpl(new UUIInteractionHelper(rxContext))
87 : {
88 0 : }
89 :
90 0 : UUIInteractionHandler::~UUIInteractionHandler()
91 : {
92 0 : delete m_pImpl;
93 0 : }
94 :
95 0 : OUString SAL_CALL UUIInteractionHandler::getImplementationName()
96 : throw (uno::RuntimeException, std::exception)
97 : {
98 0 : return OUString("com.sun.star.comp.uui.UUIInteractionHandler");
99 : }
100 :
101 : sal_Bool SAL_CALL
102 0 : UUIInteractionHandler::supportsService(OUString const & rServiceName)
103 : throw (uno::RuntimeException, std::exception)
104 : {
105 0 : return cppu::supportsService(this, rServiceName);
106 : }
107 :
108 : uno::Sequence< OUString > SAL_CALL
109 0 : UUIInteractionHandler::getSupportedServiceNames()
110 : throw (uno::RuntimeException, std::exception)
111 : {
112 0 : uno::Sequence< OUString > aNames(3);
113 0 : aNames[0] = "com.sun.star.task.InteractionHandler";
114 : // added to indicate support for configuration.backend.MergeRecoveryRequest
115 0 : aNames[1] = "com.sun.star.configuration.backend.InteractionHandler";
116 0 : aNames[2] = "com.sun.star.uui.InteractionHandler";
117 : // for backwards compatibility
118 0 : return aNames;
119 : }
120 :
121 : void SAL_CALL
122 0 : UUIInteractionHandler::initialize(
123 : uno::Sequence< uno::Any > const & rArguments)
124 : throw (uno::Exception, std::exception)
125 : {
126 0 : uno::Reference<uno::XComponentContext> xContext = m_pImpl->getORB();
127 0 : delete m_pImpl;
128 :
129 : // The old-style InteractionHandler service supported a sequence of
130 : // PropertyValue, while the new-style service now uses constructors to pass
131 : // in Parent and Context values; for backwards compatibility, keep support
132 : // for a PropertyValue sequence, too:
133 0 : uno::Reference< awt::XWindow > xWindow;
134 0 : OUString aContext;
135 0 : if (!((rArguments.getLength() == 1 && (rArguments[0] >>= xWindow)) ||
136 0 : (rArguments.getLength() == 2 && (rArguments[0] >>= xWindow) &&
137 0 : (rArguments[1] >>= aContext))))
138 : {
139 0 : ::comphelper::NamedValueCollection aProperties( rArguments );
140 0 : if ( aProperties.has( "Parent" ) )
141 : {
142 0 : OSL_VERIFY( aProperties.get( "Parent" ) >>= xWindow );
143 : }
144 0 : if ( aProperties.has( "Context" ) )
145 : {
146 0 : OSL_VERIFY( aProperties.get( "Context" ) >>= aContext );
147 0 : }
148 : }
149 :
150 0 : m_pImpl = new UUIInteractionHelper(xContext, xWindow, aContext);
151 0 : }
152 :
153 : void SAL_CALL
154 0 : UUIInteractionHandler::handle(
155 : uno::Reference< task::XInteractionRequest > const & rRequest)
156 : throw (uno::RuntimeException, std::exception)
157 : {
158 : try
159 : {
160 0 : m_pImpl->handleRequest(rRequest);
161 : }
162 0 : catch (uno::RuntimeException const & ex)
163 : {
164 0 : throw uno::RuntimeException(ex.Message, *this);
165 : }
166 0 : }
167 :
168 0 : sal_Bool SAL_CALL UUIInteractionHandler::handleInteractionRequest(
169 : const uno::Reference< task::XInteractionRequest >& _Request ) throw ( uno::RuntimeException, std::exception )
170 : {
171 : try
172 : {
173 0 : return m_pImpl->handleRequest( _Request );
174 : }
175 0 : catch (uno::RuntimeException const & ex)
176 : {
177 0 : throw uno::RuntimeException( ex.Message, *this );
178 : }
179 : }
180 :
181 : }
182 :
183 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
184 0 : com_sun_star_comp_uui_UUIInteractionHandler_get_implementation(
185 : css::uno::XComponentContext *context,
186 : css::uno::Sequence<css::uno::Any> const &)
187 : {
188 0 : return cppu::acquire(new UUIInteractionHandler(context));
189 : }
190 :
191 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|