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 : #include "thumbnailviewacc.hxx"
21 :
22 : #include <comphelper/servicehelper.hxx>
23 : #include <sfx2/thumbnailview.hxx>
24 : #include <sfx2/thumbnailviewitem.hxx>
25 : #include <unotools/accessiblestatesethelper.hxx>
26 : #include <vcl/svapp.hxx>
27 :
28 : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
30 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
31 :
32 : using namespace ::com::sun::star;
33 :
34 0 : ThumbnailViewAcc::ThumbnailViewAcc( ThumbnailView* pParent, bool bIsTransientChildrenDisabled ) :
35 : ValueSetAccComponentBase (m_aMutex),
36 : mpParent( pParent ),
37 : mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled ),
38 0 : mbIsFocused(false)
39 : {
40 0 : }
41 :
42 0 : ThumbnailViewAcc::~ThumbnailViewAcc()
43 : {
44 0 : }
45 :
46 0 : void ThumbnailViewAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
47 : {
48 0 : if( nEventId )
49 : {
50 0 : ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners );
51 0 : accessibility::AccessibleEventObject aEvtObject;
52 :
53 0 : aEvtObject.EventId = nEventId;
54 0 : aEvtObject.Source = static_cast<uno::XWeak*>(this);
55 0 : aEvtObject.NewValue = rNewValue;
56 0 : aEvtObject.OldValue = rOldValue;
57 :
58 0 : for (::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter( aTmpListeners.begin() ), aEnd( aTmpListeners.end() );
59 : aIter != aEnd ; ++aIter)
60 : {
61 : try
62 : {
63 0 : (*aIter)->notifyEvent( aEvtObject );
64 : }
65 0 : catch(const uno::Exception&)
66 : {
67 : }
68 0 : }
69 : }
70 0 : }
71 :
72 : namespace
73 : {
74 : class theValueSetAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueSetAccUnoTunnelId > {};
75 : }
76 :
77 0 : const uno::Sequence< sal_Int8 >& ThumbnailViewAcc::getUnoTunnelId()
78 : {
79 0 : return theValueSetAccUnoTunnelId::get().getSeq();
80 : }
81 :
82 0 : ThumbnailViewAcc* ThumbnailViewAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
83 : throw()
84 : {
85 : try
86 : {
87 0 : uno::Reference< lang::XUnoTunnel > xUnoTunnel( rxData, uno::UNO_QUERY );
88 0 : return( xUnoTunnel.is() ? reinterpret_cast<ThumbnailViewAcc*>(sal::static_int_cast<sal_IntPtr>(xUnoTunnel->getSomething( ThumbnailViewAcc::getUnoTunnelId() ))) : NULL );
89 : }
90 0 : catch(const ::com::sun::star::uno::Exception&)
91 : {
92 0 : return NULL;
93 : }
94 : }
95 :
96 0 : void ThumbnailViewAcc::GetFocus (void)
97 : {
98 0 : mbIsFocused = true;
99 :
100 : // Boradcast the state change.
101 0 : ::com::sun::star::uno::Any aOldState, aNewState;
102 0 : aNewState <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
103 : FireAccessibleEvent(
104 : ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED,
105 0 : aOldState, aNewState);
106 0 : }
107 :
108 0 : void ThumbnailViewAcc::LoseFocus (void)
109 : {
110 0 : mbIsFocused = false;
111 :
112 : // Boradcast the state change.
113 0 : ::com::sun::star::uno::Any aOldState, aNewState;
114 0 : aOldState <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
115 : FireAccessibleEvent(
116 : ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED,
117 0 : aOldState, aNewState);
118 0 : }
119 :
120 0 : uno::Reference< accessibility::XAccessibleContext > SAL_CALL ThumbnailViewAcc::getAccessibleContext()
121 : throw (uno::RuntimeException)
122 : {
123 0 : ThrowIfDisposed();
124 0 : return this;
125 : }
126 :
127 0 : sal_Int32 SAL_CALL ThumbnailViewAcc::getAccessibleChildCount()
128 : throw (uno::RuntimeException)
129 : {
130 0 : const SolarMutexGuard aSolarGuard;
131 0 : ThrowIfDisposed();
132 :
133 0 : sal_Int32 nCount = mpParent->ImplGetVisibleItemCount();
134 0 : return nCount;
135 : }
136 :
137 0 : uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleChild( sal_Int32 i )
138 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
139 : {
140 0 : ThrowIfDisposed();
141 0 : const SolarMutexGuard aSolarGuard;
142 0 : uno::Reference< accessibility::XAccessible > xRet;
143 0 : ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(i));
144 :
145 0 : if( pItem )
146 0 : xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
147 : else
148 0 : throw lang::IndexOutOfBoundsException();
149 :
150 0 : return xRet;
151 : }
152 :
153 0 : uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleParent()
154 : throw (uno::RuntimeException)
155 : {
156 0 : ThrowIfDisposed();
157 0 : const SolarMutexGuard aSolarGuard;
158 0 : Window* pParent = mpParent->GetParent();
159 0 : uno::Reference< accessibility::XAccessible > xRet;
160 :
161 0 : if( pParent )
162 0 : xRet = pParent->GetAccessible();
163 :
164 0 : return xRet;
165 : }
166 :
167 0 : sal_Int32 SAL_CALL ThumbnailViewAcc::getAccessibleIndexInParent()
168 : throw (uno::RuntimeException)
169 : {
170 0 : ThrowIfDisposed();
171 0 : const SolarMutexGuard aSolarGuard;
172 0 : Window* pParent = mpParent->GetParent();
173 0 : sal_Int32 nRet = 0;
174 :
175 0 : if( pParent )
176 : {
177 0 : sal_Bool bFound = sal_False;
178 :
179 0 : for( sal_uInt16 i = 0, nCount = pParent->GetChildCount(); ( i < nCount ) && !bFound; i++ )
180 : {
181 0 : if( pParent->GetChild( i ) == mpParent )
182 : {
183 0 : nRet = i;
184 0 : bFound = sal_True;
185 : }
186 : }
187 : }
188 :
189 0 : return nRet;
190 : }
191 :
192 0 : sal_Int16 SAL_CALL ThumbnailViewAcc::getAccessibleRole()
193 : throw (uno::RuntimeException)
194 : {
195 0 : ThrowIfDisposed();
196 : // #i73746# As the Java Access Bridge (v 2.0.1) uses "managesDescendants"
197 : // always if the role is LIST, we need a different role in this case
198 : return (mbIsTransientChildrenDisabled
199 : ? accessibility::AccessibleRole::PANEL
200 0 : : accessibility::AccessibleRole::LIST );
201 : }
202 :
203 0 : OUString SAL_CALL ThumbnailViewAcc::getAccessibleDescription()
204 : throw (uno::RuntimeException)
205 : {
206 0 : ThrowIfDisposed();
207 0 : const SolarMutexGuard aSolarGuard;
208 0 : return OUString("ThumbnailView");
209 : }
210 :
211 0 : OUString SAL_CALL ThumbnailViewAcc::getAccessibleName()
212 : throw (uno::RuntimeException)
213 : {
214 0 : ThrowIfDisposed();
215 0 : const SolarMutexGuard aSolarGuard;
216 0 : OUString aRet;
217 :
218 0 : if ( mpParent )
219 0 : aRet = mpParent->GetAccessibleName();
220 :
221 0 : if ( aRet.isEmpty() )
222 : {
223 0 : Window* pLabel = mpParent->GetAccessibleRelationLabeledBy();
224 0 : if ( pLabel && pLabel != mpParent )
225 0 : aRet = OutputDevice::GetNonMnemonicString( pLabel->GetText() );
226 : }
227 :
228 0 : return aRet;
229 : }
230 :
231 0 : uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewAcc::getAccessibleRelationSet()
232 : throw (uno::RuntimeException)
233 : {
234 0 : ThrowIfDisposed();
235 0 : return uno::Reference< accessibility::XAccessibleRelationSet >();
236 : }
237 :
238 0 : uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ThumbnailViewAcc::getAccessibleStateSet()
239 : throw (uno::RuntimeException)
240 : {
241 0 : ThrowIfDisposed();
242 0 : ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
243 :
244 : // Set some states.
245 0 : pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
246 0 : pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
247 0 : pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
248 0 : pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
249 0 : if ( !mbIsTransientChildrenDisabled )
250 0 : pStateSet->AddState (accessibility::AccessibleStateType::MANAGES_DESCENDANTS);
251 0 : pStateSet->AddState (accessibility::AccessibleStateType::FOCUSABLE);
252 0 : if (mbIsFocused)
253 0 : pStateSet->AddState (accessibility::AccessibleStateType::FOCUSED);
254 :
255 0 : return pStateSet;
256 : }
257 :
258 0 : lang::Locale SAL_CALL ThumbnailViewAcc::getLocale()
259 : throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException)
260 : {
261 0 : ThrowIfDisposed();
262 0 : const SolarMutexGuard aSolarGuard;
263 0 : const OUString aEmptyStr;
264 0 : uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
265 0 : lang::Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
266 :
267 0 : if( xParent.is() )
268 : {
269 0 : uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
270 :
271 0 : if( xParentContext.is() )
272 0 : aRet = xParentContext->getLocale ();
273 : }
274 :
275 0 : return aRet;
276 : }
277 :
278 0 : void SAL_CALL ThumbnailViewAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
279 : throw (uno::RuntimeException)
280 : {
281 0 : ThrowIfDisposed();
282 0 : ::osl::MutexGuard aGuard (m_aMutex);
283 :
284 0 : if( rxListener.is() )
285 : {
286 0 : std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter = mxEventListeners.begin();
287 0 : bool bFound = false;
288 :
289 0 : while( !bFound && ( aIter != mxEventListeners.end() ) )
290 : {
291 0 : if( *aIter == rxListener )
292 0 : bFound = true;
293 : else
294 0 : ++aIter;
295 : }
296 :
297 0 : if (!bFound)
298 0 : mxEventListeners.push_back( rxListener );
299 0 : }
300 0 : }
301 :
302 0 : void SAL_CALL ThumbnailViewAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
303 : throw (uno::RuntimeException)
304 : {
305 0 : ThrowIfDisposed();
306 0 : ::osl::MutexGuard aGuard (m_aMutex);
307 :
308 0 : if( rxListener.is() )
309 : {
310 0 : std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter = mxEventListeners.begin();
311 0 : bool bFound = false;
312 :
313 0 : while( !bFound && ( aIter != mxEventListeners.end() ) )
314 : {
315 0 : if( *aIter == rxListener )
316 : {
317 0 : mxEventListeners.erase( aIter );
318 0 : bFound = true;
319 : }
320 : else
321 0 : ++aIter;
322 : }
323 0 : }
324 0 : }
325 :
326 0 : sal_Bool SAL_CALL ThumbnailViewAcc::containsPoint( const awt::Point& aPoint )
327 : throw (uno::RuntimeException)
328 : {
329 0 : ThrowIfDisposed();
330 0 : const awt::Rectangle aRect( getBounds() );
331 0 : const Point aSize( aRect.Width, aRect.Height );
332 0 : const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
333 :
334 0 : return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
335 : }
336 :
337 0 : uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleAtPoint( const awt::Point& aPoint )
338 : throw (uno::RuntimeException)
339 : {
340 0 : ThrowIfDisposed();
341 0 : const SolarMutexGuard aSolarGuard;
342 0 : const sal_uInt16 nItemId = mpParent->GetItemId( Point( aPoint.X, aPoint.Y ) );
343 0 : uno::Reference< accessibility::XAccessible > xRet;
344 :
345 0 : if ( nItemId )
346 : {
347 0 : const size_t nItemPos = mpParent->GetItemPos( nItemId );
348 :
349 0 : if( THUMBNAILVIEW_ITEM_NONEITEM != nItemPos )
350 : {
351 0 : ThumbnailViewItem *const pItem = mpParent->mFilteredItemList[nItemPos];
352 0 : xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
353 : }
354 : }
355 :
356 0 : return xRet;
357 : }
358 :
359 0 : awt::Rectangle SAL_CALL ThumbnailViewAcc::getBounds()
360 : throw (uno::RuntimeException)
361 : {
362 0 : ThrowIfDisposed();
363 0 : const SolarMutexGuard aSolarGuard;
364 0 : const Point aOutPos( mpParent->GetPosPixel() );
365 0 : const Size aOutSize( mpParent->GetOutputSizePixel() );
366 0 : awt::Rectangle aRet;
367 :
368 0 : aRet.X = aOutPos.X();
369 0 : aRet.Y = aOutPos.Y();
370 0 : aRet.Width = aOutSize.Width();
371 0 : aRet.Height = aOutSize.Height();
372 :
373 0 : return aRet;
374 : }
375 :
376 0 : awt::Point SAL_CALL ThumbnailViewAcc::getLocation()
377 : throw (uno::RuntimeException)
378 : {
379 0 : ThrowIfDisposed();
380 0 : const awt::Rectangle aRect( getBounds() );
381 0 : awt::Point aRet;
382 :
383 0 : aRet.X = aRect.X;
384 0 : aRet.Y = aRect.Y;
385 :
386 0 : return aRet;
387 : }
388 :
389 0 : awt::Point SAL_CALL ThumbnailViewAcc::getLocationOnScreen()
390 : throw (uno::RuntimeException)
391 : {
392 0 : ThrowIfDisposed();
393 0 : const SolarMutexGuard aSolarGuard;
394 0 : const Point aScreenPos( mpParent->OutputToAbsoluteScreenPixel( Point() ) );
395 0 : awt::Point aRet;
396 :
397 0 : aRet.X = aScreenPos.X();
398 0 : aRet.Y = aScreenPos.Y();
399 :
400 0 : return aRet;
401 : }
402 :
403 0 : awt::Size SAL_CALL ThumbnailViewAcc::getSize()
404 : throw (uno::RuntimeException)
405 : {
406 0 : ThrowIfDisposed();
407 0 : const awt::Rectangle aRect( getBounds() );
408 0 : awt::Size aRet;
409 :
410 0 : aRet.Width = aRect.Width;
411 0 : aRet.Height = aRect.Height;
412 :
413 0 : return aRet;
414 : }
415 :
416 0 : void SAL_CALL ThumbnailViewAcc::grabFocus()
417 : throw (uno::RuntimeException)
418 : {
419 0 : ThrowIfDisposed();
420 0 : const SolarMutexGuard aSolarGuard;
421 0 : mpParent->GrabFocus();
422 0 : }
423 :
424 0 : uno::Any SAL_CALL ThumbnailViewAcc::getAccessibleKeyBinding()
425 : throw (uno::RuntimeException)
426 : {
427 0 : ThrowIfDisposed();
428 0 : return uno::Any();
429 : }
430 :
431 0 : sal_Int32 SAL_CALL ThumbnailViewAcc::getForeground( )
432 : throw (uno::RuntimeException)
433 : {
434 0 : ThrowIfDisposed();
435 0 : sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
436 0 : return static_cast<sal_Int32>(nColor);
437 : }
438 :
439 0 : sal_Int32 SAL_CALL ThumbnailViewAcc::getBackground( )
440 : throw (uno::RuntimeException)
441 : {
442 0 : ThrowIfDisposed();
443 0 : sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
444 0 : return static_cast<sal_Int32>(nColor);
445 : }
446 :
447 0 : void SAL_CALL ThumbnailViewAcc::selectAccessibleChild( sal_Int32 nChildIndex )
448 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
449 : {
450 0 : ThrowIfDisposed();
451 0 : const SolarMutexGuard aSolarGuard;
452 0 : ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
453 :
454 0 : if(pItem != NULL)
455 : {
456 0 : mpParent->SelectItem( pItem->mnId );
457 : }
458 : else
459 0 : throw lang::IndexOutOfBoundsException();
460 0 : }
461 :
462 0 : sal_Bool SAL_CALL ThumbnailViewAcc::isAccessibleChildSelected( sal_Int32 nChildIndex )
463 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
464 : {
465 0 : ThrowIfDisposed();
466 0 : const SolarMutexGuard aSolarGuard;
467 0 : ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
468 0 : sal_Bool bRet = sal_False;
469 :
470 0 : if (pItem != NULL)
471 0 : bRet = mpParent->IsItemSelected( pItem->mnId );
472 : else
473 0 : throw lang::IndexOutOfBoundsException();
474 :
475 0 : return bRet;
476 : }
477 :
478 0 : void SAL_CALL ThumbnailViewAcc::clearAccessibleSelection()
479 : throw (uno::RuntimeException)
480 : {
481 0 : ThrowIfDisposed();
482 0 : const SolarMutexGuard aSolarGuard;
483 0 : }
484 :
485 0 : void SAL_CALL ThumbnailViewAcc::selectAllAccessibleChildren()
486 : throw (uno::RuntimeException)
487 : {
488 0 : ThrowIfDisposed();
489 : // unsupported due to single selection only
490 0 : }
491 :
492 0 : sal_Int32 SAL_CALL ThumbnailViewAcc::getSelectedAccessibleChildCount()
493 : throw (uno::RuntimeException)
494 : {
495 0 : ThrowIfDisposed();
496 0 : const SolarMutexGuard aSolarGuard;
497 0 : sal_Int32 nRet = 0;
498 :
499 0 : for( sal_uInt16 i = 0, nCount = getItemCount(); i < nCount; i++ )
500 : {
501 0 : ThumbnailViewItem* pItem = getItem (i);
502 :
503 0 : if( pItem && mpParent->IsItemSelected( pItem->mnId ) )
504 0 : ++nRet;
505 : }
506 :
507 0 : return nRet;
508 : }
509 :
510 0 : uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
511 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
512 : {
513 0 : ThrowIfDisposed();
514 0 : const SolarMutexGuard aSolarGuard;
515 0 : uno::Reference< accessibility::XAccessible > xRet;
516 :
517 0 : for( sal_uInt16 i = 0, nCount = getItemCount(), nSel = 0; ( i < nCount ) && !xRet.is(); i++ )
518 : {
519 0 : ThumbnailViewItem* pItem = getItem(i);
520 :
521 0 : if( pItem && mpParent->IsItemSelected( pItem->mnId ) && ( nSelectedChildIndex == static_cast< sal_Int32 >( nSel++ ) ) )
522 0 : xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
523 : }
524 :
525 0 : return xRet;
526 : }
527 :
528 0 : void SAL_CALL ThumbnailViewAcc::deselectAccessibleChild( sal_Int32 nChildIndex )
529 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
530 : {
531 0 : ThrowIfDisposed();
532 0 : const SolarMutexGuard aSolarGuard;
533 : // Because of the single selection we can reset the whole selection when
534 : // the specified child is currently selected.
535 : //FIXME TODO if (isAccessibleChildSelected(nChildIndex))
536 : //FIXME TODO ;
537 0 : (void) nChildIndex;
538 0 : }
539 :
540 0 : sal_Int64 SAL_CALL ThumbnailViewAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException )
541 : {
542 : sal_Int64 nRet;
543 :
544 0 : if( ( rId.getLength() == 16 ) && ( 0 == memcmp( ThumbnailViewAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
545 0 : nRet = reinterpret_cast< sal_Int64 >( this );
546 : else
547 0 : nRet = 0;
548 :
549 0 : return nRet;
550 : }
551 :
552 0 : void SAL_CALL ThumbnailViewAcc::disposing (void)
553 : {
554 0 : ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> > aListenerListCopy;
555 :
556 : {
557 : // Make a copy of the list and clear the original.
558 0 : const SolarMutexGuard aSolarGuard;
559 0 : ::osl::MutexGuard aGuard (m_aMutex);
560 0 : aListenerListCopy = mxEventListeners;
561 0 : mxEventListeners.clear();
562 :
563 : // Reset the pointer to the parent. It has to be the one who has
564 : // disposed us because he is dying.
565 0 : mpParent = NULL;
566 : }
567 :
568 : // Inform all listeners that this objects is disposing.
569 : ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> >::const_iterator
570 0 : aListenerIterator (aListenerListCopy.begin());
571 0 : lang::EventObject aEvent (static_cast<accessibility::XAccessible*>(this));
572 0 : while (aListenerIterator != aListenerListCopy.end())
573 : {
574 : try
575 : {
576 0 : (*aListenerIterator)->disposing (aEvent);
577 : }
578 0 : catch(const uno::Exception&)
579 : {
580 : // Ignore exceptions.
581 : }
582 :
583 0 : ++aListenerIterator;
584 0 : }
585 0 : }
586 :
587 0 : sal_uInt16 ThumbnailViewAcc::getItemCount (void) const
588 : {
589 0 : return mpParent->ImplGetVisibleItemCount();
590 : }
591 :
592 0 : ThumbnailViewItem* ThumbnailViewAcc::getItem (sal_uInt16 nIndex) const
593 : {
594 0 : return mpParent->ImplGetVisibleItem (static_cast<sal_uInt16>(nIndex));
595 : }
596 :
597 0 : void ThumbnailViewAcc::ThrowIfDisposed (void)
598 : throw (::com::sun::star::lang::DisposedException)
599 : {
600 0 : if (rBHelper.bDisposed || rBHelper.bInDispose)
601 : {
602 : OSL_TRACE ("Calling disposed object. Throwing exception:");
603 : throw lang::DisposedException (
604 : OUString("object has been already disposed"),
605 0 : static_cast<uno::XWeak*>(this));
606 : }
607 : else
608 : {
609 : DBG_ASSERT (mpParent!=NULL, "ValueSetAcc not disposed but mpParent == NULL");
610 : }
611 0 : }
612 :
613 0 : ThumbnailViewItemAcc::ThumbnailViewItemAcc( ThumbnailViewItem* pParent, bool bIsTransientChildrenDisabled ) :
614 : mpParent( pParent ),
615 0 : mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled )
616 : {
617 0 : }
618 :
619 0 : ThumbnailViewItemAcc::~ThumbnailViewItemAcc()
620 : {
621 0 : }
622 :
623 0 : void ThumbnailViewItemAcc::ParentDestroyed()
624 : {
625 0 : const ::osl::MutexGuard aGuard( maMutex );
626 0 : mpParent = NULL;
627 0 : }
628 :
629 : namespace
630 : {
631 : class theValueItemAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueItemAccUnoTunnelId > {};
632 : }
633 :
634 0 : const uno::Sequence< sal_Int8 >& ThumbnailViewItemAcc::getUnoTunnelId()
635 : {
636 0 : return theValueItemAccUnoTunnelId::get().getSeq();
637 : }
638 :
639 0 : uno::Reference< accessibility::XAccessibleContext > SAL_CALL ThumbnailViewItemAcc::getAccessibleContext()
640 : throw (uno::RuntimeException)
641 : {
642 0 : return this;
643 : }
644 :
645 0 : sal_Int32 SAL_CALL ThumbnailViewItemAcc::getAccessibleChildCount()
646 : throw (uno::RuntimeException)
647 : {
648 0 : return 0;
649 : }
650 :
651 0 : uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleChild( sal_Int32 )
652 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
653 : {
654 0 : throw lang::IndexOutOfBoundsException();
655 : }
656 :
657 0 : uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleParent()
658 : throw (uno::RuntimeException)
659 : {
660 0 : const SolarMutexGuard aSolarGuard;
661 0 : uno::Reference< accessibility::XAccessible > xRet;
662 :
663 0 : if( mpParent )
664 0 : xRet = mpParent->mrParent.GetAccessible();
665 :
666 0 : return xRet;
667 : }
668 :
669 0 : sal_Int32 SAL_CALL ThumbnailViewItemAcc::getAccessibleIndexInParent()
670 : throw (uno::RuntimeException)
671 : {
672 0 : const SolarMutexGuard aSolarGuard;
673 : // The index defaults to -1 to indicate the child does not belong to its
674 : // parent.
675 0 : sal_Int32 nIndexInParent = -1;
676 :
677 0 : if( mpParent )
678 : {
679 0 : bool bDone = false;
680 :
681 0 : sal_uInt16 nCount = mpParent->mrParent.ImplGetVisibleItemCount();
682 : ThumbnailViewItem* pItem;
683 0 : for (sal_uInt16 i=0; i<nCount && !bDone; i++)
684 : {
685 : // Guard the retrieval of the i-th child with a try/catch block
686 : // just in case the number of children changes in the mean time.
687 : try
688 : {
689 0 : pItem = mpParent->mrParent.ImplGetVisibleItem (i);
690 : }
691 0 : catch (const lang::IndexOutOfBoundsException&)
692 : {
693 0 : pItem = NULL;
694 : }
695 :
696 : // Do not create an accessible object for the test.
697 0 : if (pItem != NULL && pItem->mpxAcc != NULL)
698 0 : if (pItem->GetAccessible( mbIsTransientChildrenDisabled ).get() == this )
699 : {
700 0 : nIndexInParent = i;
701 0 : bDone = true;
702 : }
703 : }
704 : }
705 :
706 0 : return nIndexInParent;
707 : }
708 :
709 0 : sal_Int16 SAL_CALL ThumbnailViewItemAcc::getAccessibleRole()
710 : throw (uno::RuntimeException)
711 : {
712 0 : return accessibility::AccessibleRole::LIST_ITEM;
713 : }
714 :
715 0 : OUString SAL_CALL ThumbnailViewItemAcc::getAccessibleDescription()
716 : throw (uno::RuntimeException)
717 : {
718 0 : return OUString();
719 : }
720 :
721 0 : OUString SAL_CALL ThumbnailViewItemAcc::getAccessibleName()
722 : throw (uno::RuntimeException)
723 : {
724 0 : const SolarMutexGuard aSolarGuard;
725 0 : OUString aRet;
726 :
727 0 : if( mpParent )
728 : {
729 0 : aRet = mpParent->maTitle;
730 :
731 0 : if( aRet.isEmpty() )
732 : {
733 0 : OUStringBuffer aBuffer("Item ");
734 0 : aBuffer.append(static_cast<sal_Int32>(mpParent->mnId));
735 0 : aRet = aBuffer.makeStringAndClear();
736 : }
737 : }
738 :
739 0 : return aRet;
740 : }
741 :
742 0 : uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewItemAcc::getAccessibleRelationSet()
743 : throw (uno::RuntimeException)
744 : {
745 0 : return uno::Reference< accessibility::XAccessibleRelationSet >();
746 : }
747 :
748 0 : uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ThumbnailViewItemAcc::getAccessibleStateSet()
749 : throw (uno::RuntimeException)
750 : {
751 0 : const SolarMutexGuard aSolarGuard;
752 0 : ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
753 :
754 0 : if( mpParent )
755 : {
756 0 : pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
757 0 : pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
758 0 : pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
759 0 : pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
760 0 : if ( !mbIsTransientChildrenDisabled )
761 0 : pStateSet->AddState (accessibility::AccessibleStateType::TRANSIENT);
762 :
763 : // SELECTABLE
764 0 : pStateSet->AddState( accessibility::AccessibleStateType::SELECTABLE );
765 : // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
766 :
767 : // SELECTED
768 0 : if( mpParent->isSelected() )
769 : {
770 0 : pStateSet->AddState( accessibility::AccessibleStateType::SELECTED );
771 : // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
772 : }
773 : }
774 :
775 0 : return pStateSet;
776 : }
777 :
778 0 : lang::Locale SAL_CALL ThumbnailViewItemAcc::getLocale()
779 : throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException)
780 : {
781 0 : const SolarMutexGuard aSolarGuard;
782 0 : const OUString aEmptyStr;
783 0 : uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
784 0 : lang::Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
785 :
786 0 : if( xParent.is() )
787 : {
788 0 : uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
789 :
790 0 : if( xParentContext.is() )
791 0 : aRet = xParentContext->getLocale();
792 : }
793 :
794 0 : return aRet;
795 : }
796 :
797 0 : void SAL_CALL ThumbnailViewItemAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
798 : throw (uno::RuntimeException)
799 : {
800 0 : const ::osl::MutexGuard aGuard( maMutex );
801 :
802 0 : if( rxListener.is() )
803 : {
804 0 : ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter = mxEventListeners.begin();
805 0 : sal_Bool bFound = sal_False;
806 :
807 0 : while( !bFound && ( aIter != mxEventListeners.end() ) )
808 : {
809 0 : if( *aIter == rxListener )
810 0 : bFound = sal_True;
811 : else
812 0 : ++aIter;
813 : }
814 :
815 0 : if (!bFound)
816 0 : mxEventListeners.push_back( rxListener );
817 0 : }
818 0 : }
819 :
820 0 : void SAL_CALL ThumbnailViewItemAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
821 : throw (uno::RuntimeException)
822 : {
823 0 : const ::osl::MutexGuard aGuard( maMutex );
824 :
825 0 : if( rxListener.is() )
826 : {
827 0 : ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter = mxEventListeners.begin();
828 0 : sal_Bool bFound = sal_False;
829 :
830 0 : while( !bFound && ( aIter != mxEventListeners.end() ) )
831 : {
832 0 : if( *aIter == rxListener )
833 : {
834 0 : mxEventListeners.erase( aIter );
835 0 : bFound = sal_True;
836 : }
837 : else
838 0 : ++aIter;
839 : }
840 0 : }
841 0 : }
842 :
843 0 : sal_Bool SAL_CALL ThumbnailViewItemAcc::containsPoint( const awt::Point& aPoint )
844 : throw (uno::RuntimeException)
845 : {
846 0 : const awt::Rectangle aRect( getBounds() );
847 0 : const Point aSize( aRect.Width, aRect.Height );
848 0 : const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
849 :
850 0 : return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
851 : }
852 :
853 0 : uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleAtPoint( const awt::Point& )
854 : throw (uno::RuntimeException)
855 : {
856 0 : uno::Reference< accessibility::XAccessible > xRet;
857 0 : return xRet;
858 : }
859 :
860 0 : awt::Rectangle SAL_CALL ThumbnailViewItemAcc::getBounds()
861 : throw (uno::RuntimeException)
862 : {
863 0 : const SolarMutexGuard aSolarGuard;
864 0 : awt::Rectangle aRet;
865 :
866 0 : if( mpParent )
867 : {
868 0 : Rectangle aRect( mpParent->getDrawArea() );
869 0 : Point aOrigin;
870 0 : Rectangle aParentRect( aOrigin, mpParent->mrParent.GetOutputSizePixel() );
871 :
872 0 : aRect.Intersection( aParentRect );
873 :
874 0 : aRet.X = aRect.Left();
875 0 : aRet.Y = aRect.Top();
876 0 : aRet.Width = aRect.GetWidth();
877 0 : aRet.Height = aRect.GetHeight();
878 : }
879 :
880 0 : return aRet;
881 : }
882 :
883 0 : awt::Point SAL_CALL ThumbnailViewItemAcc::getLocation()
884 : throw (uno::RuntimeException)
885 : {
886 0 : const awt::Rectangle aRect( getBounds() );
887 0 : awt::Point aRet;
888 :
889 0 : aRet.X = aRect.X;
890 0 : aRet.Y = aRect.Y;
891 :
892 0 : return aRet;
893 : }
894 :
895 0 : awt::Point SAL_CALL ThumbnailViewItemAcc::getLocationOnScreen()
896 : throw (uno::RuntimeException)
897 : {
898 0 : const SolarMutexGuard aSolarGuard;
899 0 : awt::Point aRet;
900 :
901 0 : if( mpParent )
902 : {
903 0 : const Point aPos = mpParent->getDrawArea().TopLeft();
904 0 : const Point aScreenPos( mpParent->mrParent.OutputToAbsoluteScreenPixel( aPos ) );
905 :
906 0 : aRet.X = aScreenPos.X();
907 0 : aRet.Y = aScreenPos.Y();
908 : }
909 :
910 0 : return aRet;
911 : }
912 :
913 0 : awt::Size SAL_CALL ThumbnailViewItemAcc::getSize()
914 : throw (uno::RuntimeException)
915 : {
916 0 : const awt::Rectangle aRect( getBounds() );
917 0 : awt::Size aRet;
918 :
919 0 : aRet.Width = aRect.Width;
920 0 : aRet.Height = aRect.Height;
921 :
922 0 : return aRet;
923 : }
924 :
925 0 : void SAL_CALL ThumbnailViewItemAcc::grabFocus()
926 : throw (uno::RuntimeException)
927 : {
928 : // nothing to do
929 0 : }
930 :
931 0 : uno::Any SAL_CALL ThumbnailViewItemAcc::getAccessibleKeyBinding()
932 : throw (uno::RuntimeException)
933 : {
934 0 : return uno::Any();
935 : }
936 :
937 0 : sal_Int32 SAL_CALL ThumbnailViewItemAcc::getForeground( )
938 : throw (uno::RuntimeException)
939 : {
940 0 : sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
941 0 : return static_cast<sal_Int32>(nColor);
942 : }
943 :
944 0 : sal_Int32 SAL_CALL ThumbnailViewItemAcc::getBackground( )
945 : throw (uno::RuntimeException)
946 : {
947 0 : return static_cast<sal_Int32>(Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor());
948 : }
949 :
950 0 : sal_Int64 SAL_CALL ThumbnailViewItemAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException )
951 : {
952 : sal_Int64 nRet;
953 :
954 0 : if( ( rId.getLength() == 16 ) && ( 0 == memcmp( ThumbnailViewItemAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
955 0 : nRet = reinterpret_cast< sal_Int64 >( this );
956 : else
957 0 : nRet = 0;
958 :
959 0 : return nRet;
960 408 : }
961 :
962 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|