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 "accessibility/extended/accessibletablistboxtable.hxx"
31 : : #include "accessibility/extended/AccessibleBrowseBoxTableCell.hxx"
32 : : #include "accessibility/extended/AccessibleBrowseBoxCheckBoxCell.hxx"
33 : : #include <svtools/svtabbx.hxx>
34 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
35 : :
36 : : //........................................................................
37 : : namespace accessibility
38 : : {
39 : : //........................................................................
40 : :
41 : : // class AccessibleTabListBoxTable ---------------------------------------------
42 : :
43 : : using namespace ::com::sun::star::accessibility;
44 : : using namespace ::com::sun::star::uno;
45 : : using namespace ::com::sun::star::lang;
46 : : using namespace ::com::sun::star;
47 : :
48 : : // -----------------------------------------------------------------------------
49 : : // Ctor() and Dtor()
50 : : // -----------------------------------------------------------------------------
51 : 0 : AccessibleTabListBoxTable::AccessibleTabListBoxTable( const Reference< XAccessible >& rxParent, SvHeaderTabListBox& rBox ) :
52 : :
53 : : AccessibleBrowseBoxTable( rxParent, rBox ),
54 : :
55 : 0 : m_pTabListBox ( &rBox )
56 : :
57 : : {
58 [ # # ][ # # ]: 0 : m_pTabListBox->AddEventListener( LINK( this, AccessibleTabListBoxTable, WindowEventListener ) );
59 : 0 : }
60 : : // -----------------------------------------------------------------------------
61 : 0 : AccessibleTabListBoxTable::~AccessibleTabListBoxTable()
62 : : {
63 [ # # ][ # # ]: 0 : if ( isAlive() )
64 : : {
65 : 0 : m_pTabListBox = NULL;
66 : :
67 : : // increment ref count to prevent double call of Dtor
68 [ # # ]: 0 : osl_incrementInterlockedCount( &m_refCount );
69 [ # # ]: 0 : dispose();
70 : : }
71 [ # # ]: 0 : }
72 : : // -----------------------------------------------------------------------------
73 : 0 : void AccessibleTabListBoxTable::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
74 : : {
75 [ # # ]: 0 : if ( isAlive() )
76 : : {
77 : 0 : sal_uLong nEventId = rVclWindowEvent.GetId();
78 [ # # # # : 0 : switch ( nEventId )
# # ]
79 : : {
80 : : case VCLEVENT_OBJECT_DYING :
81 : : {
82 [ # # ]: 0 : m_pTabListBox->RemoveEventListener( LINK( this, AccessibleTabListBoxTable, WindowEventListener ) );
83 : 0 : m_pTabListBox = NULL;
84 : 0 : break;
85 : : }
86 : :
87 : : case VCLEVENT_CONTROL_GETFOCUS :
88 : : case VCLEVENT_CONTROL_LOSEFOCUS :
89 : : {
90 : 0 : uno::Any aOldValue, aNewValue;
91 [ # # ]: 0 : if ( VCLEVENT_CONTROL_GETFOCUS == nEventId )
92 [ # # ]: 0 : aNewValue <<= AccessibleStateType::FOCUSED;
93 : : else
94 [ # # ]: 0 : aOldValue <<= AccessibleStateType::FOCUSED;
95 [ # # ]: 0 : commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
96 : 0 : break;
97 : : }
98 : :
99 : : case VCLEVENT_LISTBOX_SELECT :
100 : : {
101 : : // First send an event that tells the listeners of a
102 : : // modified selection. The active descendant event is
103 : : // send after that so that the receiving AT has time to
104 : : // read the text or name of the active child.
105 [ # # ]: 0 : commitEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
106 [ # # ][ # # ]: 0 : if ( m_pTabListBox && m_pTabListBox->HasFocus() )
[ # # ]
107 : : {
108 : 0 : SvLBoxEntry* pEntry = static_cast< SvLBoxEntry* >( rVclWindowEvent.GetData() );
109 [ # # ]: 0 : if ( pEntry )
110 : : {
111 [ # # ]: 0 : sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
112 [ # # ]: 0 : sal_uInt16 nCol = m_pTabListBox->GetCurrColumn();
113 : : Reference< XAccessible > xChild =
114 [ # # ]: 0 : m_pTabListBox->CreateAccessibleCell( nRow, nCol );
115 : 0 : uno::Any aOldValue, aNewValue;
116 : :
117 [ # # ][ # # ]: 0 : if ( m_pTabListBox->IsTransientChildrenDisabled() )
118 : : {
119 [ # # ]: 0 : aNewValue <<= AccessibleStateType::FOCUSED;
120 : 0 : TriState eState = STATE_DONTKNOW;
121 [ # # ][ # # ]: 0 : if ( m_pTabListBox->IsCellCheckBox( nRow, nCol, eState ) )
122 : : {
123 : : AccessibleCheckBoxCell* pCell =
124 [ # # ][ # # ]: 0 : static_cast< AccessibleCheckBoxCell* >( xChild.get() );
125 [ # # ]: 0 : pCell->commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
126 : : }
127 : : else
128 : : {
129 : : AccessibleBrowseBoxTableCell* pCell =
130 [ # # ][ # # ]: 0 : static_cast< AccessibleBrowseBoxTableCell* >( xChild.get() );
131 [ # # ]: 0 : pCell->commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
132 : : }
133 : : }
134 : : else
135 : : {
136 [ # # ]: 0 : aNewValue <<= xChild;
137 [ # # ]: 0 : commitEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aNewValue, aOldValue );
138 : 0 : }
139 : : }
140 : : }
141 : 0 : break;
142 : : }
143 : :
144 : : case VCLEVENT_CHECKBOX_TOGGLE :
145 : : {
146 [ # # ][ # # ]: 0 : if ( m_pTabListBox && m_pTabListBox->HasFocus() )
[ # # ]
147 : : {
148 : 0 : SvLBoxEntry* pEntry = static_cast< SvLBoxEntry* >( rVclWindowEvent.GetData() );
149 [ # # ]: 0 : if ( pEntry )
150 : : {
151 [ # # ]: 0 : sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
152 [ # # ]: 0 : sal_uInt16 nCol = m_pTabListBox->GetCurrColumn();
153 : 0 : TriState eState = STATE_DONTKNOW;
154 [ # # ][ # # ]: 0 : if ( m_pTabListBox->IsCellCheckBox( nRow, nCol, eState ) )
155 : : {
156 : : Reference< XAccessible > xChild =
157 [ # # ]: 0 : m_pTabListBox->CreateAccessibleCell( nRow, nCol );
158 : : AccessibleCheckBoxCell* pCell =
159 [ # # ][ # # ]: 0 : static_cast< AccessibleCheckBoxCell* >( xChild.get() );
160 [ # # ][ # # ]: 0 : pCell->SetChecked( m_pTabListBox->IsItemChecked( pEntry, nCol ) );
161 : : }
162 : : }
163 : : }
164 : 0 : break;
165 : : }
166 : :
167 : : case VCLEVENT_TABLECELL_NAMECHANGED :
168 : : {
169 [ # # ]: 0 : if ( m_pTabListBox->IsTransientChildrenDisabled() )
170 : : {
171 [ # # ]: 0 : commitEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
172 : 0 : TabListBoxEventData* pData = static_cast< TabListBoxEventData* >( rVclWindowEvent.GetData() );
173 [ # # ]: 0 : SvLBoxEntry* pEntry = pData != NULL ? pData->m_pEntry : NULL;
174 [ # # ]: 0 : if ( pEntry )
175 : : {
176 [ # # ]: 0 : sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
177 : 0 : sal_uInt16 nCol = pData->m_nColumn;
178 : : Reference< XAccessible > xChild =
179 [ # # ]: 0 : m_pTabListBox->CreateAccessibleCell( nRow, nCol );
180 : 0 : uno::Any aOldValue, aNewValue;
181 [ # # ][ # # ]: 0 : aOldValue <<= ::rtl::OUString( pData->m_sOldText );
182 [ # # ][ # # ]: 0 : ::rtl::OUString sNewText( m_pTabListBox->GetCellText( nRow, nCol ) );
[ # # ]
183 [ # # ]: 0 : aNewValue <<= sNewText;
184 : 0 : TriState eState = STATE_DONTKNOW;
185 : :
186 [ # # ][ # # ]: 0 : if ( m_pTabListBox->IsCellCheckBox( nRow, nCol, eState ) )
187 : : {
188 : : AccessibleCheckBoxCell* pCell =
189 [ # # ][ # # ]: 0 : static_cast< AccessibleCheckBoxCell* >( xChild.get() );
190 [ # # ]: 0 : pCell->commitEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
191 : : }
192 : : else
193 : : {
194 : : AccessibleBrowseBoxTableCell* pCell =
195 [ # # ][ # # ]: 0 : static_cast< AccessibleBrowseBoxTableCell* >( xChild.get() );
196 [ # # ][ # # ]: 0 : pCell->nameChanged( sNewText, pData->m_sOldText );
197 : 0 : }
198 : : }
199 : : }
200 : 0 : break;
201 : : }
202 : : }
203 : : }
204 : 0 : }
205 : : // -----------------------------------------------------------------------------
206 : 0 : IMPL_LINK( AccessibleTabListBoxTable, WindowEventListener, VclSimpleEvent*, pEvent )
207 : : {
208 : : OSL_ENSURE( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
209 [ # # ][ # # ]: 0 : if ( pEvent && pEvent->ISA( VclWindowEvent ) )
[ # # ]
210 : : {
211 : : OSL_ENSURE( ( (VclWindowEvent*)pEvent )->GetWindow() && m_pTabListBox, "no event window" );
212 : 0 : ProcessWindowEvent( *(VclWindowEvent*)pEvent );
213 : : }
214 : 0 : return 0;
215 : : }
216 : : // helpers --------------------------------------------------------------------
217 : :
218 : 0 : void AccessibleTabListBoxTable::ensureValidIndex( sal_Int32 _nIndex ) const
219 : : SAL_THROW( ( IndexOutOfBoundsException ) )
220 : : {
221 [ # # ][ # # ]: 0 : if ( ( _nIndex < 0 ) || ( _nIndex >= implGetCellCount() ) )
[ # # ]
222 [ # # ]: 0 : throw IndexOutOfBoundsException();
223 : 0 : }
224 : :
225 : 0 : sal_Bool AccessibleTabListBoxTable::implIsRowSelected( sal_Int32 _nRow ) const
226 : : {
227 [ # # ]: 0 : return m_pTabListBox ? m_pTabListBox->IsSelected( m_pTabListBox->GetEntry( _nRow ) ) : sal_False;
228 : : }
229 : :
230 : 0 : void AccessibleTabListBoxTable::implSelectRow( sal_Int32 _nRow, sal_Bool _bSelect )
231 : : {
232 [ # # ]: 0 : if ( m_pTabListBox )
233 : 0 : m_pTabListBox->Select( m_pTabListBox->GetEntry( _nRow ), _bSelect );
234 : 0 : }
235 : :
236 : 0 : sal_Int32 AccessibleTabListBoxTable::implGetRowCount() const
237 : : {
238 [ # # ]: 0 : return m_pTabListBox ? m_pTabListBox->GetEntryCount() : 0;
239 : : }
240 : :
241 : 0 : sal_Int32 AccessibleTabListBoxTable::implGetColumnCount() const
242 : : {
243 [ # # ]: 0 : return m_pTabListBox ? m_pTabListBox->GetColumnCount() : 0;
244 : : }
245 : :
246 : 0 : sal_Int32 AccessibleTabListBoxTable::implGetSelRowCount() const
247 : : {
248 [ # # ]: 0 : return m_pTabListBox ? m_pTabListBox->GetSelectionCount() : 0;
249 : : }
250 : :
251 : 0 : sal_Int32 AccessibleTabListBoxTable::implGetSelRow( sal_Int32 nSelRow ) const
252 : : {
253 [ # # ]: 0 : if ( m_pTabListBox )
254 : : {
255 : 0 : sal_Int32 nRow = 0;
256 : 0 : SvLBoxEntry* pEntry = m_pTabListBox->FirstSelected();
257 [ # # ]: 0 : while ( pEntry )
258 : : {
259 : 0 : ++nRow;
260 [ # # ]: 0 : if ( nRow == nSelRow )
261 : 0 : return m_pTabListBox->GetEntryPos( pEntry );
262 : 0 : pEntry = m_pTabListBox->NextSelected( pEntry );
263 : : }
264 : : }
265 : :
266 : 0 : return 0;
267 : : }
268 : : // -----------------------------------------------------------------------------
269 : : // XInterface & XTypeProvider
270 : : // -----------------------------------------------------------------------------
271 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XINTERFACE2(AccessibleTabListBoxTable, AccessibleBrowseBoxTable, AccessibleTabListBoxTableImplHelper)
272 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleTabListBoxTable, AccessibleBrowseBoxTable, AccessibleTabListBoxTableImplHelper)
[ # # ]
273 : : // -----------------------------------------------------------------------------
274 : : // XServiceInfo
275 : : // -----------------------------------------------------------------------------
276 : 0 : ::rtl::OUString AccessibleTabListBoxTable::getImplementationName (void) throw (RuntimeException)
277 : : {
278 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.AccessibleTabListBoxTable" ));
279 : : }
280 : : // -----------------------------------------------------------------------------
281 : : // XAccessibleSelection
282 : : // -----------------------------------------------------------------------------
283 : 0 : void SAL_CALL AccessibleTabListBoxTable::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
284 : : {
285 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
286 [ # # ]: 0 : ::osl::MutexGuard aGuard( getOslMutex() );
287 : :
288 [ # # ]: 0 : ensureIsAlive();
289 [ # # ]: 0 : ensureValidIndex( nChildIndex );
290 : :
291 [ # # ][ # # ]: 0 : implSelectRow( implGetRow( nChildIndex ), sal_True );
[ # # ][ # # ]
292 : 0 : }
293 : : // -----------------------------------------------------------------------------
294 : 0 : sal_Bool SAL_CALL AccessibleTabListBoxTable::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
295 : : {
296 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
297 [ # # ]: 0 : ::osl::MutexGuard aGuard( getOslMutex() );
298 : :
299 [ # # ]: 0 : ensureIsAlive();
300 [ # # ]: 0 : ensureValidIndex( nChildIndex );
301 : :
302 [ # # ][ # # ]: 0 : return implIsRowSelected( implGetRow( nChildIndex ) );
[ # # ][ # # ]
303 : : }
304 : : // -----------------------------------------------------------------------------
305 : 0 : void SAL_CALL AccessibleTabListBoxTable::clearAccessibleSelection( ) throw (RuntimeException)
306 : : {
307 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
308 [ # # ]: 0 : ::osl::MutexGuard aGuard( getOslMutex() );
309 : :
310 [ # # ]: 0 : ensureIsAlive();
311 : :
312 [ # # ][ # # ]: 0 : m_pTabListBox->SetNoSelection();
[ # # ]
313 : 0 : }
314 : : // -----------------------------------------------------------------------------
315 : 0 : void SAL_CALL AccessibleTabListBoxTable::selectAllAccessibleChildren( ) throw (RuntimeException)
316 : : {
317 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
318 [ # # ]: 0 : ::osl::MutexGuard aGuard( getOslMutex() );
319 : :
320 [ # # ]: 0 : ensureIsAlive();
321 : :
322 [ # # ][ # # ]: 0 : m_pTabListBox->SelectAll();
[ # # ]
323 : 0 : }
324 : : // -----------------------------------------------------------------------------
325 : 0 : sal_Int32 SAL_CALL AccessibleTabListBoxTable::getSelectedAccessibleChildCount( ) throw (RuntimeException)
326 : : {
327 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
328 [ # # ]: 0 : ::osl::MutexGuard aGuard( getOslMutex() );
329 : :
330 [ # # ]: 0 : ensureIsAlive();
331 : :
332 [ # # ][ # # ]: 0 : return implGetColumnCount() * implGetSelRowCount();
[ # # ]
333 : : }
334 : : // -----------------------------------------------------------------------------
335 : 0 : Reference< XAccessible > SAL_CALL AccessibleTabListBoxTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
336 : : {
337 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
338 [ # # ]: 0 : ::osl::MutexGuard aGuard( getOslMutex() );
339 : :
340 [ # # ]: 0 : ensureIsAlive();
341 : :
342 : 0 : sal_Int32 nRows = implGetSelRowCount();
343 [ # # ]: 0 : if ( nRows == 0 )
344 [ # # ]: 0 : throw IndexOutOfBoundsException();
345 : :
346 [ # # ]: 0 : sal_Int32 nRow = implGetSelRow( nSelectedChildIndex % nRows );
347 : 0 : sal_Int32 nColumn = nSelectedChildIndex / nRows;
348 [ # # ][ # # ]: 0 : return getAccessibleCellAt( nRow, nColumn );
[ # # ]
349 : : }
350 : : // -----------------------------------------------------------------------------
351 : 0 : void SAL_CALL AccessibleTabListBoxTable::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
352 : : {
353 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
354 [ # # ]: 0 : ::osl::MutexGuard aGuard( getOslMutex() );
355 : :
356 [ # # ]: 0 : ensureIsAlive();
357 [ # # ]: 0 : ensureValidIndex( nSelectedChildIndex );
358 : :
359 [ # # ][ # # ]: 0 : implSelectRow( implGetRow( nSelectedChildIndex ), sal_False );
[ # # ][ # # ]
360 : 0 : }
361 : :
362 : : //........................................................................
363 : : }// namespace accessibility
364 : : //........................................................................
365 : :
366 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|