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

Generated by: LCOV version 1.10