Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / toolkit / source / awt / vclxtabpagecontainer.cxx
blob55a27ba2af27b553cf5b77523befe798837517b1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
39 using namespace ::com::sun::star::view;
42 void VCLXTabPageContainer::GetPropertyIds( std::vector< sal_uInt16 > &rIds )
44 VCLXWindow::ImplGetPropertyIds( rIds );
47 VCLXTabPageContainer::VCLXTabPageContainer() :
48 m_aTabPageListeners( *this )
52 VCLXTabPageContainer::~VCLXTabPageContainer()
54 SAL_INFO("toolkit", __FUNCTION__);
57 void SAL_CALL VCLXTabPageContainer::draw( sal_Int32 nX, sal_Int32 nY )
59 SolarMutexGuard aGuard;
60 VclPtr<TabControl> pTabControl = GetAs<TabControl>();
61 if ( pTabControl )
63 TabPage *pTabPage = pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( pTabControl->GetCurPageId( ) ) );
64 OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() );
65 if (pTabPage && pDev)
67 ::Point aPos( nX, nY );
68 aPos = pDev->PixelToLogic( aPos );
69 pTabPage->Draw( pDev, aPos, SystemTextColorFlags::NONE );
73 VCLXWindow::draw( nX, nY );
76 void SAL_CALL VCLXTabPageContainer::setProperty(const OUString& PropertyName, const Any& Value )
78 SolarMutexGuard aGuard;
79 VclPtr<TabControl> pTabPage = GetAs<TabControl>();
80 if ( pTabPage )
81 VCLXWindow::setProperty( PropertyName, Value );
84 ::sal_Int16 SAL_CALL VCLXTabPageContainer::getActiveTabPageID()
86 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
87 return pTabCtrl ? pTabCtrl->GetCurPageId( ) : 0;
90 void SAL_CALL VCLXTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid )
92 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
93 if ( pTabCtrl )
94 pTabCtrl->SelectTabPage(_activetabpageid);
97 ::sal_Int16 SAL_CALL VCLXTabPageContainer::getTabPageCount( )
99 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
100 return pTabCtrl ? pTabCtrl->GetPageCount() : 0;
103 sal_Bool SAL_CALL VCLXTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex )
105 return (getActiveTabPageID() == tabPageIndex);
108 Reference< css::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex )
110 return (tabPageIndex >= 0 && o3tl::make_unsigned(tabPageIndex) < m_aTabPages.size()) ? m_aTabPages[tabPageIndex] : nullptr;
113 Reference< css::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID )
115 SolarMutexGuard aGuard;
116 Reference< css::awt::tab::XTabPage > xTabPage;
117 for(const auto& rTabPage : m_aTabPages)
119 Reference< awt::XControl > xControl(rTabPage,UNO_QUERY );
120 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
121 if ( tabPageID == xP->getTabPageID() )
123 xTabPage = rTabPage;
124 break;
127 return xTabPage;
130 void SAL_CALL VCLXTabPageContainer::addTabPageContainerListener( const Reference< css::awt::tab::XTabPageContainerListener >& listener )
132 m_aTabPageListeners.addInterface( listener );
135 void SAL_CALL VCLXTabPageContainer::removeTabPageContainerListener( const Reference< css::awt::tab::XTabPageContainerListener >& listener )
137 m_aTabPageListeners.removeInterface( listener );
140 void VCLXTabPageContainer::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
142 SolarMutexClearableGuard aGuard;
143 VclPtr<TabControl> pTabControl = GetAs<TabControl>();
144 if ( !pTabControl )
145 return;
147 switch ( _rVclWindowEvent.GetId() )
149 case VclEventId::TabpageActivate:
151 sal_uLong page = reinterpret_cast<sal_uLong>(_rVclWindowEvent.GetData());
152 awt::tab::TabPageActivatedEvent aEvent(nullptr,page);
153 m_aTabPageListeners.tabPageActivated(aEvent);
154 break;
156 default:
157 aGuard.clear();
158 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
159 break;
162 void SAL_CALL VCLXTabPageContainer::disposing( const css::lang::EventObject& /*Source*/ )
165 void SAL_CALL VCLXTabPageContainer::elementInserted( const css::container::ContainerEvent& Event )
167 SolarMutexGuard aGuard;
168 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
169 Reference< css::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY);
170 if ( !pTabCtrl || !xTabPage.is() )
171 return;
173 Reference< awt::XControl > xControl(xTabPage,UNO_QUERY );
174 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
175 sal_Int16 nPageID = xP->getTabPageID();
177 if (!xControl->getPeer().is())
178 throw RuntimeException("No peer for tabpage container!");
179 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xControl->getPeer());
180 TabPage* pPage = static_cast<TabPage*>(pWindow.get());
181 pTabCtrl->InsertPage(nPageID,pPage->GetText());
183 pPage->Hide();
184 pTabCtrl->SetTabPage(nPageID,pPage);
185 pTabCtrl->SetHelpText(nPageID,xP->getToolTip());
186 pTabCtrl->SetPageImage(nPageID,TkResMgr::getImageFromURL(xP->getImageURL()));
187 pTabCtrl->SelectTabPage(nPageID);
188 pTabCtrl->SetPageEnabled(nPageID,xP->getEnabled());
189 m_aTabPages.push_back(xTabPage);
192 void SAL_CALL VCLXTabPageContainer::elementRemoved( const css::container::ContainerEvent& Event )
194 SolarMutexGuard aGuard;
195 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
196 Reference< css::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY);
197 if ( pTabCtrl && xTabPage.is() )
199 Reference< awt::XControl > xControl(xTabPage,UNO_QUERY );
200 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
201 pTabCtrl->RemovePage(xP->getTabPageID());
202 m_aTabPages.erase(::std::remove(m_aTabPages.begin(),m_aTabPages.end(),xTabPage));
205 void SAL_CALL VCLXTabPageContainer::elementReplaced( const css::container::ContainerEvent& /*Event*/ )
209 void VCLXTabPageContainer::propertiesChange(const::css::uno::Sequence<PropertyChangeEvent>& rEvents)
211 SolarMutexGuard aGuard;
212 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
213 if (!pTabCtrl)
214 return;
216 for (const beans::PropertyChangeEvent& rEvent : rEvents) {
217 // handle property changes for tab pages
218 Reference< css::awt::tab::XTabPageModel > xTabPageModel(rEvent.Source, uno::UNO_QUERY);
219 if (!xTabPageModel.is())
220 continue;
222 const sal_Int16 nId = xTabPageModel->getTabPageID();
223 if (rEvent.PropertyName == GetPropertyName(BASEPROPERTY_ENABLED)) {
224 pTabCtrl->SetPageEnabled(nId, xTabPageModel->getEnabled());
225 } else if (rEvent.PropertyName == GetPropertyName(BASEPROPERTY_TITLE)) {
226 pTabCtrl->SetPageText(nId, xTabPageModel->getTitle());
227 } else if (rEvent.PropertyName == GetPropertyName(BASEPROPERTY_IMAGEURL)) {
228 pTabCtrl->SetPageImage(nId, TkResMgr::getImageFromURL(xTabPageModel->getImageURL()));
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */