Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sfx2 / source / control / thumbnailviewacc.cxx
blobccebccacbf814966942f046118647945fc97705e
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>
28 #include <sal/log.hxx>
29 #include <tools/debug.hxx>
31 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
32 #include <com/sun/star/accessibility/AccessibleRole.hpp>
33 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
34 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
36 using namespace ::com::sun::star;
38 ThumbnailViewAcc::ThumbnailViewAcc( ThumbnailView* pParent ) :
39 ValueSetAccComponentBase (m_aMutex),
40 mpParent( pParent ),
41 mbIsFocused(false)
45 ThumbnailViewAcc::~ThumbnailViewAcc()
49 void ThumbnailViewAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
51 if( !nEventId )
52 return;
54 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners );
55 accessibility::AccessibleEventObject aEvtObject;
57 aEvtObject.EventId = nEventId;
58 aEvtObject.Source = static_cast<uno::XWeak*>(this);
59 aEvtObject.NewValue = rNewValue;
60 aEvtObject.OldValue = rOldValue;
62 for (auto const& tmpListener : aTmpListeners)
64 try
66 tmpListener->notifyEvent( aEvtObject );
68 catch(const uno::Exception&)
74 namespace
76 class theValueSetAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueSetAccUnoTunnelId > {};
79 const uno::Sequence< sal_Int8 >& ThumbnailViewAcc::getUnoTunnelId()
81 return theValueSetAccUnoTunnelId::get().getSeq();
84 ThumbnailViewAcc* ThumbnailViewAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
85 throw()
87 try
89 return comphelper::getUnoTunnelImplementation<ThumbnailViewAcc>(rxData);
91 catch(const css::uno::Exception&)
93 return nullptr;
97 void ThumbnailViewAcc::GetFocus()
99 mbIsFocused = true;
101 // Broadcast the state change.
102 css::uno::Any aOldState, aNewState;
103 aNewState <<= css::accessibility::AccessibleStateType::FOCUSED;
104 FireAccessibleEvent(
105 css::accessibility::AccessibleEventId::STATE_CHANGED,
106 aOldState, aNewState);
109 void ThumbnailViewAcc::LoseFocus()
111 mbIsFocused = false;
113 // Broadcast the state change.
114 css::uno::Any aOldState, aNewState;
115 aOldState <<= css::accessibility::AccessibleStateType::FOCUSED;
116 FireAccessibleEvent(
117 css::accessibility::AccessibleEventId::STATE_CHANGED,
118 aOldState, aNewState);
121 uno::Reference< accessibility::XAccessibleContext > SAL_CALL ThumbnailViewAcc::getAccessibleContext()
123 ThrowIfDisposed();
124 return this;
127 sal_Int32 SAL_CALL ThumbnailViewAcc::getAccessibleChildCount()
129 const SolarMutexGuard aSolarGuard;
130 ThrowIfDisposed();
132 sal_Int32 nCount = mpParent->ImplGetVisibleItemCount();
133 return nCount;
136 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleChild( sal_Int32 i )
138 ThrowIfDisposed();
139 const SolarMutexGuard aSolarGuard;
140 ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(i));
142 if( !pItem )
143 throw lang::IndexOutOfBoundsException();
145 uno::Reference< accessibility::XAccessible > xRet = pItem->GetAccessible( /*bIsTransientChildrenDisabled*/false );
146 return xRet;
149 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleParent()
151 ThrowIfDisposed();
152 const SolarMutexGuard aSolarGuard;
153 vcl::Window* pParent = mpParent->GetParent();
154 uno::Reference< accessibility::XAccessible > xRet;
156 if( pParent )
157 xRet = pParent->GetAccessible();
159 return xRet;
162 sal_Int32 SAL_CALL ThumbnailViewAcc::getAccessibleIndexInParent()
164 ThrowIfDisposed();
165 const SolarMutexGuard aSolarGuard;
166 vcl::Window* pParent = mpParent->GetParent();
167 sal_Int32 nRet = 0;
169 if( pParent )
171 bool bFound = false;
173 for( sal_uInt16 i = 0, nCount = pParent->GetChildCount(); ( i < nCount ) && !bFound; i++ )
175 if( pParent->GetChild( i ) == mpParent )
177 nRet = i;
178 bFound = true;
183 return nRet;
186 sal_Int16 SAL_CALL ThumbnailViewAcc::getAccessibleRole()
188 ThrowIfDisposed();
189 // #i73746# As the Java Access Bridge (v 2.0.1) uses "managesDescendants"
190 // always if the role is LIST, we need a different role in this case
191 return accessibility::AccessibleRole::LIST;
194 OUString SAL_CALL ThumbnailViewAcc::getAccessibleDescription()
196 ThrowIfDisposed();
197 return "ThumbnailView";
200 OUString SAL_CALL ThumbnailViewAcc::getAccessibleName()
202 ThrowIfDisposed();
203 const SolarMutexGuard aSolarGuard;
204 OUString aRet;
206 if ( mpParent )
208 aRet = mpParent->GetAccessibleName();
209 if (aRet.isEmpty())
211 vcl::Window* pLabel = mpParent->GetAccessibleRelationLabeledBy();
212 if (pLabel && pLabel != mpParent)
213 aRet = OutputDevice::GetNonMnemonicString( pLabel->GetText() );
217 return aRet;
220 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewAcc::getAccessibleRelationSet()
222 ThrowIfDisposed();
223 return uno::Reference< accessibility::XAccessibleRelationSet >();
226 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ThumbnailViewAcc::getAccessibleStateSet()
228 ThrowIfDisposed();
229 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
231 // Set some states.
232 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
233 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
234 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
235 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
236 pStateSet->AddState (accessibility::AccessibleStateType::MANAGES_DESCENDANTS);
237 pStateSet->AddState (accessibility::AccessibleStateType::FOCUSABLE);
238 if (mbIsFocused)
239 pStateSet->AddState (accessibility::AccessibleStateType::FOCUSED);
241 return pStateSet;
244 lang::Locale SAL_CALL ThumbnailViewAcc::getLocale()
246 ThrowIfDisposed();
247 const SolarMutexGuard aSolarGuard;
248 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
249 lang::Locale aRet( "", "", "" );
251 if( xParent.is() )
253 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
255 if( xParentContext.is() )
256 aRet = xParentContext->getLocale ();
259 return aRet;
262 void SAL_CALL ThumbnailViewAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
264 ThrowIfDisposed();
265 ::osl::MutexGuard aGuard (m_aMutex);
267 if( !rxListener.is() )
268 return;
270 bool bFound = false;
272 for (auto const& eventListener : mxEventListeners)
274 if( eventListener == rxListener )
276 bFound = true;
277 break;
281 if (!bFound)
282 mxEventListeners.push_back( rxListener );
285 void SAL_CALL ThumbnailViewAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
287 ThrowIfDisposed();
288 ::osl::MutexGuard aGuard (m_aMutex);
290 if( rxListener.is() )
292 std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter =
293 std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener);
295 if (aIter != mxEventListeners.end())
296 mxEventListeners.erase( aIter );
300 sal_Bool SAL_CALL ThumbnailViewAcc::containsPoint( const awt::Point& aPoint )
302 ThrowIfDisposed();
303 const awt::Rectangle aRect( getBounds() );
304 const Point aSize( aRect.Width, aRect.Height );
305 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
307 return tools::Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
310 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getAccessibleAtPoint( const awt::Point& aPoint )
312 ThrowIfDisposed();
313 const SolarMutexGuard aSolarGuard;
314 const sal_uInt16 nItemId = mpParent->GetItemId( Point( aPoint.X, aPoint.Y ) );
315 uno::Reference< accessibility::XAccessible > xRet;
317 if ( nItemId )
319 const size_t nItemPos = mpParent->GetItemPos( nItemId );
321 if( THUMBNAILVIEW_ITEM_NONEITEM != nItemPos )
323 ThumbnailViewItem *const pItem = mpParent->mFilteredItemList[nItemPos];
324 xRet = pItem->GetAccessible( /*bIsTransientChildrenDisabled*/false );
328 return xRet;
331 awt::Rectangle SAL_CALL ThumbnailViewAcc::getBounds()
333 ThrowIfDisposed();
334 const SolarMutexGuard aSolarGuard;
335 const Point aOutPos( mpParent->GetPosPixel() );
336 const Size aOutSize( mpParent->GetOutputSizePixel() );
337 awt::Rectangle aRet;
339 aRet.X = aOutPos.X();
340 aRet.Y = aOutPos.Y();
341 aRet.Width = aOutSize.Width();
342 aRet.Height = aOutSize.Height();
344 return aRet;
347 awt::Point SAL_CALL ThumbnailViewAcc::getLocation()
349 ThrowIfDisposed();
350 const awt::Rectangle aRect( getBounds() );
351 awt::Point aRet;
353 aRet.X = aRect.X;
354 aRet.Y = aRect.Y;
356 return aRet;
359 awt::Point SAL_CALL ThumbnailViewAcc::getLocationOnScreen()
361 ThrowIfDisposed();
362 const SolarMutexGuard aSolarGuard;
363 const Point aScreenPos( mpParent->OutputToAbsoluteScreenPixel( Point() ) );
364 awt::Point aRet;
366 aRet.X = aScreenPos.X();
367 aRet.Y = aScreenPos.Y();
369 return aRet;
372 awt::Size SAL_CALL ThumbnailViewAcc::getSize()
374 ThrowIfDisposed();
375 const awt::Rectangle aRect( getBounds() );
376 awt::Size aRet;
378 aRet.Width = aRect.Width;
379 aRet.Height = aRect.Height;
381 return aRet;
384 void SAL_CALL ThumbnailViewAcc::grabFocus()
386 ThrowIfDisposed();
387 const SolarMutexGuard aSolarGuard;
388 mpParent->GrabFocus();
391 sal_Int32 SAL_CALL ThumbnailViewAcc::getForeground( )
393 ThrowIfDisposed();
394 Color nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor();
395 return static_cast<sal_Int32>(nColor);
398 sal_Int32 SAL_CALL ThumbnailViewAcc::getBackground( )
400 ThrowIfDisposed();
401 Color nColor = Application::GetSettings().GetStyleSettings().GetWindowColor();
402 return static_cast<sal_Int32>(nColor);
405 void SAL_CALL ThumbnailViewAcc::selectAccessibleChild( sal_Int32 nChildIndex )
407 ThrowIfDisposed();
408 const SolarMutexGuard aSolarGuard;
409 ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
411 if(pItem == nullptr)
412 throw lang::IndexOutOfBoundsException();
414 mpParent->SelectItem( pItem->mnId );
417 sal_Bool SAL_CALL ThumbnailViewAcc::isAccessibleChildSelected( sal_Int32 nChildIndex )
419 ThrowIfDisposed();
420 const SolarMutexGuard aSolarGuard;
421 ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
423 if (pItem == nullptr)
424 throw lang::IndexOutOfBoundsException();
426 return mpParent->IsItemSelected( pItem->mnId );
429 void SAL_CALL ThumbnailViewAcc::clearAccessibleSelection()
431 ThrowIfDisposed();
434 void SAL_CALL ThumbnailViewAcc::selectAllAccessibleChildren()
436 ThrowIfDisposed();
437 // unsupported due to single selection only
440 sal_Int32 SAL_CALL ThumbnailViewAcc::getSelectedAccessibleChildCount()
442 ThrowIfDisposed();
443 const SolarMutexGuard aSolarGuard;
444 sal_Int32 nRet = 0;
446 for( sal_uInt16 i = 0, nCount = getItemCount(); i < nCount; i++ )
448 ThumbnailViewItem* pItem = getItem (i);
450 if( pItem && mpParent->IsItemSelected( pItem->mnId ) )
451 ++nRet;
454 return nRet;
457 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
459 ThrowIfDisposed();
460 const SolarMutexGuard aSolarGuard;
461 uno::Reference< accessibility::XAccessible > xRet;
463 for( sal_uInt16 i = 0, nCount = getItemCount(), nSel = 0; ( i < nCount ) && !xRet.is(); i++ )
465 ThumbnailViewItem* pItem = getItem(i);
467 if( pItem && mpParent->IsItemSelected( pItem->mnId ) && ( nSelectedChildIndex == static_cast< sal_Int32 >( nSel++ ) ) )
468 xRet = pItem->GetAccessible( /*bIsTransientChildrenDisabled*/false );
471 return xRet;
474 void SAL_CALL ThumbnailViewAcc::deselectAccessibleChild( sal_Int32 )
476 ThrowIfDisposed();
477 const SolarMutexGuard aSolarGuard;
478 // Because of the single selection we can reset the whole selection when
479 // the specified child is currently selected.
480 //FIXME TODO if (isAccessibleChildSelected(nChildIndex))
481 //FIXME TODO ;
484 sal_Int64 SAL_CALL ThumbnailViewAcc::getSomething( const uno::Sequence< sal_Int8 >& rId )
486 sal_Int64 nRet;
488 if( isUnoTunnelId<ThumbnailViewAcc>(rId) )
489 nRet = reinterpret_cast< sal_Int64 >( this );
490 else
491 nRet = 0;
493 return nRet;
496 void SAL_CALL ThumbnailViewAcc::disposing()
498 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> > aListenerListCopy;
501 // Make a copy of the list and clear the original.
502 const SolarMutexGuard aSolarGuard;
503 ::osl::MutexGuard aGuard (m_aMutex);
504 aListenerListCopy = mxEventListeners;
505 mxEventListeners.clear();
507 // Reset the pointer to the parent. It has to be the one who has
508 // disposed us because he is dying.
509 mpParent = nullptr;
512 // Inform all listeners that this objects is disposing.
513 lang::EventObject aEvent (static_cast<accessibility::XAccessible*>(this));
514 for (auto const& listener : aListenerListCopy)
518 listener->disposing (aEvent);
520 catch(const uno::Exception&)
522 // Ignore exceptions.
527 sal_uInt16 ThumbnailViewAcc::getItemCount() const
529 return mpParent->ImplGetVisibleItemCount();
532 ThumbnailViewItem* ThumbnailViewAcc::getItem (sal_uInt16 nIndex) const
534 return mpParent->ImplGetVisibleItem (nIndex);
537 void ThumbnailViewAcc::ThrowIfDisposed()
539 if (rBHelper.bDisposed || rBHelper.bInDispose)
541 SAL_WARN("sfx", "Calling disposed object. Throwing exception:");
542 throw lang::DisposedException (
543 "object has been already disposed",
544 static_cast<uno::XWeak*>(this));
546 else
548 DBG_ASSERT (mpParent!=nullptr, "ValueSetAcc not disposed but mpParent == NULL");
552 SfxThumbnailViewAcc::SfxThumbnailViewAcc( SfxThumbnailView* pParent ) :
553 ValueSetAccComponentBase (m_aMutex),
554 mpParent( pParent )
558 SfxThumbnailViewAcc::~SfxThumbnailViewAcc()
562 namespace
564 class theSfxValueSetAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSfxValueSetAccUnoTunnelId > {};
567 const uno::Sequence< sal_Int8 >& SfxThumbnailViewAcc::getUnoTunnelId()
569 return theSfxValueSetAccUnoTunnelId::get().getSeq();
572 uno::Reference< accessibility::XAccessibleContext > SAL_CALL SfxThumbnailViewAcc::getAccessibleContext()
574 ThrowIfDisposed();
575 return this;
578 sal_Int32 SAL_CALL SfxThumbnailViewAcc::getAccessibleChildCount()
580 const SolarMutexGuard aSolarGuard;
581 ThrowIfDisposed();
583 sal_Int32 nCount = mpParent->ImplGetVisibleItemCount();
584 return nCount;
587 uno::Reference< accessibility::XAccessible > SAL_CALL SfxThumbnailViewAcc::getAccessibleChild( sal_Int32 i )
589 ThrowIfDisposed();
590 const SolarMutexGuard aSolarGuard;
591 ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(i));
593 if( !pItem )
594 throw lang::IndexOutOfBoundsException();
596 uno::Reference< accessibility::XAccessible > xRet = pItem->GetAccessible( /*bIsTransientChildrenDisabled*/false );
597 return xRet;
600 uno::Reference< accessibility::XAccessible > SAL_CALL SfxThumbnailViewAcc::getAccessibleParent()
602 ThrowIfDisposed();
603 const SolarMutexGuard aSolarGuard;
604 return mpParent->GetDrawingArea()->get_accessible_parent();
607 sal_Int32 SAL_CALL SfxThumbnailViewAcc::getAccessibleIndexInParent()
609 ThrowIfDisposed();
610 const SolarMutexGuard aSolarGuard;
612 // -1 for child not found/no parent (according to specification)
613 sal_Int32 nRet = -1;
615 uno::Reference<accessibility::XAccessible> xParent(getAccessibleParent());
616 if (!xParent)
617 return nRet;
621 uno::Reference<accessibility::XAccessibleContext> xParentContext(xParent->getAccessibleContext());
623 // iterate over parent's children and search for this object
624 if ( xParentContext.is() )
626 sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
627 for ( sal_Int32 nChild = 0; ( nChild < nChildCount ) && ( -1 == nRet ); ++nChild )
629 uno::Reference<XAccessible> xChild(xParentContext->getAccessibleChild(nChild));
630 if ( xChild.get() == this )
631 nRet = nChild;
635 catch (const uno::Exception&)
637 OSL_FAIL( "OAccessibleContextHelper::getAccessibleIndexInParent: caught an exception!" );
640 return nRet;
643 sal_Int16 SAL_CALL SfxThumbnailViewAcc::getAccessibleRole()
645 ThrowIfDisposed();
646 // #i73746# As the Java Access Bridge (v 2.0.1) uses "managesDescendants"
647 // always if the role is LIST, we need a different role in this case
648 return accessibility::AccessibleRole::LIST;
651 OUString SAL_CALL SfxThumbnailViewAcc::getAccessibleDescription()
653 ThrowIfDisposed();
654 return "ThumbnailView";
657 OUString SAL_CALL SfxThumbnailViewAcc::getAccessibleName()
659 ThrowIfDisposed();
660 const SolarMutexGuard aSolarGuard;
661 OUString aRet;
663 if (mpParent)
665 aRet = mpParent->GetAccessibleName();
668 return aRet;
671 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL SfxThumbnailViewAcc::getAccessibleRelationSet()
673 ThrowIfDisposed();
674 return uno::Reference< accessibility::XAccessibleRelationSet >();
677 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL SfxThumbnailViewAcc::getAccessibleStateSet()
679 ThrowIfDisposed();
680 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
682 // Set some states.
683 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
684 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
685 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
686 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
687 pStateSet->AddState (accessibility::AccessibleStateType::MANAGES_DESCENDANTS);
688 pStateSet->AddState (accessibility::AccessibleStateType::FOCUSABLE);
690 return pStateSet;
693 lang::Locale SAL_CALL SfxThumbnailViewAcc::getLocale()
695 ThrowIfDisposed();
696 const SolarMutexGuard aSolarGuard;
697 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
698 lang::Locale aRet( "", "", "" );
700 if( xParent.is() )
702 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
704 if( xParentContext.is() )
705 aRet = xParentContext->getLocale ();
708 return aRet;
711 void SAL_CALL SfxThumbnailViewAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
713 ThrowIfDisposed();
714 ::osl::MutexGuard aGuard (m_aMutex);
716 if( !rxListener.is() )
717 return;
719 bool bFound = false;
721 for (auto const& eventListener : mxEventListeners)
723 if( eventListener == rxListener )
725 bFound = true;
726 break;
730 if (!bFound)
731 mxEventListeners.push_back( rxListener );
734 void SAL_CALL SfxThumbnailViewAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
736 ThrowIfDisposed();
737 ::osl::MutexGuard aGuard (m_aMutex);
739 if( rxListener.is() )
741 std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter =
742 std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener);
744 if (aIter != mxEventListeners.end())
745 mxEventListeners.erase( aIter );
749 sal_Bool SAL_CALL SfxThumbnailViewAcc::containsPoint( const awt::Point& aPoint )
751 ThrowIfDisposed();
752 const awt::Rectangle aRect( getBounds() );
753 const Point aSize( aRect.Width, aRect.Height );
754 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
756 return tools::Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
759 uno::Reference< accessibility::XAccessible > SAL_CALL SfxThumbnailViewAcc::getAccessibleAtPoint( const awt::Point& aPoint )
761 ThrowIfDisposed();
762 const SolarMutexGuard aSolarGuard;
763 const sal_uInt16 nItemId = mpParent->GetItemId( Point( aPoint.X, aPoint.Y ) );
764 uno::Reference< accessibility::XAccessible > xRet;
766 if ( nItemId )
768 const size_t nItemPos = mpParent->GetItemPos( nItemId );
770 if( THUMBNAILVIEW_ITEM_NONEITEM != nItemPos )
772 ThumbnailViewItem *const pItem = mpParent->mFilteredItemList[nItemPos];
773 xRet = pItem->GetAccessible( /*bIsTransientChildrenDisabled*/false );
777 return xRet;
780 awt::Rectangle SAL_CALL SfxThumbnailViewAcc::getBounds()
782 ThrowIfDisposed();
783 const SolarMutexGuard aSolarGuard;
784 const Point aOutPos;
785 const Size aOutSize( mpParent->GetOutputSizePixel() );
786 awt::Rectangle aRet;
788 aRet.X = aOutPos.X();
789 aRet.Y = aOutPos.Y();
790 aRet.Width = aOutSize.Width();
791 aRet.Height = aOutSize.Height();
793 return aRet;
796 awt::Point SAL_CALL SfxThumbnailViewAcc::getLocation()
798 ThrowIfDisposed();
799 const awt::Rectangle aRect( getBounds() );
800 awt::Point aRet;
802 aRet.X = aRect.X;
803 aRet.Y = aRect.Y;
805 return aRet;
808 awt::Point SAL_CALL SfxThumbnailViewAcc::getLocationOnScreen()
810 ThrowIfDisposed();
811 const SolarMutexGuard aSolarGuard;
812 awt::Point aScreenLoc(0, 0);
814 uno::Reference<accessibility::XAccessible> xParent(getAccessibleParent());
815 if (xParent)
817 uno::Reference<accessibility::XAccessibleContext> xParentContext(xParent->getAccessibleContext());
818 uno::Reference<accessibility::XAccessibleComponent> xParentComponent(xParentContext, css::uno::UNO_QUERY);
819 OSL_ENSURE( xParentComponent.is(), "SfxThumbnailViewAcc::getLocationOnScreen: no parent component!" );
820 if ( xParentComponent.is() )
822 awt::Point aParentScreenLoc( xParentComponent->getLocationOnScreen() );
823 awt::Point aOwnRelativeLoc( getLocation() );
824 aScreenLoc.X = aParentScreenLoc.X + aOwnRelativeLoc.X;
825 aScreenLoc.Y = aParentScreenLoc.Y + aOwnRelativeLoc.Y;
829 return aScreenLoc;
832 awt::Size SAL_CALL SfxThumbnailViewAcc::getSize()
834 ThrowIfDisposed();
835 const awt::Rectangle aRect( getBounds() );
836 awt::Size aRet;
838 aRet.Width = aRect.Width;
839 aRet.Height = aRect.Height;
841 return aRet;
844 void SAL_CALL SfxThumbnailViewAcc::grabFocus()
846 ThrowIfDisposed();
847 const SolarMutexGuard aSolarGuard;
848 mpParent->GrabFocus();
851 sal_Int32 SAL_CALL SfxThumbnailViewAcc::getForeground( )
853 ThrowIfDisposed();
854 Color nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor();
855 return static_cast<sal_Int32>(nColor);
858 sal_Int32 SAL_CALL SfxThumbnailViewAcc::getBackground( )
860 ThrowIfDisposed();
861 Color nColor = Application::GetSettings().GetStyleSettings().GetWindowColor();
862 return static_cast<sal_Int32>(nColor);
865 void SAL_CALL SfxThumbnailViewAcc::selectAccessibleChild( sal_Int32 nChildIndex )
867 ThrowIfDisposed();
868 const SolarMutexGuard aSolarGuard;
869 ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
871 if(pItem == nullptr)
872 throw lang::IndexOutOfBoundsException();
874 mpParent->SelectItem( pItem->mnId );
877 sal_Bool SAL_CALL SfxThumbnailViewAcc::isAccessibleChildSelected( sal_Int32 nChildIndex )
879 ThrowIfDisposed();
880 const SolarMutexGuard aSolarGuard;
881 ThumbnailViewItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
883 if (pItem == nullptr)
884 throw lang::IndexOutOfBoundsException();
886 return mpParent->IsItemSelected( pItem->mnId );
889 void SAL_CALL SfxThumbnailViewAcc::clearAccessibleSelection()
891 ThrowIfDisposed();
894 void SAL_CALL SfxThumbnailViewAcc::selectAllAccessibleChildren()
896 ThrowIfDisposed();
897 // unsupported due to single selection only
900 sal_Int32 SAL_CALL SfxThumbnailViewAcc::getSelectedAccessibleChildCount()
902 ThrowIfDisposed();
903 const SolarMutexGuard aSolarGuard;
904 sal_Int32 nRet = 0;
906 for( sal_uInt16 i = 0, nCount = getItemCount(); i < nCount; i++ )
908 ThumbnailViewItem* pItem = getItem (i);
910 if( pItem && mpParent->IsItemSelected( pItem->mnId ) )
911 ++nRet;
914 return nRet;
917 uno::Reference< accessibility::XAccessible > SAL_CALL SfxThumbnailViewAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
919 ThrowIfDisposed();
920 const SolarMutexGuard aSolarGuard;
921 uno::Reference< accessibility::XAccessible > xRet;
923 for( sal_uInt16 i = 0, nCount = getItemCount(), nSel = 0; ( i < nCount ) && !xRet.is(); i++ )
925 ThumbnailViewItem* pItem = getItem(i);
927 if( pItem && mpParent->IsItemSelected( pItem->mnId ) && ( nSelectedChildIndex == static_cast< sal_Int32 >( nSel++ ) ) )
928 xRet = pItem->GetAccessible( /*bIsTransientChildrenDisabled*/false );
931 return xRet;
934 void SAL_CALL SfxThumbnailViewAcc::deselectAccessibleChild( sal_Int32 )
936 ThrowIfDisposed();
937 const SolarMutexGuard aSolarGuard;
938 // Because of the single selection we can reset the whole selection when
939 // the specified child is currently selected.
940 //FIXME TODO if (isAccessibleChildSelected(nChildIndex))
941 //FIXME TODO ;
944 sal_Int64 SAL_CALL SfxThumbnailViewAcc::getSomething( const uno::Sequence< sal_Int8 >& rId )
946 sal_Int64 nRet;
948 if( isUnoTunnelId<SfxThumbnailViewAcc>(rId) )
949 nRet = reinterpret_cast< sal_Int64 >( this );
950 else
951 nRet = 0;
953 return nRet;
956 void SAL_CALL SfxThumbnailViewAcc::disposing()
958 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> > aListenerListCopy;
961 // Make a copy of the list and clear the original.
962 const SolarMutexGuard aSolarGuard;
963 ::osl::MutexGuard aGuard (m_aMutex);
964 aListenerListCopy = mxEventListeners;
965 mxEventListeners.clear();
967 // Reset the pointer to the parent. It has to be the one who has
968 // disposed us because he is dying.
969 mpParent = nullptr;
972 // Inform all listeners that this objects is disposing.
973 lang::EventObject aEvent (static_cast<accessibility::XAccessible*>(this));
974 for (auto const& listener : aListenerListCopy)
978 listener->disposing (aEvent);
980 catch(const uno::Exception&)
982 // Ignore exceptions.
987 sal_uInt16 SfxThumbnailViewAcc::getItemCount() const
989 return mpParent->ImplGetVisibleItemCount();
992 ThumbnailViewItem* SfxThumbnailViewAcc::getItem (sal_uInt16 nIndex) const
994 return mpParent->ImplGetVisibleItem (nIndex);
997 void SfxThumbnailViewAcc::ThrowIfDisposed()
999 if (rBHelper.bDisposed || rBHelper.bInDispose)
1001 SAL_WARN("sfx", "Calling disposed object. Throwing exception:");
1002 throw lang::DisposedException (
1003 "object has been already disposed",
1004 static_cast<uno::XWeak*>(this));
1006 else
1008 DBG_ASSERT (mpParent!=nullptr, "ValueSetAcc not disposed but mpParent == NULL");
1012 ThumbnailViewItemAcc::ThumbnailViewItemAcc( ThumbnailViewItem* pParent, bool bIsTransientChildrenDisabled ) :
1013 mpParent( pParent ),
1014 mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled )
1018 ThumbnailViewItemAcc::~ThumbnailViewItemAcc()
1022 void ThumbnailViewItemAcc::ParentDestroyed()
1024 const ::osl::MutexGuard aGuard( maMutex );
1025 mpParent = nullptr;
1028 namespace
1030 class theValueItemAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueItemAccUnoTunnelId > {};
1033 const uno::Sequence< sal_Int8 >& ThumbnailViewItemAcc::getUnoTunnelId()
1035 return theValueItemAccUnoTunnelId::get().getSeq();
1038 ThumbnailViewItemAcc* ThumbnailViewItemAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
1039 throw()
1043 return comphelper::getUnoTunnelImplementation<ThumbnailViewItemAcc>(rxData);
1045 catch(const css::uno::Exception&)
1047 return nullptr;
1051 uno::Reference< accessibility::XAccessibleContext > SAL_CALL ThumbnailViewItemAcc::getAccessibleContext()
1053 return this;
1056 sal_Int32 SAL_CALL ThumbnailViewItemAcc::getAccessibleChildCount()
1058 return 0;
1061 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleChild( sal_Int32 )
1063 throw lang::IndexOutOfBoundsException();
1066 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleParent()
1068 const SolarMutexGuard aSolarGuard;
1069 uno::Reference< accessibility::XAccessible > xRet;
1071 if( mpParent )
1072 xRet = mpParent->mrParent.getAccessible();
1074 return xRet;
1077 sal_Int32 SAL_CALL ThumbnailViewItemAcc::getAccessibleIndexInParent()
1079 const SolarMutexGuard aSolarGuard;
1080 // The index defaults to -1 to indicate the child does not belong to its
1081 // parent.
1082 sal_Int32 nIndexInParent = -1;
1084 if( mpParent )
1086 bool bDone = false;
1088 sal_uInt16 nCount = mpParent->mrParent.ImplGetVisibleItemCount();
1089 ThumbnailViewItem* pItem;
1090 for (sal_uInt16 i=0; i<nCount && !bDone; i++)
1092 // Guard the retrieval of the i-th child with a try/catch block
1093 // just in case the number of children changes in the meantime.
1096 pItem = mpParent->mrParent.ImplGetVisibleItem (i);
1098 catch (const lang::IndexOutOfBoundsException&)
1100 pItem = nullptr;
1103 // Do not create an accessible object for the test.
1104 if (pItem != nullptr && pItem->mxAcc.is())
1105 if (pItem->GetAccessible( mbIsTransientChildrenDisabled ).get() == this )
1107 nIndexInParent = i;
1108 bDone = true;
1113 return nIndexInParent;
1116 sal_Int16 SAL_CALL ThumbnailViewItemAcc::getAccessibleRole()
1118 return accessibility::AccessibleRole::LIST_ITEM;
1121 OUString SAL_CALL ThumbnailViewItemAcc::getAccessibleDescription()
1123 return OUString();
1126 OUString SAL_CALL ThumbnailViewItemAcc::getAccessibleName()
1128 const SolarMutexGuard aSolarGuard;
1129 OUString aRet;
1131 if( mpParent )
1133 aRet = mpParent->maTitle;
1135 if( aRet.isEmpty() )
1137 aRet = "Item " + OUString::number(static_cast<sal_Int32>(mpParent->mnId));
1141 return aRet;
1144 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ThumbnailViewItemAcc::getAccessibleRelationSet()
1146 return uno::Reference< accessibility::XAccessibleRelationSet >();
1149 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ThumbnailViewItemAcc::getAccessibleStateSet()
1151 const SolarMutexGuard aSolarGuard;
1152 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
1154 if( mpParent )
1156 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
1157 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
1158 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
1159 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
1160 if ( !mbIsTransientChildrenDisabled )
1161 pStateSet->AddState (accessibility::AccessibleStateType::TRANSIENT);
1163 // SELECTABLE
1164 pStateSet->AddState( accessibility::AccessibleStateType::SELECTABLE );
1165 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
1167 // SELECTED
1168 if( mpParent->isSelected() )
1170 pStateSet->AddState( accessibility::AccessibleStateType::SELECTED );
1171 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
1175 return pStateSet;
1178 lang::Locale SAL_CALL ThumbnailViewItemAcc::getLocale()
1180 const SolarMutexGuard aSolarGuard;
1181 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
1182 lang::Locale aRet( "", "", "" );
1184 if( xParent.is() )
1186 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
1188 if( xParentContext.is() )
1189 aRet = xParentContext->getLocale();
1192 return aRet;
1195 void SAL_CALL ThumbnailViewItemAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
1197 const ::osl::MutexGuard aGuard( maMutex );
1199 if( !rxListener.is() )
1200 return;
1202 bool bFound = false;
1204 for (auto const& eventListener : mxEventListeners)
1206 if( eventListener == rxListener )
1208 bFound = true;
1209 break;
1213 if (!bFound)
1214 mxEventListeners.push_back( rxListener );
1217 void SAL_CALL ThumbnailViewItemAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
1219 const ::osl::MutexGuard aGuard( maMutex );
1221 if( rxListener.is() )
1223 std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter =
1224 std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener);
1226 if (aIter != mxEventListeners.end())
1227 mxEventListeners.erase( aIter );
1231 sal_Bool SAL_CALL ThumbnailViewItemAcc::containsPoint( const awt::Point& aPoint )
1233 const awt::Rectangle aRect( getBounds() );
1234 const Point aSize( aRect.Width, aRect.Height );
1235 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
1237 return tools::Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
1240 uno::Reference< accessibility::XAccessible > SAL_CALL ThumbnailViewItemAcc::getAccessibleAtPoint( const awt::Point& )
1242 uno::Reference< accessibility::XAccessible > xRet;
1243 return xRet;
1246 awt::Rectangle SAL_CALL ThumbnailViewItemAcc::getBounds()
1248 const SolarMutexGuard aSolarGuard;
1249 awt::Rectangle aRet;
1251 if( mpParent )
1253 tools::Rectangle aRect( mpParent->getDrawArea() );
1254 tools::Rectangle aParentRect;
1256 // get position of the accessible parent in screen coordinates
1257 uno::Reference< XAccessible > xParent = getAccessibleParent();
1258 if ( xParent.is() )
1260 uno::Reference<XAccessibleComponent> xParentComponent(xParent->getAccessibleContext(), uno::UNO_QUERY);
1261 if (xParentComponent.is())
1263 awt::Size aParentSize = xParentComponent->getSize();
1264 aParentRect = tools::Rectangle(0, 0, aParentSize.Width, aParentSize.Height);
1268 aRect.Intersection( aParentRect );
1270 aRet.X = aRect.Left();
1271 aRet.Y = aRect.Top();
1272 aRet.Width = aRect.GetWidth();
1273 aRet.Height = aRect.GetHeight();
1276 return aRet;
1279 awt::Point SAL_CALL ThumbnailViewItemAcc::getLocation()
1281 const awt::Rectangle aRect( getBounds() );
1282 awt::Point aRet;
1284 aRet.X = aRect.X;
1285 aRet.Y = aRect.Y;
1287 return aRet;
1290 awt::Point SAL_CALL ThumbnailViewItemAcc::getLocationOnScreen()
1292 const SolarMutexGuard aSolarGuard;
1293 awt::Point aRet;
1295 if( mpParent )
1297 const Point aPos = mpParent->getDrawArea().TopLeft();
1299 aRet.X = aPos.X();
1300 aRet.Y = aPos.Y();
1302 // get position of the accessible parent in screen coordinates
1303 uno::Reference< XAccessible > xParent = getAccessibleParent();
1304 if ( xParent.is() )
1306 uno::Reference<XAccessibleComponent> xParentComponent(xParent->getAccessibleContext(), uno::UNO_QUERY);
1307 if (xParentComponent.is())
1309 awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
1310 aRet.X += aParentScreenLoc.X;
1311 aRet.Y += aParentScreenLoc.Y;
1316 return aRet;
1319 awt::Size SAL_CALL ThumbnailViewItemAcc::getSize()
1321 const awt::Rectangle aRect( getBounds() );
1322 awt::Size aRet;
1324 aRet.Width = aRect.Width;
1325 aRet.Height = aRect.Height;
1327 return aRet;
1330 void SAL_CALL ThumbnailViewItemAcc::grabFocus()
1332 // nothing to do
1335 sal_Int32 SAL_CALL ThumbnailViewItemAcc::getForeground( )
1337 Color nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor();
1338 return static_cast<sal_Int32>(nColor);
1341 sal_Int32 SAL_CALL ThumbnailViewItemAcc::getBackground( )
1343 return static_cast<sal_Int32>(Application::GetSettings().GetStyleSettings().GetWindowColor());
1346 sal_Int64 SAL_CALL ThumbnailViewItemAcc::getSomething( const uno::Sequence< sal_Int8 >& rId )
1348 sal_Int64 nRet;
1350 if( isUnoTunnelId<ThumbnailViewItemAcc>(rId) )
1351 nRet = reinterpret_cast< sal_Int64 >( this );
1352 else
1353 nRet = 0;
1355 return nRet;
1358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */