1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accessibletablistboxtable.cxx,v $
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_accessibility.hxx"
34 #ifndef ACCESSIBILITY_EXT_ACCESSIBLETABLISTBOXTABLE_HXX_
35 #include "accessibility/extended/accessibletablistboxtable.hxx"
37 #include "accessibility/extended/AccessibleBrowseBoxTableCell.hxx"
38 #include "accessibility/extended/AccessibleBrowseBoxCheckBoxCell.hxx"
39 #include <svtools/svtabbx.hxx>
40 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
42 //........................................................................
43 namespace accessibility
45 //........................................................................
47 // class TLBSolarGuard ---------------------------------------------------------
49 /** Aquire the solar mutex. */
50 class TLBSolarGuard
: public ::vos::OGuard
53 inline TLBSolarGuard() : ::vos::OGuard( Application::GetSolarMutex() ) {}
56 // class AccessibleTabListBoxTable ---------------------------------------------
58 using namespace ::com::sun::star::accessibility
;
59 using namespace ::com::sun::star::uno
;
60 using namespace ::com::sun::star::lang
;
61 using namespace ::com::sun::star
;
63 DBG_NAME(AccessibleTabListBoxTable
)
65 // -----------------------------------------------------------------------------
67 // -----------------------------------------------------------------------------
68 AccessibleTabListBoxTable::AccessibleTabListBoxTable( const Reference
< XAccessible
>& rxParent
, SvHeaderTabListBox
& rBox
) :
70 AccessibleBrowseBoxTable( rxParent
, rBox
),
72 m_pTabListBox ( &rBox
)
75 DBG_CTOR( AccessibleTabListBoxTable
, NULL
);
77 m_pTabListBox
->AddEventListener( LINK( this, AccessibleTabListBoxTable
, WindowEventListener
) );
79 // -----------------------------------------------------------------------------
80 AccessibleTabListBoxTable::~AccessibleTabListBoxTable()
82 DBG_DTOR( AccessibleTabListBoxTable
, NULL
);
88 // increment ref count to prevent double call of Dtor
89 osl_incrementInterlockedCount( &m_refCount
);
93 // -----------------------------------------------------------------------------
94 void AccessibleTabListBoxTable::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
98 ULONG nEventId
= rVclWindowEvent
.GetId();
101 case VCLEVENT_OBJECT_DYING
:
103 m_pTabListBox
->RemoveEventListener( LINK( this, AccessibleTabListBoxTable
, WindowEventListener
) );
104 m_pTabListBox
= NULL
;
108 case VCLEVENT_CONTROL_GETFOCUS
:
109 case VCLEVENT_CONTROL_LOSEFOCUS
:
111 uno::Any aOldValue
, aNewValue
;
112 if ( VCLEVENT_CONTROL_GETFOCUS
== nEventId
)
113 aNewValue
<<= AccessibleStateType::FOCUSED
;
115 aOldValue
<<= AccessibleStateType::FOCUSED
;
116 commitEvent( AccessibleEventId::STATE_CHANGED
, aNewValue
, aOldValue
);
120 case VCLEVENT_LISTBOX_SELECT
:
122 // First send an event that tells the listeners of a
123 // modified selection. The active descendant event is
124 // send after that so that the receiving AT has time to
125 // read the text or name of the active child.
126 commitEvent( AccessibleEventId::SELECTION_CHANGED
, Any(), Any() );
127 if ( m_pTabListBox
&& m_pTabListBox
->HasFocus() )
129 SvLBoxEntry
* pEntry
= static_cast< SvLBoxEntry
* >( rVclWindowEvent
.GetData() );
132 sal_Int32 nRow
= m_pTabListBox
->GetEntryPos( pEntry
);
133 USHORT nCol
= m_pTabListBox
->GetCurrColumn();
134 Reference
< XAccessible
> xChild
=
135 m_pTabListBox
->CreateAccessibleCell( nRow
, nCol
);
136 uno::Any aOldValue
, aNewValue
;
138 if ( m_pTabListBox
->IsTransientChildrenDisabled() )
140 aNewValue
<<= AccessibleStateType::FOCUSED
;
141 TriState eState
= STATE_DONTKNOW
;
142 if ( m_pTabListBox
->IsCellCheckBox( nRow
, nCol
, eState
) )
144 AccessibleCheckBoxCell
* pCell
=
145 static_cast< AccessibleCheckBoxCell
* >( xChild
.get() );
146 pCell
->commitEvent( AccessibleEventId::STATE_CHANGED
, aNewValue
, aOldValue
);
150 AccessibleBrowseBoxTableCell
* pCell
=
151 static_cast< AccessibleBrowseBoxTableCell
* >( xChild
.get() );
152 pCell
->commitEvent( AccessibleEventId::STATE_CHANGED
, aNewValue
, aOldValue
);
157 aNewValue
<<= xChild
;
158 commitEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
, aNewValue
, aOldValue
);
165 case VCLEVENT_CHECKBOX_TOGGLE
:
167 if ( m_pTabListBox
&& m_pTabListBox
->HasFocus() )
169 SvLBoxEntry
* pEntry
= static_cast< SvLBoxEntry
* >( rVclWindowEvent
.GetData() );
172 sal_Int32 nRow
= m_pTabListBox
->GetEntryPos( pEntry
);
173 USHORT nCol
= m_pTabListBox
->GetCurrColumn();
174 TriState eState
= STATE_DONTKNOW
;
175 if ( m_pTabListBox
->IsCellCheckBox( nRow
, nCol
, eState
) )
177 Reference
< XAccessible
> xChild
=
178 m_pTabListBox
->CreateAccessibleCell( nRow
, nCol
);
179 AccessibleCheckBoxCell
* pCell
=
180 static_cast< AccessibleCheckBoxCell
* >( xChild
.get() );
181 pCell
->SetChecked( m_pTabListBox
->IsItemChecked( pEntry
, nCol
) );
188 case VCLEVENT_TABLECELL_NAMECHANGED
:
190 if ( m_pTabListBox
->IsTransientChildrenDisabled() )
192 commitEvent( AccessibleEventId::SELECTION_CHANGED
, Any(), Any() );
193 TabListBoxEventData
* pData
= static_cast< TabListBoxEventData
* >( rVclWindowEvent
.GetData() );
194 SvLBoxEntry
* pEntry
= pData
!= NULL
? pData
->m_pEntry
: NULL
;
197 sal_Int32 nRow
= m_pTabListBox
->GetEntryPos( pEntry
);
198 USHORT nCol
= pData
->m_nColumn
;
199 Reference
< XAccessible
> xChild
=
200 m_pTabListBox
->CreateAccessibleCell( nRow
, nCol
);
201 uno::Any aOldValue
, aNewValue
;
202 aOldValue
<<= ::rtl::OUString( pData
->m_sOldText
);
203 ::rtl::OUString
sNewText( m_pTabListBox
->GetCellText( nRow
, nCol
) );
204 aNewValue
<<= sNewText
;
205 TriState eState
= STATE_DONTKNOW
;
207 if ( m_pTabListBox
->IsCellCheckBox( nRow
, nCol
, eState
) )
209 AccessibleCheckBoxCell
* pCell
=
210 static_cast< AccessibleCheckBoxCell
* >( xChild
.get() );
211 pCell
->commitEvent( AccessibleEventId::NAME_CHANGED
, aOldValue
, aNewValue
);
215 AccessibleBrowseBoxTableCell
* pCell
=
216 static_cast< AccessibleBrowseBoxTableCell
* >( xChild
.get() );
217 pCell
->nameChanged( sNewText
, pData
->m_sOldText
);
226 // -----------------------------------------------------------------------------
227 IMPL_LINK( AccessibleTabListBoxTable
, WindowEventListener
, VclSimpleEvent
*, pEvent
)
229 DBG_ASSERT( pEvent
&& pEvent
->ISA( VclWindowEvent
), "Unknown WindowEvent!" );
230 if ( pEvent
&& pEvent
->ISA( VclWindowEvent
) )
232 DBG_ASSERT( ( (VclWindowEvent
*)pEvent
)->GetWindow() && m_pTabListBox
, "no event window" );
233 ProcessWindowEvent( *(VclWindowEvent
*)pEvent
);
237 // helpers --------------------------------------------------------------------
239 void AccessibleTabListBoxTable::ensureValidIndex( sal_Int32 _nIndex
) const
240 SAL_THROW( ( IndexOutOfBoundsException
) )
242 if ( ( _nIndex
< 0 ) || ( _nIndex
>= implGetCellCount() ) )
243 throw IndexOutOfBoundsException();
246 sal_Bool
AccessibleTabListBoxTable::implIsRowSelected( sal_Int32 _nRow
) const
248 return m_pTabListBox
? m_pTabListBox
->IsSelected( m_pTabListBox
->GetEntry( _nRow
) ) : sal_False
;
251 void AccessibleTabListBoxTable::implSelectRow( sal_Int32 _nRow
, sal_Bool _bSelect
)
254 m_pTabListBox
->Select( m_pTabListBox
->GetEntry( _nRow
), _bSelect
);
257 sal_Int32
AccessibleTabListBoxTable::implGetRowCount() const
259 return m_pTabListBox
? m_pTabListBox
->GetEntryCount() : 0;
262 sal_Int32
AccessibleTabListBoxTable::implGetColumnCount() const
264 return m_pTabListBox
? m_pTabListBox
->GetColumnCount() : 0;
267 sal_Int32
AccessibleTabListBoxTable::implGetSelRowCount() const
269 return m_pTabListBox
? m_pTabListBox
->GetSelectionCount() : 0;
272 sal_Int32
AccessibleTabListBoxTable::implGetSelRow( sal_Int32 nSelRow
) const
277 SvLBoxEntry
* pEntry
= m_pTabListBox
->FirstSelected();
281 if ( nRow
== nSelRow
)
282 return m_pTabListBox
->GetEntryPos( pEntry
);
283 pEntry
= m_pTabListBox
->NextSelected( pEntry
);
289 // -----------------------------------------------------------------------------
290 // XInterface & XTypeProvider
291 // -----------------------------------------------------------------------------
292 IMPLEMENT_FORWARD_XINTERFACE2(AccessibleTabListBoxTable
, AccessibleBrowseBoxTable
, AccessibleTabListBoxTableImplHelper
)
293 IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleTabListBoxTable
, AccessibleBrowseBoxTable
, AccessibleTabListBoxTableImplHelper
)
294 // -----------------------------------------------------------------------------
296 // -----------------------------------------------------------------------------
297 ::rtl::OUString
AccessibleTabListBoxTable::getImplementationName (void) throw (RuntimeException
)
299 return ::rtl::OUString::createFromAscii("com.sun.star.comp.svtools.AccessibleTabListBoxTable");
301 // -----------------------------------------------------------------------------
302 // XAccessibleSelection
303 // -----------------------------------------------------------------------------
304 void SAL_CALL
AccessibleTabListBoxTable::selectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
306 TLBSolarGuard aSolarGuard
;
307 ::osl::MutexGuard
aGuard( getOslMutex() );
310 ensureValidIndex( nChildIndex
);
312 implSelectRow( implGetRow( nChildIndex
), sal_True
);
314 // -----------------------------------------------------------------------------
315 sal_Bool SAL_CALL
AccessibleTabListBoxTable::isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
317 TLBSolarGuard aSolarGuard
;
318 ::osl::MutexGuard
aGuard( getOslMutex() );
321 ensureValidIndex( nChildIndex
);
323 return implIsRowSelected( implGetRow( nChildIndex
) );
325 // -----------------------------------------------------------------------------
326 void SAL_CALL
AccessibleTabListBoxTable::clearAccessibleSelection( ) throw (RuntimeException
)
328 TLBSolarGuard aSolarGuard
;
329 ::osl::MutexGuard
aGuard( getOslMutex() );
333 m_pTabListBox
->SetNoSelection();
335 // -----------------------------------------------------------------------------
336 void SAL_CALL
AccessibleTabListBoxTable::selectAllAccessibleChildren( ) throw (RuntimeException
)
338 TLBSolarGuard aSolarGuard
;
339 ::osl::MutexGuard
aGuard( getOslMutex() );
343 m_pTabListBox
->SelectAll();
345 // -----------------------------------------------------------------------------
346 sal_Int32 SAL_CALL
AccessibleTabListBoxTable::getSelectedAccessibleChildCount( ) throw (RuntimeException
)
348 TLBSolarGuard aSolarGuard
;
349 ::osl::MutexGuard
aGuard( getOslMutex() );
353 return implGetColumnCount() * implGetSelRowCount();
355 // -----------------------------------------------------------------------------
356 Reference
< XAccessible
> SAL_CALL
AccessibleTabListBoxTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
358 TLBSolarGuard aSolarGuard
;
359 ::osl::MutexGuard
aGuard( getOslMutex() );
363 sal_Int32 nRows
= implGetSelRowCount();
365 throw IndexOutOfBoundsException();
367 sal_Int32 nRow
= implGetSelRow( nSelectedChildIndex
% nRows
);
368 sal_Int32 nColumn
= nSelectedChildIndex
/ nRows
;
369 return getAccessibleCellAt( nRow
, nColumn
);
371 // -----------------------------------------------------------------------------
372 void SAL_CALL
AccessibleTabListBoxTable::deselectAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
374 TLBSolarGuard aSolarGuard
;
375 ::osl::MutexGuard
aGuard( getOslMutex() );
378 ensureValidIndex( nSelectedChildIndex
);
380 implSelectRow( implGetRow( nSelectedChildIndex
), sal_False
);
383 //........................................................................
384 }// namespace accessibility
385 //........................................................................