LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTableBase.cxx
blob7ed42bc6b830024707324f094610bda6b710a5f3
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 GridControlAccessibleElement( rxParent, rTable, eObjType )
48 // XAccessibleContext ---------------------------------------------------------
50 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleChildCount()
52 SolarMutexGuard aSolarGuard;
54 ensureIsAlive();
55 sal_Int32 nChildren = 0;
56 if(m_eObjType == TCTYPE_ROWHEADERBAR)
57 nChildren = m_aTable.GetRowCount();
58 else if(m_eObjType == TCTYPE_TABLE)
59 nChildren = m_aTable.GetRowCount()*m_aTable.GetColumnCount();
60 else if(m_eObjType == TCTYPE_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();
80 return m_aTable.GetRowCount();
83 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnCount()
85 SolarMutexGuard aSolarGuard;
87 ensureIsAlive();
88 return m_aTable.GetColumnCount();
91 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowExtentAt(
92 sal_Int32 nRow, sal_Int32 nColumn )
94 SolarMutexGuard aSolarGuard;
96 ensureIsAlive();
97 ensureIsValidAddress( nRow, nColumn );
98 return 1; // merged cells not supported
101 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnExtentAt(
102 sal_Int32 nRow, sal_Int32 nColumn )
104 SolarMutexGuard aSolarGuard;
106 ensureIsAlive();
107 ensureIsValidAddress( nRow, nColumn );
108 return 1; // merged cells not supported
111 Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleCaption()
113 SolarMutexGuard g;
115 ensureIsAlive();
116 return nullptr; // not supported
119 Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleSummary()
121 SolarMutexGuard g;
123 ensureIsAlive();
124 return nullptr; // not supported
127 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleIndex(
128 sal_Int32 nRow, sal_Int32 nColumn )
130 SolarMutexGuard aSolarGuard;
132 ensureIsAlive();
133 ensureIsValidAddress( nRow, nColumn );
134 return nRow * m_aTable.GetColumnCount() + nColumn;
137 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRow( sal_Int32 nChildIndex )
139 SolarMutexGuard aSolarGuard;
141 ensureIsAlive();
142 ensureIsValidIndex( nChildIndex );
143 return implGetRow( nChildIndex );
146 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumn( sal_Int32 nChildIndex )
148 SolarMutexGuard aSolarGuard;
150 ensureIsAlive();
151 ensureIsValidIndex( nChildIndex );
152 return implGetColumn( nChildIndex );
155 // XInterface -----------------------------------------------------------------
157 Any SAL_CALL AccessibleGridControlTableBase::queryInterface( const uno::Type& rType )
159 Any aAny( GridControlAccessibleElement::queryInterface( rType ) );
160 return aAny.hasValue() ?
161 aAny : AccessibleGridControlTableImplHelper::queryInterface( rType );
164 void SAL_CALL AccessibleGridControlTableBase::acquire() noexcept
166 GridControlAccessibleElement::acquire();
169 void SAL_CALL AccessibleGridControlTableBase::release() noexcept
171 GridControlAccessibleElement::release();
174 // XTypeProvider --------------------------------------------------------------
176 Sequence< uno::Type > SAL_CALL AccessibleGridControlTableBase::getTypes()
178 return ::comphelper::concatSequences(
179 GridControlAccessibleElement::getTypes(),
180 AccessibleGridControlTableImplHelper::getTypes() );
183 Sequence< sal_Int8 > SAL_CALL AccessibleGridControlTableBase::getImplementationId()
185 return css::uno::Sequence<sal_Int8>();
188 // internal helper methods ----------------------------------------------------
190 sal_Int32 AccessibleGridControlTableBase::implGetRow( sal_Int32 nChildIndex ) const
192 sal_Int32 nColumns = m_aTable.GetColumnCount();
193 return nColumns ? (nChildIndex / nColumns) : 0;
196 sal_Int32 AccessibleGridControlTableBase::implGetColumn( sal_Int32 nChildIndex ) const
198 sal_Int32 nColumns = m_aTable.GetColumnCount();
199 return nColumns ? (nChildIndex % nColumns) : 0;
202 void AccessibleGridControlTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq )
204 sal_Int32 const selectionCount( m_aTable.GetSelectedRowCount() );
205 rSeq.realloc( selectionCount );
206 auto pSeq = rSeq.getArray();
207 for ( sal_Int32 i=0; i<selectionCount; ++i )
208 pSeq[i] = m_aTable.GetSelectedRowIndex(i);
211 void AccessibleGridControlTableBase::ensureIsValidRow( sal_Int32 nRow )
213 if( nRow >= m_aTable.GetRowCount() )
214 throw lang::IndexOutOfBoundsException( "row index is invalid", *this );
217 void AccessibleGridControlTableBase::ensureIsValidColumn( sal_Int32 nColumn )
219 if( nColumn >= m_aTable.GetColumnCount() )
220 throw lang::IndexOutOfBoundsException( "column index is invalid", *this );
223 void AccessibleGridControlTableBase::ensureIsValidAddress(
224 sal_Int32 nRow, sal_Int32 nColumn )
226 ensureIsValidRow( nRow );
227 ensureIsValidColumn( nColumn );
230 void AccessibleGridControlTableBase::ensureIsValidIndex( sal_Int32 nChildIndex )
232 if( nChildIndex >= m_aTable.GetRowCount()*m_aTable.GetColumnCount() )
233 throw lang::IndexOutOfBoundsException( "child index is invalid", *this );
237 } // namespace accessibility
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */