tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTableBase.cxx
blobcec5382fcf2866464bfcda6b93a7d155f3421cb9
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/accessibility/AccessibleRole.hpp>
21 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
22 #include <extended/AccessibleGridControlTableBase.hxx>
23 #include <vcl/accessibletable.hxx>
24 #include <vcl/svapp.hxx>
25 #include <comphelper/sequence.hxx>
27 using css::uno::Reference;
28 using css::uno::Sequence;
29 using css::uno::Any;
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::accessibility;
33 using namespace ::vcl;
34 using namespace ::vcl::table;
37 namespace accessibility {
40 AccessibleGridControlTableBase::AccessibleGridControlTableBase(
41 const Reference< XAccessible >& rxParent,
42 IAccessibleTable& rTable,
43 AccessibleTableControlObjType eObjType ) :
44 AccessibleGridControlTableImplHelper( rxParent, rTable, eObjType )
48 // XAccessibleContext ---------------------------------------------------------
50 sal_Int64 SAL_CALL AccessibleGridControlTableBase::getAccessibleChildCount()
52 SolarMutexGuard aSolarGuard;
54 ensureIsAlive();
55 sal_Int64 nChildren = 0;
56 if (m_eObjType == AccessibleTableControlObjType::ROWHEADERBAR)
57 nChildren = m_aTable.GetRowCount();
58 else if (m_eObjType == AccessibleTableControlObjType::TABLE)
59 nChildren = static_cast<sal_Int64>(m_aTable.GetRowCount()) * static_cast<sal_Int64>(m_aTable.GetColumnCount());
60 else if (m_eObjType == AccessibleTableControlObjType::COLUMNHEADERBAR)
61 nChildren = m_aTable.GetColumnCount();
62 return nChildren;
65 sal_Int16 SAL_CALL AccessibleGridControlTableBase::getAccessibleRole()
67 SolarMutexGuard g;
69 ensureIsAlive();
70 return AccessibleRole::TABLE;
73 // XAccessibleTable -----------------------------------------------------------
75 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowCount()
77 SolarMutexGuard aSolarGuard;
79 ensureIsAlive();
81 if (m_eObjType == AccessibleTableControlObjType::COLUMNHEADERBAR)
82 return 1;
83 return m_aTable.GetRowCount();
86 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnCount()
88 SolarMutexGuard aSolarGuard;
90 ensureIsAlive();
92 if (m_eObjType == AccessibleTableControlObjType::ROWHEADERBAR)
93 return 1;
94 return m_aTable.GetColumnCount();
97 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowExtentAt(
98 sal_Int32 nRow, sal_Int32 nColumn )
100 SolarMutexGuard aSolarGuard;
102 ensureIsAlive();
103 ensureIsValidAddress( nRow, nColumn );
104 return 1; // merged cells not supported
107 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnExtentAt(
108 sal_Int32 nRow, sal_Int32 nColumn )
110 SolarMutexGuard aSolarGuard;
112 ensureIsAlive();
113 ensureIsValidAddress( nRow, nColumn );
114 return 1; // merged cells not supported
117 Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleCaption()
119 SolarMutexGuard g;
121 ensureIsAlive();
122 return nullptr; // not supported
125 Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleSummary()
127 SolarMutexGuard g;
129 ensureIsAlive();
130 return nullptr; // not supported
133 sal_Int64 SAL_CALL AccessibleGridControlTableBase::getAccessibleIndex(
134 sal_Int32 nRow, sal_Int32 nColumn )
136 SolarMutexGuard aSolarGuard;
138 ensureIsAlive();
139 ensureIsValidAddress( nRow, nColumn );
140 return static_cast<sal_Int64>(nRow) * static_cast<sal_Int64>(m_aTable.GetColumnCount()) + nColumn;
143 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRow( sal_Int64 nChildIndex )
145 SolarMutexGuard aSolarGuard;
147 ensureIsAlive();
148 ensureIsValidIndex( nChildIndex );
149 return implGetRow( nChildIndex );
152 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumn( sal_Int64 nChildIndex )
154 SolarMutexGuard aSolarGuard;
156 ensureIsAlive();
157 ensureIsValidIndex( nChildIndex );
158 return implGetColumn( nChildIndex );
161 // internal helper methods ----------------------------------------------------
163 sal_Int32 AccessibleGridControlTableBase::implGetRow( sal_Int64 nChildIndex )
165 sal_Int32 nColumns = getAccessibleColumnCount();
166 return nColumns ? (nChildIndex / nColumns) : 0;
169 sal_Int32 AccessibleGridControlTableBase::implGetColumn( sal_Int64 nChildIndex )
171 sal_Int32 nColumns = getAccessibleColumnCount();
172 return nColumns ? (nChildIndex % nColumns) : 0;
175 void AccessibleGridControlTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq )
177 sal_Int32 const selectionCount( m_aTable.GetSelectedRowCount() );
178 rSeq.realloc( selectionCount );
179 auto pSeq = rSeq.getArray();
180 for ( sal_Int32 i=0; i<selectionCount; ++i )
181 pSeq[i] = m_aTable.GetSelectedRowIndex(i);
184 void AccessibleGridControlTableBase::ensureIsValidRow( sal_Int32 nRow )
186 if (nRow >= getAccessibleRowCount())
187 throw lang::IndexOutOfBoundsException( u"row index is invalid"_ustr, *this );
190 void AccessibleGridControlTableBase::ensureIsValidColumn( sal_Int32 nColumn )
192 if (nColumn >= getAccessibleColumnCount())
193 throw lang::IndexOutOfBoundsException( u"column index is invalid"_ustr, *this );
196 void AccessibleGridControlTableBase::ensureIsValidAddress(
197 sal_Int32 nRow, sal_Int32 nColumn )
199 ensureIsValidRow( nRow );
200 ensureIsValidColumn( nColumn );
203 void AccessibleGridControlTableBase::ensureIsValidIndex( sal_Int64 nChildIndex )
205 if (nChildIndex >= static_cast<sal_Int64>(m_aTable.GetRowCount()) * static_cast<sal_Int64>(m_aTable.GetColumnCount()))
206 throw lang::IndexOutOfBoundsException( u"child index is invalid"_ustr, *this );
210 } // namespace accessibility
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */