1*b0724fc6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b0724fc6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b0724fc6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b0724fc6SAndrew Rist * distributed with this work for additional information 6*b0724fc6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b0724fc6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b0724fc6SAndrew Rist * "License"); you may not use this file except in compliance 9*b0724fc6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b0724fc6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b0724fc6SAndrew Rist * software distributed under the License is distributed on an 15*b0724fc6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b0724fc6SAndrew Rist * KIND, either express or implied. See the License for the 17*b0724fc6SAndrew Rist * specific language governing permissions and limitations 18*b0724fc6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b0724fc6SAndrew Rist *************************************************************/ 21*b0724fc6SAndrew Rist 22*b0724fc6SAndrew Rist 23cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include <toolkit/awt/vclxtabpagecontainer.hxx> 26cdf0e10cSrcweir #include <com/sun/star/awt/tab/XTabPageModel.hpp> 27cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp> 28cdf0e10cSrcweir #include <vcl/tabpage.hxx> 29cdf0e10cSrcweir #include <vcl/tabctrl.hxx> 30cdf0e10cSrcweir #include <toolkit/helper/property.hxx> 31cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 32cdf0e10cSrcweir #include <toolkit/helper/tkresmgr.hxx> 33cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir using ::rtl::OUString; 36cdf0e10cSrcweir using namespace ::com::sun::star; 37cdf0e10cSrcweir using namespace ::com::sun::star::uno; 38cdf0e10cSrcweir using namespace ::com::sun::star::lang; 39cdf0e10cSrcweir using namespace ::com::sun::star::beans; 40cdf0e10cSrcweir using namespace ::com::sun::star::container; 41cdf0e10cSrcweir using namespace ::com::sun::star::view; 42cdf0e10cSrcweir // ---------------------------------------------------- 43cdf0e10cSrcweir // class VCLXTabPageContainer 44cdf0e10cSrcweir // ---------------------------------------------------- 45cdf0e10cSrcweir void VCLXTabPageContainer::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) 46cdf0e10cSrcweir { 47cdf0e10cSrcweir VCLXWindow::ImplGetPropertyIds( rIds ); 48cdf0e10cSrcweir } 49cdf0e10cSrcweir 50cdf0e10cSrcweir VCLXTabPageContainer::VCLXTabPageContainer() : 51cdf0e10cSrcweir m_aTabPageListeners( *this ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir VCLXTabPageContainer::~VCLXTabPageContainer() 56cdf0e10cSrcweir { 57cdf0e10cSrcweir #ifndef __SUNPRO_CC 58cdf0e10cSrcweir OSL_TRACE ("%s", __FUNCTION__); 59cdf0e10cSrcweir #endif 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::draw( sal_Int32 nX, sal_Int32 nY ) throw(RuntimeException) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 65cdf0e10cSrcweir TabControl* pTabControl = (TabControl*)GetWindow(); 66cdf0e10cSrcweir if ( pTabControl ) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir TabPage *pTabPage = pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( pTabControl->GetCurPageId( ) ) ); 69cdf0e10cSrcweir if ( pTabPage ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir ::Point aPos( nX, nY ); 72cdf0e10cSrcweir ::Size aSize = pTabPage->GetSizePixel(); 73cdf0e10cSrcweir 74cdf0e10cSrcweir OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() ); 75cdf0e10cSrcweir aPos = pDev->PixelToLogic( aPos ); 76cdf0e10cSrcweir aSize = pDev->PixelToLogic( aSize ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir pTabPage->Draw( pDev, aPos, aSize, 0 ); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir VCLXWindow::draw( nX, nY ); 83cdf0e10cSrcweir /* 84cdf0e10cSrcweir if ( pWindow ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() ); 87cdf0e10cSrcweir if ( !pDev ) 88cdf0e10cSrcweir pDev = pWindow->GetParent(); 89cdf0e10cSrcweir 90cdf0e10cSrcweir Size aSize = pDev->PixelToLogic( pWindow->GetSizePixel() ); 91cdf0e10cSrcweir Point aPos = pDev->PixelToLogic( Point( nX, nY ) ); 92cdf0e10cSrcweir 93cdf0e10cSrcweir pWindow->Draw( pDev, aPos, aSize, WINDOW_DRAW_NOCONTROLS ); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir ::com::sun::star::awt::DeviceInfo VCLXTabPageContainer::getInfo() throw(RuntimeException) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir ::com::sun::star::awt::DeviceInfo aInfo = VCLXDevice::getInfo(); 101cdf0e10cSrcweir return aInfo; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::setProperty(const ::rtl::OUString& PropertyName, const Any& Value ) throw(RuntimeException) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 107cdf0e10cSrcweir 108cdf0e10cSrcweir TabControl* pTabPage = (TabControl*)GetWindow(); 109cdf0e10cSrcweir if ( pTabPage ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir VCLXWindow::setProperty( PropertyName, Value ); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir } 114cdf0e10cSrcweir ::sal_Int16 SAL_CALL VCLXTabPageContainer::getActiveTabPageID() throw (RuntimeException) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir TabControl* pTabCtrl = (TabControl*)GetWindow(); 117cdf0e10cSrcweir return pTabCtrl != NULL ? pTabCtrl->GetCurPageId( ) : 0; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid ) throw (RuntimeException) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir TabControl* pTabCtrl = (TabControl*)GetWindow(); 122cdf0e10cSrcweir if ( pTabCtrl ) 123cdf0e10cSrcweir pTabCtrl->SelectTabPage(_activetabpageid); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir ::sal_Int16 SAL_CALL VCLXTabPageContainer::getTabPageCount( ) throw (RuntimeException) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir TabControl* pTabCtrl = (TabControl*)GetWindow(); 128cdf0e10cSrcweir return pTabCtrl != NULL ? pTabCtrl->GetPageCount() : 0; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir ::sal_Bool SAL_CALL VCLXTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex ) throw (RuntimeException) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir return (getActiveTabPageID() == tabPageIndex); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex ) throw (RuntimeException) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir return (tabPageIndex >= 0 && tabPageIndex < static_cast<sal_Int16>(m_aTabPages.size())) ? m_aTabPages[tabPageIndex] : NULL; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID ) throw (RuntimeException) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir ::vos::OClearableGuard aGuard( GetMutex() ); 141cdf0e10cSrcweir Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage; 142cdf0e10cSrcweir ::std::vector< Reference< ::com::sun::star::awt::tab::XTabPage > >::iterator aIter = m_aTabPages.begin(); 143cdf0e10cSrcweir ::std::vector< Reference< ::com::sun::star::awt::tab::XTabPage > >::iterator aEnd = m_aTabPages.end(); 144cdf0e10cSrcweir for(;aIter != aEnd;++aIter) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir Reference< awt::XControl > xControl(*aIter,UNO_QUERY ); 147cdf0e10cSrcweir Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY ); 148cdf0e10cSrcweir if ( tabPageID == xP->getTabPageID() ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir xTabPage = *aIter; 151cdf0e10cSrcweir break; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir } 154cdf0e10cSrcweir return xTabPage; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::addTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir m_aTabPageListeners.addInterface( listener ); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::removeTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir m_aTabPageListeners.removeInterface( listener ); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir void VCLXTabPageContainer::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir ::vos::OClearableGuard aGuard( GetMutex() ); 168cdf0e10cSrcweir TabControl* pTabControl = static_cast< TabControl* >( GetWindow() ); 169cdf0e10cSrcweir if ( pTabControl ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir switch ( _rVclWindowEvent.GetId() ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir case VCLEVENT_TABPAGE_ACTIVATE: 174cdf0e10cSrcweir { 175cdf0e10cSrcweir // allocateArea( maAllocation ); 176cdf0e10cSrcweir sal_uLong page = (sal_uLong)_rVclWindowEvent.GetData(); 177cdf0e10cSrcweir awt::tab::TabPageActivatedEvent aEvent(NULL,page); 178cdf0e10cSrcweir m_aTabPageListeners.tabPageActivated(aEvent); 179cdf0e10cSrcweir break; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir default: 182cdf0e10cSrcweir aGuard.clear(); 183cdf0e10cSrcweir VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); 184cdf0e10cSrcweir break; 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir } 188cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw (::com::sun::star::uno::RuntimeException) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir } 191cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 194cdf0e10cSrcweir TabControl* pTabCtrl = (TabControl*)GetWindow(); 195cdf0e10cSrcweir Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY); 196cdf0e10cSrcweir if ( pTabCtrl && xTabPage.is() ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir Reference< awt::XControl > xControl(xTabPage,UNO_QUERY ); 199cdf0e10cSrcweir Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY ); 200cdf0e10cSrcweir sal_Int16 nPageID = xP->getTabPageID(); 201cdf0e10cSrcweir 202cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow(xControl->getPeer()); 203cdf0e10cSrcweir TabPage* pPage = (TabPage*)pWindow; 204cdf0e10cSrcweir pTabCtrl->InsertPage(nPageID,pPage->GetText()); 205cdf0e10cSrcweir 206cdf0e10cSrcweir pPage->Hide(); 207cdf0e10cSrcweir pTabCtrl->SetTabPage(nPageID,pPage); 208cdf0e10cSrcweir pTabCtrl->SetHelpText(nPageID,xP->getToolTip()); 209cdf0e10cSrcweir pTabCtrl->SetPageImage(nPageID,TkResMgr::getImageFromURL(xP->getImageURL())); 210cdf0e10cSrcweir pTabCtrl->SelectTabPage(nPageID); 211cdf0e10cSrcweir m_aTabPages.push_back(xTabPage); 212cdf0e10cSrcweir } 213cdf0e10cSrcweir } 214cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::uno::RuntimeException) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 217cdf0e10cSrcweir TabControl* pTabCtrl = (TabControl*)GetWindow(); 218cdf0e10cSrcweir Reference< ::com::sun::star::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY); 219cdf0e10cSrcweir if ( pTabCtrl && xTabPage.is() ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir Reference< awt::XControl > xControl(xTabPage,UNO_QUERY ); 222cdf0e10cSrcweir Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY ); 223cdf0e10cSrcweir pTabCtrl->RemovePage(xP->getTabPageID()); 224cdf0e10cSrcweir m_aTabPages.erase(::std::remove(m_aTabPages.begin(),m_aTabPages.end(),xTabPage)); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir } 227cdf0e10cSrcweir void SAL_CALL VCLXTabPageContainer::elementReplaced( const ::com::sun::star::container::ContainerEvent& /*Event*/ ) throw (::com::sun::star::uno::RuntimeException) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir } 230