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 <toolkit/awt/vclxtabpagecontainer.hxx>
21 #include <com/sun/star/awt/tab/XTabPageModel.hpp>
22 #include <com/sun/star/awt/XControl.hpp>
23 #include <sal/log.hxx>
24 #include <vcl/image.hxx>
25 #include <vcl/tabpage.hxx>
26 #include <vcl/tabctrl.hxx>
27 #include <vcl/svapp.hxx>
28 #include <toolkit/helper/property.hxx>
29 #include <toolkit/helper/vclunohelper.hxx>
30 #include <cppuhelper/typeprovider.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
;
39 using namespace ::com::sun::star::view
;
41 // class VCLXTabPageContainer
43 void VCLXTabPageContainer::GetPropertyIds( std::vector
< sal_uInt16
> &rIds
)
45 VCLXWindow::ImplGetPropertyIds( rIds
);
48 VCLXTabPageContainer::VCLXTabPageContainer() :
49 m_aTabPageListeners( *this )
53 VCLXTabPageContainer::~VCLXTabPageContainer()
55 SAL_INFO("toolkit", __FUNCTION__
);
58 void SAL_CALL
VCLXTabPageContainer::draw( sal_Int32 nX
, sal_Int32 nY
)
60 SolarMutexGuard aGuard
;
61 VclPtr
<TabControl
> pTabControl
= GetAs
<TabControl
>();
64 TabPage
*pTabPage
= pTabControl
->GetTabPage( sal::static_int_cast
< sal_uInt16
>( pTabControl
->GetCurPageId( ) ) );
65 OutputDevice
* pDev
= VCLUnoHelper::GetOutputDevice( getGraphics() );
68 ::Point
aPos( nX
, nY
);
69 ::Size aSize
= pTabPage
->GetSizePixel();
71 aPos
= pDev
->PixelToLogic( aPos
);
72 aSize
= pDev
->PixelToLogic( aSize
);
74 pTabPage
->Draw( pDev
, aPos
, aSize
, DrawFlags::NONE
);
78 VCLXWindow::draw( nX
, nY
);
81 void SAL_CALL
VCLXTabPageContainer::setProperty(const OUString
& PropertyName
, const Any
& Value
)
83 SolarMutexGuard aGuard
;
84 VclPtr
<TabControl
> pTabPage
= GetAs
<TabControl
>();
86 VCLXWindow::setProperty( PropertyName
, Value
);
89 ::sal_Int16 SAL_CALL
VCLXTabPageContainer::getActiveTabPageID()
91 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
92 return pTabCtrl
? pTabCtrl
->GetCurPageId( ) : 0;
95 void SAL_CALL
VCLXTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid
)
97 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
99 pTabCtrl
->SelectTabPage(_activetabpageid
);
102 ::sal_Int16 SAL_CALL
VCLXTabPageContainer::getTabPageCount( )
104 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
105 return pTabCtrl
? pTabCtrl
->GetPageCount() : 0;
108 sal_Bool SAL_CALL
VCLXTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex
)
110 return (getActiveTabPageID() == tabPageIndex
);
113 Reference
< css::awt::tab::XTabPage
> SAL_CALL
VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex
)
115 return (tabPageIndex
>= 0 && tabPageIndex
< static_cast<sal_Int16
>(m_aTabPages
.size())) ? m_aTabPages
[tabPageIndex
] : nullptr;
118 Reference
< css::awt::tab::XTabPage
> SAL_CALL
VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID
)
120 SolarMutexGuard aGuard
;
121 Reference
< css::awt::tab::XTabPage
> xTabPage
;
122 for(const auto& rTabPage
: m_aTabPages
)
124 Reference
< awt::XControl
> xControl(rTabPage
,UNO_QUERY
);
125 Reference
< awt::tab::XTabPageModel
> xP( xControl
->getModel(), UNO_QUERY
);
126 if ( tabPageID
== xP
->getTabPageID() )
135 void SAL_CALL
VCLXTabPageContainer::addTabPageContainerListener( const Reference
< css::awt::tab::XTabPageContainerListener
>& listener
)
137 m_aTabPageListeners
.addInterface( listener
);
140 void SAL_CALL
VCLXTabPageContainer::removeTabPageContainerListener( const Reference
< css::awt::tab::XTabPageContainerListener
>& listener
)
142 m_aTabPageListeners
.removeInterface( listener
);
145 void VCLXTabPageContainer::ProcessWindowEvent( const VclWindowEvent
& _rVclWindowEvent
)
147 SolarMutexClearableGuard aGuard
;
148 VclPtr
<TabControl
> pTabControl
= GetAs
<TabControl
>();
151 switch ( _rVclWindowEvent
.GetId() )
153 case VclEventId::TabpageActivate
:
155 sal_uLong page
= reinterpret_cast<sal_uLong
>(_rVclWindowEvent
.GetData());
156 awt::tab::TabPageActivatedEvent
aEvent(nullptr,page
);
157 m_aTabPageListeners
.tabPageActivated(aEvent
);
162 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent
);
167 void SAL_CALL
VCLXTabPageContainer::disposing( const css::lang::EventObject
& /*Source*/ )
170 void SAL_CALL
VCLXTabPageContainer::elementInserted( const css::container::ContainerEvent
& Event
)
172 SolarMutexGuard aGuard
;
173 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
174 Reference
< css::awt::tab::XTabPage
> xTabPage(Event
.Element
,uno::UNO_QUERY
);
175 if ( !pTabCtrl
|| !xTabPage
.is() )
178 Reference
< awt::XControl
> xControl(xTabPage
,UNO_QUERY
);
179 Reference
< awt::tab::XTabPageModel
> xP( xControl
->getModel(), UNO_QUERY
);
180 sal_Int16 nPageID
= xP
->getTabPageID();
182 if (!xControl
->getPeer().is())
183 throw RuntimeException("No peer for tabpage container!");
184 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow(xControl
->getPeer());
185 TabPage
* pPage
= static_cast<TabPage
*>(pWindow
.get());
186 pTabCtrl
->InsertPage(nPageID
,pPage
->GetText());
189 pTabCtrl
->SetTabPage(nPageID
,pPage
);
190 pTabCtrl
->SetHelpText(nPageID
,xP
->getToolTip());
191 pTabCtrl
->SetPageImage(nPageID
,TkResMgr::getImageFromURL(xP
->getImageURL()));
192 pTabCtrl
->SelectTabPage(nPageID
);
193 pTabCtrl
->EnablePage(nPageID
,xP
->getEnabled());
194 m_aTabPages
.push_back(xTabPage
);
197 void SAL_CALL
VCLXTabPageContainer::elementRemoved( const css::container::ContainerEvent
& Event
)
199 SolarMutexGuard aGuard
;
200 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
201 Reference
< css::awt::tab::XTabPage
> xTabPage(Event
.Element
,uno::UNO_QUERY
);
202 if ( pTabCtrl
&& xTabPage
.is() )
204 Reference
< awt::XControl
> xControl(xTabPage
,UNO_QUERY
);
205 Reference
< awt::tab::XTabPageModel
> xP( xControl
->getModel(), UNO_QUERY
);
206 pTabCtrl
->RemovePage(xP
->getTabPageID());
207 m_aTabPages
.erase(::std::remove(m_aTabPages
.begin(),m_aTabPages
.end(),xTabPage
));
210 void SAL_CALL
VCLXTabPageContainer::elementReplaced( const css::container::ContainerEvent
& /*Event*/ )
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */