Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "accessibility/extended/AccessibleGridControlTable.hxx"
21 : #include "accessibility/extended/AccessibleGridControlTableCell.hxx"
22 : #include <svtools/accessibletable.hxx>
23 :
24 :
25 :
26 : using ::com::sun::star::uno::Reference;
27 : using ::com::sun::star::uno::Sequence;
28 : using ::com::sun::star::uno::Any;
29 :
30 : using namespace ::com::sun::star;
31 : using namespace ::com::sun::star::accessibility;
32 : using namespace ::svt;
33 : using namespace ::svt::table;
34 :
35 :
36 : namespace accessibility {
37 :
38 :
39 :
40 0 : AccessibleGridControlTable::AccessibleGridControlTable(
41 : const Reference< XAccessible >& rxParent,
42 : IAccessibleTable& rTable,
43 : AccessibleTableControlObjType _eType) :
44 : AccessibleGridControlTableBase( rxParent, rTable, _eType )
45 : ,m_pCellVector( )
46 0 : ,m_pAccessCellVector( )
47 : {
48 0 : }
49 :
50 0 : AccessibleGridControlTable::~AccessibleGridControlTable()
51 : {
52 0 : }
53 :
54 : // XAccessibleContext ---------------------------------------------------------
55 :
56 : Reference< XAccessible > SAL_CALL
57 0 : AccessibleGridControlTable::getAccessibleChild( sal_Int32 nChildIndex )
58 : throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
59 : {
60 0 : SolarMutexGuard aSolarGuard;
61 :
62 0 : ensureIsAlive();
63 0 : ensureIsValidIndex( nChildIndex );
64 0 : sal_Int32 nCount = getAccessibleChildCount();
65 0 : if(m_pAccessCellVector.size() == 0 || m_pAccessCellVector.size() != (unsigned)nCount)
66 : {
67 0 : m_pAccessCellVector.resize(nCount);
68 0 : m_pCellVector.resize(nCount);
69 : }
70 0 : if(!m_pAccessCellVector[nChildIndex].is())
71 : {
72 0 : AccessibleGridControlTableCell* pCell = new AccessibleGridControlTableCell(this, m_aTable, nChildIndex/m_aTable.GetColumnCount(), nChildIndex%m_aTable.GetColumnCount(), TCTYPE_TABLECELL);
73 0 : m_pCellVector[nChildIndex] = pCell;
74 0 : m_pAccessCellVector[nChildIndex] = pCell;
75 : }
76 0 : return m_pAccessCellVector[nChildIndex];
77 : }
78 :
79 0 : sal_Int32 SAL_CALL AccessibleGridControlTable::getAccessibleIndexInParent()
80 : throw ( uno::RuntimeException, std::exception )
81 : {
82 0 : ensureIsAlive();
83 0 : if(m_aTable.HasRowHeader() && m_aTable.HasColHeader())
84 0 : return 0;
85 0 : else if((!m_aTable.HasRowHeader() && m_aTable.HasColHeader()) || (m_aTable.HasRowHeader() && !m_aTable.HasColHeader()) )
86 0 : return 1;
87 : else
88 0 : return 2;
89 : }
90 :
91 : // XAccessibleComponent -------------------------------------------------------
92 :
93 : Reference< XAccessible > SAL_CALL
94 0 : AccessibleGridControlTable::getAccessibleAtPoint( const awt::Point& rPoint )
95 : throw ( uno::RuntimeException, std::exception )
96 : {
97 0 : SolarMutexGuard aSolarGuard;
98 :
99 0 : ensureIsAlive();
100 :
101 0 : Reference< XAccessible > xChild;
102 0 : sal_Int32 nRow = 0;
103 0 : sal_Int32 nColumnPos = 0;
104 0 : if( m_aTable.ConvertPointToCellAddress( nRow, nColumnPos, VCLPoint( rPoint ) ) )
105 0 : xChild = new AccessibleGridControlTableCell(this, m_aTable, nRow, nColumnPos, TCTYPE_TABLECELL);
106 0 : return xChild;
107 : }
108 :
109 0 : void SAL_CALL AccessibleGridControlTable::grabFocus()
110 : throw ( uno::RuntimeException, std::exception )
111 : {
112 0 : SolarMutexGuard aSolarGuard;
113 :
114 0 : ensureIsAlive();
115 0 : m_aTable.GrabFocus();
116 0 : }
117 :
118 : // XAccessibleTable -----------------------------------------------------------
119 :
120 0 : OUString SAL_CALL AccessibleGridControlTable::getAccessibleRowDescription( sal_Int32 nRow )
121 : throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
122 : {
123 0 : SolarMutexGuard aSolarGuard;
124 :
125 0 : ensureIsAlive();
126 0 : ensureIsValidRow( nRow );
127 0 : return m_aTable.GetRowDescription( nRow );
128 : }
129 :
130 0 : OUString SAL_CALL AccessibleGridControlTable::getAccessibleColumnDescription( sal_Int32 nColumn )
131 : throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
132 : {
133 0 : SolarMutexGuard aSolarGuard;
134 :
135 0 : ensureIsAlive();
136 0 : ensureIsValidColumn( nColumn );
137 0 : return m_aTable.GetColumnDescription( (sal_uInt16)nColumn );
138 : }
139 :
140 0 : Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleRowHeaders()
141 : throw ( uno::RuntimeException, std::exception )
142 : {
143 0 : SolarMutexGuard g;
144 :
145 0 : ensureIsAlive();
146 0 : if(m_aTable.HasColHeader())
147 0 : return implGetHeaderBar( 1 );
148 : else
149 0 : return implGetHeaderBar( 0 );
150 : }
151 :
152 0 : Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleColumnHeaders()
153 : throw ( uno::RuntimeException, std::exception )
154 : {
155 0 : SolarMutexGuard g;
156 :
157 0 : ensureIsAlive();
158 0 : return implGetHeaderBar( 0 );
159 : }
160 :
161 0 : Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleRows()
162 : throw ( uno::RuntimeException, std::exception )
163 : {
164 0 : SolarMutexGuard aSolarGuard;
165 :
166 0 : ensureIsAlive();
167 0 : Sequence< sal_Int32 > aSelSeq;
168 0 : implGetSelectedRows( aSelSeq );
169 0 : return aSelSeq;
170 : }
171 :
172 : //columns aren't selectable
173 0 : Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleColumns()
174 : throw ( uno::RuntimeException, std::exception )
175 : {
176 0 : Sequence< sal_Int32 > aSelSeq(0);
177 0 : return aSelSeq;
178 : }
179 :
180 0 : sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleRowSelected( sal_Int32 nRow )
181 : throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
182 : {
183 0 : SolarMutexGuard aSolarGuard;
184 :
185 0 : ensureIsAlive();
186 0 : ensureIsValidRow( nRow );
187 0 : bool bSelected = false;
188 0 : Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
189 0 : for(int i=0; i<selectedRows.getLength(); i++)
190 : {
191 0 : if(nRow == selectedRows[i])
192 : {
193 0 : bSelected = true;
194 0 : continue;
195 : }
196 : }
197 0 : return bSelected;
198 : }
199 :
200 : //columns aren't selectable
201 0 : sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleColumnSelected( sal_Int32 nColumn )
202 : throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
203 : {
204 : (void) nColumn;
205 0 : return false;
206 : }
207 :
208 0 : Reference< XAccessible > SAL_CALL AccessibleGridControlTable::getAccessibleCellAt(
209 : sal_Int32 nRow, sal_Int32 nColumn )
210 : throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
211 : {
212 0 : SolarMutexGuard aSolarGuard;
213 :
214 0 : ensureIsAlive();
215 0 : ensureIsValidAddress( nRow, nColumn );
216 0 : sal_Int32 nCount = getAccessibleChildCount();
217 0 : sal_Int32 nChildIndex = nRow*m_aTable.GetColumnCount() + nColumn;
218 0 : if(m_pAccessCellVector.size() == 0 || m_pAccessCellVector.size() != (unsigned)nCount)
219 : {
220 0 : m_pAccessCellVector.resize(nCount);
221 0 : m_pCellVector.resize(nCount);
222 : }
223 0 : if(!m_pAccessCellVector[nChildIndex].is())
224 : {
225 0 : AccessibleGridControlTableCell* pCell = new AccessibleGridControlTableCell(this, m_aTable, nRow, nColumn, TCTYPE_TABLECELL);
226 0 : m_pCellVector[nChildIndex] = pCell;
227 0 : m_pAccessCellVector[nChildIndex] = pCell;
228 : }
229 0 : return m_pAccessCellVector[nChildIndex];
230 : }
231 :
232 0 : sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleSelected(
233 : sal_Int32 nRow, sal_Int32 nColumn )
234 : throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
235 : {
236 0 : SolarMutexGuard aSolarGuard;
237 :
238 0 : ensureIsAlive();
239 0 : ensureIsValidAddress( nRow, nColumn );
240 : (void) nColumn;
241 : //selection of single cells not possible, so if row is selected, the cell will be selected too
242 0 : return isAccessibleRowSelected(nRow);
243 : }
244 0 : void SAL_CALL AccessibleGridControlTable::selectAccessibleChild( sal_Int32 nChildIndex )
245 : throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
246 : {
247 0 : SolarMutexGuard aSolarGuard;
248 :
249 0 : ensureIsAlive();
250 0 : ensureIsValidIndex( nChildIndex );
251 0 : sal_Int32 nColumns = m_aTable.GetColumnCount();
252 0 : sal_Int32 nRow = (nChildIndex / nColumns);
253 0 : m_aTable.SelectRow( nRow, true );
254 0 : }
255 0 : sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleChildSelected( sal_Int32 nChildIndex )
256 : throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
257 : {
258 0 : SolarMutexGuard aSolarGuard;
259 :
260 0 : ensureIsAlive();
261 0 : ensureIsValidIndex( nChildIndex );
262 0 : sal_Int32 nColumns = m_aTable.GetColumnCount();
263 0 : sal_Int32 nRow = (nChildIndex / nColumns);
264 0 : return isAccessibleRowSelected(nRow);
265 : }
266 0 : void SAL_CALL AccessibleGridControlTable::clearAccessibleSelection()
267 : throw ( uno::RuntimeException, std::exception )
268 : {
269 0 : SolarMutexGuard aSolarGuard;
270 :
271 0 : ensureIsAlive();
272 0 : m_aTable.SelectAllRows( false );
273 0 : }
274 0 : void SAL_CALL AccessibleGridControlTable::selectAllAccessibleChildren()
275 : throw ( uno::RuntimeException, std::exception )
276 : {
277 0 : SolarMutexGuard aSolarGuard;
278 :
279 0 : ensureIsAlive();
280 0 : Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
281 0 : for(int i=0;i<m_aTable.GetRowCount();i++)
282 0 : selectedRows[i]=i;
283 0 : }
284 0 : sal_Int32 SAL_CALL AccessibleGridControlTable::getSelectedAccessibleChildCount()
285 : throw ( uno::RuntimeException, std::exception )
286 : {
287 0 : SolarMutexGuard aSolarGuard;
288 :
289 0 : ensureIsAlive();
290 0 : Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows();
291 0 : sal_Int32 nColumns = m_aTable.GetColumnCount();
292 0 : return selectedRows.getLength()*nColumns;
293 : }
294 : Reference< XAccessible > SAL_CALL
295 0 : AccessibleGridControlTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
296 : throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
297 : {
298 0 : SolarMutexGuard aSolarGuard;
299 :
300 0 : ensureIsAlive();
301 0 : if(isAccessibleChildSelected(nSelectedChildIndex))
302 0 : return getAccessibleChild(nSelectedChildIndex);
303 : else
304 0 : return NULL;
305 : }
306 : //not implemented yet, because only row selection possible
307 0 : void SAL_CALL AccessibleGridControlTable::deselectAccessibleChild(
308 : sal_Int32 nSelectedChildIndex )
309 : throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
310 : {
311 0 : SolarMutexGuard aSolarGuard;
312 :
313 0 : ensureIsAlive();
314 0 : (void)nSelectedChildIndex;
315 0 : }
316 : // XInterface -----------------------------------------------------------------
317 :
318 0 : Any SAL_CALL AccessibleGridControlTable::queryInterface( const uno::Type& rType )
319 : throw ( uno::RuntimeException, std::exception )
320 : {
321 0 : Any aAny( AccessibleGridControlTableBase::queryInterface( rType ) );
322 0 : return aAny.hasValue() ?
323 0 : aAny : AccessibleGridControlTableImplHelper1::queryInterface( rType );
324 : }
325 :
326 0 : void SAL_CALL AccessibleGridControlTable::acquire() throw ()
327 : {
328 0 : AccessibleGridControlTableBase::acquire();
329 0 : }
330 :
331 0 : void SAL_CALL AccessibleGridControlTable::release() throw ()
332 : {
333 0 : AccessibleGridControlTableBase::release();
334 0 : }
335 : // XServiceInfo ---------------------------------------------------------------
336 :
337 0 : OUString SAL_CALL AccessibleGridControlTable::getImplementationName()
338 : throw ( uno::RuntimeException, std::exception )
339 : {
340 0 : return OUString( "com.sun.star.accessibility.AccessibleGridControlTable" );
341 : }
342 :
343 : // internal virtual methods ---------------------------------------------------
344 :
345 0 : Rectangle AccessibleGridControlTable::implGetBoundingBox()
346 : {
347 0 : vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
348 : DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
349 0 : Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( pParent ));
350 0 : Rectangle aTableRect( m_aTable.calcTableRect() );
351 0 : long nX = aGridRect.Left() + aTableRect.Left();
352 0 : long nY = aGridRect.Top() + aTableRect.Top();
353 0 : long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
354 0 : long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
355 0 : Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
356 0 : return aTable;
357 : }
358 :
359 0 : Rectangle AccessibleGridControlTable::implGetBoundingBoxOnScreen()
360 : {
361 0 : Rectangle aGridRect( m_aTable.GetWindowExtentsRelative( NULL ));
362 0 : Rectangle aTableRect( m_aTable.calcTableRect() );
363 0 : long nX = aGridRect.Left() + aTableRect.Left();
364 0 : long nY = aGridRect.Top() + aTableRect.Top();
365 0 : long nWidth = aGridRect.GetSize().Width()-aTableRect.Left();
366 0 : long nHeight = aGridRect.GetSize().Height()-aTableRect.Top();
367 0 : Rectangle aTable( Point( nX, nY ), Size( nWidth, nHeight ));
368 0 : return aTable;
369 : }
370 : // internal helper methods ----------------------------------------------------
371 0 : Reference< XAccessibleTable > AccessibleGridControlTable::implGetHeaderBar(
372 : sal_Int32 nChildIndex )
373 : throw ( uno::RuntimeException )
374 : {
375 0 : Reference< XAccessible > xRet;
376 0 : Reference< XAccessibleContext > xContext( m_xParent, uno::UNO_QUERY );
377 0 : if( xContext.is() )
378 : {
379 : try
380 : {
381 0 : xRet = xContext->getAccessibleChild( nChildIndex );
382 : }
383 0 : catch (const lang::IndexOutOfBoundsException&)
384 : {
385 : OSL_FAIL( "implGetHeaderBar - wrong child index" );
386 : }
387 : // RuntimeException goes to caller
388 : }
389 0 : return Reference< XAccessibleTable >( xRet, uno::UNO_QUERY );
390 : }
391 :
392 :
393 :
394 :
395 60 : } // namespace accessibility
396 :
397 :
398 :
399 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|