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