Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTable.cxx
blob5392c54af73b69f0ad12582ff5fa020e5d5aff18
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>
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;
36 namespace accessibility {
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, std::exception )
60 SolarMutexGuard aSolarGuard;
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, std::exception )
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, std::exception )
97 SolarMutexGuard aSolarGuard;
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, std::exception )
112 SolarMutexGuard aSolarGuard;
114 ensureIsAlive();
115 m_aTable.GrabFocus();
118 // XAccessibleTable -----------------------------------------------------------
120 OUString SAL_CALL AccessibleGridControlTable::getAccessibleRowDescription( sal_Int32 nRow )
121 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
123 SolarMutexGuard aSolarGuard;
125 ensureIsAlive();
126 ensureIsValidRow( nRow );
127 return m_aTable.GetRowDescription( nRow );
130 OUString SAL_CALL AccessibleGridControlTable::getAccessibleColumnDescription( sal_Int32 nColumn )
131 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
133 SolarMutexGuard aSolarGuard;
135 ensureIsAlive();
136 ensureIsValidColumn( nColumn );
137 return m_aTable.GetColumnDescription( (sal_uInt16)nColumn );
140 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleRowHeaders()
141 throw ( uno::RuntimeException, std::exception )
143 SolarMutexGuard g;
145 ensureIsAlive();
146 if(m_aTable.HasColHeader())
147 return implGetHeaderBar( 1 );
148 else
149 return implGetHeaderBar( 0 );
152 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleColumnHeaders()
153 throw ( uno::RuntimeException, std::exception )
155 SolarMutexGuard g;
157 ensureIsAlive();
158 return implGetHeaderBar( 0 );
161 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleRows()
162 throw ( uno::RuntimeException, std::exception )
164 SolarMutexGuard aSolarGuard;
166 ensureIsAlive();
167 Sequence< sal_Int32 > aSelSeq;
168 implGetSelectedRows( aSelSeq );
169 return aSelSeq;
172 //columns aren't selectable
173 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleColumns()
174 throw ( uno::RuntimeException, std::exception )
176 Sequence< sal_Int32 > aSelSeq(0);
177 return aSelSeq;
180 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleRowSelected( sal_Int32 nRow )
181 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
183 SolarMutexGuard aSolarGuard;
185 ensureIsAlive();
186 ensureIsValidRow( nRow );
187 bool bSelected = false;
188 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
189 for(int i=0; i<selectedRows.getLength(); i++)
191 if(nRow == selectedRows[i])
193 bSelected = true;
194 continue;
197 return bSelected;
200 //columns aren't selectable
201 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleColumnSelected( sal_Int32 nColumn )
202 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
204 (void) nColumn;
205 return false;
208 Reference< XAccessible > SAL_CALL AccessibleGridControlTable::getAccessibleCellAt(
209 sal_Int32 nRow, sal_Int32 nColumn )
210 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
212 SolarMutexGuard aSolarGuard;
214 ensureIsAlive();
215 ensureIsValidAddress( nRow, nColumn );
216 sal_Int32 nCount = getAccessibleChildCount();
217 sal_Int32 nChildIndex = nRow*m_aTable.GetColumnCount() + nColumn;
218 if(m_pAccessCellVector.size() == 0 || m_pAccessCellVector.size() != (unsigned)nCount)
220 m_pAccessCellVector.resize(nCount);
221 m_pCellVector.resize(nCount);
223 if(!m_pAccessCellVector[nChildIndex].is())
225 AccessibleGridControlTableCell* pCell = new AccessibleGridControlTableCell(this, m_aTable, nRow, nColumn, TCTYPE_TABLECELL);
226 m_pCellVector[nChildIndex] = pCell;
227 m_pAccessCellVector[nChildIndex] = pCell;
229 return m_pAccessCellVector[nChildIndex];
232 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleSelected(
233 sal_Int32 nRow, sal_Int32 nColumn )
234 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
236 SolarMutexGuard aSolarGuard;
238 ensureIsAlive();
239 ensureIsValidAddress( nRow, nColumn );
240 (void) nColumn;
241 //selection of single cells not possible, so if row is selected, the cell will be selected too
242 return isAccessibleRowSelected(nRow);
244 void SAL_CALL AccessibleGridControlTable::selectAccessibleChild( sal_Int32 nChildIndex )
245 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
247 SolarMutexGuard aSolarGuard;
249 ensureIsAlive();
250 ensureIsValidIndex( nChildIndex );
251 sal_Int32 nColumns = m_aTable.GetColumnCount();
252 sal_Int32 nRow = (nChildIndex / nColumns);
253 m_aTable.SelectRow( nRow, true );
255 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleChildSelected( sal_Int32 nChildIndex )
256 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
258 SolarMutexGuard aSolarGuard;
260 ensureIsAlive();
261 ensureIsValidIndex( nChildIndex );
262 sal_Int32 nColumns = m_aTable.GetColumnCount();
263 sal_Int32 nRow = (nChildIndex / nColumns);
264 return isAccessibleRowSelected(nRow);
266 void SAL_CALL AccessibleGridControlTable::clearAccessibleSelection()
267 throw ( uno::RuntimeException, std::exception )
269 SolarMutexGuard aSolarGuard;
271 ensureIsAlive();
272 m_aTable.SelectAllRows( false );
274 void SAL_CALL AccessibleGridControlTable::selectAllAccessibleChildren()
275 throw ( uno::RuntimeException, std::exception )
277 SolarMutexGuard aSolarGuard;
279 ensureIsAlive();
280 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
281 for(int i=0;i<m_aTable.GetRowCount();i++)
282 selectedRows[i]=i;
284 sal_Int32 SAL_CALL AccessibleGridControlTable::getSelectedAccessibleChildCount()
285 throw ( uno::RuntimeException, std::exception )
287 SolarMutexGuard aSolarGuard;
289 ensureIsAlive();
290 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
291 sal_Int32 nColumns = m_aTable.GetColumnCount();
292 return selectedRows.getLength()*nColumns;
294 Reference< XAccessible > SAL_CALL
295 AccessibleGridControlTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
296 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
298 SolarMutexGuard aSolarGuard;
300 ensureIsAlive();
301 if(isAccessibleChildSelected(nSelectedChildIndex))
302 return getAccessibleChild(nSelectedChildIndex);
303 else
304 return NULL;
306 //not implemented yet, because only row selection possible
307 void SAL_CALL AccessibleGridControlTable::deselectAccessibleChild(
308 sal_Int32 nSelectedChildIndex )
309 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
311 SolarMutexGuard aSolarGuard;
313 ensureIsAlive();
314 (void)nSelectedChildIndex;
316 // XInterface -----------------------------------------------------------------
318 Any SAL_CALL AccessibleGridControlTable::queryInterface( const uno::Type& rType )
319 throw ( uno::RuntimeException, std::exception )
321 Any aAny( AccessibleGridControlTableBase::queryInterface( rType ) );
322 return aAny.hasValue() ?
323 aAny : AccessibleGridControlTableImplHelper1::queryInterface( rType );
326 void SAL_CALL AccessibleGridControlTable::acquire() throw ()
328 AccessibleGridControlTableBase::acquire();
331 void SAL_CALL AccessibleGridControlTable::release() throw ()
333 AccessibleGridControlTableBase::release();
335 // XServiceInfo ---------------------------------------------------------------
337 OUString SAL_CALL AccessibleGridControlTable::getImplementationName()
338 throw ( uno::RuntimeException, std::exception )
340 return OUString( "com.sun.star.accessibility.AccessibleGridControlTable" );
343 // internal virtual methods ---------------------------------------------------
345 Rectangle AccessibleGridControlTable::implGetBoundingBox()
347 vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
348 DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
349 Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( pParent ));
350 Rectangle aTableRect( m_aTable.calcTableRect() );
351 long nX = aGridRect.Left() + aTableRect.Left();
352 long nY = aGridRect.Top() + aTableRect.Top();
353 long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
354 long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
355 Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
356 return aTable;
359 Rectangle AccessibleGridControlTable::implGetBoundingBoxOnScreen()
361 Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( NULL ));
362 Rectangle aTableRect( m_aTable.calcTableRect() );
363 long nX = aGridRect.Left() + aTableRect.Left();
364 long nY = aGridRect.Top() + aTableRect.Top();
365 long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
366 long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
367 Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
368 return aTable;
370 // internal helper methods ----------------------------------------------------
371 Reference< XAccessibleTable > AccessibleGridControlTable::implGetHeaderBar(
372 sal_Int32 nChildIndex )
373 throw ( uno::RuntimeException )
375 Reference< XAccessible > xRet;
376 Reference< XAccessibleContext > xContext( m_xParent, uno::UNO_QUERY );
377 if( xContext.is() )
381 xRet = xContext->getAccessibleChild( nChildIndex );
383 catch (const lang::IndexOutOfBoundsException&)
385 OSL_FAIL( "implGetHeaderBar - wrong child index" );
387 // RuntimeException goes to caller
389 return Reference< XAccessibleTable >( xRet, uno::UNO_QUERY );
395 } // namespace accessibility
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */