LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBoxHeaderBar.cxx
blob3d3541e4a19b5d55bcefe54579c0d5ffe2d1f7ae
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/AccessibleBrowseBoxHeaderBar.hxx>
21 #include <toolkit/helper/convert.hxx>
22 #include <vcl/accessibletableprovider.hxx>
23 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
25 using ::com::sun::star::uno::Reference;
26 using ::com::sun::star::uno::Sequence;
27 using ::com::sun::star::uno::Any;
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::accessibility;
33 namespace accessibility {
36 // Ctor/Dtor/disposing --------------------------------------------------------
38 AccessibleBrowseBoxHeaderBar::AccessibleBrowseBoxHeaderBar(
39 const Reference< XAccessible >& rxParent,
40 vcl::IAccessibleTableProvider& rBrowseBox,
41 AccessibleBrowseBoxObjType eObjType ) :
42 AccessibleBrowseBoxTableBase( rxParent, rBrowseBox,eObjType )
44 OSL_ENSURE( isRowBar() || isColumnBar(),
45 "extended/AccessibleBrowseBoxHeaderBar - invalid object type" );
48 AccessibleBrowseBoxHeaderBar::~AccessibleBrowseBoxHeaderBar()
52 // XAccessibleContext ---------------------------------------------------------
54 Reference< XAccessible > SAL_CALL
55 AccessibleBrowseBoxHeaderBar::getAccessibleChild( sal_Int32 nChildIndex )
57 SolarMethodGuard aGuard(getMutex());
58 ensureIsAlive();
60 ensureIsValidHeaderIndex( nChildIndex );
61 return implGetChild( nChildIndex, implToVCLColumnPos( nChildIndex ) );
64 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleIndexInParent()
66 return isRowBar() ? vcl::BBINDEX_ROWHEADERBAR : vcl::BBINDEX_COLUMNHEADERBAR;
69 // XAccessibleComponent -------------------------------------------------------
71 Reference< XAccessible > SAL_CALL
72 AccessibleBrowseBoxHeaderBar::getAccessibleAtPoint( const awt::Point& rPoint )
74 SolarMethodGuard aGuard(getMutex());
75 ensureIsAlive();
77 sal_Int32 nRow = 0;
78 sal_uInt16 nColumnPos = 0;
79 bool bConverted = isRowBar() ?
80 mpBrowseBox->ConvertPointToRowHeader( nRow, VCLPoint( rPoint ) ) :
81 mpBrowseBox->ConvertPointToColumnHeader( nColumnPos, VCLPoint( rPoint ) );
83 return bConverted ? implGetChild( nRow, nColumnPos ) : Reference< XAccessible >();
86 void SAL_CALL AccessibleBrowseBoxHeaderBar::grabFocus()
88 SolarMethodGuard aGuard(getMutex());
90 ensureIsAlive();
91 // focus on header not supported
94 // XAccessibleTable -----------------------------------------------------------
96 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowDescription( sal_Int32 nRow )
98 SolarMethodGuard aGuard(getMutex());
100 ensureIsAlive();
101 ensureIsValidRow( nRow );
102 return OUString(); // no headers in headers
105 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnDescription( sal_Int32 nColumn )
107 SolarMethodGuard aGuard(getMutex());
109 ensureIsAlive();
110 ensureIsValidColumn( nColumn );
111 return OUString(); // no headers in headers
114 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowHeaders()
116 SolarMethodGuard aGuard(getMutex());
118 ensureIsAlive();
119 return nullptr; // no headers in headers
122 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnHeaders()
124 SolarMethodGuard aGuard(getMutex());
126 ensureIsAlive();
127 return nullptr; // no headers in headers
130 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleRows()
132 SolarMethodGuard aGuard(getMutex());
133 ensureIsAlive();
135 Sequence< sal_Int32 > aSelSeq;
136 // row of column header bar not selectable
137 if( isRowBar() )
138 implGetSelectedRows( aSelSeq );
139 return aSelSeq;
142 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleColumns()
144 SolarMethodGuard aGuard(getMutex());
145 ensureIsAlive();
147 Sequence< sal_Int32 > aSelSeq;
148 // column of row header bar ("handle column") not selectable
149 if( isColumnBar() )
150 implGetSelectedColumns( aSelSeq );
151 return aSelSeq;
154 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleRowSelected( sal_Int32 nRow )
156 SolarMethodGuard aGuard(getMutex());
158 ensureIsAlive();
159 ensureIsValidRow( nRow );
160 return isRowBar() && implIsRowSelected( nRow );
163 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleColumnSelected( sal_Int32 nColumn )
165 SolarMethodGuard aGuard(getMutex());
167 ensureIsAlive();
168 ensureIsValidColumn( nColumn );
169 return isColumnBar() && implIsColumnSelected( nColumn );
172 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleCellAt(
173 sal_Int32 nRow, sal_Int32 nColumn )
175 SolarMethodGuard aGuard(getMutex());
177 ensureIsAlive();
178 ensureIsValidAddress( nRow, nColumn );
180 return implGetChild( nRow, implToVCLColumnPos( nColumn ) );
183 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleSelected(
184 sal_Int32 nRow, sal_Int32 nColumn )
186 SolarMethodGuard aGuard(getMutex());
187 ensureIsAlive();
189 ensureIsValidAddress( nRow, nColumn );
190 return isRowBar() ? implIsRowSelected( nRow ) : implIsColumnSelected( nColumn );
193 // XAccessibleSelection -------------------------------------------------------
195 void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAccessibleChild( sal_Int32 nChildIndex )
197 SolarMethodGuard aGuard(getMutex());
198 ensureIsAlive();
200 ensureIsValidHeaderIndex( nChildIndex );
201 if( isRowBar() )
202 implSelectRow( nChildIndex, true );
203 else
204 implSelectColumn( implToVCLColumnPos( nChildIndex ), true );
207 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleChildSelected( sal_Int32 nChildIndex )
209 // using interface methods - no mutex
210 return isRowBar() ?
211 isAccessibleRowSelected( nChildIndex ) :
212 isAccessibleColumnSelected( nChildIndex );
215 void SAL_CALL AccessibleBrowseBoxHeaderBar::clearAccessibleSelection()
217 SolarMethodGuard aGuard(getMutex());
218 ensureIsAlive();
220 mpBrowseBox->SetNoSelection();
223 void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAllAccessibleChildren()
225 SolarMethodGuard aGuard(getMutex());
226 ensureIsAlive();
228 // no multiselection of columns possible
229 if( isRowBar() )
230 mpBrowseBox->SelectAll();
231 else
232 implSelectColumn( implToVCLColumnPos( 0 ), true );
235 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChildCount()
237 SolarMethodGuard aGuard(getMutex());
238 ensureIsAlive();
240 return isRowBar() ? implGetSelectedRowCount() : implGetSelectedColumnCount();
243 Reference< XAccessible > SAL_CALL
244 AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
246 SolarMethodGuard aGuard(getMutex());
247 ensureIsAlive();
249 // method may throw lang::IndexOutOfBoundsException
250 sal_Int32 nIndex = implGetChildIndexFromSelectedIndex( nSelectedChildIndex );
251 return implGetChild( nIndex, implToVCLColumnPos( nIndex ) );
254 void SAL_CALL AccessibleBrowseBoxHeaderBar::deselectAccessibleChild(
255 sal_Int32 nSelectedChildIndex )
257 SolarMethodGuard aGuard(getMutex());
258 ensureIsAlive();
260 // method may throw lang::IndexOutOfBoundsException
261 if ( isAccessibleChildSelected(nSelectedChildIndex) )
263 if( isRowBar() )
264 implSelectRow( nSelectedChildIndex, false );
265 else
266 implSelectColumn( implToVCLColumnPos( nSelectedChildIndex ), false );
270 // XInterface -----------------------------------------------------------------
272 Any SAL_CALL AccessibleBrowseBoxHeaderBar::queryInterface( const uno::Type& rType )
274 Any aAny( AccessibleBrowseBoxTableBase::queryInterface( rType ) );
275 return aAny.hasValue() ?
276 aAny : AccessibleBrowseBoxHeaderBarImplHelper::queryInterface( rType );
279 void SAL_CALL AccessibleBrowseBoxHeaderBar::acquire() noexcept
281 AccessibleBrowseBoxTableBase::acquire();
284 void SAL_CALL AccessibleBrowseBoxHeaderBar::release() noexcept
286 AccessibleBrowseBoxTableBase::release();
289 // XServiceInfo ---------------------------------------------------------------
291 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getImplementationName()
293 return "com.sun.star.comp.svtools.AccessibleBrowseBoxHeaderBar";
296 Sequence< sal_Int8 > SAL_CALL AccessibleBrowseBoxHeaderBar::getImplementationId()
298 return css::uno::Sequence<sal_Int8>();
301 // internal virtual methods ---------------------------------------------------
303 tools::Rectangle AccessibleBrowseBoxHeaderBar::implGetBoundingBox()
305 return mpBrowseBox->calcHeaderRect(isColumnBar(), false);
308 tools::Rectangle AccessibleBrowseBoxHeaderBar::implGetBoundingBoxOnScreen()
310 return mpBrowseBox->calcHeaderRect(isColumnBar());
313 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetRowCount() const
315 // column header bar: only 1 row
316 return isRowBar() ? AccessibleBrowseBoxTableBase::implGetRowCount() : 1;
319 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetColumnCount() const
321 // row header bar ("handle column"): only 1 column
322 return isColumnBar() ? AccessibleBrowseBoxTableBase::implGetColumnCount() : 1;
325 // internal helper methods ----------------------------------------------------
327 Reference< XAccessible > AccessibleBrowseBoxHeaderBar::implGetChild(
328 sal_Int32 nRow, sal_uInt16 nColumnPos )
330 return isRowBar() ?
331 mpBrowseBox->CreateAccessibleRowHeader( nRow ) :
332 mpBrowseBox->CreateAccessibleColumnHeader( nColumnPos );
335 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetChildIndexFromSelectedIndex(
336 sal_Int32 nSelectedChildIndex )
338 Sequence< sal_Int32 > aSelSeq;
339 if( isRowBar() )
340 implGetSelectedRows( aSelSeq );
341 else
342 implGetSelectedColumns( aSelSeq );
344 if( (nSelectedChildIndex < 0) || (nSelectedChildIndex >= aSelSeq.getLength()) )
345 throw lang::IndexOutOfBoundsException();
347 return aSelSeq.getConstArray()[ nSelectedChildIndex ];
350 void AccessibleBrowseBoxHeaderBar::ensureIsValidHeaderIndex( sal_Int32 nIndex )
352 if( isRowBar() )
353 ensureIsValidRow( nIndex );
354 else
355 ensureIsValidColumn( nIndex );
359 } // namespace accessibility
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */