Coverage Report

Created: 2025-11-16 09:57

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