Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <com/sun/star/table/XMergeableCell.hpp>
31 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
32 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
33 : :
34 : : #include <comphelper/accessiblewrapper.hxx>
35 : : #include <osl/mutex.hxx>
36 : : #include <vcl/svapp.hxx>
37 : :
38 : : #include <svx/AccessibleTableShape.hxx>
39 : : #include "tablecontroller.hxx"
40 : : #include "accessiblecell.hxx"
41 : :
42 : : #include <algorithm>
43 : :
44 : : #include <cppuhelper/implbase1.hxx>
45 : :
46 : : using ::rtl::OUString;
47 : :
48 : : using namespace ::accessibility;
49 : : using namespace ::sdr::table;
50 : : using namespace ::com::sun::star::accessibility;
51 : : using namespace ::com::sun::star::uno;
52 : : using namespace ::com::sun::star::beans;
53 : : using namespace ::com::sun::star::util;
54 : : using namespace ::com::sun::star::lang;
55 : : using namespace ::com::sun::star::drawing;
56 : : using namespace ::com::sun::star::table;
57 : : using namespace ::com::sun::star::container;
58 : :
59 : : #define C2U(x) OUString(RTL_CONSTASCII_USTRINGPARAM(x))
60 : :
61 : : namespace accessibility
62 : : {
63 : :
64 : : struct hash
65 : : {
66 : 0 : std::size_t operator()( const Reference< XCell >& xCell ) const
67 : : {
68 : 0 : return std::size_t( xCell.get() );
69 : : }
70 : : };
71 : :
72 : : typedef boost::unordered_map< Reference< XCell >, rtl::Reference< AccessibleCell >, hash > AccessibleCellMap;
73 : :
74 : : //-----------------------------------------------------------------------------
75 : : // AccessibleTableShapeImpl
76 : : //-----------------------------------------------------------------------------
77 : :
78 [ # # ][ # # ]: 0 : class AccessibleTableShapeImpl : public cppu::WeakImplHelper1< XModifyListener >
79 : : {
80 : : public:
81 : : AccessibleTableShapeImpl( AccessibleShapeTreeInfo& rShapeTreeInfo );
82 : :
83 : : void init( const Reference< XAccessible>& xAccessible, const Reference< XTable >& xTable );
84 : : void dispose();
85 : :
86 : : Reference< XAccessible > getAccessibleChild( sal_Int32 i ) throw(IndexOutOfBoundsException);
87 : : void getColumnAndRow( sal_Int32 nChildIndex, sal_Int32& rnColumn, sal_Int32& rnRow ) throw (IndexOutOfBoundsException );
88 : :
89 : : // XModifyListener
90 : : virtual void SAL_CALL modified( const EventObject& aEvent ) throw (RuntimeException);
91 : :
92 : : // XEventListener
93 : : virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
94 : :
95 : : AccessibleShapeTreeInfo& mrShapeTreeInfo;
96 : : Reference< XTable > mxTable;
97 : : AccessibleCellMap maChildMap;
98 : : Reference< XAccessible> mxAccessible;
99 : : };
100 : :
101 : : //-----------------------------------------------------------------------------
102 : :
103 : 0 : AccessibleTableShapeImpl::AccessibleTableShapeImpl( AccessibleShapeTreeInfo& rShapeTreeInfo )
104 [ # # ]: 0 : : mrShapeTreeInfo( rShapeTreeInfo )
105 : : {
106 : 0 : }
107 : :
108 : : //-----------------------------------------------------------------------------
109 : :
110 : 0 : void AccessibleTableShapeImpl::init( const Reference< XAccessible>& xAccessible, const Reference< XTable >& xTable )
111 : : {
112 : 0 : mxAccessible = xAccessible;
113 : 0 : mxTable = xTable;
114 : :
115 [ # # ]: 0 : if( mxTable.is() )
116 : : {
117 [ # # ]: 0 : Reference< XModifyListener > xListener( this );
118 [ # # ][ # # ]: 0 : mxTable->addModifyListener( xListener );
119 : : }
120 : 0 : }
121 : :
122 : : //-----------------------------------------------------------------------------
123 : :
124 : 0 : void AccessibleTableShapeImpl::dispose()
125 : : {
126 [ # # ]: 0 : if( mxTable.is() )
127 : : {
128 [ # # ]: 0 : Reference< XModifyListener > xListener( this );
129 [ # # ][ # # ]: 0 : mxTable->removeModifyListener( xListener );
130 : 0 : mxTable.clear();
131 : : }
132 : 0 : mxAccessible.clear();
133 : 0 : }
134 : :
135 : : //-----------------------------------------------------------------------------
136 : :
137 : 0 : Reference< XAccessible > AccessibleTableShapeImpl::getAccessibleChild( sal_Int32 nChildIndex ) throw(IndexOutOfBoundsException)
138 : : {
139 : 0 : sal_Int32 nColumn = 0, nRow = 0;
140 [ # # ]: 0 : getColumnAndRow( nChildIndex, nColumn, nRow );
141 : :
142 [ # # ][ # # ]: 0 : Reference< XCell > xCell( mxTable->getCellByPosition( nColumn, nRow ) );
143 [ # # ]: 0 : AccessibleCellMap::iterator iter( maChildMap.find( xCell ) );
144 : :
145 [ # # ][ # # ]: 0 : if( iter != maChildMap.end() )
146 : : {
147 [ # # ][ # # ]: 0 : Reference< XAccessible > xChild( (*iter).second.get() );
[ # # ]
148 : 0 : return xChild;
149 : : }
150 : : else
151 : : {
152 [ # # ][ # # ]: 0 : CellRef xCellRef( dynamic_cast< Cell* >( xCell.get() ) );
153 : :
154 [ # # ]: 0 : rtl::Reference< AccessibleCell > xAccessibleCell( new AccessibleCell( mxAccessible, xCellRef, nChildIndex, mrShapeTreeInfo ) );
155 : :
156 [ # # ][ # # ]: 0 : maChildMap[xCell] = xAccessibleCell;
157 : :
158 [ # # ]: 0 : xAccessibleCell->Init();
159 : :
160 [ # # ][ # # ]: 0 : Reference< XAccessible > xChild( xAccessibleCell.get() );
161 : 0 : return xChild;
162 : 0 : }
163 : : }
164 : :
165 : : //-----------------------------------------------------------------------------
166 : :
167 : 0 : void AccessibleTableShapeImpl::getColumnAndRow( sal_Int32 nChildIndex, sal_Int32& rnColumn, sal_Int32& rnRow ) throw (IndexOutOfBoundsException )
168 : : {
169 : 0 : rnRow = 0;
170 : 0 : rnColumn = nChildIndex;
171 : :
172 [ # # ]: 0 : if( mxTable.is() )
173 : : {
174 : 0 : const sal_Int32 nColumnCount = mxTable->getColumnCount();
175 [ # # ]: 0 : while( rnColumn >= nColumnCount )
176 : : {
177 : 0 : rnRow++;
178 : 0 : rnColumn -= nColumnCount;
179 : : }
180 : :
181 [ # # ]: 0 : if( rnRow < mxTable->getRowCount() )
182 : 0 : return;
183 : : }
184 : :
185 [ # # ]: 0 : throw IndexOutOfBoundsException();
186 : : }
187 : :
188 : : // XModifyListener
189 : 0 : void SAL_CALL AccessibleTableShapeImpl::modified( const EventObject& /*aEvent*/ ) throw (RuntimeException)
190 : : {
191 [ # # ]: 0 : if( mxTable.is() ) try
192 : : {
193 : : // structural changes may have happened to the table, validate all accessible cell instances
194 [ # # ]: 0 : AccessibleCellMap aTempChildMap;
195 [ # # ]: 0 : aTempChildMap.swap( maChildMap );
196 : :
197 : : // first move all still existing cells to maChildMap again and update their index
198 : :
199 [ # # ][ # # ]: 0 : const sal_Int32 nRowCount = mxTable->getRowCount();
200 [ # # ][ # # ]: 0 : const sal_Int32 nColCount = mxTable->getColumnCount();
201 : :
202 : 0 : sal_Int32 nChildIndex = 0;
203 : :
204 [ # # ]: 0 : for( sal_Int32 nRow = 0; nRow < nRowCount; ++nRow )
205 : : {
206 [ # # ]: 0 : for( sal_Int32 nCol = 0; nCol < nColCount; ++nCol )
207 : : {
208 [ # # ][ # # ]: 0 : Reference< XCell > xCell( mxTable->getCellByPosition( nCol, nRow ) );
209 [ # # ]: 0 : AccessibleCellMap::iterator iter( aTempChildMap.find( xCell ) );
210 : :
211 [ # # ][ # # ]: 0 : if( iter != aTempChildMap.end() )
212 : : {
213 [ # # ]: 0 : rtl::Reference< AccessibleCell > xAccessibleCell( (*iter).second );
214 : 0 : xAccessibleCell->setIndexInParent( nChildIndex );
215 [ # # ]: 0 : xAccessibleCell->CommitChange(AccessibleEventId::VISIBLE_DATA_CHANGED, Any(), Any());
216 : :
217 : : // move still existing cell from temporary child map to our child map
218 [ # # ][ # # ]: 0 : maChildMap[xCell] = xAccessibleCell;
219 [ # # ]: 0 : aTempChildMap.erase( iter );
220 : : }
221 : :
222 : 0 : ++nChildIndex;
223 : 0 : }
224 : : }
225 : :
226 : : // all accessible cell instances still left in aTempChildMap must be disposed
227 : : // as they are no longer part of the table
228 : :
229 [ # # ][ # # ]: 0 : for( AccessibleCellMap::iterator iter( aTempChildMap.begin() ); iter != aTempChildMap.end(); ++iter )
[ # # ]
230 : : {
231 [ # # ][ # # ]: 0 : (*iter).second->dispose();
232 [ # # ][ # # ]: 0 : }
233 : : }
234 : 0 : catch( Exception& )
235 : : {
236 : : OSL_FAIL("svx::AccessibleTableShape::modified(), exception caught!");
237 : : }
238 : 0 : }
239 : :
240 : : // XEventListener
241 : 0 : void SAL_CALL AccessibleTableShapeImpl::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
242 : : {
243 : 0 : }
244 : :
245 : : //-----------------------------------------------------------------------------
246 : : // AccessibleTableShape
247 : : //-----------------------------------------------------------------------------
248 : :
249 : : //-----------------------------------------------------------------------------
250 : :
251 : 0 : AccessibleTableShape::AccessibleTableShape( const AccessibleShapeInfo& rShapeInfo, const AccessibleShapeTreeInfo& rShapeTreeInfo)
252 : : : AccessibleTableShape_Base(rShapeInfo, rShapeTreeInfo)
253 [ # # ][ # # ]: 0 : , mxImpl( new AccessibleTableShapeImpl( maShapeTreeInfo ) )
254 : : {
255 : 0 : }
256 : :
257 : : //-----------------------------------------------------------------------------
258 : :
259 [ # # ]: 0 : AccessibleTableShape::~AccessibleTableShape (void)
260 : : {
261 [ # # ]: 0 : }
262 : :
263 : : //-----------------------------------------------------------------------------
264 : :
265 : 0 : void AccessibleTableShape::Init()
266 : : {
267 : : try
268 : : {
269 : :
270 [ # # ]: 0 : Reference< XPropertySet > xSet( mxShape, UNO_QUERY_THROW );
271 [ # # ][ # # ]: 0 : Reference< XTable > xTable( xSet->getPropertyValue(C2U("Model")), UNO_QUERY_THROW );
[ # # ][ # # ]
272 : :
273 [ # # ][ # # ]: 0 : mxImpl->init( this, xTable );
[ # # ]
274 : : }
275 : 0 : catch( Exception& )
276 : : {
277 : : OSL_FAIL("AccessibleTableShape::init(), exception caught?");
278 : : }
279 : :
280 : 0 : AccessibleTableShape_Base::Init();
281 : 0 : }
282 : :
283 : : //-----------------------------------------------------------------------------
284 : :
285 : 0 : SvxTableController* AccessibleTableShape::getTableController()
286 : : {
287 : 0 : SdrView* pView = maShapeTreeInfo.GetSdrView ();
288 [ # # ]: 0 : if( pView )
289 [ # # ]: 0 : return dynamic_cast< SvxTableController* >( pView->getSelectionController().get() );
290 : : else
291 : 0 : return 0;
292 : : }
293 : :
294 : : //-----------------------------------------------------------------------------
295 : : // XInterface
296 : : //-----------------------------------------------------------------------------
297 : :
298 : 0 : Any SAL_CALL AccessibleTableShape::queryInterface( const Type& aType ) throw (RuntimeException)
299 : : {
300 : 0 : return AccessibleTableShape_Base::queryInterface( aType );
301 : : }
302 : :
303 : : //-----------------------------------------------------------------------------
304 : :
305 : 0 : void SAL_CALL AccessibleTableShape::acquire( ) throw ()
306 : : {
307 : 0 : AccessibleTableShape_Base::acquire();
308 : 0 : }
309 : :
310 : : //-----------------------------------------------------------------------------
311 : :
312 : 0 : void SAL_CALL AccessibleTableShape::release( ) throw ()
313 : : {
314 : 0 : AccessibleTableShape_Base::release();
315 : 0 : }
316 : :
317 : : //-----------------------------------------------------------------------------
318 : : // XAccessible
319 : : //-----------------------------------------------------------------------------
320 : :
321 : 0 : Reference< XAccessibleContext > SAL_CALL AccessibleTableShape::getAccessibleContext(void) throw (RuntimeException)
322 : : {
323 : 0 : return AccessibleShape::getAccessibleContext ();
324 : : }
325 : :
326 : : //-----------------------------------------------------------------------------
327 : 0 : OUString SAL_CALL AccessibleTableShape::getImplementationName(void) throw (RuntimeException)
328 : : {
329 : 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.accessibility.AccessibleTableShape" ) );
330 : : }
331 : :
332 : : //-----------------------------------------------------------------------------
333 : :
334 : 0 : OUString AccessibleTableShape::CreateAccessibleBaseName(void) throw (RuntimeException)
335 : : {
336 : 0 : return OUString (RTL_CONSTASCII_USTRINGPARAM("TableShape"));
337 : : }
338 : :
339 : : //--------------------------------------------------------------------
340 : :
341 : 0 : sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleChildCount( ) throw(RuntimeException)
342 : : {
343 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
344 [ # # ][ # # ]: 0 : return mxImpl->mxTable.is() ? mxImpl->mxTable->getRowCount() * mxImpl->mxTable->getColumnCount() : 0;
[ # # ][ # # ]
[ # # ][ # # ]
345 : : }
346 : :
347 : : //--------------------------------------------------------------------
348 : 0 : Reference< XAccessible > SAL_CALL AccessibleTableShape::getAccessibleChild( sal_Int32 i ) throw(IndexOutOfBoundsException, RuntimeException)
349 : : {
350 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
351 [ # # ]: 0 : ThrowIfDisposed();
352 : :
353 [ # # ][ # # ]: 0 : return mxImpl->getAccessibleChild( i );
354 : : }
355 : :
356 : : //--------------------------------------------------------------------
357 : 0 : Reference< XAccessibleRelationSet > SAL_CALL AccessibleTableShape::getAccessibleRelationSet( ) throw (RuntimeException)
358 : : {
359 : 0 : return AccessibleShape::getAccessibleRelationSet( );
360 : : }
361 : :
362 : : //--------------------------------------------------------------------
363 : :
364 : 0 : sal_Int16 SAL_CALL AccessibleTableShape::getAccessibleRole (void) throw (RuntimeException)
365 : : {
366 : 0 : return AccessibleRole::TABLE;
367 : : }
368 : :
369 : : //--------------------------------------------------------------------
370 : :
371 : 0 : void SAL_CALL AccessibleTableShape::disposing (void)
372 : : {
373 : 0 : mxImpl->dispose();
374 : :
375 : : // let the base do it's stuff
376 : 0 : AccessibleShape::disposing();
377 : 0 : }
378 : :
379 : : //--------------------------------------------------------------------
380 : : // XAccessibleTable
381 : : //--------------------------------------------------------------------
382 : :
383 : 0 : sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleRowCount() throw (RuntimeException)
384 : : {
385 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
386 [ # # ][ # # ]: 0 : return mxImpl->mxTable.is() ? mxImpl->mxTable->getRowCount() : 0;
[ # # ][ # # ]
387 : : }
388 : :
389 : : //--------------------------------------------------------------------
390 : :
391 : 0 : sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleColumnCount( ) throw (RuntimeException)
392 : : {
393 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
394 [ # # ][ # # ]: 0 : return mxImpl->mxTable.is() ? mxImpl->mxTable->getColumnCount() : 0;
[ # # ][ # # ]
395 : : }
396 : :
397 : : //--------------------------------------------------------------------
398 : :
399 : 0 : OUString SAL_CALL AccessibleTableShape::getAccessibleRowDescription( sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
400 : : {
401 : 0 : checkCellPosition( 0, nRow );
402 : 0 : return OUString();
403 : : }
404 : :
405 : : //--------------------------------------------------------------------
406 : :
407 : 0 : OUString SAL_CALL AccessibleTableShape::getAccessibleColumnDescription( sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
408 : : {
409 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
410 [ # # ]: 0 : checkCellPosition( nColumn, 0 );
411 [ # # ]: 0 : return OUString();
412 : : }
413 : :
414 : : //--------------------------------------------------------------------
415 : :
416 : 0 : sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleRowExtentAt( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
417 : : {
418 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
419 [ # # ]: 0 : checkCellPosition( nColumn, nRow );
420 [ # # ]: 0 : if( mxImpl->mxTable.is() )
421 : : {
422 [ # # ][ # # ]: 0 : Reference< XMergeableCell > xCell( mxImpl->mxTable->getCellByPosition( nColumn, nRow ), UNO_QUERY );
[ # # ]
423 [ # # ]: 0 : if( xCell.is() )
424 [ # # ][ # # ]: 0 : return xCell->getRowSpan();
[ # # ]
425 : : }
426 [ # # ]: 0 : return 1;
427 : : }
428 : :
429 : : //--------------------------------------------------------------------
430 : :
431 : 0 : sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleColumnExtentAt( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
432 : : {
433 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
434 [ # # ]: 0 : checkCellPosition( nColumn, nRow );
435 [ # # ]: 0 : if( mxImpl->mxTable.is() )
436 : : {
437 [ # # ][ # # ]: 0 : Reference< XMergeableCell > xCell( mxImpl->mxTable->getCellByPosition( nColumn, nRow ), UNO_QUERY );
[ # # ]
438 [ # # ]: 0 : if( xCell.is() )
439 [ # # ][ # # ]: 0 : return xCell->getColumnSpan();
[ # # ]
440 : : }
441 [ # # ]: 0 : return 1;
442 : : }
443 : :
444 : : //--------------------------------------------------------------------
445 : :
446 : 0 : Reference< XAccessibleTable > SAL_CALL AccessibleTableShape::getAccessibleRowHeaders( ) throw (RuntimeException)
447 : : {
448 : 0 : Reference< XAccessibleTable > xRet( this ); // todo
449 : 0 : return xRet;
450 : : }
451 : :
452 : : //--------------------------------------------------------------------
453 : :
454 : 0 : Reference< XAccessibleTable > SAL_CALL AccessibleTableShape::getAccessibleColumnHeaders( ) throw (RuntimeException)
455 : : {
456 : 0 : Reference< XAccessibleTable > xRet( this ); // todo
457 : 0 : return xRet;
458 : : }
459 : :
460 : : //--------------------------------------------------------------------
461 : :
462 : 0 : Sequence< sal_Int32 > SAL_CALL AccessibleTableShape::getSelectedAccessibleRows( ) throw (RuntimeException)
463 : : {
464 : 0 : Sequence< sal_Int32 > aRet;
465 : 0 : return aRet;
466 : : }
467 : :
468 : : //--------------------------------------------------------------------
469 : :
470 : 0 : Sequence< sal_Int32 > SAL_CALL AccessibleTableShape::getSelectedAccessibleColumns( ) throw (RuntimeException)
471 : : {
472 : 0 : Sequence< sal_Int32 > aRet;
473 : 0 : return aRet;
474 : : }
475 : :
476 : : //--------------------------------------------------------------------
477 : :
478 : 0 : sal_Bool SAL_CALL AccessibleTableShape::isAccessibleRowSelected( sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
479 : : {
480 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
481 [ # # ]: 0 : checkCellPosition( 0, nRow );
482 [ # # ]: 0 : return sal_False;
483 : : }
484 : :
485 : : //--------------------------------------------------------------------
486 : :
487 : 0 : sal_Bool SAL_CALL AccessibleTableShape::isAccessibleColumnSelected( sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
488 : : {
489 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
490 [ # # ]: 0 : checkCellPosition( nColumn, 0 );
491 [ # # ]: 0 : return sal_False;
492 : : }
493 : :
494 : : //--------------------------------------------------------------------
495 : :
496 : 0 : Reference< XAccessible > SAL_CALL AccessibleTableShape::getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
497 : : {
498 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
499 [ # # ]: 0 : checkCellPosition( nColumn, nRow );
500 : :
501 : 0 : sal_Int32 nChildIndex = 0;
502 [ # # ]: 0 : if( mxImpl->mxTable.is() )
503 [ # # ][ # # ]: 0 : nChildIndex = mxImpl->mxTable->getColumnCount() * nRow + nColumn;
504 : :
505 [ # # ][ # # ]: 0 : return getAccessibleChild( nChildIndex );
506 : : }
507 : :
508 : : //--------------------------------------------------------------------
509 : :
510 : 0 : Reference< XAccessible > SAL_CALL AccessibleTableShape::getAccessibleCaption( ) throw (RuntimeException)
511 : : {
512 : 0 : Reference< XAccessible > xRet;
513 : 0 : return xRet;
514 : : }
515 : :
516 : : //--------------------------------------------------------------------
517 : :
518 : 0 : Reference< XAccessible > SAL_CALL AccessibleTableShape::getAccessibleSummary( ) throw (RuntimeException)
519 : : {
520 : 0 : Reference< XAccessible > xRet;
521 : 0 : return xRet;
522 : : }
523 : :
524 : : //--------------------------------------------------------------------
525 : :
526 : 0 : sal_Bool SAL_CALL AccessibleTableShape::isAccessibleSelected( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
527 : : {
528 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
529 [ # # ]: 0 : checkCellPosition( nColumn, nRow );
530 : :
531 [ # # ]: 0 : SvxTableController* pController = getTableController();
532 [ # # ][ # # ]: 0 : if( pController && pController->hasSelectedCells() )
[ # # ][ # # ]
533 : : {
534 : 0 : CellPos aFirstPos, aLastPos;
535 [ # # ]: 0 : pController->getSelectedCells( aFirstPos, aLastPos );
536 [ # # ][ # # ]: 0 : if( (aFirstPos.mnRow <= nRow) && (aFirstPos.mnCol <= nColumn) && (nRow <= aLastPos.mnRow) && (nColumn <= aLastPos.mnCol) )
[ # # ][ # # ]
537 : 0 : return sal_True;
538 : : }
539 : :
540 [ # # ]: 0 : return sal_False;
541 : : }
542 : :
543 : : //--------------------------------------------------------------------
544 : :
545 : 0 : sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleIndex( sal_Int32 nRow, sal_Int32 nColumn ) throw (IndexOutOfBoundsException, RuntimeException)
546 : : {
547 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
548 [ # # ]: 0 : checkCellPosition( nColumn, nRow );
549 [ # # ][ # # ]: 0 : return mxImpl->mxTable.is() ? (nRow * mxImpl->mxTable->getColumnCount() + nColumn) : 0;
[ # # ][ # # ]
550 : : }
551 : :
552 : : //--------------------------------------------------------------------
553 : :
554 : 0 : sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleRow( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
555 : : {
556 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
557 : 0 : sal_Int32 nColumn = 0, nRow = 0;
558 [ # # ]: 0 : mxImpl->getColumnAndRow( nChildIndex, nColumn, nRow );
559 [ # # ]: 0 : return nRow;
560 : : }
561 : :
562 : : //--------------------------------------------------------------------
563 : :
564 : 0 : sal_Int32 SAL_CALL AccessibleTableShape::getAccessibleColumn( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
565 : : {
566 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
567 : 0 : sal_Int32 nColumn = 0, nRow = 0;
568 [ # # ]: 0 : mxImpl->getColumnAndRow( nChildIndex, nColumn, nRow );
569 [ # # ]: 0 : return nChildIndex;
570 : : }
571 : :
572 : : //--------------------------------------------------------------------
573 : : // XAccessibleSelection
574 : : //--------------------------------------------------------------------
575 : :
576 : 0 : void SAL_CALL AccessibleTableShape::selectAccessibleChild( sal_Int32 nChildIndex ) throw ( IndexOutOfBoundsException, RuntimeException )
577 : : {
578 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
579 : 0 : CellPos aPos;
580 [ # # ]: 0 : mxImpl->getColumnAndRow( nChildIndex, aPos.mnCol, aPos.mnRow );
581 : :
582 : : // todo, select table shape?!?
583 [ # # ]: 0 : SvxTableController* pController = getTableController();
584 [ # # ]: 0 : if( pController )
585 : : {
586 : 0 : CellPos aFirstPos( aPos ), aLastPos( aPos );
587 [ # # ][ # # ]: 0 : if( pController->hasSelectedCells() )
588 : : {
589 [ # # ]: 0 : pController->getSelectedCells( aFirstPos, aLastPos );
590 : :
591 [ # # ]: 0 : aFirstPos.mnRow = std::min( aFirstPos.mnRow, aPos.mnRow );
592 [ # # ]: 0 : aFirstPos.mnCol = std::min( aFirstPos.mnCol, aPos.mnCol );
593 [ # # ]: 0 : aLastPos.mnRow = std::max( aLastPos.mnRow, aPos.mnRow );
594 [ # # ]: 0 : aLastPos.mnCol = std::max( aLastPos.mnCol, aPos.mnCol );
595 : : }
596 [ # # ]: 0 : pController->setSelectedCells( aFirstPos, aLastPos );
597 [ # # ]: 0 : }
598 : 0 : }
599 : :
600 : : //--------------------------------------------------------------------
601 : :
602 : 0 : sal_Bool SAL_CALL AccessibleTableShape::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw ( IndexOutOfBoundsException, RuntimeException )
603 : : {
604 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
605 : 0 : CellPos aPos;
606 [ # # ]: 0 : mxImpl->getColumnAndRow( nChildIndex, aPos.mnCol, aPos.mnRow );
607 : :
608 [ # # ][ # # ]: 0 : return isAccessibleSelected(aPos.mnCol, aPos.mnRow);
609 : : }
610 : :
611 : : //--------------------------------------------------------------------
612 : :
613 : 0 : void SAL_CALL AccessibleTableShape::clearAccessibleSelection() throw ( RuntimeException )
614 : : {
615 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
616 : :
617 [ # # ]: 0 : SvxTableController* pController = getTableController();
618 [ # # ]: 0 : if( pController )
619 [ # # ][ # # ]: 0 : pController->clearSelection();
620 : 0 : }
621 : : //--------------------------------------------------------------------
622 : :
623 : 0 : void SAL_CALL AccessibleTableShape::selectAllAccessibleChildren() throw ( RuntimeException )
624 : : {
625 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
626 : :
627 : : // todo: force selection of shape?
628 [ # # ]: 0 : SvxTableController* pController = getTableController();
629 [ # # ]: 0 : if( pController )
630 [ # # ][ # # ]: 0 : pController->selectAll();
631 : 0 : }
632 : :
633 : : //--------------------------------------------------------------------
634 : :
635 : 0 : sal_Int32 SAL_CALL AccessibleTableShape::getSelectedAccessibleChildCount() throw ( RuntimeException )
636 : : {
637 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
638 : :
639 [ # # ]: 0 : SvxTableController* pController = getTableController();
640 [ # # ][ # # ]: 0 : if( pController && pController->hasSelectedCells() )
[ # # ][ # # ]
641 : : {
642 : 0 : CellPos aFirstPos, aLastPos;
643 [ # # ]: 0 : pController->getSelectedCells( aFirstPos, aLastPos );
644 : :
645 [ # # ]: 0 : const sal_Int32 nSelectedColumns = std::max( (sal_Int32)0, aLastPos.mnCol - aFirstPos.mnCol ) + 1;
646 [ # # ]: 0 : const sal_Int32 nSelectedRows = std::max( (sal_Int32)0, aLastPos.mnRow - aFirstPos.mnRow ) + 1;
647 : 0 : return nSelectedRows * nSelectedColumns;
648 : : }
649 : :
650 [ # # ]: 0 : return 0;
651 : : }
652 : :
653 : : //--------------------------------------------------------------------
654 : :
655 : 0 : Reference< XAccessible > SAL_CALL AccessibleTableShape::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw ( IndexOutOfBoundsException, RuntimeException)
656 : : {
657 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
658 : :
659 [ # # ]: 0 : SvxTableController* pController = getTableController();
660 [ # # ][ # # ]: 0 : if( pController && pController->hasSelectedCells() )
[ # # ][ # # ]
661 : : {
662 : 0 : CellPos aFirstPos, aLastPos;
663 [ # # ]: 0 : pController->getSelectedCells( aFirstPos, aLastPos );
664 : :
665 [ # # ]: 0 : const sal_Int32 nSelectedColumns = std::max( (sal_Int32)0, aLastPos.mnCol - aFirstPos.mnCol ) + 1;
666 [ # # ]: 0 : const sal_Int32 nSelectedRows = std::max( (sal_Int32)0, aLastPos.mnRow - aFirstPos.mnRow ) + 1;
667 : :
668 [ # # ]: 0 : if( nSelectedChildIndex < (nSelectedRows * nSelectedColumns) )
669 : : {
670 [ # # ]: 0 : while( nSelectedChildIndex >= nSelectedColumns )
671 : : {
672 : 0 : aFirstPos.mnRow++;
673 : 0 : nSelectedChildIndex -= nSelectedColumns;
674 : : }
675 [ # # ]: 0 : return getAccessibleCellAt( nSelectedColumns, aFirstPos.mnRow );
676 : : }
677 : : }
678 : :
679 [ # # ][ # # ]: 0 : throw IndexOutOfBoundsException();
680 : : }
681 : :
682 : : //--------------------------------------------------------------------
683 : :
684 : 0 : void SAL_CALL AccessibleTableShape::deselectAccessibleChild( sal_Int32 nChildIndex ) throw ( IndexOutOfBoundsException, RuntimeException )
685 : : {
686 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
687 : 0 : CellPos aPos;
688 [ # # ]: 0 : mxImpl->getColumnAndRow( nChildIndex, aPos.mnCol, aPos.mnRow );
689 : :
690 : : // todo, select table shape?!?
691 [ # # ]: 0 : SvxTableController* pController = getTableController();
692 [ # # ][ # # ]: 0 : if( pController && pController->hasSelectedCells() )
[ # # ][ # # ]
693 : : {
694 : 0 : CellPos aFirstPos, aLastPos;
695 [ # # ]: 0 : pController->getSelectedCells( aFirstPos, aLastPos );
696 : :
697 : : // create a selection where aPos is not part of anymore
698 [ # # ]: 0 : aFirstPos.mnRow = std::min( aFirstPos.mnRow, aPos.mnRow+1 );
699 [ # # ]: 0 : aFirstPos.mnCol = std::min( aFirstPos.mnCol, aPos.mnCol+1 );
700 [ # # ]: 0 : aLastPos.mnRow = std::max( aLastPos.mnRow, aPos.mnRow-1 );
701 [ # # ]: 0 : aLastPos.mnCol = std::max( aLastPos.mnCol, aPos.mnCol-1 );
702 : :
703 : : // new selection may be invalid (child to deselect is not at a border of the selection but in between)
704 [ # # ][ # # ]: 0 : if( (aFirstPos.mnRow > aLastPos.mnRow) || (aFirstPos.mnCol > aLastPos.mnCol) )
705 [ # # ]: 0 : pController->clearSelection(); // if selection is invalid, clear all
706 : : else
707 [ # # ]: 0 : pController->setSelectedCells( aFirstPos, aLastPos );
708 [ # # ]: 0 : }
709 : 0 : }
710 : :
711 : : //--------------------------------------------------------------------
712 : :
713 : 0 : void AccessibleTableShape::checkCellPosition( sal_Int32 nCol, sal_Int32 nRow ) throw ( IndexOutOfBoundsException )
714 : : {
715 [ # # ][ # # ]: 0 : if( (nCol >= 0) && (nRow >= 0) && mxImpl->mxTable.is() && (nCol < mxImpl->mxTable->getColumnCount()) && (nRow < mxImpl->mxTable->getRowCount()) )
[ # # ][ # # ]
[ # # ][ # # ]
716 : 0 : return;
717 : :
718 [ # # ]: 0 : throw IndexOutOfBoundsException();
719 : : }
720 : :
721 : : }
722 : :
723 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|