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 <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/lang/IndexOutOfBoundsException.hpp>
31 #include <com/sun/star/reflection/ProxyFactory.hpp>
32 #include <com/sun/star/util/XModeChangeBroadcaster.hpp>
33 #include <com/sun/star/container/XContainer.hpp>
34 #include <comphelper/processfactory.hxx>
35 #include <comphelper/property.hxx>
36 #include <unotools/accessiblerelationsethelper.hxx>
37 #include <svx/IAccessibleParent.hxx>
38 #include <svx/svdouno.hxx>
39 #include <svx/ShapeTypeHandler.hxx>
40 #include <svx/SvxShapeTypes.hxx>
41 #include <comphelper/accessiblewrapper.hxx>
42 #include <svx/svdview.hxx>
43 #include <svx/svdpagv.hxx>
44 #include <svx/strings.hrc>
45 #include <vcl/svapp.hxx>
46 #include <vcl/window.hxx>
47 #include <sal/log.hxx>
48 #include <tools/debug.hxx>
49 #include <comphelper/diagnose_ex.hxx>
51 using namespace ::accessibility
;
52 using namespace ::com::sun::star::accessibility
;
53 using namespace ::com::sun::star::uno
;
54 using namespace ::com::sun::star::awt
;
55 using namespace ::com::sun::star::beans
;
56 using namespace ::com::sun::star::util
;
57 using namespace ::com::sun::star::lang
;
58 using namespace ::com::sun::star::reflection
;
59 using namespace ::com::sun::star::drawing
;
60 using namespace ::com::sun::star::container
;
64 OUString
lcl_getNamePropertyName( )
68 OUString
lcl_getDescPropertyName( )
72 OUString
lcl_getLabelPropertyName( )
76 OUString
lcl_getLabelControlPropertyName( )
78 return "LabelControl";
80 // return the property which should be used as AccessibleName
81 OUString
lcl_getPreferredAccNameProperty( const Reference
< XPropertySetInfo
>& _rxPSI
)
83 if ( _rxPSI
.is() && _rxPSI
->hasPropertyByName( lcl_getLabelPropertyName() ) )
84 return lcl_getLabelPropertyName();
86 return lcl_getNamePropertyName();
89 // determines whether or not a state which belongs to the inner context needs to be forwarded to the "composed"
91 bool isComposedState( const sal_Int64 _nState
)
93 return ( ( AccessibleStateType::INVALID
!= _nState
)
94 && ( AccessibleStateType::DEFUNC
!= _nState
)
95 && ( AccessibleStateType::ICONIFIED
!= _nState
)
96 && ( AccessibleStateType::RESIZABLE
!= _nState
)
97 && ( AccessibleStateType::SELECTABLE
!= _nState
)
98 && ( AccessibleStateType::SHOWING
!= _nState
)
99 && ( AccessibleStateType::MANAGES_DESCENDANTS
!= _nState
)
100 && ( AccessibleStateType::VISIBLE
!= _nState
)
104 /// determines whether the given control is in alive mode
105 bool isAliveMode( const Reference
< XControl
>& _rxControl
)
107 OSL_PRECOND( _rxControl
.is(), "AccessibleControlShape::isAliveMode: invalid control" );
108 return _rxControl
.is() && !_rxControl
->isDesignMode();
112 AccessibleControlShape::AccessibleControlShape (
113 const AccessibleShapeInfo
& rShapeInfo
,
114 const AccessibleShapeTreeInfo
& rShapeTreeInfo
)
115 : AccessibleShape (rShapeInfo
, rShapeTreeInfo
)
116 , m_bListeningForName( false )
117 , m_bListeningForDesc( false )
118 , m_bMultiplexingStates( false )
119 , m_bDisposeNativeContext( false )
120 , m_bWaitingForControl( false )
122 m_pChildManager
= new comphelper::OWrappedAccessibleChildrenManager( comphelper::getProcessComponentContext() );
124 osl_atomic_increment( &m_refCount
);
126 m_pChildManager
->setOwningAccessible( this );
128 osl_atomic_decrement( &m_refCount
);
131 AccessibleControlShape::~AccessibleControlShape()
133 m_pChildManager
.clear();
135 if ( m_xControlContextProxy
.is() )
136 m_xControlContextProxy
->setDelegator( nullptr );
137 m_xControlContextProxy
.clear();
138 m_xControlContextTypeAccess
.clear();
139 m_xControlContextComponent
.clear();
140 // this should remove the _only_ three "real" reference (means not delegated to
141 // ourself) to this proxy, and thus delete it
145 Reference
< XContainer
> lcl_getControlContainer( const OutputDevice
* _pWin
, const SdrView
* _pView
)
147 Reference
< XContainer
> xReturn
;
148 DBG_ASSERT( _pView
, "lcl_getControlContainer: invalid view!" );
149 if ( _pView
&& _pView
->GetSdrPageView())
151 xReturn
.set(_pView
->GetSdrPageView()->GetControlContainer( *_pWin
), css::uno::UNO_QUERY
);
157 void AccessibleControlShape::Init()
159 AccessibleShape::Init();
161 OSL_ENSURE( !m_xControlContextProxy
.is(), "AccessibleControlShape::Init: already initialized!" );
164 // What we need to do here is merge the functionality of the AccessibleContext of our UNO control
165 // with our own AccessibleContext-related functionality.
167 // The problem is that we do not know the interfaces our "inner" context supports - this may be any
168 // XAccessibleXXX interface (or even any other) which makes sense for it.
170 // In theory, we could implement all possible interfaces ourself, and re-route all functionality to
171 // the inner context (except those we implement ourself, like XAccessibleComponent). But this is in no
172 // way future-proof - as soon as an inner context appears which implements an additional interface,
173 // we would need to adjust our implementation to support this new interface, too. Bad idea.
175 // The usual solution for such a problem is aggregation. Aggregation means using UNO's own mechanism
176 // for merging an inner with an outer component, and get a component which behaves as it is exactly one.
177 // This is what XAggregation is for. Unfortunately, aggregation requires _exact_ control over the ref count
178 // of the inner object, which we do not have at all.
181 // But there is a solution: com.sun.star.reflection.ProxyFactory. This service is able to create a proxy
182 // for any component, which supports _exactly_ the same interfaces as the component. In addition, it can
183 // be aggregated, as by definition the proxy's ref count is exactly 1 when returned from the factory.
184 // Sounds better. Though this yields the problem of slightly degraded performance, it's the only solution
185 // I'm aware of at the moment...
187 // get the control which belongs to our model (relative to our view)
188 const vcl::Window
* pViewWindow
= maShapeTreeInfo
.GetWindow();
189 SdrUnoObj
* pUnoObjectImpl
= dynamic_cast<SdrUnoObj
*>(SdrObject::getSdrObjectFromXShape(mxShape
));
190 SdrView
* pView
= maShapeTreeInfo
.GetSdrView();
191 OSL_ENSURE( pView
&& pViewWindow
&& pUnoObjectImpl
, "AccessibleControlShape::Init: no view, or no view window, no SdrUnoObj!" );
193 if ( pView
&& pViewWindow
&& pUnoObjectImpl
)
195 // get the context of the control - it will be our "inner" context
196 m_xUnoControl
= pUnoObjectImpl
->GetUnoControl( *pView
, *pViewWindow
->GetOutDev() );
198 if ( !m_xUnoControl
.is() )
200 // the control has not yet been created. Though speaking strictly, it is a bug that
201 // our instance here is created without an existing control (because an AccessibleControlShape
202 // is a representation of a view object, and can only live if the view it should represent
203 // is complete, which implies a living control), it's by far the easiest and most riskless way
204 // to fix this here in this class.
205 // Okay, we will add as listener to the control container where we expect our control to appear.
206 OSL_ENSURE( !m_bWaitingForControl
, "AccessibleControlShape::Init: already waiting for the control!" );
208 Reference
< XContainer
> xControlContainer
= lcl_getControlContainer( pViewWindow
->GetOutDev(), maShapeTreeInfo
.GetSdrView() );
209 OSL_ENSURE( xControlContainer
.is(), "AccessibleControlShape::Init: unable to find my ControlContainer!" );
210 if ( xControlContainer
.is() )
212 xControlContainer
->addContainerListener( this );
213 m_bWaitingForControl
= true;
218 Reference
< XModeChangeBroadcaster
> xControlModes( m_xUnoControl
, UNO_QUERY
);
219 Reference
< XAccessible
> xControlAccessible( xControlModes
, UNO_QUERY
);
220 Reference
< XAccessibleContext
> xNativeControlContext
;
221 if ( xControlAccessible
.is() )
222 xNativeControlContext
= xControlAccessible
->getAccessibleContext();
223 OSL_ENSURE( xNativeControlContext
.is(), "AccessibleControlShape::Init: no AccessibleContext for the control!" );
224 m_aControlContext
= WeakReference
< XAccessibleContext
>( xNativeControlContext
);
226 // add as listener to the context - we want to multiplex some states
227 if ( isAliveMode( m_xUnoControl
) && xNativeControlContext
.is() )
228 { // (but only in alive mode)
229 startStateMultiplexing( );
232 // now that we have all information about our control, do some adjustments
233 adjustAccessibleRole();
234 initializeComposedState();
236 // some initialization for our child manager, which is used in alive mode only
237 if ( isAliveMode( m_xUnoControl
) )
239 sal_Int64
nStates( getAccessibleStateSet( ) );
240 m_pChildManager
->setTransientChildren( nStates
& AccessibleStateType::MANAGES_DESCENDANTS
);
243 // finally, aggregate a proxy for the control context
244 // first a factory for the proxy
245 Reference
< XProxyFactory
> xFactory
= ProxyFactory::create( comphelper::getProcessComponentContext() );
246 // then the proxy itself
247 if ( xNativeControlContext
.is() )
249 m_xControlContextProxy
= xFactory
->createProxy( xNativeControlContext
);
250 m_xControlContextTypeAccess
.set( xNativeControlContext
, UNO_QUERY_THROW
);
251 m_xControlContextComponent
.set( xNativeControlContext
, UNO_QUERY_THROW
);
253 // aggregate the proxy
254 osl_atomic_increment( &m_refCount
);
255 if ( m_xControlContextProxy
.is() )
257 // At this point in time, the proxy has a ref count of exactly one - in m_xControlContextProxy.
258 // Remember to _not_ reset this member unless the delegator of the proxy has been reset, too!
259 m_xControlContextProxy
->setDelegator( *this );
261 osl_atomic_decrement( &m_refCount
);
263 m_bDisposeNativeContext
= true;
265 // Finally, we need to add ourself as mode listener to the control. In case the mode switches,
266 // we need to dispose ourself.
267 xControlModes
->addModeChangeListener( this );
272 catch( const Exception
& )
274 OSL_FAIL( "AccessibleControlShape::Init: could not \"aggregate\" the controls XAccessibleContext!" );
278 void SAL_CALL
AccessibleControlShape::grabFocus()
280 if ( !m_xUnoControl
.is() || !isAliveMode( m_xUnoControl
) )
282 // in design mode, we simply forward the request to the base class
283 AccessibleShape::grabFocus();
287 Reference
< XWindow
> xWindow( m_xUnoControl
, UNO_QUERY
);
288 OSL_ENSURE( xWindow
.is(), "AccessibleControlShape::grabFocus: invalid control!" );
294 OUString SAL_CALL
AccessibleControlShape::getImplementationName()
296 return "com.sun.star.comp.accessibility.AccessibleControlShape";
299 OUString
AccessibleControlShape::CreateAccessibleBaseName()
303 ShapeTypeId nShapeType
= ShapeTypeHandler::Instance().GetTypeId (mxShape
);
306 case DRAWING_CONTROL
:
307 sName
= "ControlShape";
310 sName
= "UnknownAccessibleControlShape";
312 sName
+= ": " + mxShape
->getShapeType();
319 AccessibleControlShape::CreateAccessibleDescription()
321 DescriptionGenerator
aDG (mxShape
);
322 ShapeTypeId nShapeType
= ShapeTypeHandler::Instance().GetTypeId (mxShape
);
325 case DRAWING_CONTROL
:
327 // check if we can obtain the "Desc" property from the model
328 OUString
sDesc( getControlModelStringProperty( lcl_getDescPropertyName() ) );
329 if ( sDesc
.isEmpty() )
330 { // no -> use the default
331 aDG
.Initialize (STR_ObjNameSingulUno
);
332 aDG
.AddProperty ("ControlBackground", DescriptionGenerator::PropertyType::Color
);
333 aDG
.AddProperty ( "ControlBorder", DescriptionGenerator::PropertyType::Integer
);
335 // ensure that we are listening to the Name property
336 m_bListeningForDesc
= ensureListeningState( m_bListeningForDesc
, true, lcl_getDescPropertyName() );
341 aDG
.Initialize (u
"Unknown accessible control shape");
344 aDG
.AppendString (u
"service name=");
345 aDG
.AppendString (mxShape
->getShapeType());
352 IMPLEMENT_FORWARD_REFCOUNT( AccessibleControlShape
, AccessibleShape
)
353 IMPLEMENT_GET_IMPLEMENTATION_ID( AccessibleControlShape
)
355 void SAL_CALL
AccessibleControlShape::propertyChange( const PropertyChangeEvent
& _rEvent
)
357 ::osl::MutexGuard
aGuard( m_aMutex
);
359 // check if it is the name or the description
360 if ( _rEvent
.PropertyName
== lcl_getNamePropertyName()
361 || _rEvent
.PropertyName
== lcl_getLabelPropertyName() )
364 CreateAccessibleName(),
365 AccessibleContextBase::AutomaticallyCreated
);
367 else if ( _rEvent
.PropertyName
== lcl_getDescPropertyName() )
369 SetAccessibleDescription(
370 CreateAccessibleDescription(),
371 AccessibleContextBase::AutomaticallyCreated
);
373 #if OSL_DEBUG_LEVEL > 0
376 OSL_FAIL( "AccessibleControlShape::propertyChange: where did this come from?" );
381 Any SAL_CALL
AccessibleControlShape::queryInterface( const Type
& _rType
)
383 Any aReturn
= AccessibleShape::queryInterface( _rType
);
384 if ( !aReturn
.hasValue() )
386 aReturn
= AccessibleControlShape_Base::queryInterface( _rType
);
387 if ( !aReturn
.hasValue() && m_xControlContextProxy
.is() )
388 aReturn
= m_xControlContextProxy
->queryAggregation( _rType
);
393 Sequence
< Type
> SAL_CALL
AccessibleControlShape::getTypes()
395 Sequence
< Type
> aShapeTypes
= AccessibleShape::getTypes();
396 Sequence
< Type
> aOwnTypes
= AccessibleControlShape_Base::getTypes();
398 Sequence
< Type
> aAggregateTypes
;
399 if ( m_xControlContextTypeAccess
.is() )
400 aAggregateTypes
= m_xControlContextTypeAccess
->getTypes();
403 return comphelper::combineSequences(comphelper::concatSequences( aShapeTypes
, aOwnTypes
), aAggregateTypes
);
406 void SAL_CALL
AccessibleControlShape::notifyEvent( const AccessibleEventObject
& _rEvent
)
408 if ( AccessibleEventId::STATE_CHANGED
== _rEvent
.EventId
)
410 // multiplex this change
411 sal_Int64
nLostState( 0 ), nGainedState( 0 );
412 _rEvent
.OldValue
>>= nLostState
;
413 _rEvent
.NewValue
>>= nGainedState
;
415 // don't multiplex states which the inner context is not responsible for
416 if ( isComposedState( nLostState
) )
417 AccessibleShape::ResetState( nLostState
);
419 if ( isComposedState( nGainedState
) )
420 AccessibleShape::SetState( nGainedState
);
424 AccessibleEventObject
aTranslatedEvent( _rEvent
);
427 ::osl::MutexGuard
aGuard( m_aMutex
);
429 // let the child manager translate the event
430 aTranslatedEvent
.Source
= *this;
431 m_pChildManager
->translateAccessibleEvent( _rEvent
, aTranslatedEvent
);
433 // see if any of these notifications affect our child manager
434 m_pChildManager
->handleChildNotification( _rEvent
);
437 FireEvent( aTranslatedEvent
);
441 void SAL_CALL
AccessibleControlShape::modeChanged(const ModeChangeEvent
& rSource
)
443 // did it come from our inner context (the real one, not it's proxy!)?
444 SAL_INFO("sw.uno", "AccessibleControlShape::modeChanged");
445 Reference
<XControl
> xSource(rSource
.Source
, UNO_QUERY
); // for faster compare
446 if(xSource
.get() != m_xUnoControl
.get())
448 SAL_WARN("sw.uno", "AccessibleControlShape::modeChanged: where did this come from?");
452 // If our "pseudo-aggregated" inner context does not live anymore,
453 // we don't want to live, too. This is accomplished by asking our
454 // parent to replace this object with a new one. Disposing this
455 // object and sending notifications about the replacement are in
456 // the responsibility of our parent.
457 const bool bReplaced
= mpParent
->ReplaceChild(this, mxShape
, 0, maShapeTreeInfo
);
458 SAL_WARN_IF(!bReplaced
, "sw.uno", "AccessibleControlShape::modeChanged: replacing ourselves away did fail");
461 void SAL_CALL
AccessibleControlShape::disposing (const EventObject
& _rSource
)
463 AccessibleShape::disposing( _rSource
);
466 bool AccessibleControlShape::ensureListeningState(
467 const bool _bCurrentlyListening
, const bool _bNeedNewListening
,
468 const OUString
& _rPropertyName
)
470 if ( ( _bCurrentlyListening
== _bNeedNewListening
) || !ensureControlModelAccess() )
472 return _bCurrentlyListening
;
476 if ( !m_xModelPropsMeta
.is() || m_xModelPropsMeta
->hasPropertyByName( _rPropertyName
) )
478 // add or revoke as listener
479 if ( _bNeedNewListening
)
480 m_xControlModel
->addPropertyChangeListener( _rPropertyName
, static_cast< XPropertyChangeListener
* >( this ) );
482 m_xControlModel
->removePropertyChangeListener( _rPropertyName
, static_cast< XPropertyChangeListener
* >( this ) );
485 OSL_FAIL( "AccessibleControlShape::ensureListeningState: this property does not exist at this model!" );
487 catch( const Exception
& )
489 OSL_FAIL( "AccessibleControlShape::ensureListeningState: could not change the listening state!" );
492 return _bNeedNewListening
;
495 sal_Int64 SAL_CALL
AccessibleControlShape::getAccessibleChildCount( )
497 if ( !m_xUnoControl
.is() )
499 else if ( !isAliveMode( m_xUnoControl
) )
500 // no special action required when in design mode
501 return AccessibleShape::getAccessibleChildCount( );
504 // in alive mode, we have the full control over our children - they are determined by the children
505 // of the context of our UNO control
506 Reference
< XAccessibleContext
> xControlContext( m_aControlContext
);
507 OSL_ENSURE( xControlContext
.is(), "AccessibleControlShape::getAccessibleChildCount: control context already dead! How this!" );
508 return xControlContext
.is() ? xControlContext
->getAccessibleChildCount() : 0;
512 Reference
< XAccessible
> SAL_CALL
AccessibleControlShape::getAccessibleChild( sal_Int64 i
)
514 Reference
< XAccessible
> xChild
;
515 if ( !m_xUnoControl
.is() )
517 throw IndexOutOfBoundsException();
519 if ( !isAliveMode( m_xUnoControl
) )
521 // no special action required when in design mode - let the base class handle this
522 xChild
= AccessibleShape::getAccessibleChild( i
);
526 // in alive mode, we have the full control over our children - they are determined by the children
527 // of the context of our UNO control
529 Reference
< XAccessibleContext
> xControlContext( m_aControlContext
);
530 OSL_ENSURE( xControlContext
.is(), "AccessibleControlShape::getAccessibleChild: control context already dead! How this!" );
531 if ( xControlContext
.is() )
533 Reference
< XAccessible
> xInnerChild( xControlContext
->getAccessibleChild( i
) );
534 OSL_ENSURE( xInnerChild
.is(), "AccessibleControlShape::getAccessibleChild: control context returned nonsense!" );
535 if ( xInnerChild
.is() )
537 // we need to wrap this inner child into an own implementation
538 xChild
= m_pChildManager
->getAccessibleWrapperFor( xInnerChild
);
543 #if OSL_DEBUG_LEVEL > 0
544 sal_Int64 nChildIndex
= -1;
545 Reference
< XAccessibleContext
> xContext
;
547 xContext
= xChild
->getAccessibleContext( );
549 nChildIndex
= xContext
->getAccessibleIndexInParent( );
550 SAL_WARN_IF( nChildIndex
!= i
, "svx", "AccessibleControlShape::getAccessibleChild: index mismatch,"
551 " nChildIndex=" << nChildIndex
<< " vs i=" << i
);
556 Reference
< XAccessibleRelationSet
> SAL_CALL
AccessibleControlShape::getAccessibleRelationSet( )
558 rtl::Reference
<utl::AccessibleRelationSetHelper
> pRelationSetHelper
= new utl::AccessibleRelationSetHelper
;
559 ensureControlModelAccess();
560 AccessibleControlShape
* pCtlAccShape
= GetLabeledByControlShape();
563 Reference
< XAccessible
> xAcc (pCtlAccShape
->getAccessibleContext(), UNO_QUERY
);
565 css::uno::Sequence
< css::uno::Reference
< css::uno::XInterface
> > aSequence
{ xAcc
};
566 if( getAccessibleRole() == AccessibleRole::RADIO_BUTTON
)
568 pRelationSetHelper
->AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF
, aSequence
) );
572 pRelationSetHelper
->AddRelation( AccessibleRelation( AccessibleRelationType::LABELED_BY
, aSequence
) );
575 return pRelationSetHelper
;
578 OUString
AccessibleControlShape::CreateAccessibleName()
580 ensureControlModelAccess();
583 sal_Int16 aAccessibleRole
= getAccessibleRole();
584 if ( aAccessibleRole
!= AccessibleRole::SHAPE
585 && aAccessibleRole
!= AccessibleRole::RADIO_BUTTON
)
587 AccessibleControlShape
* pCtlAccShape
= GetLabeledByControlShape();
590 sName
= pCtlAccShape
->CreateAccessibleName();
596 // check if we can obtain the "Name" resp. "Label" property from the model
597 const OUString
& rAccNameProperty
= lcl_getPreferredAccNameProperty( m_xModelPropsMeta
);
598 sName
= getControlModelStringProperty( rAccNameProperty
);
599 if ( !sName
.getLength() )
600 { // no -> use the default
601 sName
= AccessibleShape::CreateAccessibleName();
605 // now that somebody first asked us for our name, ensure that we are listening to name changes on the model
606 m_bListeningForName
= ensureListeningState( m_bListeningForName
, true, lcl_getPreferredAccNameProperty( m_xModelPropsMeta
) );
611 void SAL_CALL
AccessibleControlShape::disposing()
613 // ensure we're not listening
614 m_bListeningForName
= ensureListeningState( m_bListeningForName
, false, lcl_getPreferredAccNameProperty( m_xModelPropsMeta
) );
615 m_bListeningForDesc
= ensureListeningState( m_bListeningForDesc
, false, lcl_getDescPropertyName() );
617 if ( m_bMultiplexingStates
)
618 stopStateMultiplexing( );
620 // dispose the child cache/map
621 m_pChildManager
->dispose();
624 m_xControlModel
.clear();
625 m_xModelPropsMeta
.clear();
626 m_aControlContext
= WeakReference
< XAccessibleContext
>();
628 // stop listening at the control container (should never be necessary here, but who knows...)
629 if ( m_bWaitingForControl
)
631 OSL_FAIL( "AccessibleControlShape::disposing: this should never happen!" );
632 if (auto pWindow
= maShapeTreeInfo
.GetWindow())
634 Reference
< XContainer
> xContainer
= lcl_getControlContainer( pWindow
->GetOutDev(), maShapeTreeInfo
.GetSdrView() );
635 if ( xContainer
.is() )
637 m_bWaitingForControl
= false;
638 xContainer
->removeContainerListener( this );
643 // forward the disposal to our inner context
644 if ( m_bDisposeNativeContext
)
646 // don't listen for mode changes anymore
647 Reference
< XModeChangeBroadcaster
> xControlModes( m_xUnoControl
, UNO_QUERY
);
648 OSL_ENSURE( xControlModes
.is(), "AccessibleControlShape::disposing: don't have a mode broadcaster anymore!" );
649 if ( xControlModes
.is() )
650 xControlModes
->removeModeChangeListener( this );
652 if ( m_xControlContextComponent
.is() )
653 m_xControlContextComponent
->dispose();
654 // do _not_ clear m_xControlContextProxy! This has to be done in the dtor for correct ref-count handling
656 // no need to dispose the proxy/inner context anymore
657 m_bDisposeNativeContext
= false;
660 m_xUnoControl
.clear();
662 // let the base do its stuff
663 AccessibleShape::disposing();
666 bool AccessibleControlShape::ensureControlModelAccess()
668 if ( m_xControlModel
.is() )
673 Reference
< XControlShape
> xShape( mxShape
, UNO_QUERY
);
675 m_xControlModel
.set(xShape
->getControl(), css::uno::UNO_QUERY
);
677 if ( m_xControlModel
.is() )
678 m_xModelPropsMeta
= m_xControlModel
->getPropertySetInfo();
680 catch( const Exception
& )
682 TOOLS_WARN_EXCEPTION( "svx", "AccessibleControlShape::ensureControlModelAccess" );
685 return m_xControlModel
.is();
688 void AccessibleControlShape::startStateMultiplexing()
690 OSL_PRECOND( !m_bMultiplexingStates
, "AccessibleControlShape::startStateMultiplexing: already multiplexing!" );
692 #if OSL_DEBUG_LEVEL > 0
693 // we should have a control, and it should be in alive mode
694 OSL_PRECOND( isAliveMode( m_xUnoControl
),
695 "AccessibleControlShape::startStateMultiplexing: should be done in alive mode only!" );
697 // we should have the native context of the control
698 Reference
< XAccessibleEventBroadcaster
> xBroadcaster( m_aControlContext
.get(), UNO_QUERY
);
699 OSL_ENSURE( xBroadcaster
.is(), "AccessibleControlShape::startStateMultiplexing: no AccessibleEventBroadcaster on the native context!" );
701 if ( xBroadcaster
.is() )
703 xBroadcaster
->addAccessibleEventListener( this );
704 m_bMultiplexingStates
= true;
708 void AccessibleControlShape::stopStateMultiplexing()
710 OSL_PRECOND( m_bMultiplexingStates
, "AccessibleControlShape::stopStateMultiplexing: not multiplexing!" );
712 // we should have the native context of the control
713 Reference
< XAccessibleEventBroadcaster
> xBroadcaster( m_aControlContext
.get(), UNO_QUERY
);
714 OSL_ENSURE( xBroadcaster
.is(), "AccessibleControlShape::stopStateMultiplexing: no AccessibleEventBroadcaster on the native context!" );
716 if ( xBroadcaster
.is() )
718 xBroadcaster
->removeAccessibleEventListener( this );
719 m_bMultiplexingStates
= false;
723 OUString
AccessibleControlShape::getControlModelStringProperty( const OUString
& _rPropertyName
) const
728 if ( const_cast< AccessibleControlShape
* >( this )->ensureControlModelAccess() )
730 if ( !m_xModelPropsMeta
.is() || m_xModelPropsMeta
->hasPropertyByName( _rPropertyName
) )
731 // ask only if a) the control does not have a PropertySetInfo object or b) it has, and the
732 // property in question is available
733 m_xControlModel
->getPropertyValue( _rPropertyName
) >>= sReturn
;
736 catch( const Exception
& )
738 TOOLS_WARN_EXCEPTION( "svx", "OAccessibleControlContext::getModelStringProperty" );
743 void AccessibleControlShape::adjustAccessibleRole( )
745 // if we're in design mode, we are a simple SHAPE, in alive mode, we use the role of our inner context
746 if ( !isAliveMode( m_xUnoControl
) )
749 // we're in alive mode -> determine the role of the inner context
750 Reference
< XAccessibleContext
> xNativeContext( m_aControlContext
);
751 OSL_PRECOND( xNativeContext
.is(), "AccessibleControlShape::adjustAccessibleRole: no inner context!" );
752 if ( xNativeContext
.is() )
753 SetAccessibleRole( xNativeContext
->getAccessibleRole( ) );
758 bool AccessibleControlShape::SetState( sal_Int64 _nState
)
760 OSL_ENSURE( !isAliveMode( m_xUnoControl
) || !isComposedState( _nState
),
761 "AccessibleControlShape::SetState: a state which should be determined by the control context is set from outside!" );
762 return AccessibleShape::SetState( _nState
);
766 void AccessibleControlShape::initializeComposedState()
768 if ( !isAliveMode( m_xUnoControl
) )
769 // no action necessary for design mode
772 // we need to reset some states of the composed set, because they either do not apply
773 // for controls in alive mode, or are in the responsibility of the UNO-control, anyway
774 mnStateSet
&= ~AccessibleStateType::ENABLED
; // this is controlled by the UNO-control
775 mnStateSet
&= ~AccessibleStateType::SENSITIVE
; // this is controlled by the UNO-control
776 mnStateSet
&= ~AccessibleStateType::FOCUSABLE
; // this is controlled by the UNO-control
777 mnStateSet
&= ~AccessibleStateType::SELECTABLE
; // this does not hold for an alive UNO-control
779 // get my inner context
780 Reference
< XAccessibleContext
> xInnerContext( m_aControlContext
);
781 OSL_PRECOND( xInnerContext
.is(), "AccessibleControlShape::initializeComposedState: no inner context!" );
782 if ( !xInnerContext
.is() )
785 // get all states of the inner context
786 sal_Int64
nInnerStates( xInnerContext
->getAccessibleStateSet() );
788 // look which one are to be propagated to the composed context
789 for ( int i
= 0; i
< 63; ++i
)
791 sal_Int64 nState
= sal_Int64(1) << i
;
792 if ( (nInnerStates
& nState
) && isComposedState( nState
) )
794 mnStateSet
|= nState
;
799 void SAL_CALL
AccessibleControlShape::elementInserted( const css::container::ContainerEvent
& _rEvent
)
801 Reference
< XContainer
> xContainer( _rEvent
.Source
, UNO_QUERY
);
802 Reference
< XControl
> xControl( _rEvent
.Element
, UNO_QUERY
);
804 OSL_ENSURE( xContainer
.is() && xControl
.is(),
805 "AccessibleControlShape::elementInserted: invalid event description!" );
807 if ( !xControl
.is() )
810 ensureControlModelAccess();
812 Reference
< XInterface
> xNewNormalized( xControl
->getModel(), UNO_QUERY
);
813 Reference
< XInterface
> xMyModelNormalized( m_xControlModel
, UNO_QUERY
);
814 if ( !(xNewNormalized
&& xMyModelNormalized
) )
817 // now finally the control for the model we're responsible for has been inserted into the container
818 Reference
< XInterface
> xKeepAlive( *this );
820 // first, we're not interested in any more container events
821 if ( xContainer
.is() )
823 xContainer
->removeContainerListener( this );
824 m_bWaitingForControl
= false;
827 // second, we need to replace ourself with a new version, which now can be based on the
829 OSL_VERIFY( mpParent
->ReplaceChild ( this, mxShape
, 0, maShapeTreeInfo
) );
832 void SAL_CALL
AccessibleControlShape::elementRemoved( const css::container::ContainerEvent
& )
837 void SAL_CALL
AccessibleControlShape::elementReplaced( const css::container::ContainerEvent
& )
842 AccessibleControlShape
* AccessibleControlShape::GetLabeledByControlShape( )
844 if(m_xControlModel
.is())
846 const OUString
& rAccLabelControlProperty
= lcl_getLabelControlPropertyName();
848 // get the "label by" property value of the control
849 if (::comphelper::hasProperty(rAccLabelControlProperty
, m_xControlModel
))
851 sCtlLabelBy
= m_xControlModel
->getPropertyValue(rAccLabelControlProperty
);
852 if( sCtlLabelBy
.hasValue() )
854 Reference
< XPropertySet
> xAsSet (sCtlLabelBy
, UNO_QUERY
);
855 AccessibleControlShape
* pCtlAccShape
= mpParent
->GetAccControlShapeFromModel(xAsSet
.get());
863 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */