Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svtools/source/uno/genericunodialog.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 <svtools/genericunodialog.hxx>
21
22
#include <com/sun/star/awt/XWindow.hpp>
23
#include <com/sun/star/beans/NamedValue.hpp>
24
#include <com/sun/star/beans/PropertyValue.hpp>
25
#include <com/sun/star/beans/PropertyAttribute.hpp>
26
#include <com/sun/star/ucb/AlreadyInitializedException.hpp>
27
28
#include <cppuhelper/supportsservice.hxx>
29
#include <cppuhelper/queryinterface.hxx>
30
#include <osl/diagnose.h>
31
#include <comphelper/diagnose_ex.hxx>
32
#include <osl/mutex.hxx>
33
#include <vcl/svapp.hxx>
34
#include <vcl/weld/DialogController.hxx>
35
36
using namespace css::uno;
37
using namespace css::lang;
38
using namespace css::beans;
39
using namespace css::ucb;
40
41
42
namespace svt
43
{
44
45
46
OGenericUnoDialog::OGenericUnoDialog(const Reference< XComponentContext >& _rxContext)
47
0
        :OPropertyContainer(GetBroadcastHelper())
48
0
        ,m_bExecuting(false)
49
0
        ,m_bTitleAmbiguous(true)
50
0
        ,m_bInitialized( false )
51
0
        ,m_aContext(_rxContext)
52
0
{
53
0
    registerProperty(UNODIALOG_PROPERTY_TITLE, UNODIALOG_PROPERTY_ID_TITLE, PropertyAttribute::TRANSIENT,
54
0
        &m_sTitle, cppu::UnoType<decltype(m_sTitle)>::get());
55
0
    registerProperty(UNODIALOG_PROPERTY_PARENT, UNODIALOG_PROPERTY_ID_PARENT, PropertyAttribute::TRANSIENT,
56
0
        &m_xParent, cppu::UnoType<decltype(m_xParent)>::get());
57
0
}
58
59
60
OGenericUnoDialog::~OGenericUnoDialog()
61
0
{
62
0
    if (m_xDialog)
63
0
    {
64
0
        SolarMutexGuard aSolarGuard;
65
0
        ::osl::MutexGuard aGuard( m_aMutex );
66
0
        if (m_xDialog)
67
0
            destroyDialog();
68
0
    }
69
0
}
70
71
72
Any SAL_CALL OGenericUnoDialog::queryInterface(const Type& _rType)
73
0
{
74
0
    Any aReturn = OGenericUnoDialogBase::queryInterface(_rType);
75
76
0
    if (!aReturn.hasValue())
77
0
        aReturn = ::cppu::queryInterface(_rType
78
0
            ,static_cast<XPropertySet*>(this)
79
0
            ,static_cast<XMultiPropertySet*>(this)
80
0
            ,static_cast<XFastPropertySet*>(this)
81
0
        );
82
83
0
    return aReturn;
84
0
}
85
86
87
Sequence<Type> SAL_CALL OGenericUnoDialog::getTypes(  )
88
0
{
89
0
    return ::comphelper::concatSequences(
90
0
        OGenericUnoDialogBase::getTypes(),
91
0
        getBaseTypes()
92
0
    );
93
0
}
94
95
sal_Bool SAL_CALL OGenericUnoDialog::supportsService(const OUString& ServiceName)
96
0
{
97
0
    return cppu::supportsService(this, ServiceName);
98
0
}
99
100
101
void OGenericUnoDialog::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue )
102
0
{
103
    // TODO: need some handling if we're currently executing ...
104
105
0
    OPropertyContainer::setFastPropertyValue_NoBroadcast(nHandle, rValue);
106
107
0
    if (UNODIALOG_PROPERTY_ID_TITLE == nHandle)
108
0
    {
109
        // from now on m_sTitle is valid
110
0
        m_bTitleAmbiguous = false;
111
112
0
        if (m_xDialog)
113
0
            m_xDialog->set_title(m_sTitle);
114
0
    }
115
0
}
116
117
118
sal_Bool OGenericUnoDialog::convertFastPropertyValue( Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue)
119
0
{
120
0
    switch (nHandle)
121
0
    {
122
0
        case UNODIALOG_PROPERTY_ID_PARENT:
123
0
        {
124
0
            Reference<css::awt::XWindow> xNew(rValue, css::uno::UNO_QUERY);
125
0
            if (xNew != m_xParent)
126
0
            {
127
0
                rConvertedValue <<= xNew;
128
0
                rOldValue <<= m_xParent;
129
0
                return true;
130
0
            }
131
0
            return false;
132
0
        }
133
0
    }
134
0
    return OPropertyContainer::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
135
0
}
136
137
138
void SAL_CALL OGenericUnoDialog::setTitle( const OUString& _rTitle )
139
0
{
140
0
    UnoDialogEntryGuard aGuard( *this );
141
142
0
    try
143
0
    {
144
0
        setPropertyValue(UNODIALOG_PROPERTY_TITLE, Any(_rTitle));
145
0
    }
146
0
    catch(RuntimeException&)
147
0
    {
148
        // allowed to pass
149
0
        throw;
150
0
    }
151
0
    catch( const Exception& )
152
0
    {
153
0
        DBG_UNHANDLED_EXCEPTION("svtools.uno");
154
        // not allowed to pass
155
0
    }
156
0
}
157
158
159
bool OGenericUnoDialog::impl_ensureDialog_lck()
160
0
{
161
0
    if (m_xDialog)
162
0
        return true;
163
164
    // get the parameters for the dialog from the current settings
165
166
    // the title
167
0
    OUString sTitle = m_sTitle;
168
169
0
    auto xDialog(createDialog(m_xParent));
170
0
    OSL_ENSURE(xDialog, "OGenericUnoDialog::impl_ensureDialog_lck: createDialog returned nonsense!");
171
0
    if (!xDialog)
172
0
        return false;
173
174
    // do some initialisations
175
0
    if (!m_bTitleAmbiguous)
176
0
        xDialog->set_title(sTitle);
177
178
0
    m_xDialog = std::move(xDialog);
179
180
0
    return true;
181
0
}
182
183
sal_Int16 SAL_CALL OGenericUnoDialog::execute()
184
0
{
185
    // both creation and execution of the dialog must be guarded with the SolarMutex, so be generous here
186
0
    SolarMutexGuard aSolarGuard;
187
188
    // create the dialog, if necessary
189
0
    {
190
0
        UnoDialogEntryGuard aGuard( *this );
191
192
0
        if (m_bExecuting)
193
0
            throw RuntimeException(
194
0
                    u"already executing the dialog (recursive call)"_ustr,
195
0
                    *this
196
0
                  );
197
198
0
        m_bExecuting = true;
199
200
0
        if ( !impl_ensureDialog_lck() )
201
0
            return 0;
202
0
    }
203
204
    // start execution
205
0
    sal_Int16 nReturn(0);
206
0
    if (m_xDialog)
207
0
        nReturn = m_xDialog->run();
208
209
0
    {
210
0
        ::osl::MutexGuard aGuard(m_aMutex);
211
212
        // get the settings of the dialog
213
0
        executedDialog( nReturn );
214
215
0
        m_bExecuting = false;
216
0
    }
217
218
    // outta here
219
0
    return nReturn;
220
0
}
221
222
void OGenericUnoDialog::implInitialize(const Any& _rValue)
223
0
{
224
0
    try
225
0
    {
226
0
        PropertyValue aProperty;
227
0
        NamedValue aValue;
228
0
        if ( _rValue >>= aProperty )
229
0
        {
230
0
            setPropertyValue( aProperty.Name, aProperty.Value );
231
0
        }
232
0
        else if ( _rValue >>= aValue )
233
0
        {
234
0
            setPropertyValue( aValue.Name, aValue.Value );
235
0
        }
236
0
    }
237
0
    catch(const Exception&)
238
0
    {
239
0
        DBG_UNHANDLED_EXCEPTION("svtools.uno");
240
0
    }
241
0
}
242
243
void SAL_CALL OGenericUnoDialog::initialize( const Sequence< Any >& aArguments )
244
0
{
245
0
    ::osl::MutexGuard aGuard( m_aMutex );
246
0
    if ( m_bInitialized )
247
0
        throw AlreadyInitializedException( OUString(), *this );
248
249
0
    for (const Any& rArgument : aArguments)
250
0
        implInitialize(rArgument);
251
252
0
    m_bInitialized = true;
253
0
}
254
255
void OGenericUnoDialog::destroyDialog()
256
0
{
257
0
    SolarMutexGuard aSolarGuard;
258
0
    m_xDialog.reset();
259
0
}
260
261
}   // namespace svt
262
263
264
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */