LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTable.cxx
blob8938ba83a12248a07392a09c06d4083d326e1ea4
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_aCellVector.empty() || m_aCellVector.size() != static_cast<unsigned>(nCount))
60 m_aCellVector.resize(nCount);
62 if(!m_aCellVector[nChildIndex].is())
64 rtl::Reference<AccessibleGridControlTableCell> pCell = new AccessibleGridControlTableCell(this, m_aTable, nChildIndex/m_aTable.GetColumnCount(), nChildIndex%m_aTable.GetColumnCount());
65 m_aCellVector[nChildIndex] = pCell;
67 return m_aCellVector[nChildIndex];
70 sal_Int32 SAL_CALL AccessibleGridControlTable::getAccessibleIndexInParent()
72 ensureIsAlive();
73 if(m_aTable.HasRowHeader() && m_aTable.HasColHeader())
74 return 0;
75 else if((!m_aTable.HasRowHeader() && m_aTable.HasColHeader()) || (m_aTable.HasRowHeader() && !m_aTable.HasColHeader()) )
76 return 1;
77 else
78 return 2;
81 // XAccessibleComponent -------------------------------------------------------
83 Reference< XAccessible > SAL_CALL
84 AccessibleGridControlTable::getAccessibleAtPoint( const awt::Point& rPoint )
86 SolarMutexGuard aSolarGuard;
88 ensureIsAlive();
90 Reference< XAccessible > xChild;
91 sal_Int32 nRow = 0;
92 sal_Int32 nColumnPos = 0;
93 if( m_aTable.ConvertPointToCellAddress( nRow, nColumnPos, VCLPoint( rPoint ) ) )
94 xChild = new AccessibleGridControlTableCell(this, m_aTable, nRow, nColumnPos);
95 return xChild;
98 void SAL_CALL AccessibleGridControlTable::grabFocus()
100 SolarMutexGuard aSolarGuard;
102 ensureIsAlive();
103 m_aTable.GrabFocus();
106 // XAccessibleTable -----------------------------------------------------------
108 OUString SAL_CALL AccessibleGridControlTable::getAccessibleRowDescription( sal_Int32 nRow )
110 SolarMutexGuard aSolarGuard;
112 ensureIsAlive();
113 ensureIsValidRow( nRow );
114 return "row description";
117 OUString SAL_CALL AccessibleGridControlTable::getAccessibleColumnDescription( sal_Int32 nColumn )
119 SolarMutexGuard aSolarGuard;
121 ensureIsAlive();
122 ensureIsValidColumn( nColumn );
123 return "col description";
126 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleRowHeaders()
128 SolarMutexGuard g;
130 ensureIsAlive();
131 if(m_aTable.HasColHeader())
132 return implGetHeaderBar( 1 );
133 else
134 return implGetHeaderBar( 0 );
137 Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleColumnHeaders()
139 SolarMutexGuard g;
141 ensureIsAlive();
142 return implGetHeaderBar( 0 );
145 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleRows()
147 SolarMutexGuard aSolarGuard;
149 ensureIsAlive();
150 Sequence< sal_Int32 > aSelSeq;
151 implGetSelectedRows( aSelSeq );
152 return aSelSeq;
155 //columns aren't selectable
156 Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleColumns()
158 return {};
161 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleRowSelected( sal_Int32 nRow )
163 SolarMutexGuard aSolarGuard;
165 ensureIsAlive();
166 ensureIsValidRow( nRow );
167 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
168 return comphelper::findValue(selectedRows, nRow) != -1;
171 //columns aren't selectable
172 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleColumnSelected( sal_Int32 )
174 return false;
177 Reference< XAccessible > SAL_CALL AccessibleGridControlTable::getAccessibleCellAt(
178 sal_Int32 nRow, sal_Int32 nColumn )
180 SolarMutexGuard aSolarGuard;
182 ensureIsAlive();
183 ensureIsValidAddress( nRow, nColumn );
184 sal_Int32 nCount = getAccessibleChildCount();
185 sal_Int32 nChildIndex = nRow*m_aTable.GetColumnCount() + nColumn;
186 if(m_aCellVector.empty() || m_aCellVector.size() != static_cast<unsigned>(nCount))
188 m_aCellVector.resize(nCount);
190 if(!m_aCellVector[nChildIndex].is())
192 rtl::Reference<AccessibleGridControlTableCell> pCell = new AccessibleGridControlTableCell(this, m_aTable, nRow, nColumn);
193 m_aCellVector[nChildIndex] = pCell;
195 return m_aCellVector[nChildIndex];
198 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleSelected(
199 sal_Int32 nRow, sal_Int32 nColumn )
201 SolarMutexGuard aSolarGuard;
203 ensureIsAlive();
204 ensureIsValidAddress( nRow, nColumn );
205 //selection of single cells not possible, so if row is selected, the cell will be selected too
206 return isAccessibleRowSelected(nRow);
208 void SAL_CALL AccessibleGridControlTable::selectAccessibleChild( sal_Int32 nChildIndex )
210 SolarMutexGuard aSolarGuard;
212 ensureIsAlive();
213 ensureIsValidIndex( nChildIndex );
214 sal_Int32 nColumns = m_aTable.GetColumnCount();
215 sal_Int32 nRow = nChildIndex / nColumns;
216 m_aTable.SelectRow( nRow, true );
218 sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleChildSelected( 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 return isAccessibleRowSelected(nRow);
228 void SAL_CALL AccessibleGridControlTable::clearAccessibleSelection()
230 SolarMutexGuard aSolarGuard;
232 ensureIsAlive();
233 m_aTable.SelectAllRows( false );
235 void SAL_CALL AccessibleGridControlTable::selectAllAccessibleChildren()
237 SolarMutexGuard aSolarGuard;
239 ensureIsAlive();
240 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
241 auto selectedRowsRange = asNonConstRange(selectedRows);
242 for(tools::Long i=0; i<m_aTable.GetRowCount(); i++)
243 selectedRowsRange[i]=i;
245 sal_Int32 SAL_CALL AccessibleGridControlTable::getSelectedAccessibleChildCount()
247 SolarMutexGuard aSolarGuard;
249 ensureIsAlive();
250 Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
251 sal_Int32 nColumns = m_aTable.GetColumnCount();
252 return selectedRows.getLength()*nColumns;
254 Reference< XAccessible > SAL_CALL
255 AccessibleGridControlTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
257 SolarMutexGuard aSolarGuard;
259 ensureIsAlive();
260 if(isAccessibleChildSelected(nSelectedChildIndex))
261 return getAccessibleChild(nSelectedChildIndex);
262 else
263 return nullptr;
265 //not implemented yet, because only row selection possible
266 void SAL_CALL AccessibleGridControlTable::deselectAccessibleChild(
267 sal_Int32 )
269 SolarMutexGuard aSolarGuard;
271 ensureIsAlive();
273 // XInterface -----------------------------------------------------------------
275 Any SAL_CALL AccessibleGridControlTable::queryInterface( const uno::Type& rType )
277 Any aAny( AccessibleGridControlTableBase::queryInterface( rType ) );
278 return aAny.hasValue() ?
279 aAny : AccessibleGridControlTableSelectionImplHelper::queryInterface( rType );
282 void SAL_CALL AccessibleGridControlTable::acquire() noexcept
284 AccessibleGridControlTableBase::acquire();
287 void SAL_CALL AccessibleGridControlTable::release() noexcept
289 AccessibleGridControlTableBase::release();
291 // XServiceInfo ---------------------------------------------------------------
293 OUString SAL_CALL AccessibleGridControlTable::getImplementationName()
295 return "com.sun.star.accessibility.AccessibleGridControlTable";
298 // internal virtual methods ---------------------------------------------------
300 tools::Rectangle AccessibleGridControlTable::implGetBoundingBox()
302 vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
303 DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
304 tools::Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( pParent ));
305 tools::Rectangle aTableRect( m_aTable.calcTableRect() );
306 tools::Long nX = aGridRect.Left() + aTableRect.Left();
307 tools::Long nY = aGridRect.Top() + aTableRect.Top();
308 tools::Long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
309 tools::Long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
310 tools::Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
311 return aTable;
314 tools::Rectangle AccessibleGridControlTable::implGetBoundingBoxOnScreen()
316 tools::Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( nullptr ));
317 tools::Rectangle aTableRect( m_aTable.calcTableRect() );
318 tools::Long nX = aGridRect.Left() + aTableRect.Left();
319 tools::Long nY = aGridRect.Top() + aTableRect.Top();
320 tools::Long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
321 tools::Long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
322 tools::Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
323 return aTable;
325 // internal helper methods ----------------------------------------------------
326 Reference< XAccessibleTable > AccessibleGridControlTable::implGetHeaderBar(
327 sal_Int32 nChildIndex )
329 Reference< XAccessible > xRet;
330 Reference< XAccessibleContext > xContext( m_xParent, uno::UNO_QUERY );
331 if( xContext.is() )
335 xRet = xContext->getAccessibleChild( nChildIndex );
337 catch (const lang::IndexOutOfBoundsException&)
339 OSL_FAIL( "implGetHeaderBar - wrong child index" );
341 // RuntimeException goes to caller
343 return Reference< XAccessibleTable >( xRet, uno::UNO_QUERY );
347 } // namespace accessibility
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */