Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / accessibility / source / extended / accessibletablistboxtable.cxx
bloba33c9f1ea77406e4c2eafeced2108545bf5f6096
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "accessibility/extended/accessibletablistboxtable.hxx"
22 #include "accessibility/extended/AccessibleBrowseBoxTableCell.hxx"
23 #include "accessibility/extended/AccessibleBrowseBoxCheckBoxCell.hxx"
24 #include <svtools/svtabbx.hxx>
25 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
27 //........................................................................
28 namespace accessibility
30 //........................................................................
32 // class AccessibleTabListBoxTable ---------------------------------------------
34 using namespace ::com::sun::star::accessibility;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star;
39 // -----------------------------------------------------------------------------
40 // Ctor() and Dtor()
41 // -----------------------------------------------------------------------------
42 AccessibleTabListBoxTable::AccessibleTabListBoxTable( const Reference< XAccessible >& rxParent, SvHeaderTabListBox& rBox ) :
44 AccessibleBrowseBoxTable( rxParent, rBox ),
46 m_pTabListBox ( &rBox )
49 m_pTabListBox->AddEventListener( LINK( this, AccessibleTabListBoxTable, WindowEventListener ) );
51 // -----------------------------------------------------------------------------
52 AccessibleTabListBoxTable::~AccessibleTabListBoxTable()
54 if ( isAlive() )
56 m_pTabListBox = NULL;
58 // increment ref count to prevent double call of Dtor
59 osl_atomic_increment( &m_refCount );
60 dispose();
63 // -----------------------------------------------------------------------------
64 void AccessibleTabListBoxTable::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
66 if ( isAlive() )
68 sal_uLong nEventId = rVclWindowEvent.GetId();
69 switch ( nEventId )
71 case VCLEVENT_OBJECT_DYING :
73 m_pTabListBox->RemoveEventListener( LINK( this, AccessibleTabListBoxTable, WindowEventListener ) );
74 m_pTabListBox = NULL;
75 break;
78 case VCLEVENT_CONTROL_GETFOCUS :
79 case VCLEVENT_CONTROL_LOSEFOCUS :
81 uno::Any aOldValue, aNewValue;
82 if ( VCLEVENT_CONTROL_GETFOCUS == nEventId )
83 aNewValue <<= AccessibleStateType::FOCUSED;
84 else
85 aOldValue <<= AccessibleStateType::FOCUSED;
86 commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
87 break;
90 case VCLEVENT_LISTBOX_SELECT :
92 // First send an event that tells the listeners of a
93 // modified selection. The active descendant event is
94 // send after that so that the receiving AT has time to
95 // read the text or name of the active child.
96 commitEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
97 if ( m_pTabListBox && m_pTabListBox->HasFocus() )
99 SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
100 if ( pEntry )
102 sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
103 sal_uInt16 nCol = m_pTabListBox->GetCurrColumn();
104 Reference< XAccessible > xChild =
105 m_pTabListBox->CreateAccessibleCell( nRow, nCol );
106 uno::Any aOldValue, aNewValue;
108 if ( m_pTabListBox->IsTransientChildrenDisabled() )
110 aNewValue <<= AccessibleStateType::FOCUSED;
111 TriState eState = STATE_DONTKNOW;
112 if ( m_pTabListBox->IsCellCheckBox( nRow, nCol, eState ) )
114 AccessibleCheckBoxCell* pCell =
115 static_cast< AccessibleCheckBoxCell* >( xChild.get() );
116 pCell->commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
118 else
120 AccessibleBrowseBoxTableCell* pCell =
121 static_cast< AccessibleBrowseBoxTableCell* >( xChild.get() );
122 pCell->commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
125 else
127 aNewValue <<= xChild;
128 commitEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aNewValue, aOldValue );
132 break;
135 case VCLEVENT_CHECKBOX_TOGGLE :
137 if ( m_pTabListBox && m_pTabListBox->HasFocus() )
139 SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
140 if ( pEntry )
142 sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
143 sal_uInt16 nCol = m_pTabListBox->GetCurrColumn();
144 TriState eState = STATE_DONTKNOW;
145 if ( m_pTabListBox->IsCellCheckBox( nRow, nCol, eState ) )
147 Reference< XAccessible > xChild =
148 m_pTabListBox->CreateAccessibleCell( nRow, nCol );
149 AccessibleCheckBoxCell* pCell =
150 static_cast< AccessibleCheckBoxCell* >( xChild.get() );
151 pCell->SetChecked( m_pTabListBox->IsItemChecked( pEntry, nCol ) );
155 break;
158 case VCLEVENT_TABLECELL_NAMECHANGED :
160 if ( m_pTabListBox->IsTransientChildrenDisabled() )
162 commitEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
163 TabListBoxEventData* pData = static_cast< TabListBoxEventData* >( rVclWindowEvent.GetData() );
164 SvTreeListEntry* pEntry = pData != NULL ? pData->m_pEntry : NULL;
165 if ( pEntry )
167 sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
168 sal_uInt16 nCol = pData->m_nColumn;
169 Reference< XAccessible > xChild =
170 m_pTabListBox->CreateAccessibleCell( nRow, nCol );
171 uno::Any aOldValue, aNewValue;
172 aOldValue <<= OUString( pData->m_sOldText );
173 OUString sNewText( m_pTabListBox->GetCellText( nRow, nCol ) );
174 aNewValue <<= sNewText;
175 TriState eState = STATE_DONTKNOW;
177 if ( m_pTabListBox->IsCellCheckBox( nRow, nCol, eState ) )
179 AccessibleCheckBoxCell* pCell =
180 static_cast< AccessibleCheckBoxCell* >( xChild.get() );
181 pCell->commitEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
183 else
185 AccessibleBrowseBoxTableCell* pCell =
186 static_cast< AccessibleBrowseBoxTableCell* >( xChild.get() );
187 pCell->nameChanged( sNewText, pData->m_sOldText );
191 break;
196 // -----------------------------------------------------------------------------
197 IMPL_LINK( AccessibleTabListBoxTable, WindowEventListener, VclSimpleEvent*, pEvent )
199 OSL_ENSURE( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
200 if ( pEvent && pEvent->ISA( VclWindowEvent ) )
202 OSL_ENSURE( ( (VclWindowEvent*)pEvent )->GetWindow() && m_pTabListBox, "no event window" );
203 ProcessWindowEvent( *(VclWindowEvent*)pEvent );
205 return 0;
207 // helpers --------------------------------------------------------------------
209 void AccessibleTabListBoxTable::ensureValidIndex( sal_Int32 _nIndex ) const
210 SAL_THROW( ( IndexOutOfBoundsException ) )
212 if ( ( _nIndex < 0 ) || ( _nIndex >= implGetCellCount() ) )
213 throw IndexOutOfBoundsException();
216 sal_Bool AccessibleTabListBoxTable::implIsRowSelected( sal_Int32 _nRow ) const
218 return m_pTabListBox ? m_pTabListBox->IsSelected( m_pTabListBox->GetEntry( _nRow ) ) : sal_False;
221 void AccessibleTabListBoxTable::implSelectRow( sal_Int32 _nRow, sal_Bool _bSelect )
223 if ( m_pTabListBox )
224 m_pTabListBox->Select( m_pTabListBox->GetEntry( _nRow ), _bSelect );
227 sal_Int32 AccessibleTabListBoxTable::implGetRowCount() const
229 return m_pTabListBox ? m_pTabListBox->GetEntryCount() : 0;
232 sal_Int32 AccessibleTabListBoxTable::implGetColumnCount() const
234 return m_pTabListBox ? m_pTabListBox->GetColumnCount() : 0;
237 sal_Int32 AccessibleTabListBoxTable::implGetSelRowCount() const
239 return m_pTabListBox ? m_pTabListBox->GetSelectionCount() : 0;
242 sal_Int32 AccessibleTabListBoxTable::implGetSelRow( sal_Int32 nSelRow ) const
244 if ( m_pTabListBox )
246 sal_Int32 nRow = 0;
247 SvTreeListEntry* pEntry = m_pTabListBox->FirstSelected();
248 while ( pEntry )
250 ++nRow;
251 if ( nRow == nSelRow )
252 return m_pTabListBox->GetEntryPos( pEntry );
253 pEntry = m_pTabListBox->NextSelected( pEntry );
257 return 0;
259 // -----------------------------------------------------------------------------
260 // XInterface & XTypeProvider
261 // -----------------------------------------------------------------------------
262 IMPLEMENT_FORWARD_XINTERFACE2(AccessibleTabListBoxTable, AccessibleBrowseBoxTable, AccessibleTabListBoxTableImplHelper)
263 IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleTabListBoxTable, AccessibleBrowseBoxTable, AccessibleTabListBoxTableImplHelper)
264 // -----------------------------------------------------------------------------
265 // XServiceInfo
266 // -----------------------------------------------------------------------------
267 OUString AccessibleTabListBoxTable::getImplementationName (void) throw (RuntimeException)
269 return OUString( "com.sun.star.comp.svtools.AccessibleTabListBoxTable" );
271 // -----------------------------------------------------------------------------
272 // XAccessibleSelection
273 // -----------------------------------------------------------------------------
274 void SAL_CALL AccessibleTabListBoxTable::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
276 SolarMutexGuard aSolarGuard;
277 ::osl::MutexGuard aGuard( getOslMutex() );
279 ensureIsAlive();
280 ensureValidIndex( nChildIndex );
282 implSelectRow( implGetRow( nChildIndex ), sal_True );
284 // -----------------------------------------------------------------------------
285 sal_Bool SAL_CALL AccessibleTabListBoxTable::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
287 SolarMutexGuard aSolarGuard;
288 ::osl::MutexGuard aGuard( getOslMutex() );
290 ensureIsAlive();
291 ensureValidIndex( nChildIndex );
293 return implIsRowSelected( implGetRow( nChildIndex ) );
295 // -----------------------------------------------------------------------------
296 void SAL_CALL AccessibleTabListBoxTable::clearAccessibleSelection( ) throw (RuntimeException)
298 SolarMutexGuard aSolarGuard;
299 ::osl::MutexGuard aGuard( getOslMutex() );
301 ensureIsAlive();
303 m_pTabListBox->SetNoSelection();
305 // -----------------------------------------------------------------------------
306 void SAL_CALL AccessibleTabListBoxTable::selectAllAccessibleChildren( ) throw (RuntimeException)
308 SolarMutexGuard aSolarGuard;
309 ::osl::MutexGuard aGuard( getOslMutex() );
311 ensureIsAlive();
313 m_pTabListBox->SelectAll();
315 // -----------------------------------------------------------------------------
316 sal_Int32 SAL_CALL AccessibleTabListBoxTable::getSelectedAccessibleChildCount( ) throw (RuntimeException)
318 SolarMutexGuard aSolarGuard;
319 ::osl::MutexGuard aGuard( getOslMutex() );
321 ensureIsAlive();
323 return implGetColumnCount() * implGetSelRowCount();
325 // -----------------------------------------------------------------------------
326 Reference< XAccessible > SAL_CALL AccessibleTabListBoxTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
328 SolarMutexGuard aSolarGuard;
329 ::osl::MutexGuard aGuard( getOslMutex() );
331 ensureIsAlive();
333 sal_Int32 nRows = implGetSelRowCount();
334 if ( nRows == 0 )
335 throw IndexOutOfBoundsException();
337 sal_Int32 nRow = implGetSelRow( nSelectedChildIndex % nRows );
338 sal_Int32 nColumn = nSelectedChildIndex / nRows;
339 return getAccessibleCellAt( nRow, nColumn );
341 // -----------------------------------------------------------------------------
342 void SAL_CALL AccessibleTabListBoxTable::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
344 SolarMutexGuard aSolarGuard;
345 ::osl::MutexGuard aGuard( getOslMutex() );
347 ensureIsAlive();
348 ensureValidIndex( nSelectedChildIndex );
350 implSelectRow( implGetRow( nSelectedChildIndex ), sal_False );
353 //........................................................................
354 }// namespace accessibility
355 //........................................................................
357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */