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/drawing/XControlShape.hpp>
24 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
25 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <com/sun/star/form/FormComponentType.hpp>
28 #include <com/sun/star/reflection/ProxyFactory.hpp>
29 #include <com/sun/star/container/XContainer.hpp>
30 #include <com/sun/star/container/XChild.hpp>
31 #include <comphelper/processfactory.hxx>
32 #include <comphelper/property.hxx>
33 #include <comphelper/types.hxx>
34 #include <unotools/accessiblestatesethelper.hxx>
35 #include <unotools/accessiblerelationsethelper.hxx>
36 #include <svx/svdouno.hxx>
37 #include "svx/unoapi.hxx"
38 #include <svx/ShapeTypeHandler.hxx>
39 #include <svx/SvxShapeTypes.hxx>
40 #include <toolkit/helper/vclunohelper.hxx>
41 #include <comphelper/accessiblewrapper.hxx>
42 #include <svx/svdview.hxx>
43 #include <svx/svdpagv.hxx>
44 #include "svx/svdstr.hrc"
47 using namespace ::accessibility
;
48 using namespace ::com::sun::star::accessibility
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::awt
;
51 using namespace ::com::sun::star::beans
;
52 using namespace ::com::sun::star::util
;
53 using namespace ::com::sun::star::lang
;
54 using namespace ::com::sun::star::reflection
;
55 using namespace ::com::sun::star::drawing
;
56 using namespace ::com::sun::star::container
;
60 static OUString
lcl_getNamePropertyName( )
62 return OUString( "Name" );
64 static OUString
lcl_getDescPropertyName( )
66 return OUString( "HelpText" );
68 static OUString
lcl_getLabelPropertyName( )
70 return OUString( "Label" );
72 static OUString
lcl_getLabelControlPropertyName( )
74 return OUString("LabelControl");
76 // return the property which should be used as AccessibleName
77 const OUString
lcl_getPreferredAccNameProperty( const Reference
< XPropertySetInfo
>& _rxPSI
)
79 if ( _rxPSI
.is() && _rxPSI
->hasPropertyByName( lcl_getLabelPropertyName() ) )
80 return lcl_getLabelPropertyName();
82 return lcl_getNamePropertyName();
85 // determines whether or not a state which belongs to the inner context needs to be forwarded to the "composed"
87 bool isComposedState( const sal_Int16 _nState
)
89 return ( ( AccessibleStateType::INVALID
!= _nState
)
90 && ( AccessibleStateType::DEFUNC
!= _nState
)
91 && ( AccessibleStateType::ICONIFIED
!= _nState
)
92 && ( AccessibleStateType::RESIZABLE
!= _nState
)
93 && ( AccessibleStateType::SELECTABLE
!= _nState
)
94 && ( AccessibleStateType::SHOWING
!= _nState
)
95 && ( AccessibleStateType::MANAGES_DESCENDANTS
!= _nState
)
96 && ( AccessibleStateType::VISIBLE
!= _nState
)
100 /// determines whether the given control is in alive mode
101 inline bool isAliveMode( const Reference
< XControl
>& _rxControl
)
103 OSL_PRECOND( _rxControl
.is(), "AccessibleControlShape::isAliveMode: invalid control" );
104 return _rxControl
.is() && !_rxControl
->isDesignMode();
108 AccessibleControlShape::AccessibleControlShape (
109 const AccessibleShapeInfo
& rShapeInfo
,
110 const AccessibleShapeTreeInfo
& rShapeTreeInfo
)
111 : AccessibleShape (rShapeInfo
, rShapeTreeInfo
)
112 , m_bListeningForName( false )
113 , m_bListeningForDesc( false )
114 , m_bMultiplexingStates( false )
115 , m_bDisposeNativeContext( false )
116 , m_bWaitingForControl( false )
118 m_pChildManager
= new comphelper::OWrappedAccessibleChildrenManager( comphelper::getProcessComponentContext() );
119 m_pChildManager
->acquire();
121 osl_atomic_increment( &m_refCount
);
123 m_pChildManager
->setOwningAccessible( this );
125 osl_atomic_decrement( &m_refCount
);
128 AccessibleControlShape::~AccessibleControlShape()
130 m_pChildManager
->release();
131 m_pChildManager
= NULL
;
133 if ( m_xControlContextProxy
.is() )
134 m_xControlContextProxy
->setDelegator( NULL
);
135 m_xControlContextProxy
.clear();
136 m_xControlContextTypeAccess
.clear();
137 m_xControlContextComponent
.clear();
138 // this should remove the _only_ three "real" reference (means not delegated to
139 // ourself) to this proxy, and thus delete it
142 SdrObject
* AccessibleControlShape::getSdrObject() const
144 return GetSdrObjectFromXShape (mxShape
);
148 Reference
< XContainer
> lcl_getControlContainer( const vcl::Window
* _pWin
, const SdrView
* _pView
)
150 Reference
< XContainer
> xReturn
;
151 DBG_ASSERT( _pView
, "lcl_getControlContainer: invalid view!" );
152 if ( _pView
&& _pView
->GetSdrPageView())
154 xReturn
.set(_pView
->GetSdrPageView()->GetControlContainer( *_pWin
), css::uno::UNO_QUERY
);
160 void AccessibleControlShape::Init()
162 AccessibleShape::Init();
164 OSL_ENSURE( !m_xControlContextProxy
.is(), "AccessibleControlShape::Init: already initialized!" );
167 // What we need to do here is merge the functionality of the AccessibleContext of our UNO control
168 // with our own AccessibleContext-related functionality.
170 // The problem is that we do not know the interfaces our "inner" context supports - this may be any
171 // XAccessibleXXX interface (or even any other) which makes sense for it.
173 // In theory, we could implement all possible interfaces ourself, and re-route all functionality to
174 // the inner context (except those we implement ourself, like XAccessibleComponent). But this is in no
175 // way future-proof - as soon as an inner context appears which implements an additional interface,
176 // we would need to adjust our implementation to support this new interface, too. Bad idea.
178 // The usual solution for such a problem is aggregation. Aggregation means using UNO's own meachnisms
179 // for merging an inner with an outer component, and get a component which behaves as it is exactly one.
180 // This is what XAggregation is for. Unfortunately, aggregation requires _exact_ control over the ref count
181 // of the inner object, which we do not have at all.
184 // But there is a solution: com.sun.star.reflection.ProxyFactory. This service is able to create a proxy
185 // for any component, which supports _exactly_ the same interfaces as the component. In addition, it can
186 // be aggregated, as by definition the proxy's ref count is exactly 1 when returned from the factory.
187 // Sounds better. Though this yields the problem of slightly degraded performance, it's the only solution
188 // I'm aware of at the moment .....
190 // get the control which belongs to our model (relative to our view)
191 const vcl::Window
* pViewWindow
= maShapeTreeInfo
.GetWindow();
192 SdrUnoObj
* pUnoObjectImpl
= PTR_CAST( SdrUnoObj
, getSdrObject() );
193 SdrView
* pView
= maShapeTreeInfo
.GetSdrView();
194 OSL_ENSURE( pView
&& pViewWindow
&& pUnoObjectImpl
, "AccessibleControlShape::Init: no view, or no view window, no SdrUnoObj!" );
196 if ( pView
&& pViewWindow
&& pUnoObjectImpl
)
198 // get the context of the control - it will be our "inner" context
199 m_xUnoControl
= pUnoObjectImpl
->GetUnoControl( *pView
, *pViewWindow
);
201 if ( !m_xUnoControl
.is() )
203 // the control has not yet been created. Though speaking strictly, it is a bug that
204 // our instance here is created without an existing control (because an AccessibleControlShape
205 // is a representation of a view object, and can only live if the view it should represent
206 // is complete, which implies a living control), it's by far the easiest and most riskless way
207 // to fix this here in this class.
208 // Okay, we will add as listener to the control container where we expect our control to appear.
209 OSL_ENSURE( !m_bWaitingForControl
, "AccessibleControlShape::Init: already waiting for the control!" );
211 Reference
< XContainer
> xControlContainer
= lcl_getControlContainer( pViewWindow
, maShapeTreeInfo
.GetSdrView() );
212 OSL_ENSURE( xControlContainer
.is(), "AccessibleControlShape::Init: unable to find my ControlContainer!" );
213 if ( xControlContainer
.is() )
215 xControlContainer
->addContainerListener( this );
216 m_bWaitingForControl
= true;
221 Reference
< XModeChangeBroadcaster
> xControlModes( m_xUnoControl
, UNO_QUERY
);
222 Reference
< XAccessible
> xControlAccessible( xControlModes
, UNO_QUERY
);
223 Reference
< XAccessibleContext
> xNativeControlContext
;
224 if ( xControlAccessible
.is() )
225 xNativeControlContext
= xControlAccessible
->getAccessibleContext();
226 OSL_ENSURE( xNativeControlContext
.is(), "AccessibleControlShape::Init: no AccessibleContext for the control!" );
227 m_aControlContext
= WeakReference
< XAccessibleContext
>( xNativeControlContext
);
229 // add as listener to the context - we want to multiplex some states
230 if ( isAliveMode( m_xUnoControl
) && xNativeControlContext
.is() )
231 { // (but only in alive mode)
232 startStateMultiplexing( );
235 // now that we have all information about our control, do some adjustments
236 adjustAccessibleRole();
237 initializeComposedState();
239 // some initialization for our child manager, which is used in alive mode only
240 if ( isAliveMode( m_xUnoControl
) )
242 Reference
< XAccessibleStateSet
> xStates( getAccessibleStateSet( ) );
243 OSL_ENSURE( xStates
.is(), "AccessibleControlShape::AccessibleControlShape: no inner state set!" );
244 m_pChildManager
->setTransientChildren( !xStates
.is() || xStates
->contains( AccessibleStateType::MANAGES_DESCENDANTS
) );
247 // finally, aggregate a proxy for the control context
248 // first a factory for the proxy
249 Reference
< XProxyFactory
> xFactory
= ProxyFactory::create( comphelper::getProcessComponentContext() );
250 // then the proxy itself
251 if ( xNativeControlContext
.is() )
253 m_xControlContextProxy
= xFactory
->createProxy( xNativeControlContext
);
254 m_xControlContextTypeAccess
.set( xNativeControlContext
, UNO_QUERY_THROW
);
255 m_xControlContextComponent
.set( xNativeControlContext
, UNO_QUERY_THROW
);
257 // aggregate the proxy
258 osl_atomic_increment( &m_refCount
);
259 if ( m_xControlContextProxy
.is() )
261 // At this point in time, the proxy has a ref count of exactly one - in m_xControlContextProxy.
262 // Remember to _not_ reset this member unles the delegator of the proxy has been reset, too!
263 m_xControlContextProxy
->setDelegator( *this );
265 osl_atomic_decrement( &m_refCount
);
267 m_bDisposeNativeContext
= true;
269 // Finally, we need to add ourself as mode listener to the control. In case the mode switches,
270 // we need to dispose ourself.
271 xControlModes
->addModeChangeListener( this );
276 catch( const Exception
& )
278 OSL_FAIL( "AccessibleControlShape::Init: could not \"aggregate\" the controls XAccessibleContext!" );
282 Reference
< XAccessibleContext
> SAL_CALL
AccessibleControlShape::getAccessibleContext() throw (RuntimeException
, std::exception
)
284 return AccessibleShape::getAccessibleContext ();
287 void SAL_CALL
AccessibleControlShape::grabFocus() throw (RuntimeException
, std::exception
)
289 if ( !m_xUnoControl
.is() || !isAliveMode( m_xUnoControl
) )
291 // in design mode, we simply forward the request to the base class
292 AccessibleShape::grabFocus();
296 Reference
< XWindow
> xWindow( m_xUnoControl
, UNO_QUERY
);
297 OSL_ENSURE( xWindow
.is(), "AccessibleControlShape::grabFocus: invalid control!" );
303 OUString SAL_CALL
AccessibleControlShape::getImplementationName() throw (RuntimeException
, std::exception
)
305 return OUString( "com.sun.star.comp.accessibility.AccessibleControlShape" );
308 OUString
AccessibleControlShape::CreateAccessibleBaseName() throw (RuntimeException
)
312 ShapeTypeId nShapeType
= ShapeTypeHandler::Instance().GetTypeId (mxShape
);
315 case DRAWING_CONTROL
:
316 sName
= "ControlShape";
319 sName
= "UnknownAccessibleControlShape";
320 Reference
< XShapeDescriptor
> xDescriptor (mxShape
, UNO_QUERY
);
321 if (xDescriptor
.is())
322 sName
+= ": " + xDescriptor
->getShapeType();
332 AccessibleControlShape::CreateAccessibleDescription()
333 throw (RuntimeException
)
335 DescriptionGenerator
aDG (mxShape
);
336 ShapeTypeId nShapeType
= ShapeTypeHandler::Instance().GetTypeId (mxShape
);
339 case DRAWING_CONTROL
:
341 // check if we can obtain the "Desc" property from the model
342 OUString
sDesc( getControlModelStringProperty( lcl_getDescPropertyName() ) );
343 if ( sDesc
.isEmpty() )
344 { // no -> use the default
345 aDG
.Initialize (STR_ObjNameSingulUno
);
346 aDG
.AddProperty ("ControlBackground", DescriptionGenerator::COLOR
, "");
347 aDG
.AddProperty ( "ControlBorder", DescriptionGenerator::INTEGER
, "");
349 // ensure that we are listening to the Name property
350 m_bListeningForDesc
= ensureListeningState( m_bListeningForDesc
, true, lcl_getDescPropertyName() );
355 aDG
.Initialize ("Unknown accessible control shape");
356 Reference
< XShapeDescriptor
> xDescriptor (mxShape
, UNO_QUERY
);
357 if (xDescriptor
.is())
359 aDG
.AppendString ("service name=");
360 aDG
.AppendString (xDescriptor
->getShapeType());
367 IMPLEMENT_FORWARD_REFCOUNT( AccessibleControlShape
, AccessibleShape
)
368 IMPLEMENT_GET_IMPLEMENTATION_ID( AccessibleControlShape
)
370 void SAL_CALL
AccessibleControlShape::propertyChange( const PropertyChangeEvent
& _rEvent
) throw (RuntimeException
, std::exception
)
372 ::osl::MutexGuard
aGuard( maMutex
);
374 // check if it is the name or the description
375 if ( _rEvent
.PropertyName
== lcl_getNamePropertyName()
376 || _rEvent
.PropertyName
== lcl_getLabelPropertyName() )
379 CreateAccessibleName(),
380 AccessibleContextBase::AutomaticallyCreated
);
382 else if ( _rEvent
.PropertyName
== lcl_getDescPropertyName() )
384 SetAccessibleDescription(
385 CreateAccessibleDescription(),
386 AccessibleContextBase::AutomaticallyCreated
);
388 #if OSL_DEBUG_LEVEL > 0
391 OSL_FAIL( "AccessibleControlShape::propertyChange: where did this come from?" );
396 Any SAL_CALL
AccessibleControlShape::queryInterface( const Type
& _rType
) throw (RuntimeException
, std::exception
)
398 Any aReturn
= AccessibleShape::queryInterface( _rType
);
399 if ( !aReturn
.hasValue() )
401 aReturn
= AccessibleControlShape_Base::queryInterface( _rType
);
402 if ( !aReturn
.hasValue() && m_xControlContextProxy
.is() )
403 aReturn
= m_xControlContextProxy
->queryAggregation( _rType
);
408 Sequence
< Type
> SAL_CALL
AccessibleControlShape::getTypes() throw (RuntimeException
, std::exception
)
410 Sequence
< Type
> aShapeTypes
= AccessibleShape::getTypes();
411 Sequence
< Type
> aOwnTypes
= AccessibleControlShape_Base::getTypes();
413 Sequence
< Type
> aAggregateTypes
;
414 if ( m_xControlContextTypeAccess
.is() )
415 aAggregateTypes
= m_xControlContextTypeAccess
->getTypes();
417 Sequence
< Type
> aAllTypes
= comphelper::concatSequences( aShapeTypes
, aOwnTypes
, aAggregateTypes
);
420 Type
* pBegin
= aAllTypes
.getArray();
421 Type
* pEnd
= pBegin
+ aAllTypes
.getLength();
422 while ( pBegin
!= pEnd
)
424 Type aThisRoundType
= *pBegin
;
425 if ( ++pBegin
!= pEnd
)
427 pEnd
= ::std::remove( pBegin
, pEnd
, aThisRoundType
);
428 // now all types between begin and (the old) end which equal aThisRoundType
429 // are moved behind the new end
432 aAllTypes
.realloc( pEnd
- aAllTypes
.getArray() );
437 void SAL_CALL
AccessibleControlShape::notifyEvent( const AccessibleEventObject
& _rEvent
) throw (RuntimeException
, std::exception
)
439 if ( AccessibleEventId::STATE_CHANGED
== _rEvent
.EventId
)
441 // multiplex this change
442 sal_Int16
nLostState( 0 ), nGainedState( 0 );
443 _rEvent
.OldValue
>>= nLostState
;
444 _rEvent
.NewValue
>>= nGainedState
;
446 // don't multiplex states which the inner context is not resposible for
447 if ( isComposedState( nLostState
) )
448 AccessibleShape::ResetState( nLostState
);
450 if ( isComposedState( nGainedState
) )
451 AccessibleShape::SetState( nGainedState
);
455 AccessibleEventObject
aTranslatedEvent( _rEvent
);
458 ::osl::MutexGuard
aGuard( maMutex
);
460 // let the child manager translate the event
461 aTranslatedEvent
.Source
= *this;
462 m_pChildManager
->translateAccessibleEvent( _rEvent
, aTranslatedEvent
);
464 // see if any of these notifications affect our child manager
465 m_pChildManager
->handleChildNotification( _rEvent
);
468 FireEvent( aTranslatedEvent
);
472 void SAL_CALL
AccessibleControlShape::modeChanged( const ModeChangeEvent
& _rSource
) throw (RuntimeException
, std::exception
)
474 // did it come from our inner context (the real one, not it's proxy!)?
475 OSL_TRACE ("AccessibleControlShape::modeChanged");
476 Reference
< XControl
> xSource( _rSource
.Source
, UNO_QUERY
); // for faster compare
477 if ( xSource
.get() == m_xUnoControl
.get() )
479 // If our "pseudo-aggregated" inner context does not live anymore,
480 // we don't want to live, too. This is accomplished by asking our
481 // parent to replace this object with a new one. Disposing this
482 // object and sending notifications about the replacement are in
483 // the responsibility of our parent.
484 OSL_VERIFY( mpParent
->ReplaceChild ( this, mxShape
, mnIndex
, maShapeTreeInfo
) );
486 #if OSL_DEBUG_LEVEL > 0
488 OSL_FAIL( "AccessibleControlShape::modeChanged: where did this come from?" );
492 void SAL_CALL
AccessibleControlShape::disposing (const EventObject
& _rSource
) throw (RuntimeException
, std::exception
)
494 AccessibleShape::disposing( _rSource
);
497 bool AccessibleControlShape::ensureListeningState(
498 const bool _bCurrentlyListening
, const bool _bNeedNewListening
,
499 const OUString
& _rPropertyName
)
501 if ( ( _bCurrentlyListening
== _bNeedNewListening
) || !ensureControlModelAccess() )
503 return _bCurrentlyListening
;
507 if ( !m_xModelPropsMeta
.is() || m_xModelPropsMeta
->hasPropertyByName( _rPropertyName
) )
509 // add or revoke as listener
510 if ( _bNeedNewListening
)
511 m_xControlModel
->addPropertyChangeListener( _rPropertyName
, static_cast< XPropertyChangeListener
* >( this ) );
513 m_xControlModel
->removePropertyChangeListener( _rPropertyName
, static_cast< XPropertyChangeListener
* >( this ) );
516 OSL_FAIL( "AccessibleControlShape::ensureListeningState: this property does not exist at this model!" );
518 catch( const Exception
& e
)
520 (void)e
; // make compiler happy
521 OSL_FAIL( "AccessibleControlShape::ensureListeningState: could not change the listening state!" );
524 return _bNeedNewListening
;
527 sal_Int32 SAL_CALL
AccessibleControlShape::getAccessibleChildCount( ) throw(RuntimeException
, std::exception
)
529 if ( !m_xUnoControl
.is() )
531 else if ( !isAliveMode( m_xUnoControl
) )
532 // no special action required when in design mode
533 return AccessibleShape::getAccessibleChildCount( );
536 // in alive mode, we have the full control over our children - they are determined by the children
537 // of the context of our UNO control
538 Reference
< XAccessibleContext
> xControlContext( m_aControlContext
);
539 OSL_ENSURE( xControlContext
.is(), "AccessibleControlShape::getAccessibleChildCount: control context already dead! How this!" );
540 return xControlContext
.is() ? xControlContext
->getAccessibleChildCount() : 0;
544 Reference
< XAccessible
> SAL_CALL
AccessibleControlShape::getAccessibleChild( sal_Int32 i
) throw(IndexOutOfBoundsException
, RuntimeException
, std::exception
)
546 Reference
< XAccessible
> xChild
;
547 if ( !m_xUnoControl
.is() )
549 throw IndexOutOfBoundsException();
551 if ( !isAliveMode( m_xUnoControl
) )
553 // no special action required when in design mode - let the base class handle this
554 xChild
= AccessibleShape::getAccessibleChild( i
);
558 // in alive mode, we have the full control over our children - they are determined by the children
559 // of the context of our UNO control
561 Reference
< XAccessibleContext
> xControlContext( m_aControlContext
);
562 OSL_ENSURE( xControlContext
.is(), "AccessibleControlShape::getAccessibleChildCount: control context already dead! How this!" );
563 if ( xControlContext
.is() )
565 Reference
< XAccessible
> xInnerChild( xControlContext
->getAccessibleChild( i
) );
566 OSL_ENSURE( xInnerChild
.is(), "AccessibleControlShape::getAccessibleChild: control context returned nonsense!" );
567 if ( xInnerChild
.is() )
569 // we need to wrap this inner child into an own implementation
570 xChild
= m_pChildManager
->getAccessibleWrapperFor( xInnerChild
);
575 #if OSL_DEBUG_LEVEL > 0
576 sal_Int32 nChildIndex
= -1;
577 Reference
< XAccessibleContext
> xContext
;
579 xContext
= xChild
->getAccessibleContext( );
581 nChildIndex
= xContext
->getAccessibleIndexInParent( );
582 OSL_ENSURE( nChildIndex
== i
, "AccessibleControlShape::getAccessibleChild: index mismatch!" );
587 Reference
< XAccessibleRelationSet
> SAL_CALL
AccessibleControlShape::getAccessibleRelationSet( ) throw (RuntimeException
, std::exception
)
589 utl::AccessibleRelationSetHelper
* pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
590 ensureControlModelAccess();
591 AccessibleControlShape
* pCtlAccShape
= GetLabeledByControlShape();
594 Reference
< XAccessible
> xAcc (pCtlAccShape
->getAccessibleContext(), UNO_QUERY
);
596 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> > aSequence(1);
598 if( getAccessibleRole() == AccessibleRole::RADIO_BUTTON
)
600 pRelationSetHelper
->AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF
, aSequence
) );
604 pRelationSetHelper
->AddRelation( AccessibleRelation( AccessibleRelationType::LABELED_BY
, aSequence
) );
607 Reference
< XAccessibleRelationSet
> xSet
= pRelationSetHelper
;
611 OUString
AccessibleControlShape::CreateAccessibleName() throw (RuntimeException
)
613 ensureControlModelAccess();
616 if ( getAccessibleRole() != AccessibleRole::SHAPE
617 && getAccessibleRole() != AccessibleRole::RADIO_BUTTON
)
619 AccessibleControlShape
* pCtlAccShape
= GetLabeledByControlShape();
622 sName
= pCtlAccShape
->CreateAccessibleName();
628 // check if we can obtain the "Name" resp. "Label" property from the model
629 const OUString
& rAccNameProperty
= lcl_getPreferredAccNameProperty( m_xModelPropsMeta
);
630 sName
= getControlModelStringProperty( rAccNameProperty
);
631 if ( !sName
.getLength() )
632 { // no -> use the default
633 sName
= AccessibleShape::CreateAccessibleName();
637 // now that somebody first asked us for our name, ensure that we are listening to name changes on the model
638 m_bListeningForName
= ensureListeningState( m_bListeningForName
, true, lcl_getPreferredAccNameProperty( m_xModelPropsMeta
) );
643 void SAL_CALL
AccessibleControlShape::disposing()
645 // ensure we're not listening
646 m_bListeningForName
= ensureListeningState( m_bListeningForName
, false, lcl_getPreferredAccNameProperty( m_xModelPropsMeta
) );
647 m_bListeningForDesc
= ensureListeningState( m_bListeningForDesc
, false, lcl_getDescPropertyName() );
649 if ( m_bMultiplexingStates
)
650 stopStateMultiplexing( );
652 // dispose the child cache/map
653 m_pChildManager
->dispose();
656 m_xControlModel
.clear();
657 m_xModelPropsMeta
.clear();
658 m_aControlContext
= WeakReference
< XAccessibleContext
>();
660 // stop listening at the control container (should never be necessary here, but who knows ....)
661 if ( m_bWaitingForControl
)
663 OSL_FAIL( "AccessibleControlShape::disposing: this should never happen!" );
664 Reference
< XContainer
> xContainer
= lcl_getControlContainer( maShapeTreeInfo
.GetWindow(), maShapeTreeInfo
.GetSdrView() );
665 if ( xContainer
.is() )
667 m_bWaitingForControl
= false;
668 xContainer
->removeContainerListener( this );
672 // forward the disposel to our inner context
673 if ( m_bDisposeNativeContext
)
675 // don't listen for mode changes anymore
676 Reference
< XModeChangeBroadcaster
> xControlModes( m_xUnoControl
, UNO_QUERY
);
677 OSL_ENSURE( xControlModes
.is(), "AccessibleControlShape::disposing: don't have an mode broadcaster anymore!" );
678 if ( xControlModes
.is() )
679 xControlModes
->removeModeChangeListener( this );
681 if ( m_xControlContextComponent
.is() )
682 m_xControlContextComponent
->dispose();
683 // do _not_ clear m_xControlContextProxy! This has to be done in the dtor for correct ref-count handling
685 // no need to dispose the proxy/inner context anymore
686 m_bDisposeNativeContext
= false;
689 m_xUnoControl
.clear();
691 // let the base do it's stuff
692 AccessibleShape::disposing();
695 bool AccessibleControlShape::ensureControlModelAccess()
697 if ( m_xControlModel
.is() )
702 Reference
< XControlShape
> xShape( mxShape
, UNO_QUERY
);
704 m_xControlModel
.set(xShape
->getControl(), css::uno::UNO_QUERY
);
706 if ( m_xControlModel
.is() )
707 m_xModelPropsMeta
= m_xControlModel
->getPropertySetInfo();
709 catch( const Exception
& e
)
711 (void)e
; // make compiler happy
712 OSL_FAIL( "AccessibleControlShape::ensureControlModelAccess: caught an exception!" );
715 return m_xControlModel
.is();
718 void AccessibleControlShape::startStateMultiplexing()
720 OSL_PRECOND( !m_bMultiplexingStates
, "AccessibleControlShape::startStateMultiplexing: already multiplexing!" );
722 #if OSL_DEBUG_LEVEL > 0
723 // we should have a control, and it should be in alive mode
724 OSL_PRECOND( isAliveMode( m_xUnoControl
),
725 "AccessibleControlShape::startStateMultiplexing: should be done in alive mode only!" );
727 // we should have the native context of the control
728 Reference
< XAccessibleEventBroadcaster
> xBroadcaster( m_aControlContext
.get(), UNO_QUERY
);
729 OSL_ENSURE( xBroadcaster
.is(), "AccessibleControlShape::startStateMultiplexing: no AccessibleEventBroadcaster on the native context!" );
731 if ( xBroadcaster
.is() )
733 xBroadcaster
->addAccessibleEventListener( this );
734 m_bMultiplexingStates
= true;
738 void AccessibleControlShape::stopStateMultiplexing()
740 OSL_PRECOND( m_bMultiplexingStates
, "AccessibleControlShape::stopStateMultiplexing: not multiplexing!" );
742 // we should have the native context of the control
743 Reference
< XAccessibleEventBroadcaster
> xBroadcaster( m_aControlContext
.get(), UNO_QUERY
);
744 OSL_ENSURE( xBroadcaster
.is(), "AccessibleControlShape::stopStateMultiplexing: no AccessibleEventBroadcaster on the native context!" );
746 if ( xBroadcaster
.is() )
748 xBroadcaster
->removeAccessibleEventListener( this );
749 m_bMultiplexingStates
= false;
753 OUString
AccessibleControlShape::getControlModelStringProperty( const OUString
& _rPropertyName
) const
758 if ( const_cast< AccessibleControlShape
* >( this )->ensureControlModelAccess() )
760 if ( !m_xModelPropsMeta
.is() || m_xModelPropsMeta
->hasPropertyByName( _rPropertyName
) )
761 // ask only if a) the control does not have a PropertySetInfo object or b) it has, and the
762 // property in question is available
763 m_xControlModel
->getPropertyValue( _rPropertyName
) >>= sReturn
;
766 catch( const Exception
& )
768 OSL_FAIL( "OAccessibleControlContext::getModelStringProperty: caught an exception!" );
773 void AccessibleControlShape::adjustAccessibleRole( )
775 // if we're in design mode, we are a simple SHAPE, in alive mode, we use the role of our inner context
776 if ( !isAliveMode( m_xUnoControl
) )
779 // we're in alive mode -> determine the role of the inner context
780 Reference
< XAccessibleContext
> xNativeContext( m_aControlContext
);
781 OSL_PRECOND( xNativeContext
.is(), "AccessibleControlShape::adjustAccessibleRole: no inner context!" );
782 if ( xNativeContext
.is() )
783 SetAccessibleRole( xNativeContext
->getAccessibleRole( ) );
788 bool AccessibleControlShape::SetState( sal_Int16 _nState
)
790 OSL_ENSURE( !isAliveMode( m_xUnoControl
) || !isComposedState( _nState
),
791 "AccessibleControlShape::SetState: a state which should be determined by the control context is set from outside!" );
792 return AccessibleShape::SetState( _nState
);
796 void AccessibleControlShape::initializeComposedState()
798 if ( !isAliveMode( m_xUnoControl
) )
799 // no action necessary for design mode
802 // get our own state set implementation
803 ::utl::AccessibleStateSetHelper
* pComposedStates
=
804 static_cast< ::utl::AccessibleStateSetHelper
* >( mxStateSet
.get() );
805 OSL_PRECOND( pComposedStates
,
806 "AccessibleControlShape::initializeComposedState: no composed set!" );
808 // we need to reset some states of the composed set, because they either do not apply
809 // for controls in alive mode, or are in the responsibility of the UNO-control, anyway
810 pComposedStates
->RemoveState( AccessibleStateType::ENABLED
); // this is controlled by the UNO-control
811 pComposedStates
->RemoveState( AccessibleStateType::SENSITIVE
); // this is controlled by the UNO-control
812 pComposedStates
->RemoveState( AccessibleStateType::FOCUSABLE
); // this is controlled by the UNO-control
813 pComposedStates
->RemoveState( AccessibleStateType::SELECTABLE
); // this does not hold for an alive UNO-control
814 #if OSL_DEBUG_LEVEL > 0
815 // now, only states which are not in the responsibility of the UNO control should be part of this state set
817 Sequence
< sal_Int16
> aInitStates
= pComposedStates
->getStates();
818 for ( sal_Int32 i
=0; i
<aInitStates
.getLength(); ++i
)
819 OSL_ENSURE( !isComposedState( aInitStates
.getConstArray()[i
] ),
820 "AccessibleControlShape::initializeComposedState: invalid initial composed state (should be controlled by the UNO-control)!" );
824 // get my inner context
825 Reference
< XAccessibleContext
> xInnerContext( m_aControlContext
);
826 OSL_PRECOND( xInnerContext
.is(), "AccessibleControlShape::initializeComposedState: no inner context!" );
827 if ( xInnerContext
.is() )
829 // get all states of the inner context
830 Reference
< XAccessibleStateSet
> xInnerStates( xInnerContext
->getAccessibleStateSet() );
831 OSL_ENSURE( xInnerStates
.is(), "AccessibleControlShape::initializeComposedState: no inner states!" );
832 Sequence
< sal_Int16
> aInnerStates
;
833 if ( xInnerStates
.is() )
834 aInnerStates
= xInnerStates
->getStates();
836 // look which one are to be propagated to the composed context
837 const sal_Int16
* pStates
= aInnerStates
.getConstArray();
838 const sal_Int16
* pStatesEnd
= pStates
+ aInnerStates
.getLength();
839 for ( ; pStates
!= pStatesEnd
; ++pStates
)
841 if ( isComposedState( *pStates
) && !pComposedStates
->contains( *pStates
) )
843 pComposedStates
->AddState( *pStates
);
849 void SAL_CALL
AccessibleControlShape::elementInserted( const ::com::sun::star::container::ContainerEvent
& _rEvent
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
851 Reference
< XContainer
> xContainer( _rEvent
.Source
, UNO_QUERY
);
852 Reference
< XControl
> xControl( _rEvent
.Element
, UNO_QUERY
);
854 OSL_ENSURE( xContainer
.is() && xControl
.is(),
855 "AccessibleControlShape::elementInserted: invalid event description!" );
857 if ( !xControl
.is() )
860 ensureControlModelAccess();
862 Reference
< XInterface
> xNewNormalized( xControl
->getModel(), UNO_QUERY
);
863 Reference
< XInterface
> xMyModelNormalized( m_xControlModel
, UNO_QUERY
);
864 if ( xNewNormalized
.get() && xMyModelNormalized
.get() )
866 // now finally the control for the model we're responsible for has been inserted into the container
867 Reference
< XInterface
> xKeepAlive( *this );
869 // first, we're not interested in any more container events
870 if ( xContainer
.is() )
872 xContainer
->removeContainerListener( this );
873 m_bWaitingForControl
= false;
876 // second, we need to replace ourself with a new version, which now can be based on the
878 OSL_VERIFY( mpParent
->ReplaceChild ( this, mxShape
, mnIndex
, maShapeTreeInfo
) );
882 void SAL_CALL
AccessibleControlShape::elementRemoved( const ::com::sun::star::container::ContainerEvent
& ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
887 void SAL_CALL
AccessibleControlShape::elementReplaced( const ::com::sun::star::container::ContainerEvent
& ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
892 AccessibleControlShape
* SAL_CALL
AccessibleControlShape::GetLabeledByControlShape( )
894 if(m_xControlModel
.is())
896 const OUString
& rAccLabelControlProperty
= lcl_getLabelControlPropertyName();
898 // get the "label by" property value of the control
899 if (::comphelper::hasProperty(rAccLabelControlProperty
, m_xControlModel
))
901 m_xControlModel
->getPropertyValue( rAccLabelControlProperty
) >>= sCtlLabelBy
;
902 if( sCtlLabelBy
.hasValue() )
904 Reference
< XPropertySet
> xAsSet (sCtlLabelBy
, UNO_QUERY
);
905 AccessibleControlShape
* pCtlAccShape
= mpParent
->GetAccControlShapeFromModel(xAsSet
.get());
913 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */