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