update credits
[LibreOffice.git] / svtools / source / control / valueacc.cxx
blob1bef13a9a1efd9f071c6bc4723d6a115cde4519d
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 <svtools/valueset.hxx>
23 #include "valueimp.hxx"
24 #include <comphelper/servicehelper.hxx>
25 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
26 #include <com/sun/star/accessibility/AccessibleRole.hpp>
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
29 using namespace ::com::sun::star;
31 // ----------------
32 // - ValueSetItem -
33 // ----------------
35 ValueSetItem::ValueSetItem( ValueSet& rParent )
36 : mrParent(rParent)
37 , mnId(0)
38 , meType(VALUESETITEM_NONE)
39 , mbVisible(true)
40 , mpData(NULL)
41 , mpxAcc(NULL)
45 // -----------------------------------------------------------------------
47 ValueSetItem::~ValueSetItem()
49 if( mpxAcc )
51 static_cast< ValueItemAcc* >( mpxAcc->get() )->ParentDestroyed();
52 delete mpxAcc;
56 // -----------------------------------------------------------------------
58 uno::Reference< accessibility::XAccessible > ValueSetItem::GetAccessible( bool bIsTransientChildrenDisabled )
60 if( !mpxAcc )
61 mpxAcc = new uno::Reference< accessibility::XAccessible >( new ValueItemAcc( this, bIsTransientChildrenDisabled ) );
63 return *mpxAcc;
66 // ---------------
67 // - ValueSetAcc -
68 // ---------------
70 ValueSetAcc::ValueSetAcc( ValueSet* pParent, bool bIsTransientChildrenDisabled ) :
71 ValueSetAccComponentBase (m_aMutex),
72 mpParent( pParent ),
73 mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled ),
74 mbIsFocused(false)
78 // -----------------------------------------------------------------------------
80 ValueSetAcc::~ValueSetAcc()
84 // -----------------------------------------------------------------------
86 void ValueSetAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
88 if( nEventId )
90 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners );
91 accessibility::AccessibleEventObject aEvtObject;
93 aEvtObject.EventId = nEventId;
94 aEvtObject.Source = static_cast<uno::XWeak*>(this);
95 aEvtObject.NewValue = rNewValue;
96 aEvtObject.OldValue = rOldValue;
98 for (::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter( aTmpListeners.begin() );
99 aIter != aTmpListeners.end() ; ++aIter)
103 (*aIter)->notifyEvent( aEvtObject );
105 catch(const uno::Exception&)
112 namespace
114 class theValueSetAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueSetAccUnoTunnelId > {};
117 const uno::Sequence< sal_Int8 >& ValueSetAcc::getUnoTunnelId()
119 return theValueSetAccUnoTunnelId::get().getSeq();
122 // -----------------------------------------------------------------------------
124 ValueSetAcc* ValueSetAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
125 throw()
129 uno::Reference< lang::XUnoTunnel > xUnoTunnel( rxData, uno::UNO_QUERY );
130 return( xUnoTunnel.is() ? reinterpret_cast<ValueSetAcc*>(sal::static_int_cast<sal_IntPtr>(xUnoTunnel->getSomething( ValueSetAcc::getUnoTunnelId() ))) : NULL );
132 catch(const ::com::sun::star::uno::Exception&)
134 return NULL;
139 // -----------------------------------------------------------------------------
141 void ValueSetAcc::GetFocus (void)
143 mbIsFocused = true;
145 // Boradcast the state change.
146 ::com::sun::star::uno::Any aOldState, aNewState;
147 aNewState <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
148 FireAccessibleEvent(
149 ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED,
150 aOldState, aNewState);
153 // -----------------------------------------------------------------------------
155 void ValueSetAcc::LoseFocus (void)
157 mbIsFocused = false;
159 // Boradcast the state change.
160 ::com::sun::star::uno::Any aOldState, aNewState;
161 aOldState <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
162 FireAccessibleEvent(
163 ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED,
164 aOldState, aNewState);
167 // -----------------------------------------------------------------------------
169 uno::Reference< accessibility::XAccessibleContext > SAL_CALL ValueSetAcc::getAccessibleContext()
170 throw (uno::RuntimeException)
172 ThrowIfDisposed();
173 return this;
176 // -----------------------------------------------------------------------------
178 sal_Int32 SAL_CALL ValueSetAcc::getAccessibleChildCount()
179 throw (uno::RuntimeException)
181 const SolarMutexGuard aSolarGuard;
182 ThrowIfDisposed();
184 sal_Int32 nCount = mpParent->ImplGetVisibleItemCount();
185 if (HasNoneField())
186 nCount += 1;
187 return nCount;
190 // -----------------------------------------------------------------------------
192 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessibleChild( sal_Int32 i )
193 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
195 ThrowIfDisposed();
196 const SolarMutexGuard aSolarGuard;
197 uno::Reference< accessibility::XAccessible > xRet;
198 ValueSetItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(i));
200 if( pItem )
201 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
202 else
203 throw lang::IndexOutOfBoundsException();
205 return xRet;
208 // -----------------------------------------------------------------------------
210 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessibleParent()
211 throw (uno::RuntimeException)
213 ThrowIfDisposed();
214 const SolarMutexGuard aSolarGuard;
215 Window* pParent = mpParent->GetParent();
216 uno::Reference< accessibility::XAccessible > xRet;
218 if( pParent )
219 xRet = pParent->GetAccessible();
221 return xRet;
224 // -----------------------------------------------------------------------------
226 sal_Int32 SAL_CALL ValueSetAcc::getAccessibleIndexInParent()
227 throw (uno::RuntimeException)
229 ThrowIfDisposed();
230 const SolarMutexGuard aSolarGuard;
231 Window* pParent = mpParent->GetParent();
232 sal_Int32 nRet = 0;
234 if( pParent )
236 sal_Bool bFound = sal_False;
238 for( sal_uInt16 i = 0, nCount = pParent->GetChildCount(); ( i < nCount ) && !bFound; i++ )
240 if( pParent->GetChild( i ) == mpParent )
242 nRet = i;
243 bFound = sal_True;
248 return nRet;
251 // -----------------------------------------------------------------------------
253 sal_Int16 SAL_CALL ValueSetAcc::getAccessibleRole()
254 throw (uno::RuntimeException)
256 ThrowIfDisposed();
257 // #i73746# As the Java Access Bridge (v 2.0.1) uses "managesDescendants"
258 // always if the role is LIST, we need a different role in this case
259 return (mbIsTransientChildrenDisabled
260 ? accessibility::AccessibleRole::PANEL
261 : accessibility::AccessibleRole::LIST );
264 // -----------------------------------------------------------------------------
266 OUString SAL_CALL ValueSetAcc::getAccessibleDescription()
267 throw (uno::RuntimeException)
269 ThrowIfDisposed();
270 const SolarMutexGuard aSolarGuard;
271 String aRet( RTL_CONSTASCII_USTRINGPARAM( "ValueSet" ) );
273 return aRet;
276 // -----------------------------------------------------------------------------
278 OUString SAL_CALL ValueSetAcc::getAccessibleName()
279 throw (uno::RuntimeException)
281 ThrowIfDisposed();
282 const SolarMutexGuard aSolarGuard;
283 String aRet;
285 if ( mpParent )
286 aRet = mpParent->GetAccessibleName();
288 if ( !aRet.Len() )
290 Window* pLabel = mpParent->GetAccessibleRelationLabeledBy();
291 if ( pLabel && pLabel != mpParent )
292 aRet = OutputDevice::GetNonMnemonicString( pLabel->GetText() );
295 return aRet;
298 // -----------------------------------------------------------------------------
300 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ValueSetAcc::getAccessibleRelationSet()
301 throw (uno::RuntimeException)
303 ThrowIfDisposed();
304 return uno::Reference< accessibility::XAccessibleRelationSet >();
307 // -----------------------------------------------------------------------------
309 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ValueSetAcc::getAccessibleStateSet()
310 throw (uno::RuntimeException)
312 ThrowIfDisposed();
313 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
315 // Set some states.
316 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
317 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
318 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
319 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
320 if ( !mbIsTransientChildrenDisabled )
321 pStateSet->AddState (accessibility::AccessibleStateType::MANAGES_DESCENDANTS);
322 pStateSet->AddState (accessibility::AccessibleStateType::FOCUSABLE);
323 if (mbIsFocused)
324 pStateSet->AddState (accessibility::AccessibleStateType::FOCUSED);
326 return pStateSet;
329 // -----------------------------------------------------------------------------
331 lang::Locale SAL_CALL ValueSetAcc::getLocale()
332 throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException)
334 ThrowIfDisposed();
335 const SolarMutexGuard aSolarGuard;
336 const OUString aEmptyStr;
337 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
338 lang::Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
340 if( xParent.is() )
342 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
344 if( xParentContext.is() )
345 aRet = xParentContext->getLocale ();
348 return aRet;
351 // -----------------------------------------------------------------------------
353 void SAL_CALL ValueSetAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
354 throw (uno::RuntimeException)
356 ThrowIfDisposed();
357 ::osl::MutexGuard aGuard (m_aMutex);
359 if( rxListener.is() )
361 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter = mxEventListeners.begin();
362 sal_Bool bFound = sal_False;
364 while( !bFound && ( aIter != mxEventListeners.end() ) )
366 if( *aIter == rxListener )
367 bFound = sal_True;
368 else
369 ++aIter;
372 if (!bFound)
373 mxEventListeners.push_back( rxListener );
377 // -----------------------------------------------------------------------------
379 void SAL_CALL ValueSetAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
380 throw (uno::RuntimeException)
382 ThrowIfDisposed();
383 ::osl::MutexGuard aGuard (m_aMutex);
385 if( rxListener.is() )
387 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter = mxEventListeners.begin();
388 sal_Bool bFound = sal_False;
390 while( !bFound && ( aIter != mxEventListeners.end() ) )
392 if( *aIter == rxListener )
394 mxEventListeners.erase( aIter );
395 bFound = sal_True;
397 else
398 ++aIter;
403 // -----------------------------------------------------------------------------
405 sal_Bool SAL_CALL ValueSetAcc::containsPoint( const awt::Point& aPoint )
406 throw (uno::RuntimeException)
408 ThrowIfDisposed();
409 const awt::Rectangle aRect( getBounds() );
410 const Point aSize( aRect.Width, aRect.Height );
411 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
413 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
416 // -----------------------------------------------------------------------------
418 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessibleAtPoint( const awt::Point& aPoint )
419 throw (uno::RuntimeException)
421 ThrowIfDisposed();
422 const SolarMutexGuard aSolarGuard;
423 const sal_uInt16 nItemId = mpParent->GetItemId( Point( aPoint.X, aPoint.Y ) );
424 uno::Reference< accessibility::XAccessible > xRet;
426 if ( nItemId )
428 const size_t nItemPos = mpParent->GetItemPos( nItemId );
430 if( VALUESET_ITEM_NONEITEM != nItemPos )
432 ValueSetItem *const pItem = mpParent->mItemList[nItemPos];
433 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
437 return xRet;
440 // -----------------------------------------------------------------------------
442 awt::Rectangle SAL_CALL ValueSetAcc::getBounds()
443 throw (uno::RuntimeException)
445 ThrowIfDisposed();
446 const SolarMutexGuard aSolarGuard;
447 const Point aOutPos( mpParent->GetPosPixel() );
448 const Size aOutSize( mpParent->GetOutputSizePixel() );
449 awt::Rectangle aRet;
451 aRet.X = aOutPos.X();
452 aRet.Y = aOutPos.Y();
453 aRet.Width = aOutSize.Width();
454 aRet.Height = aOutSize.Height();
456 return aRet;
459 // -----------------------------------------------------------------------------
461 awt::Point SAL_CALL ValueSetAcc::getLocation()
462 throw (uno::RuntimeException)
464 ThrowIfDisposed();
465 const awt::Rectangle aRect( getBounds() );
466 awt::Point aRet;
468 aRet.X = aRect.X;
469 aRet.Y = aRect.Y;
471 return aRet;
474 // -----------------------------------------------------------------------------
476 awt::Point SAL_CALL ValueSetAcc::getLocationOnScreen()
477 throw (uno::RuntimeException)
479 ThrowIfDisposed();
480 const SolarMutexGuard aSolarGuard;
481 const Point aScreenPos( mpParent->OutputToAbsoluteScreenPixel( Point() ) );
482 awt::Point aRet;
484 aRet.X = aScreenPos.X();
485 aRet.Y = aScreenPos.Y();
487 return aRet;
490 // -----------------------------------------------------------------------------
492 awt::Size SAL_CALL ValueSetAcc::getSize()
493 throw (uno::RuntimeException)
495 ThrowIfDisposed();
496 const awt::Rectangle aRect( getBounds() );
497 awt::Size aRet;
499 aRet.Width = aRect.Width;
500 aRet.Height = aRect.Height;
502 return aRet;
505 // -----------------------------------------------------------------------------
507 void SAL_CALL ValueSetAcc::grabFocus()
508 throw (uno::RuntimeException)
510 ThrowIfDisposed();
511 const SolarMutexGuard aSolarGuard;
512 mpParent->GrabFocus();
515 // -----------------------------------------------------------------------------
517 uno::Any SAL_CALL ValueSetAcc::getAccessibleKeyBinding()
518 throw (uno::RuntimeException)
520 ThrowIfDisposed();
521 return uno::Any();
524 // -----------------------------------------------------------------------------
526 sal_Int32 SAL_CALL ValueSetAcc::getForeground( )
527 throw (uno::RuntimeException)
529 ThrowIfDisposed();
530 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
531 return static_cast<sal_Int32>(nColor);
534 // -----------------------------------------------------------------------------
536 sal_Int32 SAL_CALL ValueSetAcc::getBackground( )
537 throw (uno::RuntimeException)
539 ThrowIfDisposed();
540 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
541 return static_cast<sal_Int32>(nColor);
544 // -----------------------------------------------------------------------------
546 void SAL_CALL ValueSetAcc::selectAccessibleChild( sal_Int32 nChildIndex )
547 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
549 ThrowIfDisposed();
550 const SolarMutexGuard aSolarGuard;
551 ValueSetItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
553 if(pItem != NULL)
555 mpParent->SelectItem( pItem->mnId );
556 mpParent->Select ();
558 else
559 throw lang::IndexOutOfBoundsException();
562 // -----------------------------------------------------------------------------
564 sal_Bool SAL_CALL ValueSetAcc::isAccessibleChildSelected( sal_Int32 nChildIndex )
565 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
567 ThrowIfDisposed();
568 const SolarMutexGuard aSolarGuard;
569 ValueSetItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
570 sal_Bool bRet = sal_False;
572 if (pItem != NULL)
573 bRet = mpParent->IsItemSelected( pItem->mnId );
574 else
575 throw lang::IndexOutOfBoundsException();
577 return bRet;
580 // -----------------------------------------------------------------------------
582 void SAL_CALL ValueSetAcc::clearAccessibleSelection()
583 throw (uno::RuntimeException)
585 ThrowIfDisposed();
586 const SolarMutexGuard aSolarGuard;
587 mpParent->SetNoSelection();
590 // -----------------------------------------------------------------------------
592 void SAL_CALL ValueSetAcc::selectAllAccessibleChildren()
593 throw (uno::RuntimeException)
595 ThrowIfDisposed();
596 // unsupported due to single selection only
599 // -----------------------------------------------------------------------------
601 sal_Int32 SAL_CALL ValueSetAcc::getSelectedAccessibleChildCount()
602 throw (uno::RuntimeException)
604 ThrowIfDisposed();
605 const SolarMutexGuard aSolarGuard;
606 sal_Int32 nRet = 0;
608 for( sal_uInt16 i = 0, nCount = getItemCount(); i < nCount; i++ )
610 ValueSetItem* pItem = getItem (i);
612 if( pItem && mpParent->IsItemSelected( pItem->mnId ) )
613 ++nRet;
616 return nRet;
619 // -----------------------------------------------------------------------------
621 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
622 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
624 ThrowIfDisposed();
625 const SolarMutexGuard aSolarGuard;
626 uno::Reference< accessibility::XAccessible > xRet;
628 for( sal_uInt16 i = 0, nCount = getItemCount(), nSel = 0; ( i < nCount ) && !xRet.is(); i++ )
630 ValueSetItem* pItem = getItem(i);
632 if( pItem && mpParent->IsItemSelected( pItem->mnId ) && ( nSelectedChildIndex == static_cast< sal_Int32 >( nSel++ ) ) )
633 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
636 return xRet;
639 // -----------------------------------------------------------------------------
641 void SAL_CALL ValueSetAcc::deselectAccessibleChild( sal_Int32 nChildIndex )
642 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
644 ThrowIfDisposed();
645 const SolarMutexGuard aSolarGuard;
646 // Because of the single selection we can reset the whole selection when
647 // the specified child is currently selected.
648 if (isAccessibleChildSelected(nChildIndex))
649 mpParent->SetNoSelection();
652 // -----------------------------------------------------------------------------
654 sal_Int64 SAL_CALL ValueSetAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException )
656 sal_Int64 nRet;
658 if( ( rId.getLength() == 16 ) && ( 0 == memcmp( ValueSetAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
659 nRet = reinterpret_cast< sal_Int64 >( this );
660 else
661 nRet = 0;
663 return nRet;
669 void SAL_CALL ValueSetAcc::disposing (void)
671 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> > aListenerListCopy;
674 // Make a copy of the list and clear the original.
675 const SolarMutexGuard aSolarGuard;
676 ::osl::MutexGuard aGuard (m_aMutex);
677 aListenerListCopy = mxEventListeners;
678 mxEventListeners.clear();
680 // Reset the pointer to the parent. It has to be the one who has
681 // disposed us because he is dying.
682 mpParent = NULL;
685 // Inform all listeners that this objects is disposing.
686 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> >::const_iterator
687 aListenerIterator (aListenerListCopy.begin());
688 lang::EventObject aEvent (static_cast<accessibility::XAccessible*>(this));
689 while (aListenerIterator != aListenerListCopy.end())
693 (*aListenerIterator)->disposing (aEvent);
695 catch(const uno::Exception&)
697 // Ignore exceptions.
700 ++aListenerIterator;
705 sal_uInt16 ValueSetAcc::getItemCount (void) const
707 sal_uInt16 nCount = mpParent->ImplGetVisibleItemCount();
708 // When the None-Item is visible then increase the number of items by
709 // one.
710 if (HasNoneField())
711 nCount += 1;
712 return nCount;
716 ValueSetItem* ValueSetAcc::getItem (sal_uInt16 nIndex) const
718 ValueSetItem* pItem = NULL;
720 if (HasNoneField())
722 if (nIndex == 0)
723 // When present the first item is the then always visible none field.
724 pItem = mpParent->ImplGetItem (VALUESET_ITEM_NONEITEM);
725 else
726 // Shift down the index to compensate for the none field.
727 nIndex -= 1;
729 if (pItem == NULL)
730 pItem = mpParent->ImplGetVisibleItem (static_cast<sal_uInt16>(nIndex));
732 return pItem;
738 void ValueSetAcc::ThrowIfDisposed (void)
739 throw (::com::sun::star::lang::DisposedException)
741 if (rBHelper.bDisposed || rBHelper.bInDispose)
743 OSL_TRACE ("Calling disposed object. Throwing exception:");
744 throw lang::DisposedException (
745 OUString("object has been already disposed"),
746 static_cast<uno::XWeak*>(this));
748 else
750 DBG_ASSERT (mpParent!=NULL, "ValueSetAcc not disposed but mpParent == NULL");
756 bool ValueSetAcc::HasNoneField (void) const
758 DBG_ASSERT (mpParent!=NULL, "ValueSetAcc::HasNoneField called with mpParent==NULL");
759 return ((mpParent->GetStyle() & WB_NONEFIELD) != 0);
765 // ----------------
766 // - ValueItemAcc -
767 // ----------------
769 ValueItemAcc::ValueItemAcc( ValueSetItem* pParent, bool bIsTransientChildrenDisabled ) :
770 mpParent( pParent ),
771 mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled )
775 // -----------------------------------------------------------------------------
777 ValueItemAcc::~ValueItemAcc()
781 // -----------------------------------------------------------------------
783 void ValueItemAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
785 if( nEventId )
787 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners );
788 accessibility::AccessibleEventObject aEvtObject;
790 aEvtObject.EventId = nEventId;
791 aEvtObject.Source = static_cast<uno::XWeak*>(this);
792 aEvtObject.NewValue = rNewValue;
793 aEvtObject.OldValue = rOldValue;
795 for (::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter( aTmpListeners.begin() );
796 aIter != aTmpListeners.end() ; ++aIter)
798 (*aIter)->notifyEvent( aEvtObject );
803 // -----------------------------------------------------------------------------
805 void ValueItemAcc::ParentDestroyed()
807 const ::osl::MutexGuard aGuard( maMutex );
808 mpParent = NULL;
811 namespace
813 class theValueItemAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueItemAccUnoTunnelId > {};
816 const uno::Sequence< sal_Int8 >& ValueItemAcc::getUnoTunnelId()
818 return theValueItemAccUnoTunnelId::get().getSeq();
821 // -----------------------------------------------------------------------------
823 ValueItemAcc* ValueItemAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
824 throw()
828 uno::Reference< lang::XUnoTunnel > xUnoTunnel( rxData, uno::UNO_QUERY );
829 return( xUnoTunnel.is() ? reinterpret_cast<ValueItemAcc*>(sal::static_int_cast<sal_IntPtr>(xUnoTunnel->getSomething( ValueItemAcc::getUnoTunnelId() ))) : NULL );
831 catch(const ::com::sun::star::uno::Exception&)
833 return NULL;
837 // -----------------------------------------------------------------------------
839 uno::Reference< accessibility::XAccessibleContext > SAL_CALL ValueItemAcc::getAccessibleContext()
840 throw (uno::RuntimeException)
842 return this;
845 // -----------------------------------------------------------------------------
847 sal_Int32 SAL_CALL ValueItemAcc::getAccessibleChildCount()
848 throw (uno::RuntimeException)
850 return 0;
853 // -----------------------------------------------------------------------------
855 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleChild( sal_Int32 )
856 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
858 throw lang::IndexOutOfBoundsException();
861 // -----------------------------------------------------------------------------
863 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleParent()
864 throw (uno::RuntimeException)
866 const SolarMutexGuard aSolarGuard;
867 uno::Reference< accessibility::XAccessible > xRet;
869 if( mpParent )
870 xRet = mpParent->mrParent.GetAccessible();
872 return xRet;
875 // -----------------------------------------------------------------------------
877 sal_Int32 SAL_CALL ValueItemAcc::getAccessibleIndexInParent()
878 throw (uno::RuntimeException)
880 const SolarMutexGuard aSolarGuard;
881 // The index defaults to -1 to indicate the child does not belong to its
882 // parent.
883 sal_Int32 nIndexInParent = -1;
885 if( mpParent )
887 bool bDone = false;
889 sal_uInt16 nCount = mpParent->mrParent.ImplGetVisibleItemCount();
890 ValueSetItem* pItem;
891 for (sal_uInt16 i=0; i<nCount && !bDone; i++)
893 // Guard the retrieval of the i-th child with a try/catch block
894 // just in case the number of children changes in the mean time.
897 pItem = mpParent->mrParent.ImplGetVisibleItem (i);
899 catch (const lang::IndexOutOfBoundsException&)
901 pItem = NULL;
904 // Do not create an accessible object for the test.
905 if (pItem != NULL && pItem->mpxAcc != NULL)
906 if (pItem->GetAccessible( mbIsTransientChildrenDisabled ).get() == this )
908 nIndexInParent = i;
909 bDone = true;
914 return nIndexInParent;
917 // -----------------------------------------------------------------------------
919 sal_Int16 SAL_CALL ValueItemAcc::getAccessibleRole()
920 throw (uno::RuntimeException)
922 return accessibility::AccessibleRole::LIST_ITEM;
925 // -----------------------------------------------------------------------------
927 OUString SAL_CALL ValueItemAcc::getAccessibleDescription()
928 throw (uno::RuntimeException)
930 return OUString();
933 // -----------------------------------------------------------------------------
935 OUString SAL_CALL ValueItemAcc::getAccessibleName()
936 throw (uno::RuntimeException)
938 const SolarMutexGuard aSolarGuard;
939 OUString aRet;
941 if( mpParent )
943 aRet = mpParent->maText;
945 if( aRet.isEmpty() )
947 OUStringBuffer aBuffer("Item ");
948 aBuffer.append(static_cast<sal_Int32>(mpParent->mnId));
949 aRet = aBuffer.makeStringAndClear();
953 return aRet;
956 // -----------------------------------------------------------------------------
958 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ValueItemAcc::getAccessibleRelationSet()
959 throw (uno::RuntimeException)
961 return uno::Reference< accessibility::XAccessibleRelationSet >();
964 // -----------------------------------------------------------------------------
966 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ValueItemAcc::getAccessibleStateSet()
967 throw (uno::RuntimeException)
969 const SolarMutexGuard aSolarGuard;
970 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
972 if( mpParent )
974 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
975 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
976 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
977 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
978 if ( !mbIsTransientChildrenDisabled )
979 pStateSet->AddState (accessibility::AccessibleStateType::TRANSIENT);
981 // SELECTABLE
982 pStateSet->AddState( accessibility::AccessibleStateType::SELECTABLE );
983 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
985 // SELECTED
986 if( mpParent->mrParent.GetSelectItemId() == mpParent->mnId )
988 pStateSet->AddState( accessibility::AccessibleStateType::SELECTED );
989 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
993 return pStateSet;
996 // -----------------------------------------------------------------------------
998 lang::Locale SAL_CALL ValueItemAcc::getLocale()
999 throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException)
1001 const SolarMutexGuard aSolarGuard;
1002 const OUString aEmptyStr;
1003 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
1004 lang::Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
1006 if( xParent.is() )
1008 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
1010 if( xParentContext.is() )
1011 aRet = xParentContext->getLocale();
1014 return aRet;
1017 // -----------------------------------------------------------------------------
1019 void SAL_CALL ValueItemAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
1020 throw (uno::RuntimeException)
1022 const ::osl::MutexGuard aGuard( maMutex );
1024 if( rxListener.is() )
1026 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter = mxEventListeners.begin();
1027 sal_Bool bFound = sal_False;
1029 while( !bFound && ( aIter != mxEventListeners.end() ) )
1031 if( *aIter == rxListener )
1032 bFound = sal_True;
1033 else
1034 ++aIter;
1037 if (!bFound)
1038 mxEventListeners.push_back( rxListener );
1042 // -----------------------------------------------------------------------------
1044 void SAL_CALL ValueItemAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
1045 throw (uno::RuntimeException)
1047 const ::osl::MutexGuard aGuard( maMutex );
1049 if( rxListener.is() )
1051 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter = mxEventListeners.begin();
1052 sal_Bool bFound = sal_False;
1054 while( !bFound && ( aIter != mxEventListeners.end() ) )
1056 if( *aIter == rxListener )
1058 mxEventListeners.erase( aIter );
1059 bFound = sal_True;
1061 else
1062 ++aIter;
1067 // -----------------------------------------------------------------------------
1069 sal_Bool SAL_CALL ValueItemAcc::containsPoint( const awt::Point& aPoint )
1070 throw (uno::RuntimeException)
1072 const awt::Rectangle aRect( getBounds() );
1073 const Point aSize( aRect.Width, aRect.Height );
1074 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
1076 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
1079 // -----------------------------------------------------------------------------
1081 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleAtPoint( const awt::Point& )
1082 throw (uno::RuntimeException)
1084 uno::Reference< accessibility::XAccessible > xRet;
1085 return xRet;
1088 // -----------------------------------------------------------------------------
1090 awt::Rectangle SAL_CALL ValueItemAcc::getBounds()
1091 throw (uno::RuntimeException)
1093 const SolarMutexGuard aSolarGuard;
1094 awt::Rectangle aRet;
1096 if( mpParent )
1098 Rectangle aRect( mpParent->mrParent.GetItemRect(mpParent->mnId) );
1099 Point aOrigin;
1100 Rectangle aParentRect( aOrigin, mpParent->mrParent.GetOutputSizePixel() );
1102 aRect.Intersection( aParentRect );
1104 aRet.X = aRect.Left();
1105 aRet.Y = aRect.Top();
1106 aRet.Width = aRect.GetWidth();
1107 aRet.Height = aRect.GetHeight();
1110 return aRet;
1113 // -----------------------------------------------------------------------------
1115 awt::Point SAL_CALL ValueItemAcc::getLocation()
1116 throw (uno::RuntimeException)
1118 const awt::Rectangle aRect( getBounds() );
1119 awt::Point aRet;
1121 aRet.X = aRect.X;
1122 aRet.Y = aRect.Y;
1124 return aRet;
1127 // -----------------------------------------------------------------------------
1129 awt::Point SAL_CALL ValueItemAcc::getLocationOnScreen()
1130 throw (uno::RuntimeException)
1132 const SolarMutexGuard aSolarGuard;
1133 awt::Point aRet;
1135 if( mpParent )
1137 const Point aPos = mpParent->mrParent.GetItemRect(mpParent->mnId).TopLeft();
1138 const Point aScreenPos( mpParent->mrParent.OutputToAbsoluteScreenPixel( aPos ) );
1140 aRet.X = aScreenPos.X();
1141 aRet.Y = aScreenPos.Y();
1144 return aRet;
1147 // -----------------------------------------------------------------------------
1149 awt::Size SAL_CALL ValueItemAcc::getSize()
1150 throw (uno::RuntimeException)
1152 const awt::Rectangle aRect( getBounds() );
1153 awt::Size aRet;
1155 aRet.Width = aRect.Width;
1156 aRet.Height = aRect.Height;
1158 return aRet;
1161 // -----------------------------------------------------------------------------
1163 void SAL_CALL ValueItemAcc::grabFocus()
1164 throw (uno::RuntimeException)
1166 // nothing to do
1169 // -----------------------------------------------------------------------------
1171 uno::Any SAL_CALL ValueItemAcc::getAccessibleKeyBinding()
1172 throw (uno::RuntimeException)
1174 return uno::Any();
1177 // -----------------------------------------------------------------------------
1179 sal_Int32 SAL_CALL ValueItemAcc::getForeground( )
1180 throw (uno::RuntimeException)
1182 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
1183 return static_cast<sal_Int32>(nColor);
1186 // -----------------------------------------------------------------------------
1188 sal_Int32 SAL_CALL ValueItemAcc::getBackground( )
1189 throw (uno::RuntimeException)
1191 sal_uInt32 nColor;
1192 if (mpParent && mpParent->meType == VALUESETITEM_COLOR)
1193 nColor = mpParent->maColor.GetColor();
1194 else
1195 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
1196 return static_cast<sal_Int32>(nColor);
1199 // -----------------------------------------------------------------------------
1201 sal_Int64 SAL_CALL ValueItemAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException )
1203 sal_Int64 nRet;
1205 if( ( rId.getLength() == 16 ) && ( 0 == memcmp( ValueItemAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
1206 nRet = reinterpret_cast< sal_Int64 >( this );
1207 else
1208 nRet = 0;
1210 return nRet;
1213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */