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

Generated by: LCOV version 1.10