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 "iahndl.hxx"
21 : #include "interactionhandler.hxx"
22 : #include "comphelper/namedvaluecollection.hxx"
23 : #include "comphelper/processfactory.hxx"
24 : #include "com/sun/star/awt/XWindow.hpp"
25 :
26 : using namespace com::sun::star;
27 :
28 428 : UUIInteractionHandler::UUIInteractionHandler(
29 : uno::Reference< uno::XComponentContext > const &
30 : rxContext)
31 : SAL_THROW(())
32 428 : : m_pImpl(new UUIInteractionHelper(rxContext))
33 : {
34 428 : }
35 :
36 1278 : UUIInteractionHandler::~UUIInteractionHandler()
37 : {
38 426 : delete m_pImpl;
39 852 : }
40 :
41 0 : OUString SAL_CALL UUIInteractionHandler::getImplementationName()
42 : throw (uno::RuntimeException)
43 : {
44 0 : return OUString::createFromAscii(m_aImplementationName);
45 : }
46 :
47 : sal_Bool SAL_CALL
48 0 : UUIInteractionHandler::supportsService(OUString const & rServiceName)
49 : throw (uno::RuntimeException)
50 : {
51 : uno::Sequence< OUString >
52 0 : aNames(getSupportedServiceNames_static());
53 0 : for (sal_Int32 i = 0; i < aNames.getLength(); ++i)
54 0 : if (aNames[i] == rServiceName)
55 0 : return true;
56 0 : return false;
57 : }
58 :
59 : uno::Sequence< OUString > SAL_CALL
60 0 : UUIInteractionHandler::getSupportedServiceNames()
61 : throw (uno::RuntimeException)
62 : {
63 0 : return getSupportedServiceNames_static();
64 : }
65 :
66 : void SAL_CALL
67 425 : UUIInteractionHandler::initialize(
68 : uno::Sequence< uno::Any > const & rArguments)
69 : throw (uno::Exception)
70 : {
71 425 : uno::Reference<uno::XComponentContext> xContext = m_pImpl->getORB();
72 425 : delete m_pImpl;
73 :
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 850 : uno::Reference< awt::XWindow > xWindow;
79 850 : OUString aContext;
80 1275 : if (!((rArguments.getLength() == 1 && (rArguments[0] >>= xWindow)) ||
81 0 : (rArguments.getLength() == 2 && (rArguments[0] >>= xWindow) &&
82 425 : (rArguments[1] >>= aContext))))
83 : {
84 0 : ::comphelper::NamedValueCollection aProperties( rArguments );
85 0 : if ( aProperties.has( "Parent" ) )
86 : {
87 0 : OSL_VERIFY( aProperties.get( "Parent" ) >>= xWindow );
88 : }
89 0 : if ( aProperties.has( "Context" ) )
90 : {
91 0 : OSL_VERIFY( aProperties.get( "Context" ) >>= aContext );
92 0 : }
93 : }
94 :
95 850 : m_pImpl = new UUIInteractionHelper(xContext, xWindow, aContext);
96 425 : }
97 :
98 : void SAL_CALL
99 0 : UUIInteractionHandler::handle(
100 : uno::Reference< task::XInteractionRequest > const & rRequest)
101 : throw (uno::RuntimeException)
102 : {
103 : try
104 : {
105 0 : m_pImpl->handleRequest(rRequest);
106 : }
107 0 : catch (uno::RuntimeException const & ex)
108 : {
109 0 : throw uno::RuntimeException(ex.Message, *this);
110 : }
111 0 : }
112 :
113 0 : ::sal_Bool SAL_CALL UUIInteractionHandler::handleInteractionRequest(
114 : const uno::Reference< task::XInteractionRequest >& _Request ) throw ( uno::RuntimeException )
115 : {
116 : try
117 : {
118 0 : return m_pImpl->handleRequest( _Request );
119 : }
120 0 : catch (uno::RuntimeException const & ex)
121 : {
122 0 : throw uno::RuntimeException( ex.Message, *this );
123 : }
124 : }
125 :
126 : char const UUIInteractionHandler::m_aImplementationName[]
127 : = "com.sun.star.comp.uui.UUIInteractionHandler";
128 :
129 : uno::Sequence< OUString >
130 12 : UUIInteractionHandler::getSupportedServiceNames_static()
131 : {
132 12 : uno::Sequence< OUString > aNames(3);
133 12 : aNames[0] = "com.sun.star.task.InteractionHandler";
134 : // added to indicate support for configuration.backend.MergeRecoveryRequest
135 12 : aNames[1] = "com.sun.star.configuration.backend.InteractionHandler";
136 12 : aNames[2] = "com.sun.star.uui.InteractionHandler";
137 : // for backwards compatibility
138 12 : return aNames;
139 : }
140 :
141 : uno::Reference< uno::XInterface > SAL_CALL
142 428 : UUIInteractionHandler::createInstance(
143 : uno::Reference< lang::XMultiServiceFactory > const &
144 : rServiceFactory)
145 : SAL_THROW((uno::Exception))
146 : {
147 : try
148 : {
149 428 : return *new UUIInteractionHandler(comphelper::getComponentContext(rServiceFactory));
150 : }
151 0 : catch (std::bad_alloc const &)
152 : {
153 0 : throw uno::RuntimeException("out of memory", 0);
154 : }
155 : }
156 :
157 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|