Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/toolkit/source/controls/tabpagemodel.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 <controls/tabpagemodel.hxx>
21
22
#include <vcl/svapp.hxx>
23
#include <helper/property.hxx>
24
#include <com/sun/star/awt/UnoControlDialogModelProvider.hpp>
25
#include <com/sun/star/awt/tab/XTabPage.hpp>
26
#include <com/sun/star/beans/XPropertySet.hpp>
27
#include <com/sun/star/uno/XComponentContext.hpp>
28
#include <cppuhelper/supportsservice.hxx>
29
#include <tools/debug.hxx>
30
#include <tools/mapunit.hxx>
31
#include <vcl/outdev.hxx>
32
33
#include <controls/controlmodelcontainerbase.hxx>
34
#include <toolkit/controls/unocontrolcontainer.hxx>
35
36
#include <helper/unopropertyarrayhelper.hxx>
37
38
using namespace ::com::sun::star;
39
using namespace ::com::sun::star::uno;
40
using namespace ::com::sun::star::awt;
41
42
UnoControlTabPageModel::UnoControlTabPageModel( Reference< XComponentContext > const & i_factory )
43
0
    :ControlModelContainerBase( i_factory )
44
0
{
45
0
    ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
46
0
    ImplRegisterProperty( BASEPROPERTY_TITLE );
47
0
    ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
48
0
    ImplRegisterProperty( BASEPROPERTY_HELPURL );
49
0
    ImplRegisterProperty( BASEPROPERTY_USERFORMCONTAINEES );
50
0
    ImplRegisterProperty( BASEPROPERTY_HSCROLL );
51
0
    ImplRegisterProperty( BASEPROPERTY_VSCROLL );
52
0
    ImplRegisterProperty( BASEPROPERTY_SCROLLWIDTH );
53
0
    ImplRegisterProperty( BASEPROPERTY_SCROLLHEIGHT );
54
0
    ImplRegisterProperty( BASEPROPERTY_SCROLLTOP );
55
0
    ImplRegisterProperty( BASEPROPERTY_SCROLLLEFT );
56
0
    ImplRegisterProperty( BASEPROPERTY_IMAGEURL );
57
0
}
Unexecuted instantiation: UnoControlTabPageModel::UnoControlTabPageModel(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&)
Unexecuted instantiation: UnoControlTabPageModel::UnoControlTabPageModel(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&)
58
59
OUString SAL_CALL UnoControlTabPageModel::getImplementationName()
60
0
{
61
0
    return u"stardiv.Toolkit.UnoControlTabPageModel"_ustr;
62
0
}
63
64
css::uno::Sequence< OUString > SAL_CALL UnoControlTabPageModel::getSupportedServiceNames()
65
0
{
66
0
    css::uno::Sequence< OUString > aNames = ControlModelContainerBase::getSupportedServiceNames( );
67
0
    aNames.realloc( aNames.getLength() + 1 );
68
0
    aNames.getArray()[ aNames.getLength() - 1 ] = "com.sun.star.awt.tab.UnoControlTabPageModel";
69
0
    return aNames;
70
0
}
71
72
OUString UnoControlTabPageModel::getServiceName( )
73
0
{
74
0
    return u"com.sun.star.awt.tab.UnoControlTabPageModel"_ustr;
75
0
}
76
77
Any UnoControlTabPageModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
78
0
{
79
0
    Any aAny;
80
81
0
    switch ( nPropId )
82
0
    {
83
0
        case BASEPROPERTY_DEFAULTCONTROL:
84
0
            aAny <<= u"com.sun.star.awt.tab.UnoControlTabPage"_ustr;
85
0
            break;
86
0
        case BASEPROPERTY_USERFORMCONTAINEES:
87
0
        {
88
            // We do not have here any usercontainers (yet?), but let's return empty container back
89
            // so normal properties could be set without triggering UnknownPropertyException
90
0
            aAny <<= uno::Reference< XNameContainer >();
91
0
            break;
92
0
        }
93
0
        default:
94
0
            aAny = UnoControlModel::ImplGetDefaultValue( nPropId );
95
0
    }
96
97
0
    return aAny;
98
0
}
99
100
::cppu::IPropertyArrayHelper& UnoControlTabPageModel::getInfoHelper()
101
0
{
102
0
    static UnoPropertyArrayHelper aHelper( ImplGetPropertyIds() );
103
0
    return aHelper;
104
0
}
105
// beans::XMultiPropertySet
106
uno::Reference< beans::XPropertySetInfo > UnoControlTabPageModel::getPropertySetInfo(  )
107
0
{
108
0
    static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
109
0
    return xInfo;
110
0
}
111
////----- XInitialization -------------------------------------------------------------------
112
void SAL_CALL UnoControlTabPageModel::initialize (const Sequence<Any>& rArguments)
113
0
{
114
0
    sal_Int16 nPageId = -1;
115
0
    if ( rArguments.getLength() == 1 )
116
0
    {
117
0
        if ( !( rArguments[ 0 ] >>= nPageId ))
118
0
             throw lang::IllegalArgumentException();
119
0
        m_nTabPageId = nPageId;
120
0
    }
121
0
    else if ( rArguments.getLength() == 2 )
122
0
    {
123
0
        if ( !( rArguments[ 0 ] >>= nPageId ))
124
0
             throw lang::IllegalArgumentException();
125
0
        m_nTabPageId = nPageId;
126
0
        OUString sURL;
127
0
        if ( !( rArguments[ 1 ] >>= sURL ))
128
0
            throw lang::IllegalArgumentException();
129
0
        Reference<container::XNameContainer > xDialogModel = awt::UnoControlDialogModelProvider::create( m_xContext, sURL );
130
0
        if ( xDialogModel.is() )
131
0
        {
132
0
            const Sequence< OUString> aNames = xDialogModel->getElementNames();
133
0
            for(const OUString& rName : aNames)
134
0
            {
135
0
                try
136
0
                {
137
0
                    Any aElement(xDialogModel->getByName(rName));
138
0
                    xDialogModel->removeByName(rName);
139
0
                    insertByName(rName,aElement);
140
0
                }
141
0
                catch(const Exception&) {}
142
0
            }
143
0
            Reference<XPropertySet> xDialogProp(xDialogModel,UNO_QUERY);
144
0
            if ( xDialogProp.is() )
145
0
            {
146
0
                static constexpr OUString s_sResourceResolver = u"ResourceResolver"_ustr;
147
0
                setPropertyValue(s_sResourceResolver,xDialogProp->getPropertyValue(s_sResourceResolver));
148
0
                setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE)));
149
0
                setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT)));
150
0
                setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL)));
151
0
            }
152
0
        }
153
0
    }
154
0
    else
155
0
        m_nTabPageId = -1;
156
0
}
157
158
159
UnoControlTabPage::UnoControlTabPage( const uno::Reference< uno::XComponentContext >& rxContext )
160
0
    :UnoControlTabPage_Base(rxContext)
161
0
    ,m_bWindowListener(false)
162
0
{
163
0
    maComponentInfos.nWidth = 280;
164
0
    maComponentInfos.nHeight = 400;
165
0
}
166
UnoControlTabPage::~UnoControlTabPage()
167
0
{
168
0
}
169
170
OUString UnoControlTabPage::GetComponentServiceName() const
171
0
{
172
0
    return u"TabPageModel"_ustr;
173
0
}
174
175
OUString SAL_CALL UnoControlTabPage::getImplementationName()
176
0
{
177
0
    return u"stardiv.Toolkit.UnoControlTabPage"_ustr;
178
0
}
179
180
sal_Bool SAL_CALL UnoControlTabPage::supportsService(OUString const & ServiceName)
181
0
{
182
0
    return cppu::supportsService(this, ServiceName);
183
0
}
184
185
css::uno::Sequence<OUString> SAL_CALL UnoControlTabPage::getSupportedServiceNames()
186
0
{
187
0
    return { u"com.sun.star.awt.tab.UnoControlTabPage"_ustr };
188
0
}
189
190
void SAL_CALL UnoControlTabPage::disposing( const lang::EventObject& Source )
191
0
{
192
0
     ControlContainerBase::disposing( Source );
193
0
}
194
195
void UnoControlTabPage::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer >  & rParentPeer )
196
0
{
197
0
    SolarMutexGuard aSolarGuard;
198
0
    ImplUpdateResourceResolver();
199
200
0
    UnoControlContainer::createPeer( rxToolkit, rParentPeer );
201
202
0
    Reference < tab::XTabPage > xTabPage( getPeer(), UNO_QUERY );
203
0
    if ( xTabPage.is() )
204
0
    {
205
0
        if ( !m_bWindowListener )
206
0
        {
207
0
            Reference< XWindowListener > xWL(this);
208
0
            addWindowListener( xWL );
209
0
            m_bWindowListener = true;
210
0
        }
211
0
    }
212
0
}
213
214
static ::Size ImplMapPixelToAppFont( OutputDevice const * pOutDev, const ::Size& aSize )
215
0
{
216
0
    ::Size aTmp = pOutDev->PixelToLogic(aSize, MapMode(MapUnit::MapAppFont));
217
0
    return aTmp;
218
0
}
219
// css::awt::XWindowListener
220
void SAL_CALL UnoControlTabPage::windowResized( const css::awt::WindowEvent& e )
221
0
{
222
0
    OutputDevice*pOutDev = Application::GetDefaultDevice();
223
0
    DBG_ASSERT( pOutDev, "Missing Default Device!" );
224
0
    if ( !pOutDev || mbSizeModified )
225
0
        return;
226
227
    // Currently we are simply using MapUnit::MapAppFont
228
0
    ::Size aAppFontSize( e.Width, e.Height );
229
230
0
    Reference< XControl > xDialogControl( *this, UNO_QUERY_THROW );
231
0
    Reference< XDevice > xDialogDevice( xDialogControl->getPeer(), UNO_QUERY );
232
0
    OSL_ENSURE( xDialogDevice.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
233
0
    if ( xDialogDevice.is() )
234
0
    {
235
0
        DeviceInfo aDeviceInfo( xDialogDevice->getInfo() );
236
0
        aAppFontSize.AdjustWidth( -(aDeviceInfo.LeftInset + aDeviceInfo.RightInset) );
237
0
        aAppFontSize.AdjustHeight( -(aDeviceInfo.TopInset + aDeviceInfo.BottomInset) );
238
0
    }
239
240
0
    aAppFontSize = ImplMapPixelToAppFont( pOutDev, aAppFontSize );
241
242
    // Remember that changes have been done by listener. No need to
243
    // update the position because of property change event.
244
0
    mbSizeModified = true;
245
    // Properties in a sequence must be sorted!
246
0
    Sequence< OUString > aProps{ u"Height"_ustr, u"Width"_ustr };
247
0
    Sequence< Any > aValues{ Any(aAppFontSize.Height()), Any(aAppFontSize.Width()) };
248
249
0
    ImplSetPropertyValues( aProps, aValues, true );
250
0
    mbSizeModified = false;
251
252
0
}
253
254
void SAL_CALL UnoControlTabPage::windowMoved( const css::awt::WindowEvent& e )
255
0
{
256
0
    OutputDevice*pOutDev = Application::GetDefaultDevice();
257
0
    DBG_ASSERT( pOutDev, "Missing Default Device!" );
258
0
    if ( !pOutDev || mbPosModified )
259
0
        return;
260
261
    // Currently we are simply using MapUnit::MapAppFont
262
0
    ::Size aTmp( e.X, e.Y );
263
0
    aTmp = ImplMapPixelToAppFont( pOutDev, aTmp );
264
265
    // Remember that changes have been done by listener. No need to
266
    // update the position because of property change event.
267
0
    mbPosModified = true;
268
0
    Sequence< OUString > aProps{ u"PositionX"_ustr, u"PositionY"_ustr };
269
0
    Sequence< Any > aValues{ Any(aTmp.Width()), Any(aTmp.Height()) };
270
271
0
    ImplSetPropertyValues( aProps, aValues, true );
272
0
    mbPosModified = false;
273
274
0
}
275
276
0
void SAL_CALL UnoControlTabPage::windowShown( const css::lang::EventObject& ) {}
277
278
0
void SAL_CALL UnoControlTabPage::windowHidden( const css::lang::EventObject& ) {}
279
280
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
281
stardiv_Toolkit_UnoControlTabPageModel_get_implementation(
282
    css::uno::XComponentContext *context,
283
    css::uno::Sequence<css::uno::Any> const &)
284
0
{
285
0
    return cppu::acquire(new UnoControlTabPageModel(context));
286
0
}
287
288
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
289
stardiv_Toolkit_UnoControlTabPage_get_implementation(
290
    css::uno::XComponentContext *context,
291
    css::uno::Sequence<css::uno::Any> const &)
292
0
{
293
0
    return cppu::acquire(new UnoControlTabPage(context));
294
0
}
295
296
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */