1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
),
45 ThumbnailViewAcc::~ThumbnailViewAcc()
49 void ThumbnailViewAcc::FireAccessibleEvent( short nEventId
, const uno::Any
& rOldValue
, const uno::Any
& rNewValue
)
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
)
66 tmpListener
->notifyEvent( aEvtObject
);
68 catch(const uno::Exception
&)
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
)
89 return comphelper::getUnoTunnelImplementation
<ThumbnailViewAcc
>(rxData
);
91 catch(const css::uno::Exception
&)
97 void ThumbnailViewAcc::GetFocus()
101 // Broadcast the state change.
102 css::uno::Any aOldState
, aNewState
;
103 aNewState
<<= css::accessibility::AccessibleStateType::FOCUSED
;
105 css::accessibility::AccessibleEventId::STATE_CHANGED
,
106 aOldState
, aNewState
);
109 void ThumbnailViewAcc::LoseFocus()
113 // Broadcast the state change.
114 css::uno::Any aOldState
, aNewState
;
115 aOldState
<<= css::accessibility::AccessibleStateType::FOCUSED
;
117 css::accessibility::AccessibleEventId::STATE_CHANGED
,
118 aOldState
, aNewState
);
121 uno::Reference
< accessibility::XAccessibleContext
> SAL_CALL
ThumbnailViewAcc::getAccessibleContext()
127 sal_Int32 SAL_CALL
ThumbnailViewAcc::getAccessibleChildCount()
129 const SolarMutexGuard aSolarGuard
;
132 sal_Int32 nCount
= mpParent
->ImplGetVisibleItemCount();
136 uno::Reference
< accessibility::XAccessible
> SAL_CALL
ThumbnailViewAcc::getAccessibleChild( sal_Int32 i
)
139 const SolarMutexGuard aSolarGuard
;
140 ThumbnailViewItem
* pItem
= getItem (sal::static_int_cast
< sal_uInt16
>(i
));
143 throw lang::IndexOutOfBoundsException();
145 uno::Reference
< accessibility::XAccessible
> xRet
= pItem
->GetAccessible( /*bIsTransientChildrenDisabled*/false );
149 uno::Reference
< accessibility::XAccessible
> SAL_CALL
ThumbnailViewAcc::getAccessibleParent()
152 const SolarMutexGuard aSolarGuard
;
153 vcl::Window
* pParent
= mpParent
->GetParent();
154 uno::Reference
< accessibility::XAccessible
> xRet
;
157 xRet
= pParent
->GetAccessible();
162 sal_Int32 SAL_CALL
ThumbnailViewAcc::getAccessibleIndexInParent()
165 const SolarMutexGuard aSolarGuard
;
166 vcl::Window
* pParent
= mpParent
->GetParent();
173 for( sal_uInt16 i
= 0, nCount
= pParent
->GetChildCount(); ( i
< nCount
) && !bFound
; i
++ )
175 if( pParent
->GetChild( i
) == mpParent
)
186 sal_Int16 SAL_CALL
ThumbnailViewAcc::getAccessibleRole()
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()
197 return "ThumbnailView";
200 OUString SAL_CALL
ThumbnailViewAcc::getAccessibleName()
203 const SolarMutexGuard aSolarGuard
;
208 aRet
= mpParent
->GetAccessibleName();
211 vcl::Window
* pLabel
= mpParent
->GetAccessibleRelationLabeledBy();
212 if (pLabel
&& pLabel
!= mpParent
)
213 aRet
= OutputDevice::GetNonMnemonicString( pLabel
->GetText() );
220 uno::Reference
< accessibility::XAccessibleRelationSet
> SAL_CALL
ThumbnailViewAcc::getAccessibleRelationSet()
223 return uno::Reference
< accessibility::XAccessibleRelationSet
>();
226 uno::Reference
< accessibility::XAccessibleStateSet
> SAL_CALL
ThumbnailViewAcc::getAccessibleStateSet()
229 ::utl::AccessibleStateSetHelper
* pStateSet
= new ::utl::AccessibleStateSetHelper();
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
);
239 pStateSet
->AddState (accessibility::AccessibleStateType::FOCUSED
);
244 lang::Locale SAL_CALL
ThumbnailViewAcc::getLocale()
247 const SolarMutexGuard aSolarGuard
;
248 uno::Reference
< accessibility::XAccessible
> xParent( getAccessibleParent() );
249 lang::Locale
aRet( "", "", "" );
253 uno::Reference
< accessibility::XAccessibleContext
> xParentContext( xParent
->getAccessibleContext() );
255 if( xParentContext
.is() )
256 aRet
= xParentContext
->getLocale ();
262 void SAL_CALL
ThumbnailViewAcc::addAccessibleEventListener( const uno::Reference
< accessibility::XAccessibleEventListener
>& rxListener
)
265 ::osl::MutexGuard
aGuard (m_aMutex
);
267 if( !rxListener
.is() )
272 for (auto const& eventListener
: mxEventListeners
)
274 if( eventListener
== rxListener
)
282 mxEventListeners
.push_back( rxListener
);
285 void SAL_CALL
ThumbnailViewAcc::removeAccessibleEventListener( const uno::Reference
< accessibility::XAccessibleEventListener
>& rxListener
)
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
)
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
)
313 const SolarMutexGuard aSolarGuard
;
314 const sal_uInt16 nItemId
= mpParent
->GetItemId( Point( aPoint
.X
, aPoint
.Y
) );
315 uno::Reference
< accessibility::XAccessible
> xRet
;
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 );
331 awt::Rectangle SAL_CALL
ThumbnailViewAcc::getBounds()
334 const SolarMutexGuard aSolarGuard
;
335 const Point
aOutPos( mpParent
->GetPosPixel() );
336 const Size
aOutSize( mpParent
->GetOutputSizePixel() );
339 aRet
.X
= aOutPos
.X();
340 aRet
.Y
= aOutPos
.Y();
341 aRet
.Width
= aOutSize
.Width();
342 aRet
.Height
= aOutSize
.Height();
347 awt::Point SAL_CALL
ThumbnailViewAcc::getLocation()
350 const awt::Rectangle
aRect( getBounds() );
359 awt::Point SAL_CALL
ThumbnailViewAcc::getLocationOnScreen()
362 const SolarMutexGuard aSolarGuard
;
363 const Point
aScreenPos( mpParent
->OutputToAbsoluteScreenPixel( Point() ) );
366 aRet
.X
= aScreenPos
.X();
367 aRet
.Y
= aScreenPos
.Y();
372 awt::Size SAL_CALL
ThumbnailViewAcc::getSize()
375 const awt::Rectangle
aRect( getBounds() );
378 aRet
.Width
= aRect
.Width
;
379 aRet
.Height
= aRect
.Height
;
384 void SAL_CALL
ThumbnailViewAcc::grabFocus()
387 const SolarMutexGuard aSolarGuard
;
388 mpParent
->GrabFocus();
391 sal_Int32 SAL_CALL
ThumbnailViewAcc::getForeground( )
394 Color nColor
= Application::GetSettings().GetStyleSettings().GetWindowTextColor();
395 return static_cast<sal_Int32
>(nColor
);
398 sal_Int32 SAL_CALL
ThumbnailViewAcc::getBackground( )
401 Color nColor
= Application::GetSettings().GetStyleSettings().GetWindowColor();
402 return static_cast<sal_Int32
>(nColor
);
405 void SAL_CALL
ThumbnailViewAcc::selectAccessibleChild( sal_Int32 nChildIndex
)
408 const SolarMutexGuard aSolarGuard
;
409 ThumbnailViewItem
* pItem
= getItem (sal::static_int_cast
< sal_uInt16
>(nChildIndex
));
412 throw lang::IndexOutOfBoundsException();
414 mpParent
->SelectItem( pItem
->mnId
);
417 sal_Bool SAL_CALL
ThumbnailViewAcc::isAccessibleChildSelected( sal_Int32 nChildIndex
)
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()
434 void SAL_CALL
ThumbnailViewAcc::selectAllAccessibleChildren()
437 // unsupported due to single selection only
440 sal_Int32 SAL_CALL
ThumbnailViewAcc::getSelectedAccessibleChildCount()
443 const SolarMutexGuard aSolarGuard
;
446 for( sal_uInt16 i
= 0, nCount
= getItemCount(); i
< nCount
; i
++ )
448 ThumbnailViewItem
* pItem
= getItem (i
);
450 if( pItem
&& mpParent
->IsItemSelected( pItem
->mnId
) )
457 uno::Reference
< accessibility::XAccessible
> SAL_CALL
ThumbnailViewAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
)
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 );
474 void SAL_CALL
ThumbnailViewAcc::deselectAccessibleChild( sal_Int32
)
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))
484 sal_Int64 SAL_CALL
ThumbnailViewAcc::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
488 if( isUnoTunnelId
<ThumbnailViewAcc
>(rId
) )
489 nRet
= reinterpret_cast< sal_Int64
>( this );
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.
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));
548 DBG_ASSERT (mpParent
!=nullptr, "ValueSetAcc not disposed but mpParent == NULL");
552 SfxThumbnailViewAcc::SfxThumbnailViewAcc( SfxThumbnailView
* pParent
) :
553 ValueSetAccComponentBase (m_aMutex
),
558 SfxThumbnailViewAcc::~SfxThumbnailViewAcc()
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()
578 sal_Int32 SAL_CALL
SfxThumbnailViewAcc::getAccessibleChildCount()
580 const SolarMutexGuard aSolarGuard
;
583 sal_Int32 nCount
= mpParent
->ImplGetVisibleItemCount();
587 uno::Reference
< accessibility::XAccessible
> SAL_CALL
SfxThumbnailViewAcc::getAccessibleChild( sal_Int32 i
)
590 const SolarMutexGuard aSolarGuard
;
591 ThumbnailViewItem
* pItem
= getItem (sal::static_int_cast
< sal_uInt16
>(i
));
594 throw lang::IndexOutOfBoundsException();
596 uno::Reference
< accessibility::XAccessible
> xRet
= pItem
->GetAccessible( /*bIsTransientChildrenDisabled*/false );
600 uno::Reference
< accessibility::XAccessible
> SAL_CALL
SfxThumbnailViewAcc::getAccessibleParent()
603 const SolarMutexGuard aSolarGuard
;
604 return mpParent
->GetDrawingArea()->get_accessible_parent();
607 sal_Int32 SAL_CALL
SfxThumbnailViewAcc::getAccessibleIndexInParent()
610 const SolarMutexGuard aSolarGuard
;
612 // -1 for child not found/no parent (according to specification)
615 uno::Reference
<accessibility::XAccessible
> xParent(getAccessibleParent());
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 )
635 catch (const uno::Exception
&)
637 OSL_FAIL( "OAccessibleContextHelper::getAccessibleIndexInParent: caught an exception!" );
643 sal_Int16 SAL_CALL
SfxThumbnailViewAcc::getAccessibleRole()
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()
654 return "ThumbnailView";
657 OUString SAL_CALL
SfxThumbnailViewAcc::getAccessibleName()
660 const SolarMutexGuard aSolarGuard
;
665 aRet
= mpParent
->GetAccessibleName();
671 uno::Reference
< accessibility::XAccessibleRelationSet
> SAL_CALL
SfxThumbnailViewAcc::getAccessibleRelationSet()
674 return uno::Reference
< accessibility::XAccessibleRelationSet
>();
677 uno::Reference
< accessibility::XAccessibleStateSet
> SAL_CALL
SfxThumbnailViewAcc::getAccessibleStateSet()
680 ::utl::AccessibleStateSetHelper
* pStateSet
= new ::utl::AccessibleStateSetHelper();
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
);
693 lang::Locale SAL_CALL
SfxThumbnailViewAcc::getLocale()
696 const SolarMutexGuard aSolarGuard
;
697 uno::Reference
< accessibility::XAccessible
> xParent( getAccessibleParent() );
698 lang::Locale
aRet( "", "", "" );
702 uno::Reference
< accessibility::XAccessibleContext
> xParentContext( xParent
->getAccessibleContext() );
704 if( xParentContext
.is() )
705 aRet
= xParentContext
->getLocale ();
711 void SAL_CALL
SfxThumbnailViewAcc::addAccessibleEventListener( const uno::Reference
< accessibility::XAccessibleEventListener
>& rxListener
)
714 ::osl::MutexGuard
aGuard (m_aMutex
);
716 if( !rxListener
.is() )
721 for (auto const& eventListener
: mxEventListeners
)
723 if( eventListener
== rxListener
)
731 mxEventListeners
.push_back( rxListener
);
734 void SAL_CALL
SfxThumbnailViewAcc::removeAccessibleEventListener( const uno::Reference
< accessibility::XAccessibleEventListener
>& rxListener
)
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
)
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
)
762 const SolarMutexGuard aSolarGuard
;
763 const sal_uInt16 nItemId
= mpParent
->GetItemId( Point( aPoint
.X
, aPoint
.Y
) );
764 uno::Reference
< accessibility::XAccessible
> xRet
;
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 );
780 awt::Rectangle SAL_CALL
SfxThumbnailViewAcc::getBounds()
783 const SolarMutexGuard aSolarGuard
;
785 const Size
aOutSize( mpParent
->GetOutputSizePixel() );
788 aRet
.X
= aOutPos
.X();
789 aRet
.Y
= aOutPos
.Y();
790 aRet
.Width
= aOutSize
.Width();
791 aRet
.Height
= aOutSize
.Height();
796 awt::Point SAL_CALL
SfxThumbnailViewAcc::getLocation()
799 const awt::Rectangle
aRect( getBounds() );
808 awt::Point SAL_CALL
SfxThumbnailViewAcc::getLocationOnScreen()
811 const SolarMutexGuard aSolarGuard
;
812 awt::Point
aScreenLoc(0, 0);
814 uno::Reference
<accessibility::XAccessible
> xParent(getAccessibleParent());
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
;
832 awt::Size SAL_CALL
SfxThumbnailViewAcc::getSize()
835 const awt::Rectangle
aRect( getBounds() );
838 aRet
.Width
= aRect
.Width
;
839 aRet
.Height
= aRect
.Height
;
844 void SAL_CALL
SfxThumbnailViewAcc::grabFocus()
847 const SolarMutexGuard aSolarGuard
;
848 mpParent
->GrabFocus();
851 sal_Int32 SAL_CALL
SfxThumbnailViewAcc::getForeground( )
854 Color nColor
= Application::GetSettings().GetStyleSettings().GetWindowTextColor();
855 return static_cast<sal_Int32
>(nColor
);
858 sal_Int32 SAL_CALL
SfxThumbnailViewAcc::getBackground( )
861 Color nColor
= Application::GetSettings().GetStyleSettings().GetWindowColor();
862 return static_cast<sal_Int32
>(nColor
);
865 void SAL_CALL
SfxThumbnailViewAcc::selectAccessibleChild( sal_Int32 nChildIndex
)
868 const SolarMutexGuard aSolarGuard
;
869 ThumbnailViewItem
* pItem
= getItem (sal::static_int_cast
< sal_uInt16
>(nChildIndex
));
872 throw lang::IndexOutOfBoundsException();
874 mpParent
->SelectItem( pItem
->mnId
);
877 sal_Bool SAL_CALL
SfxThumbnailViewAcc::isAccessibleChildSelected( sal_Int32 nChildIndex
)
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()
894 void SAL_CALL
SfxThumbnailViewAcc::selectAllAccessibleChildren()
897 // unsupported due to single selection only
900 sal_Int32 SAL_CALL
SfxThumbnailViewAcc::getSelectedAccessibleChildCount()
903 const SolarMutexGuard aSolarGuard
;
906 for( sal_uInt16 i
= 0, nCount
= getItemCount(); i
< nCount
; i
++ )
908 ThumbnailViewItem
* pItem
= getItem (i
);
910 if( pItem
&& mpParent
->IsItemSelected( pItem
->mnId
) )
917 uno::Reference
< accessibility::XAccessible
> SAL_CALL
SfxThumbnailViewAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
)
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 );
934 void SAL_CALL
SfxThumbnailViewAcc::deselectAccessibleChild( sal_Int32
)
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))
944 sal_Int64 SAL_CALL
SfxThumbnailViewAcc::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
948 if( isUnoTunnelId
<SfxThumbnailViewAcc
>(rId
) )
949 nRet
= reinterpret_cast< sal_Int64
>( this );
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.
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));
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
);
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
)
1043 return comphelper::getUnoTunnelImplementation
<ThumbnailViewItemAcc
>(rxData
);
1045 catch(const css::uno::Exception
&)
1051 uno::Reference
< accessibility::XAccessibleContext
> SAL_CALL
ThumbnailViewItemAcc::getAccessibleContext()
1056 sal_Int32 SAL_CALL
ThumbnailViewItemAcc::getAccessibleChildCount()
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
;
1072 xRet
= mpParent
->mrParent
.getAccessible();
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
1082 sal_Int32 nIndexInParent
= -1;
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
&)
1103 // Do not create an accessible object for the test.
1104 if (pItem
!= nullptr && pItem
->mxAcc
.is())
1105 if (pItem
->GetAccessible( mbIsTransientChildrenDisabled
).get() == this )
1113 return nIndexInParent
;
1116 sal_Int16 SAL_CALL
ThumbnailViewItemAcc::getAccessibleRole()
1118 return accessibility::AccessibleRole::LIST_ITEM
;
1121 OUString SAL_CALL
ThumbnailViewItemAcc::getAccessibleDescription()
1126 OUString SAL_CALL
ThumbnailViewItemAcc::getAccessibleName()
1128 const SolarMutexGuard aSolarGuard
;
1133 aRet
= mpParent
->maTitle
;
1135 if( aRet
.isEmpty() )
1137 aRet
= "Item " + OUString::number(static_cast<sal_Int32
>(mpParent
->mnId
));
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
;
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
);
1164 pStateSet
->AddState( accessibility::AccessibleStateType::SELECTABLE
);
1165 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
1168 if( mpParent
->isSelected() )
1170 pStateSet
->AddState( accessibility::AccessibleStateType::SELECTED
);
1171 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
1178 lang::Locale SAL_CALL
ThumbnailViewItemAcc::getLocale()
1180 const SolarMutexGuard aSolarGuard
;
1181 uno::Reference
< accessibility::XAccessible
> xParent( getAccessibleParent() );
1182 lang::Locale
aRet( "", "", "" );
1186 uno::Reference
< accessibility::XAccessibleContext
> xParentContext( xParent
->getAccessibleContext() );
1188 if( xParentContext
.is() )
1189 aRet
= xParentContext
->getLocale();
1195 void SAL_CALL
ThumbnailViewItemAcc::addAccessibleEventListener( const uno::Reference
< accessibility::XAccessibleEventListener
>& rxListener
)
1197 const ::osl::MutexGuard
aGuard( maMutex
);
1199 if( !rxListener
.is() )
1202 bool bFound
= false;
1204 for (auto const& eventListener
: mxEventListeners
)
1206 if( eventListener
== rxListener
)
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
;
1246 awt::Rectangle SAL_CALL
ThumbnailViewItemAcc::getBounds()
1248 const SolarMutexGuard aSolarGuard
;
1249 awt::Rectangle aRet
;
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();
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();
1279 awt::Point SAL_CALL
ThumbnailViewItemAcc::getLocation()
1281 const awt::Rectangle
aRect( getBounds() );
1290 awt::Point SAL_CALL
ThumbnailViewItemAcc::getLocationOnScreen()
1292 const SolarMutexGuard aSolarGuard
;
1297 const Point aPos
= mpParent
->getDrawArea().TopLeft();
1302 // get position of the accessible parent in screen coordinates
1303 uno::Reference
< XAccessible
> xParent
= getAccessibleParent();
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
;
1319 awt::Size SAL_CALL
ThumbnailViewItemAcc::getSize()
1321 const awt::Rectangle
aRect( getBounds() );
1324 aRet
.Width
= aRect
.Width
;
1325 aRet
.Height
= aRect
.Height
;
1330 void SAL_CALL
ThumbnailViewItemAcc::grabFocus()
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
)
1350 if( isUnoTunnelId
<ThumbnailViewItemAcc
>(rId
) )
1351 nRet
= reinterpret_cast< sal_Int64
>( this );
1358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */