Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / uui / source / interactionhandler.cxx
blob71f11eb33533142d0763c3f8c2d947a64debd9e8
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 "iahndl.hxx"
21 #include "interactionhandler.hxx"
22 #include "comphelper/namedvaluecollection.hxx"
23 #include "com/sun/star/awt/XWindow.hpp"
25 using namespace com::sun::star;
27 UUIInteractionHandler::UUIInteractionHandler(
28 uno::Reference< lang::XMultiServiceFactory > const &
29 rServiceFactory)
30 SAL_THROW(())
31 : m_xServiceFactory(rServiceFactory),
32 m_pImpl(new UUIInteractionHelper(m_xServiceFactory))
36 UUIInteractionHandler::~UUIInteractionHandler()
38 delete m_pImpl;
41 rtl::OUString SAL_CALL UUIInteractionHandler::getImplementationName()
42 throw (uno::RuntimeException)
44 return rtl::OUString::createFromAscii(m_aImplementationName);
47 sal_Bool SAL_CALL
48 UUIInteractionHandler::supportsService(rtl::OUString const & rServiceName)
49 throw (uno::RuntimeException)
51 uno::Sequence< rtl::OUString >
52 aNames(getSupportedServiceNames_static());
53 for (sal_Int32 i = 0; i < aNames.getLength(); ++i)
54 if (aNames[i] == rServiceName)
55 return true;
56 return false;
59 uno::Sequence< rtl::OUString > SAL_CALL
60 UUIInteractionHandler::getSupportedServiceNames()
61 throw (uno::RuntimeException)
63 return getSupportedServiceNames_static();
66 void SAL_CALL
67 UUIInteractionHandler::initialize(
68 uno::Sequence< uno::Any > const & rArguments)
69 throw (uno::Exception)
71 delete m_pImpl;
73 // The old-style InteractionHandler service supported a sequence of
74 // PropertyValue, while the new-style service now uses constructors to pass
75 // in Parent and Context values; for backwards compatibility, keep support
76 // for a PropertyValue sequence, too:
77 uno::Reference< awt::XWindow > xWindow;
78 rtl::OUString aContext;
79 if (!((rArguments.getLength() == 1 && (rArguments[0] >>= xWindow)) ||
80 (rArguments.getLength() == 2 && (rArguments[0] >>= xWindow) &&
81 (rArguments[1] >>= aContext))))
83 ::comphelper::NamedValueCollection aProperties( rArguments );
84 if ( aProperties.has( "Parent" ) )
86 OSL_VERIFY( aProperties.get( "Parent" ) >>= xWindow );
88 if ( aProperties.has( "Context" ) )
90 OSL_VERIFY( aProperties.get( "Context" ) >>= aContext );
94 m_pImpl = new UUIInteractionHelper(m_xServiceFactory, xWindow, aContext);
97 void SAL_CALL
98 UUIInteractionHandler::handle(
99 uno::Reference< task::XInteractionRequest > const & rRequest)
100 throw (uno::RuntimeException)
104 m_pImpl->handleRequest(rRequest);
106 catch (uno::RuntimeException const & ex)
108 throw uno::RuntimeException(ex.Message, *this);
112 ::sal_Bool SAL_CALL UUIInteractionHandler::handleInteractionRequest(
113 const uno::Reference< task::XInteractionRequest >& _Request ) throw ( uno::RuntimeException )
117 return m_pImpl->handleRequest( _Request );
119 catch (uno::RuntimeException const & ex)
121 throw uno::RuntimeException( ex.Message, *this );
125 char const UUIInteractionHandler::m_aImplementationName[]
126 = "com.sun.star.comp.uui.UUIInteractionHandler";
128 uno::Sequence< rtl::OUString >
129 UUIInteractionHandler::getSupportedServiceNames_static()
131 uno::Sequence< rtl::OUString > aNames(3);
132 aNames[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
133 "com.sun.star.task.InteractionHandler"));
134 // added to indicate support for configuration.backend.MergeRecoveryRequest
135 aNames[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
136 "com.sun.star.configuration.backend.InteractionHandler"));
137 aNames[2] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
138 "com.sun.star.uui.InteractionHandler"));
139 // for backwards compatibility
140 return aNames;
143 uno::Reference< uno::XInterface > SAL_CALL
144 UUIInteractionHandler::createInstance(
145 uno::Reference< lang::XMultiServiceFactory > const &
146 rServiceFactory)
147 SAL_THROW((uno::Exception))
151 return *new UUIInteractionHandler(rServiceFactory);
153 catch (std::bad_alloc const &)
155 throw uno::RuntimeException(
156 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */