1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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/tabpage.hxx>
28 #include <vcl/tabctrl.hxx>
29 #include <vcl/svapp.hxx>
30 #include <toolkit/helper/vclunohelper.hxx>
32 #include <helper/tkresmgr.hxx>
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::lang
;
37 using namespace ::com::sun::star::beans
;
38 using namespace ::com::sun::star::container
;
41 void VCLXTabPageContainer::GetPropertyIds( std::vector
< sal_uInt16
> &rIds
)
43 VCLXWindow::ImplGetPropertyIds( rIds
);
46 VCLXTabPageContainer::VCLXTabPageContainer() :
47 m_aTabPageListeners( *this )
51 VCLXTabPageContainer::~VCLXTabPageContainer()
53 SAL_INFO("toolkit", __FUNCTION__
);
56 void SAL_CALL
VCLXTabPageContainer::draw( sal_Int32 nX
, sal_Int32 nY
)
58 SolarMutexGuard aGuard
;
59 VclPtr
<TabControl
> pTabControl
= GetAs
<TabControl
>();
62 TabPage
*pTabPage
= pTabControl
->GetTabPage( sal::static_int_cast
< sal_uInt16
>( pTabControl
->GetCurPageId( ) ) );
63 OutputDevice
* pDev
= VCLUnoHelper::GetOutputDevice( getGraphics() );
66 ::Point
aPos( nX
, nY
);
67 aPos
= pDev
->PixelToLogic( aPos
);
68 pTabPage
->Draw( pDev
, aPos
, SystemTextColorFlags::NONE
);
72 VCLXWindow::draw( nX
, nY
);
75 void SAL_CALL
VCLXTabPageContainer::setProperty(const OUString
& PropertyName
, const Any
& Value
)
77 SolarMutexGuard aGuard
;
78 VclPtr
<TabControl
> pTabPage
= GetAs
<TabControl
>();
80 VCLXWindow::setProperty( PropertyName
, Value
);
83 ::sal_Int16 SAL_CALL
VCLXTabPageContainer::getActiveTabPageID()
85 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
86 return pTabCtrl
? pTabCtrl
->GetCurPageId( ) : 0;
89 void SAL_CALL
VCLXTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid
)
91 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
93 pTabCtrl
->SelectTabPage(_activetabpageid
);
96 ::sal_Int16 SAL_CALL
VCLXTabPageContainer::getTabPageCount( )
98 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
99 return pTabCtrl
? pTabCtrl
->GetPageCount() : 0;
102 sal_Bool SAL_CALL
VCLXTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex
)
104 return (getActiveTabPageID() == tabPageIndex
);
107 Reference
< css::awt::tab::XTabPage
> SAL_CALL
VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex
)
109 return (tabPageIndex
>= 0 && o3tl::make_unsigned(tabPageIndex
) < m_aTabPages
.size()) ? m_aTabPages
[tabPageIndex
] : nullptr;
112 Reference
< css::awt::tab::XTabPage
> SAL_CALL
VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID
)
114 SolarMutexGuard aGuard
;
115 Reference
< css::awt::tab::XTabPage
> xTabPage
;
116 for(const auto& rTabPage
: m_aTabPages
)
118 Reference
< awt::XControl
> xControl(rTabPage
,UNO_QUERY
);
119 Reference
< awt::tab::XTabPageModel
> xP( xControl
->getModel(), UNO_QUERY
);
120 if ( tabPageID
== xP
->getTabPageID() )
129 void SAL_CALL
VCLXTabPageContainer::addTabPageContainerListener( const Reference
< css::awt::tab::XTabPageContainerListener
>& listener
)
131 m_aTabPageListeners
.addInterface( listener
);
134 void SAL_CALL
VCLXTabPageContainer::removeTabPageContainerListener( const Reference
< css::awt::tab::XTabPageContainerListener
>& listener
)
136 m_aTabPageListeners
.removeInterface( listener
);
139 void VCLXTabPageContainer::ProcessWindowEvent( const VclWindowEvent
& _rVclWindowEvent
)
141 SolarMutexClearableGuard aGuard
;
142 VclPtr
<TabControl
> pTabControl
= GetAs
<TabControl
>();
146 switch ( _rVclWindowEvent
.GetId() )
148 case VclEventId::TabpageActivate
:
150 sal_uInt16 page
= static_cast<sal_uInt16
>(reinterpret_cast<sal_uIntPtr
>(_rVclWindowEvent
.GetData()));
151 awt::tab::TabPageActivatedEvent
aEvent(nullptr,page
);
152 m_aTabPageListeners
.tabPageActivated(aEvent
);
157 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent
);
161 void SAL_CALL
VCLXTabPageContainer::disposing( const css::lang::EventObject
& /*Source*/ )
164 void SAL_CALL
VCLXTabPageContainer::elementInserted( const css::container::ContainerEvent
& Event
)
166 SolarMutexGuard aGuard
;
167 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
168 Reference
< css::awt::tab::XTabPage
> xTabPage(Event
.Element
,uno::UNO_QUERY
);
169 if ( !pTabCtrl
|| !xTabPage
.is() )
172 Reference
< awt::XControl
> xControl(xTabPage
,UNO_QUERY
);
173 Reference
< awt::tab::XTabPageModel
> xP( xControl
->getModel(), UNO_QUERY
);
174 sal_Int16 nPageID
= xP
->getTabPageID();
176 if (!xControl
->getPeer().is())
177 throw RuntimeException(u
"No peer for tabpage container!"_ustr
);
178 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow(xControl
->getPeer());
179 TabPage
* pPage
= static_cast<TabPage
*>(pWindow
.get());
180 pTabCtrl
->InsertPage(nPageID
,pPage
->GetText());
183 pTabCtrl
->SetTabPage(nPageID
,pPage
);
184 pTabCtrl
->SetHelpText(nPageID
,xP
->getToolTip());
185 pTabCtrl
->SetPageImage(nPageID
,TkResMgr::getImageFromURL(xP
->getImageURL()));
186 pTabCtrl
->SelectTabPage(nPageID
);
187 pTabCtrl
->SetPageEnabled(nPageID
,xP
->getEnabled());
188 m_aTabPages
.push_back(xTabPage
);
191 void SAL_CALL
VCLXTabPageContainer::elementRemoved( const css::container::ContainerEvent
& Event
)
193 SolarMutexGuard aGuard
;
194 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
195 Reference
< css::awt::tab::XTabPage
> xTabPage(Event
.Element
,uno::UNO_QUERY
);
196 if ( pTabCtrl
&& xTabPage
.is() )
198 Reference
< awt::XControl
> xControl(xTabPage
,UNO_QUERY
);
199 Reference
< awt::tab::XTabPageModel
> xP( xControl
->getModel(), UNO_QUERY
);
200 pTabCtrl
->RemovePage(xP
->getTabPageID());
201 std::erase(m_aTabPages
,xTabPage
);
204 void SAL_CALL
VCLXTabPageContainer::elementReplaced( const css::container::ContainerEvent
& /*Event*/ )
208 void VCLXTabPageContainer::propertiesChange(const::css::uno::Sequence
<PropertyChangeEvent
>& rEvents
)
210 SolarMutexGuard aGuard
;
211 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
215 for (const beans::PropertyChangeEvent
& rEvent
: rEvents
) {
216 // handle property changes for tab pages
217 Reference
< css::awt::tab::XTabPageModel
> xTabPageModel(rEvent
.Source
, uno::UNO_QUERY
);
218 if (!xTabPageModel
.is())
221 const sal_Int16 nId
= xTabPageModel
->getTabPageID();
222 if (rEvent
.PropertyName
== GetPropertyName(BASEPROPERTY_ENABLED
)) {
223 pTabCtrl
->SetPageEnabled(nId
, xTabPageModel
->getEnabled());
224 } else if (rEvent
.PropertyName
== GetPropertyName(BASEPROPERTY_TITLE
)) {
225 pTabCtrl
->SetPageText(nId
, xTabPageModel
->getTitle());
226 } else if (rEvent
.PropertyName
== GetPropertyName(BASEPROPERTY_IMAGEURL
)) {
227 pTabCtrl
->SetPageImage(nId
, TkResMgr::getImageFromURL(xTabPageModel
->getImageURL()));
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */