Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTable.cxx
blobcf9aa221a5a152854d3071fcc846e373b0381f08
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 <com/sun/star/lang/IndexOutOfBoundsException.hpp>
21 #include <extended/AccessibleGridControlTable.hxx>
22 #include <extended/AccessibleGridControlTableCell.hxx>
23 #include <toolkit/helper/convert.hxx>
24 #include <vcl/accessibletable.hxx>
25 #include <vcl/svapp.hxx>
26 #include <tools/debug.hxx>
28 using ::com::sun::star::uno::Reference;
29 using ::com::sun::star::uno::Sequence;
30 using ::com::sun::star::uno::Any;
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::accessibility;
34 using namespace ::vcl;
35 using namespace ::vcl::table;
38 namespace accessibility {
41 AccessibleGridControlTable::AccessibleGridControlTable(
42 const Reference< XAccessible >& rxParent,
43 IAccessibleTable& rTable) :
44 AccessibleGridControlTableBase( rxParent, rTable, TCTYPE_TABLE )
48 // XAccessibleContext ---------------------------------------------------------
50 Reference< XAccessible > SAL_CALL
51 AccessibleGridControlTable::getAccessibleChild( sal_Int32 nChildIndex )
53 SolarMutexGuard aSolarGuard;
55 ensureIsAlive();
56 ensureIsValidIndex( nChildIndex );
57 sal_Int32 nCount = getAccessibleChildCount();
58 if(m_pAccessCellVector.empty() || m_pAccessCellVector.size() != static_cast<unsigned>(nCount))
60 m_pAccessCellVector.resize(nCount);
61 m_pCellVector.resize(nCount);
63 if(!m_pAccessCellVector[nChildIndex].is())
65 AccessibleGridControlTableCell* pCell = new AccessibleGridControlTableCell(this, m_aTable, nChildIndex/m_aTable.GetColumnCount(), nChildIndex%m_aTable.GetColumnCount());
66 m_pCellVector[nChildIndex] = pCell;
67 m_pAccessCellVector[nChildIndex] = pCell;
69 return m_pAccessCellVector[nChildIndex];
72 sal_Int32 SAL_CALL AccessibleGridControlTable::getAccessibleIndexInParent()
74 ensureIsAlive();
75 if(m_aTable.HasRowHeader() && m_aTable.HasColHeader())
76 return 0;
77 else if((!m_aTable.HasRowHeader() && m_aTable.HasColHeader()) || (m_aTable.HasRowHeader() && !m_aTable.HasColHeader()) )
78 return 1;
79 else
80 return 2;
83 // XAccessibleComponent -------------------------------------------------------
85 Reference< XAccessible > SAL_CALL
86 AccessibleGridControlTable::getAccessibleAtPoint( const awt::Point& rPoint )
88 SolarMutexGuard aSolarGuard;
90 ensureIsAlive();
92 Reference< XAccessible > xChild;
93 sal_Int32 nRow = 0;
94 sal_Int32 nColumnPos = 0;
95 if( m_aTable.ConvertPointToCellAddress( nRow, nColumnPos, VCLPoint( rPoint ) ) )
96 xChild = new AccessibleGridControlTableCell(this, m_aTable, nRow, nColumnPos);
97 return xChild;
100 void SAL_CALL AccessibleGridControlTable::grabFocus()
102 SolarMutexGuard aSolarGuard;
104 ensureIsAlive();
105 m_aTable.GrabFocus();
108 // XAccessibleTable -----------------------------------------------------------
110 OUString SAL_CALL AccessibleGridControlTable::getAccessibleRowDescription( sal_Int32 nRow )
112 SolarMutexGuard aSolarGuard;
114 ensureIsAlive();
115 ensureIsValidRow( nRow );
116 return "row description";
119 OUString SAL_CALL AccessibleGridControlTable::getAccessibleColumnDescription( sal_Int32 nColumn )
121 SolarMutexGuard aSolarGuard;
123 ensureIsAlive();
124 ensureIsValidColumn( nColumn );
125 return "col description";
128 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleRowHeaders()
130 SolarMutexGuard g;
132 ensureIsAlive();
133 if(m_aTable.HasColHeader())
134 return implGetHeaderBar( 1 );
135 else
136 return implGetHeaderBar( 0 );
139 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleColumnHeaders()
141 SolarMutexGuard g;
143 ensureIsAlive();
144 return implGetHeaderBar( 0 );
147 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleRows()
149 SolarMutexGuard aSolarGuard;
151 ensureIsAlive();
152 Sequence< sal_Int32 > aSelSeq;
153 implGetSelectedRows( aSelSeq );
154 return aSelSeq;
157 //columns aren't selectable
158 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleColumns()
160 Sequence< sal_Int32 > aSelSeq(0);
161 return aSelSeq;
164 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleRowSelected( sal_Int32 nRow )
166 SolarMutexGuard aSolarGuard;
168 ensureIsAlive();
169 ensureIsValidRow( nRow );
170 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
171 return comphelper::findValue(selectedRows, nRow) != -1;
174 //columns aren't selectable
175 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleColumnSelected( sal_Int32 )
177 return false;
180 Reference< XAccessible > SAL_CALL AccessibleGridControlTable::getAccessibleCellAt(
181 sal_Int32 nRow, sal_Int32 nColumn )
183 SolarMutexGuard aSolarGuard;
185 ensureIsAlive();
186 ensureIsValidAddress( nRow, nColumn );
187 sal_Int32 nCount = getAccessibleChildCount();
188 sal_Int32 nChildIndex = nRow*m_aTable.GetColumnCount() + nColumn;
189 if(m_pAccessCellVector.empty() || m_pAccessCellVector.size() != static_cast<unsigned>(nCount))
191 m_pAccessCellVector.resize(nCount);
192 m_pCellVector.resize(nCount);
194 if(!m_pAccessCellVector[nChildIndex].is())
196 AccessibleGridControlTableCell* pCell = new AccessibleGridControlTableCell(this, m_aTable, nRow, nColumn);
197 m_pCellVector[nChildIndex] = pCell;
198 m_pAccessCellVector[nChildIndex] = pCell;
200 return m_pAccessCellVector[nChildIndex];
203 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleSelected(
204 sal_Int32 nRow, sal_Int32 nColumn )
206 SolarMutexGuard aSolarGuard;
208 ensureIsAlive();
209 ensureIsValidAddress( nRow, nColumn );
210 //selection of single cells not possible, so if row is selected, the cell will be selected too
211 return isAccessibleRowSelected(nRow);
213 void SAL_CALL AccessibleGridControlTable::selectAccessibleChild( sal_Int32 nChildIndex )
215 SolarMutexGuard aSolarGuard;
217 ensureIsAlive();
218 ensureIsValidIndex( nChildIndex );
219 sal_Int32 nColumns = m_aTable.GetColumnCount();
220 sal_Int32 nRow = nChildIndex / nColumns;
221 m_aTable.SelectRow( nRow, true );
223 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleChildSelected( sal_Int32 nChildIndex )
225 SolarMutexGuard aSolarGuard;
227 ensureIsAlive();
228 ensureIsValidIndex( nChildIndex );
229 sal_Int32 nColumns = m_aTable.GetColumnCount();
230 sal_Int32 nRow = nChildIndex / nColumns;
231 return isAccessibleRowSelected(nRow);
233 void SAL_CALL AccessibleGridControlTable::clearAccessibleSelection()
235 SolarMutexGuard aSolarGuard;
237 ensureIsAlive();
238 m_aTable.SelectAllRows( false );
240 void SAL_CALL AccessibleGridControlTable::selectAllAccessibleChildren()
242 SolarMutexGuard aSolarGuard;
244 ensureIsAlive();
245 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
246 for(long i=0; i<m_aTable.GetRowCount(); i++)
247 selectedRows[i]=i;
249 sal_Int32 SAL_CALL AccessibleGridControlTable::getSelectedAccessibleChildCount()
251 SolarMutexGuard aSolarGuard;
253 ensureIsAlive();
254 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
255 sal_Int32 nColumns = m_aTable.GetColumnCount();
256 return selectedRows.getLength()*nColumns;
258 Reference< XAccessible > SAL_CALL
259 AccessibleGridControlTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
261 SolarMutexGuard aSolarGuard;
263 ensureIsAlive();
264 if(isAccessibleChildSelected(nSelectedChildIndex))
265 return getAccessibleChild(nSelectedChildIndex);
266 else
267 return nullptr;
269 //not implemented yet, because only row selection possible
270 void SAL_CALL AccessibleGridControlTable::deselectAccessibleChild(
271 sal_Int32 )
273 SolarMutexGuard aSolarGuard;
275 ensureIsAlive();
277 // XInterface -----------------------------------------------------------------
279 Any SAL_CALL AccessibleGridControlTable::queryInterface( const uno::Type& rType )
281 Any aAny( AccessibleGridControlTableBase::queryInterface( rType ) );
282 return aAny.hasValue() ?
283 aAny : AccessibleGridControlTableSelectionImplHelper::queryInterface( rType );
286 void SAL_CALL AccessibleGridControlTable::acquire() throw ()
288 AccessibleGridControlTableBase::acquire();
291 void SAL_CALL AccessibleGridControlTable::release() throw ()
293 AccessibleGridControlTableBase::release();
295 // XServiceInfo ---------------------------------------------------------------
297 OUString SAL_CALL AccessibleGridControlTable::getImplementationName()
299 return "com.sun.star.accessibility.AccessibleGridControlTable";
302 // internal virtual methods ---------------------------------------------------
304 tools::Rectangle AccessibleGridControlTable::implGetBoundingBox()
306 vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
307 DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
308 tools::Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( pParent ));
309 tools::Rectangle aTableRect( m_aTable.calcTableRect() );
310 long nX = aGridRect.Left() + aTableRect.Left();
311 long nY = aGridRect.Top() + aTableRect.Top();
312 long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
313 long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
314 tools::Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
315 return aTable;
318 tools::Rectangle AccessibleGridControlTable::implGetBoundingBoxOnScreen()
320 tools::Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( nullptr ));
321 tools::Rectangle aTableRect( m_aTable.calcTableRect() );
322 long nX = aGridRect.Left() + aTableRect.Left();
323 long nY = aGridRect.Top() + aTableRect.Top();
324 long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
325 long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
326 tools::Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
327 return aTable;
329 // internal helper methods ----------------------------------------------------
330 Reference< XAccessibleTable > AccessibleGridControlTable::implGetHeaderBar(
331 sal_Int32 nChildIndex )
333 Reference< XAccessible > xRet;
334 Reference< XAccessibleContext > xContext( m_xParent, uno::UNO_QUERY );
335 if( xContext.is() )
339 xRet = xContext->getAccessibleChild( nChildIndex );
341 catch (const lang::IndexOutOfBoundsException&)
343 OSL_FAIL( "implGetHeaderBar - wrong child index" );
345 // RuntimeException goes to caller
347 return Reference< XAccessibleTable >( xRet, uno::UNO_QUERY );
351 } // namespace accessibility
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */