Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/toolkit/source/controls/unocontrolbase.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 <com/sun/star/awt/XLayoutConstrains.hpp>
21
#include <com/sun/star/awt/XTextLayoutConstrains.hpp>
22
#include <com/sun/star/awt/XVclWindowPeer.hpp>
23
#include <com/sun/star/beans/XPropertySet.hpp>
24
#include <com/sun/star/beans/XMultiPropertySet.hpp>
25
#include <com/sun/star/util/Date.hpp>
26
#include <com/sun/star/util/Time.hpp>
27
28
#include <toolkit/controls/unocontrolbase.hxx>
29
#include <helper/property.hxx>
30
31
#include <tools/debug.hxx>
32
33
using namespace com::sun::star;
34
35
36
37
38
bool UnoControlBase::ImplHasProperty( sal_uInt16 nPropId )
39
0
{
40
0
    const OUString& aPropName( GetPropertyName( nPropId ) );
41
0
    return ImplHasProperty( aPropName );
42
0
}
43
44
bool UnoControlBase::ImplHasProperty( const OUString& aPropertyName )
45
0
{
46
0
    css::uno::Reference< css::beans::XPropertySet >  xPSet( mxModel, css::uno::UNO_QUERY );
47
0
    if ( !xPSet.is() )
48
0
        return false;
49
0
    css::uno::Reference< css::beans::XPropertySetInfo >  xInfo = xPSet->getPropertySetInfo();
50
0
    if ( !xInfo.is() )
51
0
        return false;
52
53
0
    return xInfo->hasPropertyByName( aPropertyName );
54
0
}
55
56
void UnoControlBase::ImplSetPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues, bool bUpdateThis )
57
0
{
58
0
    css::uno::Reference< css::beans::XMultiPropertySet > xMPS( mxModel, css::uno::UNO_QUERY );
59
0
    if ( !mxModel.is() )
60
0
        return;
61
62
0
    DBG_ASSERT( xMPS.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" );
63
0
    if ( !xMPS.is() )
64
0
        return;
65
66
0
    if ( !bUpdateThis )
67
0
        ImplLockPropertyChangeNotifications( aPropertyNames, true );
68
69
0
    try
70
0
    {
71
0
        xMPS->setPropertyValues( aPropertyNames, aValues );
72
0
    }
73
0
    catch( const css::uno::Exception& )
74
0
    {
75
0
        if ( !bUpdateThis )
76
0
            ImplLockPropertyChangeNotifications( aPropertyNames, false );
77
0
    }
78
0
    if ( !bUpdateThis )
79
0
        ImplLockPropertyChangeNotifications( aPropertyNames, false );
80
0
}
81
82
void UnoControlBase::ImplSetPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue, bool bUpdateThis )
83
0
{
84
    // Model might be logged off already but an event still fires
85
0
    if ( !mxModel.is() )
86
0
        return;
87
88
0
    css::uno::Reference< css::beans::XPropertySet >  xPSet( mxModel, css::uno::UNO_QUERY );
89
0
    if ( !bUpdateThis )
90
0
        ImplLockPropertyChangeNotification( aPropertyName, true );
91
92
0
    try
93
0
    {
94
0
        xPSet->setPropertyValue( aPropertyName, aValue );
95
0
    }
96
0
    catch( const css::uno::Exception& )
97
0
    {
98
0
        if ( !bUpdateThis )
99
0
            ImplLockPropertyChangeNotification( aPropertyName, false );
100
0
        throw;
101
0
    }
102
0
    if ( !bUpdateThis )
103
0
        ImplLockPropertyChangeNotification( aPropertyName, false );
104
0
}
105
106
css::uno::Any UnoControlBase::ImplGetPropertyValue( const OUString& aPropertyName ) const
107
0
{
108
0
    css::uno::Reference< css::beans::XPropertySet >  xPSet( mxModel, css::uno::UNO_QUERY );
109
0
    if ( xPSet.is() )
110
0
        return xPSet->getPropertyValue( aPropertyName );
111
0
    else
112
0
        return css::uno::Any();
113
0
}
114
115
template <typename T> T UnoControlBase::ImplGetPropertyValuePOD( sal_uInt16 nProp )
116
0
{
117
0
    T t(0);
118
0
    if ( mxModel.is() )
119
0
    {
120
0
        css::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
121
0
        aVal >>= t;
122
0
    }
123
0
    return t;
124
0
}
Unexecuted instantiation: bool UnoControlBase::ImplGetPropertyValuePOD<bool>(unsigned short)
Unexecuted instantiation: short UnoControlBase::ImplGetPropertyValuePOD<short>(unsigned short)
Unexecuted instantiation: int UnoControlBase::ImplGetPropertyValuePOD<int>(unsigned short)
Unexecuted instantiation: double UnoControlBase::ImplGetPropertyValuePOD<double>(unsigned short)
125
126
template <typename T> T UnoControlBase::ImplGetPropertyValueClass( sal_uInt16 nProp )
127
0
{
128
0
    T t;
129
0
    if ( mxModel.is() )
130
0
    {
131
0
        css::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
132
0
        aVal >>= t;
133
0
    }
134
0
    return t;
135
0
}
Unexecuted instantiation: rtl::OUString UnoControlBase::ImplGetPropertyValueClass<rtl::OUString>(unsigned short)
Unexecuted instantiation: com::sun::star::util::Date UnoControlBase::ImplGetPropertyValueClass<com::sun::star::util::Date>(unsigned short)
Unexecuted instantiation: com::sun::star::util::Time UnoControlBase::ImplGetPropertyValueClass<com::sun::star::util::Time>(unsigned short)
136
137
bool UnoControlBase::ImplGetPropertyValue_BOOL( sal_uInt16 nProp )
138
0
{
139
0
    return ImplGetPropertyValuePOD<bool>(nProp);
140
0
}
141
142
sal_Int16 UnoControlBase::ImplGetPropertyValue_INT16( sal_uInt16 nProp )
143
0
{
144
0
    return ImplGetPropertyValuePOD<sal_Int16>(nProp);
145
0
}
146
147
sal_Int32 UnoControlBase::ImplGetPropertyValue_INT32( sal_uInt16 nProp )
148
0
{
149
0
    return ImplGetPropertyValuePOD<sal_Int32>(nProp);
150
0
}
151
152
double UnoControlBase::ImplGetPropertyValue_DOUBLE( sal_uInt16 nProp )
153
0
{
154
0
    return ImplGetPropertyValuePOD<double>(nProp);
155
0
}
156
157
OUString UnoControlBase::ImplGetPropertyValue_UString( sal_uInt16 nProp )
158
0
{
159
0
    return ImplGetPropertyValueClass<OUString>(nProp);
160
0
}
161
162
util::Date UnoControlBase::ImplGetPropertyValue_Date( sal_uInt16 nProp )
163
0
{
164
0
    return ImplGetPropertyValueClass<util::Date>(nProp);
165
0
}
166
167
util::Time UnoControlBase::ImplGetPropertyValue_Time( sal_uInt16 nProp )
168
0
{
169
0
    return ImplGetPropertyValueClass<util::Time>(nProp);
170
0
}
171
172
css::awt::Size UnoControlBase::Impl_getMinimumSize()
173
0
{
174
0
    css::awt::Size aSz;
175
0
    css::uno::Reference< css::awt::XWindowPeer >  xP = ImplGetCompatiblePeer();
176
0
    DBG_ASSERT( xP.is(), "Layout: No Peer!" );
177
0
    if ( xP.is() )
178
0
    {
179
0
        css::uno::Reference< css::awt::XLayoutConstrains >  xL( xP, css::uno::UNO_QUERY );
180
0
        if ( xL.is() )
181
0
            aSz = xL->getMinimumSize();
182
183
0
        if ( !getPeer().is() || ( getPeer() != xP ) )
184
0
            xP->dispose();
185
0
    }
186
0
    return aSz;
187
0
}
188
189
css::awt::Size UnoControlBase::Impl_getPreferredSize()
190
0
{
191
0
    css::awt::Size aSz;
192
0
    css::uno::Reference< css::awt::XWindowPeer >  xP = ImplGetCompatiblePeer();
193
0
    DBG_ASSERT( xP.is(), "Layout: No Peer!" );
194
0
    if ( xP.is() )
195
0
    {
196
0
        css::uno::Reference< css::awt::XLayoutConstrains >  xL( xP, css::uno::UNO_QUERY );
197
0
        if ( xL.is() )
198
0
            aSz = xL->getPreferredSize();
199
200
0
        if ( !getPeer().is() || ( getPeer() != xP ) )
201
0
            xP->dispose();
202
0
    }
203
0
    return aSz;
204
0
}
205
206
css::awt::Size UnoControlBase::Impl_calcAdjustedSize( const css::awt::Size& rNewSize )
207
0
{
208
0
    css::awt::Size aSz;
209
0
    css::uno::Reference< css::awt::XWindowPeer >  xP = ImplGetCompatiblePeer();
210
0
    DBG_ASSERT( xP.is(), "Layout: No Peer!" );
211
0
    if ( xP.is() )
212
0
    {
213
0
        css::uno::Reference< css::awt::XLayoutConstrains > xL( xP, css::uno::UNO_QUERY );
214
0
        if ( xL.is() )
215
0
            aSz = xL->calcAdjustedSize( rNewSize );
216
217
0
        if ( !getPeer().is() || ( getPeer() != xP ) )
218
0
            xP->dispose();
219
0
    }
220
0
    return aSz;
221
0
}
222
223
css::awt::Size UnoControlBase::Impl_getMinimumSize( sal_Int16 nCols, sal_Int16 nLines )
224
0
{
225
0
    css::awt::Size aSz;
226
0
    css::uno::Reference< css::awt::XWindowPeer >  xP = ImplGetCompatiblePeer();
227
0
    DBG_ASSERT( xP.is(), "Layout: No Peer!" );
228
0
    if ( xP.is() )
229
0
    {
230
0
        css::uno::Reference< css::awt::XTextLayoutConstrains >  xL( xP, css::uno::UNO_QUERY );
231
0
        if ( xL.is() )
232
0
            aSz = xL->getMinimumSize( nCols, nLines );
233
234
0
        if ( !getPeer().is() || ( getPeer() != xP ) )
235
0
            xP->dispose();
236
0
    }
237
0
    return aSz;
238
0
}
239
240
void UnoControlBase::Impl_getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines )
241
0
{
242
0
    css::uno::Reference< css::awt::XWindowPeer >  xP = ImplGetCompatiblePeer();
243
0
    DBG_ASSERT( xP.is(), "Layout: No Peer!" );
244
0
    if ( xP.is() )
245
0
    {
246
0
        css::uno::Reference< css::awt::XTextLayoutConstrains >  xL( xP, css::uno::UNO_QUERY );
247
0
        if ( xL.is() )
248
0
            xL->getColumnsAndLines( nCols, nLines );
249
250
0
        if ( !getPeer().is() || ( getPeer() != xP ) )
251
0
            xP->dispose();
252
0
    }
253
0
}
254
255
256
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */