fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / accessibility / AccessibleBase.cxx
blobc2726669d6434fca6e5ebdeb04d702545d7d5b4c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "AccessibleBase.hxx"
21 #include "AccessibleChartShape.hxx"
22 #include "ObjectHierarchy.hxx"
23 #include "ObjectIdentifier.hxx"
24 #include "chartview/ExplicitValueProvider.hxx"
25 #include "macros.hxx"
27 #include <com/sun/star/awt/XDevice.hpp>
28 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
29 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
30 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
31 #include <com/sun/star/accessibility/AccessibleRole.hpp>
32 #include <com/sun/star/drawing/LineStyle.hpp>
33 #include <com/sun/star/drawing/FillStyle.hpp>
34 #include <rtl/ustrbuf.hxx>
35 #include <vcl/svapp.hxx>
36 #include <rtl/uuid.h>
37 #include <cppuhelper/queryinterface.hxx>
38 #include <cppuhelper/supportsservice.hxx>
39 #include <svl/itemset.hxx>
40 #include <editeng/unofdesc.hxx>
41 #include <editeng/outliner.hxx>
42 #include <svx/svdoutl.hxx>
43 #include <svx/svdetc.hxx>
44 #include <svx/unoshape.hxx>
45 #include <svx/unoprov.hxx>
46 #include <vcl/unohelp.hxx>
47 #include <toolkit/helper/vclunohelper.hxx>
48 #include <vcl/window.hxx>
49 #include <vcl/graph.hxx>
50 #include <vcl/settings.hxx>
52 #include <algorithm>
53 #include <o3tl/compat_functional.hxx>
55 #include "ChartElementFactory.hxx"
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::accessibility;
60 using ::com::sun::star::uno::UNO_QUERY;
61 using ::com::sun::star::uno::Reference;
62 using ::osl::MutexGuard;
63 using ::osl::ClearableMutexGuard;
64 using ::osl::ResettableMutexGuard;
65 using ::com::sun::star::uno::RuntimeException;
66 using ::com::sun::star::uno::Any;
68 namespace chart
71 /** @param bMayHaveChildren is false per default
73 AccessibleBase::AccessibleBase(
74 const AccessibleElementInfo & rAccInfo,
75 bool bMayHaveChildren,
76 bool bAlwaysTransparent /* default: false */ ) :
77 impl::AccessibleBase_Base( m_aMutex ),
78 m_bIsDisposed( false ),
79 m_bMayHaveChildren( bMayHaveChildren ),
80 m_bChildrenInitialized( false ),
81 m_nEventNotifierId(0),
82 m_pStateSetHelper( new ::utl::AccessibleStateSetHelper() ),
83 m_aStateSet( m_pStateSetHelper ),
84 m_aAccInfo( rAccInfo ),
85 m_bAlwaysTransparent( bAlwaysTransparent ),
86 m_bStateSetInitialized( false )
88 // initialize some states
89 OSL_ASSERT( m_pStateSetHelper );
90 m_pStateSetHelper->AddState( AccessibleStateType::ENABLED );
91 m_pStateSetHelper->AddState( AccessibleStateType::SHOWING );
92 m_pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
93 m_pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
94 m_pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
97 AccessibleBase::~AccessibleBase()
99 OSL_ASSERT( m_bIsDisposed );
102 bool AccessibleBase::CheckDisposeState( bool bThrowException /* default: true */ ) const
103 throw (lang::DisposedException)
105 if( bThrowException &&
106 m_bIsDisposed )
108 throw lang::DisposedException("component has state DEFUNC",
109 static_cast< uno::XWeak * >( const_cast< AccessibleBase * >( this )));
111 return m_bIsDisposed;
114 bool AccessibleBase::NotifyEvent( EventType eEventType, const AccessibleUniqueId & rId )
116 if( GetId() == rId )
118 // event is addressed to this object
120 ::com::sun::star::uno::Any aEmpty;
121 ::com::sun::star::uno::Any aSelected;
122 aSelected <<= AccessibleStateType::SELECTED;
123 switch( eEventType )
125 case OBJECT_CHANGE:
127 BroadcastAccEvent( AccessibleEventId::VISIBLE_DATA_CHANGED, aEmpty, aEmpty );
128 #if OSL_DEBUG_LEVEL > 1
129 OSL_TRACE(
130 OUStringToOString(
131 OUString( "Visible data event sent by: " ) +
132 getAccessibleName(),
133 RTL_TEXTENCODING_ASCII_US ).getStr() );
134 #endif
136 break;
138 case GOT_SELECTION:
140 AddState( AccessibleStateType::SELECTED );
141 BroadcastAccEvent( AccessibleEventId::STATE_CHANGED, aSelected, aEmpty );
143 AddState( AccessibleStateType::FOCUSED );
144 aSelected <<= AccessibleStateType::FOCUSED;
145 BroadcastAccEvent( AccessibleEventId::STATE_CHANGED, aSelected, aEmpty, true );
146 #if OSL_DEBUG_LEVEL > 1
147 OSL_TRACE(
148 OUStringToOString(
149 OUString( "Selection acquired by: " ) +
150 getAccessibleName(),
151 RTL_TEXTENCODING_ASCII_US ).getStr() );
152 #endif
154 break;
156 case LOST_SELECTION:
158 RemoveState( AccessibleStateType::SELECTED );
159 BroadcastAccEvent( AccessibleEventId::STATE_CHANGED, aEmpty, aSelected );
161 AddState( AccessibleStateType::FOCUSED );
162 aSelected <<= AccessibleStateType::FOCUSED;
163 BroadcastAccEvent( AccessibleEventId::STATE_CHANGED, aEmpty, aSelected, true );
164 #if OSL_DEBUG_LEVEL > 1
165 OSL_TRACE(
166 OUStringToOString(
167 OUString( "Selection lost by: " ) +
168 getAccessibleName(),
169 RTL_TEXTENCODING_ASCII_US ).getStr() );
170 #endif
172 break;
174 case PROPERTY_CHANGE:
176 //not implemented --> rebuild all
178 break;
180 return true;
182 else if( m_bMayHaveChildren )
184 bool bStop = false;
186 ClearableMutexGuard aGuard( GetMutex() );
187 // make local copy for notification
188 ChildListVectorType aLocalChildList( m_aChildList );
189 aGuard.clear();
191 ChildListVectorType::iterator aEndIter = aLocalChildList.end();
192 for( ChildListVectorType::iterator aIter = aLocalChildList.begin() ;
193 ( aIter != aEndIter ) && ( ! bStop ) ;
194 ++aIter )
196 // Note: at this place we must be sure to have an AccessibleBase
197 // object in the UNO reference to XAccessible !
198 bStop = (*static_cast< AccessibleBase * >
199 ( (*aIter).get() )).NotifyEvent( eEventType, rId );
201 return bStop;
204 return false;
207 void AccessibleBase::AddState( sal_Int16 aState )
208 throw (RuntimeException)
210 CheckDisposeState();
211 OSL_ASSERT( m_pStateSetHelper );
212 m_pStateSetHelper->AddState( aState );
215 void AccessibleBase::RemoveState( sal_Int16 aState )
216 throw (RuntimeException)
218 CheckDisposeState();
219 OSL_ASSERT( m_pStateSetHelper );
220 m_pStateSetHelper->RemoveState( aState );
223 bool AccessibleBase::UpdateChildren()
225 bool bMustUpdateChildren = false;
227 MutexGuard aGuard( GetMutex() );
228 if( ! m_bMayHaveChildren ||
229 m_bIsDisposed )
230 return false;
232 bMustUpdateChildren = ( m_bMayHaveChildren &&
233 ! m_bChildrenInitialized );
236 // update unguarded
237 if( bMustUpdateChildren )
238 m_bChildrenInitialized = ImplUpdateChildren();
240 return m_bChildrenInitialized;
243 bool AccessibleBase::ImplUpdateChildren()
245 bool bResult = false;
247 if( m_aAccInfo.m_spObjectHierarchy )
249 ObjectHierarchy::tChildContainer aModelChildren(
250 m_aAccInfo.m_spObjectHierarchy->getChildren( GetId() ));
251 ::std::vector< ChildOIDMap::key_type > aAccChildren;
252 aAccChildren.reserve( aModelChildren.size());
253 ::std::transform( m_aChildOIDMap.begin(), m_aChildOIDMap.end(),
254 ::std::back_inserter( aAccChildren ),
255 ::o3tl::select1st< ChildOIDMap::value_type >());
257 ::std::sort( aModelChildren.begin(), aModelChildren.end());
259 ::std::vector< ObjectHierarchy::tOID > aChildrenToRemove, aChildrenToAdd;
260 ::std::set_difference( aModelChildren.begin(), aModelChildren.end(),
261 aAccChildren.begin(), aAccChildren.end(),
262 ::std::back_inserter( aChildrenToAdd ));
263 ::std::set_difference( aAccChildren.begin(), aAccChildren.end(),
264 aModelChildren.begin(), aModelChildren.end(),
265 ::std::back_inserter( aChildrenToRemove ));
267 ::std::vector< ObjectHierarchy::tOID >::const_iterator aIt( aChildrenToRemove.begin());
268 for( ; aIt != aChildrenToRemove.end(); ++aIt )
270 RemoveChildByOId( *aIt );
273 AccessibleElementInfo aAccInfo( GetInfo());
274 aAccInfo.m_pParent = this;
276 for( aIt = aChildrenToAdd.begin(); aIt != aChildrenToAdd.end(); ++aIt )
278 aAccInfo.m_aOID = *aIt;
279 if ( aIt->isAutoGeneratedObject() )
281 AddChild( ChartElementFactory::CreateChartElement( aAccInfo ) );
283 else if ( aIt->isAdditionalShape() )
285 AddChild( new AccessibleChartShape( aAccInfo, true, false ) );
288 bResult = true;
291 return bResult;
294 void AccessibleBase::AddChild( AccessibleBase * pChild )
296 OSL_ENSURE( pChild != NULL, "Invalid Child" );
297 if( pChild )
299 ClearableMutexGuard aGuard( GetMutex() );
301 Reference< XAccessible > xChild( pChild );
302 m_aChildList.push_back( xChild );
304 m_aChildOIDMap[ pChild->GetId() ] = xChild;
306 // inform listeners of new child
307 if( m_bChildrenInitialized )
309 Any aEmpty, aNew;
310 aNew <<= xChild;
312 aGuard.clear();
313 BroadcastAccEvent( AccessibleEventId::CHILD, aNew, aEmpty );
318 /** in this method we imply that the Reference< XAccessible > elements in the
319 vector are AccessibleBase objects !
321 void AccessibleBase::RemoveChildByOId( const ObjectIdentifier& rOId )
323 ClearableMutexGuard aGuard( GetMutex() );
325 ChildOIDMap::iterator aIt( m_aChildOIDMap.find( rOId ));
326 if( aIt != m_aChildOIDMap.end())
328 Reference< XAccessible > xChild( aIt->second );
330 // remove from map
331 m_aChildOIDMap.erase( aIt );
333 // search child in vector
334 ChildListVectorType::iterator aVecIter =
335 ::std::find( m_aChildList.begin(), m_aChildList.end(), xChild );
337 OSL_ENSURE( aVecIter != m_aChildList.end(),
338 "Inconsistent ChildMap" );
340 // remove child from vector
341 m_aChildList.erase( aVecIter );
342 bool bInitialized = m_bChildrenInitialized;
344 // call listeners unguarded
345 aGuard.clear();
347 // inform listeners of removed child
348 if( bInitialized )
350 Any aEmpty, aOld;
351 aOld <<= xChild;
353 BroadcastAccEvent( AccessibleEventId::CHILD, aEmpty, aOld );
356 // dispose the child
357 Reference< lang::XComponent > xComp( xChild, UNO_QUERY );
358 if( xComp.is())
359 xComp->dispose();
363 awt::Point AccessibleBase::GetUpperLeftOnScreen() const
365 awt::Point aResult;
366 if( m_aAccInfo.m_pParent )
368 ClearableMutexGuard aGuard( GetMutex() );
369 AccessibleBase * pParent = m_aAccInfo.m_pParent;
370 aGuard.clear();
372 if( pParent )
374 aResult = pParent->GetUpperLeftOnScreen();
376 else
377 OSL_FAIL( "Default position used is probably incorrect." );
380 return aResult;
383 void AccessibleBase::BroadcastAccEvent(
384 sal_Int16 nId,
385 const Any & rNew,
386 const Any & rOld,
387 bool bSendGlobally ) const
389 ClearableMutexGuard aGuard( GetMutex() );
391 if ( !m_nEventNotifierId && !bSendGlobally )
392 return;
393 // if we don't have a client id for the notifier, then we don't have listeners, then
394 // we don't need to notify anything
395 //except SendGlobally for focus handling?
397 // the const cast is needed, because UNO parameters are never const
398 const AccessibleEventObject aEvent(
399 const_cast< uno::XWeak * >( static_cast< const uno::XWeak * >( this )),
400 nId, rNew, rOld );
402 if ( m_nEventNotifierId ) // let the notifier handle this event
403 ::comphelper::AccessibleEventNotifier::addEvent( m_nEventNotifierId, aEvent );
405 aGuard.clear();
407 // send event to global message queue
408 if( bSendGlobally )
410 vcl::unohelper::NotifyAccessibleStateEventGlobally( aEvent );
414 void AccessibleBase::KillAllChildren()
416 ClearableMutexGuard aGuard( GetMutex() );
418 // make local copy for notification
419 ChildListVectorType aLocalChildList( m_aChildList );
421 // remove all children
422 m_aChildList.clear();
423 m_aChildOIDMap.clear();
425 aGuard.clear();
427 // call dispose for all children
428 // and notify listeners
429 Reference< lang::XComponent > xComp;
430 Any aEmpty, aOld;
431 ChildListVectorType::const_iterator aEndIter = aLocalChildList.end();
432 for( ChildListVectorType::const_iterator aIter = aLocalChildList.begin();
433 aIter != aEndIter; ++aIter )
435 aOld <<= (*aIter);
436 BroadcastAccEvent( AccessibleEventId::CHILD, aEmpty, aOld );
438 xComp.set( *aIter, UNO_QUERY );
439 if( xComp.is())
440 xComp->dispose();
442 m_bChildrenInitialized = false;
445 void AccessibleBase::SetInfo( const AccessibleElementInfo & rNewInfo )
447 m_aAccInfo = rNewInfo;
448 if( m_bMayHaveChildren )
450 KillAllChildren();
452 BroadcastAccEvent( AccessibleEventId::INVALIDATE_ALL_CHILDREN, uno::Any(), uno::Any(),
453 true /* global notification */ );
456 // ________ (XComponent::dispose) ________
457 void SAL_CALL AccessibleBase::disposing()
459 ClearableMutexGuard aGuard( GetMutex() );
460 OSL_ENSURE( ! m_bIsDisposed, "dispose() called twice" );
462 // notify disposing to all AccessibleEvent listeners asynchron
463 if ( m_nEventNotifierId )
465 ::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( m_nEventNotifierId, *this );
466 m_nEventNotifierId = 0;
469 // reset pointers
470 m_aAccInfo.m_pParent = NULL;
472 // invalidate implementation for helper, but keep UNO reference to still
473 // allow a tool to query the DEFUNC state.
474 // Note: The object will be deleted when the last reference is released
475 m_pStateSetHelper = NULL;
477 // attach new empty state set helper to member reference
478 ::utl::AccessibleStateSetHelper * pHelper = new ::utl::AccessibleStateSetHelper();
479 pHelper->AddState( AccessibleStateType::DEFUNC );
480 // release old helper and attach new one
481 m_aStateSet.set( pHelper );
483 m_bIsDisposed = true;
485 // call listeners unguarded
486 aGuard.clear();
488 if( m_bMayHaveChildren )
490 KillAllChildren();
492 else
493 OSL_ENSURE( m_aChildList.empty(), "Child list should be empty" );
496 // ________ XAccessible ________
497 Reference< XAccessibleContext > SAL_CALL AccessibleBase::getAccessibleContext()
498 throw (RuntimeException, std::exception)
500 return this;
503 // ________ AccessibleBase::XAccessibleContext ________
504 sal_Int32 SAL_CALL AccessibleBase::getAccessibleChildCount()
505 throw (RuntimeException, std::exception)
507 ClearableMutexGuard aGuard( GetMutex() );
508 if( ! m_bMayHaveChildren ||
509 m_bIsDisposed )
510 return 0;
512 bool bMustUpdateChildren = ( m_bMayHaveChildren &&
513 ! m_bChildrenInitialized );
515 aGuard.clear();
517 // update unguarded
518 if( bMustUpdateChildren )
519 UpdateChildren();
521 return ImplGetAccessibleChildCount();
524 sal_Int32 AccessibleBase::ImplGetAccessibleChildCount() const
525 throw (RuntimeException)
527 return m_aChildList.size();
530 Reference< XAccessible > SAL_CALL AccessibleBase::getAccessibleChild( sal_Int32 i )
531 throw (lang::IndexOutOfBoundsException, RuntimeException, std::exception)
533 CheckDisposeState();
534 Reference< XAccessible > xResult;
536 ResettableMutexGuard aGuard( GetMutex() );
537 bool bMustUpdateChildren = ( m_bMayHaveChildren &&
538 ! m_bChildrenInitialized );
540 aGuard.clear();
542 if( bMustUpdateChildren )
543 UpdateChildren();
545 xResult.set( ImplGetAccessibleChildById( i ));
547 return xResult;
550 Reference< XAccessible > AccessibleBase::ImplGetAccessibleChildById( sal_Int32 i ) const
551 throw (lang::IndexOutOfBoundsException, RuntimeException)
553 Reference< XAccessible > xResult;
555 MutexGuard aGuard( GetMutex());
556 if( ! m_bMayHaveChildren ||
557 i < 0 ||
558 static_cast< ChildListVectorType::size_type >( i ) >= m_aChildList.size() )
560 OUString aBuf = "Index " + OUString::number( i ) + " is invalid for range [ 0, " +
561 OUString::number( m_aChildList.size() - 1 ) +
562 " ]";
563 lang::IndexOutOfBoundsException aEx( aBuf,
564 const_cast< ::cppu::OWeakObject * >(
565 static_cast< const ::cppu::OWeakObject * >( this )));
566 throw aEx;
568 else
569 xResult.set( m_aChildList[ i ] );
571 return xResult;
574 Reference< XAccessible > SAL_CALL AccessibleBase::getAccessibleParent()
575 throw (RuntimeException, std::exception)
577 CheckDisposeState();
578 Reference< XAccessible > aResult;
579 if( m_aAccInfo.m_pParent )
580 aResult.set( m_aAccInfo.m_pParent );
582 return aResult;
585 sal_Int32 SAL_CALL AccessibleBase::getAccessibleIndexInParent()
586 throw (RuntimeException, std::exception)
588 CheckDisposeState();
590 if( m_aAccInfo.m_spObjectHierarchy )
591 return m_aAccInfo.m_spObjectHierarchy->getIndexInParent( GetId() );
592 return -1;
595 sal_Int16 SAL_CALL AccessibleBase::getAccessibleRole()
596 throw (RuntimeException, std::exception)
598 return AccessibleRole::SHAPE;
601 Reference< XAccessibleRelationSet > SAL_CALL AccessibleBase::getAccessibleRelationSet()
602 throw (RuntimeException, std::exception)
604 Reference< XAccessibleRelationSet > aResult;
605 return aResult;
608 Reference< XAccessibleStateSet > SAL_CALL AccessibleBase::getAccessibleStateSet()
609 throw (RuntimeException, std::exception)
611 if( ! m_bStateSetInitialized )
613 Reference< view::XSelectionSupplier > xSelSupp( GetInfo().m_xSelectionSupplier );
614 if ( xSelSupp.is() )
616 ObjectIdentifier aOID( xSelSupp->getSelection() );
617 if ( aOID.isValid() && GetId() == aOID )
619 AddState( AccessibleStateType::SELECTED );
620 AddState( AccessibleStateType::FOCUSED );
623 m_bStateSetInitialized = true;
626 return m_aStateSet;
629 lang::Locale SAL_CALL AccessibleBase::getLocale()
630 throw (IllegalAccessibleComponentStateException, RuntimeException, std::exception)
632 CheckDisposeState();
634 return Application::GetSettings().GetLanguageTag().getLocale();
637 // ________ AccessibleBase::XAccessibleComponent ________
638 sal_Bool SAL_CALL AccessibleBase::containsPoint( const awt::Point& aPoint )
639 throw (RuntimeException, std::exception)
641 awt::Rectangle aRect( getBounds() );
643 // contains() works with relative coordinates
644 aRect.X = 0;
645 aRect.Y = 0;
647 return ( aPoint.X >= aRect.X &&
648 aPoint.Y >= aRect.Y &&
649 aPoint.X < (aRect.X + aRect.Width) &&
650 aPoint.Y < (aRect.Y + aRect.Height) );
653 Reference< XAccessible > SAL_CALL AccessibleBase::getAccessibleAtPoint( const awt::Point& aPoint )
654 throw (RuntimeException, std::exception)
656 CheckDisposeState();
657 Reference< XAccessible > aResult;
658 awt::Rectangle aRect( getBounds());
660 // children are positioned relative to this object, so translate bound rect
661 aRect.X = 0;
662 aRect.Y = 0;
664 // children must be inside the own bound rect
665 if( ( aRect.X <= aPoint.X && aPoint.X <= (aRect.X + aRect.Width) ) &&
666 ( aRect.Y <= aPoint.Y && aPoint.Y <= (aRect.Y + aRect.Height)))
668 ClearableMutexGuard aGuard( GetMutex() );
669 ChildListVectorType aLocalChildList( m_aChildList );
670 aGuard.clear();
672 Reference< XAccessibleComponent > aComp;
673 for( ChildListVectorType::const_iterator aIter = aLocalChildList.begin();
674 aIter != aLocalChildList.end(); ++aIter )
676 aComp.set( *aIter, UNO_QUERY );
677 if( aComp.is())
679 aRect = aComp->getBounds();
680 if( ( aRect.X <= aPoint.X && aPoint.X <= (aRect.X + aRect.Width) ) &&
681 ( aRect.Y <= aPoint.Y && aPoint.Y <= (aRect.Y + aRect.Height)))
683 aResult = (*aIter);
684 break;
690 return aResult;
693 awt::Rectangle SAL_CALL AccessibleBase::getBounds()
694 throw (RuntimeException, std::exception)
696 ExplicitValueProvider *pExplicitValueProvider(
697 ExplicitValueProvider::getExplicitValueProvider( m_aAccInfo.m_xView ));
698 if( pExplicitValueProvider )
700 vcl::Window* pWindow( VCLUnoHelper::GetWindow( m_aAccInfo.m_xWindow ));
701 awt::Rectangle aLogicRect( pExplicitValueProvider->getRectangleOfObject( m_aAccInfo.m_aOID.getObjectCID() ));
702 if( pWindow )
704 Rectangle aRect( aLogicRect.X, aLogicRect.Y,
705 aLogicRect.X + aLogicRect.Width,
706 aLogicRect.Y + aLogicRect.Height );
707 SolarMutexGuard aSolarGuard;
708 aRect = pWindow->LogicToPixel( aRect );
710 // aLogicRect is relative to the page, but we need a value relative
711 // to the parent object
712 awt::Point aParentLocOnScreen;
713 uno::Reference< XAccessibleComponent > xParent( getAccessibleParent(), uno::UNO_QUERY );
714 if( xParent.is() )
715 aParentLocOnScreen = xParent->getLocationOnScreen();
717 awt::Point aULOnScreen = GetUpperLeftOnScreen();
718 awt::Point aOffset( aParentLocOnScreen.X - aULOnScreen.X,
719 aParentLocOnScreen.Y - aULOnScreen.Y );
721 return awt::Rectangle( aRect.getX() - aOffset.X, aRect.getY() - aOffset.Y,
722 aRect.getWidth(), aRect.getHeight());
726 return awt::Rectangle();
729 awt::Point SAL_CALL AccessibleBase::getLocation()
730 throw (RuntimeException, std::exception)
732 CheckDisposeState();
733 awt::Rectangle aBBox( getBounds() );
734 return awt::Point( aBBox.X, aBBox.Y );
737 awt::Point SAL_CALL AccessibleBase::getLocationOnScreen()
738 throw (RuntimeException, std::exception)
740 CheckDisposeState();
742 if( m_aAccInfo.m_pParent != NULL )
744 AccessibleBase * pParent = m_aAccInfo.m_pParent;
745 awt::Point aLocThisRel( getLocation());
746 awt::Point aUpperLeft;
748 if( pParent != NULL )
749 aUpperLeft = pParent->getLocationOnScreen();
751 return awt::Point( aUpperLeft.X + aLocThisRel.X,
752 aUpperLeft.Y + aLocThisRel.Y );
754 else
755 return getLocation();
758 awt::Size SAL_CALL AccessibleBase::getSize()
759 throw (RuntimeException, std::exception)
761 CheckDisposeState();
762 awt::Rectangle aBBox( getBounds() );
763 return awt::Size( aBBox.Width, aBBox.Height );
766 void SAL_CALL AccessibleBase::grabFocus()
767 throw (RuntimeException, std::exception)
769 CheckDisposeState();
771 Reference< view::XSelectionSupplier > xSelSupp( GetInfo().m_xSelectionSupplier );
772 if ( xSelSupp.is() )
774 xSelSupp->select( GetId().getAny() );
778 sal_Int32 SAL_CALL AccessibleBase::getForeground()
779 throw (RuntimeException, std::exception)
781 return getColor( ACC_BASE_FOREGROUND );
784 sal_Int32 SAL_CALL AccessibleBase::getBackground()
785 throw (RuntimeException, std::exception)
787 return getColor( ACC_BASE_BACKGROUND );
790 sal_Int32 AccessibleBase::getColor( eColorType eColType )
792 sal_Int32 nResult = static_cast< sal_Int32 >( Color( COL_TRANSPARENT ).GetColor());
793 if( m_bAlwaysTransparent )
794 return nResult;
796 ObjectIdentifier aOID( m_aAccInfo.m_aOID );
797 ObjectType eType( aOID.getObjectType() );
798 Reference< beans::XPropertySet > xObjProp;
799 OUString aObjectCID = aOID.getObjectCID();
800 if( eType == OBJECTTYPE_LEGEND_ENTRY )
802 // for colors get the data series/point properties
803 OUString aParentParticle( ObjectIdentifier::getFullParentParticle( aObjectCID ));
804 aObjectCID = ObjectIdentifier::createClassifiedIdentifierForParticle( aParentParticle );
807 xObjProp.set(
808 ObjectIdentifier::getObjectPropertySet(
809 aObjectCID, Reference< chart2::XChartDocument >( m_aAccInfo.m_xChartDocument )), uno::UNO_QUERY );
810 if( xObjProp.is())
814 OUString aPropName;
815 OUString aStylePropName;
817 switch( eType )
819 case OBJECTTYPE_LEGEND_ENTRY:
820 case OBJECTTYPE_DATA_SERIES:
821 case OBJECTTYPE_DATA_POINT:
822 if( eColType == ACC_BASE_FOREGROUND )
824 aPropName = "BorderColor";
825 aStylePropName = "BorderTransparency";
827 else
829 aPropName = "Color";
830 aStylePropName = "Transparency";
832 break;
833 default:
834 if( eColType == ACC_BASE_FOREGROUND )
836 aPropName = "LineColor";
837 aStylePropName = "LineTransparence";
839 else
841 aPropName = "FillColor";
842 aStylePropName = "FillTransparence";
844 break;
847 bool bTransparent = m_bAlwaysTransparent;
848 Reference< beans::XPropertySetInfo > xInfo( xObjProp->getPropertySetInfo(), uno::UNO_QUERY );
849 if( xInfo.is() &&
850 xInfo->hasPropertyByName( aStylePropName ))
852 if( eColType == ACC_BASE_FOREGROUND )
854 drawing::LineStyle aLStyle;
855 if( xObjProp->getPropertyValue( aStylePropName ) >>= aLStyle )
856 bTransparent = (aLStyle == drawing::LineStyle_NONE);
858 else
860 drawing::FillStyle aFStyle;
861 if( xObjProp->getPropertyValue( aStylePropName ) >>= aFStyle )
862 bTransparent = (aFStyle == drawing::FillStyle_NONE);
866 if( !bTransparent &&
867 xInfo.is() &&
868 xInfo->hasPropertyByName( aPropName ))
870 xObjProp->getPropertyValue( aPropName ) >>= nResult;
873 catch( const uno::Exception & ex )
875 ASSERT_EXCEPTION( ex );
879 return nResult;
882 // ________ AccessibleBase::XServiceInfo ________
883 OUString SAL_CALL AccessibleBase::getImplementationName()
884 throw (RuntimeException, std::exception)
886 return OUString( "AccessibleBase" );
889 sal_Bool SAL_CALL AccessibleBase::supportsService( const OUString& ServiceName )
890 throw (RuntimeException, std::exception)
892 return cppu::supportsService( this, ServiceName );
895 uno::Sequence< OUString > SAL_CALL AccessibleBase::getSupportedServiceNames()
896 throw (RuntimeException, std::exception)
898 uno::Sequence< OUString > aSeq( 2 );
899 OUString* pStr = aSeq.getArray();
900 pStr[ 0 ] = "com.sun.star.accessibility.Accessible";
901 pStr[ 1 ] = "com.sun.star.accessibility.AccessibleContext";
903 return aSeq;
906 // ________ AccessibleBase::XEventListener ________
907 void SAL_CALL AccessibleBase::disposing( const lang::EventObject& /*Source*/ )
908 throw (RuntimeException, std::exception)
912 // ________ XAccessibleEventBroadcasters ________
913 void SAL_CALL AccessibleBase::addAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
914 throw (RuntimeException, std::exception)
916 MutexGuard aGuard( GetMutex() );
918 if ( xListener.is() )
920 if ( !m_nEventNotifierId )
921 m_nEventNotifierId = ::comphelper::AccessibleEventNotifier::registerClient();
923 ::comphelper::AccessibleEventNotifier::addEventListener( m_nEventNotifierId, xListener );
927 void SAL_CALL AccessibleBase::removeAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
928 throw (RuntimeException, std::exception)
930 MutexGuard aGuard( GetMutex() );
932 if ( xListener.is() )
934 sal_Int32 nListenerCount = ::comphelper::AccessibleEventNotifier::removeEventListener( m_nEventNotifierId, xListener );
935 if ( !nListenerCount )
937 // no listeners anymore
938 ::comphelper::AccessibleEventNotifier::revokeClient( m_nEventNotifierId );
939 m_nEventNotifierId = 0;
944 } // namespace chart
946 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */