1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_accessibility.hxx" 26 27 28 #include "accessibility/extended/AccessibleGridControlTableBase.hxx" 29 #include <svtools/accessibletable.hxx> 30 #include <tools/multisel.hxx> 31 #include <comphelper/sequence.hxx> 32 33 // ============================================================================ 34 35 using ::rtl::OUString; 36 37 using ::com::sun::star::uno::Reference; 38 using ::com::sun::star::uno::Sequence; 39 using ::com::sun::star::uno::Any; 40 41 using namespace ::com::sun::star; 42 using namespace ::com::sun::star::accessibility; 43 using namespace ::svt; 44 using namespace ::svt::table; 45 46 // ============================================================================ 47 48 namespace accessibility { 49 50 // ============================================================================ 51 52 DBG_NAME( AccessibleGridControlTableBase ) 53 54 AccessibleGridControlTableBase::AccessibleGridControlTableBase( 55 const Reference< XAccessible >& rxParent, 56 IAccessibleTable& rTable, 57 AccessibleTableControlObjType eObjType ) : 58 GridControlAccessibleElement( rxParent, rTable, eObjType ) 59 { 60 } 61 62 AccessibleGridControlTableBase::~AccessibleGridControlTableBase() 63 { 64 } 65 66 // XAccessibleContext --------------------------------------------------------- 67 68 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleChildCount() 69 { 70 TCSolarGuard aSolarGuard; 71 ::osl::MutexGuard aGuard( getOslMutex() ); 72 ensureIsAlive(); 73 sal_Int32 nChildren = 0; 74 if(m_eObjType == TCTYPE_ROWHEADERBAR) 75 nChildren = m_aTable.GetRowCount(); 76 else if(m_eObjType == TCTYPE_TABLE) 77 nChildren = m_aTable.GetRowCount()*m_aTable.GetColumnCount(); 78 else if(m_eObjType == TCTYPE_COLUMNHEADERBAR) 79 nChildren = m_aTable.GetColumnCount(); 80 return nChildren; 81 } 82 83 sal_Int16 SAL_CALL AccessibleGridControlTableBase::getAccessibleRole() 84 { 85 ensureIsAlive(); 86 return AccessibleRole::TABLE; 87 } 88 89 // XAccessibleTable ----------------------------------------------------------- 90 91 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowCount() 92 { 93 TCSolarGuard aSolarGuard; 94 ::osl::MutexGuard aGuard( getOslMutex() ); 95 ensureIsAlive(); 96 return m_aTable.GetRowCount(); 97 } 98 99 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnCount() 100 { 101 TCSolarGuard aSolarGuard; 102 ::osl::MutexGuard aGuard( getOslMutex() ); 103 ensureIsAlive(); 104 return m_aTable.GetColumnCount(); 105 } 106 107 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowExtentAt( 108 sal_Int32 nRow, sal_Int32 nColumn ) 109 { 110 TCSolarGuard aSolarGuard; 111 ::osl::MutexGuard aGuard( getOslMutex() ); 112 ensureIsAlive(); 113 ensureIsValidAddress( nRow, nColumn ); 114 return 1; // merged cells not supported 115 } 116 117 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnExtentAt( 118 sal_Int32 nRow, sal_Int32 nColumn ) 119 { 120 TCSolarGuard aSolarGuard; 121 ::osl::MutexGuard aGuard( getOslMutex() ); 122 ensureIsAlive(); 123 ensureIsValidAddress( nRow, nColumn ); 124 return 1; // merged cells not supported 125 } 126 127 Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleCaption() 128 { 129 ensureIsAlive(); 130 return NULL; // not supported 131 } 132 133 Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleSummary() 134 { 135 ensureIsAlive(); 136 return NULL; // not supported 137 } 138 139 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleIndex( 140 sal_Int32 nRow, sal_Int32 nColumn ) 141 { 142 TCSolarGuard aSolarGuard; 143 ::osl::MutexGuard aGuard( getOslMutex() ); 144 ensureIsAlive(); 145 ensureIsValidAddress( nRow, nColumn ); 146 return implGetChildIndex( nRow, nColumn ); 147 } 148 149 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRow( sal_Int32 nChildIndex ) 150 { 151 TCSolarGuard aSolarGuard; 152 ::osl::MutexGuard aGuard( getOslMutex() ); 153 ensureIsAlive(); 154 ensureIsValidIndex( nChildIndex ); 155 return implGetRow( nChildIndex ); 156 } 157 158 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumn( sal_Int32 nChildIndex ) 159 { 160 TCSolarGuard aSolarGuard; 161 ::osl::MutexGuard aGuard( getOslMutex() ); 162 ensureIsAlive(); 163 ensureIsValidIndex( nChildIndex ); 164 return implGetColumn( nChildIndex ); 165 } 166 167 // XInterface ----------------------------------------------------------------- 168 169 Any SAL_CALL AccessibleGridControlTableBase::queryInterface( const uno::Type& rType ) 170 { 171 Any aAny( GridControlAccessibleElement::queryInterface( rType ) ); 172 return aAny.hasValue() ? 173 aAny : AccessibleGridControlTableImplHelper::queryInterface( rType ); 174 } 175 176 void SAL_CALL AccessibleGridControlTableBase::acquire() throw () 177 { 178 GridControlAccessibleElement::acquire(); 179 } 180 181 void SAL_CALL AccessibleGridControlTableBase::release() throw () 182 { 183 GridControlAccessibleElement::release(); 184 } 185 186 // XTypeProvider -------------------------------------------------------------- 187 188 Sequence< uno::Type > SAL_CALL AccessibleGridControlTableBase::getTypes() 189 { 190 return ::comphelper::concatSequences( 191 GridControlAccessibleElement::getTypes(), 192 AccessibleGridControlTableImplHelper::getTypes() ); 193 } 194 195 Sequence< sal_Int8 > SAL_CALL AccessibleGridControlTableBase::getImplementationId() 196 { 197 ::osl::MutexGuard aGuard( getOslGlobalMutex() ); 198 static Sequence< sal_Int8 > aId; 199 implCreateUuid( aId ); 200 return aId; 201 } 202 203 // internal helper methods ---------------------------------------------------- 204 205 sal_Int32 AccessibleGridControlTableBase::implGetChildCount() const 206 { 207 return m_aTable.GetRowCount()*m_aTable.GetColumnCount(); 208 } 209 210 sal_Int32 AccessibleGridControlTableBase::implGetRow( sal_Int32 nChildIndex ) const 211 { 212 sal_Int32 nColumns = m_aTable.GetColumnCount(); 213 return nColumns ? (nChildIndex / nColumns) : 0; 214 } 215 216 sal_Int32 AccessibleGridControlTableBase::implGetColumn( sal_Int32 nChildIndex ) const 217 { 218 sal_Int32 nColumns = m_aTable.GetColumnCount(); 219 return nColumns ? (nChildIndex % nColumns) : 0; 220 } 221 222 sal_Int32 AccessibleGridControlTableBase::implGetChildIndex( 223 sal_Int32 nRow, sal_Int32 nColumn ) const 224 { 225 return nRow * m_aTable.GetColumnCount() + nColumn; 226 } 227 228 void AccessibleGridControlTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq ) 229 { 230 sal_Int32 const selectionCount( m_aTable.GetSelectedRowCount() ); 231 rSeq.realloc( selectionCount ); 232 for ( sal_Int32 i=0; i<selectionCount; ++i ) 233 rSeq[i] = m_aTable.GetSelectedRowIndex(i); 234 } 235 236 void AccessibleGridControlTableBase::ensureIsValidRow( sal_Int32 nRow ) 237 { 238 if( nRow >= m_aTable.GetRowCount() ) 239 throw lang::IndexOutOfBoundsException( 240 OUString( RTL_CONSTASCII_USTRINGPARAM( "row index is invalid" ) ), *this ); 241 } 242 243 void AccessibleGridControlTableBase::ensureIsValidColumn( sal_Int32 nColumn ) 244 { 245 if( nColumn >= m_aTable.GetColumnCount() ) 246 throw lang::IndexOutOfBoundsException( 247 OUString( RTL_CONSTASCII_USTRINGPARAM("column index is invalid") ), *this ); 248 } 249 250 void AccessibleGridControlTableBase::ensureIsValidAddress( 251 sal_Int32 nRow, sal_Int32 nColumn ) 252 { 253 ensureIsValidRow( nRow ); 254 ensureIsValidColumn( nColumn ); 255 } 256 257 void AccessibleGridControlTableBase::ensureIsValidIndex( sal_Int32 nChildIndex ) 258 { 259 if( nChildIndex >= implGetChildCount() ) 260 throw lang::IndexOutOfBoundsException( 261 OUString( RTL_CONSTASCII_USTRINGPARAM("child index is invalid") ), *this ); 262 } 263 264 // ============================================================================ 265 } // namespace accessibility 266 // ============================================================================ 267