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