1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/AccessibleControlShape.hxx>
21 #include <svx/AccessibleShapeInfo.hxx>
22 #include <svx/DescriptionGenerator.hxx>
23 #include <com/sun/star/awt/XWindow.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/drawing/XControlShape.hpp>
26 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
27 #include <com/sun/star/accessibility/AccessibleRole.hpp>
28 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
30 #include <com/sun/star/form/FormComponentType.hpp>
31 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
32 #include <com/sun/star/reflection/ProxyFactory.hpp>
33 #include <com/sun/star/util/XModeChangeBroadcaster.hpp>
34 #include <com/sun/star/container/XContainer.hpp>
35 #include <com/sun/star/container/XChild.hpp>
36 #include <comphelper/processfactory.hxx>
37 #include <comphelper/property.hxx>
38 #include <comphelper/types.hxx>
39 #include <unotools/accessiblestatesethelper.hxx>
40 #include <unotools/accessiblerelationsethelper.hxx>
41 #include <svx/IAccessibleParent.hxx>
42 #include <svx/svdouno.hxx>
43 #include <svx/unoapi.hxx>
44 #include <svx/ShapeTypeHandler.hxx>
45 #include <svx/SvxShapeTypes.hxx>
46 #include <comphelper/accessiblewrapper.hxx>
47 #include <svx/svdview.hxx>
48 #include <svx/svdpagv.hxx>
49 #include <svx/strings.hrc>
50 #include <vcl/svapp.hxx>
51 #include <sal/log.hxx>
52 #include <tools/debug.hxx>
55 using namespace ::accessibility
;
56 using namespace ::com::sun::star::accessibility
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::awt
;
59 using namespace ::com::sun::star::beans
;
60 using namespace ::com::sun::star::util
;
61 using namespace ::com::sun::star::lang
;
62 using namespace ::com::sun::star::reflection
;
63 using namespace ::com::sun::star::drawing
;
64 using namespace ::com::sun::star::container
;
68 OUString
lcl_getNamePropertyName( )
72 OUString
lcl_getDescPropertyName( )
76 OUString
lcl_getLabelPropertyName( )
80 OUString
lcl_getLabelControlPropertyName( )
82 return "LabelControl";
84 // return the property which should be used as AccessibleName
85 OUString
lcl_getPreferredAccNameProperty( const Reference
< XPropertySetInfo
>& _rxPSI
)
87 if ( _rxPSI
.is() && _rxPSI
->hasPropertyByName( lcl_getLabelPropertyName() ) )
88 return lcl_getLabelPropertyName();
90 return lcl_getNamePropertyName();
93 // determines whether or not a state which belongs to the inner context needs to be forwarded to the "composed"
95 bool isComposedState( const sal_Int16 _nState
)
97 return ( ( AccessibleStateType::INVALID
!= _nState
)
98 && ( AccessibleStateType::DEFUNC
!= _nState
)
99 && ( AccessibleStateType::ICONIFIED
!= _nState
)
100 && ( AccessibleStateType::RESIZABLE
!= _nState
)
101 && ( AccessibleStateType::SELECTABLE
!= _nState
)
102 && ( AccessibleStateType::SHOWING
!= _nState
)
103 && ( AccessibleStateType::MANAGES_DESCENDANTS
!= _nState
)
104 && ( AccessibleStateType::VISIBLE
!= _nState
)
108 /// determines whether the given control is in alive mode
109 bool isAliveMode( const Reference
< XControl
>& _rxControl
)
111 OSL_PRECOND( _rxControl
.is(), "AccessibleControlShape::isAliveMode: invalid control" );
112 return _rxControl
.is() && !_rxControl
->isDesignMode();
116 AccessibleControlShape::AccessibleControlShape (
117 const AccessibleShapeInfo
& rShapeInfo
,
118 const AccessibleShapeTreeInfo
& rShapeTreeInfo
)
119 : AccessibleShape (rShapeInfo
, rShapeTreeInfo
)
120 , m_bListeningForName( false )
121 , m_bListeningForDesc( false )
122 , m_bMultiplexingStates( false )
123 , m_bDisposeNativeContext( false )
124 , m_bWaitingForControl( false )
126 m_pChildManager
= new comphelper::OWrappedAccessibleChildrenManager( comphelper::getProcessComponentContext() );
128 osl_atomic_increment( &m_refCount
);
130 m_pChildManager
->setOwningAccessible( this );
132 osl_atomic_decrement( &m_refCount
);
135 AccessibleControlShape::~AccessibleControlShape()
137 m_pChildManager
.clear();
139 if ( m_xControlContextProxy
.is() )
140 m_xControlContextProxy
->setDelegator( nullptr );
141 m_xControlContextProxy
.clear();
142 m_xControlContextTypeAccess
.clear();
143 m_xControlContextComponent
.clear();
144 // this should remove the _only_ three "real" reference (means not delegated to
145 // ourself) to this proxy, and thus delete it
149 Reference
< XContainer
> lcl_getControlContainer( const OutputDevice
* _pWin
, const SdrView
* _pView
)
151 Reference
< XContainer
> xReturn
;
152 DBG_ASSERT( _pView
, "lcl_getControlContainer: invalid view!" );
153 if ( _pView
&& _pView
->GetSdrPageView())
155 xReturn
.set(_pView
->GetSdrPageView()->GetControlContainer( *_pWin
), css::uno::UNO_QUERY
);
161 void AccessibleControlShape::Init()
163 AccessibleShape::Init();
165 OSL_ENSURE( !m_xControlContextProxy
.is(), "AccessibleControlShape::Init: already initialized!" );
168 // What we need to do here is merge the functionality of the AccessibleContext of our UNO control
169 // with our own AccessibleContext-related functionality.
171 // The problem is that we do not know the interfaces our "inner" context supports - this may be any
172 // XAccessibleXXX interface (or even any other) which makes sense for it.
174 // In theory, we could implement all possible interfaces ourself, and re-route all functionality to
175 // the inner context (except those we implement ourself, like XAccessibleComponent). But this is in no
176 // way future-proof - as soon as an inner context appears which implements an additional interface,
177 // we would need to adjust our implementation to support this new interface, too. Bad idea.
179 // The usual solution for such a problem is aggregation. Aggregation means using UNO's own mechanism
180 // for merging an inner with an outer component, and get a component which behaves as it is exactly one.
181 // This is what XAggregation is for. Unfortunately, aggregation requires _exact_ control over the ref count
182 // of the inner object, which we do not have at all.
185 // But there is a solution: com.sun.star.reflection.ProxyFactory. This service is able to create a proxy
186 // for any component, which supports _exactly_ the same interfaces as the component. In addition, it can
187 // be aggregated, as by definition the proxy's ref count is exactly 1 when returned from the factory.
188 // Sounds better. Though this yields the problem of slightly degraded performance, it's the only solution
189 // I'm aware of at the moment...
191 // get the control which belongs to our model (relative to our view)
192 const OutputDevice
* pViewWindow
= maShapeTreeInfo
.GetDevice();
193 SdrUnoObj
* pUnoObjectImpl
= dynamic_cast<SdrUnoObj
*>( GetSdrObjectFromXShape(mxShape
) );
194 SdrView
* pView
= maShapeTreeInfo
.GetSdrView();
195 OSL_ENSURE( pView
&& pViewWindow
&& pUnoObjectImpl
, "AccessibleControlShape::Init: no view, or no view window, no SdrUnoObj!" );
197 if ( pView
&& pViewWindow
&& pUnoObjectImpl
)
199 // get the context of the control - it will be our "inner" context
200 m_xUnoControl
= pUnoObjectImpl
->GetUnoControl( *pView
, *pViewWindow
);
202 if ( !m_xUnoControl
.is() )
204 // the control has not yet been created. Though speaking strictly, it is a bug that
205 // our instance here is created without an existing control (because an AccessibleControlShape
206 // is a representation of a view object, and can only live if the view it should represent
207 // is complete, which implies a living control), it's by far the easiest and most riskless way
208 // to fix this here in this class.
209 // Okay, we will add as listener to the control container where we expect our control to appear.
210 OSL_ENSURE( !m_bWaitingForControl
, "AccessibleControlShape::Init: already waiting for the control!" );
212 Reference
< XContainer
> xControlContainer
= lcl_getControlContainer( pViewWindow
, maShapeTreeInfo
.GetSdrView() );
213 OSL_ENSURE( xControlContainer
.is(), "AccessibleControlShape::Init: unable to find my ControlContainer!" );
214 if ( xControlContainer
.is() )
216 xControlContainer
->addContainerListener( this );
217 m_bWaitingForControl
= true;
222 Reference
< XModeChangeBroadcaster
> xControlModes( m_xUnoControl
, UNO_QUERY
);
223 Reference
< XAccessible
> xControlAccessible( xControlModes
, UNO_QUERY
);
224 Reference
< XAccessibleContext
> xNativeControlContext
;
225 if ( xControlAccessible
.is() )
226 xNativeControlContext
= xControlAccessible
->getAccessibleContext();
227 OSL_ENSURE( xNativeControlContext
.is(), "AccessibleControlShape::Init: no AccessibleContext for the control!" );
228 m_aControlContext
= WeakReference
< XAccessibleContext
>( xNativeControlContext
);
230 // add as listener to the context - we want to multiplex some states
231 if ( isAliveMode( m_xUnoControl
) && xNativeControlContext
.is() )
232 { // (but only in alive mode)
233 startStateMultiplexing( );
236 // now that we have all information about our control, do some adjustments
237 adjustAccessibleRole();
238 initializeComposedState();
240 // some initialization for our child manager, which is used in alive mode only
241 if ( isAliveMode( m_xUnoControl
) )
243 Reference
< XAccessibleStateSet
> xStates( getAccessibleStateSet( ) );
244 OSL_ENSURE( xStates
.is(), "AccessibleControlShape::AccessibleControlShape: no inner state set!" );
245 m_pChildManager
->setTransientChildren( !xStates
.is() || xStates
->contains( AccessibleStateType::MANAGES_DESCENDANTS
) );
248 // finally, aggregate a proxy for the control context
249 // first a factory for the proxy
250 Reference
< XProxyFactory
> xFactory
= ProxyFactory::create( comphelper::getProcessComponentContext() );
251 // then the proxy itself
252 if ( xNativeControlContext
.is() )
254 m_xControlContextProxy
= xFactory
->createProxy( xNativeControlContext
);
255 m_xControlContextTypeAccess
.set( xNativeControlContext
, UNO_QUERY_THROW
);
256 m_xControlContextComponent
.set( xNativeControlContext
, UNO_QUERY_THROW
);
258 // aggregate the proxy
259 osl_atomic_increment( &m_refCount
);
260 if ( m_xControlContextProxy
.is() )
262 // At this point in time, the proxy has a ref count of exactly one - in m_xControlContextProxy.
263 // Remember to _not_ reset this member unless the delegator of the proxy has been reset, too!
264 m_xControlContextProxy
->setDelegator( *this );
266 osl_atomic_decrement( &m_refCount
);
268 m_bDisposeNativeContext
= true;
270 // Finally, we need to add ourself as mode listener to the control. In case the mode switches,
271 // we need to dispose ourself.
272 xControlModes
->addModeChangeListener( this );
277 catch( const Exception
& )
279 OSL_FAIL( "AccessibleControlShape::Init: could not \"aggregate\" the controls XAccessibleContext!" );
283 void SAL_CALL
AccessibleControlShape::grabFocus()
285 if ( !m_xUnoControl
.is() || !isAliveMode( m_xUnoControl
) )
287 // in design mode, we simply forward the request to the base class
288 AccessibleShape::grabFocus();
292 Reference
< XWindow
> xWindow( m_xUnoControl
, UNO_QUERY
);
293 OSL_ENSURE( xWindow
.is(), "AccessibleControlShape::grabFocus: invalid control!" );
299 OUString SAL_CALL
AccessibleControlShape::getImplementationName()
301 return "com.sun.star.comp.accessibility.AccessibleControlShape";
304 OUString
AccessibleControlShape::CreateAccessibleBaseName()
308 ShapeTypeId nShapeType
= ShapeTypeHandler::Instance().GetTypeId (mxShape
);
311 case DRAWING_CONTROL
:
312 sName
= "ControlShape";
315 sName
= "UnknownAccessibleControlShape";
317 sName
+= ": " + mxShape
->getShapeType();
324 AccessibleControlShape::CreateAccessibleDescription()
326 DescriptionGenerator
aDG (mxShape
);
327 ShapeTypeId nShapeType
= ShapeTypeHandler::Instance().GetTypeId (mxShape
);
330 case DRAWING_CONTROL
:
332 // check if we can obtain the "Desc" property from the model
333 OUString
sDesc( getControlModelStringProperty( lcl_getDescPropertyName() ) );
334 if ( sDesc
.isEmpty() )
335 { // no -> use the default
336 aDG
.Initialize (STR_ObjNameSingulUno
);
337 aDG
.AddProperty ("ControlBackground", DescriptionGenerator::PropertyType::Color
);
338 aDG
.AddProperty ( "ControlBorder", DescriptionGenerator::PropertyType::Integer
);
340 // ensure that we are listening to the Name property
341 m_bListeningForDesc
= ensureListeningState( m_bListeningForDesc
, true, lcl_getDescPropertyName() );
346 aDG
.Initialize ("Unknown accessible control shape");
349 aDG
.AppendString ("service name=");
350 aDG
.AppendString (mxShape
->getShapeType());
357 IMPLEMENT_FORWARD_REFCOUNT( AccessibleControlShape
, AccessibleShape
)
358 IMPLEMENT_GET_IMPLEMENTATION_ID( AccessibleControlShape
)
360 void SAL_CALL
AccessibleControlShape::propertyChange( const PropertyChangeEvent
& _rEvent
)
362 ::osl::MutexGuard
aGuard( maMutex
);
364 // check if it is the name or the description
365 if ( _rEvent
.PropertyName
== lcl_getNamePropertyName()
366 || _rEvent
.PropertyName
== lcl_getLabelPropertyName() )
369 CreateAccessibleName(),
370 AccessibleContextBase::AutomaticallyCreated
);
372 else if ( _rEvent
.PropertyName
== lcl_getDescPropertyName() )
374 SetAccessibleDescription(
375 CreateAccessibleDescription(),
376 AccessibleContextBase::AutomaticallyCreated
);
378 #if OSL_DEBUG_LEVEL > 0
381 OSL_FAIL( "AccessibleControlShape::propertyChange: where did this come from?" );
386 Any SAL_CALL
AccessibleControlShape::queryInterface( const Type
& _rType
)
388 Any aReturn
= AccessibleShape::queryInterface( _rType
);
389 if ( !aReturn
.hasValue() )
391 aReturn
= AccessibleControlShape_Base::queryInterface( _rType
);
392 if ( !aReturn
.hasValue() && m_xControlContextProxy
.is() )
393 aReturn
= m_xControlContextProxy
->queryAggregation( _rType
);
398 Sequence
< Type
> SAL_CALL
AccessibleControlShape::getTypes()
400 Sequence
< Type
> aShapeTypes
= AccessibleShape::getTypes();
401 Sequence
< Type
> aOwnTypes
= AccessibleControlShape_Base::getTypes();
403 Sequence
< Type
> aAggregateTypes
;
404 if ( m_xControlContextTypeAccess
.is() )
405 aAggregateTypes
= m_xControlContextTypeAccess
->getTypes();
408 return comphelper::combineSequences(comphelper::concatSequences( aShapeTypes
, aOwnTypes
), aAggregateTypes
);
411 void SAL_CALL
AccessibleControlShape::notifyEvent( const AccessibleEventObject
& _rEvent
)
413 if ( AccessibleEventId::STATE_CHANGED
== _rEvent
.EventId
)
415 // multiplex this change
416 sal_Int16
nLostState( 0 ), nGainedState( 0 );
417 _rEvent
.OldValue
>>= nLostState
;
418 _rEvent
.NewValue
>>= nGainedState
;
420 // don't multiplex states which the inner context is not responsible for
421 if ( isComposedState( nLostState
) )
422 AccessibleShape::ResetState( nLostState
);
424 if ( isComposedState( nGainedState
) )
425 AccessibleShape::SetState( nGainedState
);
429 AccessibleEventObject
aTranslatedEvent( _rEvent
);
432 ::osl::MutexGuard
aGuard( maMutex
);
434 // let the child manager translate the event
435 aTranslatedEvent
.Source
= *this;
436 m_pChildManager
->translateAccessibleEvent( _rEvent
, aTranslatedEvent
);
438 // see if any of these notifications affect our child manager
439 m_pChildManager
->handleChildNotification( _rEvent
);
442 FireEvent( aTranslatedEvent
);
446 void SAL_CALL
AccessibleControlShape::modeChanged(const ModeChangeEvent
& rSource
)
448 // did it come from our inner context (the real one, not it's proxy!)?
449 SAL_INFO("sw.uno", "AccessibleControlShape::modeChanged");
450 Reference
<XControl
> xSource(rSource
.Source
, UNO_QUERY
); // for faster compare
451 if(xSource
.get() != m_xUnoControl
.get())
453 SAL_WARN("sw.uno", "AccessibleControlShape::modeChanged: where did this come from?");
457 // If our "pseudo-aggregated" inner context does not live anymore,
458 // we don't want to live, too. This is accomplished by asking our
459 // parent to replace this object with a new one. Disposing this
460 // object and sending notifications about the replacement are in
461 // the responsibility of our parent.
462 const bool bReplaced
= mpParent
->ReplaceChild(this, mxShape
, 0, maShapeTreeInfo
);
463 SAL_WARN_IF(!bReplaced
, "sw.uno", "AccessibleControlShape::modeChanged: replacing ourselves away did fail");
466 void SAL_CALL
AccessibleControlShape::disposing (const EventObject
& _rSource
)
468 AccessibleShape::disposing( _rSource
);
471 bool AccessibleControlShape::ensureListeningState(
472 const bool _bCurrentlyListening
, const bool _bNeedNewListening
,
473 const OUString
& _rPropertyName
)
475 if ( ( _bCurrentlyListening
== _bNeedNewListening
) || !ensureControlModelAccess() )
477 return _bCurrentlyListening
;
481 if ( !m_xModelPropsMeta
.is() || m_xModelPropsMeta
->hasPropertyByName( _rPropertyName
) )
483 // add or revoke as listener
484 if ( _bNeedNewListening
)
485 m_xControlModel
->addPropertyChangeListener( _rPropertyName
, static_cast< XPropertyChangeListener
* >( this ) );
487 m_xControlModel
->removePropertyChangeListener( _rPropertyName
, static_cast< XPropertyChangeListener
* >( this ) );
490 OSL_FAIL( "AccessibleControlShape::ensureListeningState: this property does not exist at this model!" );
492 catch( const Exception
& )
494 OSL_FAIL( "AccessibleControlShape::ensureListeningState: could not change the listening state!" );
497 return _bNeedNewListening
;
500 sal_Int32 SAL_CALL
AccessibleControlShape::getAccessibleChildCount( )
502 if ( !m_xUnoControl
.is() )
504 else if ( !isAliveMode( m_xUnoControl
) )
505 // no special action required when in design mode
506 return AccessibleShape::getAccessibleChildCount( );
509 // in alive mode, we have the full control over our children - they are determined by the children
510 // of the context of our UNO control
511 Reference
< XAccessibleContext
> xControlContext( m_aControlContext
);
512 OSL_ENSURE( xControlContext
.is(), "AccessibleControlShape::getAccessibleChildCount: control context already dead! How this!" );
513 return xControlContext
.is() ? xControlContext
->getAccessibleChildCount() : 0;
517 Reference
< XAccessible
> SAL_CALL
AccessibleControlShape::getAccessibleChild( sal_Int32 i
)
519 Reference
< XAccessible
> xChild
;
520 if ( !m_xUnoControl
.is() )
522 throw IndexOutOfBoundsException();
524 if ( !isAliveMode( m_xUnoControl
) )
526 // no special action required when in design mode - let the base class handle this
527 xChild
= AccessibleShape::getAccessibleChild( i
);
531 // in alive mode, we have the full control over our children - they are determined by the children
532 // of the context of our UNO control
534 Reference
< XAccessibleContext
> xControlContext( m_aControlContext
);
535 OSL_ENSURE( xControlContext
.is(), "AccessibleControlShape::getAccessibleChildCount: control context already dead! How this!" );
536 if ( xControlContext
.is() )
538 Reference
< XAccessible
> xInnerChild( xControlContext
->getAccessibleChild( i
) );
539 OSL_ENSURE( xInnerChild
.is(), "AccessibleControlShape::getAccessibleChild: control context returned nonsense!" );
540 if ( xInnerChild
.is() )
542 // we need to wrap this inner child into an own implementation
543 xChild
= m_pChildManager
->getAccessibleWrapperFor( xInnerChild
);
548 #if OSL_DEBUG_LEVEL > 0
549 sal_Int32 nChildIndex
= -1;
550 Reference
< XAccessibleContext
> xContext
;
552 xContext
= xChild
->getAccessibleContext( );
554 nChildIndex
= xContext
->getAccessibleIndexInParent( );
555 SAL_WARN_IF( nChildIndex
!= i
, "svx", "AccessibleControlShape::getAccessibleChild: index mismatch,"
556 " nChildIndex=" << nChildIndex
<< " vs i=" << i
);
561 Reference
< XAccessibleRelationSet
> SAL_CALL
AccessibleControlShape::getAccessibleRelationSet( )
563 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
564 ensureControlModelAccess();
565 AccessibleControlShape
* pCtlAccShape
= GetLabeledByControlShape();
568 Reference
< XAccessible
> xAcc (pCtlAccShape
->getAccessibleContext(), UNO_QUERY
);
570 css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> > aSequence
{ xAcc
};
571 if( getAccessibleRole() == AccessibleRole::RADIO_BUTTON
)
573 pRelationSetHelper
->AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF
, aSequence
) );
577 pRelationSetHelper
->AddRelation( AccessibleRelation( AccessibleRelationType::LABELED_BY
, aSequence
) );
580 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
584 OUString
AccessibleControlShape::CreateAccessibleName()
586 ensureControlModelAccess();
589 sal_Int16 aAccessibleRole
= getAccessibleRole();
590 if ( aAccessibleRole
!= AccessibleRole::SHAPE
591 && aAccessibleRole
!= AccessibleRole::RADIO_BUTTON
)
593 AccessibleControlShape
* pCtlAccShape
= GetLabeledByControlShape();
596 sName
= pCtlAccShape
->CreateAccessibleName();
602 // check if we can obtain the "Name" resp. "Label" property from the model
603 const OUString
& rAccNameProperty
= lcl_getPreferredAccNameProperty( m_xModelPropsMeta
);
604 sName
= getControlModelStringProperty( rAccNameProperty
);
605 if ( !sName
.getLength() )
606 { // no -> use the default
607 sName
= AccessibleShape::CreateAccessibleName();
611 // now that somebody first asked us for our name, ensure that we are listening to name changes on the model
612 m_bListeningForName
= ensureListeningState( m_bListeningForName
, true, lcl_getPreferredAccNameProperty( m_xModelPropsMeta
) );
617 void SAL_CALL
AccessibleControlShape::disposing()
619 // ensure we're not listening
620 m_bListeningForName
= ensureListeningState( m_bListeningForName
, false, lcl_getPreferredAccNameProperty( m_xModelPropsMeta
) );
621 m_bListeningForDesc
= ensureListeningState( m_bListeningForDesc
, false, lcl_getDescPropertyName() );
623 if ( m_bMultiplexingStates
)
624 stopStateMultiplexing( );
626 // dispose the child cache/map
627 m_pChildManager
->dispose();
630 m_xControlModel
.clear();
631 m_xModelPropsMeta
.clear();
632 m_aControlContext
= WeakReference
< XAccessibleContext
>();
634 // stop listening at the control container (should never be necessary here, but who knows...)
635 if ( m_bWaitingForControl
)
637 OSL_FAIL( "AccessibleControlShape::disposing: this should never happen!" );
638 Reference
< XContainer
> xContainer
= lcl_getControlContainer( maShapeTreeInfo
.GetDevice(), maShapeTreeInfo
.GetSdrView() );
639 if ( xContainer
.is() )
641 m_bWaitingForControl
= false;
642 xContainer
->removeContainerListener( this );
646 // forward the disposal to our inner context
647 if ( m_bDisposeNativeContext
)
649 // don't listen for mode changes anymore
650 Reference
< XModeChangeBroadcaster
> xControlModes( m_xUnoControl
, UNO_QUERY
);
651 OSL_ENSURE( xControlModes
.is(), "AccessibleControlShape::disposing: don't have a mode broadcaster anymore!" );
652 if ( xControlModes
.is() )
653 xControlModes
->removeModeChangeListener( this );
655 if ( m_xControlContextComponent
.is() )
656 m_xControlContextComponent
->dispose();
657 // do _not_ clear m_xControlContextProxy! This has to be done in the dtor for correct ref-count handling
659 // no need to dispose the proxy/inner context anymore
660 m_bDisposeNativeContext
= false;
663 m_xUnoControl
.clear();
665 // let the base do its stuff
666 AccessibleShape::disposing();
669 bool AccessibleControlShape::ensureControlModelAccess()
671 if ( m_xControlModel
.is() )
676 Reference
< XControlShape
> xShape( mxShape
, UNO_QUERY
);
678 m_xControlModel
.set(xShape
->getControl(), css::uno::UNO_QUERY
);
680 if ( m_xControlModel
.is() )
681 m_xModelPropsMeta
= m_xControlModel
->getPropertySetInfo();
683 catch( const Exception
& )
685 OSL_FAIL( "AccessibleControlShape::ensureControlModelAccess: caught an exception!" );
688 return m_xControlModel
.is();
691 void AccessibleControlShape::startStateMultiplexing()
693 OSL_PRECOND( !m_bMultiplexingStates
, "AccessibleControlShape::startStateMultiplexing: already multiplexing!" );
695 #if OSL_DEBUG_LEVEL > 0
696 // we should have a control, and it should be in alive mode
697 OSL_PRECOND( isAliveMode( m_xUnoControl
),
698 "AccessibleControlShape::startStateMultiplexing: should be done in alive mode only!" );
700 // we should have the native context of the control
701 Reference
< XAccessibleEventBroadcaster
> xBroadcaster( m_aControlContext
.get(), UNO_QUERY
);
702 OSL_ENSURE( xBroadcaster
.is(), "AccessibleControlShape::startStateMultiplexing: no AccessibleEventBroadcaster on the native context!" );
704 if ( xBroadcaster
.is() )
706 xBroadcaster
->addAccessibleEventListener( this );
707 m_bMultiplexingStates
= true;
711 void AccessibleControlShape::stopStateMultiplexing()
713 OSL_PRECOND( m_bMultiplexingStates
, "AccessibleControlShape::stopStateMultiplexing: not multiplexing!" );
715 // we should have the native context of the control
716 Reference
< XAccessibleEventBroadcaster
> xBroadcaster( m_aControlContext
.get(), UNO_QUERY
);
717 OSL_ENSURE( xBroadcaster
.is(), "AccessibleControlShape::stopStateMultiplexing: no AccessibleEventBroadcaster on the native context!" );
719 if ( xBroadcaster
.is() )
721 xBroadcaster
->removeAccessibleEventListener( this );
722 m_bMultiplexingStates
= false;
726 OUString
AccessibleControlShape::getControlModelStringProperty( const OUString
& _rPropertyName
) const
731 if ( const_cast< AccessibleControlShape
* >( this )->ensureControlModelAccess() )
733 if ( !m_xModelPropsMeta
.is() || m_xModelPropsMeta
->hasPropertyByName( _rPropertyName
) )
734 // ask only if a) the control does not have a PropertySetInfo object or b) it has, and the
735 // property in question is available
736 m_xControlModel
->getPropertyValue( _rPropertyName
) >>= sReturn
;
739 catch( const Exception
& )
741 OSL_FAIL( "OAccessibleControlContext::getModelStringProperty: caught an exception!" );
746 void AccessibleControlShape::adjustAccessibleRole( )
748 // if we're in design mode, we are a simple SHAPE, in alive mode, we use the role of our inner context
749 if ( !isAliveMode( m_xUnoControl
) )
752 // we're in alive mode -> determine the role of the inner context
753 Reference
< XAccessibleContext
> xNativeContext( m_aControlContext
);
754 OSL_PRECOND( xNativeContext
.is(), "AccessibleControlShape::adjustAccessibleRole: no inner context!" );
755 if ( xNativeContext
.is() )
756 SetAccessibleRole( xNativeContext
->getAccessibleRole( ) );
761 bool AccessibleControlShape::SetState( sal_Int16 _nState
)
763 OSL_ENSURE( !isAliveMode( m_xUnoControl
) || !isComposedState( _nState
),
764 "AccessibleControlShape::SetState: a state which should be determined by the control context is set from outside!" );
765 return AccessibleShape::SetState( _nState
);
769 void AccessibleControlShape::initializeComposedState()
771 if ( !isAliveMode( m_xUnoControl
) )
772 // no action necessary for design mode
775 // get our own state set implementation
776 ::utl::AccessibleStateSetHelper
* pComposedStates
=
777 static_cast< ::utl::AccessibleStateSetHelper
* >( mxStateSet
.get() );
778 OSL_PRECOND( pComposedStates
,
779 "AccessibleControlShape::initializeComposedState: no composed set!" );
781 // we need to reset some states of the composed set, because they either do not apply
782 // for controls in alive mode, or are in the responsibility of the UNO-control, anyway
783 pComposedStates
->RemoveState( AccessibleStateType::ENABLED
); // this is controlled by the UNO-control
784 pComposedStates
->RemoveState( AccessibleStateType::SENSITIVE
); // this is controlled by the UNO-control
785 pComposedStates
->RemoveState( AccessibleStateType::FOCUSABLE
); // this is controlled by the UNO-control
786 pComposedStates
->RemoveState( AccessibleStateType::SELECTABLE
); // this does not hold for an alive UNO-control
787 #if OSL_DEBUG_LEVEL > 0
788 // now, only states which are not in the responsibility of the UNO control should be part of this state set
790 Sequence
< sal_Int16
> aInitStates
= pComposedStates
->getStates();
791 for ( sal_Int32 i
=0; i
<aInitStates
.getLength(); ++i
)
792 OSL_ENSURE( !isComposedState( aInitStates
.getConstArray()[i
] ),
793 "AccessibleControlShape::initializeComposedState: invalid initial composed state (should be controlled by the UNO-control)!" );
797 // get my inner context
798 Reference
< XAccessibleContext
> xInnerContext( m_aControlContext
);
799 OSL_PRECOND( xInnerContext
.is(), "AccessibleControlShape::initializeComposedState: no inner context!" );
800 if ( xInnerContext
.is() )
802 // get all states of the inner context
803 Reference
< XAccessibleStateSet
> xInnerStates( xInnerContext
->getAccessibleStateSet() );
804 OSL_ENSURE( xInnerStates
.is(), "AccessibleControlShape::initializeComposedState: no inner states!" );
805 Sequence
< sal_Int16
> aInnerStates
;
806 if ( xInnerStates
.is() )
807 aInnerStates
= xInnerStates
->getStates();
809 // look which one are to be propagated to the composed context
810 for ( const sal_Int16 nState
: aInnerStates
)
812 if ( isComposedState( nState
) && !pComposedStates
->contains( nState
) )
814 pComposedStates
->AddState( nState
);
820 void SAL_CALL
AccessibleControlShape::elementInserted( const css::container::ContainerEvent
& _rEvent
)
822 Reference
< XContainer
> xContainer( _rEvent
.Source
, UNO_QUERY
);
823 Reference
< XControl
> xControl( _rEvent
.Element
, UNO_QUERY
);
825 OSL_ENSURE( xContainer
.is() && xControl
.is(),
826 "AccessibleControlShape::elementInserted: invalid event description!" );
828 if ( !xControl
.is() )
831 ensureControlModelAccess();
833 Reference
< XInterface
> xNewNormalized( xControl
->getModel(), UNO_QUERY
);
834 Reference
< XInterface
> xMyModelNormalized( m_xControlModel
, UNO_QUERY
);
835 if ( xNewNormalized
.get() && xMyModelNormalized
.get() )
837 // now finally the control for the model we're responsible for has been inserted into the container
838 Reference
< XInterface
> xKeepAlive( *this );
840 // first, we're not interested in any more container events
841 if ( xContainer
.is() )
843 xContainer
->removeContainerListener( this );
844 m_bWaitingForControl
= false;
847 // second, we need to replace ourself with a new version, which now can be based on the
849 OSL_VERIFY( mpParent
->ReplaceChild ( this, mxShape
, 0, maShapeTreeInfo
) );
853 void SAL_CALL
AccessibleControlShape::elementRemoved( const css::container::ContainerEvent
& )
858 void SAL_CALL
AccessibleControlShape::elementReplaced( const css::container::ContainerEvent
& )
863 AccessibleControlShape
* AccessibleControlShape::GetLabeledByControlShape( )
865 if(m_xControlModel
.is())
867 const OUString
& rAccLabelControlProperty
= lcl_getLabelControlPropertyName();
869 // get the "label by" property value of the control
870 if (::comphelper::hasProperty(rAccLabelControlProperty
, m_xControlModel
))
872 sCtlLabelBy
= m_xControlModel
->getPropertyValue(rAccLabelControlProperty
);
873 if( sCtlLabelBy
.hasValue() )
875 Reference
< XPropertySet
> xAsSet (sCtlLabelBy
, UNO_QUERY
);
876 AccessibleControlShape
* pCtlAccShape
= mpParent
->GetAccControlShapeFromModel(xAsSet
.get());
884 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */