Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTable.cxx
blob3b08eadfd62f8c4befe8d3d4a0ee1b86aff1d182
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "accessibility/extended/AccessibleGridControlTable.hxx"
21 #include "accessibility/extended/AccessibleGridControlTableCell.hxx"
22 #include <svtools/accessibletable.hxx>
24 // ============================================================================
26 using ::com::sun::star::uno::Reference;
27 using ::com::sun::star::uno::Sequence;
28 using ::com::sun::star::uno::Any;
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::accessibility;
32 using namespace ::svt;
33 using namespace ::svt::table;
34 // ============================================================================
36 namespace accessibility {
38 // ============================================================================
40 AccessibleGridControlTable::AccessibleGridControlTable(
41 const Reference< XAccessible >& rxParent,
42 IAccessibleTable& rTable,
43 AccessibleTableControlObjType _eType) :
44 AccessibleGridControlTableBase( rxParent, rTable, _eType )
45 ,m_pCellVector( )
46 ,m_pAccessCellVector( )
50 AccessibleGridControlTable::~AccessibleGridControlTable()
54 // XAccessibleContext ---------------------------------------------------------
56 Reference< XAccessible > SAL_CALL
57 AccessibleGridControlTable::getAccessibleChild( sal_Int32 nChildIndex )
58 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
60 SolarMutexGuard aSolarGuard;
61 ::osl::MutexGuard aGuard( getOslMutex() );
62 ensureIsAlive();
63 ensureIsValidIndex( nChildIndex );
64 sal_Int32 nCount = getAccessibleChildCount();
65 if(m_pAccessCellVector.size() == 0 || m_pAccessCellVector.size() != (unsigned)nCount)
67 m_pAccessCellVector.resize(nCount);
68 m_pCellVector.resize(nCount);
70 if(!m_pAccessCellVector[nChildIndex].is())
72 AccessibleGridControlTableCell* pCell = new AccessibleGridControlTableCell(this, m_aTable, nChildIndex/m_aTable.GetColumnCount(), nChildIndex%m_aTable.GetColumnCount(), TCTYPE_TABLECELL);
73 m_pCellVector[nChildIndex] = pCell;
74 m_pAccessCellVector[nChildIndex] = pCell;
76 return m_pAccessCellVector[nChildIndex];
79 sal_Int32 SAL_CALL AccessibleGridControlTable::getAccessibleIndexInParent()
80 throw ( uno::RuntimeException )
82 ensureIsAlive();
83 if(m_aTable.HasRowHeader() && m_aTable.HasColHeader())
84 return 0;
85 else if((!m_aTable.HasRowHeader() && m_aTable.HasColHeader()) || (m_aTable.HasRowHeader() && !m_aTable.HasColHeader()) )
86 return 1;
87 else
88 return 2;
91 // XAccessibleComponent -------------------------------------------------------
93 Reference< XAccessible > SAL_CALL
94 AccessibleGridControlTable::getAccessibleAtPoint( const awt::Point& rPoint )
95 throw ( uno::RuntimeException )
97 SolarMutexGuard aSolarGuard;
98 ::osl::MutexGuard aGuard( getOslMutex() );
99 ensureIsAlive();
101 Reference< XAccessible > xChild;
102 sal_Int32 nRow = 0;
103 sal_Int32 nColumnPos = 0;
104 if( m_aTable.ConvertPointToCellAddress( nRow, nColumnPos, VCLPoint( rPoint ) ) )
105 xChild = new AccessibleGridControlTableCell(this, m_aTable, nRow, nColumnPos, TCTYPE_TABLECELL);
106 return xChild;
109 void SAL_CALL AccessibleGridControlTable::grabFocus()
110 throw ( uno::RuntimeException )
112 SolarMutexGuard aSolarGuard;
113 ::osl::MutexGuard aGuard( getOslMutex() );
114 ensureIsAlive();
115 m_aTable.GrabFocus();
118 Any SAL_CALL AccessibleGridControlTable::getAccessibleKeyBinding()
119 throw ( uno::RuntimeException )
121 ensureIsAlive();
122 return Any(); // no special key bindings for data table
125 // XAccessibleTable -----------------------------------------------------------
127 OUString SAL_CALL AccessibleGridControlTable::getAccessibleRowDescription( sal_Int32 nRow )
128 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
130 SolarMutexGuard aSolarGuard;
131 ::osl::MutexGuard aGuard( getOslMutex() );
132 ensureIsAlive();
133 ensureIsValidRow( nRow );
134 return m_aTable.GetRowDescription( nRow );
137 OUString SAL_CALL AccessibleGridControlTable::getAccessibleColumnDescription( sal_Int32 nColumn )
138 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
140 SolarMutexGuard aSolarGuard;
141 ::osl::MutexGuard aGuard( getOslMutex() );
142 ensureIsAlive();
143 ensureIsValidColumn( nColumn );
144 return m_aTable.GetColumnDescription( (sal_uInt16)nColumn );
147 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleRowHeaders()
148 throw ( uno::RuntimeException )
150 ::osl::MutexGuard aGuard( getOslMutex() );
151 ensureIsAlive();
152 if(m_aTable.HasColHeader())
153 return implGetHeaderBar( 1 );
154 else
155 return implGetHeaderBar( 0 );
158 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleColumnHeaders()
159 throw ( uno::RuntimeException )
161 ::osl::MutexGuard aGuard( getOslMutex() );
162 ensureIsAlive();
163 return implGetHeaderBar( 0 );
166 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleRows()
167 throw ( uno::RuntimeException )
169 SolarMutexGuard aSolarGuard;
170 ::osl::MutexGuard aGuard( getOslMutex() );
171 ensureIsAlive();
172 Sequence< sal_Int32 > aSelSeq;
173 implGetSelectedRows( aSelSeq );
174 return aSelSeq;
177 //columns aren't selectable
178 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleColumns()
179 throw ( uno::RuntimeException )
181 Sequence< sal_Int32 > aSelSeq(0);
182 return aSelSeq;
185 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleRowSelected( sal_Int32 nRow )
186 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
188 SolarMutexGuard aSolarGuard;
189 ::osl::MutexGuard aGuard( getOslMutex() );
190 ensureIsAlive();
191 ensureIsValidRow( nRow );
192 sal_Bool bSelected = sal_False;
193 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
194 for(int i=0; i<selectedRows.getLength(); i++)
196 if(nRow == selectedRows[i])
198 bSelected = sal_True;
199 continue;
202 return bSelected;
205 //columns aren't selectable
206 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleColumnSelected( sal_Int32 nColumn )
207 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
209 (void) nColumn;
210 return sal_False;
213 Reference< XAccessible > SAL_CALL AccessibleGridControlTable::getAccessibleCellAt(
214 sal_Int32 nRow, sal_Int32 nColumn )
215 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
217 SolarMutexGuard aSolarGuard;
218 ::osl::MutexGuard aGuard( getOslMutex() );
219 ensureIsAlive();
220 ensureIsValidAddress( nRow, nColumn );
221 sal_Int32 nCount = getAccessibleChildCount();
222 sal_Int32 nChildIndex = nRow*m_aTable.GetColumnCount() + nColumn;
223 if(m_pAccessCellVector.size() == 0 || m_pAccessCellVector.size() != (unsigned)nCount)
225 m_pAccessCellVector.resize(nCount);
226 m_pCellVector.resize(nCount);
228 if(!m_pAccessCellVector[nChildIndex].is())
230 AccessibleGridControlTableCell* pCell = new AccessibleGridControlTableCell(this, m_aTable, nRow, nColumn, TCTYPE_TABLECELL);
231 m_pCellVector[nChildIndex] = pCell;
232 m_pAccessCellVector[nChildIndex] = pCell;
234 return m_pAccessCellVector[nChildIndex];
237 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleSelected(
238 sal_Int32 nRow, sal_Int32 nColumn )
239 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
241 SolarMutexGuard aSolarGuard;
242 ::osl::MutexGuard aGuard( getOslMutex() );
243 ensureIsAlive();
244 ensureIsValidAddress( nRow, nColumn );
245 (void) nColumn;
246 //selection of single cells not possible, so if row is selected, the cell will be selected too
247 return isAccessibleRowSelected(nRow);
249 void SAL_CALL AccessibleGridControlTable::selectAccessibleChild( sal_Int32 nChildIndex )
250 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
252 SolarMutexGuard aSolarGuard;
253 ::osl::MutexGuard aGuard( getOslMutex() );
254 ensureIsAlive();
255 ensureIsValidIndex( nChildIndex );
256 sal_Int32 nColumns = m_aTable.GetColumnCount();
257 sal_Int32 nRow = (nChildIndex / nColumns);
258 m_aTable.SelectRow( nRow, sal_True );
260 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleChildSelected( sal_Int32 nChildIndex )
261 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
263 SolarMutexGuard aSolarGuard;
264 ::osl::MutexGuard aGuard( getOslMutex() );
265 ensureIsAlive();
266 ensureIsValidIndex( nChildIndex );
267 sal_Int32 nColumns = m_aTable.GetColumnCount();
268 sal_Int32 nRow = (nChildIndex / nColumns);
269 return isAccessibleRowSelected(nRow);
271 void SAL_CALL AccessibleGridControlTable::clearAccessibleSelection()
272 throw ( uno::RuntimeException )
274 SolarMutexGuard aSolarGuard;
275 ::osl::MutexGuard aGuard( getOslMutex() );
276 ensureIsAlive();
277 m_aTable.SelectAllRows( false );
279 void SAL_CALL AccessibleGridControlTable::selectAllAccessibleChildren()
280 throw ( uno::RuntimeException )
282 SolarMutexGuard aSolarGuard;
283 ::osl::MutexGuard aGuard( getOslMutex() );
284 ensureIsAlive();
285 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
286 for(int i=0;i<m_aTable.GetRowCount();i++)
287 selectedRows[i]=i;
289 sal_Int32 SAL_CALL AccessibleGridControlTable::getSelectedAccessibleChildCount()
290 throw ( uno::RuntimeException )
292 SolarMutexGuard aSolarGuard;
293 ::osl::MutexGuard aGuard( getOslMutex() );
294 ensureIsAlive();
295 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
296 sal_Int32 nColumns = m_aTable.GetColumnCount();
297 return selectedRows.getLength()*nColumns;
299 Reference< XAccessible > SAL_CALL
300 AccessibleGridControlTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
301 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
303 SolarMutexGuard aSolarGuard;
304 ::osl::MutexGuard aGuard( getOslMutex() );
305 ensureIsAlive();
306 if(isAccessibleChildSelected(nSelectedChildIndex))
307 return getAccessibleChild(nSelectedChildIndex);
308 else
309 return NULL;
311 //not implemented yet, because only row selection possible
312 void SAL_CALL AccessibleGridControlTable::deselectAccessibleChild(
313 sal_Int32 nSelectedChildIndex )
314 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
316 SolarMutexGuard aSolarGuard;
317 ::osl::MutexGuard aGuard( getOslMutex() );
318 ensureIsAlive();
319 (void)nSelectedChildIndex;
321 // XInterface -----------------------------------------------------------------
323 Any SAL_CALL AccessibleGridControlTable::queryInterface( const uno::Type& rType )
324 throw ( uno::RuntimeException )
326 Any aAny( AccessibleGridControlTableBase::queryInterface( rType ) );
327 return aAny.hasValue() ?
328 aAny : AccessibleGridControlTableImplHelper1::queryInterface( rType );
331 void SAL_CALL AccessibleGridControlTable::acquire() throw ()
333 AccessibleGridControlTableBase::acquire();
336 void SAL_CALL AccessibleGridControlTable::release() throw ()
338 AccessibleGridControlTableBase::release();
340 // XServiceInfo ---------------------------------------------------------------
342 OUString SAL_CALL AccessibleGridControlTable::getImplementationName()
343 throw ( uno::RuntimeException )
345 return OUString( "com.sun.star.accessibility.AccessibleGridControlTable" );
348 // internal virtual methods ---------------------------------------------------
350 Rectangle AccessibleGridControlTable::implGetBoundingBox()
352 Window* pParent = m_aTable.GetAccessibleParentWindow();
353 DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
354 Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( pParent ));
355 Rectangle aTableRect( m_aTable.calcTableRect() );
356 long nX = aGridRect.Left() + aTableRect.Left();
357 long nY = aGridRect.Top() + aTableRect.Top();
358 long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
359 long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
360 Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
361 return aTable;
364 Rectangle AccessibleGridControlTable::implGetBoundingBoxOnScreen()
366 Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( NULL ));
367 Rectangle aTableRect( m_aTable.calcTableRect() );
368 long nX = aGridRect.Left() + aTableRect.Left();
369 long nY = aGridRect.Top() + aTableRect.Top();
370 long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
371 long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
372 Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
373 return aTable;
375 // internal helper methods ----------------------------------------------------
376 Reference< XAccessibleTable > AccessibleGridControlTable::implGetHeaderBar(
377 sal_Int32 nChildIndex )
378 throw ( uno::RuntimeException )
380 Reference< XAccessible > xRet;
381 Reference< XAccessibleContext > xContext( m_xParent, uno::UNO_QUERY );
382 if( xContext.is() )
386 xRet = xContext->getAccessibleChild( nChildIndex );
388 catch (const lang::IndexOutOfBoundsException&)
390 OSL_FAIL( "implGetHeaderBar - wrong child index" );
392 // RuntimeException goes to caller
394 return Reference< XAccessibleTable >( xRet, uno::UNO_QUERY );
397 std::vector< AccessibleGridControlTableCell* >& AccessibleGridControlTable::getCellVector()
399 return m_pCellVector;
402 std::vector< Reference< XAccessible > >& AccessibleGridControlTable::getAccessibleCellVector()
404 return m_pAccessCellVector;
406 // ============================================================================
408 } // namespace accessibility
410 // ============================================================================
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */