Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/toolkit/source/awt/vclxtabpagecontainer.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 <awt/vclxtabpagecontainer.hxx>
21
#include <com/sun/star/awt/tab/XTabPageModel.hpp>
22
#include <com/sun/star/awt/XControl.hpp>
23
#include <o3tl/safeint.hxx>
24
#include <sal/log.hxx>
25
#include <helper/property.hxx>
26
#include <vcl/image.hxx>
27
#include <vcl/rendercontext/SystemTextColorFlags.hxx>
28
#include <vcl/tabpage.hxx>
29
#include <vcl/tabctrl.hxx>
30
#include <vcl/svapp.hxx>
31
#include <vcl/vclevent.hxx>
32
#include <toolkit/helper/vclunohelper.hxx>
33
34
#include <helper/tkresmgr.hxx>
35
36
using namespace ::com::sun::star;
37
using namespace ::com::sun::star::uno;
38
using namespace ::com::sun::star::lang;
39
using namespace ::com::sun::star::beans;
40
using namespace ::com::sun::star::container;
41
42
43
void VCLXTabPageContainer::GetPropertyIds( std::vector< sal_uInt16 > &rIds )
44
0
{
45
0
    VCLXWindow::ImplGetPropertyIds( rIds );
46
0
}
47
48
VCLXTabPageContainer::VCLXTabPageContainer() :
49
0
    m_aTabPageListeners( *this )
50
0
{
51
0
}
52
53
VCLXTabPageContainer::~VCLXTabPageContainer()
54
0
{
55
0
    SAL_INFO("toolkit", __FUNCTION__);
56
0
}
57
58
void SAL_CALL VCLXTabPageContainer::draw( sal_Int32 nX, sal_Int32 nY )
59
0
{
60
0
    SolarMutexGuard aGuard;
61
0
    VclPtr<TabControl> pTabControl = GetAs<TabControl>();
62
0
    if ( pTabControl )
63
0
    {
64
0
        TabPage *pTabPage = pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >(  pTabControl->GetCurPageId( ) ) );
65
0
        OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() );
66
0
        if (pTabPage && pDev)
67
0
        {
68
0
            ::Point aPos( nX, nY );
69
0
            aPos  = pDev->PixelToLogic( aPos );
70
0
            pTabPage->Draw( pDev, aPos, SystemTextColorFlags::NONE );
71
0
        }
72
0
    }
73
74
0
    VCLXWindow::draw( nX, nY );
75
0
}
76
77
void SAL_CALL VCLXTabPageContainer::setProperty(const OUString& PropertyName,   const Any& Value )
78
0
{
79
0
    SolarMutexGuard aGuard;
80
0
    VclPtr<TabControl> pTabPage = GetAs<TabControl>();
81
0
    if ( pTabPage )
82
0
        VCLXWindow::setProperty( PropertyName, Value );
83
0
}
84
85
::sal_Int16 SAL_CALL VCLXTabPageContainer::getActiveTabPageID()
86
0
{
87
0
    VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
88
0
    return pTabCtrl ? pTabCtrl->GetCurPageId( ) : 0;
89
0
}
90
91
void SAL_CALL VCLXTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid )
92
0
{
93
0
    VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
94
0
    if ( pTabCtrl )
95
0
        pTabCtrl->SelectTabPage(_activetabpageid);
96
0
}
97
98
::sal_Int16 SAL_CALL VCLXTabPageContainer::getTabPageCount(  )
99
0
{
100
0
    VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
101
0
    return pTabCtrl ? pTabCtrl->GetPageCount() : 0;
102
0
}
103
104
sal_Bool SAL_CALL VCLXTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex )
105
0
{
106
0
    return (getActiveTabPageID() == tabPageIndex);
107
0
}
108
109
Reference< css::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex )
110
0
{
111
0
    return (tabPageIndex >= 0 && o3tl::make_unsigned(tabPageIndex) < m_aTabPages.size()) ? m_aTabPages[tabPageIndex] : nullptr;
112
0
}
113
114
Reference< css::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID )
115
0
{
116
0
    SolarMutexGuard aGuard;
117
0
    Reference< css::awt::tab::XTabPage > xTabPage;
118
0
    for(const auto& rTabPage : m_aTabPages)
119
0
    {
120
0
        Reference< awt::XControl > xControl(rTabPage,UNO_QUERY );
121
0
        Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
122
0
        if ( tabPageID == xP->getTabPageID() )
123
0
        {
124
0
            xTabPage = rTabPage;
125
0
            break;
126
0
        }
127
0
    }
128
0
    return xTabPage;
129
0
}
130
131
void SAL_CALL VCLXTabPageContainer::addTabPageContainerListener( const Reference< css::awt::tab::XTabPageContainerListener >& listener )
132
0
{
133
0
    m_aTabPageListeners.addInterface( listener );
134
0
}
135
136
void SAL_CALL VCLXTabPageContainer::removeTabPageContainerListener( const Reference< css::awt::tab::XTabPageContainerListener >& listener )
137
0
{
138
0
    m_aTabPageListeners.removeInterface( listener );
139
0
}
140
141
void VCLXTabPageContainer::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
142
0
{
143
0
    SolarMutexClearableGuard aGuard;
144
0
    VclPtr<TabControl> pTabControl = GetAs<TabControl>();
145
0
    if ( !pTabControl )
146
0
        return;
147
148
0
    switch ( _rVclWindowEvent.GetId() )
149
0
    {
150
0
        case VclEventId::TabpageActivate:
151
0
        {
152
0
            sal_uInt16 page = static_cast<sal_uInt16>(reinterpret_cast<sal_uIntPtr>(_rVclWindowEvent.GetData()));
153
0
            awt::tab::TabPageActivatedEvent aEvent(nullptr,page);
154
0
            m_aTabPageListeners.tabPageActivated(aEvent);
155
0
            break;
156
0
        }
157
0
        default:
158
0
            aGuard.clear();
159
0
            VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
160
0
            break;
161
0
    }
162
0
}
163
void SAL_CALL VCLXTabPageContainer::disposing( const css::lang::EventObject& /*Source*/ )
164
0
{
165
0
}
166
void SAL_CALL VCLXTabPageContainer::elementInserted( const css::container::ContainerEvent& Event )
167
0
{
168
0
    SolarMutexGuard aGuard;
169
0
    VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
170
0
    Reference< css::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY);
171
0
    if ( !pTabCtrl || !xTabPage.is() )
172
0
        return;
173
174
0
    Reference< awt::XControl > xControl(xTabPage,UNO_QUERY );
175
0
    Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
176
0
    sal_Int16 nPageID = xP->getTabPageID();
177
178
0
    if (!xControl->getPeer().is())
179
0
        throw RuntimeException(u"No peer for tabpage container!"_ustr);
180
0
    VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xControl->getPeer());
181
0
    TabPage* pPage = static_cast<TabPage*>(pWindow.get());
182
0
    pTabCtrl->InsertPage(nPageID,pPage->GetText());
183
184
0
    pPage->Hide();
185
0
    pTabCtrl->SetTabPage(nPageID,pPage);
186
0
    pTabCtrl->SetHelpText(nPageID,xP->getToolTip());
187
0
    pTabCtrl->SetPageImage(nPageID,TkResMgr::getImageFromURL(xP->getImageURL()));
188
0
    pTabCtrl->SelectTabPage(nPageID);
189
0
    pTabCtrl->SetPageEnabled(nPageID,xP->getEnabled());
190
0
    m_aTabPages.push_back(xTabPage);
191
192
0
}
193
void SAL_CALL VCLXTabPageContainer::elementRemoved( const css::container::ContainerEvent& Event )
194
0
{
195
0
    SolarMutexGuard aGuard;
196
0
    VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
197
0
    Reference< css::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY);
198
0
    if ( pTabCtrl && xTabPage.is() )
199
0
    {
200
0
        Reference< awt::XControl > xControl(xTabPage,UNO_QUERY );
201
0
        Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
202
0
        pTabCtrl->RemovePage(xP->getTabPageID());
203
0
        std::erase(m_aTabPages,xTabPage);
204
0
    }
205
0
}
206
void SAL_CALL VCLXTabPageContainer::elementReplaced( const css::container::ContainerEvent& /*Event*/ )
207
0
{
208
0
}
209
210
void VCLXTabPageContainer::propertiesChange(const::css::uno::Sequence<PropertyChangeEvent>& rEvents)
211
0
{
212
0
    SolarMutexGuard aGuard;
213
0
    VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
214
0
    if (!pTabCtrl)
215
0
        return;
216
217
0
    for (const beans::PropertyChangeEvent& rEvent : rEvents) {
218
        // handle property changes for tab pages
219
0
        Reference< css::awt::tab::XTabPageModel > xTabPageModel(rEvent.Source, uno::UNO_QUERY);
220
0
        if (!xTabPageModel.is())
221
0
            continue;
222
223
0
        const sal_Int16 nId = xTabPageModel->getTabPageID();
224
0
        if (rEvent.PropertyName == GetPropertyName(BASEPROPERTY_ENABLED)) {
225
0
            pTabCtrl->SetPageEnabled(nId, xTabPageModel->getEnabled());
226
0
        } else if (rEvent.PropertyName == GetPropertyName(BASEPROPERTY_TITLE)) {
227
0
            pTabCtrl->SetPageText(nId, xTabPageModel->getTitle());
228
0
        } else if (rEvent.PropertyName == GetPropertyName(BASEPROPERTY_IMAGEURL)) {
229
0
            pTabCtrl->SetPageImage(nId, TkResMgr::getImageFromURL(xTabPageModel->getImageURL()));
230
0
        }
231
0
    }
232
0
}
233
234
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */