Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / toolkit / source / awt / vclxtabpagecontainer.cxx
blob91c8708c82a691b8b890850f4b8b4bc133192940
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 ::rtl::OUString;
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::lang;
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::container;
37 using namespace ::com::sun::star::view;
38 // ----------------------------------------------------
39 // class VCLXTabPageContainer
40 // ----------------------------------------------------
41 void VCLXTabPageContainer::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
43 VCLXWindow::ImplGetPropertyIds( rIds );
46 VCLXTabPageContainer::VCLXTabPageContainer() :
47 m_aTabPageListeners( *this )
51 VCLXTabPageContainer::~VCLXTabPageContainer()
53 #ifndef __SUNPRO_CC
54 OSL_TRACE ("%s", __FUNCTION__);
55 #endif
58 void SAL_CALL VCLXTabPageContainer::draw( sal_Int32 nX, sal_Int32 nY ) throw(RuntimeException)
60 SolarMutexGuard aGuard;
61 TabControl* pTabControl = (TabControl*)GetWindow();
62 if ( pTabControl )
64 TabPage *pTabPage = pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( pTabControl->GetCurPageId( ) ) );
65 if ( pTabPage )
67 ::Point aPos( nX, nY );
68 ::Size aSize = pTabPage->GetSizePixel();
70 OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() );
71 aPos = pDev->PixelToLogic( aPos );
72 aSize = pDev->PixelToLogic( aSize );
74 pTabPage->Draw( pDev, aPos, aSize, 0 );
78 VCLXWindow::draw( nX, nY );
81 ::com::sun::star::awt::DeviceInfo VCLXTabPageContainer::getInfo() throw(RuntimeException)
83 ::com::sun::star::awt::DeviceInfo aInfo = VCLXDevice::getInfo();
84 return aInfo;
87 void SAL_CALL VCLXTabPageContainer::setProperty(const ::rtl::OUString& PropertyName, const Any& Value ) throw(RuntimeException)
89 SolarMutexGuard aGuard;
91 TabControl* pTabPage = (TabControl*)GetWindow();
92 if ( pTabPage )
94 VCLXWindow::setProperty( PropertyName, Value );
97 ::sal_Int16 SAL_CALL VCLXTabPageContainer::getActiveTabPageID() throw (RuntimeException)
99 TabControl* pTabCtrl = (TabControl*)GetWindow();
100 return pTabCtrl != NULL ? pTabCtrl->GetCurPageId( ) : 0;
102 void SAL_CALL VCLXTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid ) throw (RuntimeException)
104 TabControl* pTabCtrl = (TabControl*)GetWindow();
105 if ( pTabCtrl )
106 pTabCtrl->SelectTabPage(_activetabpageid);
108 ::sal_Int16 SAL_CALL VCLXTabPageContainer::getTabPageCount( ) throw (RuntimeException)
110 TabControl* pTabCtrl = (TabControl*)GetWindow();
111 return pTabCtrl != NULL ? pTabCtrl->GetPageCount() : 0;
113 ::sal_Bool SAL_CALL VCLXTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
115 return (getActiveTabPageID() == tabPageIndex);
117 Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
119 return (tabPageIndex >= 0 && tabPageIndex < static_cast<sal_Int16>(m_aTabPages.size())) ? m_aTabPages[tabPageIndex] : NULL;
121 Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID ) throw (RuntimeException)
123 SolarMutexGuard aGuard;
124 Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage;
125 ::std::vector< Reference< ::com::sun::star::awt::tab::XTabPage > >::iterator aIter = m_aTabPages.begin();
126 ::std::vector< Reference< ::com::sun::star::awt::tab::XTabPage > >::iterator aEnd = m_aTabPages.end();
127 for(;aIter != aEnd;++aIter)
129 Reference< awt::XControl > xControl(*aIter,UNO_QUERY );
130 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
131 if ( tabPageID == xP->getTabPageID() )
133 xTabPage = *aIter;
134 break;
137 return xTabPage;
139 void SAL_CALL VCLXTabPageContainer::addTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
141 m_aTabPageListeners.addInterface( listener );
143 void SAL_CALL VCLXTabPageContainer::removeTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
145 m_aTabPageListeners.removeInterface( listener );
148 void VCLXTabPageContainer::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
150 SolarMutexClearableGuard aGuard;
151 TabControl* pTabControl = static_cast< TabControl* >( GetWindow() );
152 if ( pTabControl )
154 switch ( _rVclWindowEvent.GetId() )
156 case VCLEVENT_TABPAGE_ACTIVATE:
158 sal_uLong page = (sal_uLong)_rVclWindowEvent.GetData();
159 awt::tab::TabPageActivatedEvent aEvent(NULL,page);
160 m_aTabPageListeners.tabPageActivated(aEvent);
161 break;
163 default:
164 aGuard.clear();
165 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
166 break;
170 void SAL_CALL VCLXTabPageContainer::disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw (::com::sun::star::uno::RuntimeException)
173 void SAL_CALL VCLXTabPageContainer::elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
175 SolarMutexGuard aGuard;
176 TabControl* pTabCtrl = (TabControl*)GetWindow();
177 Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY);
178 if ( pTabCtrl && xTabPage.is() )
180 Reference< awt::XControl > xControl(xTabPage,UNO_QUERY );
181 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
182 sal_Int16 nPageID = xP->getTabPageID();
184 Window* pWindow = VCLUnoHelper::GetWindow(xControl->getPeer());
185 TabPage* pPage = (TabPage*)pWindow;
186 pTabCtrl->InsertPage(nPageID,pPage->GetText());
188 pPage->Hide();
189 pTabCtrl->SetTabPage(nPageID,pPage);
190 pTabCtrl->SetHelpText(nPageID,xP->getToolTip());
191 pTabCtrl->SetPageImage(nPageID,TkResMgr::getImageFromURL(xP->getImageURL()));
192 pTabCtrl->SelectTabPage(nPageID);
193 m_aTabPages.push_back(xTabPage);
196 void SAL_CALL VCLXTabPageContainer::elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException)
198 SolarMutexGuard aGuard;
199 TabControl* pTabCtrl = (TabControl*)GetWindow();
200 Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY);
201 if ( pTabCtrl && xTabPage.is() )
203 Reference< awt::XControl > xControl(xTabPage,UNO_QUERY );
204 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
205 pTabCtrl->RemovePage(xP->getTabPageID());
206 m_aTabPages.erase(::std::remove(m_aTabPages.begin(),m_aTabPages.end(),xTabPage));
209 void SAL_CALL VCLXTabPageContainer::elementReplaced( const ::com::sun::star::container::ContainerEvent& /*Event*/ ) throw (::com::sun::star::uno::RuntimeException)
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */