LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBoxTableBase.cxx
blobebb6e06e099da7efe55125f27167b4b5e1cf7cf1
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/AccessibleBrowseBoxTableBase.hxx>
21 #include <vcl/accessibletableprovider.hxx>
22 #include <comphelper/sequence.hxx>
23 #include <com/sun/star/accessibility/AccessibleRole.hpp>
24 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
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;
35 namespace accessibility {
38 // Ctor/Dtor/disposing --------------------------------------------------------
40 AccessibleBrowseBoxTableBase::AccessibleBrowseBoxTableBase(
41 const Reference< XAccessible >& rxParent,
42 vcl::IAccessibleTableProvider& rBrowseBox,
43 AccessibleBrowseBoxObjType eObjType ) :
44 BrowseBoxAccessibleElement( rxParent, rBrowseBox,nullptr, eObjType )
48 // XAccessibleContext ---------------------------------------------------------
50 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleChildCount()
52 SolarMethodGuard aGuard(getMutex());
53 ensureIsAlive();
54 return implGetChildCount();
57 sal_Int16 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRole()
59 osl::MutexGuard aGuard( getMutex() );
60 ensureIsAlive();
61 return AccessibleRole::TABLE;
64 // XAccessibleTable -----------------------------------------------------------
66 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRowCount()
68 SolarMethodGuard aGuard(getMutex());
69 ensureIsAlive();
70 return implGetRowCount();
73 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumnCount()
75 SolarMethodGuard aGuard(getMutex());
76 ensureIsAlive();
77 return implGetColumnCount();
80 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRowExtentAt(
81 sal_Int32 nRow, sal_Int32 nColumn )
83 SolarMethodGuard aGuard(getMutex());
84 ensureIsAlive();
85 ensureIsValidAddress( nRow, nColumn );
86 return 1; // merged cells not supported
89 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumnExtentAt(
90 sal_Int32 nRow, sal_Int32 nColumn )
92 SolarMethodGuard aGuard(getMutex());
93 ensureIsAlive();
94 ensureIsValidAddress( nRow, nColumn );
95 return 1; // merged cells not supported
98 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleCaption()
100 ensureIsAlive();
101 return nullptr; // not supported
104 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleSummary()
106 ensureIsAlive();
107 return nullptr; // not supported
110 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleIndex(
111 sal_Int32 nRow, sal_Int32 nColumn )
113 SolarMethodGuard aGuard(getMutex());
114 ensureIsAlive();
115 ensureIsValidAddress( nRow, nColumn );
116 return nRow * implGetColumnCount() + nColumn;
119 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRow( sal_Int32 nChildIndex )
121 SolarMethodGuard aGuard(getMutex());
122 ensureIsAlive();
123 ensureIsValidIndex( nChildIndex );
124 return implGetRow( nChildIndex );
127 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumn( sal_Int32 nChildIndex )
129 SolarMethodGuard aGuard(getMutex());
130 ensureIsAlive();
131 ensureIsValidIndex( nChildIndex );
132 return implGetColumn( nChildIndex );
135 // XInterface -----------------------------------------------------------------
137 Any SAL_CALL AccessibleBrowseBoxTableBase::queryInterface( const uno::Type& rType )
139 Any aAny( BrowseBoxAccessibleElement::queryInterface( rType ) );
140 return aAny.hasValue() ?
141 aAny : AccessibleBrowseBoxTableImplHelper::queryInterface( rType );
144 void SAL_CALL AccessibleBrowseBoxTableBase::acquire() noexcept
146 BrowseBoxAccessibleElement::acquire();
149 void SAL_CALL AccessibleBrowseBoxTableBase::release() noexcept
151 BrowseBoxAccessibleElement::release();
154 // XTypeProvider --------------------------------------------------------------
156 Sequence< uno::Type > SAL_CALL AccessibleBrowseBoxTableBase::getTypes()
158 return ::comphelper::concatSequences(
159 BrowseBoxAccessibleElement::getTypes(),
160 AccessibleBrowseBoxTableImplHelper::getTypes() );
163 Sequence< sal_Int8 > SAL_CALL AccessibleBrowseBoxTableBase::getImplementationId()
165 return css::uno::Sequence<sal_Int8>();
168 // internal virtual methods ---------------------------------------------------
170 sal_Int32 AccessibleBrowseBoxTableBase::implGetRowCount() const
172 return mpBrowseBox->GetRowCount();
175 sal_Int32 AccessibleBrowseBoxTableBase::implGetColumnCount() const
177 sal_uInt16 nColumns = mpBrowseBox->GetColumnCount();
178 // do not count the "handle column"
179 if( nColumns && implHasHandleColumn() )
180 --nColumns;
181 return nColumns;
184 // internal helper methods ----------------------------------------------------
186 bool AccessibleBrowseBoxTableBase::implHasHandleColumn() const
188 return mpBrowseBox->HasRowHeader();
191 sal_uInt16 AccessibleBrowseBoxTableBase::implToVCLColumnPos( sal_Int32 nColumn ) const
193 sal_uInt16 nVCLPos = 0;
194 if( (0 <= nColumn) && (nColumn < implGetColumnCount()) )
196 // regard "handle column"
197 if( implHasHandleColumn() )
198 ++nColumn;
199 nVCLPos = static_cast< sal_uInt16 >( nColumn );
201 return nVCLPos;
204 sal_Int32 AccessibleBrowseBoxTableBase::implGetChildCount() const
206 return implGetRowCount() * implGetColumnCount();
209 sal_Int32 AccessibleBrowseBoxTableBase::implGetRow( sal_Int32 nChildIndex ) const
211 sal_Int32 nColumns = implGetColumnCount();
212 return nColumns ? (nChildIndex / nColumns) : 0;
215 sal_Int32 AccessibleBrowseBoxTableBase::implGetColumn( sal_Int32 nChildIndex ) const
217 sal_Int32 nColumns = implGetColumnCount();
218 return nColumns ? (nChildIndex % nColumns) : 0;
221 bool AccessibleBrowseBoxTableBase::implIsRowSelected( sal_Int32 nRow ) const
223 return mpBrowseBox->IsRowSelected( nRow );
226 bool AccessibleBrowseBoxTableBase::implIsColumnSelected( sal_Int32 nColumn ) const
228 if( implHasHandleColumn() )
229 --nColumn;
230 return mpBrowseBox->IsColumnSelected( nColumn );
233 void AccessibleBrowseBoxTableBase::implSelectRow( sal_Int32 nRow, bool bSelect )
235 mpBrowseBox->SelectRow( nRow, bSelect );
238 void AccessibleBrowseBoxTableBase::implSelectColumn( sal_Int32 nColumnPos, bool bSelect )
240 mpBrowseBox->SelectColumn( static_cast<sal_uInt16>(nColumnPos), bSelect );
243 sal_Int32 AccessibleBrowseBoxTableBase::implGetSelectedRowCount() const
245 return mpBrowseBox->GetSelectedRowCount();
248 sal_Int32 AccessibleBrowseBoxTableBase::implGetSelectedColumnCount() const
250 return mpBrowseBox->GetSelectedColumnCount();
253 void AccessibleBrowseBoxTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq )
255 mpBrowseBox->GetAllSelectedRows( rSeq );
258 void AccessibleBrowseBoxTableBase::implGetSelectedColumns( Sequence< sal_Int32 >& rSeq )
260 mpBrowseBox->GetAllSelectedColumns( rSeq );
263 void AccessibleBrowseBoxTableBase::ensureIsValidRow( sal_Int32 nRow )
265 if( nRow >= implGetRowCount() )
266 throw lang::IndexOutOfBoundsException( "row index is invalid", *this );
269 void AccessibleBrowseBoxTableBase::ensureIsValidColumn( sal_Int32 nColumn )
271 if( nColumn >= implGetColumnCount() )
272 throw lang::IndexOutOfBoundsException( "column index is invalid", *this );
275 void AccessibleBrowseBoxTableBase::ensureIsValidAddress(
276 sal_Int32 nRow, sal_Int32 nColumn )
278 ensureIsValidRow( nRow );
279 ensureIsValidColumn( nColumn );
282 void AccessibleBrowseBoxTableBase::ensureIsValidIndex( sal_Int32 nChildIndex )
284 if( nChildIndex >= implGetChildCount() )
285 throw lang::IndexOutOfBoundsException( "child index is invalid", *this );
289 } // namespace accessibility
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */