1*5900e8ecSAndrew Rist /**************************************************************
2*5900e8ecSAndrew Rist  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
28cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
29cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <vcl/svapp.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "svtools/toolbarmenu.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "toolbarmenuimp.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using ::rtl::OUString;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using namespace ::com::sun::star;
42cdf0e10cSrcweir using namespace ::com::sun::star::uno;
43cdf0e10cSrcweir using namespace ::com::sun::star::lang;
44cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace svtools {
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // ------------------
49cdf0e10cSrcweir // - ToolbarMenuAcc -
50cdf0e10cSrcweir // ------------------
51cdf0e10cSrcweir 
ToolbarMenuAcc(ToolbarMenu_Impl & rParent)52cdf0e10cSrcweir ToolbarMenuAcc::ToolbarMenuAcc( ToolbarMenu_Impl& rParent )
53cdf0e10cSrcweir : ToolbarMenuAccComponentBase(m_aMutex)
54cdf0e10cSrcweir , mpParent( &rParent )
55cdf0e10cSrcweir , mbIsFocused(false)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	mpParent->mrMenu.AddEventListener( LINK( this, ToolbarMenuAcc, WindowEventListener ) );
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir // -----------------------------------------------------------------------------
61cdf0e10cSrcweir 
~ToolbarMenuAcc()62cdf0e10cSrcweir ToolbarMenuAcc::~ToolbarMenuAcc()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	if( mpParent )
65cdf0e10cSrcweir 		mpParent->mrMenu.RemoveEventListener( LINK( this, ToolbarMenuAcc, WindowEventListener ) );
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir // -----------------------------------------------------------------------
69cdf0e10cSrcweir 
IMPL_LINK(ToolbarMenuAcc,WindowEventListener,VclSimpleEvent *,pEvent)70cdf0e10cSrcweir IMPL_LINK( ToolbarMenuAcc, WindowEventListener, VclSimpleEvent*, pEvent )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     /* Ignore VCLEVENT_WINDOW_ENDPOPUPMODE, because the UNO accessibility wrapper
75cdf0e10cSrcweir      * might have been destroyed by the previous VCLEventListener (if no AT tool
76cdf0e10cSrcweir      * is running), e.g. sub-toolbars in impress.
77cdf0e10cSrcweir      */
78cdf0e10cSrcweir 	if ( mpParent && pEvent && pEvent->ISA( VclWindowEvent ) && (pEvent->GetId() != VCLEVENT_WINDOW_ENDPOPUPMODE) )
79cdf0e10cSrcweir 	{
80cdf0e10cSrcweir 		DBG_ASSERT( ((VclWindowEvent*)pEvent)->GetWindow(), "Window???" );
81cdf0e10cSrcweir         if( !((VclWindowEvent*)pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() || ( pEvent->GetId() == VCLEVENT_OBJECT_DYING ) )
82cdf0e10cSrcweir 		{
83cdf0e10cSrcweir 		    ProcessWindowEvent( *(VclWindowEvent*)pEvent );
84cdf0e10cSrcweir 		}
85cdf0e10cSrcweir 	}
86cdf0e10cSrcweir 	return 0;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir // -----------------------------------------------------------------------
90cdf0e10cSrcweir 
ProcessWindowEvent(const VclWindowEvent & rVclWindowEvent)91cdf0e10cSrcweir void ToolbarMenuAcc::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir 	Any aOldValue, aNewValue;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	switch ( rVclWindowEvent.GetId() )
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir         case VCLEVENT_OBJECT_DYING:
98cdf0e10cSrcweir         {
99cdf0e10cSrcweir 		    mpParent->mrMenu.RemoveEventListener( LINK( this, ToolbarMenuAcc, WindowEventListener ) );
100cdf0e10cSrcweir 	        mpParent = 0;
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir         break;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 		case VCLEVENT_WINDOW_GETFOCUS:
105cdf0e10cSrcweir 		{
106cdf0e10cSrcweir 			if( !mbIsFocused )
107cdf0e10cSrcweir 			{
108cdf0e10cSrcweir 				mpParent->notifyHighlightedEntry();
109cdf0e10cSrcweir 				mbIsFocused = true;
110cdf0e10cSrcweir 			}
111cdf0e10cSrcweir 		}
112cdf0e10cSrcweir 		break;
113cdf0e10cSrcweir 		case VCLEVENT_WINDOW_LOSEFOCUS:
114cdf0e10cSrcweir 		{
115cdf0e10cSrcweir 			if( mbIsFocused )
116cdf0e10cSrcweir 			{
117cdf0e10cSrcweir 				mbIsFocused = false;
118cdf0e10cSrcweir 			}
119cdf0e10cSrcweir 		}
120cdf0e10cSrcweir 		break;
121cdf0e10cSrcweir 		default:
122cdf0e10cSrcweir 		{
123cdf0e10cSrcweir 		}
124cdf0e10cSrcweir 		break;
125cdf0e10cSrcweir 	}
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir // -----------------------------------------------------------------------
129cdf0e10cSrcweir 
FireAccessibleEvent(short nEventId,const Any & rOldValue,const Any & rNewValue)130cdf0e10cSrcweir void ToolbarMenuAcc::FireAccessibleEvent( short nEventId, const Any& rOldValue, const Any& rNewValue )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     if( nEventId )
133cdf0e10cSrcweir     {
134cdf0e10cSrcweir         EventListenerVector                  aTmpListeners( mxEventListeners );
135cdf0e10cSrcweir         EventListenerVector::const_iterator  aIter( aTmpListeners.begin() );
136cdf0e10cSrcweir         AccessibleEventObject aEvtObject;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         aEvtObject.EventId = nEventId;
139cdf0e10cSrcweir         aEvtObject.Source = static_cast<XWeak*>(this);
140cdf0e10cSrcweir         aEvtObject.NewValue = rNewValue;
141cdf0e10cSrcweir 	    aEvtObject.OldValue = rOldValue;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		while( aIter != aTmpListeners.end() )
144cdf0e10cSrcweir         {
145cdf0e10cSrcweir 			try
146cdf0e10cSrcweir 			{
147cdf0e10cSrcweir 				(*aIter)->notifyEvent( aEvtObject );
148cdf0e10cSrcweir 			}
149cdf0e10cSrcweir 			catch( Exception& )
150cdf0e10cSrcweir 			{
151cdf0e10cSrcweir 			}
152cdf0e10cSrcweir 
153cdf0e10cSrcweir             aIter++;
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir // -----------------------------------------------------------------------------
159cdf0e10cSrcweir 
getAccessibleContext()160cdf0e10cSrcweir Reference< XAccessibleContext > SAL_CALL ToolbarMenuAcc::getAccessibleContext() throw (RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     ThrowIfDisposed();
163cdf0e10cSrcweir     return this;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir // -----------------------------------------------------------------------------
167cdf0e10cSrcweir 
getAccessibleChildCount()168cdf0e10cSrcweir sal_Int32 SAL_CALL ToolbarMenuAcc::getAccessibleChildCount() throw (RuntimeException)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
171cdf0e10cSrcweir     ThrowIfDisposed();
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     return mpParent->getAccessibleChildCount();
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir // -----------------------------------------------------------------------------
177cdf0e10cSrcweir 
getAccessibleChild(sal_Int32 i)178cdf0e10cSrcweir Reference< XAccessible > SAL_CALL ToolbarMenuAcc::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
181cdf0e10cSrcweir     ThrowIfDisposed();
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	return mpParent->getAccessibleChild(i);
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir // -----------------------------------------------------------------------------
187cdf0e10cSrcweir 
getAccessibleParent()188cdf0e10cSrcweir Reference< XAccessible > SAL_CALL ToolbarMenuAcc::getAccessibleParent() throw (RuntimeException)
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     ThrowIfDisposed();
191cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	Reference< XAccessible > xRet;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     Window* pParent = mpParent->mrMenu.GetParent();
196cdf0e10cSrcweir     if( pParent )
197cdf0e10cSrcweir         xRet = pParent->GetAccessible();
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     return xRet;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir // -----------------------------------------------------------------------------
203cdf0e10cSrcweir 
getAccessibleIndexInParent()204cdf0e10cSrcweir sal_Int32 SAL_CALL ToolbarMenuAcc::getAccessibleIndexInParent() throw (RuntimeException)
205cdf0e10cSrcweir {
206cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
207cdf0e10cSrcweir     ThrowIfDisposed();
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 	Window* pParent = mpParent->mrMenu.GetParent();
210cdf0e10cSrcweir     if( pParent )
211cdf0e10cSrcweir     {
212cdf0e10cSrcweir         for( sal_uInt16 i = 0, nCount = pParent->GetChildCount(); i < nCount ; i++ )
213cdf0e10cSrcweir         {
214cdf0e10cSrcweir             if( pParent->GetChild( i ) == &mpParent->mrMenu )
215cdf0e10cSrcweir 				return i;
216cdf0e10cSrcweir         }
217cdf0e10cSrcweir     }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     return 0;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir // -----------------------------------------------------------------------------
223cdf0e10cSrcweir 
getAccessibleRole()224cdf0e10cSrcweir sal_Int16 SAL_CALL ToolbarMenuAcc::getAccessibleRole() throw (RuntimeException)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     ThrowIfDisposed();
227cdf0e10cSrcweir     return AccessibleRole::LIST;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir // -----------------------------------------------------------------------------
231cdf0e10cSrcweir 
getAccessibleDescription()232cdf0e10cSrcweir OUString SAL_CALL ToolbarMenuAcc::getAccessibleDescription() throw (RuntimeException)
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     ThrowIfDisposed();
235cdf0e10cSrcweir     return OUString( RTL_CONSTASCII_USTRINGPARAM( "ToolbarMenu" ) );
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir // -----------------------------------------------------------------------------
239cdf0e10cSrcweir 
getAccessibleName()240cdf0e10cSrcweir OUString SAL_CALL ToolbarMenuAcc::getAccessibleName() throw (RuntimeException)
241cdf0e10cSrcweir {
242cdf0e10cSrcweir     ThrowIfDisposed();
243cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
244cdf0e10cSrcweir     OUString aRet;
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     if( mpParent )
247cdf0e10cSrcweir 		aRet = mpParent->mrMenu.GetAccessibleName();
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     if( !aRet.getLength() )
250cdf0e10cSrcweir     {
251cdf0e10cSrcweir         Window* pLabel = mpParent->mrMenu.GetAccessibleRelationLabeledBy();
252cdf0e10cSrcweir         if( pLabel && pLabel != &mpParent->mrMenu )
253cdf0e10cSrcweir 			aRet = OutputDevice::GetNonMnemonicString( pLabel->GetText() );
254cdf0e10cSrcweir     }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     return aRet;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir // -----------------------------------------------------------------------------
260cdf0e10cSrcweir 
getAccessibleRelationSet()261cdf0e10cSrcweir Reference< XAccessibleRelationSet > SAL_CALL ToolbarMenuAcc::getAccessibleRelationSet() throw (RuntimeException)
262cdf0e10cSrcweir {
263cdf0e10cSrcweir     ThrowIfDisposed();
264cdf0e10cSrcweir     return Reference< XAccessibleRelationSet >();
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir // -----------------------------------------------------------------------------
268cdf0e10cSrcweir 
getAccessibleStateSet()269cdf0e10cSrcweir Reference< XAccessibleStateSet > SAL_CALL ToolbarMenuAcc::getAccessibleStateSet() throw (RuntimeException)
270cdf0e10cSrcweir {
271cdf0e10cSrcweir     ThrowIfDisposed();
272cdf0e10cSrcweir     ::utl::AccessibleStateSetHelper* pStateSet = new ::utl::AccessibleStateSetHelper();
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     // Set some states.
275cdf0e10cSrcweir     pStateSet->AddState (AccessibleStateType::ENABLED);
276cdf0e10cSrcweir     pStateSet->AddState (AccessibleStateType::SENSITIVE);
277cdf0e10cSrcweir     pStateSet->AddState (AccessibleStateType::SHOWING);
278cdf0e10cSrcweir     pStateSet->AddState (AccessibleStateType::VISIBLE);
279cdf0e10cSrcweir 	pStateSet->AddState (AccessibleStateType::MANAGES_DESCENDANTS);
280cdf0e10cSrcweir     pStateSet->AddState (AccessibleStateType::FOCUSABLE);
281cdf0e10cSrcweir     if (mbIsFocused)
282cdf0e10cSrcweir         pStateSet->AddState (AccessibleStateType::FOCUSED);
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     return pStateSet;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir // -----------------------------------------------------------------------------
288cdf0e10cSrcweir 
getLocale()289cdf0e10cSrcweir Locale SAL_CALL ToolbarMenuAcc::getLocale() throw (IllegalAccessibleComponentStateException, RuntimeException)
290cdf0e10cSrcweir {
291cdf0e10cSrcweir     ThrowIfDisposed();
292cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
293cdf0e10cSrcweir     const ::rtl::OUString aEmptyStr;
294cdf0e10cSrcweir     Reference< XAccessible > xParent( getAccessibleParent() );
295cdf0e10cSrcweir     Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     if( xParent.is() )
298cdf0e10cSrcweir     {
299cdf0e10cSrcweir         Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir         if( xParentContext.is() )
302cdf0e10cSrcweir             aRet = xParentContext->getLocale ();
303cdf0e10cSrcweir     }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir     return aRet;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir // -----------------------------------------------------------------------------
309cdf0e10cSrcweir 
addEventListener(const Reference<XAccessibleEventListener> & rxListener)310cdf0e10cSrcweir void SAL_CALL ToolbarMenuAcc::addEventListener( const Reference< XAccessibleEventListener >& rxListener ) throw (RuntimeException)
311cdf0e10cSrcweir {
312cdf0e10cSrcweir     ThrowIfDisposed();
313cdf0e10cSrcweir     ::osl::MutexGuard aGuard(m_aMutex);
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 	if( rxListener.is() )
316cdf0e10cSrcweir     {
317cdf0e10cSrcweir        	EventListenerVector::const_iterator aIter = mxEventListeners.begin();
318cdf0e10cSrcweir 		bool bFound = false;
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 		while( !bFound && ( aIter != mxEventListeners.end() ) )
321cdf0e10cSrcweir         {
322cdf0e10cSrcweir 			if( *aIter == rxListener )
323cdf0e10cSrcweir                 bFound = true;
324cdf0e10cSrcweir             else
325cdf0e10cSrcweir                 aIter++;
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 		if (!bFound)
329cdf0e10cSrcweir             mxEventListeners.push_back( rxListener );
330cdf0e10cSrcweir     }
331cdf0e10cSrcweir }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir // -----------------------------------------------------------------------------
334cdf0e10cSrcweir 
removeEventListener(const Reference<XAccessibleEventListener> & rxListener)335cdf0e10cSrcweir void SAL_CALL ToolbarMenuAcc::removeEventListener( const Reference< XAccessibleEventListener >& rxListener ) throw (RuntimeException)
336cdf0e10cSrcweir {
337cdf0e10cSrcweir     ThrowIfDisposed();
338cdf0e10cSrcweir     ::osl::MutexGuard aGuard(m_aMutex);
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 	if( rxListener.is() )
341cdf0e10cSrcweir     {
342cdf0e10cSrcweir        	EventListenerVector::iterator aIter = mxEventListeners.begin();
343cdf0e10cSrcweir 		bool bFound = false;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 		while( !bFound && ( aIter != mxEventListeners.end() ) )
346cdf0e10cSrcweir         {
347cdf0e10cSrcweir 			if( *aIter == rxListener )
348cdf0e10cSrcweir             {
349cdf0e10cSrcweir                 mxEventListeners.erase( aIter );
350cdf0e10cSrcweir                 bFound = true;
351cdf0e10cSrcweir             }
352cdf0e10cSrcweir             else
353cdf0e10cSrcweir                 aIter++;
354cdf0e10cSrcweir         }
355cdf0e10cSrcweir     }
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir // -----------------------------------------------------------------------------
359cdf0e10cSrcweir 
containsPoint(const awt::Point & aPoint)360cdf0e10cSrcweir sal_Bool SAL_CALL ToolbarMenuAcc::containsPoint( const awt::Point& aPoint ) throw (RuntimeException)
361cdf0e10cSrcweir {
362cdf0e10cSrcweir     ThrowIfDisposed();
363cdf0e10cSrcweir     const awt::Rectangle aRect( getBounds() );
364cdf0e10cSrcweir     const Point aSize( aRect.Width, aRect.Height );
365cdf0e10cSrcweir     const Point aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir // -----------------------------------------------------------------------------
371cdf0e10cSrcweir 
getAccessibleAtPoint(const awt::Point & aPoint)372cdf0e10cSrcweir Reference< XAccessible > SAL_CALL ToolbarMenuAcc::getAccessibleAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
373cdf0e10cSrcweir {
374cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
375cdf0e10cSrcweir     ThrowIfDisposed();
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 	Reference< XAccessible > xRet;
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 	const Point aVclPoint( aPoint.X, aPoint.Y );
380cdf0e10cSrcweir 
381cdf0e10cSrcweir 	const int nEntryCount = mpParent->maEntryVector.size();
382cdf0e10cSrcweir 	for( int nEntry = 0; (nEntry < nEntryCount) && !xRet.is(); nEntry++ )
383cdf0e10cSrcweir 	{
384cdf0e10cSrcweir 		ToolbarMenuEntry* pEntry = mpParent->maEntryVector[nEntry];
385cdf0e10cSrcweir 		if( pEntry && pEntry->maRect.IsInside( aVclPoint ) )
386cdf0e10cSrcweir 		{
387cdf0e10cSrcweir 			if( pEntry->mpControl )
388cdf0e10cSrcweir 			{
389cdf0e10cSrcweir 				awt::Point aChildPoint( aPoint.X - pEntry->maRect.Left(), aPoint.Y - pEntry->maRect.Top() );
390cdf0e10cSrcweir 				Reference< XAccessibleComponent > xComp( pEntry->GetAccessible(true), UNO_QUERY_THROW );
391cdf0e10cSrcweir 				xRet = xComp->getAccessibleAtPoint(aChildPoint);
392cdf0e10cSrcweir 			}
393cdf0e10cSrcweir 			else
394cdf0e10cSrcweir 			{
395cdf0e10cSrcweir 				xRet = Reference< XAccessible >( pEntry->GetAccessible(true), UNO_QUERY );
396cdf0e10cSrcweir 			}
397cdf0e10cSrcweir 		}
398cdf0e10cSrcweir 	}
399cdf0e10cSrcweir 	return xRet;
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
402cdf0e10cSrcweir // -----------------------------------------------------------------------------
403cdf0e10cSrcweir 
getBounds()404cdf0e10cSrcweir awt::Rectangle SAL_CALL ToolbarMenuAcc::getBounds() throw (RuntimeException)
405cdf0e10cSrcweir {
406cdf0e10cSrcweir     ThrowIfDisposed();
407cdf0e10cSrcweir     const vos::OGuard   aSolarGuard( Application::GetSolarMutex() );
408cdf0e10cSrcweir     const Point         aOutPos( mpParent->mrMenu.GetPosPixel() );
409cdf0e10cSrcweir     const Size          aOutSize( mpParent->mrMenu.GetOutputSizePixel() );
410cdf0e10cSrcweir     awt::Rectangle      aRet;
411cdf0e10cSrcweir 
412cdf0e10cSrcweir     aRet.X = aOutPos.X();
413cdf0e10cSrcweir     aRet.Y = aOutPos.Y();
414cdf0e10cSrcweir     aRet.Width = aOutSize.Width();
415cdf0e10cSrcweir     aRet.Height = aOutSize.Height();
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     return aRet;
418cdf0e10cSrcweir }
419cdf0e10cSrcweir 
420cdf0e10cSrcweir // -----------------------------------------------------------------------------
421cdf0e10cSrcweir 
getLocation()422cdf0e10cSrcweir awt::Point SAL_CALL ToolbarMenuAcc::getLocation() throw (RuntimeException)
423cdf0e10cSrcweir {
424cdf0e10cSrcweir     ThrowIfDisposed();
425cdf0e10cSrcweir     const vos::OGuard   aSolarGuard( Application::GetSolarMutex() );
426cdf0e10cSrcweir     const Point aOutPos( mpParent->mrMenu.GetPosPixel() );
427cdf0e10cSrcweir     return awt::Point( aOutPos.X(), aOutPos.Y() );
428cdf0e10cSrcweir }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir // -----------------------------------------------------------------------------
431cdf0e10cSrcweir 
getLocationOnScreen()432cdf0e10cSrcweir awt::Point SAL_CALL ToolbarMenuAcc::getLocationOnScreen()  throw (RuntimeException)
433cdf0e10cSrcweir {
434cdf0e10cSrcweir     ThrowIfDisposed();
435cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
436cdf0e10cSrcweir     const Point aScreenPos( mpParent->mrMenu.OutputToAbsoluteScreenPixel( Point() ) );
437cdf0e10cSrcweir     return awt::Point( aScreenPos.X(), aScreenPos.Y() );
438cdf0e10cSrcweir }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir // -----------------------------------------------------------------------------
441cdf0e10cSrcweir 
getSize()442cdf0e10cSrcweir awt::Size SAL_CALL ToolbarMenuAcc::getSize() throw (RuntimeException)
443cdf0e10cSrcweir {
444cdf0e10cSrcweir     ThrowIfDisposed();
445cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
446cdf0e10cSrcweir     const Size aOutSize( mpParent->mrMenu.GetOutputSizePixel() );
447cdf0e10cSrcweir     return awt::Size( aOutSize.Width(), aOutSize.Height() );
448cdf0e10cSrcweir }
449cdf0e10cSrcweir 
450cdf0e10cSrcweir // -----------------------------------------------------------------------------
451cdf0e10cSrcweir 
grabFocus()452cdf0e10cSrcweir void SAL_CALL ToolbarMenuAcc::grabFocus() throw (RuntimeException)
453cdf0e10cSrcweir {
454cdf0e10cSrcweir     ThrowIfDisposed();
455cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
456cdf0e10cSrcweir     mpParent->mrMenu.GrabFocus();
457cdf0e10cSrcweir }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir // -----------------------------------------------------------------------------
460cdf0e10cSrcweir 
getAccessibleKeyBinding()461cdf0e10cSrcweir Any SAL_CALL ToolbarMenuAcc::getAccessibleKeyBinding() throw (RuntimeException)
462cdf0e10cSrcweir {
463cdf0e10cSrcweir     ThrowIfDisposed();
464cdf0e10cSrcweir     return Any();
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir // -----------------------------------------------------------------------------
468cdf0e10cSrcweir 
getForeground()469cdf0e10cSrcweir sal_Int32 SAL_CALL ToolbarMenuAcc::getForeground() throw (RuntimeException)
470cdf0e10cSrcweir {
471cdf0e10cSrcweir     ThrowIfDisposed();
472cdf0e10cSrcweir     sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetMenuTextColor().GetColor();
473cdf0e10cSrcweir     return static_cast<sal_Int32>(nColor);
474cdf0e10cSrcweir }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir // -----------------------------------------------------------------------------
477cdf0e10cSrcweir 
getBackground()478cdf0e10cSrcweir sal_Int32 SAL_CALL ToolbarMenuAcc::getBackground() throw (RuntimeException)
479cdf0e10cSrcweir {
480cdf0e10cSrcweir     ThrowIfDisposed();
481cdf0e10cSrcweir     sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetMenuColor().GetColor();
482cdf0e10cSrcweir     return static_cast<sal_Int32>(nColor);
483cdf0e10cSrcweir }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir // -----------------------------------------------------------------------------
486cdf0e10cSrcweir 
selectAccessibleChild(sal_Int32 nChildIndex)487cdf0e10cSrcweir void SAL_CALL ToolbarMenuAcc::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
488cdf0e10cSrcweir {
489cdf0e10cSrcweir     const vos::OGuard   aSolarGuard( Application::GetSolarMutex() );
490cdf0e10cSrcweir     ThrowIfDisposed();
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 	mpParent->selectAccessibleChild( nChildIndex );
493cdf0e10cSrcweir }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir // -----------------------------------------------------------------------------
496cdf0e10cSrcweir 
isAccessibleChildSelected(sal_Int32 nChildIndex)497cdf0e10cSrcweir sal_Bool SAL_CALL ToolbarMenuAcc::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
498cdf0e10cSrcweir {
499cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
500cdf0e10cSrcweir     ThrowIfDisposed();
501cdf0e10cSrcweir 	return mpParent->isAccessibleChildSelected( nChildIndex );
502cdf0e10cSrcweir }
503cdf0e10cSrcweir 
504cdf0e10cSrcweir // -----------------------------------------------------------------------------
505cdf0e10cSrcweir 
clearAccessibleSelection()506cdf0e10cSrcweir void SAL_CALL ToolbarMenuAcc::clearAccessibleSelection() throw (RuntimeException)
507cdf0e10cSrcweir {
508cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
509cdf0e10cSrcweir     ThrowIfDisposed();
510cdf0e10cSrcweir     mpParent->clearAccessibleSelection();
511cdf0e10cSrcweir }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir // -----------------------------------------------------------------------------
514cdf0e10cSrcweir 
selectAllAccessibleChildren()515cdf0e10cSrcweir void SAL_CALL ToolbarMenuAcc::selectAllAccessibleChildren() throw (RuntimeException)
516cdf0e10cSrcweir {
517cdf0e10cSrcweir     ThrowIfDisposed();
518cdf0e10cSrcweir     // unsupported due to single selection only
519cdf0e10cSrcweir }
520cdf0e10cSrcweir 
521cdf0e10cSrcweir // -----------------------------------------------------------------------------
522cdf0e10cSrcweir 
getSelectedAccessibleChildCount()523cdf0e10cSrcweir sal_Int32 SAL_CALL ToolbarMenuAcc::getSelectedAccessibleChildCount() throw (RuntimeException)
524cdf0e10cSrcweir {
525cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
526cdf0e10cSrcweir     ThrowIfDisposed();
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 	return mpParent->mnHighlightedEntry != -1 ? 1 : 0;
529cdf0e10cSrcweir }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir // -----------------------------------------------------------------------------
532cdf0e10cSrcweir 
getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)533cdf0e10cSrcweir Reference< XAccessible > SAL_CALL ToolbarMenuAcc::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
534cdf0e10cSrcweir {
535cdf0e10cSrcweir     ThrowIfDisposed();
536cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
537cdf0e10cSrcweir 
538cdf0e10cSrcweir 	if( (mpParent->mnHighlightedEntry != -1) && (nSelectedChildIndex == 0) )
539cdf0e10cSrcweir 	{
540cdf0e10cSrcweir 		ToolbarMenuEntry* pEntry = mpParent->maEntryVector[ mpParent->mnHighlightedEntry ];
541cdf0e10cSrcweir 		if( pEntry )
542cdf0e10cSrcweir 		{
543cdf0e10cSrcweir 			if( pEntry->mpControl )
544cdf0e10cSrcweir 			{
545cdf0e10cSrcweir 				Reference< XAccessibleSelection > xSel( pEntry->GetAccessible(true), UNO_QUERY_THROW );
546cdf0e10cSrcweir 				return xSel->getSelectedAccessibleChild(0);
547cdf0e10cSrcweir 			}
548cdf0e10cSrcweir 			else
549cdf0e10cSrcweir 				return Reference< XAccessible >( pEntry->GetAccessible(true), UNO_QUERY );
550cdf0e10cSrcweir 		}
551cdf0e10cSrcweir 	}
552cdf0e10cSrcweir 
553cdf0e10cSrcweir 	throw IndexOutOfBoundsException();
554cdf0e10cSrcweir }
555cdf0e10cSrcweir 
556cdf0e10cSrcweir // -----------------------------------------------------------------------------
557cdf0e10cSrcweir 
deselectAccessibleChild(sal_Int32 nChildIndex)558cdf0e10cSrcweir void SAL_CALL ToolbarMenuAcc::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
559cdf0e10cSrcweir {
560cdf0e10cSrcweir     ThrowIfDisposed();
561cdf0e10cSrcweir     const vos::OGuard   aSolarGuard( Application::GetSolarMutex() );
562cdf0e10cSrcweir     // Because of the single selection we can reset the whole selection when
563cdf0e10cSrcweir     // the specified child is currently selected.
564cdf0e10cSrcweir     if (isAccessibleChildSelected(nChildIndex))
565cdf0e10cSrcweir         mpParent->clearAccessibleSelection();
566cdf0e10cSrcweir }
567cdf0e10cSrcweir 
568cdf0e10cSrcweir // -----------------------------------------------------------------------------
569cdf0e10cSrcweir 
disposing(void)570cdf0e10cSrcweir void SAL_CALL ToolbarMenuAcc::disposing (void)
571cdf0e10cSrcweir {
572cdf0e10cSrcweir     EventListenerVector aListenerListCopy;
573cdf0e10cSrcweir 
574cdf0e10cSrcweir     {
575cdf0e10cSrcweir         // Make a copy of the list and clear the original.
576cdf0e10cSrcweir         const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
577cdf0e10cSrcweir         ::osl::MutexGuard aGuard (m_aMutex);
578cdf0e10cSrcweir         aListenerListCopy = mxEventListeners;
579cdf0e10cSrcweir         mxEventListeners.clear();
580cdf0e10cSrcweir 
581cdf0e10cSrcweir         // Reset the pointer to the parent.  It has to be the one who has
582cdf0e10cSrcweir         // disposed us because he is dying.
583cdf0e10cSrcweir         mpParent = NULL;
584cdf0e10cSrcweir     }
585cdf0e10cSrcweir 
586cdf0e10cSrcweir     // Inform all listeners that this objects is disposing.
587cdf0e10cSrcweir     EventListenerVector::const_iterator aListenerIterator (aListenerListCopy.begin());
588cdf0e10cSrcweir     EventObject aEvent (static_cast<XAccessible*>(this));
589cdf0e10cSrcweir     while(aListenerIterator != aListenerListCopy.end())
590cdf0e10cSrcweir     {
591cdf0e10cSrcweir         try
592cdf0e10cSrcweir         {
593cdf0e10cSrcweir             (*aListenerIterator)->disposing (aEvent);
594cdf0e10cSrcweir         }
595cdf0e10cSrcweir         catch( Exception& )
596cdf0e10cSrcweir         {
597cdf0e10cSrcweir             // Ignore exceptions.
598cdf0e10cSrcweir         }
599cdf0e10cSrcweir 
600cdf0e10cSrcweir         ++aListenerIterator;
601cdf0e10cSrcweir     }
602cdf0e10cSrcweir }
603cdf0e10cSrcweir 
ThrowIfDisposed(void)604cdf0e10cSrcweir void ToolbarMenuAcc::ThrowIfDisposed (void) throw (DisposedException)
605cdf0e10cSrcweir {
606cdf0e10cSrcweir     if(rBHelper.bDisposed || rBHelper.bInDispose || !mpParent)
607cdf0e10cSrcweir     {
608cdf0e10cSrcweir         throw DisposedException ( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("object has been already disposed")), static_cast<XWeak*>(this));
609cdf0e10cSrcweir     }
610cdf0e10cSrcweir }
611cdf0e10cSrcweir 
612cdf0e10cSrcweir // -----------------------
613cdf0e10cSrcweir // - ToolbarMenuEntryAcc -
614cdf0e10cSrcweir // -----------------------
615cdf0e10cSrcweir 
ToolbarMenuEntryAcc(ToolbarMenuEntry * pParent)616cdf0e10cSrcweir ToolbarMenuEntryAcc::ToolbarMenuEntryAcc( ToolbarMenuEntry* pParent )
617cdf0e10cSrcweir : ToolbarMenuEntryAccBase( m_aMutex )
618cdf0e10cSrcweir , mpParent( pParent )
619cdf0e10cSrcweir {
620cdf0e10cSrcweir }
621cdf0e10cSrcweir 
622cdf0e10cSrcweir // -----------------------------------------------------------------------------
623cdf0e10cSrcweir 
~ToolbarMenuEntryAcc()624cdf0e10cSrcweir ToolbarMenuEntryAcc::~ToolbarMenuEntryAcc()
625cdf0e10cSrcweir {
626cdf0e10cSrcweir }
627cdf0e10cSrcweir 
628cdf0e10cSrcweir // -----------------------------------------------------------------------
629cdf0e10cSrcweir 
FireAccessibleEvent(short nEventId,const Any & rOldValue,const Any & rNewValue)630cdf0e10cSrcweir void ToolbarMenuEntryAcc::FireAccessibleEvent( short nEventId, const Any& rOldValue, const Any& rNewValue )
631cdf0e10cSrcweir {
632cdf0e10cSrcweir     if( nEventId )
633cdf0e10cSrcweir     {
634cdf0e10cSrcweir         EventListenerVector aTmpListeners( mxEventListeners );
635cdf0e10cSrcweir         ::std::vector< Reference< XAccessibleEventListener > >::const_iterator  aIter( aTmpListeners.begin() );
636cdf0e10cSrcweir         AccessibleEventObject aEvtObject;
637cdf0e10cSrcweir 
638cdf0e10cSrcweir         aEvtObject.EventId = nEventId;
639cdf0e10cSrcweir         aEvtObject.Source = static_cast<XWeak*>(this);
640cdf0e10cSrcweir         aEvtObject.NewValue = rNewValue;
641cdf0e10cSrcweir 	    aEvtObject.OldValue = rOldValue;
642cdf0e10cSrcweir 
643cdf0e10cSrcweir 		while( aIter != aTmpListeners.end() )
644cdf0e10cSrcweir         {
645cdf0e10cSrcweir             (*aIter)->notifyEvent( aEvtObject );
646cdf0e10cSrcweir             aIter++;
647cdf0e10cSrcweir         }
648cdf0e10cSrcweir     }
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir 
652cdf0e10cSrcweir // -----------------------------------------------------------------------------
653cdf0e10cSrcweir 
disposing(void)654cdf0e10cSrcweir void SAL_CALL ToolbarMenuEntryAcc::disposing (void)
655cdf0e10cSrcweir {
656cdf0e10cSrcweir     EventListenerVector aListenerListCopy;
657cdf0e10cSrcweir 
658cdf0e10cSrcweir     {
659cdf0e10cSrcweir         // Make a copy of the list and clear the original.
660cdf0e10cSrcweir         const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
661cdf0e10cSrcweir         ::osl::MutexGuard aGuard (m_aMutex);
662cdf0e10cSrcweir         aListenerListCopy = mxEventListeners;
663cdf0e10cSrcweir         mxEventListeners.clear();
664cdf0e10cSrcweir 
665cdf0e10cSrcweir         // Reset the pointer to the parent.  It has to be the one who has
666cdf0e10cSrcweir         // disposed us because he is dying.
667cdf0e10cSrcweir         mpParent = NULL;
668cdf0e10cSrcweir     }
669cdf0e10cSrcweir 
670cdf0e10cSrcweir     // Inform all listeners that this objects is disposing.
671cdf0e10cSrcweir     EventListenerVector::const_iterator aListenerIterator (aListenerListCopy.begin());
672cdf0e10cSrcweir     EventObject aEvent (static_cast<XAccessible*>(this));
673cdf0e10cSrcweir     while(aListenerIterator != aListenerListCopy.end())
674cdf0e10cSrcweir     {
675cdf0e10cSrcweir         try
676cdf0e10cSrcweir         {
677cdf0e10cSrcweir             (*aListenerIterator)->disposing (aEvent);
678cdf0e10cSrcweir         }
679cdf0e10cSrcweir         catch( Exception& )
680cdf0e10cSrcweir         {
681cdf0e10cSrcweir             // Ignore exceptions.
682cdf0e10cSrcweir         }
683cdf0e10cSrcweir 
684cdf0e10cSrcweir         ++aListenerIterator;
685cdf0e10cSrcweir     }
686cdf0e10cSrcweir }
687cdf0e10cSrcweir // -----------------------------------------------------------------------------
688cdf0e10cSrcweir 
getAccessibleContext()689cdf0e10cSrcweir Reference< XAccessibleContext > SAL_CALL ToolbarMenuEntryAcc::getAccessibleContext() throw (RuntimeException)
690cdf0e10cSrcweir {
691cdf0e10cSrcweir     return this;
692cdf0e10cSrcweir }
693cdf0e10cSrcweir 
694cdf0e10cSrcweir // -----------------------------------------------------------------------------
695cdf0e10cSrcweir 
getAccessibleChildCount()696cdf0e10cSrcweir sal_Int32 SAL_CALL ToolbarMenuEntryAcc::getAccessibleChildCount() throw (RuntimeException)
697cdf0e10cSrcweir {
698cdf0e10cSrcweir     return 0;
699cdf0e10cSrcweir }
700cdf0e10cSrcweir 
701cdf0e10cSrcweir // -----------------------------------------------------------------------------
702cdf0e10cSrcweir 
getAccessibleChild(sal_Int32)703cdf0e10cSrcweir Reference< XAccessible > SAL_CALL ToolbarMenuEntryAcc::getAccessibleChild( sal_Int32 ) throw (IndexOutOfBoundsException, RuntimeException)
704cdf0e10cSrcweir {
705cdf0e10cSrcweir 	throw IndexOutOfBoundsException();
706cdf0e10cSrcweir }
707cdf0e10cSrcweir 
708cdf0e10cSrcweir // -----------------------------------------------------------------------------
709cdf0e10cSrcweir 
getAccessibleParent()710cdf0e10cSrcweir Reference< XAccessible > SAL_CALL ToolbarMenuEntryAcc::getAccessibleParent() throw (RuntimeException)
711cdf0e10cSrcweir {
712cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
713cdf0e10cSrcweir     Reference< XAccessible > xRet;
714cdf0e10cSrcweir 
715cdf0e10cSrcweir     if( mpParent )
716cdf0e10cSrcweir         xRet = mpParent->mrMenu.GetAccessible();
717cdf0e10cSrcweir 
718cdf0e10cSrcweir     return xRet;
719cdf0e10cSrcweir }
720cdf0e10cSrcweir 
721cdf0e10cSrcweir // -----------------------------------------------------------------------------
722cdf0e10cSrcweir 
getAccessibleIndexInParent()723cdf0e10cSrcweir sal_Int32 SAL_CALL ToolbarMenuEntryAcc::getAccessibleIndexInParent() throw (RuntimeException)
724cdf0e10cSrcweir {
725cdf0e10cSrcweir     const vos::OGuard   aSolarGuard( Application::GetSolarMutex() );
726cdf0e10cSrcweir     // The index defaults to -1 to indicate the child does not belong to its
727cdf0e10cSrcweir     // parent.
728cdf0e10cSrcweir     sal_Int32 nIndexInParent = -1;
729cdf0e10cSrcweir 
730cdf0e10cSrcweir     if( mpParent )
731cdf0e10cSrcweir     {
732cdf0e10cSrcweir 		Reference< XAccessibleContext > xParent( mpParent->mrMenu.GetAccessible(), UNO_QUERY );
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 		if( xParent.is() )
735cdf0e10cSrcweir 		{
736cdf0e10cSrcweir 			Reference< XAccessible > xThis( this );
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 			const sal_Int32 nCount = xParent->getAccessibleChildCount();
739cdf0e10cSrcweir 			for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
740cdf0e10cSrcweir 			{
741cdf0e10cSrcweir 				if( xParent->getAccessibleChild(nIndex) == xThis )
742cdf0e10cSrcweir 				{
743cdf0e10cSrcweir 					nIndexInParent = nIndex;
744cdf0e10cSrcweir 					break;
745cdf0e10cSrcweir 				}
746cdf0e10cSrcweir 			}
747cdf0e10cSrcweir 		}
748cdf0e10cSrcweir     }
749cdf0e10cSrcweir 
750cdf0e10cSrcweir     return nIndexInParent;
751cdf0e10cSrcweir }
752cdf0e10cSrcweir 
753cdf0e10cSrcweir // -----------------------------------------------------------------------------
754cdf0e10cSrcweir 
getAccessibleRole()755cdf0e10cSrcweir sal_Int16 SAL_CALL ToolbarMenuEntryAcc::getAccessibleRole() throw (RuntimeException)
756cdf0e10cSrcweir {
757cdf0e10cSrcweir     return AccessibleRole::LIST_ITEM;
758cdf0e10cSrcweir }
759cdf0e10cSrcweir 
760cdf0e10cSrcweir // -----------------------------------------------------------------------------
761cdf0e10cSrcweir 
getAccessibleDescription()762cdf0e10cSrcweir ::rtl::OUString SAL_CALL ToolbarMenuEntryAcc::getAccessibleDescription() throw (RuntimeException)
763cdf0e10cSrcweir {
764cdf0e10cSrcweir 	return ::rtl::OUString();
765cdf0e10cSrcweir }
766cdf0e10cSrcweir 
767cdf0e10cSrcweir // -----------------------------------------------------------------------------
768cdf0e10cSrcweir 
getAccessibleName()769cdf0e10cSrcweir ::rtl::OUString SAL_CALL ToolbarMenuEntryAcc::getAccessibleName() throw (RuntimeException)
770cdf0e10cSrcweir {
771cdf0e10cSrcweir     const vos::OGuard   aSolarGuard( Application::GetSolarMutex() );
772cdf0e10cSrcweir     String              aRet;
773cdf0e10cSrcweir 
774cdf0e10cSrcweir     if( mpParent )
775cdf0e10cSrcweir     {
776cdf0e10cSrcweir         aRet = mpParent->maText;
777cdf0e10cSrcweir 
778cdf0e10cSrcweir         if( !aRet.Len() )
779cdf0e10cSrcweir         {
780cdf0e10cSrcweir             aRet = String( RTL_CONSTASCII_USTRINGPARAM( "Item " ) );
781cdf0e10cSrcweir             aRet += String::CreateFromInt32( mpParent->mnEntryId );
782cdf0e10cSrcweir         }
783cdf0e10cSrcweir     }
784cdf0e10cSrcweir 
785cdf0e10cSrcweir     return aRet;
786cdf0e10cSrcweir }
787cdf0e10cSrcweir 
788cdf0e10cSrcweir // -----------------------------------------------------------------------------
789cdf0e10cSrcweir 
getAccessibleRelationSet()790cdf0e10cSrcweir Reference< XAccessibleRelationSet > SAL_CALL ToolbarMenuEntryAcc::getAccessibleRelationSet() throw (RuntimeException)
791cdf0e10cSrcweir {
792cdf0e10cSrcweir     return Reference< XAccessibleRelationSet >();
793cdf0e10cSrcweir }
794cdf0e10cSrcweir 
795cdf0e10cSrcweir // -----------------------------------------------------------------------------
796cdf0e10cSrcweir 
getAccessibleStateSet()797cdf0e10cSrcweir Reference< XAccessibleStateSet > SAL_CALL ToolbarMenuEntryAcc::getAccessibleStateSet() throw (RuntimeException)
798cdf0e10cSrcweir {
799cdf0e10cSrcweir     const vos::OGuard                   aSolarGuard( Application::GetSolarMutex() );
800cdf0e10cSrcweir     ::utl::AccessibleStateSetHelper*    pStateSet = new ::utl::AccessibleStateSetHelper;
801cdf0e10cSrcweir 
802cdf0e10cSrcweir     if( mpParent )
803cdf0e10cSrcweir     {
804cdf0e10cSrcweir         pStateSet->AddState (AccessibleStateType::ENABLED);
805cdf0e10cSrcweir         pStateSet->AddState (AccessibleStateType::SENSITIVE);
806cdf0e10cSrcweir         pStateSet->AddState (AccessibleStateType::SHOWING);
807cdf0e10cSrcweir         pStateSet->AddState (AccessibleStateType::VISIBLE);
808cdf0e10cSrcweir         pStateSet->AddState (AccessibleStateType::TRANSIENT);
809cdf0e10cSrcweir 		if( mpParent->mnEntryId != TITLE_ID )
810cdf0e10cSrcweir 		{
811cdf0e10cSrcweir 			pStateSet->AddState( AccessibleStateType::SELECTABLE );
812cdf0e10cSrcweir 
813cdf0e10cSrcweir 			// SELECTED
814cdf0e10cSrcweir 			if( mpParent->mrMenu.getHighlightedEntryId() == mpParent->mnEntryId )
815cdf0e10cSrcweir 				pStateSet->AddState( AccessibleStateType::SELECTED );
816cdf0e10cSrcweir 		}
817cdf0e10cSrcweir     }
818cdf0e10cSrcweir 
819cdf0e10cSrcweir     return pStateSet;
820cdf0e10cSrcweir }
821cdf0e10cSrcweir 
822cdf0e10cSrcweir // -----------------------------------------------------------------------------
823cdf0e10cSrcweir 
getLocale()824cdf0e10cSrcweir Locale SAL_CALL ToolbarMenuEntryAcc::getLocale() throw (IllegalAccessibleComponentStateException, RuntimeException)
825cdf0e10cSrcweir {
826cdf0e10cSrcweir     const ::rtl::OUString aEmptyStr;
827cdf0e10cSrcweir     Locale aRet( aEmptyStr, aEmptyStr, aEmptyStr );
828cdf0e10cSrcweir 
829cdf0e10cSrcweir 	Reference< XAccessible > xParent( getAccessibleParent() );
830cdf0e10cSrcweir     if( xParent.is() )
831cdf0e10cSrcweir     {
832cdf0e10cSrcweir         Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
833cdf0e10cSrcweir 
834cdf0e10cSrcweir         if( xParentContext.is() )
835cdf0e10cSrcweir             aRet = xParentContext->getLocale();
836cdf0e10cSrcweir     }
837cdf0e10cSrcweir 
838cdf0e10cSrcweir     return aRet;
839cdf0e10cSrcweir }
840cdf0e10cSrcweir 
841cdf0e10cSrcweir // -----------------------------------------------------------------------------
842cdf0e10cSrcweir 
addEventListener(const Reference<XAccessibleEventListener> & rxListener)843cdf0e10cSrcweir void SAL_CALL ToolbarMenuEntryAcc::addEventListener( const Reference< XAccessibleEventListener >& rxListener ) throw (RuntimeException)
844cdf0e10cSrcweir {
845cdf0e10cSrcweir     const ::vos::OGuard aGuard( maMutex );
846cdf0e10cSrcweir 
847cdf0e10cSrcweir 	if( rxListener.is() )
848cdf0e10cSrcweir     {
849cdf0e10cSrcweir        	EventListenerVector::const_iterator aIter( mxEventListeners.begin() );
850cdf0e10cSrcweir 		bool bFound = false;
851cdf0e10cSrcweir 
852cdf0e10cSrcweir 		while( !bFound && ( aIter != mxEventListeners.end() ) )
853cdf0e10cSrcweir         {
854cdf0e10cSrcweir 			if( *aIter == rxListener )
855cdf0e10cSrcweir                 bFound = true;
856cdf0e10cSrcweir             else
857cdf0e10cSrcweir                 aIter++;
858cdf0e10cSrcweir         }
859cdf0e10cSrcweir 
860cdf0e10cSrcweir 		if (!bFound)
861cdf0e10cSrcweir             mxEventListeners.push_back( rxListener );
862cdf0e10cSrcweir     }
863cdf0e10cSrcweir }
864cdf0e10cSrcweir 
865cdf0e10cSrcweir // -----------------------------------------------------------------------------
866cdf0e10cSrcweir 
removeEventListener(const Reference<XAccessibleEventListener> & rxListener)867cdf0e10cSrcweir void SAL_CALL ToolbarMenuEntryAcc::removeEventListener( const Reference< XAccessibleEventListener >& rxListener ) throw (RuntimeException)
868cdf0e10cSrcweir {
869cdf0e10cSrcweir     const ::vos::OGuard aGuard( maMutex );
870cdf0e10cSrcweir 
871cdf0e10cSrcweir 	if( rxListener.is() )
872cdf0e10cSrcweir     {
873cdf0e10cSrcweir        	EventListenerVector::iterator aIter = mxEventListeners.begin();
874cdf0e10cSrcweir 		bool bFound = false;
875cdf0e10cSrcweir 
876cdf0e10cSrcweir 		while( !bFound && ( aIter != mxEventListeners.end() ) )
877cdf0e10cSrcweir         {
878cdf0e10cSrcweir 			if( *aIter == rxListener )
879cdf0e10cSrcweir             {
880cdf0e10cSrcweir                 mxEventListeners.erase( aIter );
881cdf0e10cSrcweir                 bFound = true;
882cdf0e10cSrcweir             }
883cdf0e10cSrcweir             else
884cdf0e10cSrcweir                 aIter++;
885cdf0e10cSrcweir         }
886cdf0e10cSrcweir     }
887cdf0e10cSrcweir }
888cdf0e10cSrcweir 
889cdf0e10cSrcweir // -----------------------------------------------------------------------------
890cdf0e10cSrcweir 
containsPoint(const awt::Point & aPoint)891cdf0e10cSrcweir sal_Bool SAL_CALL ToolbarMenuEntryAcc::containsPoint( const awt::Point& aPoint ) throw (RuntimeException)
892cdf0e10cSrcweir {
893cdf0e10cSrcweir     const awt::Rectangle    aRect( getBounds() );
894cdf0e10cSrcweir     const Point             aSize( aRect.Width, aRect.Height );
895cdf0e10cSrcweir     const Point             aNullPoint, aTestPoint( aPoint.X, aPoint.Y );
896cdf0e10cSrcweir 
897cdf0e10cSrcweir     return Rectangle( aNullPoint, aSize ).IsInside( aTestPoint );
898cdf0e10cSrcweir }
899cdf0e10cSrcweir 
900cdf0e10cSrcweir // -----------------------------------------------------------------------------
901cdf0e10cSrcweir 
getAccessibleAtPoint(const awt::Point &)902cdf0e10cSrcweir Reference< XAccessible > SAL_CALL ToolbarMenuEntryAcc::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException)
903cdf0e10cSrcweir {
904cdf0e10cSrcweir     Reference< XAccessible > xRet;
905cdf0e10cSrcweir     return xRet;
906cdf0e10cSrcweir }
907cdf0e10cSrcweir 
908cdf0e10cSrcweir // -----------------------------------------------------------------------------
909cdf0e10cSrcweir 
getBounds()910cdf0e10cSrcweir awt::Rectangle SAL_CALL ToolbarMenuEntryAcc::getBounds() throw (RuntimeException)
911cdf0e10cSrcweir {
912cdf0e10cSrcweir     const vos::OGuard   aSolarGuard( Application::GetSolarMutex() );
913cdf0e10cSrcweir     awt::Rectangle      aRet;
914cdf0e10cSrcweir 
915cdf0e10cSrcweir     if( mpParent )
916cdf0e10cSrcweir     {
917cdf0e10cSrcweir         Rectangle   aRect( mpParent->maRect );
918cdf0e10cSrcweir         Point       aOrigin;
919cdf0e10cSrcweir         Rectangle   aParentRect( aOrigin, mpParent->mrMenu.GetOutputSizePixel() );
920cdf0e10cSrcweir 
921cdf0e10cSrcweir         aRect.Intersection( aParentRect );
922cdf0e10cSrcweir 
923cdf0e10cSrcweir         aRet.X = aRect.Left();
924cdf0e10cSrcweir         aRet.Y = aRect.Top();
925cdf0e10cSrcweir         aRet.Width = aRect.GetWidth();
926cdf0e10cSrcweir         aRet.Height = aRect.GetHeight();
927cdf0e10cSrcweir     }
928cdf0e10cSrcweir 
929cdf0e10cSrcweir     return aRet;
930cdf0e10cSrcweir }
931cdf0e10cSrcweir 
932cdf0e10cSrcweir // -----------------------------------------------------------------------------
933cdf0e10cSrcweir 
getLocation()934cdf0e10cSrcweir awt::Point SAL_CALL ToolbarMenuEntryAcc::getLocation() throw (RuntimeException)
935cdf0e10cSrcweir {
936cdf0e10cSrcweir     const awt::Rectangle aRect( getBounds() );
937cdf0e10cSrcweir     return awt::Point( aRect.X, aRect.Y );
938cdf0e10cSrcweir }
939cdf0e10cSrcweir 
940cdf0e10cSrcweir // -----------------------------------------------------------------------------
941cdf0e10cSrcweir 
getLocationOnScreen()942cdf0e10cSrcweir awt::Point SAL_CALL ToolbarMenuEntryAcc::getLocationOnScreen() throw (RuntimeException)
943cdf0e10cSrcweir {
944cdf0e10cSrcweir     const vos::OGuard aSolarGuard( Application::GetSolarMutex() );
945cdf0e10cSrcweir     awt::Point aRet;
946cdf0e10cSrcweir 
947cdf0e10cSrcweir     if( mpParent )
948cdf0e10cSrcweir     {
949cdf0e10cSrcweir         const Point aScreenPos( mpParent->mrMenu.OutputToAbsoluteScreenPixel( mpParent->maRect.TopLeft() ) );
950cdf0e10cSrcweir 
951cdf0e10cSrcweir         aRet.X = aScreenPos.X();
952cdf0e10cSrcweir         aRet.Y = aScreenPos.Y();
953cdf0e10cSrcweir     }
954cdf0e10cSrcweir 
955cdf0e10cSrcweir     return aRet;
956cdf0e10cSrcweir }
957cdf0e10cSrcweir 
958cdf0e10cSrcweir // -----------------------------------------------------------------------------
959cdf0e10cSrcweir 
getSize()960cdf0e10cSrcweir awt::Size SAL_CALL ToolbarMenuEntryAcc::getSize() throw (RuntimeException)
961cdf0e10cSrcweir {
962cdf0e10cSrcweir     const awt::Rectangle aRect( getBounds() );
963cdf0e10cSrcweir     awt::Size aRet;
964cdf0e10cSrcweir 
965cdf0e10cSrcweir     aRet.Width = aRect.Width;
966cdf0e10cSrcweir     aRet.Height = aRect.Height;
967cdf0e10cSrcweir 
968cdf0e10cSrcweir     return aRet;
969cdf0e10cSrcweir }
970cdf0e10cSrcweir 
971cdf0e10cSrcweir // -----------------------------------------------------------------------------
972cdf0e10cSrcweir 
grabFocus()973cdf0e10cSrcweir void SAL_CALL ToolbarMenuEntryAcc::grabFocus() throw (RuntimeException)
974cdf0e10cSrcweir {
975cdf0e10cSrcweir     // nothing to do
976cdf0e10cSrcweir }
977cdf0e10cSrcweir 
978cdf0e10cSrcweir // -----------------------------------------------------------------------------
979cdf0e10cSrcweir 
getAccessibleKeyBinding()980cdf0e10cSrcweir Any SAL_CALL ToolbarMenuEntryAcc::getAccessibleKeyBinding() throw (RuntimeException)
981cdf0e10cSrcweir {
982cdf0e10cSrcweir     return Any();
983cdf0e10cSrcweir }
984cdf0e10cSrcweir 
985cdf0e10cSrcweir // -----------------------------------------------------------------------------
986cdf0e10cSrcweir 
getForeground()987cdf0e10cSrcweir sal_Int32 SAL_CALL ToolbarMenuEntryAcc::getForeground(  ) throw (RuntimeException)
988cdf0e10cSrcweir {
989cdf0e10cSrcweir     return static_cast<sal_Int32>(Application::GetSettings().GetStyleSettings().GetMenuTextColor().GetColor());
990cdf0e10cSrcweir }
991cdf0e10cSrcweir 
992cdf0e10cSrcweir // -----------------------------------------------------------------------------
993cdf0e10cSrcweir 
getBackground()994cdf0e10cSrcweir sal_Int32 SAL_CALL ToolbarMenuEntryAcc::getBackground(  )  throw (RuntimeException)
995cdf0e10cSrcweir {
996cdf0e10cSrcweir     return static_cast<sal_Int32>(Application::GetSettings().GetStyleSettings().GetMenuColor().GetColor());
997cdf0e10cSrcweir }
998cdf0e10cSrcweir 
999cdf0e10cSrcweir }
1000