lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTable.cxx
blob6e5e9d6def79f6c8270ef499555a28fea1a62a6c
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 <extended/AccessibleGridControlTable.hxx>
21 #include <extended/AccessibleGridControlTableCell.hxx>
22 #include <vcl/accessibletable.hxx>
24 using ::com::sun::star::uno::Reference;
25 using ::com::sun::star::uno::Sequence;
26 using ::com::sun::star::uno::Any;
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::accessibility;
30 using namespace ::vcl;
31 using namespace ::vcl::table;
34 namespace accessibility {
37 AccessibleGridControlTable::AccessibleGridControlTable(
38 const Reference< XAccessible >& rxParent,
39 IAccessibleTable& rTable) :
40 AccessibleGridControlTableBase( rxParent, rTable, TCTYPE_TABLE )
44 // XAccessibleContext ---------------------------------------------------------
46 Reference< XAccessible > SAL_CALL
47 AccessibleGridControlTable::getAccessibleChild( sal_Int32 nChildIndex )
49 SolarMutexGuard aSolarGuard;
51 ensureIsAlive();
52 ensureIsValidIndex( nChildIndex );
53 sal_Int32 nCount = getAccessibleChildCount();
54 if(m_pAccessCellVector.empty() || m_pAccessCellVector.size() != static_cast<unsigned>(nCount))
56 m_pAccessCellVector.resize(nCount);
57 m_pCellVector.resize(nCount);
59 if(!m_pAccessCellVector[nChildIndex].is())
61 AccessibleGridControlTableCell* pCell = new AccessibleGridControlTableCell(this, m_aTable, nChildIndex/m_aTable.GetColumnCount(), nChildIndex%m_aTable.GetColumnCount());
62 m_pCellVector[nChildIndex] = pCell;
63 m_pAccessCellVector[nChildIndex] = pCell;
65 return m_pAccessCellVector[nChildIndex];
68 sal_Int32 SAL_CALL AccessibleGridControlTable::getAccessibleIndexInParent()
70 ensureIsAlive();
71 if(m_aTable.HasRowHeader() && m_aTable.HasColHeader())
72 return 0;
73 else if((!m_aTable.HasRowHeader() && m_aTable.HasColHeader()) || (m_aTable.HasRowHeader() && !m_aTable.HasColHeader()) )
74 return 1;
75 else
76 return 2;
79 // XAccessibleComponent -------------------------------------------------------
81 Reference< XAccessible > SAL_CALL
82 AccessibleGridControlTable::getAccessibleAtPoint( const awt::Point& rPoint )
84 SolarMutexGuard aSolarGuard;
86 ensureIsAlive();
88 Reference< XAccessible > xChild;
89 sal_Int32 nRow = 0;
90 sal_Int32 nColumnPos = 0;
91 if( m_aTable.ConvertPointToCellAddress( nRow, nColumnPos, VCLPoint( rPoint ) ) )
92 xChild = new AccessibleGridControlTableCell(this, m_aTable, nRow, nColumnPos);
93 return xChild;
96 void SAL_CALL AccessibleGridControlTable::grabFocus()
98 SolarMutexGuard aSolarGuard;
100 ensureIsAlive();
101 m_aTable.GrabFocus();
104 // XAccessibleTable -----------------------------------------------------------
106 OUString SAL_CALL AccessibleGridControlTable::getAccessibleRowDescription( sal_Int32 nRow )
108 SolarMutexGuard aSolarGuard;
110 ensureIsAlive();
111 ensureIsValidRow( nRow );
112 return m_aTable.GetRowDescription( nRow );
115 OUString SAL_CALL AccessibleGridControlTable::getAccessibleColumnDescription( sal_Int32 nColumn )
117 SolarMutexGuard aSolarGuard;
119 ensureIsAlive();
120 ensureIsValidColumn( nColumn );
121 return m_aTable.GetColumnDescription( static_cast<sal_uInt16>(nColumn) );
124 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleRowHeaders()
126 SolarMutexGuard g;
128 ensureIsAlive();
129 if(m_aTable.HasColHeader())
130 return implGetHeaderBar( 1 );
131 else
132 return implGetHeaderBar( 0 );
135 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleColumnHeaders()
137 SolarMutexGuard g;
139 ensureIsAlive();
140 return implGetHeaderBar( 0 );
143 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleRows()
145 SolarMutexGuard aSolarGuard;
147 ensureIsAlive();
148 Sequence< sal_Int32 > aSelSeq;
149 implGetSelectedRows( aSelSeq );
150 return aSelSeq;
153 //columns aren't selectable
154 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleColumns()
156 Sequence< sal_Int32 > aSelSeq(0);
157 return aSelSeq;
160 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleRowSelected( sal_Int32 nRow )
162 SolarMutexGuard aSolarGuard;
164 ensureIsAlive();
165 ensureIsValidRow( nRow );
166 bool bSelected = false;
167 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
168 for(int i=0; i<selectedRows.getLength(); i++)
170 if(nRow == selectedRows[i])
172 bSelected = true;
173 continue;
176 return bSelected;
179 //columns aren't selectable
180 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleColumnSelected( sal_Int32 )
182 return false;
185 Reference< XAccessible > SAL_CALL AccessibleGridControlTable::getAccessibleCellAt(
186 sal_Int32 nRow, sal_Int32 nColumn )
188 SolarMutexGuard aSolarGuard;
190 ensureIsAlive();
191 ensureIsValidAddress( nRow, nColumn );
192 sal_Int32 nCount = getAccessibleChildCount();
193 sal_Int32 nChildIndex = nRow*m_aTable.GetColumnCount() + nColumn;
194 if(m_pAccessCellVector.empty() || m_pAccessCellVector.size() != static_cast<unsigned>(nCount))
196 m_pAccessCellVector.resize(nCount);
197 m_pCellVector.resize(nCount);
199 if(!m_pAccessCellVector[nChildIndex].is())
201 AccessibleGridControlTableCell* pCell = new AccessibleGridControlTableCell(this, m_aTable, nRow, nColumn);
202 m_pCellVector[nChildIndex] = pCell;
203 m_pAccessCellVector[nChildIndex] = pCell;
205 return m_pAccessCellVector[nChildIndex];
208 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleSelected(
209 sal_Int32 nRow, sal_Int32 nColumn )
211 SolarMutexGuard aSolarGuard;
213 ensureIsAlive();
214 ensureIsValidAddress( nRow, nColumn );
215 //selection of single cells not possible, so if row is selected, the cell will be selected too
216 return isAccessibleRowSelected(nRow);
218 void SAL_CALL AccessibleGridControlTable::selectAccessibleChild( sal_Int32 nChildIndex )
220 SolarMutexGuard aSolarGuard;
222 ensureIsAlive();
223 ensureIsValidIndex( nChildIndex );
224 sal_Int32 nColumns = m_aTable.GetColumnCount();
225 sal_Int32 nRow = (nChildIndex / nColumns);
226 m_aTable.SelectRow( nRow, true );
228 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleChildSelected( sal_Int32 nChildIndex )
230 SolarMutexGuard aSolarGuard;
232 ensureIsAlive();
233 ensureIsValidIndex( nChildIndex );
234 sal_Int32 nColumns = m_aTable.GetColumnCount();
235 sal_Int32 nRow = (nChildIndex / nColumns);
236 return isAccessibleRowSelected(nRow);
238 void SAL_CALL AccessibleGridControlTable::clearAccessibleSelection()
240 SolarMutexGuard aSolarGuard;
242 ensureIsAlive();
243 m_aTable.SelectAllRows( false );
245 void SAL_CALL AccessibleGridControlTable::selectAllAccessibleChildren()
247 SolarMutexGuard aSolarGuard;
249 ensureIsAlive();
250 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
251 for(long i=0; i<m_aTable.GetRowCount(); i++)
252 selectedRows[i]=i;
254 sal_Int32 SAL_CALL AccessibleGridControlTable::getSelectedAccessibleChildCount()
256 SolarMutexGuard aSolarGuard;
258 ensureIsAlive();
259 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
260 sal_Int32 nColumns = m_aTable.GetColumnCount();
261 return selectedRows.getLength()*nColumns;
263 Reference< XAccessible > SAL_CALL
264 AccessibleGridControlTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
266 SolarMutexGuard aSolarGuard;
268 ensureIsAlive();
269 if(isAccessibleChildSelected(nSelectedChildIndex))
270 return getAccessibleChild(nSelectedChildIndex);
271 else
272 return nullptr;
274 //not implemented yet, because only row selection possible
275 void SAL_CALL AccessibleGridControlTable::deselectAccessibleChild(
276 sal_Int32 )
278 SolarMutexGuard aSolarGuard;
280 ensureIsAlive();
282 // XInterface -----------------------------------------------------------------
284 Any SAL_CALL AccessibleGridControlTable::queryInterface( const uno::Type& rType )
286 Any aAny( AccessibleGridControlTableBase::queryInterface( rType ) );
287 return aAny.hasValue() ?
288 aAny : AccessibleGridControlTableSelectionImplHelper::queryInterface( rType );
291 void SAL_CALL AccessibleGridControlTable::acquire() throw ()
293 AccessibleGridControlTableBase::acquire();
296 void SAL_CALL AccessibleGridControlTable::release() throw ()
298 AccessibleGridControlTableBase::release();
300 // XServiceInfo ---------------------------------------------------------------
302 OUString SAL_CALL AccessibleGridControlTable::getImplementationName()
304 return OUString( "com.sun.star.accessibility.AccessibleGridControlTable" );
307 // internal virtual methods ---------------------------------------------------
309 tools::Rectangle AccessibleGridControlTable::implGetBoundingBox()
311 vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
312 DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
313 tools::Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( pParent ));
314 tools::Rectangle aTableRect( m_aTable.calcTableRect() );
315 long nX = aGridRect.Left() + aTableRect.Left();
316 long nY = aGridRect.Top() + aTableRect.Top();
317 long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
318 long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
319 tools::Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
320 return aTable;
323 tools::Rectangle AccessibleGridControlTable::implGetBoundingBoxOnScreen()
325 tools::Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( nullptr ));
326 tools::Rectangle aTableRect( m_aTable.calcTableRect() );
327 long nX = aGridRect.Left() + aTableRect.Left();
328 long nY = aGridRect.Top() + aTableRect.Top();
329 long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
330 long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
331 tools::Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
332 return aTable;
334 // internal helper methods ----------------------------------------------------
335 Reference< XAccessibleTable > AccessibleGridControlTable::implGetHeaderBar(
336 sal_Int32 nChildIndex )
338 Reference< XAccessible > xRet;
339 Reference< XAccessibleContext > xContext( m_xParent, uno::UNO_QUERY );
340 if( xContext.is() )
344 xRet = xContext->getAccessibleChild( nChildIndex );
346 catch (const lang::IndexOutOfBoundsException&)
348 OSL_FAIL( "implGetHeaderBar - wrong child index" );
350 // RuntimeException goes to caller
352 return Reference< XAccessibleTable >( xRet, uno::UNO_QUERY );
356 } // namespace accessibility
359 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */