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 "interactionhandler.hxx"
22 #include "comphelper/namedvaluecollection.hxx"
23 #include "comphelper/processfactory.hxx"
24 #include "com/sun/star/awt/XWindow.hpp"
26 using namespace com::sun::star
;
28 UUIInteractionHandler::UUIInteractionHandler(
29 uno::Reference
< uno::XComponentContext
> const &
32 : m_pImpl(new UUIInteractionHelper(rxContext
))
36 UUIInteractionHandler::~UUIInteractionHandler()
41 OUString SAL_CALL
UUIInteractionHandler::getImplementationName()
42 throw (uno::RuntimeException
)
44 return OUString::createFromAscii(m_aImplementationName
);
48 UUIInteractionHandler::supportsService(OUString
const & rServiceName
)
49 throw (uno::RuntimeException
)
51 uno::Sequence
< OUString
>
52 aNames(getSupportedServiceNames_static());
53 for (sal_Int32 i
= 0; i
< aNames
.getLength(); ++i
)
54 if (aNames
[i
] == rServiceName
)
59 uno::Sequence
< OUString
> SAL_CALL
60 UUIInteractionHandler::getSupportedServiceNames()
61 throw (uno::RuntimeException
)
63 return getSupportedServiceNames_static();
67 UUIInteractionHandler::initialize(
68 uno::Sequence
< uno::Any
> const & rArguments
)
69 throw (uno::Exception
)
71 uno::Reference
<uno::XComponentContext
> xContext
= m_pImpl
->getORB();
74 // The old-style InteractionHandler service supported a sequence of
75 // PropertyValue, while the new-style service now uses constructors to pass
76 // in Parent and Context values; for backwards compatibility, keep support
77 // for a PropertyValue sequence, too:
78 uno::Reference
< awt::XWindow
> xWindow
;
80 if (!((rArguments
.getLength() == 1 && (rArguments
[0] >>= xWindow
)) ||
81 (rArguments
.getLength() == 2 && (rArguments
[0] >>= xWindow
) &&
82 (rArguments
[1] >>= aContext
))))
84 ::comphelper::NamedValueCollection
aProperties( rArguments
);
85 if ( aProperties
.has( "Parent" ) )
87 OSL_VERIFY( aProperties
.get( "Parent" ) >>= xWindow
);
89 if ( aProperties
.has( "Context" ) )
91 OSL_VERIFY( aProperties
.get( "Context" ) >>= aContext
);
95 m_pImpl
= new UUIInteractionHelper(xContext
, xWindow
, aContext
);
99 UUIInteractionHandler::handle(
100 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
101 throw (uno::RuntimeException
)
105 m_pImpl
->handleRequest(rRequest
);
107 catch (uno::RuntimeException
const & ex
)
109 throw uno::RuntimeException(ex
.Message
, *this);
113 ::sal_Bool SAL_CALL
UUIInteractionHandler::handleInteractionRequest(
114 const uno::Reference
< task::XInteractionRequest
>& _Request
) throw ( uno::RuntimeException
)
118 return m_pImpl
->handleRequest( _Request
);
120 catch (uno::RuntimeException
const & ex
)
122 throw uno::RuntimeException( ex
.Message
, *this );
126 char const UUIInteractionHandler::m_aImplementationName
[]
127 = "com.sun.star.comp.uui.UUIInteractionHandler";
129 uno::Sequence
< OUString
>
130 UUIInteractionHandler::getSupportedServiceNames_static()
132 uno::Sequence
< OUString
> aNames(3);
133 aNames
[0] = "com.sun.star.task.InteractionHandler";
134 // added to indicate support for configuration.backend.MergeRecoveryRequest
135 aNames
[1] = "com.sun.star.configuration.backend.InteractionHandler";
136 aNames
[2] = "com.sun.star.uui.InteractionHandler";
137 // for backwards compatibility
141 uno::Reference
< uno::XInterface
> SAL_CALL
142 UUIInteractionHandler::createInstance(
143 uno::Reference
< lang::XMultiServiceFactory
> const &
145 SAL_THROW((uno::Exception
))
149 return *new UUIInteractionHandler(comphelper::getComponentContext(rServiceFactory
));
151 catch (std::bad_alloc
const &)
153 throw uno::RuntimeException(OUString("out of memory"), 0);
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */