bump product version to 4.2.0.1
[LibreOffice.git] / svtools / source / control / toolbarmenuacc.cxx
blobe0d2dd5dffd9e6e3dd1cea5975addef417864918
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 .
21 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
22 #include <com/sun/star/accessibility/AccessibleRole.hpp>
23 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
25 #include <unotools/accessiblestatesethelper.hxx>
27 #include <vcl/svapp.hxx>
29 #include "svtools/toolbarmenu.hxx"
31 #include "toolbarmenuimp.hxx"
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::accessibility;
39 namespace svtools {
41 // ------------------
42 // - ToolbarMenuAcc -
43 // ------------------
45 ToolbarMenuAcc::ToolbarMenuAcc( ToolbarMenu_Impl& rParent )
46 : ToolbarMenuAccComponentBase(m_aMutex)
47 , mpParent( &rParent )
48 , mbIsFocused(false)
50 mpParent->mrMenu.AddEventListener( LINK( this, ToolbarMenuAcc, WindowEventListener ) );
53 // -----------------------------------------------------------------------------
55 ToolbarMenuAcc::~ToolbarMenuAcc()
57 if( mpParent )
58 mpParent->mrMenu.RemoveEventListener( LINK( this, ToolbarMenuAcc, WindowEventListener ) );
61 // -----------------------------------------------------------------------
63 IMPL_LINK( ToolbarMenuAcc, WindowEventListener, VclSimpleEvent*, pEvent )
65 DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
67 /* Ignore VCLEVENT_WINDOW_ENDPOPUPMODE, because the UNO accessibility wrapper
68 * might have been destroyed by the previous VCLEventListener (if no AT tool
69 * is running), e.g. sub-toolbars in impress.
71 if ( mpParent && pEvent && pEvent->ISA( VclWindowEvent ) && (pEvent->GetId() != VCLEVENT_WINDOW_ENDPOPUPMODE) )
73 DBG_ASSERT( ((VclWindowEvent*)pEvent)->GetWindow(), "Window???" );
74 if( !((VclWindowEvent*)pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() || ( pEvent->GetId() == VCLEVENT_OBJECT_DYING ) )
76 ProcessWindowEvent( *(VclWindowEvent*)pEvent );
79 return 0;
82 // -----------------------------------------------------------------------
84 void ToolbarMenuAcc::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
86 switch ( rVclWindowEvent.GetId() )
88 case VCLEVENT_OBJECT_DYING:
90 mpParent->mrMenu.RemoveEventListener( LINK( this, ToolbarMenuAcc, WindowEventListener ) );
91 mpParent = 0;
93 break;
95 case VCLEVENT_WINDOW_GETFOCUS:
97 if( !mbIsFocused )
99 mpParent->notifyHighlightedEntry();
100 mbIsFocused = true;
103 break;
104 case VCLEVENT_WINDOW_LOSEFOCUS:
106 if( mbIsFocused )
108 mbIsFocused = false;
111 break;
112 default:
115 break;
119 // -----------------------------------------------------------------------
121 void ToolbarMenuAcc::FireAccessibleEvent( short nEventId, const Any& rOldValue, const Any& rNewValue )
123 if( nEventId )
125 EventListenerVector aTmpListeners( mxEventListeners );
126 AccessibleEventObject aEvtObject;
128 aEvtObject.EventId = nEventId;
129 aEvtObject.Source = static_cast<XWeak*>(this);
130 aEvtObject.NewValue = rNewValue;
131 aEvtObject.OldValue = rOldValue;
133 for (EventListenerVector::const_iterator aIter( aTmpListeners.begin() ), aEnd( aTmpListeners.end() );
134 aIter != aEnd ; ++aIter)
138 (*aIter)->notifyEvent( aEvtObject );
140 catch( Exception& )
147 // -----------------------------------------------------------------------------
149 Reference< XAccessibleContext > SAL_CALL ToolbarMenuAcc::getAccessibleContext() throw (RuntimeException)
151 ThrowIfDisposed();
152 return this;
155 // -----------------------------------------------------------------------------
157 sal_Int32 SAL_CALL ToolbarMenuAcc::getAccessibleChildCount() throw (RuntimeException)
159 const SolarMutexGuard aSolarGuard;
160 ThrowIfDisposed();
162 return mpParent->getAccessibleChildCount();
165 // -----------------------------------------------------------------------------
167 Reference< XAccessible > SAL_CALL ToolbarMenuAcc::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
169 const SolarMutexGuard aSolarGuard;
170 ThrowIfDisposed();
172 return mpParent->getAccessibleChild(i);
175 // -----------------------------------------------------------------------------
177 Reference< XAccessible > SAL_CALL ToolbarMenuAcc::getAccessibleParent() throw (RuntimeException)
179 ThrowIfDisposed();
180 const SolarMutexGuard aSolarGuard;
182 Reference< XAccessible > xRet;
184 Window* pParent = mpParent->mrMenu.GetParent();
185 if( pParent )
186 xRet = pParent->GetAccessible();
188 return xRet;
191 // -----------------------------------------------------------------------------
193 sal_Int32 SAL_CALL ToolbarMenuAcc::getAccessibleIndexInParent() throw (RuntimeException)
195 const SolarMutexGuard aSolarGuard;
196 ThrowIfDisposed();
198 Window* pParent = mpParent->mrMenu.GetParent();
199 if( pParent )
201 for( sal_uInt16 i = 0, nCount = pParent->GetChildCount(); i < nCount ; i++ )
203 if( pParent->GetChild( i ) == &mpParent->mrMenu )
204 return i;
208 return 0;
211 // -----------------------------------------------------------------------------
213 sal_Int16 SAL_CALL ToolbarMenuAcc::getAccessibleRole() throw (RuntimeException)
215 ThrowIfDisposed();
216 return AccessibleRole::LIST;
219 // -----------------------------------------------------------------------------
221 OUString SAL_CALL ToolbarMenuAcc::getAccessibleDescription() throw (RuntimeException)
223 ThrowIfDisposed();
224 return OUString( "ToolbarMenu" );
227 // -----------------------------------------------------------------------------
229 OUString SAL_CALL ToolbarMenuAcc::getAccessibleName() throw (RuntimeException)
231 ThrowIfDisposed();
232 const SolarMutexGuard aSolarGuard;
233 OUString aRet;
235 if( mpParent )
236 aRet = mpParent->mrMenu.GetAccessibleName();
238 if( aRet.isEmpty() )
240 Window* pLabel = mpParent->mrMenu.GetAccessibleRelationLabeledBy();
241 if( pLabel && pLabel != &mpParent->mrMenu )
242 aRet = OutputDevice::GetNonMnemonicString( pLabel->GetText() );
245 return aRet;
248 // -----------------------------------------------------------------------------
250 Reference< XAccessibleRelationSet > SAL_CALL ToolbarMenuAcc::getAccessibleRelationSet() throw (RuntimeException)
252 ThrowIfDisposed();
253 return Reference< XAccessibleRelationSet >();
256 // -----------------------------------------------------------------------------
258 Reference< XAccessibleStateSet > SAL_CALL ToolbarMenuAcc::getAccessibleStateSet() throw (RuntimeException)
260 ThrowIfDisposed();
261 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
263 // Set some states.
264 pStateSet->AddState (AccessibleStateType::ENABLED);
265 pStateSet->AddState (AccessibleStateType::SENSITIVE);
266 pStateSet->AddState (AccessibleStateType::SHOWING);
267 pStateSet->AddState (AccessibleStateType::VISIBLE);
268 pStateSet->AddState (AccessibleStateType::MANAGES_DESCENDANTS);
269 pStateSet->AddState (AccessibleStateType::FOCUSABLE);
270 if (mbIsFocused)
271 pStateSet->AddState (AccessibleStateType::FOCUSED);
273 return pStateSet;
276 // -----------------------------------------------------------------------------
278 Locale SAL_CALL ToolbarMenuAcc::getLocale() throw (IllegalAccessibleComponentStateException, RuntimeException)
280 ThrowIfDisposed();
281 const SolarMutexGuard aSolarGuard;
282 const OUString aEmptyStr;
283 Reference< XAccessible > xParent( getAccessibleParent() );
284 Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
286 if( xParent.is() )
288 Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
290 if( xParentContext.is() )
291 aRet = xParentContext->getLocale ();
294 return aRet;
297 // -----------------------------------------------------------------------------
299 void SAL_CALL ToolbarMenuAcc::addAccessibleEventListener( const Reference< XAccessibleEventListener >& rxListener ) throw (RuntimeException)
301 ThrowIfDisposed();
302 ::osl::MutexGuard aGuard(m_aMutex);
304 if( rxListener.is() )
306 EventListenerVector::const_iterator aIter = mxEventListeners.begin();
307 bool bFound = false;
309 while( !bFound && ( aIter != mxEventListeners.end() ) )
311 if( *aIter == rxListener )
312 bFound = true;
313 else
314 ++aIter;
317 if (!bFound)
318 mxEventListeners.push_back( rxListener );
322 // -----------------------------------------------------------------------------
324 void SAL_CALL ToolbarMenuAcc::removeAccessibleEventListener( const Reference< XAccessibleEventListener >& rxListener ) throw (RuntimeException)
326 ThrowIfDisposed();
327 ::osl::MutexGuard aGuard(m_aMutex);
329 if( rxListener.is() )
331 EventListenerVector::iterator aIter = std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener);
332 if (aIter != mxEventListeners.end())
333 mxEventListeners.erase(aIter);
337 // -----------------------------------------------------------------------------
339 sal_Bool SAL_CALL ToolbarMenuAcc::containsPoint( const awt::Point& aPoint ) throw (RuntimeException)
341 ThrowIfDisposed();
342 const awt::Rectangle aRect( getBounds() );
343 const Point aSize( aRect.Width, aRect.Height );
344 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
346 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
349 // -----------------------------------------------------------------------------
351 Reference< XAccessible > SAL_CALL ToolbarMenuAcc::getAccessibleAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
353 const SolarMutexGuard aSolarGuard;
354 ThrowIfDisposed();
356 Reference< XAccessible > xRet;
358 const Point aVclPoint( aPoint.X, aPoint.Y );
360 const int nEntryCount = mpParent->maEntryVector.size();
361 for( int nEntry = 0; (nEntry < nEntryCount) && !xRet.is(); nEntry++ )
363 ToolbarMenuEntry* pEntry = mpParent->maEntryVector[nEntry];
364 if( pEntry && pEntry->maRect.IsInside( aVclPoint ) )
366 if( pEntry->mpControl )
368 awt::Point aChildPoint( aPoint.X - pEntry->maRect.Left(), aPoint.Y - pEntry->maRect.Top() );
369 Reference< XAccessibleComponent > xComp( pEntry->GetAccessible(true), UNO_QUERY_THROW );
370 xRet = xComp->getAccessibleAtPoint(aChildPoint);
372 else
374 xRet = Reference< XAccessible >( pEntry->GetAccessible(true), UNO_QUERY );
378 return xRet;
381 // -----------------------------------------------------------------------------
383 awt::Rectangle SAL_CALL ToolbarMenuAcc::getBounds() throw (RuntimeException)
385 ThrowIfDisposed();
386 const SolarMutexGuard aSolarGuard;
387 const Point aOutPos( mpParent->mrMenu.GetPosPixel() );
388 const Size aOutSize( mpParent->mrMenu.GetOutputSizePixel() );
389 awt::Rectangle aRet;
391 aRet.X = aOutPos.X();
392 aRet.Y = aOutPos.Y();
393 aRet.Width = aOutSize.Width();
394 aRet.Height = aOutSize.Height();
396 return aRet;
399 // -----------------------------------------------------------------------------
401 awt::Point SAL_CALL ToolbarMenuAcc::getLocation() throw (RuntimeException)
403 ThrowIfDisposed();
404 const SolarMutexGuard aSolarGuard;
405 const Point aOutPos( mpParent->mrMenu.GetPosPixel() );
406 return awt::Point( aOutPos.X(), aOutPos.Y() );
409 // -----------------------------------------------------------------------------
411 awt::Point SAL_CALL ToolbarMenuAcc::getLocationOnScreen() throw (RuntimeException)
413 ThrowIfDisposed();
414 const SolarMutexGuard aSolarGuard;
415 const Point aScreenPos( mpParent->mrMenu.OutputToAbsoluteScreenPixel( Point() ) );
416 return awt::Point( aScreenPos.X(), aScreenPos.Y() );
419 // -----------------------------------------------------------------------------
421 awt::Size SAL_CALL ToolbarMenuAcc::getSize() throw (RuntimeException)
423 ThrowIfDisposed();
424 const SolarMutexGuard aSolarGuard;
425 const Size aOutSize( mpParent->mrMenu.GetOutputSizePixel() );
426 return awt::Size( aOutSize.Width(), aOutSize.Height() );
429 // -----------------------------------------------------------------------------
431 void SAL_CALL ToolbarMenuAcc::grabFocus() throw (RuntimeException)
433 ThrowIfDisposed();
434 const SolarMutexGuard aSolarGuard;
435 mpParent->mrMenu.GrabFocus();
438 // -----------------------------------------------------------------------------
440 Any SAL_CALL ToolbarMenuAcc::getAccessibleKeyBinding() throw (RuntimeException)
442 ThrowIfDisposed();
443 return Any();
446 // -----------------------------------------------------------------------------
448 sal_Int32 SAL_CALL ToolbarMenuAcc::getForeground() throw (RuntimeException)
450 ThrowIfDisposed();
451 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetMenuTextColor().GetColor();
452 return static_cast<sal_Int32>(nColor);
455 // -----------------------------------------------------------------------------
457 sal_Int32 SAL_CALL ToolbarMenuAcc::getBackground() throw (RuntimeException)
459 ThrowIfDisposed();
460 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetMenuColor().GetColor();
461 return static_cast<sal_Int32>(nColor);
464 // -----------------------------------------------------------------------------
466 void SAL_CALL ToolbarMenuAcc::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
468 const SolarMutexGuard aSolarGuard;
469 ThrowIfDisposed();
471 mpParent->selectAccessibleChild( nChildIndex );
474 // -----------------------------------------------------------------------------
476 sal_Bool SAL_CALL ToolbarMenuAcc::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
478 const SolarMutexGuard aSolarGuard;
479 ThrowIfDisposed();
480 return mpParent->isAccessibleChildSelected( nChildIndex );
483 // -----------------------------------------------------------------------------
485 void SAL_CALL ToolbarMenuAcc::clearAccessibleSelection() throw (RuntimeException)
487 const SolarMutexGuard aSolarGuard;
488 ThrowIfDisposed();
489 mpParent->clearAccessibleSelection();
492 // -----------------------------------------------------------------------------
494 void SAL_CALL ToolbarMenuAcc::selectAllAccessibleChildren() throw (RuntimeException)
496 ThrowIfDisposed();
497 // unsupported due to single selection only
500 // -----------------------------------------------------------------------------
502 sal_Int32 SAL_CALL ToolbarMenuAcc::getSelectedAccessibleChildCount() throw (RuntimeException)
504 const SolarMutexGuard aSolarGuard;
505 ThrowIfDisposed();
507 return mpParent->mnHighlightedEntry != -1 ? 1 : 0;
510 // -----------------------------------------------------------------------------
512 Reference< XAccessible > SAL_CALL ToolbarMenuAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
514 ThrowIfDisposed();
515 const SolarMutexGuard aSolarGuard;
517 if( (mpParent->mnHighlightedEntry != -1) && (nSelectedChildIndex == 0) )
519 ToolbarMenuEntry* pEntry = mpParent->maEntryVector[ mpParent->mnHighlightedEntry ];
520 if( pEntry )
522 if( pEntry->mpControl )
524 Reference< XAccessibleSelection > xSel( pEntry->GetAccessible(true), UNO_QUERY_THROW );
525 return xSel->getSelectedAccessibleChild(0);
527 else
528 return Reference< XAccessible >( pEntry->GetAccessible(true), UNO_QUERY );
532 throw IndexOutOfBoundsException();
535 // -----------------------------------------------------------------------------
537 void SAL_CALL ToolbarMenuAcc::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
539 ThrowIfDisposed();
540 const SolarMutexGuard aSolarGuard;
541 // Because of the single selection we can reset the whole selection when
542 // the specified child is currently selected.
543 if (isAccessibleChildSelected(nChildIndex))
544 mpParent->clearAccessibleSelection();
547 // -----------------------------------------------------------------------------
549 void SAL_CALL ToolbarMenuAcc::disposing (void)
551 EventListenerVector aListenerListCopy;
554 // Make a copy of the list and clear the original.
555 const SolarMutexGuard aSolarGuard;
556 ::osl::MutexGuard aGuard (m_aMutex);
557 aListenerListCopy = mxEventListeners;
558 mxEventListeners.clear();
560 // Reset the pointer to the parent. It has to be the one who has
561 // disposed us because he is dying.
562 mpParent = NULL;
565 // Inform all listeners that this objects is disposing.
566 EventListenerVector::const_iterator aListenerIterator (aListenerListCopy.begin());
567 EventObject aEvent (static_cast<XAccessible*>(this));
568 while(aListenerIterator != aListenerListCopy.end())
572 (*aListenerIterator)->disposing (aEvent);
574 catch( Exception& )
576 // Ignore exceptions.
579 ++aListenerIterator;
583 void ToolbarMenuAcc::ThrowIfDisposed (void) throw (DisposedException)
585 if(rBHelper.bDisposed || rBHelper.bInDispose || !mpParent)
587 throw DisposedException ("object has been already disposed", static_cast<XWeak*>(this));
591 // -----------------------
592 // - ToolbarMenuEntryAcc -
593 // -----------------------
595 ToolbarMenuEntryAcc::ToolbarMenuEntryAcc( ToolbarMenuEntry* pParent )
596 : ToolbarMenuEntryAccBase( m_aMutex )
597 , mpParent( pParent )
601 // -----------------------------------------------------------------------------
603 ToolbarMenuEntryAcc::~ToolbarMenuEntryAcc()
607 // -----------------------------------------------------------------------
609 void SAL_CALL ToolbarMenuEntryAcc::disposing (void)
611 EventListenerVector aListenerListCopy;
614 // Make a copy of the list and clear the original.
615 const SolarMutexGuard aSolarGuard;
616 ::osl::MutexGuard aGuard (m_aMutex);
617 aListenerListCopy = mxEventListeners;
618 mxEventListeners.clear();
620 // Reset the pointer to the parent. It has to be the one who has
621 // disposed us because he is dying.
622 mpParent = NULL;
625 // Inform all listeners that this objects is disposing.
626 EventListenerVector::const_iterator aListenerIterator (aListenerListCopy.begin());
627 EventObject aEvent (static_cast<XAccessible*>(this));
628 while(aListenerIterator != aListenerListCopy.end())
632 (*aListenerIterator)->disposing (aEvent);
634 catch( Exception& )
636 // Ignore exceptions.
639 ++aListenerIterator;
642 // -----------------------------------------------------------------------------
644 Reference< XAccessibleContext > SAL_CALL ToolbarMenuEntryAcc::getAccessibleContext() throw (RuntimeException)
646 return this;
649 // -----------------------------------------------------------------------------
651 sal_Int32 SAL_CALL ToolbarMenuEntryAcc::getAccessibleChildCount() throw (RuntimeException)
653 return 0;
656 // -----------------------------------------------------------------------------
658 Reference< XAccessible > SAL_CALL ToolbarMenuEntryAcc::getAccessibleChild( sal_Int32 ) throw (IndexOutOfBoundsException, RuntimeException)
660 throw IndexOutOfBoundsException();
663 // -----------------------------------------------------------------------------
665 Reference< XAccessible > SAL_CALL ToolbarMenuEntryAcc::getAccessibleParent() throw (RuntimeException)
667 const SolarMutexGuard aSolarGuard;
668 Reference< XAccessible > xRet;
670 if( mpParent )
671 xRet = mpParent->mrMenu.GetAccessible();
673 return xRet;
676 // -----------------------------------------------------------------------------
678 sal_Int32 SAL_CALL ToolbarMenuEntryAcc::getAccessibleIndexInParent() throw (RuntimeException)
680 const SolarMutexGuard aSolarGuard;
681 // The index defaults to -1 to indicate the child does not belong to its
682 // parent.
683 sal_Int32 nIndexInParent = -1;
685 if( mpParent )
687 Reference< XAccessibleContext > xParent( mpParent->mrMenu.GetAccessible(), UNO_QUERY );
689 if( xParent.is() )
691 Reference< XAccessible > xThis( this );
693 const sal_Int32 nCount = xParent->getAccessibleChildCount();
694 for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
696 if( xParent->getAccessibleChild(nIndex) == xThis )
698 nIndexInParent = nIndex;
699 break;
705 return nIndexInParent;
708 // -----------------------------------------------------------------------------
710 sal_Int16 SAL_CALL ToolbarMenuEntryAcc::getAccessibleRole() throw (RuntimeException)
712 return AccessibleRole::LIST_ITEM;
715 // -----------------------------------------------------------------------------
717 OUString SAL_CALL ToolbarMenuEntryAcc::getAccessibleDescription() throw (RuntimeException)
719 return OUString();
722 // -----------------------------------------------------------------------------
724 OUString SAL_CALL ToolbarMenuEntryAcc::getAccessibleName() throw (RuntimeException)
726 const SolarMutexGuard aSolarGuard;
727 OUString aRet;
729 if( mpParent )
731 aRet = mpParent->maText;
733 if( aRet.isEmpty() )
735 aRet = "Item ";
736 aRet += OUString::number( mpParent->mnEntryId );
740 return aRet;
743 // -----------------------------------------------------------------------------
745 Reference< XAccessibleRelationSet > SAL_CALL ToolbarMenuEntryAcc::getAccessibleRelationSet() throw (RuntimeException)
747 return Reference< XAccessibleRelationSet >();
750 // -----------------------------------------------------------------------------
752 Reference< XAccessibleStateSet > SAL_CALL ToolbarMenuEntryAcc::getAccessibleStateSet() throw (RuntimeException)
754 const SolarMutexGuard aSolarGuard;
755 ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper;
757 if( mpParent )
759 pStateSet->AddState (AccessibleStateType::ENABLED);
760 pStateSet->AddState (AccessibleStateType::SENSITIVE);
761 pStateSet->AddState (AccessibleStateType::SHOWING);
762 pStateSet->AddState (AccessibleStateType::VISIBLE);
763 pStateSet->AddState (AccessibleStateType::TRANSIENT);
764 if( mpParent->mnEntryId != TITLE_ID )
766 pStateSet->AddState( AccessibleStateType::SELECTABLE );
768 // SELECTED
769 if( mpParent->mrMenu.getHighlightedEntryId() == mpParent->mnEntryId )
770 pStateSet->AddState( AccessibleStateType::SELECTED );
774 return pStateSet;
777 // -----------------------------------------------------------------------------
779 Locale SAL_CALL ToolbarMenuEntryAcc::getLocale() throw (IllegalAccessibleComponentStateException, RuntimeException)
781 const OUString aEmptyStr;
782 Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
784 Reference< XAccessible > xParent( getAccessibleParent() );
785 if( xParent.is() )
787 Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
789 if( xParentContext.is() )
790 aRet = xParentContext->getLocale();
793 return aRet;
796 // -----------------------------------------------------------------------------
798 void SAL_CALL ToolbarMenuEntryAcc::addAccessibleEventListener( const Reference< XAccessibleEventListener >& rxListener ) throw (RuntimeException)
800 const ::osl::MutexGuard aGuard( maMutex );
802 if( rxListener.is() )
804 for (EventListenerVector::const_iterator aIter( mxEventListeners.begin() ), aEnd( mxEventListeners.end() );
805 aIter != aEnd; ++aIter )
807 if( *aIter == rxListener )
808 return;
810 // listener not found so add it
811 mxEventListeners.push_back( rxListener );
815 // -----------------------------------------------------------------------------
817 void SAL_CALL ToolbarMenuEntryAcc::removeAccessibleEventListener( const Reference< XAccessibleEventListener >& rxListener ) throw (RuntimeException)
819 const ::osl::MutexGuard aGuard( maMutex );
821 if( rxListener.is() )
823 EventListenerVector::iterator aIter = std::find(mxEventListeners.begin(), mxEventListeners.end(), rxListener);
824 if (aIter != mxEventListeners.end())
825 mxEventListeners.erase(aIter);
829 // -----------------------------------------------------------------------------
831 sal_Bool SAL_CALL ToolbarMenuEntryAcc::containsPoint( const awt::Point& aPoint ) throw (RuntimeException)
833 const awt::Rectangle aRect( getBounds() );
834 const Point aSize( aRect.Width, aRect.Height );
835 const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
837 return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
840 // -----------------------------------------------------------------------------
842 Reference< XAccessible > SAL_CALL ToolbarMenuEntryAcc::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException)
844 Reference< XAccessible > xRet;
845 return xRet;
848 // -----------------------------------------------------------------------------
850 awt::Rectangle SAL_CALL ToolbarMenuEntryAcc::getBounds() throw (RuntimeException)
852 const SolarMutexGuard aSolarGuard;
853 awt::Rectangle aRet;
855 if( mpParent )
857 Rectangle aRect( mpParent->maRect );
858 Point aOrigin;
859 Rectangle aParentRect( aOrigin, mpParent->mrMenu.GetOutputSizePixel() );
861 aRect.Intersection( aParentRect );
863 aRet.X = aRect.Left();
864 aRet.Y = aRect.Top();
865 aRet.Width = aRect.GetWidth();
866 aRet.Height = aRect.GetHeight();
869 return aRet;
872 // -----------------------------------------------------------------------------
874 awt::Point SAL_CALL ToolbarMenuEntryAcc::getLocation() throw (RuntimeException)
876 const awt::Rectangle aRect( getBounds() );
877 return awt::Point( aRect.X, aRect.Y );
880 // -----------------------------------------------------------------------------
882 awt::Point SAL_CALL ToolbarMenuEntryAcc::getLocationOnScreen() throw (RuntimeException)
884 const SolarMutexGuard aSolarGuard;
885 awt::Point aRet;
887 if( mpParent )
889 const Point aScreenPos( mpParent->mrMenu.OutputToAbsoluteScreenPixel( mpParent->maRect.TopLeft() ) );
891 aRet.X = aScreenPos.X();
892 aRet.Y = aScreenPos.Y();
895 return aRet;
898 // -----------------------------------------------------------------------------
900 awt::Size SAL_CALL ToolbarMenuEntryAcc::getSize() throw (RuntimeException)
902 const awt::Rectangle aRect( getBounds() );
903 awt::Size aRet;
905 aRet.Width = aRect.Width;
906 aRet.Height = aRect.Height;
908 return aRet;
911 // -----------------------------------------------------------------------------
913 void SAL_CALL ToolbarMenuEntryAcc::grabFocus() throw (RuntimeException)
915 // nothing to do
918 // -----------------------------------------------------------------------------
920 Any SAL_CALL ToolbarMenuEntryAcc::getAccessibleKeyBinding() throw (RuntimeException)
922 return Any();
925 // -----------------------------------------------------------------------------
927 sal_Int32 SAL_CALL ToolbarMenuEntryAcc::getForeground( ) throw (RuntimeException)
929 return static_cast<sal_Int32>(Application::GetSettings().GetStyleSettings().GetMenuTextColor().GetColor());
932 // -----------------------------------------------------------------------------
934 sal_Int32 SAL_CALL ToolbarMenuEntryAcc::getBackground( ) throw (RuntimeException)
936 return static_cast<sal_Int32>(Application::GetSettings().GetStyleSettings().GetMenuColor().GetColor());
941 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */