Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/uui/source/interactionhandler.cxx
Line
Count
Source
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 <memory>
21
#include <sal/config.h>
22
#include <osl/diagnose.h>
23
24
#include <com/sun/star/awt/XWindow.hpp>
25
#include <com/sun/star/beans/XPropertySet.hpp>
26
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
27
#include <com/sun/star/lang/XInitialization.hpp>
28
#include <com/sun/star/lang/XServiceInfo.hpp>
29
#include <com/sun/star/task/XInteractionHandler2.hpp>
30
#include <com/sun/star/uno/RuntimeException.hpp>
31
32
#include "iahndl.hxx"
33
#include <comphelper/namedvaluecollection.hxx>
34
#include <cppuhelper/exc_hlp.hxx>
35
#include <cppuhelper/implbase.hxx>
36
#include <cppuhelper/supportsservice.hxx>
37
38
using namespace com::sun::star;
39
40
namespace {
41
42
class UUIInteractionHandler:
43
    public cppu::WeakImplHelper<css::lang::XServiceInfo,
44
                                css::lang::XInitialization,
45
                                css::task::XInteractionHandler2,
46
                                css::beans::XPropertySet>
47
{
48
private:
49
    UUIInteractionHelper m_pImpl;
50
51
public:
52
    explicit UUIInteractionHandler(css::uno::Reference< css::uno::XComponentContext > const & rxContext);
53
54
    UUIInteractionHandler(const UUIInteractionHandler&) = delete;
55
    UUIInteractionHandler& operator=(const UUIInteractionHandler&) = delete;
56
57
    virtual OUString SAL_CALL getImplementationName() override;
58
59
    virtual sal_Bool SAL_CALL supportsService(OUString const & rServiceName) override;
60
61
    virtual css::uno::Sequence< OUString > SAL_CALL
62
    getSupportedServiceNames() override;
63
64
    virtual void SAL_CALL
65
    initialize(
66
        css::uno::Sequence< css::uno::Any > const & rArguments) override;
67
68
    virtual void SAL_CALL
69
    handle(css::uno::Reference< css::task::XInteractionRequest > const & rRequest) override;
70
71
    virtual sal_Bool SAL_CALL
72
        handleInteractionRequest(
73
            const css::uno::Reference< css::task::XInteractionRequest >& Request
74
        ) override;
75
76
    virtual void SAL_CALL
77
        addPropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ ) override
78
0
    {
79
0
        throw css::uno::RuntimeException(
80
0
            u"UUIInteractionHandler addPropertyChangeListener is not supported"_ustr);
81
0
    }
82
83
    virtual void SAL_CALL
84
        removePropertyChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XPropertyChangeListener >& /*xListener*/ ) override
85
0
    {
86
0
        throw css::uno::RuntimeException(
87
0
            u"UUIInteractionHandler removePropertyChangeListener is not supported"_ustr);
88
0
    }
89
90
    virtual void SAL_CALL
91
        addVetoableChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*xListener*/ ) override
92
0
    {
93
0
        throw css::uno::RuntimeException(
94
0
            u"UUIInteractionHandler addVetoableChangeListener is not supported"_ustr);
95
0
    }
96
97
    virtual void SAL_CALL
98
        removeVetoableChangeListener( const OUString& /*aPropertyName*/, const css::uno::Reference< css::beans::XVetoableChangeListener >& /*xListener*/ ) override
99
0
    {
100
0
        throw css::uno::RuntimeException(
101
0
            u"UUIInteractionHandler removeVetoableChangeListener is not supported"_ustr);
102
0
    }
103
104
    virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
105
        getPropertySetInfo() override
106
0
    {
107
0
        return nullptr;
108
0
    }
109
110
    virtual void SAL_CALL setPropertyValue(const OUString& rPropertyName, const css::uno::Any& rValue) override
111
0
    {
112
0
        if (rPropertyName == "ParentWindow")
113
0
        {
114
0
            css::uno::Reference<css::awt::XWindow> xWindow;
115
0
            rValue >>= xWindow;
116
0
            m_pImpl.SetParentWindow(xWindow);
117
0
            return;
118
0
        }
119
0
        throw css::beans::UnknownPropertyException(rPropertyName);
120
0
    }
121
122
    virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& rPropertyName) override
123
0
    {
124
0
        if (rPropertyName == "ParentWindow")
125
0
        {
126
0
            return uno::Any(m_pImpl.GetParentWindow());
127
0
        }
128
0
        throw css::beans::UnknownPropertyException(rPropertyName);
129
0
    }
130
};
131
132
UUIInteractionHandler::UUIInteractionHandler(
133
    uno::Reference< uno::XComponentContext > const & rxContext)
134
179k
        : m_pImpl(rxContext)
135
179k
{
136
179k
}
137
138
OUString SAL_CALL UUIInteractionHandler::getImplementationName()
139
0
{
140
0
    return u"com.sun.star.comp.uui.UUIInteractionHandler"_ustr;
141
0
}
142
143
sal_Bool SAL_CALL
144
UUIInteractionHandler::supportsService(OUString const & rServiceName)
145
0
{
146
0
    return cppu::supportsService(this, rServiceName);
147
0
}
148
149
uno::Sequence< OUString > SAL_CALL
150
UUIInteractionHandler::getSupportedServiceNames()
151
0
{
152
0
    return { u"com.sun.star.task.InteractionHandler"_ustr,
153
 // added to indicate support for configuration.backend.MergeRecoveryRequest
154
0
             u"com.sun.star.configuration.backend.InteractionHandler"_ustr,
155
    // for backwards compatibility
156
0
             u"com.sun.star.uui.InteractionHandler"_ustr };
157
0
}
158
159
void SAL_CALL
160
UUIInteractionHandler::initialize(
161
    uno::Sequence< uno::Any > const & rArguments)
162
179k
{
163
    // The old-style InteractionHandler service supported a sequence of
164
    // PropertyValue, while the new-style service now uses constructors to pass
165
    // in Parent and Context values; for backwards compatibility, keep support
166
    // for a PropertyValue sequence, too:
167
179k
    uno::Reference< awt::XWindow > xWindow;
168
179k
    OUString aContext;
169
179k
    if (!((rArguments.getLength() == 1 && (rArguments[0] >>= xWindow)) ||
170
0
          (rArguments.getLength() == 2 && (rArguments[0] >>= xWindow) &&
171
0
           (rArguments[1] >>= aContext))))
172
0
    {
173
0
        ::comphelper::NamedValueCollection aProperties( rArguments );
174
0
        if ( aProperties.has( u"Parent"_ustr ) )
175
0
        {
176
0
            OSL_VERIFY( aProperties.get( u"Parent"_ustr ) >>= xWindow );
177
0
        }
178
0
        if ( aProperties.has( u"Context"_ustr ) )
179
0
        {
180
0
            OSL_VERIFY( aProperties.get( u"Context"_ustr ) >>= aContext );
181
0
        }
182
0
    }
183
184
179k
    m_pImpl.SetParentWindow(xWindow);
185
179k
    m_pImpl.setContext(aContext);
186
179k
}
187
188
void SAL_CALL
189
UUIInteractionHandler::handle(
190
    uno::Reference< task::XInteractionRequest > const & rRequest)
191
0
{
192
0
    try
193
0
    {
194
0
        m_pImpl.handleRequest(rRequest);
195
0
    }
196
0
    catch (uno::RuntimeException const & ex)
197
0
    {
198
0
        css::uno::Any anyEx = cppu::getCaughtException();
199
0
        throw css::lang::WrappedTargetRuntimeException( ex.Message,
200
0
                *this, anyEx );
201
0
    }
202
0
}
203
204
sal_Bool SAL_CALL UUIInteractionHandler::handleInteractionRequest(
205
    const uno::Reference< task::XInteractionRequest >& Request )
206
0
{
207
0
    try
208
0
    {
209
0
        return m_pImpl.handleRequest( Request );
210
0
    }
211
0
    catch (uno::RuntimeException const & ex)
212
0
    {
213
0
        css::uno::Any anyEx = cppu::getCaughtException();
214
0
        throw css::lang::WrappedTargetRuntimeException( ex.Message,
215
0
                *this, anyEx );
216
0
    }
217
0
}
218
219
}
220
221
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
222
com_sun_star_comp_uui_UUIInteractionHandler_get_implementation(
223
    css::uno::XComponentContext *context,
224
    css::uno::Sequence<css::uno::Any> const &)
225
179k
{
226
179k
    return cppu::acquire(new UUIInteractionHandler(context));
227
179k
}
228
229
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */