xref: /AOO41X/main/accessibility/source/extended/accessiblelistboxentry.cxx (revision 21075d779129cb18aa18227e3636dda359ad2404)
10841af79SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
30841af79SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
40841af79SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
50841af79SAndrew Rist  * distributed with this work for additional information
60841af79SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
70841af79SAndrew Rist  * to you under the Apache License, Version 2.0 (the
80841af79SAndrew Rist  * "License"); you may not use this file except in compliance
90841af79SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
110841af79SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
130841af79SAndrew Rist  * Unless required by applicable law or agreed to in writing,
140841af79SAndrew Rist  * software distributed under the License is distributed on an
150841af79SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
160841af79SAndrew Rist  * KIND, either express or implied.  See the License for the
170841af79SAndrew Rist  * specific language governing permissions and limitations
180841af79SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
200841af79SAndrew Rist  *************************************************************/
210841af79SAndrew Rist 
220841af79SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_accessibility.hxx"
26cdf0e10cSrcweir #include "accessibility/extended/accessiblelistboxentry.hxx"
27cdf0e10cSrcweir #include <svtools/svtreebx.hxx>
28*21075d77SSteve Yin #include <accessibility/helper/accresmgr.hxx>
29cdf0e10cSrcweir #include <svtools/stringtransfer.hxx>
30cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp>
31cdf0e10cSrcweir #include <com/sun/star/awt/Rectangle.hpp>
32cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
33cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
34cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
35cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
36cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
37cdf0e10cSrcweir #include <tools/debug.hxx>
38cdf0e10cSrcweir #include <vcl/svapp.hxx>
39cdf0e10cSrcweir #include <vcl/controllayout.hxx>
40cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
41cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
42cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
43cdf0e10cSrcweir #include <unotools/accessiblerelationsethelper.hxx>
44cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
45cdf0e10cSrcweir #include <comphelper/sequence.hxx>
46cdf0e10cSrcweir #include <comphelper/accessibleeventnotifier.hxx>
47cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
48*21075d77SSteve Yin #include <accessibility/helper/accessiblestrings.hrc>
49*21075d77SSteve Yin #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEVALUE_HPP_
50*21075d77SSteve Yin #include <com/sun/star/accessibility/XAccessibleValue.hpp>
51*21075d77SSteve Yin #endif
52cdf0e10cSrcweir #define ACCESSIBLE_ACTION_COUNT	1
53cdf0e10cSrcweir 
54cdf0e10cSrcweir namespace
55cdf0e10cSrcweir {
56cdf0e10cSrcweir 	void checkActionIndex_Impl( sal_Int32 _nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException)
57cdf0e10cSrcweir 	{
58cdf0e10cSrcweir 		if ( _nIndex < 0 || _nIndex >= ACCESSIBLE_ACTION_COUNT )
59cdf0e10cSrcweir 			// only three actions
60cdf0e10cSrcweir 			throw ::com::sun::star::lang::IndexOutOfBoundsException();
61cdf0e10cSrcweir 	}
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //........................................................................
65cdf0e10cSrcweir namespace accessibility
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	//........................................................................
68cdf0e10cSrcweir 	// class ALBSolarGuard ---------------------------------------------------------
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	/** Aquire the solar mutex. */
71cdf0e10cSrcweir 	class ALBSolarGuard : public ::vos::OGuard
72cdf0e10cSrcweir 	{
73cdf0e10cSrcweir 	public:
74cdf0e10cSrcweir     	inline ALBSolarGuard() : ::vos::OGuard( Application::GetSolarMutex() ) {}
75cdf0e10cSrcweir 	};
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	// class AccessibleListBoxEntry -----------------------------------------------------
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	using namespace ::com::sun::star::accessibility;
80cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
81cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
82cdf0e10cSrcweir 	using namespace ::com::sun::star;
83*21075d77SSteve Yin 	using namespace ::comphelper;
84cdf0e10cSrcweir 	DBG_NAME(AccessibleListBoxEntry)
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
87cdf0e10cSrcweir 	// Ctor() and Dtor()
88cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
89cdf0e10cSrcweir 	AccessibleListBoxEntry::AccessibleListBoxEntry( SvTreeListBox& _rListBox,
90cdf0e10cSrcweir 													SvLBoxEntry* _pEntry,
91cdf0e10cSrcweir 													const Reference< XAccessible >& _xParent ) :
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 		AccessibleListBoxEntry_BASE	( m_aMutex ),
94cdf0e10cSrcweir 		ListBoxAccessibleBase( _rListBox ),
95cdf0e10cSrcweir 
96*21075d77SSteve Yin 		m_pSvLBoxEntry  ( _pEntry ),
97cdf0e10cSrcweir         m_nClientId     ( 0 ),
98cdf0e10cSrcweir 		m_aParent		( _xParent )
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	{
101cdf0e10cSrcweir 		DBG_CTOR( AccessibleListBoxEntry, NULL );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 		_rListBox.FillEntryPath( _pEntry, m_aEntryPath );
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
106cdf0e10cSrcweir 	AccessibleListBoxEntry::~AccessibleListBoxEntry()
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		DBG_DTOR( AccessibleListBoxEntry, NULL );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 		if ( IsAlive_Impl() )
111cdf0e10cSrcweir 		{
112cdf0e10cSrcweir         	// increment ref count to prevent double call of Dtor
113cdf0e10cSrcweir         	osl_incrementInterlockedCount( &m_refCount );
114cdf0e10cSrcweir         	dispose();
115cdf0e10cSrcweir 		}
116cdf0e10cSrcweir 	}
117cdf0e10cSrcweir 
118*21075d77SSteve Yin 	// IA2 CWS
119*21075d77SSteve Yin 	void AccessibleListBoxEntry::NotifyAccessibleEvent( sal_Int16 _nEventId,
120*21075d77SSteve Yin 											   	const ::com::sun::star::uno::Any& _aOldValue,
121*21075d77SSteve Yin 											   	const ::com::sun::star::uno::Any& _aNewValue )
122*21075d77SSteve Yin 	{
123*21075d77SSteve Yin         Reference< uno::XInterface > xSource( *this );
124*21075d77SSteve Yin         AccessibleEventObject aEventObj( xSource, _nEventId, _aNewValue, _aOldValue );
125*21075d77SSteve Yin 
126*21075d77SSteve Yin 	    if (m_nClientId)
127*21075d77SSteve Yin 		    comphelper::AccessibleEventNotifier::addEvent( m_nClientId, aEventObj );
128*21075d77SSteve Yin 	}
129*21075d77SSteve Yin 
130*21075d77SSteve Yin 
131cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
132cdf0e10cSrcweir 	Rectangle AccessibleListBoxEntry::GetBoundingBox_Impl() const
133cdf0e10cSrcweir 	{
134cdf0e10cSrcweir 		Rectangle aRect;
135cdf0e10cSrcweir 		SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
136cdf0e10cSrcweir 		if ( pEntry )
137cdf0e10cSrcweir 		{
138cdf0e10cSrcweir 			aRect = getListBox()->GetBoundingRect( pEntry );
139cdf0e10cSrcweir 			SvLBoxEntry* pParent = getListBox()->GetParent( pEntry );
140cdf0e10cSrcweir 			if ( pParent )
141cdf0e10cSrcweir 			{
142cdf0e10cSrcweir 				// position relative to parent entry
143cdf0e10cSrcweir 				Point aTopLeft = aRect.TopLeft();
144cdf0e10cSrcweir     			aTopLeft -= getListBox()->GetBoundingRect( pParent ).TopLeft();
145cdf0e10cSrcweir 				aRect = Rectangle( aTopLeft, aRect.GetSize() );
146cdf0e10cSrcweir 			}
147cdf0e10cSrcweir 		}
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 		return aRect;
150cdf0e10cSrcweir 	}
151cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
152cdf0e10cSrcweir 	Rectangle AccessibleListBoxEntry::GetBoundingBoxOnScreen_Impl() const
153cdf0e10cSrcweir 	{
154cdf0e10cSrcweir 		Rectangle aRect;
155cdf0e10cSrcweir 		SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
156cdf0e10cSrcweir 		if ( pEntry )
157cdf0e10cSrcweir 		{
158cdf0e10cSrcweir 			aRect = getListBox()->GetBoundingRect( pEntry );
159cdf0e10cSrcweir 			Point aTopLeft = aRect.TopLeft();
160cdf0e10cSrcweir     		aTopLeft += getListBox()->GetWindowExtentsRelative( NULL ).TopLeft();
161cdf0e10cSrcweir 			aRect = Rectangle( aTopLeft, aRect.GetSize() );
162cdf0e10cSrcweir 		}
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		return aRect;
165cdf0e10cSrcweir 	}
166cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
167cdf0e10cSrcweir 	sal_Bool AccessibleListBoxEntry::IsAlive_Impl() const
168cdf0e10cSrcweir 	{
169cdf0e10cSrcweir     	return ( !rBHelper.bDisposed && !rBHelper.bInDispose && isAlive() );
170cdf0e10cSrcweir 	}
171cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
172cdf0e10cSrcweir 	sal_Bool AccessibleListBoxEntry::IsShowing_Impl() const
173cdf0e10cSrcweir 	{
174cdf0e10cSrcweir 		Reference< XAccessible > xParent = implGetParentAccessible( );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 		sal_Bool bShowing = sal_False;
177cdf0e10cSrcweir 		Reference< XAccessibleContext > m_xParentContext =
178cdf0e10cSrcweir 			xParent.is() ? xParent->getAccessibleContext() : Reference< XAccessibleContext >();
179cdf0e10cSrcweir     	if( m_xParentContext.is() )
180cdf0e10cSrcweir     	{
181cdf0e10cSrcweir         	Reference< XAccessibleComponent > xParentComp( m_xParentContext, uno::UNO_QUERY );
182cdf0e10cSrcweir         	if( xParentComp.is() )
183cdf0e10cSrcweir             	bShowing = GetBoundingBox_Impl().IsOver( VCLRectangle( xParentComp->getBounds() ) );
184cdf0e10cSrcweir     	}
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 		return bShowing;
187cdf0e10cSrcweir 	}
188cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
189cdf0e10cSrcweir 	Rectangle AccessibleListBoxEntry::GetBoundingBox() throw ( lang::DisposedException )
190cdf0e10cSrcweir 	{
191cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
192cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 		EnsureIsAlive();
195cdf0e10cSrcweir     	return GetBoundingBox_Impl();
196cdf0e10cSrcweir 	}
197cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
198cdf0e10cSrcweir 	Rectangle AccessibleListBoxEntry::GetBoundingBoxOnScreen() throw ( lang::DisposedException )
199cdf0e10cSrcweir 	{
200cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
201cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 		EnsureIsAlive();
204cdf0e10cSrcweir     	return GetBoundingBoxOnScreen_Impl();
205cdf0e10cSrcweir 	}
206cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
207cdf0e10cSrcweir 	void AccessibleListBoxEntry::EnsureIsAlive() const throw ( lang::DisposedException )
208cdf0e10cSrcweir 	{
209cdf0e10cSrcweir     	if ( !IsAlive_Impl() )
210cdf0e10cSrcweir         	throw lang::DisposedException();
211cdf0e10cSrcweir 	}
212cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
213cdf0e10cSrcweir 	::rtl::OUString AccessibleListBoxEntry::implGetText()
214cdf0e10cSrcweir 	{
215cdf0e10cSrcweir 		::rtl::OUString sRet;
216cdf0e10cSrcweir 		SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
217*21075d77SSteve Yin 		//IAccessibility2 Implementation 2009-----
218cdf0e10cSrcweir 		if ( pEntry )
219*21075d77SSteve Yin 			sRet = getListBox()->SearchEntryTextWithHeadTitle( pEntry );
220*21075d77SSteve Yin 		//-----IAccessibility2 Implementation 2009
221cdf0e10cSrcweir 		return sRet;
222cdf0e10cSrcweir 	}
223cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
224cdf0e10cSrcweir 	Locale AccessibleListBoxEntry::implGetLocale()
225cdf0e10cSrcweir 	{
226cdf0e10cSrcweir     	Locale aLocale;
227cdf0e10cSrcweir 		aLocale = Application::GetSettings().GetUILocale();
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     	return aLocale;
230cdf0e10cSrcweir 	}
231cdf0e10cSrcweir 	void AccessibleListBoxEntry::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
232cdf0e10cSrcweir 	{
233cdf0e10cSrcweir 		nStartIndex = 0;
234cdf0e10cSrcweir 		nEndIndex = 0;
235cdf0e10cSrcweir 	}
236cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
237cdf0e10cSrcweir 	// XTypeProvider
238cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
239cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
240cdf0e10cSrcweir 	Sequence< sal_Int8 > AccessibleListBoxEntry::getImplementationId() throw (RuntimeException)
241cdf0e10cSrcweir 	{
242cdf0e10cSrcweir 		static ::cppu::OImplementationId* pId = NULL;
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 		if ( !pId )
245cdf0e10cSrcweir 		{
246cdf0e10cSrcweir 			::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 			if ( !pId )
249cdf0e10cSrcweir 			{
250cdf0e10cSrcweir 				static ::cppu::OImplementationId aId;
251cdf0e10cSrcweir 				pId = &aId;
252cdf0e10cSrcweir 			}
253cdf0e10cSrcweir 		}
254cdf0e10cSrcweir 		return pId->getImplementationId();
255cdf0e10cSrcweir 	}
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
258cdf0e10cSrcweir 	// XComponent/ListBoxAccessibleBase
259cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
260cdf0e10cSrcweir 	void SAL_CALL AccessibleListBoxEntry::dispose() throw ( uno::RuntimeException )
261cdf0e10cSrcweir 	{
262cdf0e10cSrcweir 		AccessibleListBoxEntry_BASE::dispose();
263cdf0e10cSrcweir 	}
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
266cdf0e10cSrcweir 	// XComponent
267cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
268cdf0e10cSrcweir 	void SAL_CALL AccessibleListBoxEntry::disposing()
269cdf0e10cSrcweir 	{
270cdf0e10cSrcweir 		ALBSolarGuard();
271cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 		Reference< XAccessible > xKeepAlive( this );
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         // Send a disposing to all listeners.
276cdf0e10cSrcweir 	    if ( m_nClientId )
277cdf0e10cSrcweir 	    {
278cdf0e10cSrcweir 			::comphelper::AccessibleEventNotifier::TClientId nId = m_nClientId;
279cdf0e10cSrcweir 		    m_nClientId =  0;
280cdf0e10cSrcweir             ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nId, *this );
281cdf0e10cSrcweir 	    }
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 		// clean up
284cdf0e10cSrcweir 		{
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 			ListBoxAccessibleBase::disposing();
287cdf0e10cSrcweir 		}
288cdf0e10cSrcweir 	    m_aParent = WeakReference< XAccessible >();
289cdf0e10cSrcweir 	}
290cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
291cdf0e10cSrcweir 	// XServiceInfo
292cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
293cdf0e10cSrcweir 	::rtl::OUString SAL_CALL AccessibleListBoxEntry::getImplementationName() throw(RuntimeException)
294cdf0e10cSrcweir 	{
295cdf0e10cSrcweir 		return getImplementationName_Static();
296cdf0e10cSrcweir 	}
297cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
298cdf0e10cSrcweir 	Sequence< ::rtl::OUString > SAL_CALL AccessibleListBoxEntry::getSupportedServiceNames() throw(RuntimeException)
299cdf0e10cSrcweir 	{
300cdf0e10cSrcweir 		return getSupportedServiceNames_Static();
301cdf0e10cSrcweir 	}
302cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
303cdf0e10cSrcweir 	sal_Bool SAL_CALL AccessibleListBoxEntry::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
304cdf0e10cSrcweir 	{
305cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
306cdf0e10cSrcweir 		const ::rtl::OUString* pSupported = aSupported.getConstArray();
307cdf0e10cSrcweir 		const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
308cdf0e10cSrcweir 		for ( ; pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported )
309cdf0e10cSrcweir 			;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 		return pSupported != pEnd;
312cdf0e10cSrcweir 	}
313cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
314cdf0e10cSrcweir 	// XServiceInfo - static methods
315cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
316cdf0e10cSrcweir 	Sequence< ::rtl::OUString > AccessibleListBoxEntry::getSupportedServiceNames_Static(void) throw( RuntimeException )
317cdf0e10cSrcweir 	{
318cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aSupported(3);
319cdf0e10cSrcweir 		aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleContext") );
320cdf0e10cSrcweir 		aSupported[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleComponent") );
321cdf0e10cSrcweir 		aSupported[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.AccessibleTreeListBoxEntry") );
322cdf0e10cSrcweir 		return aSupported;
323cdf0e10cSrcweir 	}
324cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
325cdf0e10cSrcweir 	::rtl::OUString AccessibleListBoxEntry::getImplementationName_Static(void) throw( RuntimeException )
326cdf0e10cSrcweir 	{
327cdf0e10cSrcweir 		return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.svtools.AccessibleTreeListBoxEntry") );
328cdf0e10cSrcweir 	}
329cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
330cdf0e10cSrcweir 	// XAccessible
331cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
332cdf0e10cSrcweir 	Reference< XAccessibleContext > SAL_CALL AccessibleListBoxEntry::getAccessibleContext(  ) throw (RuntimeException)
333cdf0e10cSrcweir 	{
334cdf0e10cSrcweir 		EnsureIsAlive();
335cdf0e10cSrcweir 		return this;
336cdf0e10cSrcweir 	}
337cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
338cdf0e10cSrcweir 	// XAccessibleContext
339cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
340cdf0e10cSrcweir 	sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleChildCount(  ) throw (RuntimeException)
341cdf0e10cSrcweir 	{
342cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
343cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 		EnsureIsAlive();
346cdf0e10cSrcweir 		SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
347cdf0e10cSrcweir 		sal_Int32 nCount = 0;
348cdf0e10cSrcweir 		if ( pEntry )
349cdf0e10cSrcweir 			nCount = getListBox()->GetLevelChildCount( pEntry );
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 		return nCount;
352cdf0e10cSrcweir 	}
353cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
354cdf0e10cSrcweir 	Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException,RuntimeException)
355cdf0e10cSrcweir 	{
356cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
357cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
358cdf0e10cSrcweir 		EnsureIsAlive();
359cdf0e10cSrcweir 
360*21075d77SSteve Yin //		SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
361*21075d77SSteve Yin //		SvLBoxEntry* pEntry = pParent ? getListBox()->GetEntry( pParent, i ) : NULL;
362*21075d77SSteve Yin 		SvLBoxEntry* pEntry =GetRealChild(i);
363cdf0e10cSrcweir 		if ( !pEntry )
364cdf0e10cSrcweir 			throw IndexOutOfBoundsException();
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 		return new AccessibleListBoxEntry( *getListBox(), pEntry, this );
367cdf0e10cSrcweir 	}
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
370cdf0e10cSrcweir 	Reference< XAccessible > AccessibleListBoxEntry::implGetParentAccessible( ) const
371cdf0e10cSrcweir 	{
372cdf0e10cSrcweir 		Reference< XAccessible > xParent = (Reference< XAccessible >)m_aParent;
373cdf0e10cSrcweir 		if ( !xParent.is() )
374cdf0e10cSrcweir 		{
375cdf0e10cSrcweir 			DBG_ASSERT( m_aEntryPath.size(), "AccessibleListBoxEntry::getAccessibleParent: invalid path!" );
376cdf0e10cSrcweir 			if ( 1 == m_aEntryPath.size() )
377cdf0e10cSrcweir 			{	// we're a top level entry
378cdf0e10cSrcweir 				// -> our parent is the tree listbox itself
379cdf0e10cSrcweir 				if ( getListBox() )
380cdf0e10cSrcweir 					xParent = getListBox()->GetAccessible( );
381cdf0e10cSrcweir 			}
382cdf0e10cSrcweir 			else
383cdf0e10cSrcweir 			{	// we have a entry as parent -> get it's accessible
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 				// shorten our access path by one
386cdf0e10cSrcweir 				::std::deque< sal_Int32 > aParentPath( m_aEntryPath );
387cdf0e10cSrcweir 				aParentPath.pop_back();
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 				// get the entry for this shortened access path
390cdf0e10cSrcweir 				SvLBoxEntry* pParentEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
391cdf0e10cSrcweir 				DBG_ASSERT( pParentEntry, "AccessibleListBoxEntry::implGetParentAccessible: could not obtain a parent entry!" );
392cdf0e10cSrcweir 
393*21075d77SSteve Yin 				//IAccessibility2 Implementation 2009-----
394*21075d77SSteve Yin 				if ( pParentEntry )
395*21075d77SSteve Yin 					pParentEntry = getListBox()->GetParent(pParentEntry);
396*21075d77SSteve Yin 				//-----IAccessibility2 Implementation 2009
397cdf0e10cSrcweir 				if ( pParentEntry )
398cdf0e10cSrcweir 					xParent = new AccessibleListBoxEntry( *getListBox(), pParentEntry, NULL );
399cdf0e10cSrcweir 					// note that we pass NULL here as parent-accessible:
400cdf0e10cSrcweir 					// this is allowed, as the AccessibleListBoxEntry class will create it's parent
401cdf0e10cSrcweir 					// when needed
402cdf0e10cSrcweir 			}
403cdf0e10cSrcweir 		}
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 		return xParent;
406cdf0e10cSrcweir 	}
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
409cdf0e10cSrcweir 	Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleParent(  ) throw (RuntimeException)
410cdf0e10cSrcweir 	{
411cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
412cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
413cdf0e10cSrcweir 		EnsureIsAlive();
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 		return implGetParentAccessible( );
416cdf0e10cSrcweir 	}
417cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
418cdf0e10cSrcweir 	sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleIndexInParent(  ) throw (RuntimeException)
419cdf0e10cSrcweir 	{
420cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 		DBG_ASSERT( !m_aEntryPath.empty(), "empty path" );
423cdf0e10cSrcweir     	return m_aEntryPath.empty() ? -1 : m_aEntryPath.back();
424cdf0e10cSrcweir 	}
425cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
426*21075d77SSteve Yin 	sal_Int32 SAL_CALL AccessibleListBoxEntry::getRoleType()
427*21075d77SSteve Yin 	{
428*21075d77SSteve Yin 		sal_Int32 nCase = 0;
429*21075d77SSteve Yin 		SvLBoxEntry* pEntry = getListBox()->GetEntry(0);
430*21075d77SSteve Yin 		if ( pEntry )
431*21075d77SSteve Yin 		{
432*21075d77SSteve Yin 			if( pEntry->HasChildsOnDemand() || getListBox()->GetChildCount(pEntry) > 0  )
433*21075d77SSteve Yin 			{
434*21075d77SSteve Yin 				nCase = 1;
435*21075d77SSteve Yin 				return nCase;
436*21075d77SSteve Yin 			}
437*21075d77SSteve Yin 		}
438*21075d77SSteve Yin 
439*21075d77SSteve Yin 		sal_Bool bHasButtons = (getListBox()->GetStyle() & WB_HASBUTTONS)!=0;
440*21075d77SSteve Yin 		if( !(getListBox()->GetTreeFlags() & TREEFLAG_CHKBTN) )
441*21075d77SSteve Yin 		{
442*21075d77SSteve Yin 			if( bHasButtons )
443*21075d77SSteve Yin 				nCase = 1;
444*21075d77SSteve Yin 		}
445*21075d77SSteve Yin 		else
446*21075d77SSteve Yin 		{
447*21075d77SSteve Yin 			if( bHasButtons )
448*21075d77SSteve Yin 				nCase = 2;
449*21075d77SSteve Yin 			 else
450*21075d77SSteve Yin 				nCase = 3;
451*21075d77SSteve Yin 		}
452*21075d77SSteve Yin 		return nCase;
453*21075d77SSteve Yin 	}
454cdf0e10cSrcweir 	sal_Int16 SAL_CALL AccessibleListBoxEntry::getAccessibleRole(  ) throw (RuntimeException)
455cdf0e10cSrcweir 	{
456*21075d77SSteve Yin 		SvTreeListBox* pBox = getListBox();
457*21075d77SSteve Yin 		if(pBox)
458*21075d77SSteve Yin 		{
459*21075d77SSteve Yin 			short nType = pBox->GetAllEntriesAccessibleRoleType();
460*21075d77SSteve Yin 			if( nType == TREEBOX_ALLITEM_ACCROLE_TYPE_TREE)
461*21075d77SSteve Yin 					return AccessibleRole::TREE_ITEM;
462*21075d77SSteve Yin 			else if( nType == TREEBOX_ALLITEM_ACCROLE_TYPE_LIST)
463*21075d77SSteve Yin 					return AccessibleRole::LIST_ITEM;
464*21075d77SSteve Yin 		}
465*21075d77SSteve Yin 
466*21075d77SSteve Yin 		sal_uInt16 treeFlag = pBox->GetTreeFlags();
467*21075d77SSteve Yin 		if(treeFlag & TREEFLAG_CHKBTN )
468*21075d77SSteve Yin 		{
469*21075d77SSteve Yin 			SvLBoxEntry* pEntry = pBox->GetEntryFromPath( m_aEntryPath );
470*21075d77SSteve Yin 			SvButtonState eState = pBox->GetCheckButtonState( pEntry );
471*21075d77SSteve Yin 			switch( eState )
472*21075d77SSteve Yin 			{
473*21075d77SSteve Yin 				case SV_BUTTON_CHECKED:
474*21075d77SSteve Yin 				case SV_BUTTON_UNCHECKED:
475*21075d77SSteve Yin 					return AccessibleRole::CHECK_BOX;
476*21075d77SSteve Yin 				case SV_BUTTON_TRISTATE:
477*21075d77SSteve Yin 				default:
478cdf0e10cSrcweir 					return AccessibleRole::LABEL;
479cdf0e10cSrcweir 			}
480*21075d77SSteve Yin 		}
481*21075d77SSteve Yin 		else
482*21075d77SSteve Yin 		{
483*21075d77SSteve Yin 
484*21075d77SSteve Yin 		if(getRoleType() == 0)
485*21075d77SSteve Yin 			return AccessibleRole::LIST_ITEM;
486*21075d77SSteve Yin 		else
487*21075d77SSteve Yin 			//o is: return AccessibleRole::LABEL;
488*21075d77SSteve Yin 			return AccessibleRole::TREE_ITEM;
489*21075d77SSteve Yin 		}
490*21075d77SSteve Yin 	}
491cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
492cdf0e10cSrcweir 	::rtl::OUString SAL_CALL AccessibleListBoxEntry::getAccessibleDescription(  ) throw (RuntimeException)
493cdf0e10cSrcweir 	{
494cdf0e10cSrcweir 		// no description for every item
495*21075d77SSteve Yin 		SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
496*21075d77SSteve Yin 		if( getAccessibleRole() == AccessibleRole::TREE_ITEM )
497*21075d77SSteve Yin 		{
498*21075d77SSteve Yin 			return getListBox()->GetEntryLongDescription( pEntry );
499*21075d77SSteve Yin 		}
500*21075d77SSteve Yin 		//want to cout the real column nubmer in the list box.
501*21075d77SSteve Yin 		sal_uInt16 iRealItemCount = 0;
502*21075d77SSteve Yin 		sal_uInt16 iCount = 0;
503*21075d77SSteve Yin 		sal_uInt16 iTotleItemCount = pEntry->ItemCount();
504*21075d77SSteve Yin 		SvLBoxItem* pItem;
505*21075d77SSteve Yin 		while( iCount < iTotleItemCount )
506*21075d77SSteve Yin 		{
507*21075d77SSteve Yin 			pItem = pEntry->GetItem( iCount );
508*21075d77SSteve Yin 			if ( pItem->IsA() == SV_ITEM_ID_LBOXSTRING &&
509*21075d77SSteve Yin 				 static_cast<SvLBoxString*>( pItem )->GetText().Len() > 0 )
510*21075d77SSteve Yin 			{
511*21075d77SSteve Yin 				iRealItemCount++;
512*21075d77SSteve Yin 			}
513*21075d77SSteve Yin 			iCount++;
514*21075d77SSteve Yin 		}
515*21075d77SSteve Yin 		if(iRealItemCount<=1  )
516*21075d77SSteve Yin 		{
517cdf0e10cSrcweir 			return ::rtl::OUString();
518cdf0e10cSrcweir 		}
519*21075d77SSteve Yin 		else
520*21075d77SSteve Yin 		{
521*21075d77SSteve Yin 			return getListBox()->SearchEntryTextWithHeadTitle( pEntry );
522*21075d77SSteve Yin 		}
523*21075d77SSteve Yin 
524*21075d77SSteve Yin 	}
525cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
526cdf0e10cSrcweir 	::rtl::OUString SAL_CALL AccessibleListBoxEntry::getAccessibleName(  ) throw (RuntimeException)
527cdf0e10cSrcweir 	{
528cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
529cdf0e10cSrcweir 
530cdf0e10cSrcweir 		EnsureIsAlive();
531*21075d77SSteve Yin 
532*21075d77SSteve Yin 		::rtl::OUString sRet;
533*21075d77SSteve Yin 		sRet = implGetText();
534*21075d77SSteve Yin 
535*21075d77SSteve Yin 		SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
536*21075d77SSteve Yin 
537*21075d77SSteve Yin 		String altText = getListBox()->GetEntryAltText( pEntry );
538*21075d77SSteve Yin 		if( altText.Len() > 0 )
539*21075d77SSteve Yin 		{
540*21075d77SSteve Yin 			sRet += ::rtl::OUString(' ');
541*21075d77SSteve Yin 			sRet += altText;
542*21075d77SSteve Yin 		}
543*21075d77SSteve Yin 
544*21075d77SSteve Yin 		// IA2 CWS. Removed for now - only used in Sw/Sd/ScContentLBoxString, they should decide if they need this
545*21075d77SSteve Yin 		// if ( pEntry && pEntry->IsMarked())
546*21075d77SSteve Yin 		//	sRet = sRet + ::rtl::OUString(TK_RES_STRING(STR_SVT_ACC_LISTENTRY_SELCTED_STATE));
547*21075d77SSteve Yin 
548*21075d77SSteve Yin 		return sRet;
549cdf0e10cSrcweir 	}
550cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
551cdf0e10cSrcweir 	Reference< XAccessibleRelationSet > SAL_CALL AccessibleListBoxEntry::getAccessibleRelationSet(  ) throw (RuntimeException)
552cdf0e10cSrcweir 	{
553cdf0e10cSrcweir         Reference< XAccessibleRelationSet > xRelSet;
554cdf0e10cSrcweir         Reference< XAccessible > xParent;
555cdf0e10cSrcweir         if ( m_aEntryPath.size() > 1 ) // not a root entry
556cdf0e10cSrcweir             xParent = implGetParentAccessible();
557cdf0e10cSrcweir         if ( xParent.is() )
558cdf0e10cSrcweir         {
559cdf0e10cSrcweir             utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
560cdf0e10cSrcweir             Sequence< Reference< XInterface > > aSequence(1);
561cdf0e10cSrcweir             aSequence[0] = xParent;
562cdf0e10cSrcweir             pRelationSetHelper->AddRelation(
563cdf0e10cSrcweir                 AccessibleRelation( AccessibleRelationType::NODE_CHILD_OF, aSequence ) );
564cdf0e10cSrcweir             xRelSet = pRelationSetHelper;
565cdf0e10cSrcweir         }
566cdf0e10cSrcweir         return xRelSet;
567cdf0e10cSrcweir 	}
568cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
569cdf0e10cSrcweir 	Reference< XAccessibleStateSet > SAL_CALL AccessibleListBoxEntry::getAccessibleStateSet(  ) throw (RuntimeException)
570cdf0e10cSrcweir 	{
571cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
572cdf0e10cSrcweir 
573cdf0e10cSrcweir     	utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
574cdf0e10cSrcweir 		Reference< XAccessibleStateSet > xStateSet = pStateSetHelper;
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 		if ( IsAlive_Impl() )
577cdf0e10cSrcweir 		{
578*21075d77SSteve Yin 			switch(getAccessibleRole())
579*21075d77SSteve Yin 			{
580*21075d77SSteve Yin 				case AccessibleRole::LABEL:
581cdf0e10cSrcweir 			       	pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
582cdf0e10cSrcweir 			       	pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
583cdf0e10cSrcweir 			       	pStateSetHelper->AddState( AccessibleStateType::ENABLED );
584cdf0e10cSrcweir 					if ( getListBox()->IsInplaceEditingEnabled() )
585cdf0e10cSrcweir 				       	pStateSetHelper->AddState( AccessibleStateType::EDITABLE );
586cdf0e10cSrcweir 					if ( IsShowing_Impl() )
587cdf0e10cSrcweir 				        	pStateSetHelper->AddState( AccessibleStateType::SHOWING );
588*21075d77SSteve Yin 					break;
589*21075d77SSteve Yin 				case AccessibleRole::CHECK_BOX:
590*21075d77SSteve Yin 			       	pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
591*21075d77SSteve Yin 			       	pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
592*21075d77SSteve Yin 			       	pStateSetHelper->AddState( AccessibleStateType::ENABLED );
593*21075d77SSteve Yin 					if ( IsShowing_Impl() )
594*21075d77SSteve Yin 				        	pStateSetHelper->AddState( AccessibleStateType::SHOWING );
595*21075d77SSteve Yin 					break;
596*21075d77SSteve Yin 			}
597cdf0e10cSrcweir 			getListBox()->FillAccessibleEntryStateSet(
598cdf0e10cSrcweir 				getListBox()->GetEntryFromPath( m_aEntryPath ), *pStateSetHelper );
599cdf0e10cSrcweir 		}
600cdf0e10cSrcweir 		else
601cdf0e10cSrcweir         	pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
602cdf0e10cSrcweir 
603cdf0e10cSrcweir     	return xStateSet;
604cdf0e10cSrcweir 	}
605cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
606cdf0e10cSrcweir 	Locale SAL_CALL AccessibleListBoxEntry::getLocale(  ) throw (IllegalAccessibleComponentStateException, RuntimeException)
607cdf0e10cSrcweir 	{
608cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
609cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 		return implGetLocale();
612cdf0e10cSrcweir 	}
613cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
614cdf0e10cSrcweir 	// XAccessibleComponent
615cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
616cdf0e10cSrcweir 	sal_Bool SAL_CALL AccessibleListBoxEntry::containsPoint( const awt::Point& rPoint ) throw (RuntimeException)
617cdf0e10cSrcweir 	{
618cdf0e10cSrcweir     	return Rectangle( Point(), GetBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) );
619cdf0e10cSrcweir 	}
620cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
621cdf0e10cSrcweir 	Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getAccessibleAtPoint( const awt::Point& _aPoint ) throw (RuntimeException)
622cdf0e10cSrcweir 	{
623cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
624cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
625cdf0e10cSrcweir 
626cdf0e10cSrcweir 		EnsureIsAlive();
627cdf0e10cSrcweir 		SvLBoxEntry* pEntry = getListBox()->GetEntry( VCLPoint( _aPoint ) );
628cdf0e10cSrcweir 		if ( !pEntry )
629cdf0e10cSrcweir 			throw RuntimeException();
630cdf0e10cSrcweir 
631cdf0e10cSrcweir 		Reference< XAccessible > xAcc;
632cdf0e10cSrcweir 		AccessibleListBoxEntry* pAccEntry = new AccessibleListBoxEntry( *getListBox(), pEntry, this );
633cdf0e10cSrcweir 		Rectangle aRect = pAccEntry->GetBoundingBox_Impl();
634cdf0e10cSrcweir 		if ( aRect.IsInside( VCLPoint( _aPoint ) ) )
635cdf0e10cSrcweir 			xAcc = pAccEntry;
636cdf0e10cSrcweir 		return xAcc;
637cdf0e10cSrcweir 	}
638cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
639cdf0e10cSrcweir 	awt::Rectangle SAL_CALL AccessibleListBoxEntry::getBounds(  ) throw (RuntimeException)
640cdf0e10cSrcweir 	{
641cdf0e10cSrcweir     	return AWTRectangle( GetBoundingBox() );
642cdf0e10cSrcweir 	}
643cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
644cdf0e10cSrcweir 	awt::Point SAL_CALL AccessibleListBoxEntry::getLocation(  ) throw (RuntimeException)
645cdf0e10cSrcweir 	{
646cdf0e10cSrcweir     	return AWTPoint( GetBoundingBox().TopLeft() );
647cdf0e10cSrcweir 	}
648cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
649cdf0e10cSrcweir 	awt::Point SAL_CALL AccessibleListBoxEntry::getLocationOnScreen(  ) throw (RuntimeException)
650cdf0e10cSrcweir 	{
651cdf0e10cSrcweir     	return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
652cdf0e10cSrcweir 	}
653cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
654cdf0e10cSrcweir 	awt::Size SAL_CALL AccessibleListBoxEntry::getSize(  ) throw (RuntimeException)
655cdf0e10cSrcweir 	{
656cdf0e10cSrcweir     	return AWTSize( GetBoundingBox().GetSize() );
657cdf0e10cSrcweir 	}
658cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
659cdf0e10cSrcweir 	void SAL_CALL AccessibleListBoxEntry::grabFocus(  ) throw (RuntimeException)
660cdf0e10cSrcweir 	{
661cdf0e10cSrcweir 		// do nothing, because no focus for each item
662cdf0e10cSrcweir 	}
663cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
664cdf0e10cSrcweir 	sal_Int32 AccessibleListBoxEntry::getForeground(	) throw (RuntimeException)
665cdf0e10cSrcweir 	{
666cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
667cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
668cdf0e10cSrcweir 
669cdf0e10cSrcweir 		sal_Int32 nColor = 0;
670cdf0e10cSrcweir 		Reference< XAccessible > xParent = getAccessibleParent();
671cdf0e10cSrcweir 		if ( xParent.is() )
672cdf0e10cSrcweir 		{
673cdf0e10cSrcweir 			Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
674cdf0e10cSrcweir 			if ( xParentComp.is() )
675cdf0e10cSrcweir 				nColor = xParentComp->getForeground();
676cdf0e10cSrcweir 		}
677cdf0e10cSrcweir 
678cdf0e10cSrcweir 		return nColor;
679cdf0e10cSrcweir 	}
680cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
681cdf0e10cSrcweir 	sal_Int32 AccessibleListBoxEntry::getBackground(  ) throw (RuntimeException)
682cdf0e10cSrcweir 	{
683cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
684cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
685cdf0e10cSrcweir 
686cdf0e10cSrcweir 		sal_Int32 nColor = 0;
687cdf0e10cSrcweir 		Reference< XAccessible > xParent = getAccessibleParent();
688cdf0e10cSrcweir 		if ( xParent.is() )
689cdf0e10cSrcweir 		{
690cdf0e10cSrcweir 			Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
691cdf0e10cSrcweir 			if ( xParentComp.is() )
692cdf0e10cSrcweir 				nColor = xParentComp->getBackground();
693cdf0e10cSrcweir 		}
694cdf0e10cSrcweir 
695cdf0e10cSrcweir 		return nColor;
696cdf0e10cSrcweir 	}
697cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
698cdf0e10cSrcweir 	// XAccessibleText
699cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
700cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
701cdf0e10cSrcweir 	awt::Rectangle SAL_CALL AccessibleListBoxEntry::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
702cdf0e10cSrcweir 	{
703cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
704cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
705cdf0e10cSrcweir 
706cdf0e10cSrcweir 		EnsureIsAlive();
707cdf0e10cSrcweir 
708cdf0e10cSrcweir         if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
709cdf0e10cSrcweir             throw IndexOutOfBoundsException();
710cdf0e10cSrcweir 
711cdf0e10cSrcweir 		awt::Rectangle aBounds( 0, 0, 0, 0 );
712cdf0e10cSrcweir 		SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
713cdf0e10cSrcweir 		if ( pEntry )
714cdf0e10cSrcweir 		{
715cdf0e10cSrcweir 			::vcl::ControlLayoutData aLayoutData;
716cdf0e10cSrcweir 			Rectangle aItemRect = GetBoundingBox();
717cdf0e10cSrcweir 			getListBox()->RecordLayoutData( &aLayoutData, aItemRect );
718cdf0e10cSrcweir 			Rectangle aCharRect = aLayoutData.GetCharacterBounds( nIndex );
719cdf0e10cSrcweir 			aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
720cdf0e10cSrcweir 			aBounds = AWTRectangle( aCharRect );
721cdf0e10cSrcweir 		}
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 		return aBounds;
724cdf0e10cSrcweir 	}
725cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
726cdf0e10cSrcweir 	sal_Int32 SAL_CALL AccessibleListBoxEntry::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
727cdf0e10cSrcweir 	{
728cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
729cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
730cdf0e10cSrcweir 		EnsureIsAlive();
731*21075d77SSteve Yin 		if(aPoint.X==0 && aPoint.Y==0) return 0;
732cdf0e10cSrcweir 
733cdf0e10cSrcweir 		sal_Int32 nIndex = -1;
734cdf0e10cSrcweir 		SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
735cdf0e10cSrcweir 		if ( pEntry )
736cdf0e10cSrcweir 		{
737cdf0e10cSrcweir 			::vcl::ControlLayoutData aLayoutData;
738cdf0e10cSrcweir 			Rectangle aItemRect = GetBoundingBox();
739cdf0e10cSrcweir 			getListBox()->RecordLayoutData( &aLayoutData, aItemRect );
740cdf0e10cSrcweir 			Point aPnt( VCLPoint( aPoint ) );
741cdf0e10cSrcweir 			aPnt += aItemRect.TopLeft();
742cdf0e10cSrcweir 			nIndex = aLayoutData.GetIndexForPoint( aPnt );
743cdf0e10cSrcweir 		}
744cdf0e10cSrcweir 
745cdf0e10cSrcweir 	    return nIndex;
746cdf0e10cSrcweir 	}
747cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
748cdf0e10cSrcweir 	sal_Bool SAL_CALL AccessibleListBoxEntry::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
749cdf0e10cSrcweir 	{
750cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
751cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
752cdf0e10cSrcweir 		EnsureIsAlive();
753cdf0e10cSrcweir 
754cdf0e10cSrcweir 		String sText = getText();
755cdf0e10cSrcweir 		if	( ( 0 > nStartIndex ) || ( sText.Len() <= nStartIndex )
756cdf0e10cSrcweir 			|| ( 0 > nEndIndex ) || ( sText.Len() <= nEndIndex ) )
757cdf0e10cSrcweir 			throw IndexOutOfBoundsException();
758cdf0e10cSrcweir 
759cdf0e10cSrcweir 		sal_Int32 nLen = nEndIndex - nStartIndex + 1;
760cdf0e10cSrcweir         ::svt::OStringTransfer::CopyString( sText.Copy( (sal_uInt16)nStartIndex, (sal_uInt16)nLen ), getListBox() );
761cdf0e10cSrcweir 
762cdf0e10cSrcweir 		return sal_True;
763cdf0e10cSrcweir 	}
764cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
765cdf0e10cSrcweir 	// XAccessibleEventBroadcaster
766cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
767cdf0e10cSrcweir 	void SAL_CALL AccessibleListBoxEntry::addEventListener( const Reference< XAccessibleEventListener >& xListener ) throw (RuntimeException)
768cdf0e10cSrcweir 	{
769cdf0e10cSrcweir 	    if (xListener.is())
770cdf0e10cSrcweir         {
771cdf0e10cSrcweir 			::osl::MutexGuard aGuard( m_aMutex );
772cdf0e10cSrcweir 		    if (!m_nClientId)
773cdf0e10cSrcweir                 m_nClientId = comphelper::AccessibleEventNotifier::registerClient( );
774cdf0e10cSrcweir 		    comphelper::AccessibleEventNotifier::addEventListener( m_nClientId, xListener );
775cdf0e10cSrcweir         }
776cdf0e10cSrcweir 	}
777cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
778cdf0e10cSrcweir 	void SAL_CALL AccessibleListBoxEntry::removeEventListener( const Reference< XAccessibleEventListener >& xListener ) throw (RuntimeException)
779cdf0e10cSrcweir 	{
780cdf0e10cSrcweir 	    if (xListener.is())
781cdf0e10cSrcweir 	    {
782cdf0e10cSrcweir 			::osl::MutexGuard aGuard( m_aMutex );
783cdf0e10cSrcweir 
784cdf0e10cSrcweir             sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId, xListener );
785cdf0e10cSrcweir 		    if ( !nListenerCount )
786cdf0e10cSrcweir 		    {
787cdf0e10cSrcweir 			    // no listeners anymore
788cdf0e10cSrcweir 			    // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
789cdf0e10cSrcweir 			    // and at least to us not firing any events anymore, in case somebody calls
790cdf0e10cSrcweir 			    // NotifyAccessibleEvent, again
791cdf0e10cSrcweir 				sal_Int32 nId = m_nClientId;
792cdf0e10cSrcweir 				m_nClientId = 0;
793cdf0e10cSrcweir 			    comphelper::AccessibleEventNotifier::revokeClient( nId );
794cdf0e10cSrcweir 
795cdf0e10cSrcweir 		    }
796cdf0e10cSrcweir 	    }
797cdf0e10cSrcweir 	}
798cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
799cdf0e10cSrcweir 	// XAccessibleAction
800cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
801cdf0e10cSrcweir     sal_Int32 SAL_CALL AccessibleListBoxEntry::getAccessibleActionCount(  ) throw (RuntimeException)
802cdf0e10cSrcweir 	{
803cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
804cdf0e10cSrcweir 
805cdf0e10cSrcweir 		// three actions supported
806*21075d77SSteve Yin 		SvTreeListBox* pBox = getListBox();
807*21075d77SSteve Yin 		sal_uInt16 treeFlag = pBox->GetTreeFlags();
808*21075d77SSteve Yin 		sal_Bool bHasButtons = (getListBox()->GetStyle() & WB_HASBUTTONS)!=0;
809*21075d77SSteve Yin 		if( (treeFlag & TREEFLAG_CHKBTN) && !bHasButtons)
810*21075d77SSteve Yin 		{
811*21075d77SSteve Yin 			sal_Int16 role = getAccessibleRole();
812*21075d77SSteve Yin 			if ( role == AccessibleRole::CHECK_BOX )
813*21075d77SSteve Yin 				return 2;
814*21075d77SSteve Yin 			else if ( role == AccessibleRole::LABEL )
815*21075d77SSteve Yin 				return 0;
816*21075d77SSteve Yin 		}
817*21075d77SSteve Yin 		else
818cdf0e10cSrcweir 			return ACCESSIBLE_ACTION_COUNT;
819*21075d77SSteve Yin 		return 0;
820cdf0e10cSrcweir 	}
821cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
822cdf0e10cSrcweir     sal_Bool SAL_CALL AccessibleListBoxEntry::doAccessibleAction( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
823cdf0e10cSrcweir 	{
824cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
825cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
826cdf0e10cSrcweir 
827cdf0e10cSrcweir 		sal_Bool bRet = sal_False;
828cdf0e10cSrcweir 		checkActionIndex_Impl( nIndex );
829cdf0e10cSrcweir 		EnsureIsAlive();
830*21075d77SSteve Yin 		sal_uInt16 treeFlag = getListBox()->GetTreeFlags();
831*21075d77SSteve Yin 		if( nIndex == 0 && (treeFlag & TREEFLAG_CHKBTN) )
832*21075d77SSteve Yin 		{
833*21075d77SSteve Yin 			if(getAccessibleRole() == AccessibleRole::CHECK_BOX)
834*21075d77SSteve Yin 			{
835*21075d77SSteve Yin 				SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
836*21075d77SSteve Yin 				SvButtonState state = getListBox()->GetCheckButtonState( pEntry );
837*21075d77SSteve Yin 				if ( state == SV_BUTTON_CHECKED )
838*21075d77SSteve Yin 					getListBox()->SetCheckButtonState(pEntry, (SvButtonState)SV_BMP_UNCHECKED);
839*21075d77SSteve Yin 				else if (state == SV_BMP_UNCHECKED)
840*21075d77SSteve Yin 					getListBox()->SetCheckButtonState(pEntry, (SvButtonState)SV_BUTTON_CHECKED);
841*21075d77SSteve Yin 			}
842*21075d77SSteve Yin 		}else if( (nIndex == 1 && (treeFlag & TREEFLAG_CHKBTN) ) || (nIndex == 0) )
843*21075d77SSteve Yin 		{
844cdf0e10cSrcweir 			SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
845cdf0e10cSrcweir 			if ( pEntry )
846cdf0e10cSrcweir 			{
847cdf0e10cSrcweir 				if ( getListBox()->IsExpanded( pEntry ) )
848cdf0e10cSrcweir 					getListBox()->Collapse( pEntry );
849cdf0e10cSrcweir 				else
850cdf0e10cSrcweir 					getListBox()->Expand( pEntry );
851cdf0e10cSrcweir 				bRet = sal_True;
852cdf0e10cSrcweir 			}
853*21075d77SSteve Yin 		}
854cdf0e10cSrcweir 		return bRet;
855cdf0e10cSrcweir 	}
856cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
857cdf0e10cSrcweir     ::rtl::OUString SAL_CALL AccessibleListBoxEntry::getAccessibleActionDescription( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
858cdf0e10cSrcweir 	{
859cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
860cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
861cdf0e10cSrcweir 
862cdf0e10cSrcweir 		checkActionIndex_Impl( nIndex );
863cdf0e10cSrcweir 		EnsureIsAlive();
864cdf0e10cSrcweir 
865cdf0e10cSrcweir 		static const ::rtl::OUString sActionDesc( RTL_CONSTASCII_USTRINGPARAM( "toggleExpand" ) );
866*21075d77SSteve Yin 		static const ::rtl::OUString sActionDesc1( RTL_CONSTASCII_USTRINGPARAM( "Check" ) );
867*21075d77SSteve Yin 		static const ::rtl::OUString sActionDesc2( RTL_CONSTASCII_USTRINGPARAM( "UnCheck" ) );
868*21075d77SSteve Yin 		// sal_Bool bHasButtons = (getListBox()->GetStyle() & WB_HASBUTTONS)!=0;
869*21075d77SSteve Yin 		SvLBoxEntry* pEntry = getListBox()->GetEntryFromPath( m_aEntryPath );
870*21075d77SSteve Yin 		SvButtonState state = getListBox()->GetCheckButtonState( pEntry );
871*21075d77SSteve Yin 		sal_uInt16 treeFlag = getListBox()->GetTreeFlags();
872*21075d77SSteve Yin 		if(nIndex == 0 && (treeFlag & TREEFLAG_CHKBTN))
873*21075d77SSteve Yin 		{
874*21075d77SSteve Yin 			if(getAccessibleRole() == AccessibleRole::CHECK_BOX)
875*21075d77SSteve Yin 			{
876*21075d77SSteve Yin 				if ( state == SV_BUTTON_CHECKED )
877*21075d77SSteve Yin 					return sActionDesc2;
878*21075d77SSteve Yin 				else if (state == SV_BMP_UNCHECKED)
879*21075d77SSteve Yin 					return sActionDesc1;
880*21075d77SSteve Yin 			}
881*21075d77SSteve Yin 			else
882*21075d77SSteve Yin 			{
883*21075d77SSteve Yin 				//Sometimes, a List or Tree may have both checkbox and label at the same time
884*21075d77SSteve Yin 				return ::rtl::OUString();
885*21075d77SSteve Yin 			}
886*21075d77SSteve Yin 		}else if( (nIndex == 1 && (treeFlag & TREEFLAG_CHKBTN)) || nIndex == 0 )
887*21075d77SSteve Yin 		{
888*21075d77SSteve Yin 			//IAccessibility2 Implementation 2009-----
889*21075d77SSteve Yin 			if( pEntry->HasChilds() || pEntry->HasChildsOnDemand() )
890*21075d77SSteve Yin 			//-----IAccessibility2 Implementation 2009
891*21075d77SSteve Yin 				return getListBox()->IsExpanded( pEntry ) ? \
892*21075d77SSteve Yin 				::rtl::OUString(TK_RES_STRING(STR_SVT_ACC_ACTION_COLLAPSE)) :
893*21075d77SSteve Yin 				::rtl::OUString(TK_RES_STRING(STR_SVT_ACC_ACTION_EXPAND));
894*21075d77SSteve Yin 			return ::rtl::OUString();
895*21075d77SSteve Yin 
896*21075d77SSteve Yin 		}
897*21075d77SSteve Yin 		throw IndexOutOfBoundsException();
898cdf0e10cSrcweir 	}
899cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
900cdf0e10cSrcweir 	Reference< XAccessibleKeyBinding > AccessibleListBoxEntry::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
901cdf0e10cSrcweir 	{
902cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
903cdf0e10cSrcweir 
904cdf0e10cSrcweir 		Reference< XAccessibleKeyBinding > xRet;
905cdf0e10cSrcweir 		checkActionIndex_Impl( nIndex );
906cdf0e10cSrcweir 		// ... which key?
907cdf0e10cSrcweir 		return xRet;
908cdf0e10cSrcweir 	}
909cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
910cdf0e10cSrcweir 	// XAccessibleSelection
911cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
912cdf0e10cSrcweir 	void SAL_CALL AccessibleListBoxEntry::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
913cdf0e10cSrcweir 	{
914cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
915cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
916cdf0e10cSrcweir 
917cdf0e10cSrcweir 		EnsureIsAlive();
918*21075d77SSteve Yin // IAccessible2 implementation, 2009
919*21075d77SSteve Yin //		SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
920*21075d77SSteve Yin //		SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, nChildIndex );
921cdf0e10cSrcweir 
922*21075d77SSteve Yin 		SvLBoxEntry* pEntry =GetRealChild(nChildIndex);
923cdf0e10cSrcweir 		if ( !pEntry )
924cdf0e10cSrcweir 			throw IndexOutOfBoundsException();
925cdf0e10cSrcweir 
926cdf0e10cSrcweir 		getListBox()->Select( pEntry, sal_True );
927cdf0e10cSrcweir 	}
928cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
929cdf0e10cSrcweir 	sal_Bool SAL_CALL AccessibleListBoxEntry::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
930cdf0e10cSrcweir 	{
931cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
932cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
933cdf0e10cSrcweir 
934cdf0e10cSrcweir 		EnsureIsAlive();
935cdf0e10cSrcweir 
936cdf0e10cSrcweir 		SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
937cdf0e10cSrcweir 		SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, nChildIndex );
938cdf0e10cSrcweir 		if ( !pEntry )
939cdf0e10cSrcweir 			throw IndexOutOfBoundsException();
940cdf0e10cSrcweir 
941cdf0e10cSrcweir 		return getListBox()->IsSelected( pEntry );
942cdf0e10cSrcweir 	}
943cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
944cdf0e10cSrcweir 	void SAL_CALL AccessibleListBoxEntry::clearAccessibleSelection(  ) throw (RuntimeException)
945cdf0e10cSrcweir 	{
946cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
947cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
948cdf0e10cSrcweir 
949cdf0e10cSrcweir 		EnsureIsAlive();
950cdf0e10cSrcweir 
951cdf0e10cSrcweir 		SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
952cdf0e10cSrcweir 		if ( !pParent )
953cdf0e10cSrcweir 			throw RuntimeException();
954cdf0e10cSrcweir     	sal_Int32 i, nCount = 0;
955cdf0e10cSrcweir 		nCount = getListBox()->GetLevelChildCount( pParent );
956cdf0e10cSrcweir 		for ( i = 0; i < nCount; ++i )
957cdf0e10cSrcweir 		{
958cdf0e10cSrcweir 			SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, i );
959cdf0e10cSrcweir 			if ( getListBox()->IsSelected( pEntry ) )
960cdf0e10cSrcweir 				getListBox()->Select( pEntry, sal_False );
961cdf0e10cSrcweir 		}
962cdf0e10cSrcweir 	}
963cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
964cdf0e10cSrcweir 	void SAL_CALL AccessibleListBoxEntry::selectAllAccessibleChildren(  ) throw (RuntimeException)
965cdf0e10cSrcweir 	{
966cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
967cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
968cdf0e10cSrcweir 
969cdf0e10cSrcweir 		EnsureIsAlive();
970cdf0e10cSrcweir 
971cdf0e10cSrcweir 		SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
972cdf0e10cSrcweir 		if ( !pParent )
973cdf0e10cSrcweir 			throw RuntimeException();
974cdf0e10cSrcweir     	sal_Int32 i, nCount = 0;
975cdf0e10cSrcweir 		nCount = getListBox()->GetLevelChildCount( pParent );
976cdf0e10cSrcweir 		for ( i = 0; i < nCount; ++i )
977cdf0e10cSrcweir 		{
978cdf0e10cSrcweir 			SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, i );
979cdf0e10cSrcweir 			if ( !getListBox()->IsSelected( pEntry ) )
980cdf0e10cSrcweir 				getListBox()->Select( pEntry, sal_True );
981cdf0e10cSrcweir 		}
982cdf0e10cSrcweir 	}
983cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
984cdf0e10cSrcweir 	sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectedAccessibleChildCount(  ) throw (RuntimeException)
985cdf0e10cSrcweir 	{
986cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
987cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
988cdf0e10cSrcweir 
989cdf0e10cSrcweir 		EnsureIsAlive();
990cdf0e10cSrcweir 
991cdf0e10cSrcweir     	sal_Int32 i, nSelCount = 0, nCount = 0;
992cdf0e10cSrcweir 
993cdf0e10cSrcweir 		SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
994cdf0e10cSrcweir 		if ( !pParent )
995cdf0e10cSrcweir 			throw RuntimeException();
996cdf0e10cSrcweir 		nCount = getListBox()->GetLevelChildCount( pParent );
997cdf0e10cSrcweir 		for ( i = 0; i < nCount; ++i )
998cdf0e10cSrcweir 		{
999cdf0e10cSrcweir 			SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, i );
1000cdf0e10cSrcweir 			if ( getListBox()->IsSelected( pEntry ) )
1001cdf0e10cSrcweir 				++nSelCount;
1002cdf0e10cSrcweir 		}
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir     	return nSelCount;
1005cdf0e10cSrcweir 	}
1006cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
1007cdf0e10cSrcweir 	Reference< XAccessible > SAL_CALL AccessibleListBoxEntry::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
1008cdf0e10cSrcweir 	{
1009cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
1010cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir 		EnsureIsAlive();
1013cdf0e10cSrcweir 
1014cdf0e10cSrcweir 		if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
1015cdf0e10cSrcweir 			throw IndexOutOfBoundsException();
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir 		Reference< XAccessible > xChild;
1018cdf0e10cSrcweir     	sal_Int32 i, nSelCount = 0, nCount = 0;
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir 		SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
1021cdf0e10cSrcweir 		if ( !pParent )
1022cdf0e10cSrcweir 			throw RuntimeException();
1023cdf0e10cSrcweir 		nCount = getListBox()->GetLevelChildCount( pParent );
1024cdf0e10cSrcweir 		for ( i = 0; i < nCount; ++i )
1025cdf0e10cSrcweir 		{
1026cdf0e10cSrcweir 			SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, i );
1027cdf0e10cSrcweir 			if ( getListBox()->IsSelected( pEntry ) )
1028cdf0e10cSrcweir 				++nSelCount;
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir 			if ( nSelCount == ( nSelectedChildIndex + 1 ) )
1031cdf0e10cSrcweir 			{
1032cdf0e10cSrcweir 				xChild = new AccessibleListBoxEntry( *getListBox(), pEntry, this );
1033cdf0e10cSrcweir 				break;
1034cdf0e10cSrcweir 			}
1035cdf0e10cSrcweir 		}
1036cdf0e10cSrcweir 
1037cdf0e10cSrcweir 		return xChild;
1038cdf0e10cSrcweir 	}
1039cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
1040cdf0e10cSrcweir 	void SAL_CALL AccessibleListBoxEntry::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
1041cdf0e10cSrcweir 	{
1042cdf0e10cSrcweir     	ALBSolarGuard aSolarGuard;
1043cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir 		EnsureIsAlive();
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir 		SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
1048cdf0e10cSrcweir 		SvLBoxEntry* pEntry = getListBox()->GetEntry( pParent, nSelectedChildIndex );
1049cdf0e10cSrcweir 		if ( !pEntry )
1050cdf0e10cSrcweir 			throw IndexOutOfBoundsException();
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir 		getListBox()->Select( pEntry, sal_False );
1053cdf0e10cSrcweir 	}
1054cdf0e10cSrcweir 	sal_Int32 SAL_CALL AccessibleListBoxEntry::getCaretPosition(  ) throw (::com::sun::star::uno::RuntimeException)
1055cdf0e10cSrcweir 	{
1056cdf0e10cSrcweir 		return -1;
1057cdf0e10cSrcweir 	}
1058cdf0e10cSrcweir 	sal_Bool SAL_CALL AccessibleListBoxEntry::setCaretPosition ( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
1059cdf0e10cSrcweir 	{
1060cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1061cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1062cdf0e10cSrcweir 		EnsureIsAlive();
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir 		if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
1065cdf0e10cSrcweir 			throw IndexOutOfBoundsException();
1066cdf0e10cSrcweir 
1067cdf0e10cSrcweir 		return sal_False;
1068cdf0e10cSrcweir 	}
1069cdf0e10cSrcweir 	sal_Unicode SAL_CALL AccessibleListBoxEntry::getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
1070cdf0e10cSrcweir 	{
1071cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1072cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1073cdf0e10cSrcweir 		EnsureIsAlive();
1074cdf0e10cSrcweir 		return OCommonAccessibleText::getCharacter( nIndex );
1075cdf0e10cSrcweir 	}
1076cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL AccessibleListBoxEntry::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
1077cdf0e10cSrcweir 	{
1078cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1079cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1080cdf0e10cSrcweir 		EnsureIsAlive();
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir 		::rtl::OUString sText( implGetText() );
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir 		if ( !implIsValidIndex( nIndex, sText.getLength() ) )
1085cdf0e10cSrcweir 			throw IndexOutOfBoundsException();
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir 		return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >();
1088cdf0e10cSrcweir 	}
1089cdf0e10cSrcweir 	sal_Int32 SAL_CALL AccessibleListBoxEntry::getCharacterCount(  ) throw (::com::sun::star::uno::RuntimeException)
1090cdf0e10cSrcweir 	{
1091cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1092cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1093cdf0e10cSrcweir 		EnsureIsAlive();
1094cdf0e10cSrcweir 		return OCommonAccessibleText::getCharacterCount(  );
1095cdf0e10cSrcweir 	}
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir 	::rtl::OUString SAL_CALL AccessibleListBoxEntry::getSelectedText(  ) throw (::com::sun::star::uno::RuntimeException)
1098cdf0e10cSrcweir 	{
1099cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1100cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1101cdf0e10cSrcweir 		EnsureIsAlive();
1102cdf0e10cSrcweir 		return OCommonAccessibleText::getSelectedText(  );
1103cdf0e10cSrcweir 	}
1104cdf0e10cSrcweir 	sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectionStart(  ) throw (::com::sun::star::uno::RuntimeException)
1105cdf0e10cSrcweir 	{
1106cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1107cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1108cdf0e10cSrcweir 		EnsureIsAlive();
1109cdf0e10cSrcweir 		return OCommonAccessibleText::getSelectionStart(  );
1110cdf0e10cSrcweir 	}
1111cdf0e10cSrcweir 	sal_Int32 SAL_CALL AccessibleListBoxEntry::getSelectionEnd(  ) throw (::com::sun::star::uno::RuntimeException)
1112cdf0e10cSrcweir 	{
1113cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1114cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1115cdf0e10cSrcweir 		EnsureIsAlive();
1116cdf0e10cSrcweir 		return OCommonAccessibleText::getSelectionEnd(  );
1117cdf0e10cSrcweir 	}
1118cdf0e10cSrcweir 	sal_Bool SAL_CALL AccessibleListBoxEntry::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
1119cdf0e10cSrcweir 	{
1120cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1121cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1122cdf0e10cSrcweir 		EnsureIsAlive();
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir 		if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
1125cdf0e10cSrcweir 			throw IndexOutOfBoundsException();
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir 		return sal_False;
1128cdf0e10cSrcweir 	}
1129cdf0e10cSrcweir 	::rtl::OUString SAL_CALL AccessibleListBoxEntry::getText(  ) throw (::com::sun::star::uno::RuntimeException)
1130cdf0e10cSrcweir 	{
1131cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1132cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1133cdf0e10cSrcweir 		EnsureIsAlive();
1134cdf0e10cSrcweir 		return OCommonAccessibleText::getText(  );
1135cdf0e10cSrcweir 	}
1136cdf0e10cSrcweir 	::rtl::OUString SAL_CALL AccessibleListBoxEntry::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
1137cdf0e10cSrcweir 	{
1138cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1139cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1140cdf0e10cSrcweir 		EnsureIsAlive();
1141cdf0e10cSrcweir 		return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
1142cdf0e10cSrcweir 	}
1143cdf0e10cSrcweir     ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1144cdf0e10cSrcweir 	{
1145cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1146cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1147cdf0e10cSrcweir 		EnsureIsAlive();
1148cdf0e10cSrcweir 		return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
1149cdf0e10cSrcweir 	}
1150cdf0e10cSrcweir     ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1151cdf0e10cSrcweir 	{
1152cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1153cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1154cdf0e10cSrcweir 		EnsureIsAlive();
1155cdf0e10cSrcweir 		return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
1156cdf0e10cSrcweir 	}
1157cdf0e10cSrcweir     ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleListBoxEntry::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
1158cdf0e10cSrcweir 	{
1159cdf0e10cSrcweir 		ALBSolarGuard aSolarGuard;
1160cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
1161cdf0e10cSrcweir 		EnsureIsAlive();
1162cdf0e10cSrcweir 
1163cdf0e10cSrcweir 		return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
1164cdf0e10cSrcweir 	}
1165*21075d77SSteve Yin 	// -----------------------------------------------------------------------------
1166*21075d77SSteve Yin 	// XAccessibleValue
1167*21075d77SSteve Yin 	// -----------------------------------------------------------------------------
1168*21075d77SSteve Yin 
1169*21075d77SSteve Yin 	Any AccessibleListBoxEntry::getCurrentValue(  ) throw (RuntimeException)
1170*21075d77SSteve Yin 	{
1171*21075d77SSteve Yin 		::osl::MutexGuard aGuard( m_aMutex );
1172*21075d77SSteve Yin 		Any aValue;
1173*21075d77SSteve Yin 		sal_Int32 level = ((sal_Int32) m_aEntryPath.size() - 1);
1174*21075d77SSteve Yin 		level = level < 0 ?  0: level;
1175*21075d77SSteve Yin 		aValue <<= level;
1176*21075d77SSteve Yin 		return aValue;
1177*21075d77SSteve Yin 	}
1178*21075d77SSteve Yin 
1179*21075d77SSteve Yin 	// -----------------------------------------------------------------------------
1180*21075d77SSteve Yin 
1181*21075d77SSteve Yin 	sal_Bool AccessibleListBoxEntry::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
1182*21075d77SSteve Yin 	{
1183*21075d77SSteve Yin 		::osl::MutexGuard aGuard( m_aMutex );
1184*21075d77SSteve Yin 
1185*21075d77SSteve Yin 
1186*21075d77SSteve Yin 		sal_Bool bReturn = sal_False;
1187*21075d77SSteve Yin 		SvTreeListBox* pBox = getListBox();
1188*21075d77SSteve Yin 		if(getAccessibleRole() == AccessibleRole::CHECK_BOX)
1189*21075d77SSteve Yin 		{
1190*21075d77SSteve Yin 			SvLBoxEntry* pEntry = pBox->GetEntryFromPath( m_aEntryPath );
1191*21075d77SSteve Yin 			if ( pEntry )
1192*21075d77SSteve Yin 			{
1193*21075d77SSteve Yin 				sal_Int32 nValue, nValueMin, nValueMax;
1194*21075d77SSteve Yin 				aNumber >>= nValue;
1195*21075d77SSteve Yin 				getMinimumValue() >>= nValueMin;
1196*21075d77SSteve Yin 				getMaximumValue() >>= nValueMax;
1197*21075d77SSteve Yin 
1198*21075d77SSteve Yin 				if ( nValue < nValueMin )
1199*21075d77SSteve Yin 					nValue = nValueMin;
1200*21075d77SSteve Yin 				else if ( nValue > nValueMax )
1201*21075d77SSteve Yin 					nValue = nValueMax;
1202*21075d77SSteve Yin 
1203*21075d77SSteve Yin 				pBox->SetCheckButtonState(pEntry,  (SvButtonState) nValue );
1204*21075d77SSteve Yin 				bReturn = sal_True;
1205*21075d77SSteve Yin 			}
1206*21075d77SSteve Yin 		}
1207*21075d77SSteve Yin 
1208*21075d77SSteve Yin 		return bReturn;
1209*21075d77SSteve Yin 	}
1210*21075d77SSteve Yin 
1211*21075d77SSteve Yin 	// -----------------------------------------------------------------------------
1212*21075d77SSteve Yin 
1213*21075d77SSteve Yin 	Any AccessibleListBoxEntry::getMaximumValue(  ) throw (RuntimeException)
1214*21075d77SSteve Yin 	{
1215*21075d77SSteve Yin 		::osl::MutexGuard aGuard( m_aMutex );
1216*21075d77SSteve Yin 
1217*21075d77SSteve Yin 		Any aValue;
1218*21075d77SSteve Yin 		// SvTreeListBox* pBox = getListBox();
1219*21075d77SSteve Yin 		switch(getAccessibleRole())
1220*21075d77SSteve Yin 		{
1221*21075d77SSteve Yin 			case AccessibleRole::CHECK_BOX:
1222*21075d77SSteve Yin 				aValue <<= (sal_Int32)1;
1223*21075d77SSteve Yin 				break;
1224*21075d77SSteve Yin 			case AccessibleRole::LABEL:
1225*21075d77SSteve Yin 			default:
1226*21075d77SSteve Yin 				break;
1227*21075d77SSteve Yin 		}
1228*21075d77SSteve Yin 
1229*21075d77SSteve Yin 		return aValue;
1230*21075d77SSteve Yin 	}
1231*21075d77SSteve Yin 
1232*21075d77SSteve Yin 	// -----------------------------------------------------------------------------
1233*21075d77SSteve Yin 
1234*21075d77SSteve Yin 	Any AccessibleListBoxEntry::getMinimumValue(  ) throw (RuntimeException)
1235*21075d77SSteve Yin 	{
1236*21075d77SSteve Yin 		::osl::MutexGuard aGuard( m_aMutex );
1237*21075d77SSteve Yin 
1238*21075d77SSteve Yin 		Any aValue;
1239*21075d77SSteve Yin 		// SvTreeListBox* pBox = getListBox();
1240*21075d77SSteve Yin 		switch(getAccessibleRole())
1241*21075d77SSteve Yin 		{
1242*21075d77SSteve Yin 			case AccessibleRole::CHECK_BOX:
1243*21075d77SSteve Yin 				aValue <<= (sal_Int32)0;
1244*21075d77SSteve Yin 				break;
1245*21075d77SSteve Yin 			case AccessibleRole::LABEL:
1246*21075d77SSteve Yin 			default:
1247*21075d77SSteve Yin 				break;
1248*21075d77SSteve Yin 		}
1249*21075d77SSteve Yin 
1250*21075d77SSteve Yin 		return aValue;
1251*21075d77SSteve Yin 	}
1252*21075d77SSteve Yin 
1253*21075d77SSteve Yin 	// -----------------------------------------------------------------------------
1254*21075d77SSteve Yin 
1255*21075d77SSteve Yin 	SvLBoxEntry * AccessibleListBoxEntry::GetRealChild(sal_Int32 nIndex)
1256*21075d77SSteve Yin 	{
1257*21075d77SSteve Yin 		SvLBoxEntry* pEntry =NULL;
1258*21075d77SSteve Yin 		SvLBoxEntry* pParent = getListBox()->GetEntryFromPath( m_aEntryPath );
1259*21075d77SSteve Yin 		if (pParent)
1260*21075d77SSteve Yin 		{
1261*21075d77SSteve Yin 			pEntry = getListBox()->GetEntry( pParent, nIndex );
1262*21075d77SSteve Yin 			if ( !pEntry && getAccessibleChildCount() > 0 )
1263*21075d77SSteve Yin 			{
1264*21075d77SSteve Yin 				getListBox()->RequestingChilds(pParent);
1265*21075d77SSteve Yin 				pEntry = getListBox()->GetEntry( pParent, nIndex );
1266*21075d77SSteve Yin 			}
1267*21075d77SSteve Yin 		}
1268*21075d77SSteve Yin 		return pEntry;
1269*21075d77SSteve Yin 	}
1270cdf0e10cSrcweir //........................................................................
1271cdf0e10cSrcweir }// namespace accessibility
1272cdf0e10cSrcweir //........................................................................
1273cdf0e10cSrcweir 
1274