1f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5f6e50924SAndrew Rist * distributed with this work for additional information 6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10f6e50924SAndrew Rist * 11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12f6e50924SAndrew Rist * 13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14f6e50924SAndrew Rist * software distributed under the License is distributed on an 15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17f6e50924SAndrew Rist * specific language governing permissions and limitations 18f6e50924SAndrew Rist * under the License. 19f6e50924SAndrew Rist * 20f6e50924SAndrew Rist *************************************************************/ 21f6e50924SAndrew Rist 22f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/table/XMergeableCell.hpp> 28cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp> 29cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <comphelper/accessiblewrapper.hxx> 32cdf0e10cSrcweir #include <vos/mutex.hxx> 33cdf0e10cSrcweir #include <tools/debug.hxx> 34cdf0e10cSrcweir #include <vcl/svapp.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <svx/AccessibleTableShape.hxx> 37*766ce4d0SZheng Fan #include <svx/sdr/table/tablecontroller.hxx> 38cdf0e10cSrcweir #include "accessiblecell.hxx" 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <algorithm> 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir using ::rtl::OUString; 45cdf0e10cSrcweir 46cdf0e10cSrcweir using namespace ::accessibility; 47cdf0e10cSrcweir using namespace ::sdr::table; 48cdf0e10cSrcweir using namespace ::com::sun::star::accessibility; 49cdf0e10cSrcweir using namespace ::com::sun::star::uno; 50cdf0e10cSrcweir using namespace ::com::sun::star::beans; 51cdf0e10cSrcweir using namespace ::com::sun::star::util; 52cdf0e10cSrcweir using namespace ::com::sun::star::lang; 53cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 54cdf0e10cSrcweir using namespace ::com::sun::star::table; 55cdf0e10cSrcweir using namespace ::com::sun::star::container; 56cdf0e10cSrcweir 57cdf0e10cSrcweir #define C2U(x) OUString(RTL_CONSTASCII_USTRINGPARAM(x)) 58cdf0e10cSrcweir 59cdf0e10cSrcweir namespace accessibility 60cdf0e10cSrcweir { 61cdf0e10cSrcweir 62cdf0e10cSrcweir struct hash 63cdf0e10cSrcweir { 64cdf0e10cSrcweir std::size_t operator()( const Reference< XCell >& xCell ) const 65cdf0e10cSrcweir { 66cdf0e10cSrcweir return std::size_t( xCell.get() ); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir }; 69cdf0e10cSrcweir 70cdf0e10cSrcweir typedef std::hash_map< Reference< XCell >, rtl::Reference< AccessibleCell >, hash > AccessibleCellMap; 71cdf0e10cSrcweir 72cdf0e10cSrcweir //----------------------------------------------------------------------------- 73cdf0e10cSrcweir // AccessibleTableShapeImpl 74cdf0e10cSrcweir //----------------------------------------------------------------------------- 75cdf0e10cSrcweir 76cdf0e10cSrcweir class AccessibleTableShapeImpl : public cppu::WeakImplHelper1< XModifyListener > 77cdf0e10cSrcweir { 78cdf0e10cSrcweir public: 79cdf0e10cSrcweir AccessibleTableShapeImpl( AccessibleShapeTreeInfo& rShapeTreeInfo ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir void init( const Reference< XAccessible>& xAccessible, const Reference< XTable >& xTable ); 82cdf0e10cSrcweir void dispose(); 83cdf0e10cSrcweir 84cdf0e10cSrcweir Reference< XAccessible > getAccessibleChild( sal_Int32 i ) throw(IndexOutOfBoundsException); 85cdf0e10cSrcweir void getColumnAndRow( sal_Int32 nChildIndex, sal_Int32& rnColumn, sal_Int32& rnRow ) throw (IndexOutOfBoundsException ); 86cdf0e10cSrcweir 87cdf0e10cSrcweir // XModifyListener 88cdf0e10cSrcweir virtual void SAL_CALL modified( const EventObject& aEvent ) throw (RuntimeException); 89cdf0e10cSrcweir 90cdf0e10cSrcweir // XEventListener 91cdf0e10cSrcweir virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException); 92cdf0e10cSrcweir 93cdf0e10cSrcweir AccessibleShapeTreeInfo& mrShapeTreeInfo; 94cdf0e10cSrcweir Reference< XTable > mxTable; 95cdf0e10cSrcweir AccessibleCellMap maChildMap; 96cdf0e10cSrcweir Reference< XAccessible> mxAccessible; 97cdf0e10cSrcweir }; 98cdf0e10cSrcweir 99cdf0e10cSrcweir //----------------------------------------------------------------------------- 100cdf0e10cSrcweir 101cdf0e10cSrcweir AccessibleTableShapeImpl::AccessibleTableShapeImpl( AccessibleShapeTreeInfo& rShapeTreeInfo ) 102cdf0e10cSrcweir : mrShapeTreeInfo( rShapeTreeInfo ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir //----------------------------------------------------------------------------- 107cdf0e10cSrcweir 108cdf0e10cSrcweir void AccessibleTableShapeImpl::init( const Reference< XAccessible>& xAccessible, const Reference< XTable >& xTable ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir mxAccessible = xAccessible; 111cdf0e10cSrcweir mxTable = xTable; 112cdf0e10cSrcweir 113cdf0e10cSrcweir if( mxTable.is() ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir Reference< XModifyListener > xListener( this ); 116cdf0e10cSrcweir mxTable->addModifyListener( xListener ); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir //----------------------------------------------------------------------------- 121cdf0e10cSrcweir 122cdf0e10cSrcweir void AccessibleTableShapeImpl::dispose() 123cdf0e10cSrcweir { 124cdf0e10cSrcweir if( mxTable.is() ) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir Reference< XModifyListener > xListener( this ); 127cdf0e10cSrcweir mxTable->removeModifyListener( xListener ); 128cdf0e10cSrcweir mxTable.clear(); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir mxAccessible.clear(); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir //----------------------------------------------------------------------------- 134cdf0e10cSrcweir 135cdf0e10cSrcweir Reference< XAccessible > AccessibleTableShapeImpl::getAccessibleChild( sal_Int32 nChildIndex ) throw(IndexOutOfBoundsException) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir sal_Int32 nColumn = 0, nRow = 0; 138cdf0e10cSrcweir getColumnAndRow( nChildIndex, nColumn, nRow ); 139cdf0e10cSrcweir 140cdf0e10cSrcweir Reference< XCell > xCell( mxTable->getCellByPosition( nColumn, nRow ) ); 141cdf0e10cSrcweir AccessibleCellMap::iterator iter( maChildMap.find( xCell ) ); 142cdf0e10cSrcweir 143cdf0e10cSrcweir if( iter != maChildMap.end() ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir Reference< XAccessible > xChild( (*iter).second.get() ); 146cdf0e10cSrcweir return xChild; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir else 149cdf0e10cSrcweir { 150cdf0e10cSrcweir CellRef xCellRef( dynamic_cast< Cell* >( xCell.get() ) ); 151cdf0e10cSrcweir 152cdf0e10cSrcweir rtl::Reference< AccessibleCell > xAccessibleCell( new AccessibleCell( mxAccessible, xCellRef, nChildIndex, mrShapeTreeInfo ) ); 153cdf0e10cSrcweir 154cdf0e10cSrcweir maChildMap[xCell] = xAccessibleCell; 155cdf0e10cSrcweir 156cdf0e10cSrcweir xAccessibleCell->Init(); 157cdf0e10cSrcweir 158cdf0e10cSrcweir Reference< XAccessible > xChild( xAccessibleCell.get() ); 159cdf0e10cSrcweir return xChild; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir //----------------------------------------------------------------------------- 164cdf0e10cSrcweir 165cdf0e10cSrcweir void AccessibleTableShapeImpl::getColumnAndRow( sal_Int32 nChildIndex, sal_Int32& rnColumn, sal_Int32& rnRow ) throw (IndexOutOfBoundsException ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir rnRow = 0; 168cdf0e10cSrcweir rnColumn = nChildIndex; 169cdf0e10cSrcweir 170cdf0e10cSrcweir if( mxTable.is() ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir const sal_Int32 nColumnCount = mxTable->getColumnCount(); 173cdf0e10cSrcweir while( rnColumn >= nColumnCount ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir rnRow++; 176cdf0e10cSrcweir rnColumn -= nColumnCount; 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir if( rnRow < mxTable->getRowCount() ) 180cdf0e10cSrcweir return; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir throw IndexOutOfBoundsException(); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir // XModifyListener 187cdf0e10cSrcweir void SAL_CALL AccessibleTableShapeImpl::modified( const EventObject& /*aEvent*/ ) throw (RuntimeException) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir if( mxTable.is() ) try 190cdf0e10cSrcweir { 191cdf0e10cSrcweir // structural changes may have happened to the table, validate all accessible cell instances 192cdf0e10cSrcweir AccessibleCellMap aTempChildMap; 193cdf0e10cSrcweir aTempChildMap.swap( maChildMap ); 194cdf0e10cSrcweir 195cdf0e10cSrcweir // first move all still existing cells to maChildMap again and update their index 196cdf0e10cSrcweir 197cdf0e10cSrcweir const sal_Int32 nRowCount = mxTable->getRowCount(); 198cdf0e10cSrcweir const sal_Int32 nColCount = mxTable->getColumnCount(); 199cdf0e10cSrcweir 200cdf0e10cSrcweir sal_Int32 nChildIndex = 0; 201cdf0e10cSrcweir 202cdf0e10cSrcweir for( sal_Int32 nRow = 0; nRow < nRowCount; ++nRow ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir for( sal_Int32 nCol = 0; nCol < nColCount; ++nCol ) 205cdf0e10cSrcweir { 206cdf0e10cSrcweir Reference< XCell > xCell( mxTable->getCellByPosition( nCol, nRow ) ); 207cdf0e10cSrcweir AccessibleCellMap::iterator iter( aTempChildMap.find( xCell ) ); 208cdf0e10cSrcweir 209cdf0e10cSrcweir if( iter != aTempChildMap.end() ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir rtl::Reference< AccessibleCell > xAccessibleCell( (*iter).second ); 212cdf0e10cSrcweir xAccessibleCell->setIndexInParent( nChildIndex ); 213cdf0e10cSrcweir xAccessibleCell->CommitChange(AccessibleEventId::VISIBLE_DATA_CHANGED, Any(), Any()); 214cdf0e10cSrcweir 215cdf0e10cSrcweir // move still existing cell from temporary child map to our child map 216cdf0e10cSrcweir maChildMap[xCell] = xAccessibleCell; 217cdf0e10cSrcweir aTempChildMap.erase( iter ); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir ++nChildIndex; 221cdf0e10cSrcweir } 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir // all accessible cell instances still left in aTempChildMap must be disposed 225cdf0e10cSrcweir // as they are no longer part of the table 226cdf0e10cSrcweir 227cdf0e10cSrcweir for( AccessibleCellMap::iterator iter( aTempChildMap.begin() ); iter != aTempChildMap.end(); iter++ ) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir (*iter).second->dispose(); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir } 232cdf0e10cSrcweir catch( Exception& ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir DBG_ERROR("svx::AccessibleTableShape::modified(), exception caught!"); 235cdf0e10cSrcweir } 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir // XEventListener 239cdf0e10cSrcweir void SAL_CALL AccessibleTableShapeImpl::disposing( const EventObject& /*Source*/ ) throw (RuntimeException) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir //----------------------------------------------------------------------------- 244cdf0e10cSrcweir // AccessibleTableShape 245cdf0e10cSrcweir //----------------------------------------------------------------------------- 246cdf0e10cSrcweir 247cdf0e10cSrcweir //----------------------------------------------------------------------------- 248cdf0e10cSrcweir 249cdf0e10cSrcweir AccessibleTableShape::AccessibleTableShape( const AccessibleShapeInfo& rShapeInfo, const AccessibleShapeTreeInfo& rShapeTreeInfo) 250cdf0e10cSrcweir : AccessibleTableShape_Base(rShapeInfo, rShapeTreeInfo) 251cdf0e10cSrcweir , mxImpl( new AccessibleTableShapeImpl( maShapeTreeInfo ) ) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir //----------------------------------------------------------------------------- 256cdf0e10cSrcweir 257cdf0e10cSrcweir AccessibleTableShape::~AccessibleTableShape (void) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir //----------------------------------------------------------------------------- 262cdf0e10cSrcweir 263cdf0e10cSrcweir void AccessibleTableShape::Init() 264cdf0e10cSrcweir { 265cdf0e10cSrcweir try 266cdf0e10cSrcweir { 267cdf0e10cSrcweir 268cdf0e10cSrcweir Reference< XPropertySet > xSet( mxShape, UNO_QUERY_THROW ); 269cdf0e10cSrcweir Reference< XTable > xTable( xSet->getPropertyValue(C2U("Model")), UNO_QUERY_THROW ); 270cdf0e10cSrcweir 271cdf0e10cSrcweir mxImpl->init( this, xTable ); 272cdf0e10cSrcweir } 273cdf0e10cSrcweir catch( Exception& ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir DBG_ERROR("AccessibleTableShape::init(), exception caught?"); 276cdf0e10cSrcweir } 277cdf0e10cSrcweir 278cdf0e10cSrcweir AccessibleTableShape_Base::Init(); 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir //----------------------------------------------------------------------------- 282cdf0e10cSrcweir 283cdf0e10cSrcweir SvxTableController* AccessibleTableShape::getTableController() 284cdf0e10cSrcweir { 285cdf0e10cSrcweir SdrView* pView = maShapeTreeInfo.GetSdrView (); 286cdf0e10cSrcweir if( pView ) 287cdf0e10cSrcweir return dynamic_cast< SvxTableController* >( pView->getSelectionController().get() ); 288cdf0e10cSrcweir else 289cdf0e10cSrcweir return 0; 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir //----------------------------------------------------------------------------- 293cdf0e10cSrcweir // XInterface 294cdf0e10cSrcweir //----------------------------------------------------------------------------- 295cdf0e10cSrcweir 296cdf0e10cSrcweir Any SAL_CALL AccessibleTableShape::queryInterface( const Type& aType ) throw (RuntimeException) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir return AccessibleTableShape_Base::queryInterface( aType ); 299cdf0e10cSrcweir } 300cdf0e10cSrcweir 301cdf0e10cSrcweir //----------------------------------------------------------------------------- 302cdf0e10cSrcweir 303cdf0e10cSrcweir void SAL_CALL AccessibleTableShape::acquire( ) throw () 304cdf0e10cSrcweir { 305cdf0e10cSrcweir AccessibleTableShape_Base::acquire(); 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir //----------------------------------------------------------------------------- 309cdf0e10cSrcweir 310cdf0e10cSrcweir void SAL_CALL AccessibleTableShape::release( ) throw () 311cdf0e10cSrcweir { 312cdf0e10cSrcweir AccessibleTableShape_Base::release(); 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir //----------------------------------------------------------------------------- 316cdf0e10cSrcweir // XAccessible 317cdf0e10cSrcweir //----------------------------------------------------------------------------- 318cdf0e10cSrcweir 319cdf0e10cSrcweir Reference< XAccessibleContext > SAL_CALL AccessibleTableShape::getAccessibleContext(void) throw (RuntimeException) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir return AccessibleShape::getAccessibleContext (); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir 324cdf0e10cSrcweir //----------------------------------------------------------------------------- 325cdf0e10cSrcweir OUString SAL_CALL AccessibleTableShape::getImplementationName(void) throw (RuntimeException) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.accessibility.AccessibleTableShape" ) ); 328cdf0e10cSrcweir } 329cdf0e10cSrcweir 330cdf0e10cSrcweir //----------------------------------------------------------------------------- 331cdf0e10cSrcweir 332cdf0e10cSrcweir OUString AccessibleTableShape::CreateAccessibleBaseName(void) throw (RuntimeException) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir return OUString (RTL_CONSTASCII_USTRINGPARAM("TableShape"));; 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir //-------------------------------------------------------------------- 338cdf0e10cSrcweir 339cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleChildCount( ) throw(RuntimeException) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir ::vos::OGuard aSolarGuard(::Application::GetSolarMutex()); 342cdf0e10cSrcweir return mxImpl->mxTable.is() ? mxImpl->mxTable->getRowCount() * mxImpl->mxTable->getColumnCount() : 0; 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir //-------------------------------------------------------------------- 346cdf0e10cSrcweir Reference< XAccessible > SAL_CALL AccessibleTableShape::getAccessibleChild( sal_Int32 i ) throw(IndexOutOfBoundsException, RuntimeException) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 349cdf0e10cSrcweir ThrowIfDisposed(); 350cdf0e10cSrcweir 351cdf0e10cSrcweir return mxImpl->getAccessibleChild( i ); 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir //-------------------------------------------------------------------- 355cdf0e10cSrcweir Reference< XAccessibleRelationSet > SAL_CALL AccessibleTableShape::getAccessibleRelationSet( ) throw (RuntimeException) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir return AccessibleShape::getAccessibleRelationSet( ); 358cdf0e10cSrcweir } 359cdf0e10cSrcweir 360cdf0e10cSrcweir //-------------------------------------------------------------------- 361cdf0e10cSrcweir 362cdf0e10cSrcweir sal_Int16 SAL_CALL AccessibleTableShape::getAccessibleRole (void) throw (RuntimeException) 363cdf0e10cSrcweir { 364cdf0e10cSrcweir return AccessibleRole::TABLE; 365cdf0e10cSrcweir } 366cdf0e10cSrcweir 367cdf0e10cSrcweir //-------------------------------------------------------------------- 368cdf0e10cSrcweir 369cdf0e10cSrcweir void SAL_CALL AccessibleTableShape::disposing (void) 370cdf0e10cSrcweir { 371cdf0e10cSrcweir mxImpl->dispose(); 372cdf0e10cSrcweir 373cdf0e10cSrcweir // let the base do it's stuff 374cdf0e10cSrcweir AccessibleShape::disposing(); 375cdf0e10cSrcweir } 376cdf0e10cSrcweir 377cdf0e10cSrcweir //-------------------------------------------------------------------- 378cdf0e10cSrcweir // XAccessibleTable 379cdf0e10cSrcweir //-------------------------------------------------------------------- 380cdf0e10cSrcweir 381cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleRowCount() throw (RuntimeException) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 384cdf0e10cSrcweir return mxImpl->mxTable.is() ? mxImpl->mxTable->getRowCount() : 0; 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir //-------------------------------------------------------------------- 388cdf0e10cSrcweir 389cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleColumnCount( ) throw (RuntimeException) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 392cdf0e10cSrcweir return mxImpl->mxTable.is() ? mxImpl->mxTable->getColumnCount() : 0; 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir //-------------------------------------------------------------------- 396cdf0e10cSrcweir 397cdf0e10cSrcweir OUString SAL_CALL AccessibleTableShape::getAccessibleRowDescription( sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException) 398cdf0e10cSrcweir { 399cdf0e10cSrcweir checkCellPosition( 0, nRow ); 400cdf0e10cSrcweir return OUString(); 401cdf0e10cSrcweir } 402cdf0e10cSrcweir 403cdf0e10cSrcweir //-------------------------------------------------------------------- 404cdf0e10cSrcweir 405cdf0e10cSrcweir OUString SAL_CALL AccessibleTableShape::getAccessibleColumnDescription( sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException) 406cdf0e10cSrcweir { 407cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 408cdf0e10cSrcweir checkCellPosition( nColumn, 0 ); 409cdf0e10cSrcweir return OUString(); 410cdf0e10cSrcweir } 411cdf0e10cSrcweir 412cdf0e10cSrcweir //-------------------------------------------------------------------- 413cdf0e10cSrcweir 414cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleRowExtentAt( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 417cdf0e10cSrcweir checkCellPosition( nColumn, nRow ); 418cdf0e10cSrcweir if( mxImpl->mxTable.is() ) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir Reference< XMergeableCell > xCell( mxImpl->mxTable->getCellByPosition( nColumn, nRow ), UNO_QUERY ); 421cdf0e10cSrcweir if( xCell.is() ) 422cdf0e10cSrcweir return xCell->getRowSpan(); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir return 1; 425cdf0e10cSrcweir } 426cdf0e10cSrcweir 427cdf0e10cSrcweir //-------------------------------------------------------------------- 428cdf0e10cSrcweir 429cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleColumnExtentAt( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException) 430cdf0e10cSrcweir { 431cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 432cdf0e10cSrcweir checkCellPosition( nColumn, nRow ); 433cdf0e10cSrcweir if( mxImpl->mxTable.is() ) 434cdf0e10cSrcweir { 435cdf0e10cSrcweir Reference< XMergeableCell > xCell( mxImpl->mxTable->getCellByPosition( nColumn, nRow ), UNO_QUERY ); 436cdf0e10cSrcweir if( xCell.is() ) 437cdf0e10cSrcweir return xCell->getColumnSpan(); 438cdf0e10cSrcweir } 439cdf0e10cSrcweir return 1; 440cdf0e10cSrcweir } 441cdf0e10cSrcweir 442cdf0e10cSrcweir //-------------------------------------------------------------------- 443cdf0e10cSrcweir 444cdf0e10cSrcweir Reference< XAccessibleTable > SAL_CALL AccessibleTableShape::getAccessibleRowHeaders( ) throw (RuntimeException) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir Reference< XAccessibleTable > xRet( this ); // todo 447cdf0e10cSrcweir return xRet; 448cdf0e10cSrcweir } 449cdf0e10cSrcweir 450cdf0e10cSrcweir //-------------------------------------------------------------------- 451cdf0e10cSrcweir 452cdf0e10cSrcweir Reference< XAccessibleTable > SAL_CALL AccessibleTableShape::getAccessibleColumnHeaders( ) throw (RuntimeException) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir Reference< XAccessibleTable > xRet( this ); // todo 455cdf0e10cSrcweir return xRet; 456cdf0e10cSrcweir } 457cdf0e10cSrcweir 458cdf0e10cSrcweir //-------------------------------------------------------------------- 459cdf0e10cSrcweir 460cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL AccessibleTableShape::getSelectedAccessibleRows( ) throw (RuntimeException) 461cdf0e10cSrcweir { 462cdf0e10cSrcweir Sequence< sal_Int32 > aRet; 463cdf0e10cSrcweir return aRet; 464cdf0e10cSrcweir } 465cdf0e10cSrcweir 466cdf0e10cSrcweir //-------------------------------------------------------------------- 467cdf0e10cSrcweir 468cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL AccessibleTableShape::getSelectedAccessibleColumns( ) throw (RuntimeException) 469cdf0e10cSrcweir { 470cdf0e10cSrcweir Sequence< sal_Int32 > aRet; 471cdf0e10cSrcweir return aRet; 472cdf0e10cSrcweir } 473cdf0e10cSrcweir 474cdf0e10cSrcweir //-------------------------------------------------------------------- 475cdf0e10cSrcweir 476cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleTableShape::isAccessibleRowSelected( sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException) 477cdf0e10cSrcweir { 478cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 479cdf0e10cSrcweir checkCellPosition( 0, nRow ); 480cdf0e10cSrcweir return sal_False; 481cdf0e10cSrcweir } 482cdf0e10cSrcweir 483cdf0e10cSrcweir //-------------------------------------------------------------------- 484cdf0e10cSrcweir 485cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleTableShape::isAccessibleColumnSelected( sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException) 486cdf0e10cSrcweir { 487cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 488cdf0e10cSrcweir checkCellPosition( nColumn, 0 ); 489cdf0e10cSrcweir return sal_False; 490cdf0e10cSrcweir } 491cdf0e10cSrcweir 492cdf0e10cSrcweir //-------------------------------------------------------------------- 493cdf0e10cSrcweir 494cdf0e10cSrcweir Reference< XAccessible > SAL_CALL AccessibleTableShape::getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 497cdf0e10cSrcweir checkCellPosition( nColumn, nRow ); 498cdf0e10cSrcweir 499cdf0e10cSrcweir sal_Int32 nChildIndex = 0; 500cdf0e10cSrcweir if( mxImpl->mxTable.is() ) 501cdf0e10cSrcweir nChildIndex = mxImpl->mxTable->getColumnCount() * nRow + nColumn; 502cdf0e10cSrcweir 503cdf0e10cSrcweir return getAccessibleChild( nChildIndex ); 504cdf0e10cSrcweir } 505cdf0e10cSrcweir 506cdf0e10cSrcweir //-------------------------------------------------------------------- 507cdf0e10cSrcweir 508cdf0e10cSrcweir Reference< XAccessible > SAL_CALL AccessibleTableShape::getAccessibleCaption( ) throw (RuntimeException) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir Reference< XAccessible > xRet; 511cdf0e10cSrcweir return xRet; 512cdf0e10cSrcweir } 513cdf0e10cSrcweir 514cdf0e10cSrcweir //-------------------------------------------------------------------- 515cdf0e10cSrcweir 516cdf0e10cSrcweir Reference< XAccessible > SAL_CALL AccessibleTableShape::getAccessibleSummary( ) throw (RuntimeException) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir Reference< XAccessible > xRet; 519cdf0e10cSrcweir return xRet; 520cdf0e10cSrcweir } 521cdf0e10cSrcweir 522cdf0e10cSrcweir //-------------------------------------------------------------------- 523cdf0e10cSrcweir 524cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleTableShape::isAccessibleSelected( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException) 525cdf0e10cSrcweir { 526cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 527cdf0e10cSrcweir checkCellPosition( nColumn, nRow ); 528cdf0e10cSrcweir 529cdf0e10cSrcweir SvxTableController* pController = getTableController(); 530cdf0e10cSrcweir if( pController && pController->hasSelectedCells() ) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir CellPos aFirstPos, aLastPos; 533cdf0e10cSrcweir pController->getSelectedCells( aFirstPos, aLastPos ); 534cdf0e10cSrcweir if( (aFirstPos.mnRow <= nRow) && (aFirstPos.mnCol <= nColumn) && (nRow <= aLastPos.mnRow) && (nColumn <= aLastPos.mnCol) ) 535cdf0e10cSrcweir return sal_True; 536cdf0e10cSrcweir } 537cdf0e10cSrcweir 538cdf0e10cSrcweir return sal_False; 539cdf0e10cSrcweir } 540cdf0e10cSrcweir 541cdf0e10cSrcweir //-------------------------------------------------------------------- 542cdf0e10cSrcweir 543cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException) 544cdf0e10cSrcweir { 545cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 546cdf0e10cSrcweir checkCellPosition( nColumn, nRow ); 547cdf0e10cSrcweir return mxImpl->mxTable.is() ? (nRow * mxImpl->mxTable->getColumnCount() + nColumn) : 0; 548cdf0e10cSrcweir } 549cdf0e10cSrcweir 550cdf0e10cSrcweir //-------------------------------------------------------------------- 551cdf0e10cSrcweir 552cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleRow( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException) 553cdf0e10cSrcweir { 554cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 555cdf0e10cSrcweir sal_Int32 nColumn = 0, nRow = 0; 556cdf0e10cSrcweir mxImpl->getColumnAndRow( nChildIndex, nColumn, nRow ); 557cdf0e10cSrcweir return nRow; 558cdf0e10cSrcweir } 559cdf0e10cSrcweir 560cdf0e10cSrcweir //-------------------------------------------------------------------- 561cdf0e10cSrcweir 562cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleColumn( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException) 563cdf0e10cSrcweir { 564cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 565cdf0e10cSrcweir sal_Int32 nColumn = 0, nRow = 0; 566cdf0e10cSrcweir mxImpl->getColumnAndRow( nChildIndex, nColumn, nRow ); 567cdf0e10cSrcweir return nChildIndex; 568cdf0e10cSrcweir } 569cdf0e10cSrcweir 570cdf0e10cSrcweir //-------------------------------------------------------------------- 571cdf0e10cSrcweir // XAccessibleSelection 572cdf0e10cSrcweir //-------------------------------------------------------------------- 573cdf0e10cSrcweir 574cdf0e10cSrcweir void SAL_CALL AccessibleTableShape::selectAccessibleChild( sal_Int32 nChildIndex ) throw ( IndexOutOfBoundsException, RuntimeException ) 575cdf0e10cSrcweir { 576cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 577cdf0e10cSrcweir CellPos aPos; 578cdf0e10cSrcweir mxImpl->getColumnAndRow( nChildIndex, aPos.mnCol, aPos.mnRow ); 579cdf0e10cSrcweir 580cdf0e10cSrcweir // todo, select table shape?!? 581cdf0e10cSrcweir SvxTableController* pController = getTableController(); 582cdf0e10cSrcweir if( pController ) 583cdf0e10cSrcweir { 584cdf0e10cSrcweir CellPos aFirstPos( aPos ), aLastPos( aPos ); 585cdf0e10cSrcweir if( pController->hasSelectedCells() ) 586cdf0e10cSrcweir { 587cdf0e10cSrcweir pController->getSelectedCells( aFirstPos, aLastPos ); 588cdf0e10cSrcweir 589cdf0e10cSrcweir aFirstPos.mnRow = std::min( aFirstPos.mnRow, aPos.mnRow ); 590cdf0e10cSrcweir aFirstPos.mnCol = std::min( aFirstPos.mnCol, aPos.mnCol ); 591cdf0e10cSrcweir aLastPos.mnRow = std::max( aLastPos.mnRow, aPos.mnRow ); 592cdf0e10cSrcweir aLastPos.mnCol = std::max( aLastPos.mnCol, aPos.mnCol ); 593cdf0e10cSrcweir } 594cdf0e10cSrcweir pController->setSelectedCells( aFirstPos, aLastPos ); 595cdf0e10cSrcweir } 596cdf0e10cSrcweir } 597cdf0e10cSrcweir 598cdf0e10cSrcweir //-------------------------------------------------------------------- 599cdf0e10cSrcweir 600cdf0e10cSrcweir sal_Bool SAL_CALL AccessibleTableShape::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw ( IndexOutOfBoundsException, RuntimeException ) 601cdf0e10cSrcweir { 602cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 603cdf0e10cSrcweir CellPos aPos; 604cdf0e10cSrcweir mxImpl->getColumnAndRow( nChildIndex, aPos.mnCol, aPos.mnRow ); 605cdf0e10cSrcweir 606cdf0e10cSrcweir return isAccessibleSelected(aPos.mnCol, aPos.mnRow); 607cdf0e10cSrcweir } 608cdf0e10cSrcweir 609cdf0e10cSrcweir //-------------------------------------------------------------------- 610cdf0e10cSrcweir 611cdf0e10cSrcweir void SAL_CALL AccessibleTableShape::clearAccessibleSelection() throw ( RuntimeException ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 614cdf0e10cSrcweir 615cdf0e10cSrcweir SvxTableController* pController = getTableController(); 616cdf0e10cSrcweir if( pController ) 617cdf0e10cSrcweir pController->clearSelection(); 618cdf0e10cSrcweir } 619cdf0e10cSrcweir //-------------------------------------------------------------------- 620cdf0e10cSrcweir 621cdf0e10cSrcweir void SAL_CALL AccessibleTableShape::selectAllAccessibleChildren() throw ( RuntimeException ) 622cdf0e10cSrcweir { 623cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 624cdf0e10cSrcweir 625cdf0e10cSrcweir // todo: force selection of shape? 626cdf0e10cSrcweir SvxTableController* pController = getTableController(); 627cdf0e10cSrcweir if( pController ) 628cdf0e10cSrcweir pController->selectAll(); 629cdf0e10cSrcweir } 630cdf0e10cSrcweir 631cdf0e10cSrcweir //-------------------------------------------------------------------- 632cdf0e10cSrcweir 633cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleTableShape::getSelectedAccessibleChildCount() throw ( RuntimeException ) 634cdf0e10cSrcweir { 635cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 636cdf0e10cSrcweir 637cdf0e10cSrcweir SvxTableController* pController = getTableController(); 638cdf0e10cSrcweir if( pController && pController->hasSelectedCells() ) 639cdf0e10cSrcweir { 640cdf0e10cSrcweir CellPos aFirstPos, aLastPos; 641cdf0e10cSrcweir pController->getSelectedCells( aFirstPos, aLastPos ); 642cdf0e10cSrcweir 643cdf0e10cSrcweir const sal_Int32 nSelectedColumns = std::max( (sal_Int32)0, aLastPos.mnCol - aFirstPos.mnCol ) + 1; 644cdf0e10cSrcweir const sal_Int32 nSelectedRows = std::max( (sal_Int32)0, aLastPos.mnRow - aFirstPos.mnRow ) + 1; 645cdf0e10cSrcweir return nSelectedRows * nSelectedColumns; 646cdf0e10cSrcweir } 647cdf0e10cSrcweir 648cdf0e10cSrcweir return 0; 649cdf0e10cSrcweir } 650cdf0e10cSrcweir 651cdf0e10cSrcweir //-------------------------------------------------------------------- 652cdf0e10cSrcweir 653cdf0e10cSrcweir Reference< XAccessible > SAL_CALL AccessibleTableShape::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw ( IndexOutOfBoundsException, RuntimeException) 654cdf0e10cSrcweir { 655cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 656cdf0e10cSrcweir 657cdf0e10cSrcweir SvxTableController* pController = getTableController(); 658cdf0e10cSrcweir if( pController && pController->hasSelectedCells() ) 659cdf0e10cSrcweir { 660cdf0e10cSrcweir CellPos aFirstPos, aLastPos; 661cdf0e10cSrcweir pController->getSelectedCells( aFirstPos, aLastPos ); 662cdf0e10cSrcweir 663cdf0e10cSrcweir const sal_Int32 nSelectedColumns = std::max( (sal_Int32)0, aLastPos.mnCol - aFirstPos.mnCol ) + 1; 664cdf0e10cSrcweir const sal_Int32 nSelectedRows = std::max( (sal_Int32)0, aLastPos.mnRow - aFirstPos.mnRow ) + 1; 665cdf0e10cSrcweir 666cdf0e10cSrcweir if( nSelectedChildIndex < (nSelectedRows * nSelectedColumns) ) 667cdf0e10cSrcweir { 668cdf0e10cSrcweir while( nSelectedChildIndex >= nSelectedColumns ) 669cdf0e10cSrcweir { 670cdf0e10cSrcweir aFirstPos.mnRow++; 671cdf0e10cSrcweir nSelectedChildIndex -= nSelectedColumns; 672cdf0e10cSrcweir } 673cdf0e10cSrcweir return getAccessibleCellAt( nSelectedColumns, aFirstPos.mnRow ); 674cdf0e10cSrcweir } 675cdf0e10cSrcweir } 676cdf0e10cSrcweir 677cdf0e10cSrcweir throw IndexOutOfBoundsException(); 678cdf0e10cSrcweir } 679cdf0e10cSrcweir 680cdf0e10cSrcweir //-------------------------------------------------------------------- 681cdf0e10cSrcweir 682cdf0e10cSrcweir void SAL_CALL AccessibleTableShape::deselectAccessibleChild( sal_Int32 nChildIndex ) throw ( IndexOutOfBoundsException, RuntimeException ) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir ::vos::OGuard aSolarGuard (::Application::GetSolarMutex()); 685cdf0e10cSrcweir CellPos aPos; 686cdf0e10cSrcweir mxImpl->getColumnAndRow( nChildIndex, aPos.mnCol, aPos.mnRow ); 687cdf0e10cSrcweir 688cdf0e10cSrcweir // todo, select table shape?!? 689cdf0e10cSrcweir SvxTableController* pController = getTableController(); 690cdf0e10cSrcweir if( pController && pController->hasSelectedCells() ) 691cdf0e10cSrcweir { 692cdf0e10cSrcweir CellPos aFirstPos, aLastPos; 693cdf0e10cSrcweir pController->getSelectedCells( aFirstPos, aLastPos ); 694cdf0e10cSrcweir 695cdf0e10cSrcweir // create a selection where aPos is not part of anymore 696cdf0e10cSrcweir aFirstPos.mnRow = std::min( aFirstPos.mnRow, aPos.mnRow+1 ); 697cdf0e10cSrcweir aFirstPos.mnCol = std::min( aFirstPos.mnCol, aPos.mnCol+1 ); 698cdf0e10cSrcweir aLastPos.mnRow = std::max( aLastPos.mnRow, aPos.mnRow-1 ); 699cdf0e10cSrcweir aLastPos.mnCol = std::max( aLastPos.mnCol, aPos.mnCol-1 ); 700cdf0e10cSrcweir 701cdf0e10cSrcweir // new selection may be invalid (child to deselect is not at a border of the selection but in between) 702cdf0e10cSrcweir if( (aFirstPos.mnRow > aLastPos.mnRow) || (aFirstPos.mnCol > aLastPos.mnCol) ) 703cdf0e10cSrcweir pController->clearSelection(); // if selection is invalid, clear all 704cdf0e10cSrcweir else 705cdf0e10cSrcweir pController->setSelectedCells( aFirstPos, aLastPos ); 706cdf0e10cSrcweir } 707cdf0e10cSrcweir } 708cdf0e10cSrcweir 709cdf0e10cSrcweir //-------------------------------------------------------------------- 710cdf0e10cSrcweir 711cdf0e10cSrcweir void AccessibleTableShape::checkCellPosition( sal_Int32 nCol, sal_Int32 nRow ) throw ( IndexOutOfBoundsException ) 712cdf0e10cSrcweir { 713cdf0e10cSrcweir if( (nCol >= 0) && (nRow >= 0) && mxImpl->mxTable.is() && (nCol < mxImpl->mxTable->getColumnCount()) && (nRow < mxImpl->mxTable->getRowCount()) ) 714cdf0e10cSrcweir return; 715cdf0e10cSrcweir 716cdf0e10cSrcweir throw IndexOutOfBoundsException(); 717cdf0e10cSrcweir } 718cdf0e10cSrcweir 719cdf0e10cSrcweir } 720