Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / extended / accessibletablistboxtable.cxx
blobd233aa62429a58874d03d29fd845caa70b71a921
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>
28 namespace accessibility
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;
40 // Ctor() and Dtor()
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 ) );
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();
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 = TRISTATE_INDET;
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;
134 case VCLEVENT_WINDOW_GETFOCUS :
136 uno::Any aOldValue, aNewValue;
137 aNewValue <<= AccessibleStateType::FOCUSED;
138 commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
139 break;
142 case VCLEVENT_WINDOW_LOSEFOCUS :
144 uno::Any aOldValue, aNewValue;
145 aOldValue <<= AccessibleStateType::FOCUSED;
146 commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
147 break;
149 case VCLEVENT_LISTBOX_TREESELECT:
151 SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
152 if (pEntry)
154 sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
155 Reference< XAccessible > xChild = m_pTabListBox->CreateAccessibleCell( nRow, m_pTabListBox->GetCurrColumn() );
156 TriState eState = TRISTATE_INDET;
157 if ( m_pTabListBox->IsCellCheckBox( nRow, m_pTabListBox->GetCurrColumn(), eState ) )
159 AccessibleCheckBoxCell* pCell = static_cast< AccessibleCheckBoxCell* >( xChild.get() );
160 pCell->commitEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
162 else
164 AccessibleBrowseBoxTableCell* pCell = static_cast< AccessibleBrowseBoxTableCell* >( xChild.get() );
165 pCell->commitEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
169 break;
170 case VCLEVENT_LISTBOX_TREEFOCUS:
172 if ( m_pTabListBox && m_pTabListBox->HasFocus() )
174 uno::Any aOldValue, aNewValue;
175 SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
176 if ( pEntry )
178 sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
179 m_xCurChild = m_pTabListBox->CreateAccessibleCell( nRow, m_pTabListBox->GetCurrColumn() );
180 aNewValue <<= m_xCurChild;
181 commitEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aNewValue ,aOldValue);
183 else
185 aNewValue <<= AccessibleStateType::FOCUSED;
186 commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue ,aOldValue);
190 break;
192 case VCLEVENT_CHECKBOX_TOGGLE :
194 if ( m_pTabListBox && m_pTabListBox->HasFocus() )
196 SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
197 if ( pEntry )
199 sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
200 sal_uInt16 nCol = m_pTabListBox->GetCurrColumn();
201 TriState eState = TRISTATE_INDET;
202 if ( m_pTabListBox->IsCellCheckBox( nRow, nCol, eState ) )
204 Reference< XAccessible > xChild =
205 m_pTabListBox->CreateAccessibleCell( nRow, nCol );
206 AccessibleCheckBoxCell* pCell =
207 static_cast< AccessibleCheckBoxCell* >( xChild.get() );
208 pCell->SetChecked( SvHeaderTabListBox::IsItemChecked( pEntry, nCol ) );
212 break;
215 case VCLEVENT_TABLECELL_NAMECHANGED :
217 if ( m_pTabListBox->IsTransientChildrenDisabled() )
219 commitEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
220 TabListBoxEventData* pData = static_cast< TabListBoxEventData* >( rVclWindowEvent.GetData() );
221 SvTreeListEntry* pEntry = pData != NULL ? pData->m_pEntry : NULL;
222 if ( pEntry )
224 sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
225 sal_uInt16 nCol = pData->m_nColumn;
226 Reference< XAccessible > xChild =
227 m_pTabListBox->CreateAccessibleCell( nRow, nCol );
228 uno::Any aOldValue, aNewValue;
229 aOldValue <<= OUString( pData->m_sOldText );
230 OUString sNewText( m_pTabListBox->GetCellText( nRow, nCol ) );
231 aNewValue <<= sNewText;
232 TriState eState = TRISTATE_INDET;
234 if ( m_pTabListBox->IsCellCheckBox( nRow, nCol, eState ) )
236 AccessibleCheckBoxCell* pCell =
237 static_cast< AccessibleCheckBoxCell* >( xChild.get() );
238 pCell->commitEvent( AccessibleEventId::NAME_CHANGED, aNewValue, aOldValue );
240 else
242 AccessibleBrowseBoxTableCell* pCell =
243 static_cast< AccessibleBrowseBoxTableCell* >( xChild.get() );
244 pCell->nameChanged( sNewText, pData->m_sOldText );
248 break;
254 IMPL_LINK( AccessibleTabListBoxTable, WindowEventListener, VclSimpleEvent*, pEvent )
256 OSL_ENSURE( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
257 if ( pEvent && pEvent->ISA( VclWindowEvent ) )
259 OSL_ENSURE( static_cast<VclWindowEvent*>( pEvent )->GetWindow() && m_pTabListBox, "no event window" );
260 ProcessWindowEvent( *static_cast<VclWindowEvent*>(pEvent) );
262 return 0;
264 // helpers --------------------------------------------------------------------
266 void AccessibleTabListBoxTable::ensureValidIndex( sal_Int32 _nIndex ) const
268 if ( ( _nIndex < 0 ) || ( _nIndex >= implGetCellCount() ) )
269 throw IndexOutOfBoundsException();
272 bool AccessibleTabListBoxTable::implIsRowSelected( sal_Int32 _nRow ) const
274 return m_pTabListBox && m_pTabListBox->IsSelected( m_pTabListBox->GetEntry( _nRow ) );
277 void AccessibleTabListBoxTable::implSelectRow( sal_Int32 _nRow, bool _bSelect )
279 if ( m_pTabListBox )
280 m_pTabListBox->Select( m_pTabListBox->GetEntry( _nRow ), _bSelect );
283 sal_Int32 AccessibleTabListBoxTable::implGetRowCount() const
285 return m_pTabListBox ? m_pTabListBox->GetEntryCount() : 0;
288 sal_Int32 AccessibleTabListBoxTable::implGetColumnCount() const
290 return m_pTabListBox ? m_pTabListBox->GetColumnCount() : 0;
293 sal_Int32 AccessibleTabListBoxTable::implGetSelRowCount() const
295 return m_pTabListBox ? m_pTabListBox->GetSelectionCount() : 0;
298 sal_Int32 AccessibleTabListBoxTable::implGetSelRow( sal_Int32 nSelRow ) const
300 if ( m_pTabListBox )
302 sal_Int32 nRow = 0;
303 SvTreeListEntry* pEntry = m_pTabListBox->FirstSelected();
304 while ( pEntry )
306 ++nRow;
307 if ( nRow == nSelRow )
308 return m_pTabListBox->GetEntryPos( pEntry );
309 pEntry = m_pTabListBox->NextSelected( pEntry );
313 return 0;
316 // XInterface & XTypeProvider
318 IMPLEMENT_FORWARD_XINTERFACE2(AccessibleTabListBoxTable, AccessibleBrowseBoxTable, AccessibleTabListBoxTableImplHelper)
319 IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleTabListBoxTable, AccessibleBrowseBoxTable, AccessibleTabListBoxTableImplHelper)
321 // XServiceInfo
323 OUString AccessibleTabListBoxTable::getImplementationName() throw (RuntimeException, std::exception)
325 return OUString( "com.sun.star.comp.svtools.AccessibleTabListBoxTable" );
328 // XAccessibleSelection
330 void SAL_CALL AccessibleTabListBoxTable::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
332 SolarMutexGuard aSolarGuard;
333 ::osl::MutexGuard aGuard( getOslMutex() );
335 ensureIsAlive();
336 ensureValidIndex( nChildIndex );
338 implSelectRow( implGetRow( nChildIndex ), true );
341 sal_Bool SAL_CALL AccessibleTabListBoxTable::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
343 SolarMutexGuard aSolarGuard;
344 ::osl::MutexGuard aGuard( getOslMutex() );
346 ensureIsAlive();
347 ensureValidIndex( nChildIndex );
349 return implIsRowSelected( implGetRow( nChildIndex ) );
352 void SAL_CALL AccessibleTabListBoxTable::clearAccessibleSelection( ) throw (RuntimeException, std::exception)
354 SolarMutexGuard aSolarGuard;
355 ::osl::MutexGuard aGuard( getOslMutex() );
357 ensureIsAlive();
359 m_pTabListBox->SetNoSelection();
362 void SAL_CALL AccessibleTabListBoxTable::selectAllAccessibleChildren( ) throw (RuntimeException, std::exception)
364 SolarMutexGuard aSolarGuard;
365 ::osl::MutexGuard aGuard( getOslMutex() );
367 ensureIsAlive();
369 m_pTabListBox->SelectAll();
372 sal_Int32 SAL_CALL AccessibleTabListBoxTable::getSelectedAccessibleChildCount( ) throw (RuntimeException, std::exception)
374 SolarMutexGuard aSolarGuard;
375 ::osl::MutexGuard aGuard( getOslMutex() );
377 ensureIsAlive();
379 return implGetColumnCount() * implGetSelRowCount();
382 Reference< XAccessible > SAL_CALL AccessibleTabListBoxTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
384 SolarMutexGuard aSolarGuard;
385 ::osl::MutexGuard aGuard( getOslMutex() );
387 ensureIsAlive();
389 sal_Int32 nRows = implGetSelRowCount();
390 if ( nRows == 0 )
391 throw IndexOutOfBoundsException();
393 sal_Int32 nRow = implGetSelRow( nSelectedChildIndex % nRows );
394 sal_Int32 nColumn = nSelectedChildIndex / nRows;
395 return getAccessibleCellAt( nRow, nColumn );
398 void SAL_CALL AccessibleTabListBoxTable::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
400 SolarMutexGuard aSolarGuard;
401 ::osl::MutexGuard aGuard( getOslMutex() );
403 ensureIsAlive();
404 ensureValidIndex( nSelectedChildIndex );
406 implSelectRow( implGetRow( nSelectedChildIndex ), false );
410 }// namespace accessibility
413 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */