1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_accessibility.hxx"
26
27
28 #include "accessibility/extended/AccessibleBrowseBoxHeaderBar.hxx"
29 #include <svtools/accessibletableprovider.hxx>
30
31 // ============================================================================
32
33 using ::rtl::OUString;
34
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::Sequence;
37 using ::com::sun::star::uno::Any;
38
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::accessibility;
41 using namespace ::svt;
42
43 // ============================================================================
44
45 namespace accessibility {
46
47 // ============================================================================
48
49 // Ctor/Dtor/disposing --------------------------------------------------------
50
DBG_NAME(AccessibleBrowseBoxHeaderBar)51 DBG_NAME( AccessibleBrowseBoxHeaderBar )
52
53 AccessibleBrowseBoxHeaderBar::AccessibleBrowseBoxHeaderBar(
54 const Reference< XAccessible >& rxParent,
55 IAccessibleTableProvider& rBrowseBox,
56 AccessibleBrowseBoxObjType eObjType ) :
57 AccessibleBrowseBoxTableBase( rxParent, rBrowseBox,eObjType )
58 {
59 DBG_CTOR( AccessibleBrowseBoxHeaderBar, NULL );
60
61 DBG_ASSERT( isRowBar() || isColumnBar(),
62 "accessibility/extended/AccessibleBrowseBoxHeaderBar - invalid object type" );
63 }
64
~AccessibleBrowseBoxHeaderBar()65 AccessibleBrowseBoxHeaderBar::~AccessibleBrowseBoxHeaderBar()
66 {
67 DBG_DTOR( AccessibleBrowseBoxHeaderBar, NULL );
68 }
69
70 // XAccessibleContext ---------------------------------------------------------
71
72 Reference< XAccessible > SAL_CALL
getAccessibleChild(sal_Int32 nChildIndex)73 AccessibleBrowseBoxHeaderBar::getAccessibleChild( sal_Int32 nChildIndex )
74 {
75 BBSolarGuard aSolarGuard;
76 ::osl::MutexGuard aGuard( getOslMutex() );
77 ensureIsAlive();
78 ensureIsValidHeaderIndex( nChildIndex );
79 return implGetChild( nChildIndex, implToVCLColumnPos( nChildIndex ) );
80 }
81
getAccessibleIndexInParent()82 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleIndexInParent()
83 {
84 return isRowBar() ? BBINDEX_ROWHEADERBAR : BBINDEX_COLUMNHEADERBAR;
85 }
86
87 // XAccessibleComponent -------------------------------------------------------
88
89 Reference< XAccessible > SAL_CALL
getAccessibleAtPoint(const awt::Point & rPoint)90 AccessibleBrowseBoxHeaderBar::getAccessibleAtPoint( const awt::Point& rPoint )
91 {
92 BBSolarGuard aSolarGuard;
93 ::osl::MutexGuard aGuard( getOslMutex() );
94 ensureIsAlive();
95
96 sal_Int32 nRow = 0;
97 sal_uInt16 nColumnPos = 0;
98 sal_Bool bConverted = isRowBar() ?
99 mpBrowseBox->ConvertPointToRowHeader( nRow, VCLPoint( rPoint ) ) :
100 mpBrowseBox->ConvertPointToColumnHeader( nColumnPos, VCLPoint( rPoint ) );
101
102 return bConverted ? implGetChild( nRow, nColumnPos ) : Reference< XAccessible >();
103 }
104
grabFocus()105 void SAL_CALL AccessibleBrowseBoxHeaderBar::grabFocus()
106 {
107 ensureIsAlive();
108 // focus on header not supported
109 }
110
getAccessibleKeyBinding()111 Any SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleKeyBinding()
112 {
113 ensureIsAlive();
114 return Any(); // no special key bindings for header
115 }
116
117 // XAccessibleTable -----------------------------------------------------------
118
getAccessibleRowDescription(sal_Int32 nRow)119 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowDescription( sal_Int32 nRow )
120 {
121 BBSolarGuard aSolarGuard;
122 ::osl::MutexGuard aGuard( getOslMutex() );
123 ensureIsAlive();
124 ensureIsValidRow( nRow );
125 return OUString(); // no headers in headers
126 }
127
getAccessibleColumnDescription(sal_Int32 nColumn)128 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnDescription( sal_Int32 nColumn )
129 {
130 BBSolarGuard aSolarGuard;
131 ::osl::MutexGuard aGuard( getOslMutex() );
132 ensureIsAlive();
133 ensureIsValidColumn( nColumn );
134 return OUString(); // no headers in headers
135 }
136
getAccessibleRowHeaders()137 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleRowHeaders()
138 {
139 ensureIsAlive();
140 return NULL; // no headers in headers
141 }
142
getAccessibleColumnHeaders()143 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleColumnHeaders()
144 {
145 ensureIsAlive();
146 return NULL; // no headers in headers
147 }
148
getSelectedAccessibleRows()149 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleRows()
150 {
151 BBSolarGuard aSolarGuard;
152 ::osl::MutexGuard aGuard( getOslMutex() );
153 ensureIsAlive();
154
155 Sequence< sal_Int32 > aSelSeq;
156 // row of column header bar not selectable
157 if( isRowBar() )
158 implGetSelectedRows( aSelSeq );
159 return aSelSeq;
160 }
161
getSelectedAccessibleColumns()162 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleColumns()
163 {
164 BBSolarGuard aSolarGuard;
165 ::osl::MutexGuard aGuard( getOslMutex() );
166 ensureIsAlive();
167
168 Sequence< sal_Int32 > aSelSeq;
169 // column of row header bar ("handle column") not selectable
170 if( isColumnBar() )
171 implGetSelectedColumns( aSelSeq );
172 return aSelSeq;
173 }
174
isAccessibleRowSelected(sal_Int32 nRow)175 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleRowSelected( sal_Int32 nRow )
176 {
177 BBSolarGuard aSolarGuard;
178 ::osl::MutexGuard aGuard( getOslMutex() );
179 ensureIsAlive();
180 ensureIsValidRow( nRow );
181 return isRowBar() ? implIsRowSelected( nRow ) : sal_False;
182 }
183
isAccessibleColumnSelected(sal_Int32 nColumn)184 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleColumnSelected( sal_Int32 nColumn )
185 {
186 BBSolarGuard aSolarGuard;
187 ::osl::MutexGuard aGuard( getOslMutex() );
188 ensureIsAlive();
189 ensureIsValidColumn( nColumn );
190 return isColumnBar() ? implIsColumnSelected( nColumn ) : sal_False;
191 }
192
getAccessibleCellAt(sal_Int32 nRow,sal_Int32 nColumn)193 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxHeaderBar::getAccessibleCellAt(
194 sal_Int32 nRow, sal_Int32 nColumn )
195 {
196 BBSolarGuard aSolarGuard;
197 ::osl::MutexGuard aGuard( getOslMutex() );
198 ensureIsAlive();
199 ensureIsValidAddress( nRow, nColumn );
200 return implGetChild( nRow, implToVCLColumnPos( nColumn ) );
201 }
202
isAccessibleSelected(sal_Int32 nRow,sal_Int32 nColumn)203 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleSelected(
204 sal_Int32 nRow, sal_Int32 nColumn )
205 {
206 BBSolarGuard aSolarGuard;
207 ::osl::MutexGuard aGuard( getOslMutex() );
208 ensureIsAlive();
209 ensureIsValidAddress( nRow, nColumn );
210 return isRowBar() ? implIsRowSelected( nRow ) : implIsColumnSelected( nColumn );
211 }
212
213 // XAccessibleSelection -------------------------------------------------------
214
selectAccessibleChild(sal_Int32 nChildIndex)215 void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAccessibleChild( sal_Int32 nChildIndex )
216 {
217 BBSolarGuard aSolarGuard;
218 ::osl::MutexGuard aGuard( getOslMutex() );
219 ensureIsAlive();
220 ensureIsValidHeaderIndex( nChildIndex );
221 if( isRowBar() )
222 implSelectRow( nChildIndex, sal_True );
223 else
224 implSelectColumn( implToVCLColumnPos( nChildIndex ), sal_True );
225 }
226
isAccessibleChildSelected(sal_Int32 nChildIndex)227 sal_Bool SAL_CALL AccessibleBrowseBoxHeaderBar::isAccessibleChildSelected( sal_Int32 nChildIndex )
228 {
229 // using interface methods - no mutex
230 return isRowBar() ?
231 isAccessibleRowSelected( nChildIndex ) :
232 isAccessibleColumnSelected( nChildIndex );
233 }
234
clearAccessibleSelection()235 void SAL_CALL AccessibleBrowseBoxHeaderBar::clearAccessibleSelection()
236 {
237 BBSolarGuard aSolarGuard;
238 ::osl::MutexGuard aGuard( getOslMutex() );
239 ensureIsAlive();
240 mpBrowseBox->SetNoSelection();
241 }
242
selectAllAccessibleChildren()243 void SAL_CALL AccessibleBrowseBoxHeaderBar::selectAllAccessibleChildren()
244 {
245 BBSolarGuard aSolarGuard;
246 ::osl::MutexGuard aGuard( getOslMutex() );
247 ensureIsAlive();
248 // no multiselection of columns possible
249 if( isRowBar() )
250 mpBrowseBox->SelectAll();
251 else
252 implSelectColumn( implToVCLColumnPos( 0 ), sal_True );
253 }
254
getSelectedAccessibleChildCount()255 sal_Int32 SAL_CALL AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChildCount()
256 {
257 BBSolarGuard aSolarGuard;
258 ::osl::MutexGuard aGuard( getOslMutex() );
259 ensureIsAlive();
260 return isRowBar() ? implGetSelectedRowCount() : implGetSelectedColumnCount();
261 }
262
263 Reference< XAccessible > SAL_CALL
getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)264 AccessibleBrowseBoxHeaderBar::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
265 {
266 BBSolarGuard aSolarGuard;
267 ::osl::MutexGuard aGuard( getOslMutex() );
268 ensureIsAlive();
269
270 // method may throw lang::IndexOutOfBoundsException
271 sal_Int32 nIndex = implGetChildIndexFromSelectedIndex( nSelectedChildIndex );
272 return implGetChild( nIndex, implToVCLColumnPos( nIndex ) );
273 }
274
deselectAccessibleChild(sal_Int32 nSelectedChildIndex)275 void SAL_CALL AccessibleBrowseBoxHeaderBar::deselectAccessibleChild(
276 sal_Int32 nSelectedChildIndex )
277 {
278 BBSolarGuard aSolarGuard;
279 ::osl::MutexGuard aGuard( getOslMutex() );
280 ensureIsAlive();
281
282 // method may throw lang::IndexOutOfBoundsException
283 if ( isAccessibleChildSelected(nSelectedChildIndex) )
284 {
285 if( isRowBar() )
286 implSelectRow( nSelectedChildIndex, sal_False );
287 else
288 implSelectColumn( implToVCLColumnPos( nSelectedChildIndex ), sal_False );
289 }
290 }
291
292 // XInterface -----------------------------------------------------------------
293
queryInterface(const uno::Type & rType)294 Any SAL_CALL AccessibleBrowseBoxHeaderBar::queryInterface( const uno::Type& rType )
295 {
296 Any aAny( AccessibleBrowseBoxTableBase::queryInterface( rType ) );
297 return aAny.hasValue() ?
298 aAny : AccessibleBrowseBoxHeaderBarImplHelper::queryInterface( rType );
299 }
300
acquire()301 void SAL_CALL AccessibleBrowseBoxHeaderBar::acquire() throw ()
302 {
303 AccessibleBrowseBoxTableBase::acquire();
304 }
305
release()306 void SAL_CALL AccessibleBrowseBoxHeaderBar::release() throw ()
307 {
308 AccessibleBrowseBoxTableBase::release();
309 }
310
311 // XServiceInfo ---------------------------------------------------------------
312
getImplementationName()313 OUString SAL_CALL AccessibleBrowseBoxHeaderBar::getImplementationName()
314 {
315 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.AccessibleBrowseBoxHeaderBar" ) );
316 }
317
getImplementationId()318 Sequence< sal_Int8 > SAL_CALL AccessibleBrowseBoxHeaderBar::getImplementationId()
319 {
320 ::osl::MutexGuard aGuard( getOslGlobalMutex() );
321 static Sequence< sal_Int8 > aId;
322 implCreateUuid( aId );
323 return aId;
324 }
325
326 // internal virtual methods ---------------------------------------------------
327
implGetBoundingBox()328 Rectangle AccessibleBrowseBoxHeaderBar::implGetBoundingBox()
329 {
330 return mpBrowseBox->calcHeaderRect(isColumnBar(),sal_False);
331 }
332
implGetBoundingBoxOnScreen()333 Rectangle AccessibleBrowseBoxHeaderBar::implGetBoundingBoxOnScreen()
334 {
335 return mpBrowseBox->calcHeaderRect(isColumnBar(),sal_True);
336 }
337
implGetRowCount() const338 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetRowCount() const
339 {
340 // column header bar: only 1 row
341 return isRowBar() ? AccessibleBrowseBoxTableBase::implGetRowCount() : 1;
342 }
343
implGetColumnCount() const344 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetColumnCount() const
345 {
346 // row header bar ("handle column"): only 1 column
347 return isColumnBar() ? AccessibleBrowseBoxTableBase::implGetColumnCount() : 1;
348 }
349
350 // internal helper methods ----------------------------------------------------
351
implGetChild(sal_Int32 nRow,sal_uInt16 nColumnPos)352 Reference< XAccessible > AccessibleBrowseBoxHeaderBar::implGetChild(
353 sal_Int32 nRow, sal_uInt16 nColumnPos )
354 {
355 return isRowBar() ?
356 mpBrowseBox->CreateAccessibleRowHeader( nRow ) :
357 mpBrowseBox->CreateAccessibleColumnHeader( nColumnPos );
358 }
359
implGetChildIndexFromSelectedIndex(sal_Int32 nSelectedChildIndex)360 sal_Int32 AccessibleBrowseBoxHeaderBar::implGetChildIndexFromSelectedIndex(
361 sal_Int32 nSelectedChildIndex )
362 {
363 Sequence< sal_Int32 > aSelSeq;
364 if( isRowBar() )
365 implGetSelectedRows( aSelSeq );
366 else
367 implGetSelectedColumns( aSelSeq );
368
369 if( (nSelectedChildIndex < 0) || (nSelectedChildIndex >= aSelSeq.getLength()) )
370 throw lang::IndexOutOfBoundsException();
371
372 return aSelSeq[ nSelectedChildIndex ];
373 }
374
ensureIsValidHeaderIndex(sal_Int32 nIndex)375 void AccessibleBrowseBoxHeaderBar::ensureIsValidHeaderIndex( sal_Int32 nIndex )
376 {
377 if( isRowBar() )
378 ensureIsValidRow( nIndex );
379 else
380 ensureIsValidColumn( nIndex );
381 }
382
383 // ============================================================================
384 } // namespace accessibility
385 // ============================================================================
386