merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / access / acctable.cxx
blob828dc2a50013a326a734e626b26ba5ff5a697194
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: acctable.cxx,v $
10 * $Revision: 1.33 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <vos/mutex.hxx>
34 #include <rtl/uuid.h>
35 #include <rtl/ustrbuf.hxx>
37 #include <list>
38 #include <set>
39 #include <com/sun/star/accessibility/AccessibleRole.hpp>
40 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
41 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
42 #include <com/sun/star/accessibility/AccessibleTableModelChange.hpp>
43 #include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp>
44 #include <unotools/accessiblestatesethelper.hxx>
45 #include <vcl/svapp.hxx>
46 #include <frmfmt.hxx>
47 #include <tabfrm.hxx>
48 // --> OD 2007-06-27 #i77106#
49 #include <rowfrm.hxx>
50 // <--
51 #include <cellfrm.hxx>
52 #include <swtable.hxx>
53 #include "crsrsh.hxx"
54 #include "viscrs.hxx"
55 #include <hints.hxx>
56 #include "fesh.hxx"
57 #include <accfrmobjslist.hxx>
58 #include "accmap.hxx"
59 #ifndef _ACCESS_HRC
60 #include "access.hrc"
61 #endif
62 #include <acctable.hxx>
64 using namespace ::com::sun::star;
65 using namespace ::com::sun::star::accessibility;
66 using ::rtl::OUString;
67 using ::rtl::OUStringBuffer;
69 const sal_Char sServiceName[] = "com.sun.star.table.AccessibleTableView";
70 const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleTableView";
72 typedef ::std::less < sal_Int32 > Int32Less_Impl;
73 typedef ::std::set < sal_Int32, Int32Less_Impl > Int32Set_Impl;
75 typedef ::std::pair < sal_Int32, sal_Int32 > Int32Pair_Impl;
76 typedef ::std::list < Int32Pair_Impl > Int32PairList_Impl;
78 class SwAccTableSelHander_Impl
80 public:
81 virtual void Unselect( sal_Int32 nRowOrCol, sal_Int32 nExt ) = 0;
85 //------------------------------------------------------------------------------
87 class SwAccessibleTableData_Impl
89 Int32Set_Impl maRows;
90 Int32Set_Impl maColumns;
91 Int32PairList_Impl maExtents; // cell extends for event processing only
92 Point maTabFrmPos;
93 const SwTabFrm *mpTabFrm;
94 sal_Bool mbIsInPagePreview;
95 // --> OD 2007-06-27 #i77106#
96 bool mbOnlyTableColumnHeader;
97 // <--
99 void CollectData( const SwFrm *pFrm );
100 void CollectExtents( const SwFrm *pFrm );
102 sal_Bool FindCell( const Point& rPos, const SwFrm *pFrm ,
103 sal_Bool bExact, const SwFrm *& rFrm ) const;
105 void GetSelection( const Point& rTabPos, const SwRect& rArea,
106 const SwSelBoxes& rSelBoxes, const SwFrm *pFrm,
107 SwAccTableSelHander_Impl& rSelHdl,
108 sal_Bool bColumns ) const;
110 // --> OD 2007-06-27 #i77106#
111 inline bool IncludeRow( const SwFrm& rFrm ) const
113 return !mbOnlyTableColumnHeader ||
114 mpTabFrm->IsInHeadline( rFrm );
116 // <--
117 public:
118 // --> OD 2007-06-27 #i77106#
119 // add third optional parameter <bOnlyTableColumnHeader>, default value <false>
120 SwAccessibleTableData_Impl( const SwTabFrm *pTabFrm,
121 sal_Bool bIsInPagePreview,
122 bool bOnlyTableColumnHeader = false );
123 // <--
125 const Int32Set_Impl& GetRows() const { return maRows; }
126 const Int32Set_Impl& GetColumns() const { return maColumns; }
128 inline Int32Set_Impl::const_iterator GetRowIter( sal_Int32 nRow ) const;
129 inline Int32Set_Impl::const_iterator GetColumnIter( sal_Int32 nCol ) const;
131 const SwFrm *GetCell( sal_Int32 nRow, sal_Int32 nColumn, sal_Bool bExact,
132 SwAccessibleTable *pThis ) const
133 throw(lang::IndexOutOfBoundsException );
134 const SwFrm *GetCellAtPos( sal_Int32 nLeft, sal_Int32 nTop,
135 sal_Bool bExact ) const;
136 inline sal_Int32 GetRowCount() const;
137 inline sal_Int32 GetColumnCount() const;
138 sal_Bool CompareExtents( const SwAccessibleTableData_Impl& r ) const;
140 void GetSelection( sal_Int32 nStart, sal_Int32 nEnd,
141 const SwSelBoxes& rSelBoxes,
142 SwAccTableSelHander_Impl& rSelHdl,
143 sal_Bool bColumns ) const;
145 void CheckRowAndCol( sal_Int32 nRow, sal_Int32 nCol,
146 SwAccessibleTable *pThis ) const
147 throw(lang::IndexOutOfBoundsException );
149 void GetRowColumnAndExtent( const SwRect& rBox,
150 sal_Int32& rRow, sal_Int32& rColumn,
151 sal_Int32& rRowExtent,
152 sal_Int32& rColumnExtent ) const;
154 const Point& GetTablePos() const { return maTabFrmPos; }
155 void SetTablePos( const Point& rPos ) { maTabFrmPos = rPos; }
158 void SwAccessibleTableData_Impl::CollectData( const SwFrm *pFrm )
160 const SwFrmOrObjSList aList( pFrm );
161 SwFrmOrObjSList::const_iterator aIter( aList.begin() );
162 SwFrmOrObjSList::const_iterator aEndIter( aList.end() );
163 while( aIter != aEndIter )
165 const SwFrmOrObj& rLower = *aIter;
166 const SwFrm *pLower = rLower.GetSwFrm();
167 if( pLower )
169 if( pLower->IsRowFrm() )
171 // --> OD 2007-06-27 #i77106#
172 if ( IncludeRow( *pLower ) )
174 maRows.insert( pLower->Frm().Top() - maTabFrmPos.Y() );
175 CollectData( pLower );
177 // <--
179 else if( pLower->IsCellFrm() &&
180 rLower.IsAccessible( mbIsInPagePreview ) )
182 maColumns.insert( pLower->Frm().Left() - maTabFrmPos.X() );
184 else
186 CollectData( pLower );
189 ++aIter;
193 void SwAccessibleTableData_Impl::CollectExtents( const SwFrm *pFrm )
195 const SwFrmOrObjSList aList( pFrm );
196 SwFrmOrObjSList::const_iterator aIter( aList.begin() );
197 SwFrmOrObjSList::const_iterator aEndIter( aList.end() );
198 while( aIter != aEndIter )
200 const SwFrmOrObj& rLower = *aIter;
201 const SwFrm *pLower = rLower.GetSwFrm();
202 if( pLower )
204 if( pLower->IsCellFrm() &&
205 rLower.IsAccessible( mbIsInPagePreview ) )
207 sal_Int32 nRow, nCol;
208 Int32Pair_Impl aCellExtents;
209 GetRowColumnAndExtent( pLower->Frm(), nRow, nCol,
210 aCellExtents.first,
211 aCellExtents.second );
213 maExtents.push_back( aCellExtents );
215 else
217 // --> OD 2007-06-27 #i77106#
218 if ( !pLower->IsRowFrm() ||
219 IncludeRow( *pLower ) )
221 CollectExtents( pLower );
223 // <--
226 ++aIter;
230 sal_Bool SwAccessibleTableData_Impl::FindCell(
231 const Point& rPos, const SwFrm *pFrm, sal_Bool bExact,
232 const SwFrm *& rRet ) const
234 sal_Bool bFound = sal_False;
236 const SwFrmOrObjSList aList( pFrm );
237 SwFrmOrObjSList::const_iterator aIter( aList.begin() );
238 SwFrmOrObjSList::const_iterator aEndIter( aList.end() );
239 while( !bFound && aIter != aEndIter )
241 const SwFrmOrObj& rLower = *aIter;
242 const SwFrm *pLower = rLower.GetSwFrm();
243 ASSERT( pLower, "child should be a frame" );
244 if( pLower )
246 if( rLower.IsAccessible( mbIsInPagePreview ) )
248 ASSERT( pLower->IsCellFrm(), "lower is not a cell frame" );
249 const SwRect& rFrm = pLower->Frm();
250 if( rFrm.Right() >= rPos.X() && rFrm.Bottom() >= rPos.Y() )
252 // We have found the cell
253 ASSERT( rFrm.Left() <= rPos.X() && rFrm.Top() <= rPos.Y(),
254 "find frame moved to far!" );
255 bFound = sal_True;
256 if( !bExact ||
257 (rFrm.Top() == rPos.Y() && rFrm.Left() == rPos.Y() ) )
259 rRet = pLower;
263 else
265 // --> OD 2007-06-27 #i77106#
266 if ( !pLower->IsRowFrm() ||
267 IncludeRow( *pLower ) )
269 bFound = FindCell( rPos, pLower, bExact, rRet );
271 // <--
274 ++aIter;
277 return bFound;
280 void SwAccessibleTableData_Impl::GetSelection(
281 const Point& rTabPos,
282 const SwRect& rArea,
283 const SwSelBoxes& rSelBoxes,
284 const SwFrm *pFrm,
285 SwAccTableSelHander_Impl& rSelHdl,
286 sal_Bool bColumns ) const
288 const SwFrmOrObjSList aList( pFrm );
289 SwFrmOrObjSList::const_iterator aIter( aList.begin() );
290 SwFrmOrObjSList::const_iterator aEndIter( aList.end() );
291 while( aIter != aEndIter )
293 const SwFrmOrObj& rLower = *aIter;
294 const SwFrm *pLower = rLower.GetSwFrm();
295 ASSERT( pLower, "child should be a frame" );
296 const SwRect& rBox = rLower.GetBox();
297 if( pLower && rBox.IsOver( rArea ) )
299 if( rLower.IsAccessible( mbIsInPagePreview ) )
301 ASSERT( pLower->IsCellFrm(), "lower is not a cell frame" );
302 const SwCellFrm *pCFrm =
303 static_cast < const SwCellFrm * >( pLower );
304 SwTableBox *pBox =
305 const_cast< SwTableBox *>( pCFrm->GetTabBox() ); //SVPtrArr!
306 if( !rSelBoxes.Seek_Entry( pBox ) )
308 const Int32Set_Impl rRowsOrCols =
309 bColumns ? maColumns : maRows;
311 sal_Int32 nPos = bColumns ? (rBox.Left() - rTabPos.X())
312 : (rBox.Top() - rTabPos.Y());
313 Int32Set_Impl::const_iterator aSttRowOrCol(
314 rRowsOrCols.lower_bound( nPos ) );
315 sal_Int32 nRowOrCol =
316 static_cast< sal_Int32 >( ::std::distance(
317 rRowsOrCols.begin(), aSttRowOrCol ) );
319 nPos = bColumns ? (rBox.Right() - rTabPos.X())
320 : (rBox.Bottom() - rTabPos.Y());
321 Int32Set_Impl::const_iterator aEndRowOrCol(
322 rRowsOrCols.upper_bound( nPos ) );
323 sal_Int32 nExt =
324 static_cast< sal_Int32 >( ::std::distance(
325 aSttRowOrCol, aEndRowOrCol ) );
327 rSelHdl.Unselect( nRowOrCol, nExt );
330 else
332 // --> OD 2007-06-27 #i77106#
333 if ( !pLower->IsRowFrm() ||
334 IncludeRow( *pLower ) )
336 GetSelection( rTabPos, rArea, rSelBoxes, pLower, rSelHdl,
337 bColumns );
339 // <--
342 ++aIter;
346 const SwFrm *SwAccessibleTableData_Impl::GetCell(
347 sal_Int32 nRow, sal_Int32 nColumn, sal_Bool,
348 SwAccessibleTable *pThis ) const
349 throw(lang::IndexOutOfBoundsException )
351 CheckRowAndCol( nRow, nColumn, pThis );
353 Int32Set_Impl::const_iterator aSttCol( GetColumnIter( nColumn ) );
354 Int32Set_Impl::const_iterator aSttRow( GetRowIter( nRow ) );
355 const SwFrm *pCellFrm = GetCellAtPos( *aSttCol, *aSttRow, sal_False );
357 return pCellFrm;
360 void SwAccessibleTableData_Impl::GetSelection(
361 sal_Int32 nStart, sal_Int32 nEnd,
362 const SwSelBoxes& rSelBoxes,
363 SwAccTableSelHander_Impl& rSelHdl,
364 sal_Bool bColumns ) const
366 SwRect aArea( mpTabFrm->Frm() );
367 Point aPos( aArea.Pos() );
369 const Int32Set_Impl& rRowsOrColumns = bColumns ? maColumns : maRows;
370 if( nStart > 0 )
372 Int32Set_Impl::const_iterator aStt( rRowsOrColumns.begin() );
373 ::std::advance( aStt,
374 static_cast< Int32Set_Impl::difference_type >( nStart ) );
375 if( bColumns )
376 aArea.Left( *aStt + aPos.X() );
377 else
378 aArea.Top( *aStt + aPos.Y() );
380 if( nEnd < static_cast< sal_Int32 >( rRowsOrColumns.size() ) )
382 Int32Set_Impl::const_iterator aEnd( rRowsOrColumns.begin() );
383 ::std::advance( aEnd,
384 static_cast< Int32Set_Impl::difference_type >( nEnd ) );
385 if( bColumns )
386 aArea.Right( *aEnd + aPos.X() - 1 );
387 else
388 aArea.Bottom( *aEnd + aPos.Y() - 1 );
391 GetSelection( aPos, aArea, rSelBoxes, mpTabFrm, rSelHdl, bColumns );
394 const SwFrm *SwAccessibleTableData_Impl::GetCellAtPos(
395 sal_Int32 nLeft, sal_Int32 nTop, sal_Bool bExact ) const
397 Point aPos( mpTabFrm->Frm().Pos() );
398 aPos.Move( nLeft, nTop );
399 const SwFrm *pRet = 0;
400 FindCell( aPos, mpTabFrm, bExact, pRet );
402 return pRet;
405 inline sal_Int32 SwAccessibleTableData_Impl::GetRowCount() const
407 return static_cast< sal_Int32 >( maRows.size() );
410 inline sal_Int32 SwAccessibleTableData_Impl::GetColumnCount() const
412 return static_cast< sal_Int32 >( maColumns.size() );
415 sal_Bool SwAccessibleTableData_Impl::CompareExtents(
416 const SwAccessibleTableData_Impl& rCmp ) const
418 if( maExtents.size() != rCmp.maExtents.size() )
419 return sal_False;
421 Int32PairList_Impl::const_iterator aIter( maExtents.begin() );
422 Int32PairList_Impl::const_iterator aEndIter( maExtents.end() );
423 Int32PairList_Impl::const_iterator aCmpIter( rCmp.maExtents.begin() );
424 while( aIter != aEndIter )
426 if( *aIter != *aCmpIter )
427 return sal_False;
429 ++aIter;
430 ++aCmpIter;
433 return sal_True;
436 SwAccessibleTableData_Impl::SwAccessibleTableData_Impl( const SwTabFrm *pTabFrm,
437 sal_Bool bIsInPagePreview,
438 bool bOnlyTableColumnHeader )
439 : maTabFrmPos( pTabFrm->Frm().Pos() ),
440 mpTabFrm( pTabFrm ),
441 mbIsInPagePreview( bIsInPagePreview ),
442 // --> OD 2007-06-27 #i77106#
443 mbOnlyTableColumnHeader( bOnlyTableColumnHeader )
444 // <--
446 CollectData( mpTabFrm );
447 CollectExtents( mpTabFrm );
450 inline Int32Set_Impl::const_iterator SwAccessibleTableData_Impl::GetRowIter(
451 sal_Int32 nRow ) const
453 Int32Set_Impl::const_iterator aCol( GetRows().begin() );
454 if( nRow > 0 )
456 ::std::advance( aCol,
457 static_cast< Int32Set_Impl::difference_type >( nRow ) );
459 return aCol;
462 inline Int32Set_Impl::const_iterator SwAccessibleTableData_Impl::GetColumnIter(
463 sal_Int32 nColumn ) const
465 Int32Set_Impl::const_iterator aCol = GetColumns().begin();
466 if( nColumn > 0 )
468 ::std::advance( aCol,
469 static_cast< Int32Set_Impl::difference_type >( nColumn ) );
471 return aCol;
474 void SwAccessibleTableData_Impl::CheckRowAndCol(
475 sal_Int32 nRow, sal_Int32 nCol, SwAccessibleTable *pThis ) const
476 throw(lang::IndexOutOfBoundsException )
478 if( ( nRow < 0 || nRow >= static_cast< sal_Int32 >( maRows.size() ) ) ||
479 ( nCol < 0 || nCol >= static_cast< sal_Int32 >( maColumns.size() ) ) )
481 uno::Reference < XAccessibleTable > xThis( pThis );
482 lang::IndexOutOfBoundsException aExcept(
483 OUString( RTL_CONSTASCII_USTRINGPARAM(
484 "row or column index out of range") ),
485 xThis );
486 throw aExcept;
490 void SwAccessibleTableData_Impl::GetRowColumnAndExtent(
491 const SwRect& rBox,
492 sal_Int32& rRow, sal_Int32& rColumn,
493 sal_Int32& rRowExtent, sal_Int32& rColumnExtent ) const
495 Int32Set_Impl::const_iterator aStt(
496 maRows.lower_bound( rBox.Top() - maTabFrmPos.Y() ) );
497 Int32Set_Impl::const_iterator aEnd(
498 maRows.upper_bound( rBox.Bottom() - maTabFrmPos.Y() ) );
499 rRow =
500 static_cast< sal_Int32 >( ::std::distance( maRows.begin(), aStt ) );
501 rRowExtent =
502 static_cast< sal_Int32 >( ::std::distance( aStt, aEnd ) );
504 aStt = maColumns.lower_bound( rBox.Left() - maTabFrmPos.X() );
505 aEnd = maColumns.upper_bound( rBox.Right() - maTabFrmPos.X() );
506 rColumn =
507 static_cast< sal_Int32 >( ::std::distance( maColumns.begin(), aStt ) );
508 rColumnExtent =
509 static_cast< sal_Int32 >( ::std::distance( aStt, aEnd ) );
512 //------------------------------------------------------------------------------
514 class SwAccSingleTableSelHander_Impl : public SwAccTableSelHander_Impl
516 sal_Bool bSelected;
518 public:
520 inline SwAccSingleTableSelHander_Impl();
522 inline sal_Bool IsSelected() const { return bSelected; }
524 virtual void Unselect( sal_Int32, sal_Int32 );
527 inline SwAccSingleTableSelHander_Impl::SwAccSingleTableSelHander_Impl() :
528 bSelected( sal_True )
532 void SwAccSingleTableSelHander_Impl::Unselect( sal_Int32, sal_Int32 )
534 bSelected = sal_False;
537 //------------------------------------------------------------------------------
539 class SwAccAllTableSelHander_Impl : public SwAccTableSelHander_Impl
542 ::std::vector< sal_Bool > aSelected;
543 sal_Int32 nCount;
545 public:
547 inline SwAccAllTableSelHander_Impl( sal_Int32 nSize );
549 uno::Sequence < sal_Int32 > GetSelSequence();
551 virtual void Unselect( sal_Int32 nRowOrCol, sal_Int32 nExt );
552 virtual ~SwAccAllTableSelHander_Impl();
555 SwAccAllTableSelHander_Impl::~SwAccAllTableSelHander_Impl()
559 inline SwAccAllTableSelHander_Impl::SwAccAllTableSelHander_Impl( sal_Int32 nSize ) :
560 aSelected( nSize, sal_True ),
561 nCount( nSize )
565 uno::Sequence < sal_Int32 > SwAccAllTableSelHander_Impl::GetSelSequence()
567 ASSERT( nCount >= 0, "underflow" );
568 uno::Sequence < sal_Int32 > aRet( nCount );
569 sal_Int32 *pRet = aRet.getArray();
570 sal_Int32 nPos = 0;
571 size_t nSize = aSelected.size();
572 for( size_t i=0; i < nSize && nPos < nCount; i++ )
574 if( aSelected[i] )
576 *pRet++ = i;
577 nPos++;
581 ASSERT( nPos == nCount, "count is wrong" );
583 return aRet;
586 void SwAccAllTableSelHander_Impl::Unselect( sal_Int32 nRowOrCol,
587 sal_Int32 nExt )
589 ASSERT( static_cast< size_t >( nRowOrCol ) < aSelected.size(),
590 "index to large" );
591 ASSERT( static_cast< size_t >( nRowOrCol+nExt ) <= aSelected.size(),
592 "extent to large" );
593 while( nExt )
595 if( aSelected[static_cast< size_t >( nRowOrCol )] )
597 aSelected[static_cast< size_t >( nRowOrCol )] = sal_False;
598 nCount--;
600 nExt--;
601 nRowOrCol++;
605 //------------------------------------------------------------------------------
607 const SwSelBoxes *SwAccessibleTable::GetSelBoxes() const
609 const SwSelBoxes *pSelBoxes = 0;
610 const SwCrsrShell *pCSh = GetCrsrShell();
611 if( (pCSh != NULL) && pCSh->IsTableMode() )
613 pSelBoxes = &pCSh->GetTableCrsr()->GetBoxes();
616 return pSelBoxes;
619 void SwAccessibleTable::FireTableChangeEvent(
620 const SwAccessibleTableData_Impl& rTableData )
622 AccessibleTableModelChange aModelChange;
623 aModelChange.Type = AccessibleTableModelChangeType::UPDATE;
624 aModelChange.FirstRow = 0;
625 aModelChange.LastRow = rTableData.GetRowCount() - 1;
626 aModelChange.FirstColumn = 0;
627 aModelChange.LastColumn = rTableData.GetColumnCount() - 1;
629 AccessibleEventObject aEvent;
630 aEvent.EventId = AccessibleEventId::TABLE_MODEL_CHANGED;
631 aEvent.NewValue <<= aModelChange;
633 FireAccessibleEvent( aEvent );
637 const SwTableBox* SwAccessibleTable::GetTableBox( sal_Int32 nChildIndex ) const
639 DBG_ASSERT( nChildIndex >= 0, "Illegal child index." );
640 // --> OD 2007-06-27 #i77106#
641 DBG_ASSERT( nChildIndex < const_cast<SwAccessibleTable*>(this)->getAccessibleChildCount(), "Illegal child index." );
642 // <--
644 const SwTableBox* pBox = NULL;
646 // get table box for 'our' table cell
647 SwFrmOrObj aCell( GetChild( nChildIndex ) );
648 if( aCell.GetSwFrm() )
650 const SwFrm* pChildFrm = aCell.GetSwFrm();
651 if( (pChildFrm != NULL) && pChildFrm->IsCellFrm() )
653 const SwCellFrm* pCellFrm =
654 static_cast<const SwCellFrm*>( pChildFrm );
655 pBox = pCellFrm->GetTabBox();
659 DBG_ASSERT( pBox != NULL, "We need the table box." );
660 return pBox;
663 sal_Bool SwAccessibleTable::IsChildSelected( sal_Int32 nChildIndex ) const
665 sal_Bool bRet = sal_False;
666 const SwSelBoxes* pSelBoxes = GetSelBoxes();
667 if( pSelBoxes )
669 const SwTableBox* pBox = GetTableBox( nChildIndex );
670 DBG_ASSERT( pBox != NULL, "We need the table box." );
671 bRet = pSelBoxes->Seek_Entry( const_cast<SwTableBox*>( pBox ) );
674 return bRet;
677 sal_Int32 SwAccessibleTable::GetIndexOfSelectedChild(
678 sal_Int32 nSelectedChildIndex ) const
680 // iterate over all children to n-th isAccessibleChildSelected()
681 // --> OD 2007-06-27 #i77106#
682 sal_Int32 nChildren = const_cast<SwAccessibleTable*>(this)->getAccessibleChildCount();
683 // <--
684 if( nSelectedChildIndex >= nChildren )
685 return -1L;
687 sal_Int32 n = 0;
688 while( n < nChildren )
690 if( IsChildSelected( n ) )
692 if( 0 == nSelectedChildIndex )
693 break;
694 else
695 --nSelectedChildIndex;
697 ++n;
700 return n < nChildren ? n : -1L;
703 void SwAccessibleTable::GetStates(
704 ::utl::AccessibleStateSetHelper& rStateSet )
706 SwAccessibleContext::GetStates( rStateSet );
708 // MULTISELECTABLE
709 SwCrsrShell* pCrsrShell = GetCrsrShell();
710 if( pCrsrShell )
711 rStateSet.AddState( AccessibleStateType::MULTI_SELECTABLE );
714 SwAccessibleTable::SwAccessibleTable(
715 SwAccessibleMap* pInitMap,
716 const SwTabFrm* pTabFrm ) :
717 SwAccessibleContext( pInitMap, AccessibleRole::TABLE, pTabFrm ),
718 mpTableData( 0 )
720 vos::OGuard aGuard(Application::GetSolarMutex());
722 const SwFrmFmt *pFrmFmt = pTabFrm->GetFmt();
723 const_cast< SwFrmFmt * >( pFrmFmt )->Add( this );
724 const String& rName = pFrmFmt->GetName();
726 OUStringBuffer aBuffer( rName.Len() + 4 );
727 aBuffer.append( OUString(rName) );
728 aBuffer.append( static_cast<sal_Unicode>( '-' ) );
729 aBuffer.append( static_cast<sal_Int32>( pTabFrm->GetPhyPageNum() ) );
731 SetName( aBuffer.makeStringAndClear() );
733 OUString sArg1( static_cast< const SwTabFrm * >( GetFrm() )
734 ->GetFmt()->GetName() );
735 OUString sArg2( GetFormattedPageNumber() );
737 sDesc = GetResource( STR_ACCESS_TABLE_DESC, &sArg1, &sArg2 );
740 SwAccessibleTable::~SwAccessibleTable()
742 vos::OGuard aGuard(Application::GetSolarMutex());
744 delete mpTableData;
747 void SwAccessibleTable::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew)
749 sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
750 const SwTabFrm *pTabFrm = static_cast< const SwTabFrm * >( GetFrm() );
751 switch( nWhich )
753 case RES_NAME_CHANGED:
754 if( pTabFrm )
756 const SwFrmFmt *pFrmFmt = pTabFrm->GetFmt();
757 ASSERT( pFrmFmt == GetRegisteredIn(), "invalid frame" );
759 OUString sOldName( GetName() );
761 const String& rNewTabName = pFrmFmt->GetName();
762 OUStringBuffer aBuffer( rNewTabName.Len() + 4 );
763 aBuffer.append( OUString(rNewTabName) );
764 aBuffer.append( static_cast<sal_Unicode>( '-' ) );
765 aBuffer.append( static_cast<sal_Int32>( pTabFrm->GetPhyPageNum() ) );
767 SetName( aBuffer.makeStringAndClear() );
768 if( sOldName != GetName() )
770 AccessibleEventObject aEvent;
771 aEvent.EventId = AccessibleEventId::NAME_CHANGED;
772 aEvent.OldValue <<= sOldName;
773 aEvent.NewValue <<= GetName();
774 FireAccessibleEvent( aEvent );
777 OUString sOldDesc( sDesc );
778 OUString sArg1( rNewTabName );
779 OUString sArg2( GetFormattedPageNumber() );
781 sDesc = GetResource( STR_ACCESS_TABLE_DESC, &sArg1, &sArg2 );
782 if( sDesc != sOldDesc )
784 AccessibleEventObject aEvent;
785 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
786 aEvent.OldValue <<= sOldDesc;
787 aEvent.NewValue <<= sDesc;
788 FireAccessibleEvent( aEvent );
791 break;
793 case RES_OBJECTDYING:
794 if( GetRegisteredIn() ==
795 static_cast< SwModify *>( static_cast< SwPtrMsgPoolItem * >( pOld )->pObject ) )
796 pRegisteredIn->Remove( this );
797 break;
799 default:
800 SwClient::Modify( pOld, pNew );
801 break;
805 uno::Any SwAccessibleTable::queryInterface( const uno::Type& rType )
806 throw (uno::RuntimeException)
808 uno::Any aRet;
809 if ( rType == ::getCppuType( static_cast< uno::Reference< XAccessibleTable > * >( 0 ) ) )
811 uno::Reference<XAccessibleTable> xThis( this );
812 aRet <<= xThis;
814 else if ( rType == ::getCppuType( static_cast< uno::Reference< XAccessibleSelection > * >( 0 ) ) )
816 uno::Reference<XAccessibleSelection> xSelection( this );
817 aRet <<= xSelection;
819 else
821 aRet = SwAccessibleContext::queryInterface(rType);
824 return aRet;
827 //====== XTypeProvider ====================================================
828 uno::Sequence< uno::Type > SAL_CALL SwAccessibleTable::getTypes()
829 throw(uno::RuntimeException)
831 uno::Sequence< uno::Type > aTypes( SwAccessibleContext::getTypes() );
833 sal_Int32 nIndex = aTypes.getLength();
834 aTypes.realloc( nIndex + 2 );
836 uno::Type* pTypes = aTypes.getArray();
837 pTypes[nIndex++] = ::getCppuType( static_cast< uno::Reference< XAccessibleSelection > * >( 0 ) );
838 pTypes[nIndex++] = ::getCppuType( static_cast< uno::Reference< XAccessibleTable > * >( 0 ) );
840 return aTypes;
843 uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTable::getImplementationId()
844 throw(uno::RuntimeException)
846 vos::OGuard aGuard(Application::GetSolarMutex());
847 static uno::Sequence< sal_Int8 > aId( 16 );
848 static sal_Bool bInit = sal_False;
849 if(!bInit)
851 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
852 bInit = sal_True;
854 return aId;
857 // --> OD 2007-06-28 #i77106#
858 SwAccessibleTableData_Impl* SwAccessibleTable::CreateNewTableData()
860 const SwTabFrm* pTabFrm = static_cast<const SwTabFrm*>( GetFrm() );
861 return new SwAccessibleTableData_Impl( pTabFrm, IsInPagePreview() );
863 // <--
865 void SwAccessibleTable::UpdateTableData()
867 // --> OD 2007-06-28 #i77106# - usage of new method <CreateNewTableData()>
868 delete mpTableData;
869 mpTableData = CreateNewTableData();
870 // <--
873 void SwAccessibleTable::ClearTableData()
875 delete mpTableData;
876 mpTableData = 0;
879 OUString SAL_CALL SwAccessibleTable::getAccessibleDescription (void)
880 throw (uno::RuntimeException)
882 vos::OGuard aGuard(Application::GetSolarMutex());
884 CHECK_FOR_DEFUNC( XAccessibleContext )
886 return sDesc;
889 sal_Int32 SAL_CALL SwAccessibleTable::getAccessibleRowCount()
890 throw (uno::RuntimeException)
892 vos::OGuard aGuard(Application::GetSolarMutex());
894 CHECK_FOR_DEFUNC( XAccessibleTable )
896 return GetTableData().GetRowCount();
899 sal_Int32 SAL_CALL SwAccessibleTable::getAccessibleColumnCount( )
900 throw (uno::RuntimeException)
902 vos::OGuard aGuard(Application::GetSolarMutex());
904 CHECK_FOR_DEFUNC( XAccessibleTable )
906 return GetTableData().GetColumnCount();
909 OUString SAL_CALL SwAccessibleTable::getAccessibleRowDescription(
910 sal_Int32 nRow )
911 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
913 // TODO: Is there any reasonable we can do here?
914 OUString sTmpDesc;
916 GetTableData().CheckRowAndCol(nRow, 0, this);
918 return sTmpDesc;
921 OUString SAL_CALL SwAccessibleTable::getAccessibleColumnDescription(
922 sal_Int32 nColumn )
923 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
925 // TODO: Is there any reasonable we can do here?
926 OUString sTmpDesc;
928 GetTableData().CheckRowAndCol(0, nColumn, this);
930 return sTmpDesc;
933 sal_Int32 SAL_CALL SwAccessibleTable::getAccessibleRowExtentAt(
934 sal_Int32 nRow, sal_Int32 nColumn )
935 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
937 sal_Int32 nExtend = -1;
939 vos::OGuard aGuard(Application::GetSolarMutex());
941 CHECK_FOR_DEFUNC( XAccessibleTable )
943 GetTableData().CheckRowAndCol( nRow, nColumn, this );
945 Int32Set_Impl::const_iterator aSttCol(
946 GetTableData().GetColumnIter( nColumn ) );
947 Int32Set_Impl::const_iterator aSttRow(
948 GetTableData().GetRowIter( nRow ) );
949 const SwFrm *pCellFrm = GetTableData().GetCellAtPos( *aSttCol, *aSttRow,
950 sal_False );
951 if( pCellFrm )
953 sal_Int32 nBottom = pCellFrm->Frm().Bottom();
954 nBottom -= GetFrm()->Frm().Top();
955 Int32Set_Impl::const_iterator aEndRow(
956 GetTableData().GetRows().upper_bound( nBottom ) );
957 nExtend =
958 static_cast< sal_Int32 >( ::std::distance( aSttRow, aEndRow ) );
961 return nExtend;
964 sal_Int32 SAL_CALL SwAccessibleTable::getAccessibleColumnExtentAt(
965 sal_Int32 nRow, sal_Int32 nColumn )
966 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
968 sal_Int32 nExtend = -1;
970 vos::OGuard aGuard(Application::GetSolarMutex());
972 CHECK_FOR_DEFUNC( XAccessibleTable )
974 GetTableData().CheckRowAndCol( nRow, nColumn, this );
976 Int32Set_Impl::const_iterator aSttCol(
977 GetTableData().GetColumnIter( nColumn ) );
978 Int32Set_Impl::const_iterator aSttRow(
979 GetTableData().GetRowIter( nRow ) );
980 const SwFrm *pCellFrm = GetTableData().GetCellAtPos( *aSttCol, *aSttRow,
981 sal_False );
982 if( pCellFrm )
984 sal_Int32 nRight = pCellFrm->Frm().Right();
985 nRight -= GetFrm()->Frm().Left();
986 Int32Set_Impl::const_iterator aEndCol(
987 GetTableData().GetColumns().upper_bound( nRight ) );
988 nExtend =
989 static_cast< sal_Int32 >( ::std::distance( aSttCol, aEndCol ) );
992 return nExtend;
995 uno::Reference< XAccessibleTable > SAL_CALL
996 SwAccessibleTable::getAccessibleRowHeaders( )
997 throw (uno::RuntimeException)
999 // Row headers aren't supported
1000 return uno::Reference< XAccessibleTable >();
1003 uno::Reference< XAccessibleTable > SAL_CALL
1004 SwAccessibleTable::getAccessibleColumnHeaders( )
1005 throw (uno::RuntimeException)
1007 // --> OD 2007-06-29 #i77106#
1008 return new SwAccessibleTableColHeaders(
1009 GetMap(), static_cast< const SwTabFrm *>( GetFrm() ) );
1012 uno::Sequence< sal_Int32 > SAL_CALL SwAccessibleTable::getSelectedAccessibleRows()
1013 throw (uno::RuntimeException)
1015 vos::OGuard aGuard(Application::GetSolarMutex());
1017 CHECK_FOR_DEFUNC( XAccessibleTable )
1019 const SwSelBoxes *pSelBoxes = GetSelBoxes();
1020 if( pSelBoxes )
1022 sal_Int32 nRows = GetTableData().GetRowCount();
1023 SwAccAllTableSelHander_Impl aSelRows( nRows );
1025 GetTableData().GetSelection( 0, nRows, *pSelBoxes, aSelRows,
1026 sal_False );
1028 return aSelRows.GetSelSequence();
1030 else
1032 return uno::Sequence< sal_Int32 >( 0 );
1036 uno::Sequence< sal_Int32 > SAL_CALL SwAccessibleTable::getSelectedAccessibleColumns()
1037 throw (uno::RuntimeException)
1039 vos::OGuard aGuard(Application::GetSolarMutex());
1041 CHECK_FOR_DEFUNC( XAccessibleTable )
1043 const SwSelBoxes *pSelBoxes = GetSelBoxes();
1044 if( pSelBoxes )
1046 sal_Int32 nCols = GetTableData().GetColumnCount();
1047 SwAccAllTableSelHander_Impl aSelCols( nCols );
1049 GetTableData().GetSelection( 0, nCols, *pSelBoxes, aSelCols, sal_True );
1051 return aSelCols.GetSelSequence();
1053 else
1055 return uno::Sequence< sal_Int32 >( 0 );
1059 sal_Bool SAL_CALL SwAccessibleTable::isAccessibleRowSelected( sal_Int32 nRow )
1060 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1062 vos::OGuard aGuard(Application::GetSolarMutex());
1064 CHECK_FOR_DEFUNC( XAccessibleTable )
1066 GetTableData().CheckRowAndCol( nRow, 0, this );
1068 sal_Bool bRet;
1069 const SwSelBoxes *pSelBoxes = GetSelBoxes();
1070 if( pSelBoxes )
1072 SwAccSingleTableSelHander_Impl aSelRow;
1073 GetTableData().GetSelection( nRow, nRow+1, *pSelBoxes, aSelRow,
1074 sal_False );
1075 bRet = aSelRow.IsSelected();
1077 else
1079 bRet = sal_False;
1082 return bRet;
1085 sal_Bool SAL_CALL SwAccessibleTable::isAccessibleColumnSelected(
1086 sal_Int32 nColumn )
1087 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1089 vos::OGuard aGuard(Application::GetSolarMutex());
1091 CHECK_FOR_DEFUNC( XAccessibleTable )
1093 GetTableData().CheckRowAndCol( 0, nColumn, this );
1095 sal_Bool bRet;
1096 const SwSelBoxes *pSelBoxes = GetSelBoxes();
1097 if( pSelBoxes )
1099 SwAccSingleTableSelHander_Impl aSelCol;
1101 GetTableData().GetSelection( nColumn, nColumn+1, *pSelBoxes, aSelCol,
1102 sal_True );
1103 bRet = aSelCol.IsSelected();
1105 else
1107 bRet = sal_False;
1110 return bRet;
1113 uno::Reference< XAccessible > SAL_CALL SwAccessibleTable::getAccessibleCellAt(
1114 sal_Int32 nRow, sal_Int32 nColumn )
1115 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1117 uno::Reference< XAccessible > xRet;
1119 vos::OGuard aGuard(Application::GetSolarMutex());
1121 CHECK_FOR_DEFUNC( XAccessibleTable )
1123 const SwFrm *pCellFrm =
1124 GetTableData().GetCell( nRow, nColumn, sal_False, this );
1125 if( pCellFrm )
1126 xRet = GetMap()->GetContext( pCellFrm, sal_True );
1128 return xRet;
1131 uno::Reference< XAccessible > SAL_CALL SwAccessibleTable::getAccessibleCaption()
1132 throw (uno::RuntimeException)
1134 // captions aren't supported
1135 return uno::Reference< XAccessible >();
1138 uno::Reference< XAccessible > SAL_CALL SwAccessibleTable::getAccessibleSummary()
1139 throw (uno::RuntimeException)
1141 // summaries aren't supported
1142 return uno::Reference< XAccessible >();
1145 sal_Bool SAL_CALL SwAccessibleTable::isAccessibleSelected(
1146 sal_Int32 nRow, sal_Int32 nColumn )
1147 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1149 sal_Bool bRet = sal_False;
1151 vos::OGuard aGuard(Application::GetSolarMutex());
1153 CHECK_FOR_DEFUNC( XAccessibleTable )
1155 const SwFrm *pFrm =
1156 GetTableData().GetCell( nRow, nColumn, sal_False, this );
1157 if( pFrm && pFrm->IsCellFrm() )
1159 const SwSelBoxes *pSelBoxes = GetSelBoxes();
1160 if( pSelBoxes )
1162 const SwCellFrm *pCFrm = static_cast < const SwCellFrm * >( pFrm );
1163 SwTableBox *pBox =
1164 const_cast< SwTableBox *>( pCFrm->GetTabBox() ); //SVPtrArr!
1165 bRet = pSelBoxes->Seek_Entry( pBox );
1169 return bRet;
1172 sal_Int32 SAL_CALL SwAccessibleTable::getAccessibleIndex(
1173 sal_Int32 nRow, sal_Int32 nColumn )
1174 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1176 sal_Int32 nRet = -1;
1178 vos::OGuard aGuard(Application::GetSolarMutex());
1180 CHECK_FOR_DEFUNC( XAccessibleTable )
1182 SwFrmOrObj aCell( GetTableData().GetCell( nRow, nColumn, sal_False, this ));
1183 if( aCell.IsValid() )
1184 nRet = GetChildIndex( aCell );
1186 return nRet;
1189 sal_Int32 SAL_CALL SwAccessibleTable::getAccessibleRow( sal_Int32 nChildIndex )
1190 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1192 sal_Int32 nRet = -1;
1194 vos::OGuard aGuard(Application::GetSolarMutex());
1196 CHECK_FOR_DEFUNC( XAccessibleTable )
1198 // --> OD 2007-06-27 #i77106#
1199 if ( ( nChildIndex < 0 ) ||
1200 ( nChildIndex >= getAccessibleChildCount() ) )
1202 throw lang::IndexOutOfBoundsException();
1204 // <--
1206 SwFrmOrObj aCell( GetChild( nChildIndex ) );
1207 if( aCell.GetSwFrm() )
1209 sal_Int32 nTop = aCell.GetSwFrm()->Frm().Top();
1210 nTop -= GetFrm()->Frm().Top();
1211 Int32Set_Impl::const_iterator aRow(
1212 GetTableData().GetRows().lower_bound( nTop ) );
1213 nRet = static_cast< sal_Int32 >( ::std::distance(
1214 GetTableData().GetRows().begin(), aRow ) );
1216 else
1218 ASSERT( !aCell.IsValid(), "SwAccessibleTable::getAccessibleColumn:"
1219 "aCell not expected to be valid.");
1221 throw lang::IndexOutOfBoundsException();
1224 return nRet;
1227 sal_Int32 SAL_CALL SwAccessibleTable::getAccessibleColumn(
1228 sal_Int32 nChildIndex )
1229 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1231 sal_Int32 nRet = -1;
1233 vos::OGuard aGuard(Application::GetSolarMutex());
1235 CHECK_FOR_DEFUNC( XAccessibleTable )
1237 // --> OD 2007-06-27 #i77106#
1238 if ( ( nChildIndex < 0 ) ||
1239 ( nChildIndex >= getAccessibleChildCount() ) )
1241 throw lang::IndexOutOfBoundsException();
1243 // <--
1245 SwFrmOrObj aCell( GetChild( nChildIndex ) );
1246 if( aCell.GetSwFrm() )
1248 sal_Int32 nLeft = aCell.GetSwFrm()->Frm().Left();
1249 nLeft -= GetFrm()->Frm().Left();
1250 Int32Set_Impl::const_iterator aCol(
1251 GetTableData().GetColumns().lower_bound( nLeft ) );
1252 nRet = static_cast< sal_Int32 >( ::std::distance(
1253 GetTableData().GetColumns().begin(), aCol ) );
1255 else
1257 ASSERT( !aCell.IsValid(), "SwAccessibleTable::getAccessibleColumn:"
1258 "aCell not expected to be valid.");
1260 throw lang::IndexOutOfBoundsException();
1263 return nRet;
1267 OUString SAL_CALL SwAccessibleTable::getImplementationName()
1268 throw( uno::RuntimeException )
1270 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName));
1273 sal_Bool SAL_CALL SwAccessibleTable::supportsService(
1274 const OUString& sTestServiceName)
1275 throw (uno::RuntimeException)
1277 return sTestServiceName.equalsAsciiL( sServiceName,
1278 sizeof(sServiceName)-1 ) ||
1279 sTestServiceName.equalsAsciiL( sAccessibleServiceName,
1280 sizeof(sAccessibleServiceName)-1 );
1283 uno::Sequence< OUString > SAL_CALL SwAccessibleTable::getSupportedServiceNames()
1284 throw( uno::RuntimeException )
1286 uno::Sequence< OUString > aRet(2);
1287 OUString* pArray = aRet.getArray();
1288 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) );
1289 pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
1290 return aRet;
1293 void SwAccessibleTable::InvalidatePosOrSize( const SwRect& rOldBox )
1295 vos::OGuard aGuard(Application::GetSolarMutex());
1297 if( HasTableData() )
1298 GetTableData().SetTablePos( GetFrm()->Frm().Pos() );
1300 SwAccessibleContext::InvalidatePosOrSize( rOldBox );
1303 void SwAccessibleTable::Dispose( sal_Bool bRecursive )
1305 vos::OGuard aGuard(Application::GetSolarMutex());
1307 if( GetRegisteredIn() )
1308 pRegisteredIn->Remove( this );
1310 SwAccessibleContext::Dispose( bRecursive );
1313 void SwAccessibleTable::DisposeChild( const SwFrmOrObj& rChildFrmOrObj,
1314 sal_Bool bRecursive )
1316 vos::OGuard aGuard(Application::GetSolarMutex());
1318 const SwFrm *pFrm = rChildFrmOrObj.GetSwFrm();
1319 ASSERT( pFrm, "frame expected" );
1320 if( HasTableData() )
1322 FireTableChangeEvent( GetTableData() );
1323 ClearTableData();
1326 // There are two reason why this method has been called. The first one
1327 // is there is no context for pFrm. The method is them called by
1328 // the map, and we have to call our superclass.
1329 // The other situation is that we have been call by a call to get notified
1330 // about its change. We then must not call the superclass
1331 uno::Reference< XAccessible > xAcc( GetMap()->GetContext( pFrm, sal_False ) );
1332 if( !xAcc.is() )
1333 SwAccessibleContext::DisposeChild( rChildFrmOrObj, bRecursive );
1336 void SwAccessibleTable::InvalidateChildPosOrSize( const SwFrmOrObj& rChildFrmOrObj,
1337 const SwRect& rOldBox )
1339 vos::OGuard aGuard(Application::GetSolarMutex());
1341 if( HasTableData() )
1343 ASSERT( !HasTableData() ||
1344 GetFrm()->Frm().Pos() == GetTableData().GetTablePos(),
1345 "table has invalid position" );
1346 if( HasTableData() )
1348 // --> OD 2007-06-28 #i77106#
1349 SwAccessibleTableData_Impl *pNewTableData = CreateNewTableData();
1350 // <--
1351 if( !pNewTableData->CompareExtents( GetTableData() ) )
1353 FireTableChangeEvent( GetTableData() );
1354 ClearTableData();
1355 mpTableData = pNewTableData;
1357 else
1359 delete pNewTableData;
1364 // There are two reason why this method has been called. The first one
1365 // is there is no context for pFrm. The method is them called by
1366 // the map, and we have to call our superclass.
1367 // The other situation is that we have been call by a call to get notified
1368 // about its change. We then must not call the superclass
1369 ASSERT( rChildFrmOrObj.GetSwFrm(), "frame expected" );
1370 uno::Reference< XAccessible > xAcc( GetMap()->GetContext( rChildFrmOrObj.GetSwFrm(), sal_False ) );
1371 if( !xAcc.is() )
1372 SwAccessibleContext::InvalidateChildPosOrSize( rChildFrmOrObj, rOldBox );
1377 // XAccessibleSelection
1380 void SAL_CALL SwAccessibleTable::selectAccessibleChild(
1381 sal_Int32 nChildIndex )
1382 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
1384 vos::OGuard aGuard(Application::GetSolarMutex());
1385 CHECK_FOR_DEFUNC( XAccessibleTable );
1387 // --> OD 2007-06-27 #i77106#
1388 if( (nChildIndex < 0) || (nChildIndex >= getAccessibleChildCount()) )
1389 // <--
1390 throw lang::IndexOutOfBoundsException();
1392 // preliminaries: get 'our' table box, and get the cursor shell
1393 const SwTableBox* pBox = GetTableBox( nChildIndex );
1394 DBG_ASSERT( pBox != NULL, "We need the table box." );
1396 SwCrsrShell* pCrsrShell = GetCrsrShell();
1397 if( pCrsrShell == NULL )
1398 return;
1400 // --> OD 2004-11-16 #111714# - assure, that child, indentified by the given
1401 // index, isn't already selected.
1402 if ( IsChildSelected( nChildIndex ) )
1404 return;
1406 // <--
1408 // now we can start to do the work: check whether we already have
1409 // a table selection (in 'our' table). If so, extend the
1410 // selection, else select the current cell.
1412 // if we have a selection in a table, check if it's in the
1413 // same table that we're trying to select in
1414 const SwTableNode* pSelectedTable = pCrsrShell->IsCrsrInTbl();
1415 if( pSelectedTable != NULL )
1417 // get top-most table line
1418 const SwTableLine* pUpper = pBox->GetUpper();
1419 while( pUpper->GetUpper() != NULL )
1420 pUpper = pUpper->GetUpper()->GetUpper();
1421 USHORT nPos =
1422 pSelectedTable->GetTable().GetTabLines().GetPos( pUpper );
1423 if( nPos == USHRT_MAX )
1424 pSelectedTable = NULL;
1427 // create the new selection
1428 const SwStartNode* pStartNode = pBox->GetSttNd();
1429 if( pSelectedTable == NULL || !pCrsrShell->GetTblCrs() )
1431 // if we're in the wrong table, or there's no table selection
1432 // at all, then select the current table cell.
1433 // SwPaM* pPaM = pCrsrShell->GetCrsr();
1434 // pPaM->DeleteMark();
1435 // *(pPaM->GetPoint()) = SwPosition( *pStartNode );
1436 // pPaM->Move( fnMoveForward, fnGoNode );
1437 // // pCrsrShell->SelTblBox();
1439 pCrsrShell->StartAction();
1440 // Set cursor into current cell. This deletes any table cursor.
1441 SwPaM aPaM( *pStartNode );
1442 aPaM.Move( fnMoveForward, fnGoNode );
1443 Select( aPaM );
1444 // Move cursor to the end of the table creating a selection and a table
1445 // cursor.
1446 pCrsrShell->SetMark();
1447 pCrsrShell->MoveTable( fnTableCurr, fnTableEnd );
1448 // now set the cursor into the cell again.
1449 SwPaM *pPaM = pCrsrShell->GetTblCrs() ? pCrsrShell->GetTblCrs()
1450 : pCrsrShell->GetCrsr();
1451 *pPaM->GetPoint() = *pPaM->GetMark();
1452 pCrsrShell->EndAction();
1453 // we now have one cell selected!
1455 else
1457 // if the cursor is already in this table,
1458 // expand the current selection (i.e., set
1459 // point to new position; keep mark)
1460 SwPaM aPaM( *pStartNode );
1461 aPaM.Move( fnMoveForward, fnGoNode );
1462 aPaM.SetMark();
1463 const SwPaM *pPaM = pCrsrShell->GetTblCrs() ? pCrsrShell->GetTblCrs()
1464 : pCrsrShell->GetCrsr();
1465 *(aPaM.GetMark()) = *pPaM->GetMark();
1466 Select( aPaM );
1468 // if only one box is selected, we select this one in
1469 // order to maintain our table selection
1470 // if( aPaM.GetPoint()->nNode.GetNode().FindTableBoxStartNode() ==
1471 // aPaM.GetMark()->nNode.GetNode().FindTableBoxStartNode() )
1472 // {
1473 // // pCrsrShell->SelTblBox();
1474 // }
1475 // else
1476 // {
1477 // finally; set the selection. This will call UpdateCursor
1478 // on the cursor shell, too.
1479 // pCrsrShell->KillPams();
1480 // pCrsrShell->SetSelection( aPaM );
1481 // }
1486 sal_Bool SAL_CALL SwAccessibleTable::isAccessibleChildSelected(
1487 sal_Int32 nChildIndex )
1488 throw ( lang::IndexOutOfBoundsException,
1489 uno::RuntimeException )
1491 vos::OGuard aGuard(Application::GetSolarMutex());
1492 CHECK_FOR_DEFUNC( XAccessibleTable );
1494 // --> OD 2007-06-27 #i77106#
1495 if( (nChildIndex < 0) || (nChildIndex >= getAccessibleChildCount()) )
1496 // <--
1497 throw lang::IndexOutOfBoundsException();
1499 return IsChildSelected( nChildIndex );
1502 void SAL_CALL SwAccessibleTable::clearAccessibleSelection( )
1503 throw ( uno::RuntimeException )
1505 vos::OGuard aGuard(Application::GetSolarMutex());
1507 CHECK_FOR_DEFUNC( XAccessibleTable );
1509 SwCrsrShell* pCrsrShell = GetCrsrShell();
1510 if( pCrsrShell != NULL )
1512 pCrsrShell->StartAction();
1513 pCrsrShell->ClearMark();
1514 pCrsrShell->EndAction();
1518 void SAL_CALL SwAccessibleTable::selectAllAccessibleChildren( )
1519 throw ( uno::RuntimeException )
1521 // first clear selection, then select first and last child
1522 clearAccessibleSelection();
1523 selectAccessibleChild( 0 );
1524 // --> OD 2007-06-27 #i77106#
1525 selectAccessibleChild( getAccessibleChildCount()-1 );
1526 // <--
1529 sal_Int32 SAL_CALL SwAccessibleTable::getSelectedAccessibleChildCount( )
1530 throw ( uno::RuntimeException )
1532 vos::OGuard aGuard(Application::GetSolarMutex());
1533 CHECK_FOR_DEFUNC( XAccessibleTable );
1535 // iterate over all children and count isAccessibleChildSelected()
1536 sal_Int32 nCount = 0;
1538 // --> OD 2007-06-27 #i71106#
1539 sal_Int32 nChildren = getAccessibleChildCount();
1540 // <--
1541 for( sal_Int32 n = 0; n < nChildren; n++ )
1542 if( IsChildSelected( n ) )
1543 nCount++;
1545 return nCount;
1548 uno::Reference<XAccessible> SAL_CALL SwAccessibleTable::getSelectedAccessibleChild(
1549 sal_Int32 nSelectedChildIndex )
1550 throw ( lang::IndexOutOfBoundsException,
1551 uno::RuntimeException)
1553 vos::OGuard aGuard(Application::GetSolarMutex());
1554 CHECK_FOR_DEFUNC( XAccessibleTable );
1556 // paremter checking (part 1): index lower 0
1557 if( nSelectedChildIndex < 0 )
1558 throw lang::IndexOutOfBoundsException();
1560 sal_Int32 nChildIndex = GetIndexOfSelectedChild( nSelectedChildIndex );
1562 // parameter checking (part 2): index higher than selected children?
1563 if( nChildIndex < 0 )
1564 throw lang::IndexOutOfBoundsException();
1566 // --> OD 2007-06-28 #i77106#
1567 if ( nChildIndex >= getAccessibleChildCount() )
1569 throw lang::IndexOutOfBoundsException();
1571 // <--
1573 return getAccessibleChild( nChildIndex );
1576 // --> OD 2004-11-16 #111714# - index has to be treated as global child index.
1577 void SAL_CALL SwAccessibleTable::deselectAccessibleChild(
1578 sal_Int32 nChildIndex )
1579 throw ( lang::IndexOutOfBoundsException,
1580 uno::RuntimeException )
1582 vos::OGuard aGuard(Application::GetSolarMutex());
1583 CHECK_FOR_DEFUNC( XAccessibleTable );
1585 SwCrsrShell* pCrsrShell = GetCrsrShell();
1587 // --> OD 2004-11-16 #111714# - index has to be treated as global child index
1588 if ( !pCrsrShell )
1589 throw lang::IndexOutOfBoundsException();
1591 // assure, that given child index is in bounds.
1592 // --> OD 2007-06-27 #i77106#
1593 if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() )
1594 // <--
1595 throw lang::IndexOutOfBoundsException();
1597 // assure, that child, identified by the given index, is selected.
1598 if ( !IsChildSelected( nChildIndex ) )
1599 return;
1600 // <--
1602 const SwTableBox* pBox = GetTableBox( nChildIndex );
1603 DBG_ASSERT( pBox != NULL, "We need the table box." );
1605 // If we unselect point, then set cursor to mark. If we clear another
1606 // selected box, then set cursor to point.
1607 // reduce selection to mark.
1608 SwPaM *pPaM = pCrsrShell->GetTblCrs() ? pCrsrShell->GetTblCrs()
1609 : pCrsrShell->GetCrsr();
1610 sal_Bool bDeselectPoint =
1611 pBox->GetSttNd() ==
1612 pPaM->GetPoint()->nNode.GetNode().FindTableBoxStartNode();
1614 SwPaM aPaM( bDeselectPoint ? *pPaM->GetMark() : *pPaM->GetPoint() );
1616 pCrsrShell->StartAction();
1618 // Set cursor into either point or mark
1619 Select( aPaM );
1620 // Move cursor to the end of the table creating a selection and a table
1621 // cursor.
1622 pCrsrShell->SetMark();
1623 pCrsrShell->MoveTable( fnTableCurr, fnTableEnd );
1624 // now set the cursor into the cell again.
1625 pPaM = pCrsrShell->GetTblCrs() ? pCrsrShell->GetTblCrs()
1626 : pCrsrShell->GetCrsr();
1627 *pPaM->GetPoint() = *pPaM->GetMark();
1628 pCrsrShell->EndAction();
1631 // --> OD 2007-06-28 #i77106#
1632 // implementation of class <SwAccessibleTableColHeaders>
1633 SwAccessibleTableColHeaders::SwAccessibleTableColHeaders( SwAccessibleMap *pMap2,
1634 const SwTabFrm *pTabFrm )
1635 : SwAccessibleTable( pMap2, pTabFrm )
1637 vos::OGuard aGuard(Application::GetSolarMutex());
1639 const SwFrmFmt *pFrmFmt = pTabFrm->GetFmt();
1640 const_cast< SwFrmFmt * >( pFrmFmt )->Add( this );
1641 const String& rName = pFrmFmt->GetName();
1643 OUStringBuffer aBuffer( rName.Len() + 15 + 6 );
1644 aBuffer.append( OUString(rName) );
1645 aBuffer.append( String::CreateFromAscii("-ColumnHeaders-") );
1646 aBuffer.append( static_cast<sal_Int32>( pTabFrm->GetPhyPageNum() ) );
1648 SetName( aBuffer.makeStringAndClear() );
1650 OUStringBuffer aBuffer2( rName.Len() + 14 );
1651 aBuffer2.append( OUString(rName) );
1652 aBuffer2.append( String::CreateFromAscii("-ColumnHeaders") );
1653 OUString sArg1( aBuffer2.makeStringAndClear() );
1654 OUString sArg2( GetFormattedPageNumber() );
1656 OUString sDesc2 = GetResource( STR_ACCESS_TABLE_DESC, &sArg1, &sArg2 );
1657 SetDesc( sDesc2 );
1659 // --> OD 2008-03-10 #i85634#
1660 NotRegisteredAtAccessibleMap();
1661 // <--
1664 SwAccessibleTableData_Impl* SwAccessibleTableColHeaders::CreateNewTableData()
1666 const SwTabFrm* pTabFrm = static_cast<const SwTabFrm*>( GetFrm() );
1667 return new SwAccessibleTableData_Impl( pTabFrm, IsInPagePreview(), true );
1671 void SwAccessibleTableColHeaders::Modify( SfxPoolItem * /*pOld*/, SfxPoolItem * /*pNew*/ )
1675 //===== XInterface ======================================================
1676 uno::Any SAL_CALL SwAccessibleTableColHeaders::queryInterface( const uno::Type& aType )
1677 throw (uno::RuntimeException)
1679 return SwAccessibleTable::queryInterface( aType );
1682 //===== XAccessibleContext ==============================================
1683 sal_Int32 SAL_CALL SwAccessibleTableColHeaders::getAccessibleChildCount(void)
1684 throw (uno::RuntimeException)
1686 vos::OGuard aGuard(Application::GetSolarMutex());
1688 CHECK_FOR_DEFUNC( XAccessibleContext )
1690 sal_Int32 nCount = 0;
1692 const SwTabFrm* pTabFrm = static_cast<const SwTabFrm*>( GetFrm() );
1693 const SwFrmOrObjSList aVisList( GetVisArea(), pTabFrm );
1694 SwFrmOrObjSList::const_iterator aIter( aVisList.begin() );
1695 while( aIter != aVisList.end() )
1697 const SwFrmOrObj& rLower = *aIter;
1698 if( rLower.IsAccessible( IsInPagePreview() ) )
1700 nCount++;
1702 else if( rLower.GetSwFrm() )
1704 // There are no unaccessible SdrObjects that count
1705 if ( !rLower.GetSwFrm()->IsRowFrm() ||
1706 pTabFrm->IsInHeadline( *(rLower.GetSwFrm()) ) )
1708 nCount += SwAccessibleFrame::GetChildCount( GetVisArea(),
1709 rLower.GetSwFrm(),
1710 IsInPagePreview() );
1713 ++aIter;
1716 return nCount;
1719 uno::Reference< XAccessible> SAL_CALL
1720 SwAccessibleTableColHeaders::getAccessibleChild (sal_Int32 nIndex)
1721 throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
1723 if ( nIndex < 0 || nIndex >= getAccessibleChildCount() )
1725 throw lang::IndexOutOfBoundsException();
1728 return SwAccessibleTable::getAccessibleChild( nIndex );
1731 //===== XAccessibleTable ================================================
1732 uno::Reference< XAccessibleTable >
1733 SAL_CALL SwAccessibleTableColHeaders::getAccessibleRowHeaders()
1734 throw (uno::RuntimeException)
1736 return uno::Reference< XAccessibleTable >();
1739 uno::Reference< XAccessibleTable >
1740 SAL_CALL SwAccessibleTableColHeaders::getAccessibleColumnHeaders()
1741 throw (uno::RuntimeException)
1743 return uno::Reference< XAccessibleTable >();
1746 //===== XServiceInfo ====================================================
1748 ::rtl::OUString SAL_CALL SwAccessibleTableColHeaders::getImplementationName (void)
1749 throw (uno::RuntimeException)
1751 static const sal_Char sImplName[] = "com.sun.star.comp.Writer.SwAccessibleTableColumnHeadersView";
1752 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplName));