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