bump product version to 4.1.6.2
[LibreOffice.git] / toolkit / source / awt / vclxtabpagecontainer.cxx
blob928b4bd3d63d72a2df5ea56bfb38e12b643f0ea1
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 <toolkit/awt/vclxtabpagecontainer.hxx>
21 #include <com/sun/star/awt/tab/XTabPageModel.hpp>
22 #include <com/sun/star/awt/XControl.hpp>
23 #include <vcl/tabpage.hxx>
24 #include <vcl/tabctrl.hxx>
25 #include <vcl/svapp.hxx>
26 #include <toolkit/helper/property.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <toolkit/helper/tkresmgr.hxx>
29 #include <cppuhelper/typeprovider.hxx>
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::container;
36 using namespace ::com::sun::star::view;
37 // ----------------------------------------------------
38 // class VCLXTabPageContainer
39 // ----------------------------------------------------
40 void VCLXTabPageContainer::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
42 VCLXWindow::ImplGetPropertyIds( rIds );
45 VCLXTabPageContainer::VCLXTabPageContainer() :
46 m_aTabPageListeners( *this )
50 VCLXTabPageContainer::~VCLXTabPageContainer()
52 #ifndef __SUNPRO_CC
53 OSL_TRACE ("%s", __FUNCTION__);
54 #endif
57 void SAL_CALL VCLXTabPageContainer::draw( sal_Int32 nX, sal_Int32 nY ) throw(RuntimeException)
59 SolarMutexGuard aGuard;
60 TabControl* pTabControl = (TabControl*)GetWindow();
61 if ( pTabControl )
63 TabPage *pTabPage = pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( pTabControl->GetCurPageId( ) ) );
64 if ( pTabPage )
66 ::Point aPos( nX, nY );
67 ::Size aSize = pTabPage->GetSizePixel();
69 OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() );
70 aPos = pDev->PixelToLogic( aPos );
71 aSize = pDev->PixelToLogic( aSize );
73 pTabPage->Draw( pDev, aPos, aSize, 0 );
77 VCLXWindow::draw( nX, nY );
80 ::com::sun::star::awt::DeviceInfo VCLXTabPageContainer::getInfo() throw(RuntimeException)
82 ::com::sun::star::awt::DeviceInfo aInfo = VCLXDevice::getInfo();
83 return aInfo;
86 void SAL_CALL VCLXTabPageContainer::setProperty(const OUString& PropertyName, const Any& Value ) throw(RuntimeException)
88 SolarMutexGuard aGuard;
90 TabControl* pTabPage = (TabControl*)GetWindow();
91 if ( pTabPage )
93 VCLXWindow::setProperty( PropertyName, Value );
96 ::sal_Int16 SAL_CALL VCLXTabPageContainer::getActiveTabPageID() throw (RuntimeException)
98 TabControl* pTabCtrl = (TabControl*)GetWindow();
99 return pTabCtrl != NULL ? pTabCtrl->GetCurPageId( ) : 0;
101 void SAL_CALL VCLXTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid ) throw (RuntimeException)
103 TabControl* pTabCtrl = (TabControl*)GetWindow();
104 if ( pTabCtrl )
105 pTabCtrl->SelectTabPage(_activetabpageid);
107 ::sal_Int16 SAL_CALL VCLXTabPageContainer::getTabPageCount( ) throw (RuntimeException)
109 TabControl* pTabCtrl = (TabControl*)GetWindow();
110 return pTabCtrl != NULL ? pTabCtrl->GetPageCount() : 0;
112 ::sal_Bool SAL_CALL VCLXTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
114 return (getActiveTabPageID() == tabPageIndex);
116 Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
118 return (tabPageIndex >= 0 && tabPageIndex < static_cast<sal_Int16>(m_aTabPages.size())) ? m_aTabPages[tabPageIndex] : NULL;
120 Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID ) throw (RuntimeException)
122 SolarMutexGuard aGuard;
123 Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage;
124 ::std::vector< Reference< ::com::sun::star::awt::tab::XTabPage > >::iterator aIter = m_aTabPages.begin();
125 ::std::vector< Reference< ::com::sun::star::awt::tab::XTabPage > >::iterator aEnd = m_aTabPages.end();
126 for(;aIter != aEnd;++aIter)
128 Reference< awt::XControl > xControl(*aIter,UNO_QUERY );
129 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
130 if ( tabPageID == xP->getTabPageID() )
132 xTabPage = *aIter;
133 break;
136 return xTabPage;
138 void SAL_CALL VCLXTabPageContainer::addTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
140 m_aTabPageListeners.addInterface( listener );
142 void SAL_CALL VCLXTabPageContainer::removeTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
144 m_aTabPageListeners.removeInterface( listener );
147 void VCLXTabPageContainer::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
149 SolarMutexClearableGuard aGuard;
150 TabControl* pTabControl = static_cast< TabControl* >( GetWindow() );
151 if ( pTabControl )
153 switch ( _rVclWindowEvent.GetId() )
155 case VCLEVENT_TABPAGE_ACTIVATE:
157 sal_uLong page = (sal_uLong)_rVclWindowEvent.GetData();
158 awt::tab::TabPageActivatedEvent aEvent(NULL,page);
159 m_aTabPageListeners.tabPageActivated(aEvent);
160 break;
162 default:
163 aGuard.clear();
164 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
165 break;
169 void SAL_CALL VCLXTabPageContainer::disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw (::com::sun::star::uno::RuntimeException)
172 void SAL_CALL VCLXTabPageContainer::elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
174 SolarMutexGuard aGuard;
175 TabControl* pTabCtrl = (TabControl*)GetWindow();
176 Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY);
177 if ( pTabCtrl && xTabPage.is() )
179 Reference< awt::XControl > xControl(xTabPage,UNO_QUERY );
180 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
181 sal_Int16 nPageID = xP->getTabPageID();
183 Window* pWindow = VCLUnoHelper::GetWindow(xControl->getPeer());
184 TabPage* pPage = (TabPage*)pWindow;
185 pTabCtrl->InsertPage(nPageID,pPage->GetText());
187 pPage->Hide();
188 pTabCtrl->SetTabPage(nPageID,pPage);
189 pTabCtrl->SetHelpText(nPageID,xP->getToolTip());
190 pTabCtrl->SetPageImage(nPageID,TkResMgr::getImageFromURL(xP->getImageURL()));
191 pTabCtrl->SelectTabPage(nPageID);
192 m_aTabPages.push_back(xTabPage);
195 void SAL_CALL VCLXTabPageContainer::elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
197 SolarMutexGuard aGuard;
198 TabControl* pTabCtrl = (TabControl*)GetWindow();
199 Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY);
200 if ( pTabCtrl && xTabPage.is() )
202 Reference< awt::XControl > xControl(xTabPage,UNO_QUERY );
203 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
204 pTabCtrl->RemovePage(xP->getTabPageID());
205 m_aTabPages.erase(::std::remove(m_aTabPages.begin(),m_aTabPages.end(),xTabPage));
208 void SAL_CALL VCLXTabPageContainer::elementReplaced( const ::com::sun::star::container::ContainerEvent& /*Event*/ ) throw (::com::sun::star::uno::RuntimeException)
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */