lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBoxHeaderBar.cxx
blob15ba28a03a5233db2b89450d42b57681727bb0ab
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 <vcl/accessibletableprovider.hxx>
23 using ::com::sun::star::uno::Reference;
24 using ::com::sun::star::uno::Sequence;
25 using ::com::sun::star::uno::Any;
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::accessibility;
29 using namespace ::svt;
32 namespace accessibility {
35 // Ctor/Dtor/disposing --------------------------------------------------------
37 AccessibleBrowseBoxHeaderBar::AccessibleBrowseBoxHeaderBar(
38 const Reference< XAccessible >& rxParent,
39 vcl::IAccessibleTableProvider& rBrowseBox,
40 vcl::AccessibleBrowseBoxObjType eObjType ) :
41 AccessibleBrowseBoxTableBase( rxParent, rBrowseBox,eObjType )
43 OSL_ENSURE( isRowBar() || isColumnBar(),
44 "extended/AccessibleBrowseBoxHeaderBar - invalid object type" );
47 AccessibleBrowseBoxHeaderBar::~AccessibleBrowseBoxHeaderBar()
51 // XAccessibleContext ---------------------------------------------------------
53 Reference< XAccessible > SAL_CALL
54 AccessibleBrowseBoxHeaderBar::getAccessibleChild( sal_Int32 nChildIndex )
56 SolarMethodGuard aGuard(getMutex());
57 ensureIsAlive();
59 ensureIsValidHeaderIndex( nChildIndex );
60 return implGetChild( nChildIndex, implToVCLColumnPos( nChildIndex ) );
63 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleIndexInParent()
65 return isRowBar() ? vcl::BBINDEX_ROWHEADERBAR : vcl::BBINDEX_COLUMNHEADERBAR;
68 // XAccessibleComponent -------------------------------------------------------
70 Reference< XAccessible > SAL_CALL
71 AccessibleBrowseBoxHeaderBar::getAccessibleAtPoint( const awt::Point& rPoint )
73 SolarMethodGuard aGuard(getMutex());
74 ensureIsAlive();
76 sal_Int32 nRow = 0;
77 sal_uInt16 nColumnPos = 0;
78 bool bConverted = isRowBar() ?
79 mpBrowseBox->ConvertPointToRowHeader( nRow, VCLPoint( rPoint ) ) :
80 mpBrowseBox->ConvertPointToColumnHeader( nColumnPos, VCLPoint( rPoint ) );
82 return bConverted ? implGetChild( nRow, nColumnPos ) : Reference< XAccessible >();
85 void SAL_CALL AccessibleBrowseBoxHeaderBar::grabFocus()
87 SolarMethodGuard aGuard(getMutex());
89 ensureIsAlive();
90 // focus on header not supported
93 // XAccessibleTable -----------------------------------------------------------
95 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowDescription( sal_Int32 nRow )
97 SolarMethodGuard aGuard(getMutex());
99 ensureIsAlive();
100 ensureIsValidRow( nRow );
101 return OUString(); // no headers in headers
104 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnDescription( sal_Int32 nColumn )
106 SolarMethodGuard aGuard(getMutex());
108 ensureIsAlive();
109 ensureIsValidColumn( nColumn );
110 return OUString(); // no headers in headers
113 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowHeaders()
115 SolarMethodGuard aGuard(getMutex());
117 ensureIsAlive();
118 return nullptr; // no headers in headers
121 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnHeaders()
123 SolarMethodGuard aGuard(getMutex());
125 ensureIsAlive();
126 return nullptr; // no headers in headers
129 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleRows()
131 SolarMethodGuard aGuard(getMutex());
132 ensureIsAlive();
134 Sequence< sal_Int32 > aSelSeq;
135 // row of column header bar not selectable
136 if( isRowBar() )
137 implGetSelectedRows( aSelSeq );
138 return aSelSeq;
141 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleColumns()
143 SolarMethodGuard aGuard(getMutex());
144 ensureIsAlive();
146 Sequence< sal_Int32 > aSelSeq;
147 // column of row header bar ("handle column") not selectable
148 if( isColumnBar() )
149 implGetSelectedColumns( aSelSeq );
150 return aSelSeq;
153 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleRowSelected( sal_Int32 nRow )
155 SolarMethodGuard aGuard(getMutex());
157 ensureIsAlive();
158 ensureIsValidRow( nRow );
159 return isRowBar() && implIsRowSelected( nRow );
162 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleColumnSelected( sal_Int32 nColumn )
164 SolarMethodGuard aGuard(getMutex());
166 ensureIsAlive();
167 ensureIsValidColumn( nColumn );
168 return isColumnBar() && implIsColumnSelected( nColumn );
171 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleCellAt(
172 sal_Int32 nRow, sal_Int32 nColumn )
174 SolarMethodGuard aGuard(getMutex());
176 ensureIsAlive();
177 ensureIsValidAddress( nRow, nColumn );
179 return implGetChild( nRow, implToVCLColumnPos( nColumn ) );
182 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleSelected(
183 sal_Int32 nRow, sal_Int32 nColumn )
185 SolarMethodGuard aGuard(getMutex());
186 ensureIsAlive();
188 ensureIsValidAddress( nRow, nColumn );
189 return isRowBar() ? implIsRowSelected( nRow ) : implIsColumnSelected( nColumn );
192 // XAccessibleSelection -------------------------------------------------------
194 void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAccessibleChild( sal_Int32 nChildIndex )
196 SolarMethodGuard aGuard(getMutex());
197 ensureIsAlive();
199 ensureIsValidHeaderIndex( nChildIndex );
200 if( isRowBar() )
201 implSelectRow( nChildIndex, true );
202 else
203 implSelectColumn( implToVCLColumnPos( nChildIndex ), true );
206 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleChildSelected( sal_Int32 nChildIndex )
208 // using interface methods - no mutex
209 return isRowBar() ?
210 isAccessibleRowSelected( nChildIndex ) :
211 isAccessibleColumnSelected( nChildIndex );
214 void SAL_CALL AccessibleBrowseBoxHeaderBar::clearAccessibleSelection()
216 SolarMethodGuard aGuard(getMutex());
217 ensureIsAlive();
219 mpBrowseBox->SetNoSelection();
222 void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAllAccessibleChildren()
224 SolarMethodGuard aGuard(getMutex());
225 ensureIsAlive();
227 // no multiselection of columns possible
228 if( isRowBar() )
229 mpBrowseBox->SelectAll();
230 else
231 implSelectColumn( implToVCLColumnPos( 0 ), true );
234 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChildCount()
236 SolarMethodGuard aGuard(getMutex());
237 ensureIsAlive();
239 return isRowBar() ? implGetSelectedRowCount() : implGetSelectedColumnCount();
242 Reference< XAccessible > SAL_CALL
243 AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
245 SolarMethodGuard aGuard(getMutex());
246 ensureIsAlive();
248 // method may throw lang::IndexOutOfBoundsException
249 sal_Int32 nIndex = implGetChildIndexFromSelectedIndex( nSelectedChildIndex );
250 return implGetChild( nIndex, implToVCLColumnPos( nIndex ) );
253 void SAL_CALL AccessibleBrowseBoxHeaderBar::deselectAccessibleChild(
254 sal_Int32 nSelectedChildIndex )
256 SolarMethodGuard aGuard(getMutex());
257 ensureIsAlive();
259 // method may throw lang::IndexOutOfBoundsException
260 if ( isAccessibleChildSelected(nSelectedChildIndex) )
262 if( isRowBar() )
263 implSelectRow( nSelectedChildIndex, false );
264 else
265 implSelectColumn( implToVCLColumnPos( nSelectedChildIndex ), false );
269 // XInterface -----------------------------------------------------------------
271 Any SAL_CALL AccessibleBrowseBoxHeaderBar::queryInterface( const uno::Type& rType )
273 Any aAny( AccessibleBrowseBoxTableBase::queryInterface( rType ) );
274 return aAny.hasValue() ?
275 aAny : AccessibleBrowseBoxHeaderBarImplHelper::queryInterface( rType );
278 void SAL_CALL AccessibleBrowseBoxHeaderBar::acquire() throw ()
280 AccessibleBrowseBoxTableBase::acquire();
283 void SAL_CALL AccessibleBrowseBoxHeaderBar::release() throw ()
285 AccessibleBrowseBoxTableBase::release();
288 // XServiceInfo ---------------------------------------------------------------
290 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getImplementationName()
292 return OUString( "com.sun.star.comp.svtools.AccessibleBrowseBoxHeaderBar" );
295 Sequence< sal_Int8 > SAL_CALL AccessibleBrowseBoxHeaderBar::getImplementationId()
297 return css::uno::Sequence<sal_Int8>();
300 // internal virtual methods ---------------------------------------------------
302 tools::Rectangle AccessibleBrowseBoxHeaderBar::implGetBoundingBox()
304 return mpBrowseBox->calcHeaderRect(isColumnBar(), false);
307 tools::Rectangle AccessibleBrowseBoxHeaderBar::implGetBoundingBoxOnScreen()
309 return mpBrowseBox->calcHeaderRect(isColumnBar());
312 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetRowCount() const
314 // column header bar: only 1 row
315 return isRowBar() ? AccessibleBrowseBoxTableBase::implGetRowCount() : 1;
318 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetColumnCount() const
320 // row header bar ("handle column"): only 1 column
321 return isColumnBar() ? AccessibleBrowseBoxTableBase::implGetColumnCount() : 1;
324 // internal helper methods ----------------------------------------------------
326 Reference< XAccessible > AccessibleBrowseBoxHeaderBar::implGetChild(
327 sal_Int32 nRow, sal_uInt16 nColumnPos )
329 return isRowBar() ?
330 mpBrowseBox->CreateAccessibleRowHeader( nRow ) :
331 mpBrowseBox->CreateAccessibleColumnHeader( nColumnPos );
334 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetChildIndexFromSelectedIndex(
335 sal_Int32 nSelectedChildIndex )
337 Sequence< sal_Int32 > aSelSeq;
338 if( isRowBar() )
339 implGetSelectedRows( aSelSeq );
340 else
341 implGetSelectedColumns( aSelSeq );
343 if( (nSelectedChildIndex < 0) || (nSelectedChildIndex >= aSelSeq.getLength()) )
344 throw lang::IndexOutOfBoundsException();
346 return aSelSeq[ nSelectedChildIndex ];
349 void AccessibleBrowseBoxHeaderBar::ensureIsValidHeaderIndex( sal_Int32 nIndex )
351 if( isRowBar() )
352 ensureIsValidRow( nIndex );
353 else
354 ensureIsValidColumn( nIndex );
358 } // namespace accessibility
361 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */