GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / control / valueacc.cxx
blob01c60af4cc42f0b03db75c79b0df5c173353a5bb
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 OUString aRet( "ValueSet" );
273 return aRet;
276 // -----------------------------------------------------------------------------
278 OUString SAL_CALL ValueSetAcc::getAccessibleName()
279 throw (uno::RuntimeException)
281 ThrowIfDisposed();
282 const SolarMutexGuard aSolarGuard;
283 OUString aRet;
285 if ( mpParent )
286 aRet = mpParent->GetAccessibleName();
288 if ( aRet.isEmpty() )
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 =
388 std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener);
390 if (aIter != mxEventListeners.end())
391 mxEventListeners.erase(aIter);
395 // -----------------------------------------------------------------------------
397 sal_Bool SAL_CALL ValueSetAcc::containsPoint( const awt::Point& aPoint )
398 throw (uno::RuntimeException)
400 ThrowIfDisposed();
401 const awt::Rectangle aRect( getBounds() );
402 const Point aSize( aRect.Width, aRect.Height );
403 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
405 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
408 // -----------------------------------------------------------------------------
410 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessibleAtPoint( const awt::Point& aPoint )
411 throw (uno::RuntimeException)
413 ThrowIfDisposed();
414 const SolarMutexGuard aSolarGuard;
415 const sal_uInt16 nItemId = mpParent->GetItemId( Point( aPoint.X, aPoint.Y ) );
416 uno::Reference< accessibility::XAccessible > xRet;
418 if ( nItemId )
420 const size_t nItemPos = mpParent->GetItemPos( nItemId );
422 if( VALUESET_ITEM_NONEITEM != nItemPos )
424 ValueSetItem *const pItem = mpParent->mItemList[nItemPos];
425 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
429 return xRet;
432 // -----------------------------------------------------------------------------
434 awt::Rectangle SAL_CALL ValueSetAcc::getBounds()
435 throw (uno::RuntimeException)
437 ThrowIfDisposed();
438 const SolarMutexGuard aSolarGuard;
439 const Point aOutPos( mpParent->GetPosPixel() );
440 const Size aOutSize( mpParent->GetOutputSizePixel() );
441 awt::Rectangle aRet;
443 aRet.X = aOutPos.X();
444 aRet.Y = aOutPos.Y();
445 aRet.Width = aOutSize.Width();
446 aRet.Height = aOutSize.Height();
448 return aRet;
451 // -----------------------------------------------------------------------------
453 awt::Point SAL_CALL ValueSetAcc::getLocation()
454 throw (uno::RuntimeException)
456 ThrowIfDisposed();
457 const awt::Rectangle aRect( getBounds() );
458 awt::Point aRet;
460 aRet.X = aRect.X;
461 aRet.Y = aRect.Y;
463 return aRet;
466 // -----------------------------------------------------------------------------
468 awt::Point SAL_CALL ValueSetAcc::getLocationOnScreen()
469 throw (uno::RuntimeException)
471 ThrowIfDisposed();
472 const SolarMutexGuard aSolarGuard;
473 const Point aScreenPos( mpParent->OutputToAbsoluteScreenPixel( Point() ) );
474 awt::Point aRet;
476 aRet.X = aScreenPos.X();
477 aRet.Y = aScreenPos.Y();
479 return aRet;
482 // -----------------------------------------------------------------------------
484 awt::Size SAL_CALL ValueSetAcc::getSize()
485 throw (uno::RuntimeException)
487 ThrowIfDisposed();
488 const awt::Rectangle aRect( getBounds() );
489 awt::Size aRet;
491 aRet.Width = aRect.Width;
492 aRet.Height = aRect.Height;
494 return aRet;
497 // -----------------------------------------------------------------------------
499 void SAL_CALL ValueSetAcc::grabFocus()
500 throw (uno::RuntimeException)
502 ThrowIfDisposed();
503 const SolarMutexGuard aSolarGuard;
504 mpParent->GrabFocus();
507 // -----------------------------------------------------------------------------
509 uno::Any SAL_CALL ValueSetAcc::getAccessibleKeyBinding()
510 throw (uno::RuntimeException)
512 ThrowIfDisposed();
513 return uno::Any();
516 // -----------------------------------------------------------------------------
518 sal_Int32 SAL_CALL ValueSetAcc::getForeground( )
519 throw (uno::RuntimeException)
521 ThrowIfDisposed();
522 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
523 return static_cast<sal_Int32>(nColor);
526 // -----------------------------------------------------------------------------
528 sal_Int32 SAL_CALL ValueSetAcc::getBackground( )
529 throw (uno::RuntimeException)
531 ThrowIfDisposed();
532 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
533 return static_cast<sal_Int32>(nColor);
536 // -----------------------------------------------------------------------------
538 void SAL_CALL ValueSetAcc::selectAccessibleChild( sal_Int32 nChildIndex )
539 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
541 ThrowIfDisposed();
542 const SolarMutexGuard aSolarGuard;
543 ValueSetItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
545 if(pItem != NULL)
547 mpParent->SelectItem( pItem->mnId );
548 mpParent->Select ();
550 else
551 throw lang::IndexOutOfBoundsException();
554 // -----------------------------------------------------------------------------
556 sal_Bool SAL_CALL ValueSetAcc::isAccessibleChildSelected( sal_Int32 nChildIndex )
557 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
559 ThrowIfDisposed();
560 const SolarMutexGuard aSolarGuard;
561 ValueSetItem* pItem = getItem (sal::static_int_cast< sal_uInt16 >(nChildIndex));
562 sal_Bool bRet = sal_False;
564 if (pItem != NULL)
565 bRet = mpParent->IsItemSelected( pItem->mnId );
566 else
567 throw lang::IndexOutOfBoundsException();
569 return bRet;
572 // -----------------------------------------------------------------------------
574 void SAL_CALL ValueSetAcc::clearAccessibleSelection()
575 throw (uno::RuntimeException)
577 ThrowIfDisposed();
578 const SolarMutexGuard aSolarGuard;
579 mpParent->SetNoSelection();
582 // -----------------------------------------------------------------------------
584 void SAL_CALL ValueSetAcc::selectAllAccessibleChildren()
585 throw (uno::RuntimeException)
587 ThrowIfDisposed();
588 // unsupported due to single selection only
591 // -----------------------------------------------------------------------------
593 sal_Int32 SAL_CALL ValueSetAcc::getSelectedAccessibleChildCount()
594 throw (uno::RuntimeException)
596 ThrowIfDisposed();
597 const SolarMutexGuard aSolarGuard;
598 sal_Int32 nRet = 0;
600 for( sal_uInt16 i = 0, nCount = getItemCount(); i < nCount; i++ )
602 ValueSetItem* pItem = getItem (i);
604 if( pItem && mpParent->IsItemSelected( pItem->mnId ) )
605 ++nRet;
608 return nRet;
611 // -----------------------------------------------------------------------------
613 uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
614 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
616 ThrowIfDisposed();
617 const SolarMutexGuard aSolarGuard;
618 uno::Reference< accessibility::XAccessible > xRet;
620 for( sal_uInt16 i = 0, nCount = getItemCount(), nSel = 0; ( i < nCount ) && !xRet.is(); i++ )
622 ValueSetItem* pItem = getItem(i);
624 if( pItem && mpParent->IsItemSelected( pItem->mnId ) && ( nSelectedChildIndex == static_cast< sal_Int32 >( nSel++ ) ) )
625 xRet = pItem->GetAccessible( mbIsTransientChildrenDisabled );
628 return xRet;
631 // -----------------------------------------------------------------------------
633 void SAL_CALL ValueSetAcc::deselectAccessibleChild( sal_Int32 nChildIndex )
634 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
636 ThrowIfDisposed();
637 const SolarMutexGuard aSolarGuard;
638 // Because of the single selection we can reset the whole selection when
639 // the specified child is currently selected.
640 if (isAccessibleChildSelected(nChildIndex))
641 mpParent->SetNoSelection();
644 // -----------------------------------------------------------------------------
646 sal_Int64 SAL_CALL ValueSetAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException )
648 sal_Int64 nRet;
650 if( ( rId.getLength() == 16 ) && ( 0 == memcmp( ValueSetAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
651 nRet = reinterpret_cast< sal_Int64 >( this );
652 else
653 nRet = 0;
655 return nRet;
661 void SAL_CALL ValueSetAcc::disposing (void)
663 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> > aListenerListCopy;
666 // Make a copy of the list and clear the original.
667 const SolarMutexGuard aSolarGuard;
668 ::osl::MutexGuard aGuard (m_aMutex);
669 aListenerListCopy = mxEventListeners;
670 mxEventListeners.clear();
672 // Reset the pointer to the parent. It has to be the one who has
673 // disposed us because he is dying.
674 mpParent = NULL;
677 // Inform all listeners that this objects is disposing.
678 ::std::vector<uno::Reference<accessibility::XAccessibleEventListener> >::const_iterator
679 aListenerIterator (aListenerListCopy.begin());
680 lang::EventObject aEvent (static_cast<accessibility::XAccessible*>(this));
681 while (aListenerIterator != aListenerListCopy.end())
685 (*aListenerIterator)->disposing (aEvent);
687 catch(const uno::Exception&)
689 // Ignore exceptions.
692 ++aListenerIterator;
697 sal_uInt16 ValueSetAcc::getItemCount (void) const
699 sal_uInt16 nCount = mpParent->ImplGetVisibleItemCount();
700 // When the None-Item is visible then increase the number of items by
701 // one.
702 if (HasNoneField())
703 nCount += 1;
704 return nCount;
708 ValueSetItem* ValueSetAcc::getItem (sal_uInt16 nIndex) const
710 ValueSetItem* pItem = NULL;
712 if (HasNoneField())
714 if (nIndex == 0)
715 // When present the first item is the then always visible none field.
716 pItem = mpParent->ImplGetItem (VALUESET_ITEM_NONEITEM);
717 else
718 // Shift down the index to compensate for the none field.
719 nIndex -= 1;
721 if (pItem == NULL)
722 pItem = mpParent->ImplGetVisibleItem (static_cast<sal_uInt16>(nIndex));
724 return pItem;
730 void ValueSetAcc::ThrowIfDisposed (void)
731 throw (::com::sun::star::lang::DisposedException)
733 if (rBHelper.bDisposed || rBHelper.bInDispose)
735 OSL_TRACE ("Calling disposed object. Throwing exception:");
736 throw lang::DisposedException (
737 OUString("object has been already disposed"),
738 static_cast<uno::XWeak*>(this));
740 else
742 DBG_ASSERT (mpParent!=NULL, "ValueSetAcc not disposed but mpParent == NULL");
748 bool ValueSetAcc::HasNoneField (void) const
750 DBG_ASSERT (mpParent!=NULL, "ValueSetAcc::HasNoneField called with mpParent==NULL");
751 return ((mpParent->GetStyle() & WB_NONEFIELD) != 0);
757 // ----------------
758 // - ValueItemAcc -
759 // ----------------
761 ValueItemAcc::ValueItemAcc( ValueSetItem* pParent, bool bIsTransientChildrenDisabled ) :
762 mpParent( pParent ),
763 mbIsTransientChildrenDisabled( bIsTransientChildrenDisabled )
767 // -----------------------------------------------------------------------------
769 ValueItemAcc::~ValueItemAcc()
773 // -----------------------------------------------------------------------
775 void ValueItemAcc::FireAccessibleEvent( short nEventId, const uno::Any& rOldValue, const uno::Any& rNewValue )
777 if( nEventId )
779 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > > aTmpListeners( mxEventListeners );
780 accessibility::AccessibleEventObject aEvtObject;
782 aEvtObject.EventId = nEventId;
783 aEvtObject.Source = static_cast<uno::XWeak*>(this);
784 aEvtObject.NewValue = rNewValue;
785 aEvtObject.OldValue = rOldValue;
787 for (::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter( aTmpListeners.begin() );
788 aIter != aTmpListeners.end() ; ++aIter)
790 (*aIter)->notifyEvent( aEvtObject );
795 // -----------------------------------------------------------------------------
797 void ValueItemAcc::ParentDestroyed()
799 const ::osl::MutexGuard aGuard( maMutex );
800 mpParent = NULL;
803 namespace
805 class theValueItemAccUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theValueItemAccUnoTunnelId > {};
808 const uno::Sequence< sal_Int8 >& ValueItemAcc::getUnoTunnelId()
810 return theValueItemAccUnoTunnelId::get().getSeq();
813 // -----------------------------------------------------------------------------
815 ValueItemAcc* ValueItemAcc::getImplementation( const uno::Reference< uno::XInterface >& rxData )
816 throw()
820 uno::Reference< lang::XUnoTunnel > xUnoTunnel( rxData, uno::UNO_QUERY );
821 return( xUnoTunnel.is() ? reinterpret_cast<ValueItemAcc*>(sal::static_int_cast<sal_IntPtr>(xUnoTunnel->getSomething( ValueItemAcc::getUnoTunnelId() ))) : NULL );
823 catch(const ::com::sun::star::uno::Exception&)
825 return NULL;
829 // -----------------------------------------------------------------------------
831 uno::Reference< accessibility::XAccessibleContext > SAL_CALL ValueItemAcc::getAccessibleContext()
832 throw (uno::RuntimeException)
834 return this;
837 // -----------------------------------------------------------------------------
839 sal_Int32 SAL_CALL ValueItemAcc::getAccessibleChildCount()
840 throw (uno::RuntimeException)
842 return 0;
845 // -----------------------------------------------------------------------------
847 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleChild( sal_Int32 )
848 throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
850 throw lang::IndexOutOfBoundsException();
853 // -----------------------------------------------------------------------------
855 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleParent()
856 throw (uno::RuntimeException)
858 const SolarMutexGuard aSolarGuard;
859 uno::Reference< accessibility::XAccessible > xRet;
861 if( mpParent )
862 xRet = mpParent->mrParent.GetAccessible();
864 return xRet;
867 // -----------------------------------------------------------------------------
869 sal_Int32 SAL_CALL ValueItemAcc::getAccessibleIndexInParent()
870 throw (uno::RuntimeException)
872 const SolarMutexGuard aSolarGuard;
873 // The index defaults to -1 to indicate the child does not belong to its
874 // parent.
875 sal_Int32 nIndexInParent = -1;
877 if( mpParent )
879 bool bDone = false;
881 sal_uInt16 nCount = mpParent->mrParent.ImplGetVisibleItemCount();
882 ValueSetItem* pItem;
883 for (sal_uInt16 i=0; i<nCount && !bDone; i++)
885 // Guard the retrieval of the i-th child with a try/catch block
886 // just in case the number of children changes in the mean time.
889 pItem = mpParent->mrParent.ImplGetVisibleItem (i);
891 catch (const lang::IndexOutOfBoundsException&)
893 pItem = NULL;
896 // Do not create an accessible object for the test.
897 if (pItem != NULL && pItem->mpxAcc != NULL)
898 if (pItem->GetAccessible( mbIsTransientChildrenDisabled ).get() == this )
900 nIndexInParent = i;
901 bDone = true;
906 return nIndexInParent;
909 // -----------------------------------------------------------------------------
911 sal_Int16 SAL_CALL ValueItemAcc::getAccessibleRole()
912 throw (uno::RuntimeException)
914 return accessibility::AccessibleRole::LIST_ITEM;
917 // -----------------------------------------------------------------------------
919 OUString SAL_CALL ValueItemAcc::getAccessibleDescription()
920 throw (uno::RuntimeException)
922 return OUString();
925 // -----------------------------------------------------------------------------
927 OUString SAL_CALL ValueItemAcc::getAccessibleName()
928 throw (uno::RuntimeException)
930 const SolarMutexGuard aSolarGuard;
931 OUString aRet;
933 if( mpParent )
935 aRet = mpParent->maText;
937 if( aRet.isEmpty() )
939 OUStringBuffer aBuffer("Item ");
940 aBuffer.append(static_cast<sal_Int32>(mpParent->mnId));
941 aRet = aBuffer.makeStringAndClear();
945 return aRet;
948 // -----------------------------------------------------------------------------
950 uno::Reference< accessibility::XAccessibleRelationSet > SAL_CALL ValueItemAcc::getAccessibleRelationSet()
951 throw (uno::RuntimeException)
953 return uno::Reference< accessibility::XAccessibleRelationSet >();
956 // -----------------------------------------------------------------------------
958 uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ValueItemAcc::getAccessibleStateSet()
959 throw (uno::RuntimeException)
961 const SolarMutexGuard aSolarGuard;
962 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
964 if( mpParent )
966 pStateSet->AddState (accessibility::AccessibleStateType::ENABLED);
967 pStateSet->AddState (accessibility::AccessibleStateType::SENSITIVE);
968 pStateSet->AddState (accessibility::AccessibleStateType::SHOWING);
969 pStateSet->AddState (accessibility::AccessibleStateType::VISIBLE);
970 if ( !mbIsTransientChildrenDisabled )
971 pStateSet->AddState (accessibility::AccessibleStateType::TRANSIENT);
973 // SELECTABLE
974 pStateSet->AddState( accessibility::AccessibleStateType::SELECTABLE );
975 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
977 // SELECTED
978 if( mpParent->mrParent.GetSelectItemId() == mpParent->mnId )
980 pStateSet->AddState( accessibility::AccessibleStateType::SELECTED );
981 // pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
985 return pStateSet;
988 // -----------------------------------------------------------------------------
990 lang::Locale SAL_CALL ValueItemAcc::getLocale()
991 throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException)
993 const SolarMutexGuard aSolarGuard;
994 const OUString aEmptyStr;
995 uno::Reference< accessibility::XAccessible > xParent( getAccessibleParent() );
996 lang::Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
998 if( xParent.is() )
1000 uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
1002 if( xParentContext.is() )
1003 aRet = xParentContext->getLocale();
1006 return aRet;
1009 // -----------------------------------------------------------------------------
1011 void SAL_CALL ValueItemAcc::addAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
1012 throw (uno::RuntimeException)
1014 const ::osl::MutexGuard aGuard( maMutex );
1016 if( rxListener.is() )
1018 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::const_iterator aIter = mxEventListeners.begin();
1019 sal_Bool bFound = sal_False;
1021 while( !bFound && ( aIter != mxEventListeners.end() ) )
1023 if( *aIter == rxListener )
1024 bFound = sal_True;
1025 else
1026 ++aIter;
1029 if (!bFound)
1030 mxEventListeners.push_back( rxListener );
1034 // -----------------------------------------------------------------------------
1036 void SAL_CALL ValueItemAcc::removeAccessibleEventListener( const uno::Reference< accessibility::XAccessibleEventListener >& rxListener )
1037 throw (uno::RuntimeException)
1039 const ::osl::MutexGuard aGuard( maMutex );
1041 if( rxListener.is() )
1043 ::std::vector< uno::Reference< accessibility::XAccessibleEventListener > >::iterator aIter =
1044 std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener);
1046 if (aIter != mxEventListeners.end())
1047 mxEventListeners.erase(aIter);
1051 // -----------------------------------------------------------------------------
1053 sal_Bool SAL_CALL ValueItemAcc::containsPoint( const awt::Point& aPoint )
1054 throw (uno::RuntimeException)
1056 const awt::Rectangle aRect( getBounds() );
1057 const Point aSize( aRect.Width, aRect.Height );
1058 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
1060 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
1063 // -----------------------------------------------------------------------------
1065 uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibleAtPoint( const awt::Point& )
1066 throw (uno::RuntimeException)
1068 uno::Reference< accessibility::XAccessible > xRet;
1069 return xRet;
1072 // -----------------------------------------------------------------------------
1074 awt::Rectangle SAL_CALL ValueItemAcc::getBounds()
1075 throw (uno::RuntimeException)
1077 const SolarMutexGuard aSolarGuard;
1078 awt::Rectangle aRet;
1080 if( mpParent )
1082 Rectangle aRect( mpParent->mrParent.GetItemRect(mpParent->mnId) );
1083 Point aOrigin;
1084 Rectangle aParentRect( aOrigin, mpParent->mrParent.GetOutputSizePixel() );
1086 aRect.Intersection( aParentRect );
1088 aRet.X = aRect.Left();
1089 aRet.Y = aRect.Top();
1090 aRet.Width = aRect.GetWidth();
1091 aRet.Height = aRect.GetHeight();
1094 return aRet;
1097 // -----------------------------------------------------------------------------
1099 awt::Point SAL_CALL ValueItemAcc::getLocation()
1100 throw (uno::RuntimeException)
1102 const awt::Rectangle aRect( getBounds() );
1103 awt::Point aRet;
1105 aRet.X = aRect.X;
1106 aRet.Y = aRect.Y;
1108 return aRet;
1111 // -----------------------------------------------------------------------------
1113 awt::Point SAL_CALL ValueItemAcc::getLocationOnScreen()
1114 throw (uno::RuntimeException)
1116 const SolarMutexGuard aSolarGuard;
1117 awt::Point aRet;
1119 if( mpParent )
1121 const Point aPos = mpParent->mrParent.GetItemRect(mpParent->mnId).TopLeft();
1122 const Point aScreenPos( mpParent->mrParent.OutputToAbsoluteScreenPixel( aPos ) );
1124 aRet.X = aScreenPos.X();
1125 aRet.Y = aScreenPos.Y();
1128 return aRet;
1131 // -----------------------------------------------------------------------------
1133 awt::Size SAL_CALL ValueItemAcc::getSize()
1134 throw (uno::RuntimeException)
1136 const awt::Rectangle aRect( getBounds() );
1137 awt::Size aRet;
1139 aRet.Width = aRect.Width;
1140 aRet.Height = aRect.Height;
1142 return aRet;
1145 // -----------------------------------------------------------------------------
1147 void SAL_CALL ValueItemAcc::grabFocus()
1148 throw (uno::RuntimeException)
1150 // nothing to do
1153 // -----------------------------------------------------------------------------
1155 uno::Any SAL_CALL ValueItemAcc::getAccessibleKeyBinding()
1156 throw (uno::RuntimeException)
1158 return uno::Any();
1161 // -----------------------------------------------------------------------------
1163 sal_Int32 SAL_CALL ValueItemAcc::getForeground( )
1164 throw (uno::RuntimeException)
1166 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowTextColor().GetColor();
1167 return static_cast<sal_Int32>(nColor);
1170 // -----------------------------------------------------------------------------
1172 sal_Int32 SAL_CALL ValueItemAcc::getBackground( )
1173 throw (uno::RuntimeException)
1175 sal_uInt32 nColor;
1176 if (mpParent && mpParent->meType == VALUESETITEM_COLOR)
1177 nColor = mpParent->maColor.GetColor();
1178 else
1179 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
1180 return static_cast<sal_Int32>(nColor);
1183 // -----------------------------------------------------------------------------
1185 sal_Int64 SAL_CALL ValueItemAcc::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw( uno::RuntimeException )
1187 sal_Int64 nRet;
1189 if( ( rId.getLength() == 16 ) && ( 0 == memcmp( ValueItemAcc::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) )
1190 nRet = reinterpret_cast< sal_Int64 >( this );
1191 else
1192 nRet = 0;
1194 return nRet;
1197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */