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 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_accessibility.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include "accessibility/extended/AccessibleGridControlTableBase.hxx" 33*cdf0e10cSrcweir #include <svtools/accessibletable.hxx> 34*cdf0e10cSrcweir #include <tools/multisel.hxx> 35*cdf0e10cSrcweir #include <comphelper/sequence.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir // ============================================================================ 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using ::rtl::OUString; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 42*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 43*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir using namespace ::com::sun::star; 46*cdf0e10cSrcweir using namespace ::com::sun::star::accessibility; 47*cdf0e10cSrcweir using namespace ::svt; 48*cdf0e10cSrcweir using namespace ::svt::table; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir // ============================================================================ 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir namespace accessibility { 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir // ============================================================================ 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir DBG_NAME( AccessibleGridControlTableBase ) 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir AccessibleGridControlTableBase::AccessibleGridControlTableBase( 59*cdf0e10cSrcweir const Reference< XAccessible >& rxParent, 60*cdf0e10cSrcweir IAccessibleTable& rTable, 61*cdf0e10cSrcweir AccessibleTableControlObjType eObjType ) : 62*cdf0e10cSrcweir GridControlAccessibleElement( rxParent, rTable, eObjType ) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir AccessibleGridControlTableBase::~AccessibleGridControlTableBase() 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // XAccessibleContext --------------------------------------------------------- 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleChildCount() 73*cdf0e10cSrcweir throw ( uno::RuntimeException ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir TCSolarGuard aSolarGuard; 76*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getOslMutex() ); 77*cdf0e10cSrcweir ensureIsAlive(); 78*cdf0e10cSrcweir sal_Int32 nChildren = 0; 79*cdf0e10cSrcweir if(m_eObjType == TCTYPE_ROWHEADERBAR) 80*cdf0e10cSrcweir nChildren = m_aTable.GetRowCount(); 81*cdf0e10cSrcweir else if(m_eObjType == TCTYPE_TABLE) 82*cdf0e10cSrcweir nChildren = m_aTable.GetRowCount()*m_aTable.GetColumnCount(); 83*cdf0e10cSrcweir else if(m_eObjType == TCTYPE_COLUMNHEADERBAR) 84*cdf0e10cSrcweir nChildren = m_aTable.GetColumnCount(); 85*cdf0e10cSrcweir return nChildren; 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir sal_Int16 SAL_CALL AccessibleGridControlTableBase::getAccessibleRole() 89*cdf0e10cSrcweir throw ( uno::RuntimeException ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir ensureIsAlive(); 92*cdf0e10cSrcweir return AccessibleRole::TABLE; 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // XAccessibleTable ----------------------------------------------------------- 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowCount() 98*cdf0e10cSrcweir throw ( uno::RuntimeException ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir TCSolarGuard aSolarGuard; 101*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getOslMutex() ); 102*cdf0e10cSrcweir ensureIsAlive(); 103*cdf0e10cSrcweir return m_aTable.GetRowCount(); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnCount() 107*cdf0e10cSrcweir throw ( uno::RuntimeException ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir TCSolarGuard aSolarGuard; 110*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getOslMutex() ); 111*cdf0e10cSrcweir ensureIsAlive(); 112*cdf0e10cSrcweir return m_aTable.GetColumnCount(); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowExtentAt( 116*cdf0e10cSrcweir sal_Int32 nRow, sal_Int32 nColumn ) 117*cdf0e10cSrcweir throw ( lang::IndexOutOfBoundsException, uno::RuntimeException ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir TCSolarGuard aSolarGuard; 120*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getOslMutex() ); 121*cdf0e10cSrcweir ensureIsAlive(); 122*cdf0e10cSrcweir ensureIsValidAddress( nRow, nColumn ); 123*cdf0e10cSrcweir return 1; // merged cells not supported 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnExtentAt( 127*cdf0e10cSrcweir sal_Int32 nRow, sal_Int32 nColumn ) 128*cdf0e10cSrcweir throw ( lang::IndexOutOfBoundsException, uno::RuntimeException ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir TCSolarGuard aSolarGuard; 131*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getOslMutex() ); 132*cdf0e10cSrcweir ensureIsAlive(); 133*cdf0e10cSrcweir ensureIsValidAddress( nRow, nColumn ); 134*cdf0e10cSrcweir return 1; // merged cells not supported 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleCaption() 138*cdf0e10cSrcweir throw ( uno::RuntimeException ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir ensureIsAlive(); 141*cdf0e10cSrcweir return NULL; // not supported 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleSummary() 145*cdf0e10cSrcweir throw ( uno::RuntimeException ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir ensureIsAlive(); 148*cdf0e10cSrcweir return NULL; // not supported 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleIndex( 152*cdf0e10cSrcweir sal_Int32 nRow, sal_Int32 nColumn ) 153*cdf0e10cSrcweir throw ( lang::IndexOutOfBoundsException, uno::RuntimeException ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir TCSolarGuard aSolarGuard; 156*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getOslMutex() ); 157*cdf0e10cSrcweir ensureIsAlive(); 158*cdf0e10cSrcweir ensureIsValidAddress( nRow, nColumn ); 159*cdf0e10cSrcweir return implGetChildIndex( nRow, nColumn ); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRow( sal_Int32 nChildIndex ) 163*cdf0e10cSrcweir throw ( lang::IndexOutOfBoundsException, uno::RuntimeException ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir TCSolarGuard aSolarGuard; 166*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getOslMutex() ); 167*cdf0e10cSrcweir ensureIsAlive(); 168*cdf0e10cSrcweir ensureIsValidIndex( nChildIndex ); 169*cdf0e10cSrcweir return implGetRow( nChildIndex ); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumn( sal_Int32 nChildIndex ) 173*cdf0e10cSrcweir throw ( lang::IndexOutOfBoundsException, uno::RuntimeException ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir TCSolarGuard aSolarGuard; 176*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getOslMutex() ); 177*cdf0e10cSrcweir ensureIsAlive(); 178*cdf0e10cSrcweir ensureIsValidIndex( nChildIndex ); 179*cdf0e10cSrcweir return implGetColumn( nChildIndex ); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir // XInterface ----------------------------------------------------------------- 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir Any SAL_CALL AccessibleGridControlTableBase::queryInterface( const uno::Type& rType ) 185*cdf0e10cSrcweir throw ( uno::RuntimeException ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir Any aAny( GridControlAccessibleElement::queryInterface( rType ) ); 188*cdf0e10cSrcweir return aAny.hasValue() ? 189*cdf0e10cSrcweir aAny : AccessibleGridControlTableImplHelper::queryInterface( rType ); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir void SAL_CALL AccessibleGridControlTableBase::acquire() throw () 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir GridControlAccessibleElement::acquire(); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir void SAL_CALL AccessibleGridControlTableBase::release() throw () 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir GridControlAccessibleElement::release(); 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir // XTypeProvider -------------------------------------------------------------- 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir Sequence< uno::Type > SAL_CALL AccessibleGridControlTableBase::getTypes() 205*cdf0e10cSrcweir throw ( uno::RuntimeException ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir return ::comphelper::concatSequences( 208*cdf0e10cSrcweir GridControlAccessibleElement::getTypes(), 209*cdf0e10cSrcweir AccessibleGridControlTableImplHelper::getTypes() ); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL AccessibleGridControlTableBase::getImplementationId() 213*cdf0e10cSrcweir throw ( uno::RuntimeException ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getOslGlobalMutex() ); 216*cdf0e10cSrcweir static Sequence< sal_Int8 > aId; 217*cdf0e10cSrcweir implCreateUuid( aId ); 218*cdf0e10cSrcweir return aId; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir // internal helper methods ---------------------------------------------------- 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir sal_Int32 AccessibleGridControlTableBase::implGetChildCount() const 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir return m_aTable.GetRowCount()*m_aTable.GetColumnCount(); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir sal_Int32 AccessibleGridControlTableBase::implGetRow( sal_Int32 nChildIndex ) const 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir sal_Int32 nColumns = m_aTable.GetColumnCount(); 231*cdf0e10cSrcweir return nColumns ? (nChildIndex / nColumns) : 0; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir sal_Int32 AccessibleGridControlTableBase::implGetColumn( sal_Int32 nChildIndex ) const 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir sal_Int32 nColumns = m_aTable.GetColumnCount(); 237*cdf0e10cSrcweir return nColumns ? (nChildIndex % nColumns) : 0; 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir sal_Int32 AccessibleGridControlTableBase::implGetChildIndex( 241*cdf0e10cSrcweir sal_Int32 nRow, sal_Int32 nColumn ) const 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir return nRow * m_aTable.GetColumnCount() + nColumn; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir void AccessibleGridControlTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir sal_Int32 const selectionCount( m_aTable.GetSelectedRowCount() ); 249*cdf0e10cSrcweir rSeq.realloc( selectionCount ); 250*cdf0e10cSrcweir for ( sal_Int32 i=0; i<selectionCount; ++i ) 251*cdf0e10cSrcweir rSeq[i] = m_aTable.GetSelectedRowIndex(i); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir void AccessibleGridControlTableBase::ensureIsValidRow( sal_Int32 nRow ) 255*cdf0e10cSrcweir throw ( lang::IndexOutOfBoundsException ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir if( nRow >= m_aTable.GetRowCount() ) 258*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException( 259*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "row index is invalid" ) ), *this ); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir void AccessibleGridControlTableBase::ensureIsValidColumn( sal_Int32 nColumn ) 263*cdf0e10cSrcweir throw ( lang::IndexOutOfBoundsException ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir if( nColumn >= m_aTable.GetColumnCount() ) 266*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException( 267*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("column index is invalid") ), *this ); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir void AccessibleGridControlTableBase::ensureIsValidAddress( 271*cdf0e10cSrcweir sal_Int32 nRow, sal_Int32 nColumn ) 272*cdf0e10cSrcweir throw ( lang::IndexOutOfBoundsException ) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir ensureIsValidRow( nRow ); 275*cdf0e10cSrcweir ensureIsValidColumn( nColumn ); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir void AccessibleGridControlTableBase::ensureIsValidIndex( sal_Int32 nChildIndex ) 279*cdf0e10cSrcweir throw ( lang::IndexOutOfBoundsException ) 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir if( nChildIndex >= implGetChildCount() ) 282*cdf0e10cSrcweir throw lang::IndexOutOfBoundsException( 283*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("child index is invalid") ), *this ); 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir // ============================================================================ 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir } // namespace accessibility 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir // ============================================================================ 291*cdf0e10cSrcweir 292