1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <svx/AccessibleControlShape.hxx>
30 #include <svx/AccessibleShapeInfo.hxx>
31 #include "svx/DescriptionGenerator.hxx"
32 #include <com/sun/star/drawing/XControlShape.hpp>
33 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
34 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
35 #include <com/sun/star/form/FormComponentType.hpp>
36 #include <com/sun/star/reflection/XProxyFactory.hpp>
37 #include <com/sun/star/container/XContainer.hpp>
38 #include <comphelper/processfactory.hxx>
39 #include <unotools/accessiblestatesethelper.hxx>
40 #include <svx/svdouno.hxx>
41 #include "svx/unoapi.hxx"
42 #include <svx/ShapeTypeHandler.hxx>
43 #include <svx/SvxShapeTypes.hxx>
44 #include <toolkit/helper/vclunohelper.hxx>
45 #include <comphelper/accessiblewrapper.hxx>
46 #include <svx/svdview.hxx>
47 #include <svx/svdpagv.hxx>
48 #include "svx/svdstr.hrc"
51 using namespace ::comphelper
;
52 using namespace ::accessibility
;
53 using namespace ::com::sun::star::accessibility
;
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::awt
;
56 using namespace ::com::sun::star::beans
;
57 using namespace ::com::sun::star::util
;
58 using namespace ::com::sun::star::lang
;
59 using namespace ::com::sun::star::reflection
;
60 using namespace ::com::sun::star::drawing
;
61 using namespace ::com::sun::star::container
;
63 //--------------------------------------------------------------------
66 //................................................................
67 const ::rtl::OUString
& lcl_getNamePropertyName( )
69 static ::rtl::OUString
s_sNamePropertyName( RTL_CONSTASCII_USTRINGPARAM( "Name" ) );
70 return s_sNamePropertyName
;
72 //................................................................
73 const ::rtl::OUString
& lcl_getDescPropertyName( )
75 static ::rtl::OUString
s_sDescPropertyDesc( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) );
76 return s_sDescPropertyDesc
;
78 //................................................................
79 const ::rtl::OUString
& lcl_getLabelPropertyName( )
81 static ::rtl::OUString
s_sLabelPropertyLabel( RTL_CONSTASCII_USTRINGPARAM( "Label" ) );
82 return s_sLabelPropertyLabel
;
84 //................................................................
85 // return the property which should be used as AccessibleName
86 const ::rtl::OUString
& lcl_getPreferredAccNameProperty( const Reference
< XPropertySetInfo
>& _rxPSI
)
88 if ( _rxPSI
.is() && _rxPSI
->hasPropertyByName( lcl_getLabelPropertyName() ) )
89 return lcl_getLabelPropertyName();
91 return lcl_getNamePropertyName();
94 //................................................................
95 // determines whether or not a state which belongs to the inner context needs to be forwarded to the "composed"
97 sal_Bool
isComposedState( const sal_Int16 _nState
)
99 return ( ( AccessibleStateType::INVALID
!= _nState
)
100 && ( AccessibleStateType::DEFUNC
!= _nState
)
101 && ( AccessibleStateType::ICONIFIED
!= _nState
)
102 && ( AccessibleStateType::RESIZABLE
!= _nState
)
103 && ( AccessibleStateType::SELECTABLE
!= _nState
)
104 && ( AccessibleStateType::SHOWING
!= _nState
)
105 && ( AccessibleStateType::MANAGES_DESCENDANTS
!= _nState
)
106 && ( AccessibleStateType::VISIBLE
!= _nState
)
110 //................................................................
111 /** determines whether the given control is in alive mode
113 inline sal_Bool
isAliveMode( const Reference
< XControl
>& _rxControl
)
115 OSL_PRECOND( _rxControl
.is(), "AccessibleControlShape::isAliveMode: invalid control" );
116 return _rxControl
.is() && !_rxControl
->isDesignMode();
120 //=============================================================================
121 //= AccessibleControlShape
122 //=============================================================================
124 //-----------------------------------------------------------------------------
125 AccessibleControlShape::AccessibleControlShape (
126 const AccessibleShapeInfo
& rShapeInfo
,
127 const AccessibleShapeTreeInfo
& rShapeTreeInfo
)
128 : AccessibleShape (rShapeInfo
, rShapeTreeInfo
)
129 , m_bListeningForName( sal_False
)
130 , m_bListeningForDesc( sal_False
)
131 , m_bMultiplexingStates( sal_False
)
132 , m_bDisposeNativeContext( sal_False
)
133 , m_bWaitingForControl( sal_False
)
135 m_pChildManager
= new OWrappedAccessibleChildrenManager( getProcessServiceFactory() );
136 m_pChildManager
->acquire();
138 osl_incrementInterlockedCount( &m_refCount
);
140 m_pChildManager
->setOwningAccessible( this );
142 osl_decrementInterlockedCount( &m_refCount
);
145 //-----------------------------------------------------------------------------
146 AccessibleControlShape::~AccessibleControlShape (void)
148 m_pChildManager
->release();
149 m_pChildManager
= NULL
;
151 if ( m_xControlContextProxy
.is() )
152 m_xControlContextProxy
->setDelegator( NULL
);
153 m_xControlContextProxy
.clear();
154 m_xControlContextTypeAccess
.clear();
155 m_xControlContextComponent
.clear();
156 // this should remove the _only_ three "real" reference (means not delegated to
157 // ourself) to this proxy, and thus delete it
160 //-----------------------------------------------------------------------------
161 SdrObject
* AccessibleControlShape::getSdrObject() const
163 return GetSdrObjectFromXShape (mxShape
);
167 Reference
< XContainer
> lcl_getControlContainer( const Window
* _pWin
, const SdrView
* _pView
)
169 Reference
< XContainer
> xReturn
;
170 DBG_ASSERT( _pView
, "lcl_getControlContainer: invalid view!" );
171 if ( _pView
&& _pView
->GetSdrPageView())
173 xReturn
= xReturn
.query( _pView
->GetSdrPageView()->GetControlContainer( *_pWin
) );
179 //-----------------------------------------------------------------------------
180 void AccessibleControlShape::Init()
182 AccessibleShape::Init();
184 OSL_ENSURE( !m_xControlContextProxy
.is(), "AccessibleControlShape::Init: already initialized!" );
187 // What we need to do here is merge the functionality of the AccessibleContext of our UNO control
188 // with our own AccessibleContext-related functionality.
190 // The problem is that we do not know the interfaces our "inner" context supports - this may be any
191 // XAccessibleXXX interface (or even any other) which makes sense for it.
193 // In theory, we could implement all possible interfaces ourself, and re-route all functionality to
194 // the inner context (except those we implement ourself, like XAccessibleComponent). But this is in no
195 // way future-proof - as soon as an inner context appears which implements an additional interface,
196 // we would need to adjust our implementation to support this new interface, too. Bad idea.
198 // The usual solution for such a problem is aggregation. Aggregation means using UNO's own meachnisms
199 // for merging an inner with an outer component, and get a component which behaves as it is exactly one.
200 // This is what XAggregation is for. Unfortunately, aggregation requires _exact_ control over the ref count
201 // of the inner object, which we do not have at all.
204 // But there is a solution: com.sun.star.reflection.ProxyFactory. This service is able to create a proxy
205 // for any component, which supports _exactly_ the same interfaces as the component. In addition, it can
206 // be aggregated, as by definition the proxy's ref count is exactly 1 when returned from the factory.
207 // Sounds better. Though this yields the problem of slightly degraded performance, it's the only solution
208 // I'm aware of at the moment .....
210 // get the control which belongs to our model (relative to our view)
211 const Window
* pViewWindow
= maShapeTreeInfo
.GetWindow();
212 SdrUnoObj
* pUnoObjectImpl
= PTR_CAST( SdrUnoObj
, getSdrObject() );
213 SdrView
* pView
= maShapeTreeInfo
.GetSdrView();
214 OSL_ENSURE( pView
&& pViewWindow
&& pUnoObjectImpl
, "AccessibleControlShape::Init: no view, or no view window, no SdrUnoObj!" );
216 if ( pView
&& pViewWindow
&& pUnoObjectImpl
)
218 // .................................................................
219 // get the context of the control - it will be our "inner" context
220 m_xUnoControl
= pUnoObjectImpl
->GetUnoControl( *pView
, *pViewWindow
);
222 if ( !m_xUnoControl
.is() )
224 // the control has not yet been created. Though speaking strictly, it is a bug that
225 // our instance here is created without an existing control (because an AccessibleControlShape
226 // is a representation of a view object, and can only live if the view it should represent
227 // is complete, which implies a living control), it's by far the easiest and most riskless way
228 // to fix this here in this class.
229 // Okay, we will add as listener to the control container where we expect our control to appear.
230 OSL_ENSURE( !m_bWaitingForControl
, "AccessibleControlShape::Init: already waiting for the control!" );
232 Reference
< XContainer
> xControlContainer
= lcl_getControlContainer( pViewWindow
, maShapeTreeInfo
.GetSdrView() );
233 OSL_ENSURE( xControlContainer
.is(), "AccessibleControlShape::Init: unable to find my ControlContainer!" );
234 if ( xControlContainer
.is() )
236 xControlContainer
->addContainerListener( this );
237 m_bWaitingForControl
= sal_True
;
242 Reference
< XModeChangeBroadcaster
> xControlModes( m_xUnoControl
, UNO_QUERY
);
243 Reference
< XAccessible
> xControlAccessible( xControlModes
, UNO_QUERY
);
244 Reference
< XAccessibleContext
> xNativeControlContext
;
245 if ( xControlAccessible
.is() )
246 xNativeControlContext
= xControlAccessible
->getAccessibleContext();
247 OSL_ENSURE( xNativeControlContext
.is(), "AccessibleControlShape::Init: no AccessibleContext for the control!" );
248 m_aControlContext
= WeakReference
< XAccessibleContext
>( xNativeControlContext
);
250 // .................................................................
251 // add as listener to the context - we want to multiplex some states
252 if ( isAliveMode( m_xUnoControl
) && xNativeControlContext
.is() )
253 { // (but only in alive mode)
254 startStateMultiplexing( );
257 // now that we have all information about our control, do some adjustments
258 adjustAccessibleRole();
259 initializeComposedState();
261 // some initialization for our child manager, which is used in alive mode only
262 if ( isAliveMode( m_xUnoControl
) )
264 Reference
< XAccessibleStateSet
> xStates( getAccessibleStateSet( ) );
265 OSL_ENSURE( xStates
.is(), "AccessibleControlShape::AccessibleControlShape: no inner state set!" );
266 m_pChildManager
->setTransientChildren( !xStates
.is() || xStates
->contains( AccessibleStateType::MANAGES_DESCENDANTS
) );
269 // .................................................................
270 // finally, aggregate a proxy for the control context
271 // first a factory for the proxy
272 Reference
< XProxyFactory
> xFactory
;
273 xFactory
= xFactory
.query( createProcessComponent( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.reflection.ProxyFactory" ) ) ) );
274 OSL_ENSURE( xFactory
.is(), "AccessibleControlShape::Init: could not create a proxy factory!" );
275 // then the proxy itself
276 if ( xFactory
.is() && xNativeControlContext
.is() )
278 m_xControlContextProxy
= xFactory
->createProxy( xNativeControlContext
);
279 OSL_VERIFY( xNativeControlContext
->queryInterface( ::getCppuType( &m_xControlContextTypeAccess
) ) >>= m_xControlContextTypeAccess
);
280 OSL_VERIFY( xNativeControlContext
->queryInterface( ::getCppuType( &m_xControlContextComponent
) ) >>= m_xControlContextComponent
);
282 // aggregate the proxy
283 osl_incrementInterlockedCount( &m_refCount
);
284 if ( m_xControlContextProxy
.is() )
286 // At this point in time, the proxy has a ref count of exactly one - in m_xControlContextProxy.
287 // Remember to _not_ reset this member unles the delegator of the proxy has been reset, too!
288 m_xControlContextProxy
->setDelegator( *this );
290 osl_decrementInterlockedCount( &m_refCount
);
292 m_bDisposeNativeContext
= sal_True
;
294 // Finally, we need to add ourself as mode listener to the control. In case the mode switches,
295 // we need to dispose ourself.
296 xControlModes
->addModeChangeListener( this );
301 catch( const Exception
& )
303 OSL_FAIL( "AccessibleControlShape::Init: could not \"aggregate\" the controls XAccessibleContext!" );
307 //-----------------------------------------------------------------------------
308 Reference
< XAccessibleContext
> SAL_CALL
AccessibleControlShape::getAccessibleContext(void) throw (RuntimeException
)
310 return AccessibleShape::getAccessibleContext ();
314 //-----------------------------------------------------------------------------
315 void SAL_CALL
AccessibleControlShape::grabFocus(void) throw (RuntimeException
)
317 if ( !m_xUnoControl
.is() || !isAliveMode( m_xUnoControl
) )
319 // in design mode, we simply forward the request to the base class
320 AccessibleShape::grabFocus();
324 Reference
< XWindow
> xWindow( m_xUnoControl
, UNO_QUERY
);
325 OSL_ENSURE( xWindow
.is(), "AccessibleControlShape::grabFocus: invalid control!" );
331 //-----------------------------------------------------------------------------
332 ::rtl::OUString SAL_CALL
AccessibleControlShape::getImplementationName(void) throw (RuntimeException
)
334 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.accessibility.AccessibleControlShape" ) );
337 //-----------------------------------------------------------------------------
338 ::rtl::OUString
AccessibleControlShape::CreateAccessibleBaseName(void) throw (RuntimeException
)
340 ::rtl::OUString sName
;
342 ShapeTypeId nShapeType
= ShapeTypeHandler::Instance().GetTypeId (mxShape
);
345 case DRAWING_CONTROL
:
346 sName
= ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("ControlShape"));
349 sName
= ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("UnknownAccessibleControlShape"));
350 Reference
< XShapeDescriptor
> xDescriptor (mxShape
, UNO_QUERY
);
351 if (xDescriptor
.is())
352 sName
+= ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM(": "))
353 + xDescriptor
->getShapeType();
362 //--------------------------------------------------------------------
364 AccessibleControlShape::CreateAccessibleDescription (void)
365 throw (RuntimeException
)
367 DescriptionGenerator
aDG (mxShape
);
368 ShapeTypeId nShapeType
= ShapeTypeHandler::Instance().GetTypeId (mxShape
);
371 case DRAWING_CONTROL
:
373 // check if we can obtain the "Desc" property from the model
374 ::rtl::OUString
sDesc( getControlModelStringProperty( lcl_getDescPropertyName() ) );
375 if ( sDesc
.isEmpty() )
376 { // no -> use the default
377 aDG
.Initialize (STR_ObjNameSingulUno
);
378 aDG
.AddProperty (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlBackground")),
379 DescriptionGenerator::COLOR
,
381 aDG
.AddProperty (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ControlBorder")),
382 DescriptionGenerator::INTEGER
,
385 // ensure that we are listening to the Name property
386 m_bListeningForDesc
= ensureListeningState( m_bListeningForDesc
, sal_True
, lcl_getDescPropertyName() );
391 aDG
.Initialize (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
392 "Unknown accessible control shape")) );
393 Reference
< XShapeDescriptor
> xDescriptor (mxShape
, UNO_QUERY
);
394 if (xDescriptor
.is())
396 aDG
.AppendString (::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("service name=")));
397 aDG
.AppendString (xDescriptor
->getShapeType());
404 //--------------------------------------------------------------------
405 IMPLEMENT_FORWARD_REFCOUNT( AccessibleControlShape
, AccessibleShape
)
406 IMPLEMENT_GET_IMPLEMENTATION_ID( AccessibleControlShape
)
408 //--------------------------------------------------------------------
409 void SAL_CALL
AccessibleControlShape::propertyChange( const PropertyChangeEvent
& _rEvent
) throw (RuntimeException
)
411 ::osl::MutexGuard
aGuard( maMutex
);
413 // check if it is the name or the description
414 if ( _rEvent
.PropertyName
.equals( lcl_getNamePropertyName() )
415 || _rEvent
.PropertyName
.equals( lcl_getLabelPropertyName( ) )
419 CreateAccessibleName(),
420 AccessibleContextBase::AutomaticallyCreated
);
422 else if ( _rEvent
.PropertyName
.equals( lcl_getDescPropertyName() ) )
424 SetAccessibleDescription(
425 CreateAccessibleDescription(),
426 AccessibleContextBase::AutomaticallyCreated
);
428 #if OSL_DEBUG_LEVEL > 0
431 OSL_FAIL( "AccessibleControlShape::propertyChange: where did this come from?" );
436 //--------------------------------------------------------------------
437 Any SAL_CALL
AccessibleControlShape::queryInterface( const Type
& _rType
) throw (RuntimeException
)
439 Any aReturn
= AccessibleShape::queryInterface( _rType
);
440 if ( !aReturn
.hasValue() )
442 aReturn
= AccessibleControlShape_Base::queryInterface( _rType
);
443 if ( !aReturn
.hasValue() && m_xControlContextProxy
.is() )
444 aReturn
= m_xControlContextProxy
->queryAggregation( _rType
);
449 //--------------------------------------------------------------------
450 Sequence
< Type
> SAL_CALL
AccessibleControlShape::getTypes() throw (RuntimeException
)
452 Sequence
< Type
> aShapeTypes
= AccessibleShape::getTypes();
453 Sequence
< Type
> aOwnTypes
= AccessibleControlShape_Base::getTypes();
455 Sequence
< Type
> aAggregateTypes
;
456 if ( m_xControlContextTypeAccess
.is() )
457 aAggregateTypes
= m_xControlContextTypeAccess
->getTypes();
459 Sequence
< Type
> aAllTypes
= concatSequences( aShapeTypes
, aOwnTypes
, aAggregateTypes
);
462 Type
* pBegin
= aAllTypes
.getArray();
463 Type
* pEnd
= pBegin
+ aAllTypes
.getLength();
464 while ( pBegin
!= pEnd
)
466 Type aThisRoundType
= *pBegin
;
467 if ( ++pBegin
!= pEnd
)
469 pEnd
= ::std::remove( pBegin
, pEnd
, aThisRoundType
);
470 // now all types between begin and (the old) end which equal aThisRoundType
471 // are moved behind the new end
474 aAllTypes
.realloc( pEnd
- aAllTypes
.getArray() );
479 //--------------------------------------------------------------------
480 void SAL_CALL
AccessibleControlShape::notifyEvent( const AccessibleEventObject
& _rEvent
) throw (RuntimeException
)
482 if ( AccessibleEventId::STATE_CHANGED
== _rEvent
.EventId
)
484 // multiplex this change
485 sal_Int16
nLostState( 0 ), nGainedState( 0 );
486 _rEvent
.OldValue
>>= nLostState
;
487 _rEvent
.NewValue
>>= nGainedState
;
489 // don't multiplex states which the inner context is not resposible for
490 if ( isComposedState( nLostState
) )
491 AccessibleShape::ResetState( nLostState
);
493 if ( isComposedState( nGainedState
) )
494 AccessibleShape::SetState( nGainedState
);
498 AccessibleEventObject
aTranslatedEvent( _rEvent
);
501 ::osl::MutexGuard
aGuard( maMutex
);
503 // let the child manager translate the event
504 aTranslatedEvent
.Source
= *this;
505 m_pChildManager
->translateAccessibleEvent( _rEvent
, aTranslatedEvent
);
507 // see if any of these notifications affect our child manager
508 m_pChildManager
->handleChildNotification( _rEvent
);
511 FireEvent( aTranslatedEvent
);
515 //--------------------------------------------------------------------
516 void SAL_CALL
AccessibleControlShape::modeChanged( const ModeChangeEvent
& _rSource
) throw (RuntimeException
)
518 // did it come from our inner context (the real one, not it's proxy!)?
519 OSL_TRACE ("AccessibleControlShape::modeChanged");
520 Reference
< XControl
> xSource( _rSource
.Source
, UNO_QUERY
); // for faster compare
521 if ( xSource
.get() == m_xUnoControl
.get() )
523 // If our "pseudo-aggregated" inner context does not live anymore,
524 // we don't want to live, too. This is accomplished by asking our
525 // parent to replace this object with a new one. Disposing this
526 // object and sending notifications about the replacement are in
527 // the responsibility of our parent.
528 OSL_VERIFY( mpParent
->ReplaceChild ( this, mxShape
, mnIndex
, maShapeTreeInfo
) );
530 #if OSL_DEBUG_LEVEL > 0
532 OSL_FAIL( "AccessibleControlShape::modeChanged: where did this come from?" );
536 //--------------------------------------------------------------------
537 void SAL_CALL
AccessibleControlShape::disposing (const EventObject
& _rSource
) throw (RuntimeException
)
539 AccessibleShape::disposing( _rSource
);
542 //--------------------------------------------------------------------
543 sal_Bool
AccessibleControlShape::ensureListeningState(
544 const sal_Bool _bCurrentlyListening
, const sal_Bool _bNeedNewListening
,
545 const ::rtl::OUString
& _rPropertyName
)
547 if ( ( _bCurrentlyListening
== _bNeedNewListening
) || !ensureControlModelAccess() )
549 return _bCurrentlyListening
;
553 if ( !m_xModelPropsMeta
.is() || m_xModelPropsMeta
->hasPropertyByName( _rPropertyName
) )
555 // add or revoke as listener
556 if ( _bNeedNewListening
)
557 m_xControlModel
->addPropertyChangeListener( _rPropertyName
, static_cast< XPropertyChangeListener
* >( this ) );
559 m_xControlModel
->removePropertyChangeListener( _rPropertyName
, static_cast< XPropertyChangeListener
* >( this ) );
562 OSL_FAIL( "AccessibleControlShape::ensureListeningState: this property does not exist at this model!" );
564 catch( const Exception
& e
)
566 (void)e
; // make compiler happy
567 OSL_FAIL( "AccessibleControlShape::ensureListeningState: could not change the listening state!" );
570 return _bNeedNewListening
;
573 //--------------------------------------------------------------------
574 sal_Int32 SAL_CALL
AccessibleControlShape::getAccessibleChildCount( ) throw(RuntimeException
)
576 if ( !m_xUnoControl
.is() )
578 else if ( !isAliveMode( m_xUnoControl
) )
579 // no special action required when in design mode
580 return AccessibleShape::getAccessibleChildCount( );
583 // in alive mode, we have the full control over our children - they are determined by the children
584 // of the context of our UNO control
585 Reference
< XAccessibleContext
> xControlContext( m_aControlContext
);
586 OSL_ENSURE( xControlContext
.is(), "AccessibleControlShape::getAccessibleChildCount: control context already dead! How this!" );
587 return xControlContext
.is() ? xControlContext
->getAccessibleChildCount() : 0;
591 //--------------------------------------------------------------------
592 Reference
< XAccessible
> SAL_CALL
AccessibleControlShape::getAccessibleChild( sal_Int32 i
) throw(IndexOutOfBoundsException
, RuntimeException
)
594 Reference
< XAccessible
> xChild
;
595 if ( !m_xUnoControl
.is() )
597 throw IndexOutOfBoundsException();
599 if ( !isAliveMode( m_xUnoControl
) )
601 // no special action required when in design mode - let the base class handle this
602 xChild
= AccessibleShape::getAccessibleChild( i
);
606 // in alive mode, we have the full control over our children - they are determined by the children
607 // of the context of our UNO control
609 Reference
< XAccessibleContext
> xControlContext( m_aControlContext
);
610 OSL_ENSURE( xControlContext
.is(), "AccessibleControlShape::getAccessibleChildCount: control context already dead! How this!" );
611 if ( xControlContext
.is() )
613 Reference
< XAccessible
> xInnerChild( xControlContext
->getAccessibleChild( i
) );
614 OSL_ENSURE( xInnerChild
.is(), "AccessibleControlShape::getAccessibleChild: control context returned nonsense!" );
615 if ( xInnerChild
.is() )
617 // we need to wrap this inner child into an own implementation
618 xChild
= m_pChildManager
->getAccessibleWrapperFor( xInnerChild
);
623 #if OSL_DEBUG_LEVEL > 0
624 sal_Int32 nChildIndex
= -1;
625 Reference
< XAccessibleContext
> xContext
;
627 xContext
= xChild
->getAccessibleContext( );
629 nChildIndex
= xContext
->getAccessibleIndexInParent( );
630 OSL_ENSURE( nChildIndex
== i
, "AccessibleControlShape::getAccessibleChild: index mismatch!" );
635 //--------------------------------------------------------------------
636 Reference
< XAccessibleRelationSet
> SAL_CALL
AccessibleControlShape::getAccessibleRelationSet( ) throw (RuntimeException
)
639 return AccessibleShape::getAccessibleRelationSet( );
642 //--------------------------------------------------------------------
643 ::rtl::OUString
AccessibleControlShape::CreateAccessibleName (void) throw (RuntimeException
)
645 ensureControlModelAccess();
647 // check if we can obtain the "Name" resp. "Label" property from the model
648 const ::rtl::OUString
& rAccNameProperty
= lcl_getPreferredAccNameProperty( m_xModelPropsMeta
);
650 ::rtl::OUString
sName( getControlModelStringProperty( rAccNameProperty
) );
651 if ( sName
.isEmpty() )
652 { // no -> use the default
653 sName
= AccessibleShape::CreateAccessibleName();
656 // now that somebody first asked us for our name, ensure that we are listening to name changes on the model
657 m_bListeningForName
= ensureListeningState( m_bListeningForName
, sal_True
, lcl_getPreferredAccNameProperty( m_xModelPropsMeta
) );
662 //--------------------------------------------------------------------
663 void SAL_CALL
AccessibleControlShape::disposing (void)
665 // ensure we're not listening
666 m_bListeningForName
= ensureListeningState( m_bListeningForName
, sal_False
, lcl_getPreferredAccNameProperty( m_xModelPropsMeta
) );
667 m_bListeningForDesc
= ensureListeningState( m_bListeningForDesc
, sal_False
, lcl_getDescPropertyName() );
669 if ( m_bMultiplexingStates
)
670 stopStateMultiplexing( );
672 // dispose the child cache/map
673 m_pChildManager
->dispose();
676 m_xControlModel
.clear();
677 m_xModelPropsMeta
.clear();
678 m_aControlContext
= WeakReference
< XAccessibleContext
>();
680 // stop listening at the control container (should never be necessary here, but who knows ....)
681 if ( m_bWaitingForControl
)
683 OSL_FAIL( "AccessibleControlShape::disposing: this should never happen!" );
684 Reference
< XContainer
> xContainer
= lcl_getControlContainer( maShapeTreeInfo
.GetWindow(), maShapeTreeInfo
.GetSdrView() );
685 if ( xContainer
.is() )
687 m_bWaitingForControl
= sal_False
;
688 xContainer
->removeContainerListener( this );
692 // forward the disposel to our inner context
693 if ( m_bDisposeNativeContext
)
695 // don't listen for mode changes anymore
696 Reference
< XModeChangeBroadcaster
> xControlModes( m_xUnoControl
, UNO_QUERY
);
697 OSL_ENSURE( xControlModes
.is(), "AccessibleControlShape::disposing: don't have an mode broadcaster anymore!" );
698 if ( xControlModes
.is() )
699 xControlModes
->removeModeChangeListener( this );
701 if ( m_xControlContextComponent
.is() )
702 m_xControlContextComponent
->dispose();
703 // do _not_ clear m_xControlContextProxy! This has to be done in the dtor for correct ref-count handling
705 // no need to dispose the proxy/inner context anymore
706 m_bDisposeNativeContext
= sal_False
;
709 m_xUnoControl
.clear();
711 // let the base do it's stuff
712 AccessibleShape::disposing();
715 //--------------------------------------------------------------------
716 sal_Bool
AccessibleControlShape::ensureControlModelAccess() SAL_THROW(())
718 if ( m_xControlModel
.is() )
723 Reference
< XControlShape
> xShape( mxShape
, UNO_QUERY
);
725 m_xControlModel
= m_xControlModel
.query( xShape
->getControl() );
727 if ( m_xControlModel
.is() )
728 m_xModelPropsMeta
= m_xControlModel
->getPropertySetInfo();
730 catch( const Exception
& e
)
732 (void)e
; // make compiler happy
733 OSL_FAIL( "AccessibleControlShape::ensureControlModelAccess: caught an exception!" );
736 return m_xControlModel
.is();
739 //--------------------------------------------------------------------
740 void AccessibleControlShape::startStateMultiplexing()
742 OSL_PRECOND( !m_bMultiplexingStates
, "AccessibleControlShape::startStateMultiplexing: already multiplexing!" );
744 #if OSL_DEBUG_LEVEL > 0
745 // we should have a control, and it should be in alive mode
746 OSL_PRECOND( isAliveMode( m_xUnoControl
),
747 "AccessibleControlShape::startStateMultiplexing: should be done in alive mode only!" );
749 // we should have the native context of the control
750 Reference
< XAccessibleEventBroadcaster
> xBroadcaster( m_aControlContext
.get(), UNO_QUERY
);
751 OSL_ENSURE( xBroadcaster
.is(), "AccessibleControlShape::startStateMultiplexing: no AccessibleEventBroadcaster on the native context!" );
753 if ( xBroadcaster
.is() )
755 xBroadcaster
->addEventListener( this );
756 m_bMultiplexingStates
= sal_True
;
760 //--------------------------------------------------------------------
761 void AccessibleControlShape::stopStateMultiplexing()
763 OSL_PRECOND( m_bMultiplexingStates
, "AccessibleControlShape::stopStateMultiplexing: not multiplexing!" );
765 // we should have the native context of the control
766 Reference
< XAccessibleEventBroadcaster
> xBroadcaster( m_aControlContext
.get(), UNO_QUERY
);
767 OSL_ENSURE( xBroadcaster
.is(), "AccessibleControlShape::stopStateMultiplexing: no AccessibleEventBroadcaster on the native context!" );
769 if ( xBroadcaster
.is() )
771 xBroadcaster
->removeEventListener( this );
772 m_bMultiplexingStates
= sal_False
;
776 //--------------------------------------------------------------------
777 ::rtl::OUString
AccessibleControlShape::getControlModelStringProperty( const ::rtl::OUString
& _rPropertyName
) const SAL_THROW(())
779 ::rtl::OUString sReturn
;
782 if ( const_cast< AccessibleControlShape
* >( this )->ensureControlModelAccess() )
784 if ( !m_xModelPropsMeta
.is() || m_xModelPropsMeta
->hasPropertyByName( _rPropertyName
) )
785 // ask only if a) the control does not have a PropertySetInfo object or b) it has, and the
786 // property in question is available
787 m_xControlModel
->getPropertyValue( _rPropertyName
) >>= sReturn
;
790 catch( const Exception
& )
792 OSL_FAIL( "OAccessibleControlContext::getModelStringProperty: caught an exception!" );
797 //--------------------------------------------------------------------
798 void AccessibleControlShape::adjustAccessibleRole( )
800 // if we're in design mode, we are a simple SHAPE, in alive mode, we use the role of our inner context
801 if ( !isAliveMode( m_xUnoControl
) )
804 // we're in alive mode -> determine the role of the inner context
805 Reference
< XAccessibleContext
> xNativeContext( m_aControlContext
);
806 OSL_PRECOND( xNativeContext
.is(), "AccessibleControlShape::adjustAccessibleRole: no inner context!" );
807 if ( xNativeContext
.is() )
808 SetAccessibleRole( xNativeContext
->getAccessibleRole( ) );
812 //--------------------------------------------------------------------
813 sal_Bool
AccessibleControlShape::SetState( sal_Int16 _nState
)
815 OSL_ENSURE( !isAliveMode( m_xUnoControl
) || !isComposedState( _nState
),
816 "AccessibleControlShape::SetState: a state which should be determined by the control context is set from outside!" );
817 return AccessibleShape::SetState( _nState
);
821 //--------------------------------------------------------------------
822 void AccessibleControlShape::initializeComposedState()
824 if ( !isAliveMode( m_xUnoControl
) )
825 // no action necessary for design mode
828 // get our own state set implementation
829 ::utl::AccessibleStateSetHelper
* pComposedStates
=
830 static_cast< ::utl::AccessibleStateSetHelper
* >( mxStateSet
.get() );
831 OSL_PRECOND( pComposedStates
,
832 "AccessibleControlShape::initializeComposedState: no composed set!" );
834 // we need to reset some states of the composed set, because they either do not apply
835 // for controls in alive mode, or are in the responsibility of the UNO-control, anyway
836 pComposedStates
->RemoveState( AccessibleStateType::ENABLED
); // this is controlled by the UNO-control
837 pComposedStates
->RemoveState( AccessibleStateType::SENSITIVE
); // this is controlled by the UNO-control
838 pComposedStates
->RemoveState( AccessibleStateType::FOCUSABLE
); // this is controlled by the UNO-control
839 pComposedStates
->RemoveState( AccessibleStateType::SELECTABLE
); // this does not hold for an alive UNO-control
840 #if OSL_DEBUG_LEVEL > 0
841 // now, only states which are not in the responsibility of the UNO control should be part of this state set
843 Sequence
< sal_Int16
> aInitStates
= pComposedStates
->getStates();
844 for ( sal_Int32 i
=0; i
<aInitStates
.getLength(); ++i
)
845 OSL_ENSURE( !isComposedState( aInitStates
.getConstArray()[i
] ),
846 "AccessibleControlShape::initializeComposedState: invalid initial composed state (should be controlled by the UNO-control)!" );
850 // get my inner context
851 Reference
< XAccessibleContext
> xInnerContext( m_aControlContext
);
852 OSL_PRECOND( xInnerContext
.is(), "AccessibleControlShape::initializeComposedState: no inner context!" );
853 if ( xInnerContext
.is() )
855 // get all states of the inner context
856 Reference
< XAccessibleStateSet
> xInnerStates( xInnerContext
->getAccessibleStateSet() );
857 OSL_ENSURE( xInnerStates
.is(), "AccessibleControlShape::initializeComposedState: no inner states!" );
858 Sequence
< sal_Int16
> aInnerStates
;
859 if ( xInnerStates
.is() )
860 aInnerStates
= xInnerStates
->getStates();
862 // look which one are to be propagated to the composed context
863 const sal_Int16
* pStates
= aInnerStates
.getConstArray();
864 const sal_Int16
* pStatesEnd
= pStates
+ aInnerStates
.getLength();
865 for ( ; pStates
!= pStatesEnd
; ++pStates
)
867 if ( isComposedState( *pStates
) && !pComposedStates
->contains( *pStates
) )
869 pComposedStates
->AddState( *pStates
);
875 void SAL_CALL
AccessibleControlShape::elementInserted( const ::com::sun::star::container::ContainerEvent
& _rEvent
) throw (::com::sun::star::uno::RuntimeException
)
877 Reference
< XContainer
> xContainer( _rEvent
.Source
, UNO_QUERY
);
878 Reference
< XControl
> xControl( _rEvent
.Element
, UNO_QUERY
);
880 OSL_ENSURE( xContainer
.is() && xControl
.is(),
881 "AccessibleControlShape::elementInserted: invalid event description!" );
883 if ( !xControl
.is() )
886 ensureControlModelAccess();
888 Reference
< XInterface
> xNewNormalized( xControl
->getModel(), UNO_QUERY
);
889 Reference
< XInterface
> xMyModelNormalized( m_xControlModel
, UNO_QUERY
);
890 if ( xNewNormalized
.get() && xMyModelNormalized
.get() )
892 // now finally the control for the model we're responsible for has been inserted into the container
893 Reference
< XInterface
> xKeepAlive( *this );
895 // first, we're not interested in any more container events
896 if ( xContainer
.is() )
898 xContainer
->removeContainerListener( this );
899 m_bWaitingForControl
= sal_False
;
902 // second, we need to replace ourself with a new version, which now can be based on the
904 OSL_VERIFY( mpParent
->ReplaceChild ( this, mxShape
, mnIndex
, maShapeTreeInfo
) );
908 void SAL_CALL
AccessibleControlShape::elementRemoved( const ::com::sun::star::container::ContainerEvent
& ) throw (::com::sun::star::uno::RuntimeException
)
913 void SAL_CALL
AccessibleControlShape::elementReplaced( const ::com::sun::star::container::ContainerEvent
& ) throw (::com::sun::star::uno::RuntimeException
)
918 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */