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