update dev300-m58
[ooovba.git] / svtools / source / control / valueacc.cxx
blobdd1144757b08a686e69c499289dde8e5bac7e5d3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: valueacc.cxx,v $
10 * $Revision: 1.25 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #define _SV_VALUESET_CXX
36 #include <unotools/accessiblestatesethelper.hxx>
37 #include <vcl/svapp.hxx>
38 #include <svtools/valueset.hxx>
39 #include "valueimp.hxx"
40 #include <com/sun/star/accessibility/AccessibleRole.hpp>
41 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
43 using namespace ::com::sun::star;
45 // ----------------
46 // - ValueSetItem -
47 // ----------------
49 ValueSetItem::ValueSetItem( ValueSet& rParent ) :
50 mrParent( rParent ),
51 mnId( 0 ),
52 mnBits( 0 ),
53 mpData( NULL ),
54 mpxAcc( NULL )
58 // -----------------------------------------------------------------------
60 ValueSetItem::~ValueSetItem()
62 if( mpxAcc )
64 static_cast< ValueItemAcc* >( mpxAcc->get() )->ParentDestroyed();
65 delete mpxAcc;
69 // -----------------------------------------------------------------------
71 uno::Reference< accessibility::XAccessible > ValueSetItem::GetAccessible( bool bIsTransientChildrenDisabled )
73 if( !mpxAcc )
74 mpxAcc = new uno::Reference< accessibility::XAccessible >( new ValueItemAcc( this, bIsTransientChildrenDisabled ) );
76 return *mpxAcc;
79 // -----------------------------------------------------------------------
81 void ValueSetItem::ClearAccessible()
83 if( mpxAcc )
84 delete mpxAcc, mpxAcc = NULL;
88 // ---------------
89 // - ValueSetAcc -
90 // ---------------
92 ValueSetAcc::ValueSetAcc( ValueSet* pParent, bool bIsTransientChildrenDisabled ) :
93 ValueSetAccComponentBase (m_aMutex),
94 mpParent( pParent ),
95 mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled )
99 // -----------------------------------------------------------------------------
101 ValueSetAcc::~ValueSetAcc()
105 // -----------------------------------------------------------------------
107 void ValueSetAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
109 if( nEventId )
111 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners );
112 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter( aTmpListeners.begin() );
113 accessibility::AccessibleEventObject aEvtObject;
115 aEvtObject.EventId = nEventId;
116 aEvtObject.Source = static_cast<uno::XWeak*>(this);
117 aEvtObject.NewValue = rNewValue;
118 aEvtObject.OldValue = rOldValue;
120 while( aIter != aTmpListeners.end() )
124 (*aIter)->notifyEvent( aEvtObject );
126 catch( uno::Exception& )
130 aIter++;
135 // -----------------------------------------------------------------------------
137 const uno::Sequence< sal_Int8 >& ValueSetAcc::getUnoTunnelId()
139 static uno::Sequence< sal_Int8 > aSeq;
141 if( !aSeq.getLength() )
143 static osl::Mutex aCreateMutex;
144 osl::Guard< osl::Mutex > aGuard( aCreateMutex );
146 aSeq.realloc( 16 );
147 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
150 return aSeq;
153 // -----------------------------------------------------------------------------
155 ValueSetAcc* ValueSetAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
156 throw()
160 uno::Reference< lang::XUnoTunnel > xUnoTunnel( rxData, uno::UNO_QUERY );
161 return( xUnoTunnel.is() ? reinterpret_cast<ValueSetAcc*>(sal::static_int_cast<sal_IntPtr>(xUnoTunnel->getSomething( ValueSetAcc::getUnoTunnelId() ))) : NULL );
163 catch( const ::com::sun::star::uno::Exception& )
165 return NULL;
169 // -----------------------------------------------------------------------------
171 uno::Reference< accessibility::XAccessibleContext > SAL_CALL ValueSetAcc::getAccessibleContext()
172 throw (uno::RuntimeException)
174 ThrowIfDisposed();
175 return this;
178 // -----------------------------------------------------------------------------
180 sal_Int32 SAL_CALL ValueSetAcc::getAccessibleChildCount()
181 throw (uno::RuntimeException)
183 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
184 ThrowIfDisposed();
186 sal_Int32 nCount = mpParent->ImplGetVisibleItemCount();
187 if (HasNoneField())
188 nCount += 1;
189 return nCount;
192 // -----------------------------------------------------------------------------
194 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessibleChild( sal_Int32 i )
195 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
197 ThrowIfDisposed();
198 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
199 uno::Reference< accessibility::XAccessible > xRet;
200 ValueSetItem* pItem = getItem (sal::static_int_cast< USHORT >(i));
202 if( pItem )
203 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
204 else
205 throw lang::IndexOutOfBoundsException();
207 return xRet;
210 // -----------------------------------------------------------------------------
212 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessibleParent()
213 throw (uno::RuntimeException)
215 ThrowIfDisposed();
216 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
217 Window* pParent = mpParent->GetParent();
218 uno::Reference< accessibility::XAccessible > xRet;
220 if( pParent )
221 xRet = pParent->GetAccessible();
223 return xRet;
226 // -----------------------------------------------------------------------------
228 sal_Int32 SAL_CALL ValueSetAcc::getAccessibleIndexInParent()
229 throw (uno::RuntimeException)
231 ThrowIfDisposed();
232 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
233 Window* pParent = mpParent->GetParent();
234 sal_Int32 nRet = 0;
236 if( pParent )
238 sal_Bool bFound = sal_False;
240 for( USHORT i = 0, nCount = pParent->GetChildCount(); ( i < nCount ) && !bFound; i++ )
242 if( pParent->GetChild( i ) == mpParent )
244 nRet = i;
245 bFound = sal_True;
250 return nRet;
253 // -----------------------------------------------------------------------------
255 sal_Int16 SAL_CALL ValueSetAcc::getAccessibleRole()
256 throw (uno::RuntimeException)
258 ThrowIfDisposed();
259 // #i73746# As the Java Access Bridge (v 2.0.1) uses "managesDescendants"
260 // always if the role is LIST, we need a different role in this case
261 return (mbIsTransientChildrenDisabled
262 ? accessibility::AccessibleRole::PANEL
263 : accessibility::AccessibleRole::LIST );
266 // -----------------------------------------------------------------------------
268 ::rtl::OUString SAL_CALL ValueSetAcc::getAccessibleDescription()
269 throw (uno::RuntimeException)
271 ThrowIfDisposed();
272 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
273 String aRet( RTL_CONSTASCII_USTRINGPARAM( "ValueSet" ) );
275 return aRet;
278 // -----------------------------------------------------------------------------
280 ::rtl::OUString SAL_CALL ValueSetAcc::getAccessibleName()
281 throw (uno::RuntimeException)
283 ThrowIfDisposed();
284 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
285 String aRet;
287 if ( mpParent )
288 aRet = mpParent->GetAccessibleName();
290 if ( !aRet.Len() )
292 Window* pLabel = mpParent->GetLabeledBy();
293 if ( pLabel && pLabel != mpParent )
294 aRet = OutputDevice::GetNonMnemonicString( pLabel->GetText() );
297 return aRet;
300 // -----------------------------------------------------------------------------
302 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ValueSetAcc::getAccessibleRelationSet()
303 throw (uno::RuntimeException)
305 ThrowIfDisposed();
306 return uno::Reference< accessibility::XAccessibleRelationSet >();
309 // -----------------------------------------------------------------------------
311 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ValueSetAcc::getAccessibleStateSet()
312 throw (uno::RuntimeException)
314 ThrowIfDisposed();
315 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
317 // Set some states.
318 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
319 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
320 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
321 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
322 if ( !mbIsTransientChildrenDisabled )
323 pStateSet->AddState (accessibility::AccessibleStateType::MANAGES_DESCENDANTS);
325 return pStateSet;
328 // -----------------------------------------------------------------------------
330 lang::Locale SAL_CALL ValueSetAcc::getLocale()
331 throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException)
333 ThrowIfDisposed();
334 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
335 const ::rtl::OUString aEmptyStr;
336 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
337 lang::Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
339 if( xParent.is() )
341 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
343 if( xParentContext.is() )
344 aRet = xParentContext->getLocale ();
347 return aRet;
350 // -----------------------------------------------------------------------------
352 void SAL_CALL ValueSetAcc::addEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
353 throw (uno::RuntimeException)
355 ThrowIfDisposed();
356 ::osl::MutexGuard aGuard (m_aMutex);
358 if( rxListener.is() )
360 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter = mxEventListeners.begin();
361 sal_Bool bFound = sal_False;
363 while( !bFound && ( aIter != mxEventListeners.end() ) )
365 if( *aIter == rxListener )
366 bFound = sal_True;
367 else
368 aIter++;
371 if (!bFound)
372 mxEventListeners.push_back( rxListener );
376 // -----------------------------------------------------------------------------
378 void SAL_CALL ValueSetAcc::removeEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
379 throw (uno::RuntimeException)
381 ThrowIfDisposed();
382 ::osl::MutexGuard aGuard (m_aMutex);
384 if( rxListener.is() )
386 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter = mxEventListeners.begin();
387 sal_Bool bFound = sal_False;
389 while( !bFound && ( aIter != mxEventListeners.end() ) )
391 if( *aIter == rxListener )
393 mxEventListeners.erase( aIter );
394 bFound = sal_True;
396 else
397 aIter++;
402 // -----------------------------------------------------------------------------
404 sal_Bool SAL_CALL ValueSetAcc::containsPoint( const awt::Point& aPoint )
405 throw (uno::RuntimeException)
407 ThrowIfDisposed();
408 const awt::Rectangle aRect( getBounds() );
409 const Point aSize( aRect.Width, aRect.Height );
410 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
412 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
415 // -----------------------------------------------------------------------------
417 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessibleAtPoint( const awt::Point& aPoint )
418 throw (uno::RuntimeException)
420 ThrowIfDisposed();
421 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
422 const USHORT nItemId = mpParent->GetItemId( Point( aPoint.X, aPoint.Y ) );
423 uno::Reference< accessibility::XAccessible > xRet;
425 if( VALUESET_ITEM_NOTFOUND != nItemId )
427 const USHORT nItemPos = mpParent->GetItemPos( nItemId );
429 if( VALUESET_ITEM_NONEITEM != nItemPos )
431 ValueSetItem* pItem = mpParent->mpImpl->mpItemList->GetObject( nItemPos );
433 if( ( pItem->meType != VALUESETITEM_SPACE ) && !pItem->maRect.IsEmpty() )
434 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
438 return xRet;
441 // -----------------------------------------------------------------------------
443 awt::Rectangle SAL_CALL ValueSetAcc::getBounds()
444 throw (uno::RuntimeException)
446 ThrowIfDisposed();
447 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
448 const Point aOutPos( mpParent->GetPosPixel() );
449 const Size aOutSize( mpParent->GetOutputSizePixel() );
450 awt::Rectangle aRet;
452 aRet.X = aOutPos.X();
453 aRet.Y = aOutPos.Y();
454 aRet.Width = aOutSize.Width();
455 aRet.Height = aOutSize.Height();
457 return aRet;
460 // -----------------------------------------------------------------------------
462 awt::Point SAL_CALL ValueSetAcc::getLocation()
463 throw (uno::RuntimeException)
465 ThrowIfDisposed();
466 const awt::Rectangle aRect( getBounds() );
467 awt::Point aRet;
469 aRet.X = aRect.X;
470 aRet.Y = aRect.Y;
472 return aRet;
475 // -----------------------------------------------------------------------------
477 awt::Point SAL_CALL ValueSetAcc::getLocationOnScreen()
478 throw (uno::RuntimeException)
480 ThrowIfDisposed();
481 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
482 const Point aScreenPos( mpParent->OutputToAbsoluteScreenPixel( Point() ) );
483 awt::Point aRet;
485 aRet.X = aScreenPos.X();
486 aRet.Y = aScreenPos.Y();
488 return aRet;
491 // -----------------------------------------------------------------------------
493 awt::Size SAL_CALL ValueSetAcc::getSize()
494 throw (uno::RuntimeException)
496 ThrowIfDisposed();
497 const awt::Rectangle aRect( getBounds() );
498 awt::Size aRet;
500 aRet.Width = aRect.Width;
501 aRet.Height = aRect.Height;
503 return aRet;
506 // -----------------------------------------------------------------------------
508 void SAL_CALL ValueSetAcc::grabFocus()
509 throw (uno::RuntimeException)
511 ThrowIfDisposed();
512 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
513 mpParent->GrabFocus();
516 // -----------------------------------------------------------------------------
518 uno::Any SAL_CALL ValueSetAcc::getAccessibleKeyBinding()
519 throw (uno::RuntimeException)
521 ThrowIfDisposed();
522 return uno::Any();
525 // -----------------------------------------------------------------------------
527 sal_Int32 SAL_CALL ValueSetAcc::getForeground( )
528 throw (uno::RuntimeException)
530 ThrowIfDisposed();
531 UINT32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
532 return static_cast<sal_Int32>(nColor);
535 // -----------------------------------------------------------------------------
537 sal_Int32 SAL_CALL ValueSetAcc::getBackground( )
538 throw (uno::RuntimeException)
540 ThrowIfDisposed();
541 UINT32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
542 return static_cast<sal_Int32>(nColor);
545 // -----------------------------------------------------------------------------
547 void SAL_CALL ValueSetAcc::selectAccessibleChild( sal_Int32 nChildIndex )
548 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
550 ThrowIfDisposed();
551 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
552 ValueSetItem* pItem = getItem (sal::static_int_cast< USHORT >(nChildIndex));
554 if(pItem != NULL)
556 mpParent->SelectItem( pItem->mnId );
557 mpParent->Select ();
559 else
560 throw lang::IndexOutOfBoundsException();
563 // -----------------------------------------------------------------------------
565 sal_Bool SAL_CALL ValueSetAcc::isAccessibleChildSelected( sal_Int32 nChildIndex )
566 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
568 ThrowIfDisposed();
569 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
570 ValueSetItem* pItem = getItem (sal::static_int_cast< USHORT >(nChildIndex));
571 sal_Bool bRet = sal_False;
573 if (pItem != NULL)
574 bRet = mpParent->IsItemSelected( pItem->mnId );
575 else
576 throw lang::IndexOutOfBoundsException();
578 return bRet;
581 // -----------------------------------------------------------------------------
583 void SAL_CALL ValueSetAcc::clearAccessibleSelection()
584 throw (uno::RuntimeException)
586 ThrowIfDisposed();
587 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
588 mpParent->SetNoSelection();
591 // -----------------------------------------------------------------------------
593 void SAL_CALL ValueSetAcc::selectAllAccessibleChildren()
594 throw (uno::RuntimeException)
596 ThrowIfDisposed();
597 // unsupported due to single selection only
600 // -----------------------------------------------------------------------------
602 sal_Int32 SAL_CALL ValueSetAcc::getSelectedAccessibleChildCount()
603 throw (uno::RuntimeException)
605 ThrowIfDisposed();
606 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
607 sal_Int32 nRet = 0;
609 for( USHORT i = 0, nCount = getItemCount(); i < nCount; i++ )
611 ValueSetItem* pItem = getItem (i);
613 if( pItem && mpParent->IsItemSelected( pItem->mnId ) )
614 ++nRet;
617 return nRet;
620 // -----------------------------------------------------------------------------
622 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
623 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
625 ThrowIfDisposed();
626 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
627 uno::Reference< accessibility::XAccessible > xRet;
629 for( USHORT i = 0, nCount = getItemCount(), nSel = 0; ( i < nCount ) && !xRet.is(); i++ )
631 ValueSetItem* pItem = getItem(i);
633 if( pItem && mpParent->IsItemSelected( pItem->mnId ) && ( nSelectedChildIndex == static_cast< sal_Int32 >( nSel++ ) ) )
634 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
637 return xRet;
640 // -----------------------------------------------------------------------------
642 void SAL_CALL ValueSetAcc::deselectAccessibleChild( sal_Int32 nChildIndex )
643 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
645 ThrowIfDisposed();
646 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
647 // Because of the single selection we can reset the whole selection when
648 // the specified child is currently selected.
649 if (isAccessibleChildSelected(nChildIndex))
650 mpParent->SetNoSelection();
653 // -----------------------------------------------------------------------------
655 sal_Int64 SAL_CALL ValueSetAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException )
657 sal_Int64 nRet;
659 if( ( rId.getLength() == 16 ) && ( 0 == rtl_compareMemory( ValueSetAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
660 nRet = reinterpret_cast< sal_Int64 >( this );
661 else
662 nRet = 0;
664 return nRet;
670 void SAL_CALL ValueSetAcc::disposing (void)
672 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> > aListenerListCopy;
675 // Make a copy of the list and clear the original.
676 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
677 ::osl::MutexGuard aGuard (m_aMutex);
678 aListenerListCopy = mxEventListeners;
679 mxEventListeners.clear();
681 // Reset the pointer to the parent. It has to be the one who has
682 // disposed us because he is dying.
683 mpParent = NULL;
686 // Inform all listeners that this objects is disposing.
687 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> >::const_iterator
688 aListenerIterator (aListenerListCopy.begin());
689 lang::EventObject aEvent (static_cast<accessibility::XAccessible*>(this));
690 while (aListenerIterator != aListenerListCopy.end())
694 (*aListenerIterator)->disposing (aEvent);
696 catch( uno::Exception& )
698 // Ignore exceptions.
701 ++aListenerIterator;
706 USHORT ValueSetAcc::getItemCount (void) const
708 USHORT nCount = mpParent->ImplGetVisibleItemCount();
709 // When the None-Item is visible then increase the number of items by
710 // one.
711 if (HasNoneField())
712 nCount += 1;
713 return nCount;
717 ValueSetItem* ValueSetAcc::getItem (USHORT nIndex) const
719 ValueSetItem* pItem = NULL;
721 if (HasNoneField())
723 if (nIndex == 0)
724 // When present the first item is the then allways visible none field.
725 pItem = mpParent->ImplGetItem (VALUESET_ITEM_NONEITEM);
726 else
727 // Shift down the index to compensate for the none field.
728 nIndex -= 1;
730 if (pItem == NULL)
731 pItem = mpParent->ImplGetVisibleItem (static_cast<USHORT>(nIndex));
733 return pItem;
739 void ValueSetAcc::ThrowIfDisposed (void)
740 throw (::com::sun::star::lang::DisposedException)
742 if (rBHelper.bDisposed || rBHelper.bInDispose)
744 OSL_TRACE ("Calling disposed object. Throwing exception:");
745 throw lang::DisposedException (
746 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("object has been already disposed")),
747 static_cast<uno::XWeak*>(this));
749 else
751 DBG_ASSERT (mpParent!=NULL, "ValueSetAcc not disposed but mpParent == NULL");
757 sal_Bool ValueSetAcc::IsDisposed (void)
759 return (rBHelper.bDisposed || rBHelper.bInDispose);
765 bool ValueSetAcc::HasNoneField (void) const
767 DBG_ASSERT (mpParent!=NULL, "ValueSetAcc::HasNoneField called with mpParent==NULL");
768 return ((mpParent->GetStyle() & WB_NONEFIELD) != 0);
774 // ----------------
775 // - ValueItemAcc -
776 // ----------------
778 ValueItemAcc::ValueItemAcc( ValueSetItem* pParent, bool bIsTransientChildrenDisabled ) :
779 mpParent( pParent ),
780 mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled )
784 // -----------------------------------------------------------------------------
786 ValueItemAcc::~ValueItemAcc()
790 // -----------------------------------------------------------------------
792 void ValueItemAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
794 if( nEventId )
796 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners );
797 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter( aTmpListeners.begin() );
798 accessibility::AccessibleEventObject aEvtObject;
800 aEvtObject.EventId = nEventId;
801 aEvtObject.Source = static_cast<uno::XWeak*>(this);
802 aEvtObject.NewValue = rNewValue;
803 aEvtObject.OldValue = rOldValue;
805 while( aIter != aTmpListeners.end() )
807 (*aIter)->notifyEvent( aEvtObject );
808 aIter++;
813 // -----------------------------------------------------------------------------
815 void ValueItemAcc::ParentDestroyed()
817 const ::vos::OGuard aGuard( maMutex );
818 mpParent = NULL;
821 // -----------------------------------------------------------------------------
823 const uno::Sequence< sal_Int8 >& ValueItemAcc::getUnoTunnelId()
825 static uno::Sequence< sal_Int8 > aSeq;
827 if( !aSeq.getLength() )
829 static osl::Mutex aCreateMutex;
830 osl::Guard< osl::Mutex > aGuard( aCreateMutex );
832 aSeq.realloc( 16 );
833 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True );
836 return aSeq;
839 // -----------------------------------------------------------------------------
841 ValueItemAcc* ValueItemAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
842 throw()
846 uno::Reference< lang::XUnoTunnel > xUnoTunnel( rxData, uno::UNO_QUERY );
847 return( xUnoTunnel.is() ? reinterpret_cast<ValueItemAcc*>(sal::static_int_cast<sal_IntPtr>(xUnoTunnel->getSomething( ValueItemAcc::getUnoTunnelId() ))) : NULL );
849 catch( const ::com::sun::star::uno::Exception& )
851 return NULL;
855 // -----------------------------------------------------------------------------
857 uno::Reference< accessibility::XAccessibleContext > SAL_CALL ValueItemAcc::getAccessibleContext()
858 throw (uno::RuntimeException)
860 return this;
863 // -----------------------------------------------------------------------------
865 sal_Int32 SAL_CALL ValueItemAcc::getAccessibleChildCount()
866 throw (uno::RuntimeException)
868 return 0;
871 // -----------------------------------------------------------------------------
873 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleChild( sal_Int32 )
874 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
876 throw lang::IndexOutOfBoundsException();
879 // -----------------------------------------------------------------------------
881 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleParent()
882 throw (uno::RuntimeException)
884 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
885 uno::Reference< accessibility::XAccessible > xRet;
887 if( mpParent )
888 xRet = mpParent->mrParent.GetAccessible();
890 return xRet;
893 // -----------------------------------------------------------------------------
895 sal_Int32 SAL_CALL ValueItemAcc::getAccessibleIndexInParent()
896 throw (uno::RuntimeException)
898 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
899 // The index defaults to -1 to indicate the child does not belong to its
900 // parent.
901 sal_Int32 nIndexInParent = -1;
903 if( mpParent )
905 bool bDone = false;
907 USHORT nCount = mpParent->mrParent.ImplGetVisibleItemCount();
908 ValueSetItem* pItem;
909 for (USHORT i=0; i<nCount && !bDone; i++)
911 // Guard the retrieval of the i-th child with a try/catch block
912 // just in case the number of children changes in the mean time.
915 pItem = mpParent->mrParent.ImplGetVisibleItem (i);
917 catch (lang::IndexOutOfBoundsException aException)
919 pItem = NULL;
922 // Do not create an accessible object for the test.
923 if (pItem != NULL && pItem->mpxAcc != NULL)
924 if (pItem->GetAccessible( mbIsTransientChildrenDisabled ).get() == this )
926 nIndexInParent = i;
927 bDone = true;
932 return nIndexInParent;
935 // -----------------------------------------------------------------------------
937 sal_Int16 SAL_CALL ValueItemAcc::getAccessibleRole()
938 throw (uno::RuntimeException)
940 return accessibility::AccessibleRole::LIST_ITEM;
943 // -----------------------------------------------------------------------------
945 ::rtl::OUString SAL_CALL ValueItemAcc::getAccessibleDescription()
946 throw (uno::RuntimeException)
948 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
949 String aRet( RTL_CONSTASCII_USTRINGPARAM( "ValueSet item" ) );
951 return aRet;
954 // -----------------------------------------------------------------------------
956 ::rtl::OUString SAL_CALL ValueItemAcc::getAccessibleName()
957 throw (uno::RuntimeException)
959 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
960 String aRet;
962 if( mpParent )
964 aRet = mpParent->maText;
966 if( !aRet.Len() )
968 aRet = String( RTL_CONSTASCII_USTRINGPARAM( "Item " ) );
969 aRet += String::CreateFromInt32( mpParent->mnId );
973 return aRet;
976 // -----------------------------------------------------------------------------
978 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ValueItemAcc::getAccessibleRelationSet()
979 throw (uno::RuntimeException)
981 return uno::Reference< accessibility::XAccessibleRelationSet >();
984 // -----------------------------------------------------------------------------
986 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ValueItemAcc::getAccessibleStateSet()
987 throw (uno::RuntimeException)
989 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
990 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
992 if( mpParent )
994 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
995 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
996 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
997 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
998 if ( !mbIsTransientChildrenDisabled )
999 pStateSet->AddState (accessibility::AccessibleStateType::TRANSIENT);
1001 // SELECTABLE
1002 pStateSet->AddState( accessibility::AccessibleStateType::SELECTABLE );
1003 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
1005 // SELECTED
1006 if( mpParent->mrParent.GetSelectItemId() == mpParent->mnId )
1008 pStateSet->AddState( accessibility::AccessibleStateType::SELECTED );
1009 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
1013 return pStateSet;
1016 // -----------------------------------------------------------------------------
1018 lang::Locale SAL_CALL ValueItemAcc::getLocale()
1019 throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException)
1021 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1022 const ::rtl::OUString aEmptyStr;
1023 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
1024 lang::Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
1026 if( xParent.is() )
1028 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
1030 if( xParentContext.is() )
1031 aRet = xParentContext->getLocale();
1034 return aRet;
1037 // -----------------------------------------------------------------------------
1039 void SAL_CALL ValueItemAcc::addEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
1040 throw (uno::RuntimeException)
1042 const ::vos::OGuard aGuard( maMutex );
1044 if( rxListener.is() )
1046 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter = mxEventListeners.begin();
1047 sal_Bool bFound = sal_False;
1049 while( !bFound && ( aIter != mxEventListeners.end() ) )
1051 if( *aIter == rxListener )
1052 bFound = sal_True;
1053 else
1054 aIter++;
1057 if (!bFound)
1058 mxEventListeners.push_back( rxListener );
1062 // -----------------------------------------------------------------------------
1064 void SAL_CALL ValueItemAcc::removeEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
1065 throw (uno::RuntimeException)
1067 const ::vos::OGuard aGuard( maMutex );
1069 if( rxListener.is() )
1071 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter = mxEventListeners.begin();
1072 sal_Bool bFound = sal_False;
1074 while( !bFound && ( aIter != mxEventListeners.end() ) )
1076 if( *aIter == rxListener )
1078 mxEventListeners.erase( aIter );
1079 bFound = sal_True;
1081 else
1082 aIter++;
1087 // -----------------------------------------------------------------------------
1089 sal_Bool SAL_CALL ValueItemAcc::containsPoint( const awt::Point& aPoint )
1090 throw (uno::RuntimeException)
1092 const awt::Rectangle aRect( getBounds() );
1093 const Point aSize( aRect.Width, aRect.Height );
1094 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
1096 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
1099 // -----------------------------------------------------------------------------
1101 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleAtPoint( const awt::Point& )
1102 throw (uno::RuntimeException)
1104 uno::Reference< accessibility::XAccessible > xRet;
1105 return xRet;
1108 // -----------------------------------------------------------------------------
1110 awt::Rectangle SAL_CALL ValueItemAcc::getBounds()
1111 throw (uno::RuntimeException)
1113 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1114 awt::Rectangle aRet;
1116 if( mpParent )
1118 Rectangle aRect( mpParent->maRect );
1119 Point aOrigin;
1120 Rectangle aParentRect( aOrigin, mpParent->mrParent.GetOutputSizePixel() );
1122 aRect.Intersection( aParentRect );
1124 aRet.X = aRect.Left();
1125 aRet.Y = aRect.Top();
1126 aRet.Width = aRect.GetWidth();
1127 aRet.Height = aRect.GetHeight();
1130 return aRet;
1133 // -----------------------------------------------------------------------------
1135 awt::Point SAL_CALL ValueItemAcc::getLocation()
1136 throw (uno::RuntimeException)
1138 const awt::Rectangle aRect( getBounds() );
1139 awt::Point aRet;
1141 aRet.X = aRect.X;
1142 aRet.Y = aRect.Y;
1144 return aRet;
1147 // -----------------------------------------------------------------------------
1149 awt::Point SAL_CALL ValueItemAcc::getLocationOnScreen()
1150 throw (uno::RuntimeException)
1152 const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1153 awt::Point aRet;
1155 if( mpParent )
1157 const Point aScreenPos( mpParent->mrParent.OutputToAbsoluteScreenPixel( mpParent->maRect.TopLeft() ) );
1159 aRet.X = aScreenPos.X();
1160 aRet.Y = aScreenPos.Y();
1163 return aRet;
1166 // -----------------------------------------------------------------------------
1168 awt::Size SAL_CALL ValueItemAcc::getSize()
1169 throw (uno::RuntimeException)
1171 const awt::Rectangle aRect( getBounds() );
1172 awt::Size aRet;
1174 aRet.Width = aRect.Width;
1175 aRet.Height = aRect.Height;
1177 return aRet;
1180 // -----------------------------------------------------------------------------
1182 void SAL_CALL ValueItemAcc::grabFocus()
1183 throw (uno::RuntimeException)
1185 // nothing to do
1188 // -----------------------------------------------------------------------------
1190 uno::Any SAL_CALL ValueItemAcc::getAccessibleKeyBinding()
1191 throw (uno::RuntimeException)
1193 return uno::Any();
1196 // -----------------------------------------------------------------------------
1198 sal_Int32 SAL_CALL ValueItemAcc::getForeground( )
1199 throw (uno::RuntimeException)
1201 UINT32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
1202 return static_cast<sal_Int32>(nColor);
1205 // -----------------------------------------------------------------------------
1207 sal_Int32 SAL_CALL ValueItemAcc::getBackground( )
1208 throw (uno::RuntimeException)
1210 UINT32 nColor;
1211 if (mpParent->meType == VALUESETITEM_COLOR)
1212 nColor = mpParent->maColor.GetColor();
1213 else
1214 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
1215 return static_cast<sal_Int32>(nColor);
1218 // -----------------------------------------------------------------------------
1220 sal_Int64 SAL_CALL ValueItemAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException )
1222 sal_Int64 nRet;
1224 if( ( rId.getLength() == 16 ) && ( 0 == rtl_compareMemory( ValueItemAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
1225 nRet = reinterpret_cast< sal_Int64 >( this );
1226 else
1227 nRet = 0;
1229 return nRet;