Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBoxHeaderBar.cxx
blobf5703766399c8282a902bb07fc8cbb38a2ce00af
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>
24 // ============================================================================
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;
34 // ============================================================================
36 namespace accessibility {
38 // ============================================================================
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 )
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 )
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 )
81 SolarMutexGuard aSolarGuard;
82 ::osl::MutexGuard aGuard( getOslMutex() );
83 ensureIsAlive();
85 sal_Int32 nRow = 0;
86 sal_uInt16 nColumnPos = 0;
87 sal_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 )
97 ensureIsAlive();
98 // focus on header not supported
101 Any SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleKeyBinding()
102 throw ( uno::RuntimeException )
104 ensureIsAlive();
105 return Any(); // no special key bindings for header
108 // XAccessibleTable -----------------------------------------------------------
110 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowDescription( sal_Int32 nRow )
111 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
113 SolarMutexGuard aSolarGuard;
114 ::osl::MutexGuard aGuard( getOslMutex() );
115 ensureIsAlive();
116 ensureIsValidRow( nRow );
117 return OUString(); // no headers in headers
120 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnDescription( sal_Int32 nColumn )
121 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
123 SolarMutexGuard aSolarGuard;
124 ::osl::MutexGuard aGuard( getOslMutex() );
125 ensureIsAlive();
126 ensureIsValidColumn( nColumn );
127 return OUString(); // no headers in headers
130 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowHeaders()
131 throw ( uno::RuntimeException )
133 ensureIsAlive();
134 return NULL; // no headers in headers
137 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnHeaders()
138 throw ( uno::RuntimeException )
140 ensureIsAlive();
141 return NULL; // no headers in headers
144 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleRows()
145 throw ( uno::RuntimeException )
147 SolarMutexGuard aSolarGuard;
148 ::osl::MutexGuard aGuard( getOslMutex() );
149 ensureIsAlive();
151 Sequence< sal_Int32 > aSelSeq;
152 // row of column header bar not selectable
153 if( isRowBar() )
154 implGetSelectedRows( aSelSeq );
155 return aSelSeq;
158 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleColumns()
159 throw ( uno::RuntimeException )
161 SolarMutexGuard aSolarGuard;
162 ::osl::MutexGuard aGuard( getOslMutex() );
163 ensureIsAlive();
165 Sequence< sal_Int32 > aSelSeq;
166 // column of row header bar ("handle column") not selectable
167 if( isColumnBar() )
168 implGetSelectedColumns( aSelSeq );
169 return aSelSeq;
172 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleRowSelected( sal_Int32 nRow )
173 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
175 SolarMutexGuard aSolarGuard;
176 ::osl::MutexGuard aGuard( getOslMutex() );
177 ensureIsAlive();
178 ensureIsValidRow( nRow );
179 return isRowBar() ? implIsRowSelected( nRow ) : sal_False;
182 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleColumnSelected( sal_Int32 nColumn )
183 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
185 SolarMutexGuard aSolarGuard;
186 ::osl::MutexGuard aGuard( getOslMutex() );
187 ensureIsAlive();
188 ensureIsValidColumn( nColumn );
189 return isColumnBar() ? implIsColumnSelected( nColumn ) : sal_False;
192 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleCellAt(
193 sal_Int32 nRow, sal_Int32 nColumn )
194 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
196 SolarMutexGuard aSolarGuard;
197 ::osl::MutexGuard aGuard( getOslMutex() );
198 ensureIsAlive();
199 ensureIsValidAddress( nRow, nColumn );
200 return implGetChild( nRow, implToVCLColumnPos( nColumn ) );
203 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleSelected(
204 sal_Int32 nRow, sal_Int32 nColumn )
205 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
207 SolarMutexGuard aSolarGuard;
208 ::osl::MutexGuard aGuard( getOslMutex() );
209 ensureIsAlive();
210 ensureIsValidAddress( nRow, nColumn );
211 return isRowBar() ? implIsRowSelected( nRow ) : implIsColumnSelected( nColumn );
214 // XAccessibleSelection -------------------------------------------------------
216 void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAccessibleChild( sal_Int32 nChildIndex )
217 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
219 SolarMutexGuard aSolarGuard;
220 ::osl::MutexGuard aGuard( getOslMutex() );
221 ensureIsAlive();
222 ensureIsValidHeaderIndex( nChildIndex );
223 if( isRowBar() )
224 implSelectRow( nChildIndex, sal_True );
225 else
226 implSelectColumn( implToVCLColumnPos( nChildIndex ), sal_True );
229 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleChildSelected( sal_Int32 nChildIndex )
230 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
232 // using interface methods - no mutex
233 return isRowBar() ?
234 isAccessibleRowSelected( nChildIndex ) :
235 isAccessibleColumnSelected( nChildIndex );
238 void SAL_CALL AccessibleBrowseBoxHeaderBar::clearAccessibleSelection()
239 throw ( uno::RuntimeException )
241 SolarMutexGuard aSolarGuard;
242 ::osl::MutexGuard aGuard( getOslMutex() );
243 ensureIsAlive();
244 mpBrowseBox->SetNoSelection();
247 void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAllAccessibleChildren()
248 throw ( uno::RuntimeException )
250 SolarMutexGuard aSolarGuard;
251 ::osl::MutexGuard aGuard( getOslMutex() );
252 ensureIsAlive();
253 // no multiselection of columns possible
254 if( isRowBar() )
255 mpBrowseBox->SelectAll();
256 else
257 implSelectColumn( implToVCLColumnPos( 0 ), sal_True );
260 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChildCount()
261 throw ( uno::RuntimeException )
263 SolarMutexGuard aSolarGuard;
264 ::osl::MutexGuard aGuard( getOslMutex() );
265 ensureIsAlive();
266 return isRowBar() ? implGetSelectedRowCount() : implGetSelectedColumnCount();
269 Reference< XAccessible > SAL_CALL
270 AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
271 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
273 SolarMutexGuard aSolarGuard;
274 ::osl::MutexGuard aGuard( getOslMutex() );
275 ensureIsAlive();
277 // method may throw lang::IndexOutOfBoundsException
278 sal_Int32 nIndex = implGetChildIndexFromSelectedIndex( nSelectedChildIndex );
279 return implGetChild( nIndex, implToVCLColumnPos( nIndex ) );
282 void SAL_CALL AccessibleBrowseBoxHeaderBar::deselectAccessibleChild(
283 sal_Int32 nSelectedChildIndex )
284 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
286 SolarMutexGuard aSolarGuard;
287 ::osl::MutexGuard aGuard( getOslMutex() );
288 ensureIsAlive();
290 // method may throw lang::IndexOutOfBoundsException
291 if ( isAccessibleChildSelected(nSelectedChildIndex) )
293 if( isRowBar() )
294 implSelectRow( nSelectedChildIndex, sal_False );
295 else
296 implSelectColumn( implToVCLColumnPos( nSelectedChildIndex ), sal_False );
300 // XInterface -----------------------------------------------------------------
302 Any SAL_CALL AccessibleBrowseBoxHeaderBar::queryInterface( const uno::Type& rType )
303 throw ( uno::RuntimeException )
305 Any aAny( AccessibleBrowseBoxTableBase::queryInterface( rType ) );
306 return aAny.hasValue() ?
307 aAny : AccessibleBrowseBoxHeaderBarImplHelper::queryInterface( rType );
310 void SAL_CALL AccessibleBrowseBoxHeaderBar::acquire() throw ()
312 AccessibleBrowseBoxTableBase::acquire();
315 void SAL_CALL AccessibleBrowseBoxHeaderBar::release() throw ()
317 AccessibleBrowseBoxTableBase::release();
320 // XServiceInfo ---------------------------------------------------------------
322 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getImplementationName()
323 throw ( uno::RuntimeException )
325 return OUString( "com.sun.star.comp.svtools.AccessibleBrowseBoxHeaderBar" );
328 namespace
330 class theAccessibleBrowseBoxHeaderBarImplementationId : public rtl::Static< UnoTunnelIdInit, theAccessibleBrowseBoxHeaderBarImplementationId > {};
333 Sequence< sal_Int8 > SAL_CALL AccessibleBrowseBoxHeaderBar::getImplementationId()
334 throw ( uno::RuntimeException )
336 return theAccessibleBrowseBoxHeaderBarImplementationId::get().getSeq();
339 // internal virtual methods ---------------------------------------------------
341 Rectangle AccessibleBrowseBoxHeaderBar::implGetBoundingBox()
343 return mpBrowseBox->calcHeaderRect(isColumnBar(),sal_False);
346 Rectangle AccessibleBrowseBoxHeaderBar::implGetBoundingBoxOnScreen()
348 return mpBrowseBox->calcHeaderRect(isColumnBar(),sal_True);
351 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetRowCount() const
353 // column header bar: only 1 row
354 return isRowBar() ? AccessibleBrowseBoxTableBase::implGetRowCount() : 1;
357 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetColumnCount() const
359 // row header bar ("handle column"): only 1 column
360 return isColumnBar() ? AccessibleBrowseBoxTableBase::implGetColumnCount() : 1;
363 // internal helper methods ----------------------------------------------------
365 Reference< XAccessible > AccessibleBrowseBoxHeaderBar::implGetChild(
366 sal_Int32 nRow, sal_uInt16 nColumnPos )
368 return isRowBar() ?
369 mpBrowseBox->CreateAccessibleRowHeader( nRow ) :
370 mpBrowseBox->CreateAccessibleColumnHeader( nColumnPos );
373 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetChildIndexFromSelectedIndex(
374 sal_Int32 nSelectedChildIndex )
375 throw ( lang::IndexOutOfBoundsException )
377 Sequence< sal_Int32 > aSelSeq;
378 if( isRowBar() )
379 implGetSelectedRows( aSelSeq );
380 else
381 implGetSelectedColumns( aSelSeq );
383 if( (nSelectedChildIndex < 0) || (nSelectedChildIndex >= aSelSeq.getLength()) )
384 throw lang::IndexOutOfBoundsException();
386 return aSelSeq[ nSelectedChildIndex ];
389 void AccessibleBrowseBoxHeaderBar::ensureIsValidHeaderIndex( sal_Int32 nIndex )
390 throw ( lang::IndexOutOfBoundsException )
392 if( isRowBar() )
393 ensureIsValidRow( nIndex );
394 else
395 ensureIsValidColumn( nIndex );
398 // ============================================================================
400 } // namespace accessibility
402 // ============================================================================
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */