Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBoxHeaderBar.cxx
blobc446f1d6ca939ca7845724902cc76ba882de5e55
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 "accessibility/extended/AccessibleBrowseBoxHeaderBar.hxx"
21 #include <svtools/accessibletableprovider.hxx>
22 #include <comphelper/servicehelper.hxx>
26 using ::com::sun::star::uno::Reference;
27 using ::com::sun::star::uno::Sequence;
28 using ::com::sun::star::uno::Any;
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::accessibility;
32 using namespace ::svt;
36 namespace accessibility {
40 // Ctor/Dtor/disposing --------------------------------------------------------
42 AccessibleBrowseBoxHeaderBar::AccessibleBrowseBoxHeaderBar(
43 const Reference< XAccessible >& rxParent,
44 IAccessibleTableProvider& rBrowseBox,
45 AccessibleBrowseBoxObjType eObjType ) :
46 AccessibleBrowseBoxTableBase( rxParent, rBrowseBox,eObjType )
48 OSL_ENSURE( isRowBar() || isColumnBar(),
49 "accessibility/extended/AccessibleBrowseBoxHeaderBar - invalid object type" );
52 AccessibleBrowseBoxHeaderBar::~AccessibleBrowseBoxHeaderBar()
56 // XAccessibleContext ---------------------------------------------------------
58 Reference< XAccessible > SAL_CALL
59 AccessibleBrowseBoxHeaderBar::getAccessibleChild( sal_Int32 nChildIndex )
60 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
62 SolarMutexGuard aSolarGuard;
63 ::osl::MutexGuard aGuard( getOslMutex() );
64 ensureIsAlive();
65 ensureIsValidHeaderIndex( nChildIndex );
66 return implGetChild( nChildIndex, implToVCLColumnPos( nChildIndex ) );
69 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleIndexInParent()
70 throw ( uno::RuntimeException, std::exception )
72 return isRowBar() ? BBINDEX_ROWHEADERBAR : BBINDEX_COLUMNHEADERBAR;
75 // XAccessibleComponent -------------------------------------------------------
77 Reference< XAccessible > SAL_CALL
78 AccessibleBrowseBoxHeaderBar::getAccessibleAtPoint( const awt::Point& rPoint )
79 throw ( uno::RuntimeException, std::exception )
81 SolarMutexGuard aSolarGuard;
82 ::osl::MutexGuard aGuard( getOslMutex() );
83 ensureIsAlive();
85 sal_Int32 nRow = 0;
86 sal_uInt16 nColumnPos = 0;
87 bool bConverted = isRowBar() ?
88 mpBrowseBox->ConvertPointToRowHeader( nRow, VCLPoint( rPoint ) ) :
89 mpBrowseBox->ConvertPointToColumnHeader( nColumnPos, VCLPoint( rPoint ) );
91 return bConverted ? implGetChild( nRow, nColumnPos ) : Reference< XAccessible >();
94 void SAL_CALL AccessibleBrowseBoxHeaderBar::grabFocus()
95 throw ( uno::RuntimeException, std::exception )
97 ensureIsAlive();
98 // focus on header not supported
101 // XAccessibleTable -----------------------------------------------------------
103 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowDescription( sal_Int32 nRow )
104 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
106 SolarMutexGuard aSolarGuard;
107 ::osl::MutexGuard aGuard( getOslMutex() );
108 ensureIsAlive();
109 ensureIsValidRow( nRow );
110 return OUString(); // no headers in headers
113 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnDescription( sal_Int32 nColumn )
114 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
116 SolarMutexGuard aSolarGuard;
117 ::osl::MutexGuard aGuard( getOslMutex() );
118 ensureIsAlive();
119 ensureIsValidColumn( nColumn );
120 return OUString(); // no headers in headers
123 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowHeaders()
124 throw ( uno::RuntimeException, std::exception )
126 ensureIsAlive();
127 return NULL; // no headers in headers
130 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnHeaders()
131 throw ( uno::RuntimeException, std::exception )
133 ensureIsAlive();
134 return NULL; // no headers in headers
137 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleRows()
138 throw ( uno::RuntimeException, std::exception )
140 SolarMutexGuard aSolarGuard;
141 ::osl::MutexGuard aGuard( getOslMutex() );
142 ensureIsAlive();
144 Sequence< sal_Int32 > aSelSeq;
145 // row of column header bar not selectable
146 if( isRowBar() )
147 implGetSelectedRows( aSelSeq );
148 return aSelSeq;
151 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleColumns()
152 throw ( uno::RuntimeException, std::exception )
154 SolarMutexGuard aSolarGuard;
155 ::osl::MutexGuard aGuard( getOslMutex() );
156 ensureIsAlive();
158 Sequence< sal_Int32 > aSelSeq;
159 // column of row header bar ("handle column") not selectable
160 if( isColumnBar() )
161 implGetSelectedColumns( aSelSeq );
162 return aSelSeq;
165 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleRowSelected( sal_Int32 nRow )
166 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
168 SolarMutexGuard aSolarGuard;
169 ::osl::MutexGuard aGuard( getOslMutex() );
170 ensureIsAlive();
171 ensureIsValidRow( nRow );
172 return isRowBar() && implIsRowSelected( nRow );
175 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleColumnSelected( sal_Int32 nColumn )
176 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
178 SolarMutexGuard aSolarGuard;
179 ::osl::MutexGuard aGuard( getOslMutex() );
180 ensureIsAlive();
181 ensureIsValidColumn( nColumn );
182 return isColumnBar() && implIsColumnSelected( nColumn );
185 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleCellAt(
186 sal_Int32 nRow, sal_Int32 nColumn )
187 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
189 SolarMutexGuard aSolarGuard;
190 ::osl::MutexGuard aGuard( getOslMutex() );
191 ensureIsAlive();
192 ensureIsValidAddress( nRow, nColumn );
193 return implGetChild( nRow, implToVCLColumnPos( nColumn ) );
196 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleSelected(
197 sal_Int32 nRow, sal_Int32 nColumn )
198 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
200 SolarMutexGuard aSolarGuard;
201 ::osl::MutexGuard aGuard( getOslMutex() );
202 ensureIsAlive();
203 ensureIsValidAddress( nRow, nColumn );
204 return isRowBar() ? implIsRowSelected( nRow ) : implIsColumnSelected( nColumn );
207 // XAccessibleSelection -------------------------------------------------------
209 void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAccessibleChild( sal_Int32 nChildIndex )
210 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
212 SolarMutexGuard aSolarGuard;
213 ::osl::MutexGuard aGuard( getOslMutex() );
214 ensureIsAlive();
215 ensureIsValidHeaderIndex( nChildIndex );
216 if( isRowBar() )
217 implSelectRow( nChildIndex, true );
218 else
219 implSelectColumn( implToVCLColumnPos( nChildIndex ), true );
222 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleChildSelected( sal_Int32 nChildIndex )
223 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
225 // using interface methods - no mutex
226 return isRowBar() ?
227 isAccessibleRowSelected( nChildIndex ) :
228 isAccessibleColumnSelected( nChildIndex );
231 void SAL_CALL AccessibleBrowseBoxHeaderBar::clearAccessibleSelection()
232 throw ( uno::RuntimeException, std::exception )
234 SolarMutexGuard aSolarGuard;
235 ::osl::MutexGuard aGuard( getOslMutex() );
236 ensureIsAlive();
237 mpBrowseBox->SetNoSelection();
240 void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAllAccessibleChildren()
241 throw ( uno::RuntimeException, std::exception )
243 SolarMutexGuard aSolarGuard;
244 ::osl::MutexGuard aGuard( getOslMutex() );
245 ensureIsAlive();
246 // no multiselection of columns possible
247 if( isRowBar() )
248 mpBrowseBox->SelectAll();
249 else
250 implSelectColumn( implToVCLColumnPos( 0 ), true );
253 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChildCount()
254 throw ( uno::RuntimeException, std::exception )
256 SolarMutexGuard aSolarGuard;
257 ::osl::MutexGuard aGuard( getOslMutex() );
258 ensureIsAlive();
259 return isRowBar() ? implGetSelectedRowCount() : implGetSelectedColumnCount();
262 Reference< XAccessible > SAL_CALL
263 AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
264 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
266 SolarMutexGuard aSolarGuard;
267 ::osl::MutexGuard aGuard( getOslMutex() );
268 ensureIsAlive();
270 // method may throw lang::IndexOutOfBoundsException
271 sal_Int32 nIndex = implGetChildIndexFromSelectedIndex( nSelectedChildIndex );
272 return implGetChild( nIndex, implToVCLColumnPos( nIndex ) );
275 void SAL_CALL AccessibleBrowseBoxHeaderBar::deselectAccessibleChild(
276 sal_Int32 nSelectedChildIndex )
277 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
279 SolarMutexGuard aSolarGuard;
280 ::osl::MutexGuard aGuard( getOslMutex() );
281 ensureIsAlive();
283 // method may throw lang::IndexOutOfBoundsException
284 if ( isAccessibleChildSelected(nSelectedChildIndex) )
286 if( isRowBar() )
287 implSelectRow( nSelectedChildIndex, false );
288 else
289 implSelectColumn( implToVCLColumnPos( nSelectedChildIndex ), false );
293 // XInterface -----------------------------------------------------------------
295 Any SAL_CALL AccessibleBrowseBoxHeaderBar::queryInterface( const uno::Type& rType )
296 throw ( uno::RuntimeException, std::exception )
298 Any aAny( AccessibleBrowseBoxTableBase::queryInterface( rType ) );
299 return aAny.hasValue() ?
300 aAny : AccessibleBrowseBoxHeaderBarImplHelper::queryInterface( rType );
303 void SAL_CALL AccessibleBrowseBoxHeaderBar::acquire() throw ()
305 AccessibleBrowseBoxTableBase::acquire();
308 void SAL_CALL AccessibleBrowseBoxHeaderBar::release() throw ()
310 AccessibleBrowseBoxTableBase::release();
313 // XServiceInfo ---------------------------------------------------------------
315 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getImplementationName()
316 throw ( uno::RuntimeException, std::exception )
318 return OUString( "com.sun.star.comp.svtools.AccessibleBrowseBoxHeaderBar" );
321 Sequence< sal_Int8 > SAL_CALL AccessibleBrowseBoxHeaderBar::getImplementationId()
322 throw ( uno::RuntimeException, std::exception )
324 return css::uno::Sequence<sal_Int8>();
327 // internal virtual methods ---------------------------------------------------
329 Rectangle AccessibleBrowseBoxHeaderBar::implGetBoundingBox()
331 return mpBrowseBox->calcHeaderRect(isColumnBar(), false);
334 Rectangle AccessibleBrowseBoxHeaderBar::implGetBoundingBoxOnScreen()
336 return mpBrowseBox->calcHeaderRect(isColumnBar(), true);
339 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetRowCount() const
341 // column header bar: only 1 row
342 return isRowBar() ? AccessibleBrowseBoxTableBase::implGetRowCount() : 1;
345 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetColumnCount() const
347 // row header bar ("handle column"): only 1 column
348 return isColumnBar() ? AccessibleBrowseBoxTableBase::implGetColumnCount() : 1;
351 // internal helper methods ----------------------------------------------------
353 Reference< XAccessible > AccessibleBrowseBoxHeaderBar::implGetChild(
354 sal_Int32 nRow, sal_uInt16 nColumnPos )
356 return isRowBar() ?
357 mpBrowseBox->CreateAccessibleRowHeader( nRow ) :
358 mpBrowseBox->CreateAccessibleColumnHeader( nColumnPos );
361 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetChildIndexFromSelectedIndex(
362 sal_Int32 nSelectedChildIndex )
363 throw ( lang::IndexOutOfBoundsException )
365 Sequence< sal_Int32 > aSelSeq;
366 if( isRowBar() )
367 implGetSelectedRows( aSelSeq );
368 else
369 implGetSelectedColumns( aSelSeq );
371 if( (nSelectedChildIndex < 0) || (nSelectedChildIndex >= aSelSeq.getLength()) )
372 throw lang::IndexOutOfBoundsException();
374 return aSelSeq[ nSelectedChildIndex ];
377 void AccessibleBrowseBoxHeaderBar::ensureIsValidHeaderIndex( sal_Int32 nIndex )
378 throw ( lang::IndexOutOfBoundsException )
380 if( isRowBar() )
381 ensureIsValidRow( nIndex );
382 else
383 ensureIsValidColumn( nIndex );
388 } // namespace accessibility
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */