bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / control / thumbnailviewacc.cxx
blob598e3034b4e213931374cbe31bf9b3a4d20917d4
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 .
20 #include "thumbnailviewacc.hxx"
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 #include <vcl/settings.hxx>
29 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
30 #include <com/sun/star/accessibility/AccessibleRole.hpp>
31 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
33 using namespace ::com::sun::star;
35 ThumbnailViewAcc::ThumbnailViewAcc( ThumbnailView* pParent, bool bIsTransientChildrenDisabled ) :
36 ValueSetAccComponentBase (m_aMutex),
37 mpParent( pParent ),
38 mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled ),
39 mbIsFocused(false)
43 ThumbnailViewAcc::~ThumbnailViewAcc()
47 void ThumbnailViewAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
49 if( nEventId )
51 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners );
52 accessibility::AccessibleEventObject aEvtObject;
54 aEvtObject.EventId = nEventId;
55 aEvtObject.Source = static_cast<uno::XWeak*>(this);
56 aEvtObject.NewValue = rNewValue;
57 aEvtObject.OldValue = rOldValue;
59 for (::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter( aTmpListeners.begin() ), aEnd( aTmpListeners.end() );
60 aIter != aEnd ; ++aIter)
62 try
64 (*aIter)->notifyEvent( aEvtObject );
66 catch(const uno::Exception&)
73 namespace
75 class theValueSetAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueSetAccUnoTunnelId > {};
78 const uno::Sequence< sal_Int8 >& ThumbnailViewAcc::getUnoTunnelId()
80 return theValueSetAccUnoTunnelId::get().getSeq();
83 ThumbnailViewAcc* ThumbnailViewAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
84 throw()
86 try
88 uno::Reference< lang::XUnoTunnel > xUnoTunnel( rxData, uno::UNO_QUERY );
89 return( xUnoTunnel.is() ? reinterpret_cast<ThumbnailViewAcc*>(sal::static_int_cast<sal_IntPtr>(xUnoTunnel->getSomething( ThumbnailViewAcc::getUnoTunnelId() ))) : NULL );
91 catch(const ::com::sun::star::uno::Exception&)
93 return NULL;
97 void ThumbnailViewAcc::GetFocus()
99 mbIsFocused = true;
101 // Broadcast the state change.
102 ::com::sun::star::uno::Any aOldState, aNewState;
103 aNewState <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
104 FireAccessibleEvent(
105 ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED,
106 aOldState, aNewState);
109 void ThumbnailViewAcc::LoseFocus()
111 mbIsFocused = false;
113 // Broadcast the state change.
114 ::com::sun::star::uno::Any aOldState, aNewState;
115 aOldState <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
116 FireAccessibleEvent(
117 ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED,
118 aOldState, aNewState);
121 uno::Reference< accessibility::XAccessibleContext > SAL_CALL ThumbnailViewAcc::getAccessibleContext()
122 throw (uno::RuntimeException, std::exception)
124 ThrowIfDisposed();
125 return this;
128 sal_Int32 SAL_CALL ThumbnailViewAcc::getAccessibleChildCount()
129 throw (uno::RuntimeException, std::exception)
131 const SolarMutexGuard aSolarGuard;
132 ThrowIfDisposed();
134 sal_Int32 nCount = mpParent->ImplGetVisibleItemCount();
135 return nCount;
138 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleChild( sal_Int32 i )
139 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
141 ThrowIfDisposed();
142 const SolarMutexGuard aSolarGuard;
143 uno::Reference< accessibility::XAccessible > xRet;
144 ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(i));
146 if( pItem )
147 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
148 else
149 throw lang::IndexOutOfBoundsException();
151 return xRet;
154 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleParent()
155 throw (uno::RuntimeException, std::exception)
157 ThrowIfDisposed();
158 const SolarMutexGuard aSolarGuard;
159 vcl::Window* pParent = mpParent->GetParent();
160 uno::Reference< accessibility::XAccessible > xRet;
162 if( pParent )
163 xRet = pParent->GetAccessible();
165 return xRet;
168 sal_Int32 SAL_CALL ThumbnailViewAcc::getAccessibleIndexInParent()
169 throw (uno::RuntimeException, std::exception)
171 ThrowIfDisposed();
172 const SolarMutexGuard aSolarGuard;
173 vcl::Window* pParent = mpParent->GetParent();
174 sal_Int32 nRet = 0;
176 if( pParent )
178 bool bFound = false;
180 for( sal_uInt16 i = 0, nCount = pParent->GetChildCount(); ( i < nCount ) && !bFound; i++ )
182 if( pParent->GetChild( i ) == mpParent )
184 nRet = i;
185 bFound = true;
190 return nRet;
193 sal_Int16 SAL_CALL ThumbnailViewAcc::getAccessibleRole()
194 throw (uno::RuntimeException, std::exception)
196 ThrowIfDisposed();
197 // #i73746# As the Java Access Bridge (v 2.0.1) uses "managesDescendants"
198 // always if the role is LIST, we need a different role in this case
199 return (mbIsTransientChildrenDisabled
200 ? accessibility::AccessibleRole::PANEL
201 : accessibility::AccessibleRole::LIST );
204 OUString SAL_CALL ThumbnailViewAcc::getAccessibleDescription()
205 throw (uno::RuntimeException, std::exception)
207 ThrowIfDisposed();
208 const SolarMutexGuard aSolarGuard;
209 return OUString("ThumbnailView");
212 OUString SAL_CALL ThumbnailViewAcc::getAccessibleName()
213 throw (uno::RuntimeException, std::exception)
215 ThrowIfDisposed();
216 const SolarMutexGuard aSolarGuard;
217 OUString aRet;
219 if ( mpParent )
221 aRet = mpParent->GetAccessibleName();
222 if (aRet.isEmpty())
224 vcl::Window* pLabel = mpParent->GetAccessibleRelationLabeledBy();
225 if (pLabel && pLabel != mpParent)
226 aRet = OutputDevice::GetNonMnemonicString( pLabel->GetText() );
230 return aRet;
233 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewAcc::getAccessibleRelationSet()
234 throw (uno::RuntimeException, std::exception)
236 ThrowIfDisposed();
237 return uno::Reference< accessibility::XAccessibleRelationSet >();
240 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ThumbnailViewAcc::getAccessibleStateSet()
241 throw (uno::RuntimeException, std::exception)
243 ThrowIfDisposed();
244 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
246 // Set some states.
247 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
248 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
249 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
250 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
251 if ( !mbIsTransientChildrenDisabled )
252 pStateSet->AddState (accessibility::AccessibleStateType::MANAGES_DESCENDANTS);
253 pStateSet->AddState (accessibility::AccessibleStateType::FOCUSABLE);
254 if (mbIsFocused)
255 pStateSet->AddState (accessibility::AccessibleStateType::FOCUSED);
257 return pStateSet;
260 lang::Locale SAL_CALL ThumbnailViewAcc::getLocale()
261 throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException, std::exception)
263 ThrowIfDisposed();
264 const SolarMutexGuard aSolarGuard;
265 const OUString aEmptyStr;
266 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
267 lang::Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
269 if( xParent.is() )
271 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
273 if( xParentContext.is() )
274 aRet = xParentContext->getLocale ();
277 return aRet;
280 void SAL_CALL ThumbnailViewAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
281 throw (uno::RuntimeException, std::exception)
283 ThrowIfDisposed();
284 ::osl::MutexGuard aGuard (m_aMutex);
286 if( rxListener.is() )
288 std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter = mxEventListeners.begin();
289 bool bFound = false;
291 while( !bFound && ( aIter != mxEventListeners.end() ) )
293 if( *aIter == rxListener )
294 bFound = true;
295 else
296 ++aIter;
299 if (!bFound)
300 mxEventListeners.push_back( rxListener );
304 void SAL_CALL ThumbnailViewAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
305 throw (uno::RuntimeException, std::exception)
307 ThrowIfDisposed();
308 ::osl::MutexGuard aGuard (m_aMutex);
310 if( rxListener.is() )
312 std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter =
313 std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener);
315 if (aIter != mxEventListeners.end())
316 mxEventListeners.erase( aIter );
320 sal_Bool SAL_CALL ThumbnailViewAcc::containsPoint( const awt::Point& aPoint )
321 throw (uno::RuntimeException, std::exception)
323 ThrowIfDisposed();
324 const awt::Rectangle aRect( getBounds() );
325 const Point aSize( aRect.Width, aRect.Height );
326 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
328 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
331 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleAtPoint( const awt::Point& aPoint )
332 throw (uno::RuntimeException, std::exception)
334 ThrowIfDisposed();
335 const SolarMutexGuard aSolarGuard;
336 const sal_uInt16 nItemId = mpParent->GetItemId( Point( aPoint.X, aPoint.Y ) );
337 uno::Reference< accessibility::XAccessible > xRet;
339 if ( nItemId )
341 const size_t nItemPos = mpParent->GetItemPos( nItemId );
343 if( THUMBNAILVIEW_ITEM_NONEITEM != nItemPos )
345 ThumbnailViewItem *const pItem = mpParent->mFilteredItemList[nItemPos];
346 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
350 return xRet;
353 awt::Rectangle SAL_CALL ThumbnailViewAcc::getBounds()
354 throw (uno::RuntimeException, std::exception)
356 ThrowIfDisposed();
357 const SolarMutexGuard aSolarGuard;
358 const Point aOutPos( mpParent->GetPosPixel() );
359 const Size aOutSize( mpParent->GetOutputSizePixel() );
360 awt::Rectangle aRet;
362 aRet.X = aOutPos.X();
363 aRet.Y = aOutPos.Y();
364 aRet.Width = aOutSize.Width();
365 aRet.Height = aOutSize.Height();
367 return aRet;
370 awt::Point SAL_CALL ThumbnailViewAcc::getLocation()
371 throw (uno::RuntimeException, std::exception)
373 ThrowIfDisposed();
374 const awt::Rectangle aRect( getBounds() );
375 awt::Point aRet;
377 aRet.X = aRect.X;
378 aRet.Y = aRect.Y;
380 return aRet;
383 awt::Point SAL_CALL ThumbnailViewAcc::getLocationOnScreen()
384 throw (uno::RuntimeException, std::exception)
386 ThrowIfDisposed();
387 const SolarMutexGuard aSolarGuard;
388 const Point aScreenPos( mpParent->OutputToAbsoluteScreenPixel( Point() ) );
389 awt::Point aRet;
391 aRet.X = aScreenPos.X();
392 aRet.Y = aScreenPos.Y();
394 return aRet;
397 awt::Size SAL_CALL ThumbnailViewAcc::getSize()
398 throw (uno::RuntimeException, std::exception)
400 ThrowIfDisposed();
401 const awt::Rectangle aRect( getBounds() );
402 awt::Size aRet;
404 aRet.Width = aRect.Width;
405 aRet.Height = aRect.Height;
407 return aRet;
410 void SAL_CALL ThumbnailViewAcc::grabFocus()
411 throw (uno::RuntimeException, std::exception)
413 ThrowIfDisposed();
414 const SolarMutexGuard aSolarGuard;
415 mpParent->GrabFocus();
418 sal_Int32 SAL_CALL ThumbnailViewAcc::getForeground( )
419 throw (uno::RuntimeException, std::exception)
421 ThrowIfDisposed();
422 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
423 return static_cast<sal_Int32>(nColor);
426 sal_Int32 SAL_CALL ThumbnailViewAcc::getBackground( )
427 throw (uno::RuntimeException, std::exception)
429 ThrowIfDisposed();
430 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
431 return static_cast<sal_Int32>(nColor);
434 void SAL_CALL ThumbnailViewAcc::selectAccessibleChild( sal_Int32 nChildIndex )
435 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
437 ThrowIfDisposed();
438 const SolarMutexGuard aSolarGuard;
439 ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
441 if(pItem != NULL)
443 mpParent->SelectItem( pItem->mnId );
445 else
446 throw lang::IndexOutOfBoundsException();
449 sal_Bool SAL_CALL ThumbnailViewAcc::isAccessibleChildSelected( sal_Int32 nChildIndex )
450 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
452 ThrowIfDisposed();
453 const SolarMutexGuard aSolarGuard;
454 ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
455 bool bRet = false;
457 if (pItem != NULL)
458 bRet = mpParent->IsItemSelected( pItem->mnId );
459 else
460 throw lang::IndexOutOfBoundsException();
462 return bRet;
465 void SAL_CALL ThumbnailViewAcc::clearAccessibleSelection()
466 throw (uno::RuntimeException, std::exception)
468 ThrowIfDisposed();
469 const SolarMutexGuard aSolarGuard;
472 void SAL_CALL ThumbnailViewAcc::selectAllAccessibleChildren()
473 throw (uno::RuntimeException, std::exception)
475 ThrowIfDisposed();
476 // unsupported due to single selection only
479 sal_Int32 SAL_CALL ThumbnailViewAcc::getSelectedAccessibleChildCount()
480 throw (uno::RuntimeException, std::exception)
482 ThrowIfDisposed();
483 const SolarMutexGuard aSolarGuard;
484 sal_Int32 nRet = 0;
486 for( sal_uInt16 i = 0, nCount = getItemCount(); i < nCount; i++ )
488 ThumbnailViewItem* pItem = getItem (i);
490 if( pItem && mpParent->IsItemSelected( pItem->mnId ) )
491 ++nRet;
494 return nRet;
497 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
498 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
500 ThrowIfDisposed();
501 const SolarMutexGuard aSolarGuard;
502 uno::Reference< accessibility::XAccessible > xRet;
504 for( sal_uInt16 i = 0, nCount = getItemCount(), nSel = 0; ( i < nCount ) && !xRet.is(); i++ )
506 ThumbnailViewItem* pItem = getItem(i);
508 if( pItem && mpParent->IsItemSelected( pItem->mnId ) && ( nSelectedChildIndex == static_cast< sal_Int32 >( nSel++ ) ) )
509 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
512 return xRet;
515 void SAL_CALL ThumbnailViewAcc::deselectAccessibleChild( sal_Int32 nChildIndex )
516 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
518 ThrowIfDisposed();
519 const SolarMutexGuard aSolarGuard;
520 // Because of the single selection we can reset the whole selection when
521 // the specified child is currently selected.
522 //FIXME TODO if (isAccessibleChildSelected(nChildIndex))
523 //FIXME TODO ;
524 (void) nChildIndex;
527 sal_Int64 SAL_CALL ThumbnailViewAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException, std::exception )
529 sal_Int64 nRet;
531 if( ( rId.getLength() == 16 ) && ( 0 == memcmp( ThumbnailViewAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
532 nRet = reinterpret_cast< sal_Int64 >( this );
533 else
534 nRet = 0;
536 return nRet;
539 void SAL_CALL ThumbnailViewAcc::disposing()
541 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> > aListenerListCopy;
544 // Make a copy of the list and clear the original.
545 const SolarMutexGuard aSolarGuard;
546 ::osl::MutexGuard aGuard (m_aMutex);
547 aListenerListCopy = mxEventListeners;
548 mxEventListeners.clear();
550 // Reset the pointer to the parent. It has to be the one who has
551 // disposed us because he is dying.
552 mpParent = NULL;
555 // Inform all listeners that this objects is disposing.
556 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> >::const_iterator
557 aListenerIterator (aListenerListCopy.begin());
558 lang::EventObject aEvent (static_cast<accessibility::XAccessible*>(this));
559 while (aListenerIterator != aListenerListCopy.end())
563 (*aListenerIterator)->disposing (aEvent);
565 catch(const uno::Exception&)
567 // Ignore exceptions.
570 ++aListenerIterator;
574 sal_uInt16 ThumbnailViewAcc::getItemCount() const
576 return mpParent->ImplGetVisibleItemCount();
579 ThumbnailViewItem* ThumbnailViewAcc::getItem (sal_uInt16 nIndex) const
581 return mpParent->ImplGetVisibleItem (static_cast<sal_uInt16>(nIndex));
584 void ThumbnailViewAcc::ThrowIfDisposed()
585 throw (::com::sun::star::lang::DisposedException)
587 if (rBHelper.bDisposed || rBHelper.bInDispose)
589 OSL_TRACE ("Calling disposed object. Throwing exception:");
590 throw lang::DisposedException (
591 OUString("object has been already disposed"),
592 static_cast<uno::XWeak*>(this));
594 else
596 DBG_ASSERT (mpParent!=nullptr, "ValueSetAcc not disposed but mpParent == NULL");
600 ThumbnailViewItemAcc::ThumbnailViewItemAcc( ThumbnailViewItem* pParent, bool bIsTransientChildrenDisabled ) :
601 mpParent( pParent ),
602 mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled )
606 ThumbnailViewItemAcc::~ThumbnailViewItemAcc()
610 void ThumbnailViewItemAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
612 if( nEventId )
614 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners );
615 accessibility::AccessibleEventObject aEvtObject;
617 aEvtObject.EventId = nEventId;
618 aEvtObject.Source = static_cast<uno::XWeak*>(this);
619 aEvtObject.NewValue = rNewValue;
620 aEvtObject.OldValue = rOldValue;
622 for (::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter( aTmpListeners.begin() ), aEnd( aTmpListeners.end() );
623 aIter != aEnd ; ++aIter)
627 (*aIter)->notifyEvent( aEvtObject );
629 catch(const uno::Exception&)
636 void ThumbnailViewItemAcc::ParentDestroyed()
638 const ::osl::MutexGuard aGuard( maMutex );
639 mpParent = NULL;
642 namespace
644 class theValueItemAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueItemAccUnoTunnelId > {};
647 const uno::Sequence< sal_Int8 >& ThumbnailViewItemAcc::getUnoTunnelId()
649 return theValueItemAccUnoTunnelId::get().getSeq();
652 ThumbnailViewItemAcc* ThumbnailViewItemAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
653 throw()
657 uno::Reference< lang::XUnoTunnel > xUnoTunnel( rxData, uno::UNO_QUERY );
658 return( xUnoTunnel.is() ?
659 reinterpret_cast<ThumbnailViewItemAcc*>(sal::static_int_cast<sal_IntPtr>(
660 xUnoTunnel->getSomething( ThumbnailViewItemAcc::getUnoTunnelId() ))) :
661 NULL );
663 catch(const ::com::sun::star::uno::Exception&)
665 return NULL;
669 uno::Reference< accessibility::XAccessibleContext > SAL_CALL ThumbnailViewItemAcc::getAccessibleContext()
670 throw (uno::RuntimeException, std::exception)
672 return this;
675 sal_Int32 SAL_CALL ThumbnailViewItemAcc::getAccessibleChildCount()
676 throw (uno::RuntimeException, std::exception)
678 return 0;
681 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleChild( sal_Int32 )
682 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
684 throw lang::IndexOutOfBoundsException();
687 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleParent()
688 throw (uno::RuntimeException, std::exception)
690 const SolarMutexGuard aSolarGuard;
691 uno::Reference< accessibility::XAccessible > xRet;
693 if( mpParent )
694 xRet = mpParent->mrParent.GetAccessible();
696 return xRet;
699 sal_Int32 SAL_CALL ThumbnailViewItemAcc::getAccessibleIndexInParent()
700 throw (uno::RuntimeException, std::exception)
702 const SolarMutexGuard aSolarGuard;
703 // The index defaults to -1 to indicate the child does not belong to its
704 // parent.
705 sal_Int32 nIndexInParent = -1;
707 if( mpParent )
709 bool bDone = false;
711 sal_uInt16 nCount = mpParent->mrParent.ImplGetVisibleItemCount();
712 ThumbnailViewItem* pItem;
713 for (sal_uInt16 i=0; i<nCount && !bDone; i++)
715 // Guard the retrieval of the i-th child with a try/catch block
716 // just in case the number of children changes in the mean time.
719 pItem = mpParent->mrParent.ImplGetVisibleItem (i);
721 catch (const lang::IndexOutOfBoundsException&)
723 pItem = NULL;
726 // Do not create an accessible object for the test.
727 if (pItem != NULL && pItem->mpxAcc != NULL)
728 if (pItem->GetAccessible( mbIsTransientChildrenDisabled ).get() == this )
730 nIndexInParent = i;
731 bDone = true;
736 return nIndexInParent;
739 sal_Int16 SAL_CALL ThumbnailViewItemAcc::getAccessibleRole()
740 throw (uno::RuntimeException, std::exception)
742 return accessibility::AccessibleRole::LIST_ITEM;
745 OUString SAL_CALL ThumbnailViewItemAcc::getAccessibleDescription()
746 throw (uno::RuntimeException, std::exception)
748 return OUString();
751 OUString SAL_CALL ThumbnailViewItemAcc::getAccessibleName()
752 throw (uno::RuntimeException, std::exception)
754 const SolarMutexGuard aSolarGuard;
755 OUString aRet;
757 if( mpParent )
759 aRet = mpParent->maTitle;
761 if( aRet.isEmpty() )
763 OUStringBuffer aBuffer("Item ");
764 aBuffer.append(static_cast<sal_Int32>(mpParent->mnId));
765 aRet = aBuffer.makeStringAndClear();
769 return aRet;
772 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewItemAcc::getAccessibleRelationSet()
773 throw (uno::RuntimeException, std::exception)
775 return uno::Reference< accessibility::XAccessibleRelationSet >();
778 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ThumbnailViewItemAcc::getAccessibleStateSet()
779 throw (uno::RuntimeException, std::exception)
781 const SolarMutexGuard aSolarGuard;
782 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
784 if( mpParent )
786 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
787 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
788 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
789 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
790 if ( !mbIsTransientChildrenDisabled )
791 pStateSet->AddState (accessibility::AccessibleStateType::TRANSIENT);
793 // SELECTABLE
794 pStateSet->AddState( accessibility::AccessibleStateType::SELECTABLE );
795 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
797 // SELECTED
798 if( mpParent->isSelected() )
800 pStateSet->AddState( accessibility::AccessibleStateType::SELECTED );
801 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
805 return pStateSet;
808 lang::Locale SAL_CALL ThumbnailViewItemAcc::getLocale()
809 throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException, std::exception)
811 const SolarMutexGuard aSolarGuard;
812 const OUString aEmptyStr;
813 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
814 lang::Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
816 if( xParent.is() )
818 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
820 if( xParentContext.is() )
821 aRet = xParentContext->getLocale();
824 return aRet;
827 void SAL_CALL ThumbnailViewItemAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
828 throw (uno::RuntimeException, std::exception)
830 const ::osl::MutexGuard aGuard( maMutex );
832 if( rxListener.is() )
834 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter = mxEventListeners.begin();
835 bool bFound = false;
837 while( !bFound && ( aIter != mxEventListeners.end() ) )
839 if( *aIter == rxListener )
840 bFound = true;
841 else
842 ++aIter;
845 if (!bFound)
846 mxEventListeners.push_back( rxListener );
850 void SAL_CALL ThumbnailViewItemAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
851 throw (uno::RuntimeException, std::exception)
853 const ::osl::MutexGuard aGuard( maMutex );
855 if( rxListener.is() )
857 std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter =
858 std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener);
860 if (aIter != mxEventListeners.end())
861 mxEventListeners.erase( aIter );
865 sal_Bool SAL_CALL ThumbnailViewItemAcc::containsPoint( const awt::Point& aPoint )
866 throw (uno::RuntimeException, std::exception)
868 const awt::Rectangle aRect( getBounds() );
869 const Point aSize( aRect.Width, aRect.Height );
870 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
872 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
875 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleAtPoint( const awt::Point& )
876 throw (uno::RuntimeException, std::exception)
878 uno::Reference< accessibility::XAccessible > xRet;
879 return xRet;
882 awt::Rectangle SAL_CALL ThumbnailViewItemAcc::getBounds()
883 throw (uno::RuntimeException, std::exception)
885 const SolarMutexGuard aSolarGuard;
886 awt::Rectangle aRet;
888 if( mpParent )
890 Rectangle aRect( mpParent->getDrawArea() );
891 Point aOrigin;
892 Rectangle aParentRect( aOrigin, mpParent->mrParent.GetOutputSizePixel() );
894 aRect.Intersection( aParentRect );
896 aRet.X = aRect.Left();
897 aRet.Y = aRect.Top();
898 aRet.Width = aRect.GetWidth();
899 aRet.Height = aRect.GetHeight();
902 return aRet;
905 awt::Point SAL_CALL ThumbnailViewItemAcc::getLocation()
906 throw (uno::RuntimeException, std::exception)
908 const awt::Rectangle aRect( getBounds() );
909 awt::Point aRet;
911 aRet.X = aRect.X;
912 aRet.Y = aRect.Y;
914 return aRet;
917 awt::Point SAL_CALL ThumbnailViewItemAcc::getLocationOnScreen()
918 throw (uno::RuntimeException, std::exception)
920 const SolarMutexGuard aSolarGuard;
921 awt::Point aRet;
923 if( mpParent )
925 const Point aPos = mpParent->getDrawArea().TopLeft();
926 const Point aScreenPos( mpParent->mrParent.OutputToAbsoluteScreenPixel( aPos ) );
928 aRet.X = aScreenPos.X();
929 aRet.Y = aScreenPos.Y();
932 return aRet;
935 awt::Size SAL_CALL ThumbnailViewItemAcc::getSize()
936 throw (uno::RuntimeException, std::exception)
938 const awt::Rectangle aRect( getBounds() );
939 awt::Size aRet;
941 aRet.Width = aRect.Width;
942 aRet.Height = aRect.Height;
944 return aRet;
947 void SAL_CALL ThumbnailViewItemAcc::grabFocus()
948 throw (uno::RuntimeException, std::exception)
950 // nothing to do
953 sal_Int32 SAL_CALL ThumbnailViewItemAcc::getForeground( )
954 throw (uno::RuntimeException, std::exception)
956 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
957 return static_cast<sal_Int32>(nColor);
960 sal_Int32 SAL_CALL ThumbnailViewItemAcc::getBackground( )
961 throw (uno::RuntimeException, std::exception)
963 return static_cast<sal_Int32>(Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor());
966 sal_Int64 SAL_CALL ThumbnailViewItemAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException, std::exception )
968 sal_Int64 nRet;
970 if( ( rId.getLength() == 16 ) && ( 0 == memcmp( ThumbnailViewItemAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
971 nRet = reinterpret_cast< sal_Int64 >( this );
972 else
973 nRet = 0;
975 return nRet;
978 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */