Bump version to 5.0-14
[LibreOffice.git] / svtools / source / control / valueacc.cxx
blobc6aa67b65e203ccd4930695d2b00892520825f79
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 <unotools/accessiblestatesethelper.hxx>
21 #include <vcl/svapp.hxx>
22 #include <vcl/settings.hxx>
23 #include <svtools/valueset.hxx>
24 #include "valueimp.hxx"
25 #include <comphelper/servicehelper.hxx>
26 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
27 #include <com/sun/star/accessibility/AccessibleRole.hpp>
28 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
29 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
30 #include <unotools/accessiblerelationsethelper.hxx>
32 using namespace ::com::sun::star;
35 // - ValueSetItem -
38 ValueSetItem::ValueSetItem( ValueSet& rParent )
39 : mrParent(rParent)
40 , mnId(0)
41 , meType(VALUESETITEM_NONE)
42 , mbVisible(true)
43 , mpData(NULL)
44 , mbSelected(false)
45 , mpxAcc(NULL)
51 ValueSetItem::~ValueSetItem()
53 if( mpxAcc )
55 static_cast< ValueItemAcc* >( mpxAcc->get() )->ParentDestroyed();
56 delete mpxAcc;
62 uno::Reference< accessibility::XAccessible > ValueSetItem::GetAccessible( bool bIsTransientChildrenDisabled )
64 if( !mpxAcc )
65 mpxAcc = new uno::Reference< accessibility::XAccessible >( new ValueItemAcc( this, bIsTransientChildrenDisabled ) );
67 return *mpxAcc;
71 // - ValueSetAcc -
74 ValueSetAcc::ValueSetAcc( ValueSet* pParent, bool bIsTransientChildrenDisabled ) :
75 ValueSetAccComponentBase (m_aMutex),
76 mpParent( pParent ),
77 mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled ),
78 mbIsFocused(false)
84 ValueSetAcc::~ValueSetAcc()
90 void ValueSetAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
92 if( nEventId )
94 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners );
95 accessibility::AccessibleEventObject aEvtObject;
97 aEvtObject.EventId = nEventId;
98 aEvtObject.Source = static_cast<uno::XWeak*>(this);
99 aEvtObject.NewValue = rNewValue;
100 aEvtObject.OldValue = rOldValue;
102 for (::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter( aTmpListeners.begin() );
103 aIter != aTmpListeners.end() ; ++aIter)
107 (*aIter)->notifyEvent( aEvtObject );
109 catch(const uno::Exception&)
116 namespace
118 class theValueSetAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueSetAccUnoTunnelId > {};
121 const uno::Sequence< sal_Int8 >& ValueSetAcc::getUnoTunnelId()
123 return theValueSetAccUnoTunnelId::get().getSeq();
128 ValueSetAcc* ValueSetAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
129 throw()
133 uno::Reference< lang::XUnoTunnel > xUnoTunnel( rxData, uno::UNO_QUERY );
134 return( xUnoTunnel.is() ? reinterpret_cast<ValueSetAcc*>(sal::static_int_cast<sal_IntPtr>(xUnoTunnel->getSomething( ValueSetAcc::getUnoTunnelId() ))) : NULL );
136 catch(const ::com::sun::star::uno::Exception&)
138 return NULL;
145 void ValueSetAcc::GetFocus()
147 mbIsFocused = true;
149 // Broadcast the state change.
150 ::com::sun::star::uno::Any aOldState, aNewState;
151 aNewState <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
152 FireAccessibleEvent(
153 ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED,
154 aOldState, aNewState);
159 void ValueSetAcc::LoseFocus()
161 mbIsFocused = false;
163 // Broadcast the state change.
164 ::com::sun::star::uno::Any aOldState, aNewState;
165 aOldState <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
166 FireAccessibleEvent(
167 ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED,
168 aOldState, aNewState);
173 uno::Reference< accessibility::XAccessibleContext > SAL_CALL ValueSetAcc::getAccessibleContext()
174 throw (uno::RuntimeException, std::exception)
176 ThrowIfDisposed();
177 return this;
182 sal_Int32 SAL_CALL ValueSetAcc::getAccessibleChildCount()
183 throw (uno::RuntimeException, std::exception)
185 const SolarMutexGuard aSolarGuard;
186 ThrowIfDisposed();
188 sal_Int32 nCount = mpParent->ImplGetVisibleItemCount();
189 if (HasNoneField())
190 nCount += 1;
191 return nCount;
196 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessibleChild( sal_Int32 i )
197 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
199 ThrowIfDisposed();
200 const SolarMutexGuard aSolarGuard;
201 uno::Reference< accessibility::XAccessible > xRet;
202 ValueSetItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(i));
204 if( pItem )
205 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
206 else
207 throw lang::IndexOutOfBoundsException();
209 return xRet;
214 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessibleParent()
215 throw (uno::RuntimeException, std::exception)
217 ThrowIfDisposed();
218 const SolarMutexGuard aSolarGuard;
219 vcl::Window* pParent = mpParent->GetParent();
220 uno::Reference< accessibility::XAccessible > xRet;
222 if( pParent )
223 xRet = pParent->GetAccessible();
225 return xRet;
230 sal_Int32 SAL_CALL ValueSetAcc::getAccessibleIndexInParent()
231 throw (uno::RuntimeException, std::exception)
233 ThrowIfDisposed();
234 const SolarMutexGuard aSolarGuard;
235 vcl::Window* pParent = mpParent->GetParent();
236 sal_Int32 nRet = 0;
238 if( pParent )
240 bool bFound = false;
242 for( sal_uInt16 i = 0, nCount = pParent->GetChildCount(); ( i < nCount ) && !bFound; i++ )
244 if( pParent->GetChild( i ) == mpParent )
246 nRet = i;
247 bFound = true;
252 return nRet;
257 sal_Int16 SAL_CALL ValueSetAcc::getAccessibleRole()
258 throw (uno::RuntimeException, std::exception)
260 ThrowIfDisposed();
261 // #i73746# As the Java Access Bridge (v 2.0.1) uses "managesDescendants"
262 // always if the role is LIST, we need a different role in this case
263 return (mbIsTransientChildrenDisabled
264 ? accessibility::AccessibleRole::PANEL
265 : accessibility::AccessibleRole::LIST );
270 OUString SAL_CALL ValueSetAcc::getAccessibleDescription()
271 throw (uno::RuntimeException, std::exception)
273 ThrowIfDisposed();
274 const SolarMutexGuard aSolarGuard;
275 OUString aRet( "ValueSet" );
277 return aRet;
282 OUString SAL_CALL ValueSetAcc::getAccessibleName()
283 throw (uno::RuntimeException, std::exception)
285 ThrowIfDisposed();
286 const SolarMutexGuard aSolarGuard;
287 OUString aRet;
289 if (mpParent)
291 aRet = mpParent->GetAccessibleName();
293 if ( aRet.isEmpty() )
295 vcl::Window* pLabel = mpParent->GetAccessibleRelationLabeledBy();
296 if ( pLabel && pLabel != mpParent )
297 aRet = OutputDevice::GetNonMnemonicString( pLabel->GetText() );
299 if (aRet.isEmpty())
300 aRet = mpParent->GetQuickHelpText();
304 return aRet;
309 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ValueSetAcc::getAccessibleRelationSet()
310 throw (uno::RuntimeException, std::exception)
312 ThrowIfDisposed();
313 SolarMutexGuard g;
314 uno::Reference< accessibility::XAccessibleRelationSet > xRelSet;
315 vcl::Window* pWindow = (vcl::Window*)mpParent;
316 if ( pWindow )
318 utl::AccessibleRelationSetHelper* pRelationSet = new utl::AccessibleRelationSetHelper;
319 xRelSet = pRelationSet;
321 vcl::Window *pLabeledBy = pWindow->GetAccessibleRelationLabeledBy();
322 if ( pLabeledBy && pLabeledBy != pWindow )
324 uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
325 aSequence[0] = pLabeledBy->GetAccessible();
326 pRelationSet->AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABELED_BY, aSequence ) );
329 vcl::Window* pMemberOf = pWindow->GetAccessibleRelationMemberOf();
330 if ( pMemberOf && pMemberOf != pWindow )
332 uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
333 aSequence[0] = pMemberOf->GetAccessible();
334 pRelationSet->AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::MEMBER_OF, aSequence ) );
337 return xRelSet;
342 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ValueSetAcc::getAccessibleStateSet()
343 throw (uno::RuntimeException, std::exception)
345 ThrowIfDisposed();
346 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
348 // Set some states.
349 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
350 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
351 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
352 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
353 if ( !mbIsTransientChildrenDisabled )
354 pStateSet->AddState (accessibility::AccessibleStateType::MANAGES_DESCENDANTS);
355 pStateSet->AddState (accessibility::AccessibleStateType::FOCUSABLE);
356 if (mbIsFocused)
357 pStateSet->AddState (accessibility::AccessibleStateType::FOCUSED);
359 return pStateSet;
364 lang::Locale SAL_CALL ValueSetAcc::getLocale()
365 throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException, std::exception)
367 ThrowIfDisposed();
368 const SolarMutexGuard aSolarGuard;
369 const OUString aEmptyStr;
370 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
371 lang::Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
373 if( xParent.is() )
375 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
377 if( xParentContext.is() )
378 aRet = xParentContext->getLocale ();
381 return aRet;
386 void SAL_CALL ValueSetAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
387 throw (uno::RuntimeException, std::exception)
389 ThrowIfDisposed();
390 ::osl::MutexGuard aGuard (m_aMutex);
392 if( rxListener.is() )
394 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter = mxEventListeners.begin();
395 bool bFound = false;
397 while( !bFound && ( aIter != mxEventListeners.end() ) )
399 if( *aIter == rxListener )
400 bFound = true;
401 else
402 ++aIter;
405 if (!bFound)
406 mxEventListeners.push_back( rxListener );
412 void SAL_CALL ValueSetAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
413 throw (uno::RuntimeException, std::exception)
415 ThrowIfDisposed();
416 ::osl::MutexGuard aGuard (m_aMutex);
418 if( rxListener.is() )
420 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter =
421 std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener);
423 if (aIter != mxEventListeners.end())
424 mxEventListeners.erase(aIter);
430 sal_Bool SAL_CALL ValueSetAcc::containsPoint( const awt::Point& aPoint )
431 throw (uno::RuntimeException, std::exception)
433 ThrowIfDisposed();
434 const awt::Rectangle aRect( getBounds() );
435 const Point aSize( aRect.Width, aRect.Height );
436 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
438 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
443 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessibleAtPoint( const awt::Point& aPoint )
444 throw (uno::RuntimeException, std::exception)
446 ThrowIfDisposed();
447 const SolarMutexGuard aSolarGuard;
448 const sal_uInt16 nItemId = mpParent->GetItemId( Point( aPoint.X, aPoint.Y ) );
449 uno::Reference< accessibility::XAccessible > xRet;
451 if ( nItemId )
453 const size_t nItemPos = mpParent->GetItemPos( nItemId );
455 if( VALUESET_ITEM_NONEITEM != nItemPos )
457 ValueSetItem *const pItem = mpParent->mItemList[nItemPos];
458 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
462 return xRet;
467 awt::Rectangle SAL_CALL ValueSetAcc::getBounds()
468 throw (uno::RuntimeException, std::exception)
470 ThrowIfDisposed();
471 const SolarMutexGuard aSolarGuard;
472 const Point aOutPos( mpParent->GetPosPixel() );
473 const Size aOutSize( mpParent->GetOutputSizePixel() );
474 awt::Rectangle aRet;
476 aRet.X = aOutPos.X();
477 aRet.Y = aOutPos.Y();
478 aRet.Width = aOutSize.Width();
479 aRet.Height = aOutSize.Height();
481 return aRet;
486 awt::Point SAL_CALL ValueSetAcc::getLocation()
487 throw (uno::RuntimeException, std::exception)
489 ThrowIfDisposed();
490 const awt::Rectangle aRect( getBounds() );
491 awt::Point aRet;
493 aRet.X = aRect.X;
494 aRet.Y = aRect.Y;
496 return aRet;
501 awt::Point SAL_CALL ValueSetAcc::getLocationOnScreen()
502 throw (uno::RuntimeException, std::exception)
504 ThrowIfDisposed();
505 const SolarMutexGuard aSolarGuard;
506 const Point aScreenPos( mpParent->OutputToAbsoluteScreenPixel( Point() ) );
507 awt::Point aRet;
509 aRet.X = aScreenPos.X();
510 aRet.Y = aScreenPos.Y();
512 return aRet;
517 awt::Size SAL_CALL ValueSetAcc::getSize()
518 throw (uno::RuntimeException, std::exception)
520 ThrowIfDisposed();
521 const awt::Rectangle aRect( getBounds() );
522 awt::Size aRet;
524 aRet.Width = aRect.Width;
525 aRet.Height = aRect.Height;
527 return aRet;
530 void SAL_CALL ValueSetAcc::grabFocus()
531 throw (uno::RuntimeException, std::exception)
533 ThrowIfDisposed();
534 const SolarMutexGuard aSolarGuard;
535 mpParent->GrabFocus();
538 sal_Int32 SAL_CALL ValueSetAcc::getForeground( )
539 throw (uno::RuntimeException, std::exception)
541 ThrowIfDisposed();
542 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
543 return static_cast<sal_Int32>(nColor);
546 sal_Int32 SAL_CALL ValueSetAcc::getBackground( )
547 throw (uno::RuntimeException, std::exception)
549 ThrowIfDisposed();
550 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
551 return static_cast<sal_Int32>(nColor);
554 void SAL_CALL ValueSetAcc::selectAccessibleChild( sal_Int32 nChildIndex )
555 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
557 ThrowIfDisposed();
558 const SolarMutexGuard aSolarGuard;
559 ValueSetItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
561 if(pItem != NULL)
563 mpParent->SelectItem( pItem->mnId );
564 mpParent->Select ();
566 else
567 throw lang::IndexOutOfBoundsException();
572 sal_Bool SAL_CALL ValueSetAcc::isAccessibleChildSelected( sal_Int32 nChildIndex )
573 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
575 ThrowIfDisposed();
576 const SolarMutexGuard aSolarGuard;
577 ValueSetItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
578 bool bRet = false;
580 if (pItem != NULL)
581 bRet = mpParent->IsItemSelected( pItem->mnId );
582 else
583 throw lang::IndexOutOfBoundsException();
585 return bRet;
590 void SAL_CALL ValueSetAcc::clearAccessibleSelection()
591 throw (uno::RuntimeException, std::exception)
593 ThrowIfDisposed();
594 const SolarMutexGuard aSolarGuard;
595 mpParent->SetNoSelection();
600 void SAL_CALL ValueSetAcc::selectAllAccessibleChildren()
601 throw (uno::RuntimeException, std::exception)
603 ThrowIfDisposed();
604 // unsupported due to single selection only
609 sal_Int32 SAL_CALL ValueSetAcc::getSelectedAccessibleChildCount()
610 throw (uno::RuntimeException, std::exception)
612 ThrowIfDisposed();
613 const SolarMutexGuard aSolarGuard;
614 sal_Int32 nRet = 0;
616 for( sal_uInt16 i = 0, nCount = getItemCount(); i < nCount; i++ )
618 ValueSetItem* pItem = getItem (i);
620 if( pItem && mpParent->IsItemSelected( pItem->mnId ) )
621 ++nRet;
624 return nRet;
629 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
630 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
632 ThrowIfDisposed();
633 const SolarMutexGuard aSolarGuard;
634 uno::Reference< accessibility::XAccessible > xRet;
636 for( sal_uInt16 i = 0, nCount = getItemCount(), nSel = 0; ( i < nCount ) && !xRet.is(); i++ )
638 ValueSetItem* pItem = getItem(i);
640 if( pItem && mpParent->IsItemSelected( pItem->mnId ) && ( nSelectedChildIndex == static_cast< sal_Int32 >( nSel++ ) ) )
641 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
644 return xRet;
649 void SAL_CALL ValueSetAcc::deselectAccessibleChild( sal_Int32 nChildIndex )
650 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
652 ThrowIfDisposed();
653 const SolarMutexGuard aSolarGuard;
654 // Because of the single selection we can reset the whole selection when
655 // the specified child is currently selected.
656 if (isAccessibleChildSelected(nChildIndex))
657 mpParent->SetNoSelection();
662 sal_Int64 SAL_CALL ValueSetAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException, std::exception )
664 sal_Int64 nRet;
666 if( ( rId.getLength() == 16 ) && ( 0 == memcmp( ValueSetAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
667 nRet = reinterpret_cast< sal_Int64 >( this );
668 else
669 nRet = 0;
671 return nRet;
677 void SAL_CALL ValueSetAcc::disposing()
679 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> > aListenerListCopy;
682 // Make a copy of the list and clear the original.
683 const SolarMutexGuard aSolarGuard;
684 ::osl::MutexGuard aGuard (m_aMutex);
685 aListenerListCopy = mxEventListeners;
686 mxEventListeners.clear();
688 // Reset the pointer to the parent. It has to be the one who has
689 // disposed us because he is dying.
690 mpParent = NULL;
693 // Inform all listeners that this objects is disposing.
694 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> >::const_iterator
695 aListenerIterator (aListenerListCopy.begin());
696 lang::EventObject aEvent (static_cast<accessibility::XAccessible*>(this));
697 while (aListenerIterator != aListenerListCopy.end())
701 (*aListenerIterator)->disposing (aEvent);
703 catch(const uno::Exception&)
705 // Ignore exceptions.
708 ++aListenerIterator;
713 sal_uInt16 ValueSetAcc::getItemCount() const
715 sal_uInt16 nCount = mpParent->ImplGetVisibleItemCount();
716 // When the None-Item is visible then increase the number of items by
717 // one.
718 if (HasNoneField())
719 nCount += 1;
720 return nCount;
724 ValueSetItem* ValueSetAcc::getItem (sal_uInt16 nIndex) const
726 ValueSetItem* pItem = NULL;
728 if (HasNoneField())
730 if (nIndex == 0)
731 // When present the first item is the then always visible none field.
732 pItem = mpParent->ImplGetItem (VALUESET_ITEM_NONEITEM);
733 else
734 // Shift down the index to compensate for the none field.
735 nIndex -= 1;
737 if (pItem == NULL)
738 pItem = mpParent->ImplGetItem (static_cast<sal_uInt16>(nIndex));
740 return pItem;
746 void ValueSetAcc::ThrowIfDisposed()
747 throw (::com::sun::star::lang::DisposedException)
749 if (rBHelper.bDisposed || rBHelper.bInDispose)
751 OSL_TRACE ("Calling disposed object. Throwing exception:");
752 throw lang::DisposedException (
753 OUString("object has been already disposed"),
754 static_cast<uno::XWeak*>(this));
756 else
758 DBG_ASSERT (mpParent!=nullptr, "ValueSetAcc not disposed but mpParent == NULL");
762 bool ValueSetAcc::HasNoneField() const
764 assert(mpParent && "ValueSetAcc::HasNoneField called with mpParent==NULL");
765 return ((mpParent->GetStyle() & WB_NONEFIELD) != 0);
768 // - ValueItemAcc -
769 ValueItemAcc::ValueItemAcc( ValueSetItem* pParent, bool bIsTransientChildrenDisabled ) :
770 mpParent( pParent ),
771 mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled )
775 ValueItemAcc::~ValueItemAcc()
779 void ValueItemAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
781 if( nEventId )
783 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners );
784 accessibility::AccessibleEventObject aEvtObject;
786 aEvtObject.EventId = nEventId;
787 aEvtObject.Source = static_cast<uno::XWeak*>(this);
788 aEvtObject.NewValue = rNewValue;
789 aEvtObject.OldValue = rOldValue;
791 for (::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter( aTmpListeners.begin() );
792 aIter != aTmpListeners.end() ; ++aIter)
794 (*aIter)->notifyEvent( aEvtObject );
801 void ValueItemAcc::ParentDestroyed()
803 const ::osl::MutexGuard aGuard( maMutex );
804 mpParent = NULL;
807 namespace
809 class theValueItemAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueItemAccUnoTunnelId > {};
812 const uno::Sequence< sal_Int8 >& ValueItemAcc::getUnoTunnelId()
814 return theValueItemAccUnoTunnelId::get().getSeq();
819 ValueItemAcc* ValueItemAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
820 throw()
824 uno::Reference< lang::XUnoTunnel > xUnoTunnel( rxData, uno::UNO_QUERY );
825 return( xUnoTunnel.is() ? reinterpret_cast<ValueItemAcc*>(sal::static_int_cast<sal_IntPtr>(xUnoTunnel->getSomething( ValueItemAcc::getUnoTunnelId() ))) : NULL );
827 catch(const ::com::sun::star::uno::Exception&)
829 return NULL;
835 uno::Reference< accessibility::XAccessibleContext > SAL_CALL ValueItemAcc::getAccessibleContext()
836 throw (uno::RuntimeException, std::exception)
838 return this;
843 sal_Int32 SAL_CALL ValueItemAcc::getAccessibleChildCount()
844 throw (uno::RuntimeException, std::exception)
846 return 0;
851 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleChild( sal_Int32 )
852 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
854 throw lang::IndexOutOfBoundsException();
859 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleParent()
860 throw (uno::RuntimeException, std::exception)
862 const SolarMutexGuard aSolarGuard;
863 uno::Reference< accessibility::XAccessible > xRet;
865 if( mpParent )
866 xRet = mpParent->mrParent.GetAccessible();
868 return xRet;
873 sal_Int32 SAL_CALL ValueItemAcc::getAccessibleIndexInParent()
874 throw (uno::RuntimeException, std::exception)
876 const SolarMutexGuard aSolarGuard;
877 // The index defaults to -1 to indicate the child does not belong to its
878 // parent.
879 sal_Int32 nIndexInParent = -1;
881 if( mpParent )
883 bool bDone = false;
885 sal_uInt16 nCount = mpParent->mrParent.ImplGetVisibleItemCount();
886 ValueSetItem* pItem;
887 for (sal_uInt16 i=0; i<nCount && !bDone; i++)
889 // Guard the retrieval of the i-th child with a try/catch block
890 // just in case the number of children changes in the mean time.
893 pItem = mpParent->mrParent.ImplGetItem(i);
895 catch (const lang::IndexOutOfBoundsException&)
897 pItem = NULL;
900 // Do not create an accessible object for the test.
901 if (pItem != NULL && pItem->mpxAcc != NULL)
902 if (pItem->GetAccessible( mbIsTransientChildrenDisabled ).get() == this )
904 nIndexInParent = i;
905 bDone = true;
910 //if this valueset contain a none field(common value is default), then we should increase the real index and set the noitem index value equal 0.
911 if ( mpParent && ( (mpParent->mrParent.GetStyle() & WB_NONEFIELD) != 0 ) )
913 ValueSetItem* pFirstItem = mpParent->mrParent.ImplGetItem (VALUESET_ITEM_NONEITEM);
914 if( pFirstItem && pFirstItem ->GetAccessible(mbIsTransientChildrenDisabled).get() == this )
915 nIndexInParent = 0;
916 else
917 nIndexInParent++;
919 return nIndexInParent;
924 sal_Int16 SAL_CALL ValueItemAcc::getAccessibleRole()
925 throw (uno::RuntimeException, std::exception)
927 return accessibility::AccessibleRole::LIST_ITEM;
932 OUString SAL_CALL ValueItemAcc::getAccessibleDescription()
933 throw (uno::RuntimeException, std::exception)
935 return OUString();
940 OUString SAL_CALL ValueItemAcc::getAccessibleName()
941 throw (uno::RuntimeException, std::exception)
943 const SolarMutexGuard aSolarGuard;
944 OUString aRet;
946 if( mpParent )
948 aRet = mpParent->maText;
950 if( aRet.isEmpty() )
952 OUStringBuffer aBuffer("Item ");
953 aBuffer.append(static_cast<sal_Int32>(mpParent->mnId));
954 aRet = aBuffer.makeStringAndClear();
958 return aRet;
963 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ValueItemAcc::getAccessibleRelationSet()
964 throw (uno::RuntimeException, std::exception)
966 return uno::Reference< accessibility::XAccessibleRelationSet >();
971 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ValueItemAcc::getAccessibleStateSet()
972 throw (uno::RuntimeException, std::exception)
974 const SolarMutexGuard aSolarGuard;
975 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
977 if( mpParent )
979 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
980 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
981 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
982 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
983 if ( !mbIsTransientChildrenDisabled )
984 pStateSet->AddState (accessibility::AccessibleStateType::TRANSIENT);
986 // SELECTABLE
987 pStateSet->AddState( accessibility::AccessibleStateType::SELECTABLE );
988 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
990 // SELECTED
991 if( mpParent->mrParent.GetSelectItemId() == mpParent->mnId )
993 pStateSet->AddState( accessibility::AccessibleStateType::SELECTED );
994 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
998 return pStateSet;
1003 lang::Locale SAL_CALL ValueItemAcc::getLocale()
1004 throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException, std::exception)
1006 const SolarMutexGuard aSolarGuard;
1007 const OUString aEmptyStr;
1008 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
1009 lang::Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
1011 if( xParent.is() )
1013 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
1015 if( xParentContext.is() )
1016 aRet = xParentContext->getLocale();
1019 return aRet;
1024 void SAL_CALL ValueItemAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
1025 throw (uno::RuntimeException, std::exception)
1027 const ::osl::MutexGuard aGuard( maMutex );
1029 if( rxListener.is() )
1031 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter = mxEventListeners.begin();
1032 bool bFound = false;
1034 while( !bFound && ( aIter != mxEventListeners.end() ) )
1036 if( *aIter == rxListener )
1037 bFound = true;
1038 else
1039 ++aIter;
1042 if (!bFound)
1043 mxEventListeners.push_back( rxListener );
1049 void SAL_CALL ValueItemAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
1050 throw (uno::RuntimeException, std::exception)
1052 const ::osl::MutexGuard aGuard( maMutex );
1054 if( rxListener.is() )
1056 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter =
1057 std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener);
1059 if (aIter != mxEventListeners.end())
1060 mxEventListeners.erase(aIter);
1066 sal_Bool SAL_CALL ValueItemAcc::containsPoint( const awt::Point& aPoint )
1067 throw (uno::RuntimeException, std::exception)
1069 const awt::Rectangle aRect( getBounds() );
1070 const Point aSize( aRect.Width, aRect.Height );
1071 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
1073 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
1076 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleAtPoint( const awt::Point& )
1077 throw (uno::RuntimeException, std::exception)
1079 uno::Reference< accessibility::XAccessible > xRet;
1080 return xRet;
1083 awt::Rectangle SAL_CALL ValueItemAcc::getBounds()
1084 throw (uno::RuntimeException, std::exception)
1086 const SolarMutexGuard aSolarGuard;
1087 awt::Rectangle aRet;
1089 if( mpParent )
1091 Rectangle aRect( mpParent->mrParent.GetItemRect(mpParent->mnId) );
1092 Point aOrigin;
1093 Rectangle aParentRect( aOrigin, mpParent->mrParent.GetOutputSizePixel() );
1095 aRect.Intersection( aParentRect );
1097 aRet.X = aRect.Left();
1098 aRet.Y = aRect.Top();
1099 aRet.Width = aRect.GetWidth();
1100 aRet.Height = aRect.GetHeight();
1103 return aRet;
1106 awt::Point SAL_CALL ValueItemAcc::getLocation()
1107 throw (uno::RuntimeException, std::exception)
1109 const awt::Rectangle aRect( getBounds() );
1110 awt::Point aRet;
1112 aRet.X = aRect.X;
1113 aRet.Y = aRect.Y;
1115 return aRet;
1118 awt::Point SAL_CALL ValueItemAcc::getLocationOnScreen()
1119 throw (uno::RuntimeException, std::exception)
1121 const SolarMutexGuard aSolarGuard;
1122 awt::Point aRet;
1124 if( mpParent )
1126 const Point aPos = mpParent->mrParent.GetItemRect(mpParent->mnId).TopLeft();
1127 const Point aScreenPos( mpParent->mrParent.OutputToAbsoluteScreenPixel( aPos ) );
1129 aRet.X = aScreenPos.X();
1130 aRet.Y = aScreenPos.Y();
1133 return aRet;
1136 awt::Size SAL_CALL ValueItemAcc::getSize()
1137 throw (uno::RuntimeException, std::exception)
1139 const awt::Rectangle aRect( getBounds() );
1140 awt::Size aRet;
1142 aRet.Width = aRect.Width;
1143 aRet.Height = aRect.Height;
1145 return aRet;
1148 void SAL_CALL ValueItemAcc::grabFocus()
1149 throw (uno::RuntimeException, std::exception)
1151 // nothing to do
1154 sal_Int32 SAL_CALL ValueItemAcc::getForeground( )
1155 throw (uno::RuntimeException, std::exception)
1157 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
1158 return static_cast<sal_Int32>(nColor);
1161 sal_Int32 SAL_CALL ValueItemAcc::getBackground( )
1162 throw (uno::RuntimeException, std::exception)
1164 sal_uInt32 nColor;
1165 if (mpParent && mpParent->meType == VALUESETITEM_COLOR)
1166 nColor = mpParent->maColor.GetColor();
1167 else
1168 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
1169 return static_cast<sal_Int32>(nColor);
1172 sal_Int64 SAL_CALL ValueItemAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException, std::exception )
1174 sal_Int64 nRet;
1176 if( ( rId.getLength() == 16 ) && ( 0 == memcmp( ValueItemAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
1177 nRet = reinterpret_cast< sal_Int64 >( this );
1178 else
1179 nRet = 0;
1181 return nRet;
1184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */