LCOV - code coverage report
Current view: top level - svx/source/accessibility - AccessibleControlShape.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 365 0.0 %
Date: 2014-04-14 Functions: 0 43 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10