LCOV - code coverage report
Current view: top level - svx/source/accessibility - AccessibleControlShape.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 323 0.0 %
Date: 2012-08-25 Functions: 0 41 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 724 0.0 %

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

Generated by: LCOV version 1.10