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