1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir #include <toolkit/awt/vclxtabpagecontainer.hxx> 30*cdf0e10cSrcweir #include <com/sun/star/awt/tab/XTabPageModel.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp> 32*cdf0e10cSrcweir #include <vcl/tabpage.hxx> 33*cdf0e10cSrcweir #include <vcl/tabctrl.hxx> 34*cdf0e10cSrcweir #include <toolkit/helper/property.hxx> 35*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 36*cdf0e10cSrcweir #include <toolkit/helper/tkresmgr.hxx> 37*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using ::rtl::OUString; 40*cdf0e10cSrcweir using namespace ::com::sun::star; 41*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 42*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 43*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 44*cdf0e10cSrcweir using namespace ::com::sun::star::container; 45*cdf0e10cSrcweir using namespace ::com::sun::star::view; 46*cdf0e10cSrcweir // ---------------------------------------------------- 47*cdf0e10cSrcweir // class VCLXTabPageContainer 48*cdf0e10cSrcweir // ---------------------------------------------------- 49*cdf0e10cSrcweir void VCLXTabPageContainer::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir VCLXWindow::ImplGetPropertyIds( rIds ); 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir VCLXTabPageContainer::VCLXTabPageContainer() : 55*cdf0e10cSrcweir m_aTabPageListeners( *this ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir VCLXTabPageContainer::~VCLXTabPageContainer() 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir #ifndef __SUNPRO_CC 62*cdf0e10cSrcweir OSL_TRACE ("%s", __FUNCTION__); 63*cdf0e10cSrcweir #endif 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::draw( sal_Int32 nX, sal_Int32 nY ) throw(RuntimeException) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 69*cdf0e10cSrcweir TabControl* pTabControl = (TabControl*)GetWindow(); 70*cdf0e10cSrcweir if ( pTabControl ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir TabPage *pTabPage = pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( pTabControl->GetCurPageId( ) ) ); 73*cdf0e10cSrcweir if ( pTabPage ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir ::Point aPos( nX, nY ); 76*cdf0e10cSrcweir ::Size aSize = pTabPage->GetSizePixel(); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() ); 79*cdf0e10cSrcweir aPos = pDev->PixelToLogic( aPos ); 80*cdf0e10cSrcweir aSize = pDev->PixelToLogic( aSize ); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir pTabPage->Draw( pDev, aPos, aSize, 0 ); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir VCLXWindow::draw( nX, nY ); 87*cdf0e10cSrcweir /* 88*cdf0e10cSrcweir if ( pWindow ) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() ); 91*cdf0e10cSrcweir if ( !pDev ) 92*cdf0e10cSrcweir pDev = pWindow->GetParent(); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir Size aSize = pDev->PixelToLogic( pWindow->GetSizePixel() ); 95*cdf0e10cSrcweir Point aPos = pDev->PixelToLogic( Point( nX, nY ) ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir pWindow->Draw( pDev, aPos, aSize, WINDOW_DRAW_NOCONTROLS ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir */ 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir ::com::sun::star::awt::DeviceInfo VCLXTabPageContainer::getInfo() throw(RuntimeException) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir ::com::sun::star::awt::DeviceInfo aInfo = VCLXDevice::getInfo(); 105*cdf0e10cSrcweir return aInfo; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::setProperty(const ::rtl::OUString& PropertyName, const Any& Value ) throw(RuntimeException) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir TabControl* pTabPage = (TabControl*)GetWindow(); 113*cdf0e10cSrcweir if ( pTabPage ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir VCLXWindow::setProperty( PropertyName, Value ); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir ::sal_Int16 SAL_CALL VCLXTabPageContainer::getActiveTabPageID() throw (RuntimeException) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir TabControl* pTabCtrl = (TabControl*)GetWindow(); 121*cdf0e10cSrcweir return pTabCtrl != NULL ? pTabCtrl->GetCurPageId( ) : 0; 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid ) throw (RuntimeException) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir TabControl* pTabCtrl = (TabControl*)GetWindow(); 126*cdf0e10cSrcweir if ( pTabCtrl ) 127*cdf0e10cSrcweir pTabCtrl->SelectTabPage(_activetabpageid); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir ::sal_Int16 SAL_CALL VCLXTabPageContainer::getTabPageCount( ) throw (RuntimeException) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir TabControl* pTabCtrl = (TabControl*)GetWindow(); 132*cdf0e10cSrcweir return pTabCtrl != NULL ? pTabCtrl->GetPageCount() : 0; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir ::sal_Bool SAL_CALL VCLXTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex ) throw (RuntimeException) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir return (getActiveTabPageID() == tabPageIndex); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex ) throw (RuntimeException) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir return (tabPageIndex >= 0 && tabPageIndex < static_cast<sal_Int16>(m_aTabPages.size())) ? m_aTabPages[tabPageIndex] : NULL; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID ) throw (RuntimeException) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir ::vos::OClearableGuard aGuard( GetMutex() ); 145*cdf0e10cSrcweir Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage; 146*cdf0e10cSrcweir ::std::vector< Reference< ::com::sun::star::awt::tab::XTabPage > >::iterator aIter = m_aTabPages.begin(); 147*cdf0e10cSrcweir ::std::vector< Reference< ::com::sun::star::awt::tab::XTabPage > >::iterator aEnd = m_aTabPages.end(); 148*cdf0e10cSrcweir for(;aIter != aEnd;++aIter) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir Reference< awt::XControl > xControl(*aIter,UNO_QUERY ); 151*cdf0e10cSrcweir Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY ); 152*cdf0e10cSrcweir if ( tabPageID == xP->getTabPageID() ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir xTabPage = *aIter; 155*cdf0e10cSrcweir break; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir return xTabPage; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::addTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir m_aTabPageListeners.addInterface( listener ); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::removeTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir m_aTabPageListeners.removeInterface( listener ); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir void VCLXTabPageContainer::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir ::vos::OClearableGuard aGuard( GetMutex() ); 172*cdf0e10cSrcweir TabControl* pTabControl = static_cast< TabControl* >( GetWindow() ); 173*cdf0e10cSrcweir if ( pTabControl ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir switch ( _rVclWindowEvent.GetId() ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir case VCLEVENT_TABPAGE_ACTIVATE: 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir // allocateArea( maAllocation ); 180*cdf0e10cSrcweir sal_uLong page = (sal_uLong)_rVclWindowEvent.GetData(); 181*cdf0e10cSrcweir awt::tab::TabPageActivatedEvent aEvent(NULL,page); 182*cdf0e10cSrcweir m_aTabPageListeners.tabPageActivated(aEvent); 183*cdf0e10cSrcweir break; 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir default: 186*cdf0e10cSrcweir aGuard.clear(); 187*cdf0e10cSrcweir VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); 188*cdf0e10cSrcweir break; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw (::com::sun::star::uno::RuntimeException) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 198*cdf0e10cSrcweir TabControl* pTabCtrl = (TabControl*)GetWindow(); 199*cdf0e10cSrcweir Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY); 200*cdf0e10cSrcweir if ( pTabCtrl && xTabPage.is() ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir Reference< awt::XControl > xControl(xTabPage,UNO_QUERY ); 203*cdf0e10cSrcweir Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY ); 204*cdf0e10cSrcweir sal_Int16 nPageID = xP->getTabPageID(); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow(xControl->getPeer()); 207*cdf0e10cSrcweir TabPage* pPage = (TabPage*)pWindow; 208*cdf0e10cSrcweir pTabCtrl->InsertPage(nPageID,pPage->GetText()); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir pPage->Hide(); 211*cdf0e10cSrcweir pTabCtrl->SetTabPage(nPageID,pPage); 212*cdf0e10cSrcweir pTabCtrl->SetHelpText(nPageID,xP->getToolTip()); 213*cdf0e10cSrcweir pTabCtrl->SetPageImage(nPageID,TkResMgr::getImageFromURL(xP->getImageURL())); 214*cdf0e10cSrcweir pTabCtrl->SelectTabPage(nPageID); 215*cdf0e10cSrcweir m_aTabPages.push_back(xTabPage); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 221*cdf0e10cSrcweir TabControl* pTabCtrl = (TabControl*)GetWindow(); 222*cdf0e10cSrcweir Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY); 223*cdf0e10cSrcweir if ( pTabCtrl && xTabPage.is() ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir Reference< awt::XControl > xControl(xTabPage,UNO_QUERY ); 226*cdf0e10cSrcweir Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY ); 227*cdf0e10cSrcweir pTabCtrl->RemovePage(xP->getTabPageID()); 228*cdf0e10cSrcweir m_aTabPages.erase(::std::remove(m_aTabPages.begin(),m_aTabPages.end(),xTabPage)); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::elementReplaced( const ::com::sun::star::container::ContainerEvent& /*Event*/ ) throw (::com::sun::star::uno::RuntimeException) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir } 234