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