1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <svx/AccessibleControlShape.hxx>
27cdf0e10cSrcweir #include <svx/AccessibleShapeInfo.hxx>
28cdf0e10cSrcweir #include "svx/DescriptionGenerator.hxx"
29cdf0e10cSrcweir #include <com/sun/star/drawing/XControlShape.hpp>
30cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp>
33cdf0e10cSrcweir #include <com/sun/star/reflection/XProxyFactory.hpp>
34cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp>
35cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
36cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
37cdf0e10cSrcweir #include <svx/svdouno.hxx>
38cdf0e10cSrcweir #include "svx/unoapi.hxx"
39cdf0e10cSrcweir #include <svx/ShapeTypeHandler.hxx>
40cdf0e10cSrcweir #include <svx/SvxShapeTypes.hxx>
41cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
42cdf0e10cSrcweir #include <comphelper/accessiblewrapper.hxx>
43cdf0e10cSrcweir #include <svx/svdview.hxx>
44cdf0e10cSrcweir #include <svx/svdpagv.hxx>
45cdf0e10cSrcweir #include "svx/svdstr.hrc"
46cdf0e10cSrcweir #include <algorithm>
47*9b8096d0SSteve Yin #ifndef _COMPHELPER_PROPERTY_HXX_
48*9b8096d0SSteve Yin #include <comphelper/property.hxx>
49*9b8096d0SSteve Yin #endif
50*9b8096d0SSteve Yin #ifndef _COMPHELPER_TYPES_HXX_
51*9b8096d0SSteve Yin #include <comphelper/types.hxx>
52*9b8096d0SSteve Yin #endif
53*9b8096d0SSteve Yin #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
54*9b8096d0SSteve Yin #include <com/sun/star/container/XChild.hpp>
55*9b8096d0SSteve Yin #endif
56*9b8096d0SSteve Yin #ifndef _UTL_ACCESSIBLERELATIONSETHELPER_HXX_
57*9b8096d0SSteve Yin #include <unotools/accessiblerelationsethelper.hxx>
58*9b8096d0SSteve Yin #endif
59*9b8096d0SSteve Yin #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLERELATIONTYPE_HPP_
60*9b8096d0SSteve Yin #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
61*9b8096d0SSteve Yin #endif
62cdf0e10cSrcweir using namespace ::comphelper;
63cdf0e10cSrcweir using namespace ::accessibility;
64cdf0e10cSrcweir using namespace	::com::sun::star::accessibility;
65cdf0e10cSrcweir using namespace	::com::sun::star::uno;
66cdf0e10cSrcweir using namespace	::com::sun::star::awt;
67cdf0e10cSrcweir using namespace	::com::sun::star::beans;
68cdf0e10cSrcweir using namespace	::com::sun::star::util;
69cdf0e10cSrcweir using namespace	::com::sun::star::lang;
70cdf0e10cSrcweir using namespace	::com::sun::star::reflection;
71cdf0e10cSrcweir using namespace	::com::sun::star::drawing;
72cdf0e10cSrcweir using namespace	::com::sun::star::container;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir //--------------------------------------------------------------------
75cdf0e10cSrcweir namespace
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	//................................................................
lcl_getNamePropertyName()78cdf0e10cSrcweir 	const ::rtl::OUString& lcl_getNamePropertyName( )
79cdf0e10cSrcweir 	{
80cdf0e10cSrcweir 		static ::rtl::OUString s_sNamePropertyName( RTL_CONSTASCII_USTRINGPARAM( "Name" ) );
81cdf0e10cSrcweir 		return s_sNamePropertyName;
82cdf0e10cSrcweir 	}
83cdf0e10cSrcweir 	//................................................................
lcl_getDescPropertyName()84cdf0e10cSrcweir 	const ::rtl::OUString& lcl_getDescPropertyName( )
85cdf0e10cSrcweir 	{
86cdf0e10cSrcweir 		static ::rtl::OUString s_sDescPropertyDesc( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) );
87cdf0e10cSrcweir 		return s_sDescPropertyDesc;
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 	//................................................................
lcl_getLabelPropertyName()90cdf0e10cSrcweir 	const ::rtl::OUString& lcl_getLabelPropertyName( )
91cdf0e10cSrcweir 	{
92cdf0e10cSrcweir 		static ::rtl::OUString s_sLabelPropertyLabel( RTL_CONSTASCII_USTRINGPARAM( "Label" ) );
93cdf0e10cSrcweir 		return s_sLabelPropertyLabel;
94cdf0e10cSrcweir 	}
95*9b8096d0SSteve Yin 	//................................................................
lcl_getLabelControlPropertyName()96*9b8096d0SSteve Yin 	const ::rtl::OUString& lcl_getLabelControlPropertyName( )
97*9b8096d0SSteve Yin 	{
98*9b8096d0SSteve Yin 		static ::rtl::OUString s_sLabelControlPropertyLabel( RTL_CONSTASCII_USTRINGPARAM( "LabelControl" ) );
99*9b8096d0SSteve Yin 		return s_sLabelControlPropertyLabel;
100*9b8096d0SSteve Yin 	}
101cdf0e10cSrcweir 	//................................................................
102cdf0e10cSrcweir 	// return the property which should be used as AccessibleName
lcl_getPreferredAccNameProperty(const Reference<XPropertySetInfo> & _rxPSI)103cdf0e10cSrcweir 	const ::rtl::OUString& lcl_getPreferredAccNameProperty( const Reference< XPropertySetInfo >& _rxPSI )
104cdf0e10cSrcweir 	{
105cdf0e10cSrcweir 		if ( _rxPSI.is() && _rxPSI->hasPropertyByName( lcl_getLabelPropertyName() ) )
106cdf0e10cSrcweir 			return lcl_getLabelPropertyName();
107cdf0e10cSrcweir 		else
108cdf0e10cSrcweir 			return lcl_getNamePropertyName();
109cdf0e10cSrcweir 	}
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	//................................................................
112cdf0e10cSrcweir 	// determines whether or not a state which belongs to the inner context needs to be forwarded to the "composed"
113cdf0e10cSrcweir 	// context
isComposedState(const sal_Int16 _nState)114cdf0e10cSrcweir 	sal_Bool	isComposedState( const sal_Int16 _nState )
115cdf0e10cSrcweir 	{
116cdf0e10cSrcweir 		return	(	( AccessibleStateType::INVALID != _nState )
117cdf0e10cSrcweir 				&&	( AccessibleStateType::DEFUNC != _nState )
118cdf0e10cSrcweir 				&&	( AccessibleStateType::ICONIFIED != _nState )
119cdf0e10cSrcweir 				&&	( AccessibleStateType::RESIZABLE != _nState )
120cdf0e10cSrcweir 				&&	( AccessibleStateType::SELECTABLE != _nState )
121cdf0e10cSrcweir 				&&	( AccessibleStateType::SHOWING != _nState )
122cdf0e10cSrcweir 				&&	( AccessibleStateType::MANAGES_DESCENDANTS != _nState )
123cdf0e10cSrcweir 				&&	( AccessibleStateType::VISIBLE != _nState )
124cdf0e10cSrcweir 				);
125cdf0e10cSrcweir 	}
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	//................................................................
128cdf0e10cSrcweir 	/** determines whether the given control is in alive mode
129cdf0e10cSrcweir 	*/
isAliveMode(const Reference<XControl> & _rxControl)130cdf0e10cSrcweir 	inline	sal_Bool	isAliveMode( const Reference< XControl >& _rxControl )
131cdf0e10cSrcweir 	{
132cdf0e10cSrcweir 		OSL_PRECOND( _rxControl.is(), "AccessibleControlShape::isAliveMode: invalid control" );
133cdf0e10cSrcweir 		return _rxControl.is() && !_rxControl->isDesignMode();
134cdf0e10cSrcweir 	}
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir //=============================================================================
138cdf0e10cSrcweir //= AccessibleControlShape
139cdf0e10cSrcweir //=============================================================================
140cdf0e10cSrcweir 
141cdf0e10cSrcweir //-----------------------------------------------------------------------------
AccessibleControlShape(const AccessibleShapeInfo & rShapeInfo,const AccessibleShapeTreeInfo & rShapeTreeInfo)142cdf0e10cSrcweir AccessibleControlShape::AccessibleControlShape (
143cdf0e10cSrcweir     const AccessibleShapeInfo& rShapeInfo,
144cdf0e10cSrcweir     const AccessibleShapeTreeInfo& rShapeTreeInfo)
145cdf0e10cSrcweir     :      AccessibleShape (rShapeInfo, rShapeTreeInfo)
146cdf0e10cSrcweir 	,	m_bListeningForName( sal_False )
147cdf0e10cSrcweir 	,	m_bListeningForDesc( sal_False )
148cdf0e10cSrcweir 	,	m_bMultiplexingStates( sal_False )
149cdf0e10cSrcweir     ,   m_bDisposeNativeContext( sal_False )
150cdf0e10cSrcweir     ,   m_bWaitingForControl( sal_False )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	m_pChildManager = new OWrappedAccessibleChildrenManager( getProcessServiceFactory() );
153cdf0e10cSrcweir 	m_pChildManager->acquire();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	osl_incrementInterlockedCount( &m_refCount );
156cdf0e10cSrcweir 	{
157cdf0e10cSrcweir 		m_pChildManager->setOwningAccessible( this );
158cdf0e10cSrcweir 	}
159cdf0e10cSrcweir 	osl_decrementInterlockedCount( &m_refCount );
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //-----------------------------------------------------------------------------
~AccessibleControlShape(void)163cdf0e10cSrcweir AccessibleControlShape::~AccessibleControlShape (void)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir 	m_pChildManager->release();
166cdf0e10cSrcweir 	m_pChildManager = NULL;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	if ( m_xControlContextProxy.is() )
169cdf0e10cSrcweir 		m_xControlContextProxy->setDelegator( NULL );
170cdf0e10cSrcweir 	m_xControlContextProxy.clear();
171cdf0e10cSrcweir     m_xControlContextTypeAccess.clear();
172cdf0e10cSrcweir     m_xControlContextComponent.clear();
173cdf0e10cSrcweir 		// this should remove the _only_ three "real" reference (means not delegated to
174cdf0e10cSrcweir 		// ourself) to this proxy, and thus delete it
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir //-----------------------------------------------------------------------------
getSdrObject() const178cdf0e10cSrcweir SdrObject* AccessibleControlShape::getSdrObject() const
179cdf0e10cSrcweir {
180cdf0e10cSrcweir     return GetSdrObjectFromXShape (mxShape);
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir namespace {
lcl_getControlContainer(const Window * _pWin,const SdrView * _pView)184cdf0e10cSrcweir     Reference< XContainer > lcl_getControlContainer( const Window* _pWin, const SdrView* _pView )
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         Reference< XContainer > xReturn;
187cdf0e10cSrcweir         DBG_ASSERT( _pView, "lcl_getControlContainer: invalid view!" );
188cdf0e10cSrcweir         if ( _pView  && _pView->GetSdrPageView())
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir 			xReturn = xReturn.query( _pView->GetSdrPageView()->GetControlContainer( *_pWin ) );
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir         return xReturn;
193cdf0e10cSrcweir     }
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir //-----------------------------------------------------------------------------
Init()197cdf0e10cSrcweir void AccessibleControlShape::Init()
198cdf0e10cSrcweir {
199cdf0e10cSrcweir 	AccessibleShape::Init();
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	OSL_ENSURE( !m_xControlContextProxy.is(), "AccessibleControlShape::Init: already initialized!" );
202cdf0e10cSrcweir 	try
203cdf0e10cSrcweir 	{
204cdf0e10cSrcweir 		// What we need to do here is merge the functionality of the AccessibleContext of our UNO control
205cdf0e10cSrcweir 		// with our own AccessibleContext-related functionality.
206cdf0e10cSrcweir 		//
207cdf0e10cSrcweir 		// The problem is that we do not know the interfaces our "inner" context supports - this may be any
208cdf0e10cSrcweir 		// XAccessibleXXX interface (or even any other) which makes sense for it.
209cdf0e10cSrcweir 		//
210cdf0e10cSrcweir 		// In theory, we could implement all possible interfaces ourself, and re-route all functionality to
211cdf0e10cSrcweir 		// the inner context (except those we implement ourself, like XAccessibleComponent). But this is in no
212cdf0e10cSrcweir 		// way future-proof - as soon as an inner context appears which implements an additional interface,
213cdf0e10cSrcweir 		// we would need to adjust our implementation to support this new interface, too. Bad idea.
214cdf0e10cSrcweir 		//
215cdf0e10cSrcweir 		// The usual solution for such a problem is aggregation. Aggregation means using UNO's own meachnisms
216cdf0e10cSrcweir 		// for merging an inner with an outer component, and get a component which behaves as it is exactly one.
217cdf0e10cSrcweir 		// This is what XAggregation is for. Unfortunately, aggregation requires _exact_ control over the ref count
218cdf0e10cSrcweir 		// of the inner object, which we do not have at all.
219cdf0e10cSrcweir 		// Bad, too.
220cdf0e10cSrcweir 		//
221cdf0e10cSrcweir 		// But there is a solution: com.sun.star.reflection.ProxyFactory. This service is able to create a proxy
222cdf0e10cSrcweir 		// for any component, which supports _exactly_ the same interfaces as the component. In addition, it can
223cdf0e10cSrcweir 		// be aggregated, as by definition the proxy's ref count is exactly 1 when returned from the factory.
224cdf0e10cSrcweir 		// Sounds better. Though this yields the problem of slightly degraded performance, it's the only solution
225cdf0e10cSrcweir 		// I'm aware of at the moment .....
226cdf0e10cSrcweir 		//
227cdf0e10cSrcweir 		// 98750 - 30.04.2002 - fs@openoffice.org
228cdf0e10cSrcweir 		//
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 		// get the control which belongs to our model (relative to our view)
231cdf0e10cSrcweir 		const Window* pViewWindow = maShapeTreeInfo.GetWindow();
232cdf0e10cSrcweir 		SdrUnoObj* pUnoObjectImpl = PTR_CAST( SdrUnoObj, getSdrObject() );
233cdf0e10cSrcweir         SdrView* pView = maShapeTreeInfo.GetSdrView();
234cdf0e10cSrcweir 		OSL_ENSURE( pView && pViewWindow && pUnoObjectImpl, "AccessibleControlShape::Init: no view, or no view window, no SdrUnoObj!" );
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 		if ( pView && pViewWindow && pUnoObjectImpl )
237cdf0e10cSrcweir 		{
238cdf0e10cSrcweir 			// .................................................................
239cdf0e10cSrcweir 			// get the context of the control - it will be our "inner" context
240cdf0e10cSrcweir 			m_xUnoControl = pUnoObjectImpl->GetUnoControl( *pView, *pViewWindow );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir             if ( !m_xUnoControl.is() )
243cdf0e10cSrcweir             {
244cdf0e10cSrcweir                 // the control has not yet been created. Though speaking strictly, it is a bug that
245cdf0e10cSrcweir                 // our instance here is created without an existing control (because an AccessibleControlShape
246cdf0e10cSrcweir                 // is a representation of a view object, and can only live if the view it should represent
247cdf0e10cSrcweir                 // is complete, which implies a living control), it's by far the easiest and most riskless way
248cdf0e10cSrcweir                 // to fix this here in this class.
249cdf0e10cSrcweir                 // Okay, we will add as listener to the control container where we expect our control to appear.
250cdf0e10cSrcweir                 OSL_ENSURE( !m_bWaitingForControl, "AccessibleControlShape::Init: already waiting for the control!" );
251cdf0e10cSrcweir 
252cdf0e10cSrcweir                 Reference< XContainer > xControlContainer = lcl_getControlContainer( pViewWindow, maShapeTreeInfo.GetSdrView() );
253cdf0e10cSrcweir                 OSL_ENSURE( xControlContainer.is(), "AccessibleControlShape::Init: unable to find my ControlContainer!" );
254cdf0e10cSrcweir                 if ( xControlContainer.is() )
255cdf0e10cSrcweir                 {
256cdf0e10cSrcweir                     xControlContainer->addContainerListener( this );
257cdf0e10cSrcweir                     m_bWaitingForControl = sal_True;
258cdf0e10cSrcweir                 }
259cdf0e10cSrcweir             }
260cdf0e10cSrcweir             else
261cdf0e10cSrcweir             {
262cdf0e10cSrcweir 			    Reference< XModeChangeBroadcaster > xControlModes( m_xUnoControl, UNO_QUERY );
263cdf0e10cSrcweir 			    Reference< XAccessible > xControlAccessible( xControlModes, UNO_QUERY );
264cdf0e10cSrcweir 			    Reference< XAccessibleContext > xNativeControlContext;
265cdf0e10cSrcweir 			    if ( xControlAccessible.is() )
266cdf0e10cSrcweir 				    xNativeControlContext = xControlAccessible->getAccessibleContext();
267cdf0e10cSrcweir 			    OSL_ENSURE( xNativeControlContext.is(), "AccessibleControlShape::Init: no AccessibleContext for the control!" );
268cdf0e10cSrcweir 			    m_aControlContext = WeakReference< XAccessibleContext >( xNativeControlContext );
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 			    // .................................................................
271cdf0e10cSrcweir 			    // add as listener to the context - we want to multiplex some states
272cdf0e10cSrcweir 			    if ( isAliveMode( m_xUnoControl ) && xNativeControlContext.is() )
273cdf0e10cSrcweir 			    {	// (but only in alive mode)
274cdf0e10cSrcweir 				    startStateMultiplexing( );
275cdf0e10cSrcweir 			    }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 			    // now that we have all information about our control, do some adjustments
278cdf0e10cSrcweir 			    adjustAccessibleRole();
279cdf0e10cSrcweir 			    initializeComposedState();
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 			    // some initialization for our child manager, which is used in alive mode only
282cdf0e10cSrcweir 			    if ( isAliveMode( m_xUnoControl ) )
283cdf0e10cSrcweir 			    {
284cdf0e10cSrcweir 				    Reference< XAccessibleStateSet > xStates( getAccessibleStateSet( ) );
285cdf0e10cSrcweir 				    OSL_ENSURE( xStates.is(), "AccessibleControlShape::AccessibleControlShape: no inner state set!" );
286cdf0e10cSrcweir 				    m_pChildManager->setTransientChildren( !xStates.is() || xStates->contains( AccessibleStateType::MANAGES_DESCENDANTS ) );
287cdf0e10cSrcweir 			    }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 			    // .................................................................
290cdf0e10cSrcweir 			    // finally, aggregate a proxy for the control context
291cdf0e10cSrcweir 			    // first a factory for the proxy
292cdf0e10cSrcweir 			    Reference< XProxyFactory > xFactory;
293cdf0e10cSrcweir 			    xFactory = xFactory.query( createProcessComponent( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.reflection.ProxyFactory" ) ) ) );
294cdf0e10cSrcweir 			    OSL_ENSURE( xFactory.is(), "AccessibleControlShape::Init: could not create a proxy factory!" );
295cdf0e10cSrcweir 			    // then the proxy itself
296cdf0e10cSrcweir 			    if ( xFactory.is() && xNativeControlContext.is() )
297cdf0e10cSrcweir 			    {
298cdf0e10cSrcweir 				    m_xControlContextProxy = xFactory->createProxy( xNativeControlContext );
299cdf0e10cSrcweir                     OSL_VERIFY( xNativeControlContext->queryInterface( ::getCppuType( &m_xControlContextTypeAccess ) ) >>= m_xControlContextTypeAccess );
300cdf0e10cSrcweir                     OSL_VERIFY( xNativeControlContext->queryInterface( ::getCppuType( &m_xControlContextComponent ) ) >>= m_xControlContextComponent );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 				    // aggregate the proxy
303cdf0e10cSrcweir 				    osl_incrementInterlockedCount( &m_refCount );
304cdf0e10cSrcweir 				    if ( m_xControlContextProxy.is() )
305cdf0e10cSrcweir 				    {
306cdf0e10cSrcweir 					    // At this point in time, the proxy has a ref count of exactly one - in m_xControlContextProxy.
307cdf0e10cSrcweir 					    // Remember to _not_ reset this member unles the delegator of the proxy has been reset, too!
308cdf0e10cSrcweir 					    m_xControlContextProxy->setDelegator( *this );
309cdf0e10cSrcweir 				    }
310cdf0e10cSrcweir 				    osl_decrementInterlockedCount( &m_refCount );
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 				    m_bDisposeNativeContext = sal_True;
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 				    // Finally, we need to add ourself as mode listener to the control. In case the mode switches,
315cdf0e10cSrcweir 				    // we need to dispose ourself.
316cdf0e10cSrcweir 				    xControlModes->addModeChangeListener( this );
317cdf0e10cSrcweir 			    }
318cdf0e10cSrcweir             }
319cdf0e10cSrcweir 		}
320cdf0e10cSrcweir 	}
321cdf0e10cSrcweir 	catch( const Exception& )
322cdf0e10cSrcweir 	{
323cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "AccessibleControlShape::Init: could not \"aggregate\" the controls XAccessibleContext!" );
324cdf0e10cSrcweir 	}
325cdf0e10cSrcweir }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir //-----------------------------------------------------------------------------
getAccessibleContext(void)328cdf0e10cSrcweir Reference< XAccessibleContext > SAL_CALL AccessibleControlShape::getAccessibleContext(void) throw (RuntimeException)
329cdf0e10cSrcweir {
330cdf0e10cSrcweir 	return AccessibleShape::getAccessibleContext ();
331cdf0e10cSrcweir }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 
334cdf0e10cSrcweir //-----------------------------------------------------------------------------
grabFocus(void)335cdf0e10cSrcweir void SAL_CALL AccessibleControlShape::grabFocus(void)  throw (RuntimeException)
336cdf0e10cSrcweir {
337cdf0e10cSrcweir 	if ( !m_xUnoControl.is() || !isAliveMode( m_xUnoControl ) )
338cdf0e10cSrcweir 	{
339cdf0e10cSrcweir 		// in design mode, we simply forward the request to the base class
340cdf0e10cSrcweir 		AccessibleShape::grabFocus();
341cdf0e10cSrcweir 	}
342cdf0e10cSrcweir 	else
343cdf0e10cSrcweir 	{
344cdf0e10cSrcweir 		Reference< XWindow > xWindow( m_xUnoControl, UNO_QUERY );
345cdf0e10cSrcweir 		OSL_ENSURE( xWindow.is(), "AccessibleControlShape::grabFocus: invalid control!" );
346cdf0e10cSrcweir 		if ( xWindow.is() )
347cdf0e10cSrcweir 			xWindow->setFocus();
348cdf0e10cSrcweir 	}
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir //-----------------------------------------------------------------------------
getImplementationName(void)352cdf0e10cSrcweir ::rtl::OUString SAL_CALL AccessibleControlShape::getImplementationName(void) throw (RuntimeException)
353cdf0e10cSrcweir {
354cdf0e10cSrcweir 	return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.accessibility.AccessibleControlShape" ) );
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir //-----------------------------------------------------------------------------
CreateAccessibleBaseName(void)358cdf0e10cSrcweir ::rtl::OUString AccessibleControlShape::CreateAccessibleBaseName(void) throw (RuntimeException)
359cdf0e10cSrcweir {
360cdf0e10cSrcweir     ::rtl::OUString sName;
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     ShapeTypeId nShapeType = ShapeTypeHandler::Instance().GetTypeId (mxShape);
363cdf0e10cSrcweir     switch (nShapeType)
364cdf0e10cSrcweir     {
365cdf0e10cSrcweir         case DRAWING_CONTROL:
366cdf0e10cSrcweir             sName = ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("ControlShape"));
367cdf0e10cSrcweir             break;
368cdf0e10cSrcweir         default:
369cdf0e10cSrcweir             sName = ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("UnknownAccessibleControlShape"));
370cdf0e10cSrcweir             Reference< XShapeDescriptor > xDescriptor (mxShape, UNO_QUERY);
371cdf0e10cSrcweir             if (xDescriptor.is())
372cdf0e10cSrcweir                 sName += ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM(": "))
373cdf0e10cSrcweir                     + xDescriptor->getShapeType();
374cdf0e10cSrcweir     }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir     return sName;
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 
381cdf0e10cSrcweir 
382cdf0e10cSrcweir //--------------------------------------------------------------------
383cdf0e10cSrcweir ::rtl::OUString
CreateAccessibleDescription(void)384cdf0e10cSrcweir     AccessibleControlShape::CreateAccessibleDescription (void)
385cdf0e10cSrcweir     throw (RuntimeException)
386cdf0e10cSrcweir {
387cdf0e10cSrcweir     DescriptionGenerator aDG (mxShape);
388cdf0e10cSrcweir     ShapeTypeId nShapeType = ShapeTypeHandler::Instance().GetTypeId (mxShape);
389cdf0e10cSrcweir     switch (nShapeType)
390cdf0e10cSrcweir     {
391cdf0e10cSrcweir         case DRAWING_CONTROL:
392cdf0e10cSrcweir 		{
393cdf0e10cSrcweir 			// check if we can obtain the "Desc" property from the model
394cdf0e10cSrcweir 			::rtl::OUString sDesc( getControlModelStringProperty( lcl_getDescPropertyName() ) );
395cdf0e10cSrcweir 			if ( !sDesc.getLength() )
396cdf0e10cSrcweir 			{	// no -> use the default
397cdf0e10cSrcweir 				aDG.Initialize (STR_ObjNameSingulUno);
398cdf0e10cSrcweir 				aDG.AddProperty (::rtl::OUString::createFromAscii ("ControlBackground"),
399cdf0e10cSrcweir 					DescriptionGenerator::COLOR,
400cdf0e10cSrcweir 					::rtl::OUString());
401cdf0e10cSrcweir 				aDG.AddProperty (::rtl::OUString::createFromAscii ("ControlBorder"),
402cdf0e10cSrcweir 					DescriptionGenerator::INTEGER,
403cdf0e10cSrcweir 					::rtl::OUString());
404cdf0e10cSrcweir 			}
405cdf0e10cSrcweir 			// ensure that we are listening to the Name property
406cdf0e10cSrcweir 			m_bListeningForDesc = ensureListeningState( m_bListeningForDesc, sal_True, lcl_getDescPropertyName() );
407cdf0e10cSrcweir 		}
408cdf0e10cSrcweir 		break;
409cdf0e10cSrcweir 
410cdf0e10cSrcweir         default:
411cdf0e10cSrcweir             aDG.Initialize (::rtl::OUString::createFromAscii (
412cdf0e10cSrcweir                 "Unknown accessible control shape"));
413cdf0e10cSrcweir             Reference< XShapeDescriptor > xDescriptor (mxShape, UNO_QUERY);
414cdf0e10cSrcweir             if (xDescriptor.is())
415cdf0e10cSrcweir             {
416cdf0e10cSrcweir                 aDG.AppendString (::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("service name=")));
417cdf0e10cSrcweir                 aDG.AppendString (xDescriptor->getShapeType());
418cdf0e10cSrcweir             }
419cdf0e10cSrcweir     }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     return aDG();
422cdf0e10cSrcweir }
423cdf0e10cSrcweir 
424cdf0e10cSrcweir //--------------------------------------------------------------------
IMPLEMENT_FORWARD_REFCOUNT(AccessibleControlShape,AccessibleShape)425cdf0e10cSrcweir IMPLEMENT_FORWARD_REFCOUNT( AccessibleControlShape, AccessibleShape )
426cdf0e10cSrcweir IMPLEMENT_GET_IMPLEMENTATION_ID( AccessibleControlShape )
427cdf0e10cSrcweir 
428cdf0e10cSrcweir //--------------------------------------------------------------------
429cdf0e10cSrcweir void SAL_CALL AccessibleControlShape::propertyChange( const PropertyChangeEvent& _rEvent ) throw (RuntimeException)
430cdf0e10cSrcweir {
431cdf0e10cSrcweir 	::osl::MutexGuard aGuard( maMutex );
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 	// check if it is the name or the description
434cdf0e10cSrcweir 	if	(	_rEvent.PropertyName.equals( lcl_getNamePropertyName() )
435cdf0e10cSrcweir 		||	_rEvent.PropertyName.equals( lcl_getLabelPropertyName( ) )
436cdf0e10cSrcweir 		)
437cdf0e10cSrcweir 	{
438cdf0e10cSrcweir 		SetAccessibleName(
439cdf0e10cSrcweir             CreateAccessibleName(),
440cdf0e10cSrcweir             AccessibleContextBase::AutomaticallyCreated);
441cdf0e10cSrcweir 	}
442cdf0e10cSrcweir 	else if ( _rEvent.PropertyName.equals( lcl_getDescPropertyName() ) )
443cdf0e10cSrcweir 	{
444cdf0e10cSrcweir 		SetAccessibleDescription(
445cdf0e10cSrcweir             CreateAccessibleDescription(),
446cdf0e10cSrcweir             AccessibleContextBase::AutomaticallyCreated);
447cdf0e10cSrcweir 	}
448cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
449cdf0e10cSrcweir 	else
450cdf0e10cSrcweir 	{
451cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "AccessibleControlShape::propertyChange: where did this come from?" );
452cdf0e10cSrcweir 	}
453cdf0e10cSrcweir #endif
454cdf0e10cSrcweir }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir //--------------------------------------------------------------------
queryInterface(const Type & _rType)457cdf0e10cSrcweir Any SAL_CALL AccessibleControlShape::queryInterface( const Type& _rType ) throw (RuntimeException)
458cdf0e10cSrcweir {
459cdf0e10cSrcweir 	Any aReturn = AccessibleShape::queryInterface( _rType );
460cdf0e10cSrcweir 	if ( !aReturn.hasValue() )
461cdf0e10cSrcweir 	{
462cdf0e10cSrcweir 		aReturn = AccessibleControlShape_Base::queryInterface( _rType );
463cdf0e10cSrcweir 		if ( !aReturn.hasValue() && m_xControlContextProxy.is() )
464cdf0e10cSrcweir 			aReturn = m_xControlContextProxy->queryAggregation( _rType );
465cdf0e10cSrcweir 	}
466cdf0e10cSrcweir 	return aReturn;
467cdf0e10cSrcweir }
468cdf0e10cSrcweir 
469cdf0e10cSrcweir //--------------------------------------------------------------------
getTypes()470cdf0e10cSrcweir Sequence< Type > SAL_CALL AccessibleControlShape::getTypes() throw (RuntimeException)
471cdf0e10cSrcweir {
472cdf0e10cSrcweir 	Sequence< Type > aShapeTypes = AccessibleShape::getTypes();
473cdf0e10cSrcweir 	Sequence< Type > aOwnTypes = AccessibleControlShape_Base::getTypes();
474cdf0e10cSrcweir 
475cdf0e10cSrcweir 	Sequence< Type > aAggregateTypes;
476cdf0e10cSrcweir     if ( m_xControlContextTypeAccess.is() )
477cdf0e10cSrcweir 		aAggregateTypes = m_xControlContextTypeAccess->getTypes();
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 	Sequence< Type > aAllTypes = concatSequences( aShapeTypes, aOwnTypes, aAggregateTypes );
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 	// remove duplicates
482cdf0e10cSrcweir 	Type* pBegin = aAllTypes.getArray();
483cdf0e10cSrcweir 	Type* pEnd = pBegin + aAllTypes.getLength();
484cdf0e10cSrcweir 	while ( pBegin != pEnd )
485cdf0e10cSrcweir 	{
486cdf0e10cSrcweir 		Type aThisRoundType = *pBegin;
487cdf0e10cSrcweir 		if ( ++pBegin != pEnd )
488cdf0e10cSrcweir 		{
489cdf0e10cSrcweir 			pEnd = ::std::remove( pBegin, pEnd, aThisRoundType );
490cdf0e10cSrcweir 			// now all types between begin and (the old) end which equal aThisRoundType
491cdf0e10cSrcweir 			// are moved behind the new end
492cdf0e10cSrcweir 		}
493cdf0e10cSrcweir 	}
494cdf0e10cSrcweir 	aAllTypes.realloc( pEnd - aAllTypes.getArray() );
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 	return aAllTypes;
497cdf0e10cSrcweir }
498cdf0e10cSrcweir 
499cdf0e10cSrcweir //--------------------------------------------------------------------
notifyEvent(const AccessibleEventObject & _rEvent)500cdf0e10cSrcweir void SAL_CALL AccessibleControlShape::notifyEvent( const AccessibleEventObject& _rEvent ) throw (RuntimeException)
501cdf0e10cSrcweir {
502cdf0e10cSrcweir 	if ( AccessibleEventId::STATE_CHANGED == _rEvent.EventId )
503cdf0e10cSrcweir 	{
504cdf0e10cSrcweir 		// multiplex this change
505cdf0e10cSrcweir 		sal_Int16 nLostState( 0 ), nGainedState( 0 );
506cdf0e10cSrcweir 		_rEvent.OldValue >>= nLostState;
507cdf0e10cSrcweir 		_rEvent.NewValue >>= nGainedState;
508cdf0e10cSrcweir 
509cdf0e10cSrcweir 		// don't multiplex states which the inner context is not resposible for
510cdf0e10cSrcweir 		if	( isComposedState( nLostState ) )
511cdf0e10cSrcweir 			AccessibleShape::ResetState( nLostState );
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 		if	( isComposedState( nGainedState ) )
514cdf0e10cSrcweir 			AccessibleShape::SetState( nGainedState );
515cdf0e10cSrcweir 	}
516cdf0e10cSrcweir 	else
517cdf0e10cSrcweir 	{
518cdf0e10cSrcweir 		AccessibleEventObject aTranslatedEvent( _rEvent );
519cdf0e10cSrcweir 
520cdf0e10cSrcweir 		{
521cdf0e10cSrcweir 			::osl::MutexGuard aGuard( maMutex );
522cdf0e10cSrcweir 
523cdf0e10cSrcweir             // let the child manager translate the event
524cdf0e10cSrcweir 			aTranslatedEvent.Source = *this;
525cdf0e10cSrcweir 			m_pChildManager->translateAccessibleEvent( _rEvent, aTranslatedEvent );
526cdf0e10cSrcweir 
527cdf0e10cSrcweir             // see if any of these notifications affect our child manager
528cdf0e10cSrcweir 			m_pChildManager->handleChildNotification( _rEvent );
529cdf0e10cSrcweir 		}
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 		FireEvent( aTranslatedEvent );
532cdf0e10cSrcweir 	}
533cdf0e10cSrcweir }
534cdf0e10cSrcweir 
535cdf0e10cSrcweir //--------------------------------------------------------------------
modeChanged(const ModeChangeEvent & _rSource)536cdf0e10cSrcweir void SAL_CALL AccessibleControlShape::modeChanged( const ModeChangeEvent& _rSource ) throw (RuntimeException)
537cdf0e10cSrcweir {
538cdf0e10cSrcweir 	// did it come from our inner context (the real one, not it's proxy!)?
539cdf0e10cSrcweir     OSL_TRACE ("AccessibleControlShape::modeChanged");
540cdf0e10cSrcweir 	Reference< XControl > xSource( _rSource.Source, UNO_QUERY );	// for faster compare
541cdf0e10cSrcweir 	if ( xSource.get() == m_xUnoControl.get() )
542cdf0e10cSrcweir 	{
543cdf0e10cSrcweir 		// If our "pseudo-aggregated" inner context does not live anymore,
544cdf0e10cSrcweir 		// we don't want to live, too.  This is accomplished by asking our
545cdf0e10cSrcweir 		// parent to replace this object with a new one.  Disposing this
546cdf0e10cSrcweir 		// object and sending notifications about the replacement are in
547cdf0e10cSrcweir 		// the responsibility of our parent.
548cdf0e10cSrcweir 		OSL_VERIFY( mpParent->ReplaceChild ( this, mxShape, mnIndex, maShapeTreeInfo ) );
549cdf0e10cSrcweir 	}
550cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
551cdf0e10cSrcweir 	else
552cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "AccessibleControlShape::modeChanged: where did this come from?" );
553cdf0e10cSrcweir #endif
554cdf0e10cSrcweir }
555cdf0e10cSrcweir 
556cdf0e10cSrcweir //--------------------------------------------------------------------
disposing(const EventObject & _rSource)557cdf0e10cSrcweir void SAL_CALL AccessibleControlShape::disposing (const EventObject& _rSource) throw (RuntimeException)
558cdf0e10cSrcweir {
559cdf0e10cSrcweir 	AccessibleShape::disposing( _rSource );
560cdf0e10cSrcweir }
561cdf0e10cSrcweir 
562cdf0e10cSrcweir //--------------------------------------------------------------------
ensureListeningState(const sal_Bool _bCurrentlyListening,const sal_Bool _bNeedNewListening,const::rtl::OUString & _rPropertyName)563cdf0e10cSrcweir sal_Bool AccessibleControlShape::ensureListeningState(
564cdf0e10cSrcweir 		const sal_Bool _bCurrentlyListening, const sal_Bool _bNeedNewListening,
565cdf0e10cSrcweir 		const ::rtl::OUString& _rPropertyName )
566cdf0e10cSrcweir {
567cdf0e10cSrcweir 	if ( ( _bCurrentlyListening == _bNeedNewListening ) || !ensureControlModelAccess() )
568cdf0e10cSrcweir 		//  nothing to do
569cdf0e10cSrcweir 		return _bCurrentlyListening;
570cdf0e10cSrcweir 
571cdf0e10cSrcweir 	try
572cdf0e10cSrcweir 	{
573cdf0e10cSrcweir 		if ( !m_xModelPropsMeta.is() || m_xModelPropsMeta->hasPropertyByName( _rPropertyName ) )
574cdf0e10cSrcweir 		{
575cdf0e10cSrcweir 			// add or revoke as listener
576cdf0e10cSrcweir 			if ( _bNeedNewListening )
577cdf0e10cSrcweir 				m_xControlModel->addPropertyChangeListener( _rPropertyName, static_cast< XPropertyChangeListener* >( this ) );
578cdf0e10cSrcweir 			else
579cdf0e10cSrcweir 				m_xControlModel->removePropertyChangeListener( _rPropertyName, static_cast< XPropertyChangeListener* >( this ) );
580cdf0e10cSrcweir 		}
581cdf0e10cSrcweir 		else
582cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "AccessibleControlShape::ensureListeningState: this property does not exist at this model!" );
583cdf0e10cSrcweir 	}
584cdf0e10cSrcweir 	catch( const Exception& e )
585cdf0e10cSrcweir 	{
586cdf0e10cSrcweir 		(void)e;    // make compiler happy
587cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "AccessibleControlShape::ensureListeningState: could not change the listening state!" );
588cdf0e10cSrcweir 	}
589cdf0e10cSrcweir 
590cdf0e10cSrcweir 	return _bNeedNewListening;
591cdf0e10cSrcweir }
592cdf0e10cSrcweir 
593cdf0e10cSrcweir //--------------------------------------------------------------------
getAccessibleChildCount()594cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleControlShape::getAccessibleChildCount( ) throw(RuntimeException)
595cdf0e10cSrcweir {
596cdf0e10cSrcweir     if ( !m_xUnoControl.is() )
597cdf0e10cSrcweir         return 0;
598cdf0e10cSrcweir     else if ( !isAliveMode( m_xUnoControl ) )
599cdf0e10cSrcweir 		// no special action required when in design mode
600cdf0e10cSrcweir 		return AccessibleShape::getAccessibleChildCount( );
601cdf0e10cSrcweir 	else
602cdf0e10cSrcweir 	{
603cdf0e10cSrcweir 		// in alive mode, we have the full control over our children - they are determined by the children
604cdf0e10cSrcweir 		// of the context of our UNO control
605cdf0e10cSrcweir 		Reference< XAccessibleContext > xControlContext( m_aControlContext );
606cdf0e10cSrcweir 		OSL_ENSURE( xControlContext.is(), "AccessibleControlShape::getAccessibleChildCount: control context already dead! How this!" );
607cdf0e10cSrcweir 		return xControlContext.is() ? xControlContext->getAccessibleChildCount() : 0;
608cdf0e10cSrcweir 	}
609cdf0e10cSrcweir }
610cdf0e10cSrcweir 
611cdf0e10cSrcweir //--------------------------------------------------------------------
getAccessibleChild(sal_Int32 i)612cdf0e10cSrcweir Reference< XAccessible > SAL_CALL AccessibleControlShape::getAccessibleChild( sal_Int32 i ) throw(IndexOutOfBoundsException, RuntimeException)
613cdf0e10cSrcweir {
614cdf0e10cSrcweir 	Reference< XAccessible > xChild;
615cdf0e10cSrcweir     if ( !m_xUnoControl.is() )
616cdf0e10cSrcweir     {
617cdf0e10cSrcweir         throw IndexOutOfBoundsException();
618cdf0e10cSrcweir     }
619cdf0e10cSrcweir 	if ( !isAliveMode( m_xUnoControl ) )
620cdf0e10cSrcweir 	{
621cdf0e10cSrcweir 		// no special action required when in design mode - let the base class handle this
622cdf0e10cSrcweir 		xChild = AccessibleShape::getAccessibleChild( i );
623cdf0e10cSrcweir 	}
624cdf0e10cSrcweir 	else
625cdf0e10cSrcweir 	{
626cdf0e10cSrcweir 		// in alive mode, we have the full control over our children - they are determined by the children
627cdf0e10cSrcweir 		// of the context of our UNO control
628cdf0e10cSrcweir 
629cdf0e10cSrcweir 		Reference< XAccessibleContext > xControlContext( m_aControlContext );
630cdf0e10cSrcweir 		OSL_ENSURE( xControlContext.is(), "AccessibleControlShape::getAccessibleChildCount: control context already dead! How this!" );
631cdf0e10cSrcweir 		if ( xControlContext.is() )
632cdf0e10cSrcweir 		{
633cdf0e10cSrcweir 			Reference< XAccessible > xInnerChild( xControlContext->getAccessibleChild( i ) );
634cdf0e10cSrcweir 			OSL_ENSURE( xInnerChild.is(), "AccessibleControlShape::getAccessibleChild: control context returned nonsense!" );
635cdf0e10cSrcweir 			if ( xInnerChild.is() )
636cdf0e10cSrcweir 			{
637cdf0e10cSrcweir 				// we need to wrap this inner child into an own implementation
638cdf0e10cSrcweir 				xChild = m_pChildManager->getAccessibleWrapperFor( xInnerChild );
639cdf0e10cSrcweir 			}
640cdf0e10cSrcweir 		}
641cdf0e10cSrcweir 	}
642cdf0e10cSrcweir 
643cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
644cdf0e10cSrcweir     sal_Int32 nChildIndex = -1;
645cdf0e10cSrcweir     Reference< XAccessibleContext > xContext;
646cdf0e10cSrcweir     if ( xChild.is() )
647cdf0e10cSrcweir         xContext = xChild->getAccessibleContext( );
648cdf0e10cSrcweir     if ( xContext.is() )
649cdf0e10cSrcweir         nChildIndex = xContext->getAccessibleIndexInParent( );
650cdf0e10cSrcweir     OSL_ENSURE( nChildIndex == i, "AccessibleControlShape::getAccessibleChild: index mismatch!" );
651cdf0e10cSrcweir #endif
652cdf0e10cSrcweir 	return xChild;
653cdf0e10cSrcweir }
654cdf0e10cSrcweir 
655cdf0e10cSrcweir //--------------------------------------------------------------------
getAccessibleRelationSet()656cdf0e10cSrcweir Reference< XAccessibleRelationSet > SAL_CALL AccessibleControlShape::getAccessibleRelationSet(  ) throw (RuntimeException)
657cdf0e10cSrcweir {
658cdf0e10cSrcweir 	// TODO
659*9b8096d0SSteve Yin 	// return AccessibleShape::getAccessibleRelationSet( );
660*9b8096d0SSteve Yin     utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
661*9b8096d0SSteve Yin 	ensureControlModelAccess();
662*9b8096d0SSteve Yin 	AccessibleControlShape* pCtlAccShape = GetLabeledByControlShape();
663*9b8096d0SSteve Yin 	if(pCtlAccShape)
664*9b8096d0SSteve Yin 	{
665*9b8096d0SSteve Yin 		Reference < XAccessible > xAcc (pCtlAccShape->getAccessibleContext(), UNO_QUERY);
666*9b8096d0SSteve Yin 
667*9b8096d0SSteve Yin 		::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > aSequence(1);
668*9b8096d0SSteve Yin 		aSequence[0] = xAcc;
669*9b8096d0SSteve Yin 		if( getAccessibleRole() == AccessibleRole::RADIO_BUTTON )
670*9b8096d0SSteve Yin 		{
671*9b8096d0SSteve Yin 			pRelationSetHelper->AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF, aSequence ) );
672*9b8096d0SSteve Yin 		}
673*9b8096d0SSteve Yin 		else
674*9b8096d0SSteve Yin 		{
675*9b8096d0SSteve Yin 			pRelationSetHelper->AddRelation( AccessibleRelation( AccessibleRelationType::LABELED_BY, aSequence ) );
676*9b8096d0SSteve Yin 		}
677*9b8096d0SSteve Yin 	}
678*9b8096d0SSteve Yin 	Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
679*9b8096d0SSteve Yin 	return xSet;
680cdf0e10cSrcweir }
681cdf0e10cSrcweir 
682cdf0e10cSrcweir //--------------------------------------------------------------------
CreateAccessibleName(void)683cdf0e10cSrcweir ::rtl::OUString AccessibleControlShape::CreateAccessibleName (void) throw (RuntimeException)
684cdf0e10cSrcweir {
685cdf0e10cSrcweir 	ensureControlModelAccess();
686*9b8096d0SSteve Yin 	::rtl::OUString sName;
687*9b8096d0SSteve Yin 	if ( getAccessibleRole() != AccessibleRole::SHAPE
688*9b8096d0SSteve Yin 		&& getAccessibleRole() != AccessibleRole::RADIO_BUTTON  )
689*9b8096d0SSteve Yin 	{
690*9b8096d0SSteve Yin 		AccessibleControlShape* pCtlAccShape = GetLabeledByControlShape();
691*9b8096d0SSteve Yin 		if(pCtlAccShape)
692*9b8096d0SSteve Yin 		{
693*9b8096d0SSteve Yin 			sName = pCtlAccShape->CreateAccessibleName();
694*9b8096d0SSteve Yin 		}
695cdf0e10cSrcweir 	}
696*9b8096d0SSteve Yin 	if(sName.getLength() == 0)
697*9b8096d0SSteve Yin 	{
698*9b8096d0SSteve Yin 		// check if we can obtain the "Name" resp. "Label" property from the model
699*9b8096d0SSteve Yin 		const ::rtl::OUString& rAccNameProperty = lcl_getPreferredAccNameProperty( m_xModelPropsMeta );
700*9b8096d0SSteve Yin 		sName = getControlModelStringProperty( rAccNameProperty );
701*9b8096d0SSteve Yin 		if ( !sName.getLength() )
702*9b8096d0SSteve Yin 		{	// no -> use the default
703*9b8096d0SSteve Yin 			sName = AccessibleShape::CreateAccessibleName();
704*9b8096d0SSteve Yin 		}
705*9b8096d0SSteve Yin 	}
706cdf0e10cSrcweir 	// now that somebody first asked us for our name, ensure that we are listening to name changes on the model
707cdf0e10cSrcweir 	m_bListeningForName = ensureListeningState( m_bListeningForName, sal_True, lcl_getPreferredAccNameProperty( m_xModelPropsMeta ) );
708cdf0e10cSrcweir 
709cdf0e10cSrcweir 	return sName;
710cdf0e10cSrcweir }
711cdf0e10cSrcweir 
712cdf0e10cSrcweir //--------------------------------------------------------------------
disposing(void)713cdf0e10cSrcweir void SAL_CALL AccessibleControlShape::disposing (void)
714cdf0e10cSrcweir {
715cdf0e10cSrcweir 	// ensure we're not listening
716cdf0e10cSrcweir 	m_bListeningForName = ensureListeningState( m_bListeningForName, sal_False, lcl_getPreferredAccNameProperty( m_xModelPropsMeta ) );
717cdf0e10cSrcweir 	m_bListeningForDesc = ensureListeningState( m_bListeningForDesc, sal_False, lcl_getDescPropertyName() );
718cdf0e10cSrcweir 
719cdf0e10cSrcweir 	if ( m_bMultiplexingStates )
720cdf0e10cSrcweir 		stopStateMultiplexing( );
721cdf0e10cSrcweir 
722cdf0e10cSrcweir 	// dispose the child cache/map
723cdf0e10cSrcweir 	m_pChildManager->dispose();
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 	// release the model
726cdf0e10cSrcweir 	m_xControlModel.clear();
727cdf0e10cSrcweir 	m_xModelPropsMeta.clear();
728cdf0e10cSrcweir 	m_aControlContext = WeakReference< XAccessibleContext >();
729cdf0e10cSrcweir 
730cdf0e10cSrcweir     // stop listening at the control container (should never be necessary here, but who knows ....)
731cdf0e10cSrcweir     if ( m_bWaitingForControl )
732cdf0e10cSrcweir     {
733cdf0e10cSrcweir         OSL_ENSURE( sal_False, "AccessibleControlShape::disposing: this should never happen!" );
734cdf0e10cSrcweir         Reference< XContainer > xContainer = lcl_getControlContainer( maShapeTreeInfo.GetWindow(), maShapeTreeInfo.GetSdrView() );
735cdf0e10cSrcweir         if ( xContainer.is() )
736cdf0e10cSrcweir         {
737cdf0e10cSrcweir             m_bWaitingForControl = sal_False;
738cdf0e10cSrcweir             xContainer->removeContainerListener( this );
739cdf0e10cSrcweir         }
740cdf0e10cSrcweir     }
741cdf0e10cSrcweir 
742cdf0e10cSrcweir 	// forward the disposel to our inner context
743cdf0e10cSrcweir 	if ( m_bDisposeNativeContext )
744cdf0e10cSrcweir 	{
745cdf0e10cSrcweir 		// don't listen for mode changes anymore
746cdf0e10cSrcweir 		Reference< XModeChangeBroadcaster > xControlModes( m_xUnoControl, UNO_QUERY );
747cdf0e10cSrcweir 		OSL_ENSURE( xControlModes.is(), "AccessibleControlShape::disposing: don't have an mode broadcaster anymore!" );
748cdf0e10cSrcweir 		if ( xControlModes.is() )
749cdf0e10cSrcweir 			xControlModes->removeModeChangeListener( this );
750cdf0e10cSrcweir 
751cdf0e10cSrcweir         if ( m_xControlContextComponent.is() )
752cdf0e10cSrcweir 			m_xControlContextComponent->dispose();
753cdf0e10cSrcweir 		// do _not_ clear m_xControlContextProxy! This has to be done in the dtor for correct ref-count handling
754cdf0e10cSrcweir 
755cdf0e10cSrcweir 		// no need to dispose the proxy/inner context anymore
756cdf0e10cSrcweir 		m_bDisposeNativeContext = sal_False;
757cdf0e10cSrcweir 	}
758cdf0e10cSrcweir 
759cdf0e10cSrcweir 	m_xUnoControl.clear();
760cdf0e10cSrcweir 
761cdf0e10cSrcweir 	// let the base do it's stuff
762cdf0e10cSrcweir 	AccessibleShape::disposing();
763cdf0e10cSrcweir }
764cdf0e10cSrcweir 
765cdf0e10cSrcweir //--------------------------------------------------------------------
ensureControlModelAccess()766cdf0e10cSrcweir sal_Bool AccessibleControlShape::ensureControlModelAccess() SAL_THROW(())
767cdf0e10cSrcweir {
768cdf0e10cSrcweir 	if ( m_xControlModel.is() )
769cdf0e10cSrcweir 		return sal_True;
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 	try
772cdf0e10cSrcweir 	{
773cdf0e10cSrcweir 		Reference< XControlShape > xShape( mxShape, UNO_QUERY );
774cdf0e10cSrcweir 		if ( xShape.is() )
775cdf0e10cSrcweir 			m_xControlModel = m_xControlModel.query( xShape->getControl() );
776cdf0e10cSrcweir 
777cdf0e10cSrcweir 		if ( m_xControlModel.is() )
778cdf0e10cSrcweir 			m_xModelPropsMeta = m_xControlModel->getPropertySetInfo();
779cdf0e10cSrcweir 	}
780cdf0e10cSrcweir 	catch( const Exception& e )
781cdf0e10cSrcweir 	{
782cdf0e10cSrcweir 		(void)e;    // make compiler happy
783cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "AccessibleControlShape::ensureControlModelAccess: caught an exception!" );
784cdf0e10cSrcweir 	}
785cdf0e10cSrcweir 
786cdf0e10cSrcweir 	return m_xControlModel.is();
787cdf0e10cSrcweir }
788cdf0e10cSrcweir 
789cdf0e10cSrcweir //--------------------------------------------------------------------
startStateMultiplexing()790cdf0e10cSrcweir void AccessibleControlShape::startStateMultiplexing()
791cdf0e10cSrcweir {
792cdf0e10cSrcweir 	OSL_PRECOND( !m_bMultiplexingStates, "AccessibleControlShape::startStateMultiplexing: already multiplexing!" );
793cdf0e10cSrcweir 
794cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
795cdf0e10cSrcweir 	// we should have a control, and it should be in alive mode
796cdf0e10cSrcweir 	OSL_PRECOND( isAliveMode( m_xUnoControl ),
797cdf0e10cSrcweir 		"AccessibleControlShape::startStateMultiplexing: should be done in alive mode only!" );
798cdf0e10cSrcweir #endif
799cdf0e10cSrcweir 	// we should have the native context of the control
800cdf0e10cSrcweir 	Reference< XAccessibleEventBroadcaster > xBroadcaster( m_aControlContext.get(), UNO_QUERY );
801cdf0e10cSrcweir 	OSL_ENSURE( xBroadcaster.is(), "AccessibleControlShape::startStateMultiplexing: no AccessibleEventBroadcaster on the native context!" );
802cdf0e10cSrcweir 
803cdf0e10cSrcweir 	if ( xBroadcaster.is() )
804cdf0e10cSrcweir 	{
805cdf0e10cSrcweir 		xBroadcaster->addEventListener( this );
806cdf0e10cSrcweir 		m_bMultiplexingStates = sal_True;
807cdf0e10cSrcweir 	}
808cdf0e10cSrcweir }
809cdf0e10cSrcweir 
810cdf0e10cSrcweir //--------------------------------------------------------------------
stopStateMultiplexing()811cdf0e10cSrcweir void AccessibleControlShape::stopStateMultiplexing()
812cdf0e10cSrcweir {
813cdf0e10cSrcweir 	OSL_PRECOND( m_bMultiplexingStates, "AccessibleControlShape::stopStateMultiplexing: not multiplexing!" );
814cdf0e10cSrcweir 
815cdf0e10cSrcweir 	// we should have the native context of the control
816cdf0e10cSrcweir 	Reference< XAccessibleEventBroadcaster > xBroadcaster( m_aControlContext.get(), UNO_QUERY );
817cdf0e10cSrcweir 	OSL_ENSURE( xBroadcaster.is(), "AccessibleControlShape::stopStateMultiplexing: no AccessibleEventBroadcaster on the native context!" );
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 	if ( xBroadcaster.is() )
820cdf0e10cSrcweir 	{
821cdf0e10cSrcweir 		xBroadcaster->removeEventListener( this );
822cdf0e10cSrcweir 		m_bMultiplexingStates = sal_False;
823cdf0e10cSrcweir 	}
824cdf0e10cSrcweir }
825cdf0e10cSrcweir 
826cdf0e10cSrcweir //--------------------------------------------------------------------
getControlModelStringProperty(const::rtl::OUString & _rPropertyName) const827cdf0e10cSrcweir ::rtl::OUString	AccessibleControlShape::getControlModelStringProperty( const ::rtl::OUString& _rPropertyName ) const SAL_THROW(())
828cdf0e10cSrcweir {
829cdf0e10cSrcweir 	::rtl::OUString sReturn;
830cdf0e10cSrcweir 	try
831cdf0e10cSrcweir 	{
832cdf0e10cSrcweir 		if ( const_cast< AccessibleControlShape* >( this )->ensureControlModelAccess() )
833cdf0e10cSrcweir 		{
834cdf0e10cSrcweir 			if ( !m_xModelPropsMeta.is() ||	m_xModelPropsMeta->hasPropertyByName( _rPropertyName ) )
835cdf0e10cSrcweir 				// ask only if a) the control does not have a PropertySetInfo object or b) it has, and the
836cdf0e10cSrcweir 				// property in question is available
837cdf0e10cSrcweir 				m_xControlModel->getPropertyValue( _rPropertyName ) >>= sReturn;
838cdf0e10cSrcweir 		}
839cdf0e10cSrcweir 	}
840cdf0e10cSrcweir 	catch( const Exception& )
841cdf0e10cSrcweir 	{
842cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "OAccessibleControlContext::getModelStringProperty: caught an exception!" );
843cdf0e10cSrcweir 	}
844cdf0e10cSrcweir 	return sReturn;
845cdf0e10cSrcweir }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir //--------------------------------------------------------------------
adjustAccessibleRole()848cdf0e10cSrcweir void AccessibleControlShape::adjustAccessibleRole( )
849cdf0e10cSrcweir {
850cdf0e10cSrcweir 	// if we're in design mode, we are a simple SHAPE, in alive mode, we use the role of our inner context
851cdf0e10cSrcweir 	if ( !isAliveMode( m_xUnoControl ) )
852cdf0e10cSrcweir 		return;
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 	// we're in alive mode -> determine the role of the inner context
855cdf0e10cSrcweir 	Reference< XAccessibleContext > xNativeContext( m_aControlContext );
856cdf0e10cSrcweir 	OSL_PRECOND( xNativeContext.is(), "AccessibleControlShape::adjustAccessibleRole: no inner context!" );
857cdf0e10cSrcweir 	if ( xNativeContext.is() )
858cdf0e10cSrcweir 		SetAccessibleRole( xNativeContext->getAccessibleRole( ) );
859cdf0e10cSrcweir }
860cdf0e10cSrcweir 
861cdf0e10cSrcweir #ifdef DBG_UTIL
862cdf0e10cSrcweir //--------------------------------------------------------------------
SetState(sal_Int16 _nState)863cdf0e10cSrcweir sal_Bool AccessibleControlShape::SetState( sal_Int16 _nState )
864cdf0e10cSrcweir {
865cdf0e10cSrcweir 	OSL_ENSURE( !isAliveMode( m_xUnoControl ) || !isComposedState( _nState ),
866cdf0e10cSrcweir 		"AccessibleControlShape::SetState: a state which should be determined by the control context is set from outside!" );
867cdf0e10cSrcweir 	return AccessibleShape::SetState( _nState );
868cdf0e10cSrcweir }
869cdf0e10cSrcweir #endif // DBG_UTIL
870cdf0e10cSrcweir 
871cdf0e10cSrcweir //--------------------------------------------------------------------
initializeComposedState()872cdf0e10cSrcweir void AccessibleControlShape::initializeComposedState()
873cdf0e10cSrcweir {
874cdf0e10cSrcweir 	if ( !isAliveMode( m_xUnoControl ) )
875cdf0e10cSrcweir 		// no action necessary for design mode
876cdf0e10cSrcweir 		return;
877cdf0e10cSrcweir 
878cdf0e10cSrcweir 	// get our own state set implementation
879cdf0e10cSrcweir 	::utl::AccessibleStateSetHelper* pComposedStates =
880cdf0e10cSrcweir 		static_cast< ::utl::AccessibleStateSetHelper* >( mxStateSet.get() );
881cdf0e10cSrcweir 	OSL_PRECOND( pComposedStates,
882cdf0e10cSrcweir 		"AccessibleControlShape::initializeComposedState: no composed set!" );
883cdf0e10cSrcweir 
884cdf0e10cSrcweir 	// we need to reset some states of the composed set, because they either do not apply
885cdf0e10cSrcweir 	// for controls in alive mode, or are in the responsibility of the UNO-control, anyway
886cdf0e10cSrcweir 	pComposedStates->RemoveState( AccessibleStateType::ENABLED );		// this is controlled by the UNO-control
887cdf0e10cSrcweir     pComposedStates->RemoveState( AccessibleStateType::SENSITIVE );		// this is controlled by the UNO-control
888cdf0e10cSrcweir 	pComposedStates->RemoveState( AccessibleStateType::FOCUSABLE );		// this is controlled by the UNO-control
889cdf0e10cSrcweir 	pComposedStates->RemoveState( AccessibleStateType::SELECTABLE );	// this does not hold for an alive UNO-control
890cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
891cdf0e10cSrcweir 	// now, only states which are not in the responsibility of the UNO control should be part of this state set
892cdf0e10cSrcweir 	{
893cdf0e10cSrcweir 		Sequence< sal_Int16 > aInitStates = pComposedStates->getStates();
894cdf0e10cSrcweir 		for ( sal_Int32 i=0; i<aInitStates.getLength(); ++i )
895cdf0e10cSrcweir 			OSL_ENSURE( !isComposedState( aInitStates.getConstArray()[i] ),
896cdf0e10cSrcweir 				"AccessibleControlShape::initializeComposedState: invalid initial composed state (should be controlled by the UNO-control)!" );
897cdf0e10cSrcweir 	}
898cdf0e10cSrcweir #endif
899cdf0e10cSrcweir 
900cdf0e10cSrcweir 	// get my inner context
901cdf0e10cSrcweir 	Reference< XAccessibleContext > xInnerContext( m_aControlContext );
902cdf0e10cSrcweir 	OSL_PRECOND( xInnerContext.is(), "AccessibleControlShape::initializeComposedState: no inner context!" );
903cdf0e10cSrcweir 	if ( xInnerContext.is() )
904cdf0e10cSrcweir 	{
905cdf0e10cSrcweir 		// get all states of the inner context
906cdf0e10cSrcweir 		Reference< XAccessibleStateSet > xInnerStates( xInnerContext->getAccessibleStateSet() );
907cdf0e10cSrcweir 		OSL_ENSURE( xInnerStates.is(), "AccessibleControlShape::initializeComposedState: no inner states!" );
908cdf0e10cSrcweir 		Sequence< sal_Int16 > aInnerStates;
909cdf0e10cSrcweir 		if ( xInnerStates.is() )
910cdf0e10cSrcweir 			aInnerStates = xInnerStates->getStates();
911cdf0e10cSrcweir 
912cdf0e10cSrcweir 		// look which one are to be propagated to the composed context
913cdf0e10cSrcweir 		const sal_Int16* pStates = aInnerStates.getConstArray();
914cdf0e10cSrcweir 		const sal_Int16* pStatesEnd = pStates + aInnerStates.getLength();
915cdf0e10cSrcweir 		for ( ; pStates != pStatesEnd; ++pStates )
916cdf0e10cSrcweir 		{
917cdf0e10cSrcweir 			if ( isComposedState( *pStates ) && !pComposedStates->contains( *pStates ) )
918cdf0e10cSrcweir 			{
919cdf0e10cSrcweir 				pComposedStates->AddState( *pStates );
920cdf0e10cSrcweir 			}
921cdf0e10cSrcweir 		}
922cdf0e10cSrcweir 	}
923cdf0e10cSrcweir }
924cdf0e10cSrcweir 
elementInserted(const::com::sun::star::container::ContainerEvent & _rEvent)925cdf0e10cSrcweir void SAL_CALL AccessibleControlShape::elementInserted( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw (::com::sun::star::uno::RuntimeException)
926cdf0e10cSrcweir {
927cdf0e10cSrcweir     Reference< XContainer > xContainer( _rEvent.Source, UNO_QUERY );
928cdf0e10cSrcweir     Reference< XControl > xControl( _rEvent.Element, UNO_QUERY );
929cdf0e10cSrcweir 
930cdf0e10cSrcweir     OSL_ENSURE( xContainer.is() && xControl.is(),
931cdf0e10cSrcweir         "AccessibleControlShape::elementInserted: invalid event description!" );
932cdf0e10cSrcweir 
933cdf0e10cSrcweir     if ( !xControl.is() )
934cdf0e10cSrcweir         return;
935cdf0e10cSrcweir 
936cdf0e10cSrcweir     ensureControlModelAccess();
937cdf0e10cSrcweir 
938cdf0e10cSrcweir     Reference< XInterface > xNewNormalized( xControl->getModel(), UNO_QUERY );
939cdf0e10cSrcweir     Reference< XInterface > xMyModelNormalized( m_xControlModel, UNO_QUERY );
940cdf0e10cSrcweir     if ( xNewNormalized.get() && xMyModelNormalized.get() )
941cdf0e10cSrcweir     {
942cdf0e10cSrcweir         // now finally the control for the model we're responsible for has been inserted into the container
943cdf0e10cSrcweir         Reference< XInterface > xKeepAlive( *this );
944cdf0e10cSrcweir 
945cdf0e10cSrcweir         // first, we're not interested in any more container events
946cdf0e10cSrcweir         if ( xContainer.is() )
947cdf0e10cSrcweir         {
948cdf0e10cSrcweir             xContainer->removeContainerListener( this );
949cdf0e10cSrcweir             m_bWaitingForControl = sal_False;
950cdf0e10cSrcweir         }
951cdf0e10cSrcweir 
952cdf0e10cSrcweir         // second, we need to replace ourself with a new version, which now can be based on the
953cdf0e10cSrcweir         // control
954cdf0e10cSrcweir 		OSL_VERIFY( mpParent->ReplaceChild ( this, mxShape, mnIndex, maShapeTreeInfo ) );
955cdf0e10cSrcweir     }
956cdf0e10cSrcweir }
957cdf0e10cSrcweir 
elementRemoved(const::com::sun::star::container::ContainerEvent &)958cdf0e10cSrcweir void SAL_CALL AccessibleControlShape::elementRemoved( const ::com::sun::star::container::ContainerEvent& ) throw (::com::sun::star::uno::RuntimeException)
959cdf0e10cSrcweir {
960cdf0e10cSrcweir     // not interested in
961cdf0e10cSrcweir }
962cdf0e10cSrcweir 
elementReplaced(const::com::sun::star::container::ContainerEvent &)963cdf0e10cSrcweir void SAL_CALL AccessibleControlShape::elementReplaced( const ::com::sun::star::container::ContainerEvent& ) throw (::com::sun::star::uno::RuntimeException)
964cdf0e10cSrcweir {
965cdf0e10cSrcweir     // not interested in
966cdf0e10cSrcweir }
GetLabeledByControlShape()967*9b8096d0SSteve Yin AccessibleControlShape* SAL_CALL AccessibleControlShape::GetLabeledByControlShape( )
968*9b8096d0SSteve Yin {
969*9b8096d0SSteve Yin 	if(m_xControlModel.is())
970*9b8096d0SSteve Yin 	{
971*9b8096d0SSteve Yin 		const ::rtl::OUString& rAccLabelControlProperty = lcl_getLabelControlPropertyName();
972*9b8096d0SSteve Yin 		Any sCtlLabelBy;
973*9b8096d0SSteve Yin 		// get the "label by" property value of the control
974*9b8096d0SSteve Yin 		if (::comphelper::hasProperty(rAccLabelControlProperty, m_xControlModel))
975*9b8096d0SSteve Yin 		{
976*9b8096d0SSteve Yin 			m_xControlModel->getPropertyValue( rAccLabelControlProperty ) >>= sCtlLabelBy;
977*9b8096d0SSteve Yin 			if( sCtlLabelBy.hasValue() )
978*9b8096d0SSteve Yin 			{
979*9b8096d0SSteve Yin 				Reference< XPropertySet >  xAsSet (sCtlLabelBy, UNO_QUERY);
980*9b8096d0SSteve Yin 				AccessibleControlShape* pCtlAccShape = mpParent->GetAccControlShapeFromModel(xAsSet.get());
981*9b8096d0SSteve Yin 				return pCtlAccShape;
982*9b8096d0SSteve Yin 			}
983*9b8096d0SSteve Yin 		}
984*9b8096d0SSteve Yin 	}
985*9b8096d0SSteve Yin 	return NULL;
986*9b8096d0SSteve Yin }
987