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