1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "AccessibleBase.hxx"
#include "AccessibleChartShape.hxx"
#include "ObjectHierarchy.hxx"
#include "ObjectIdentifier.hxx"
#include "chartview/ExplicitValueProvider.hxx"
#include "macros.hxx"
#include <com/sun/star/awt/XDevice.hpp>
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
#include <com/sun/star/accessibility/AccessibleEventObject.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <com/sun/star/drawing/LineStyle.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <rtl/ustrbuf.hxx>
#include <vcl/svapp.hxx>
#include <rtl/uuid.h>
#include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <svl/itemset.hxx>
#include <editeng/unofdesc.hxx>
#include <editeng/outliner.hxx>
#include <svx/svdoutl.hxx>
#include <svx/svdetc.hxx>
#include <svx/unoshape.hxx>
#include <svx/unoprov.hxx>
#include <vcl/unohelp.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/window.hxx>
#include <vcl/graph.hxx>
#include <vcl/settings.hxx>
#include <o3tl/functional.hxx>
#include <algorithm>
#include <iterator>
#include "ChartElementFactory.hxx"
using namespace ::com::sun::star;
using namespace ::com::sun::star::accessibility;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::uno::Reference;
using ::osl::MutexGuard;
using ::osl::ClearableMutexGuard;
using ::osl::ResettableMutexGuard;
using ::com::sun::star::uno::RuntimeException;
using ::com::sun::star::uno::Any;
namespace chart
{
/** @param bMayHaveChildren is false per default
*/
AccessibleBase::AccessibleBase(
const AccessibleElementInfo & rAccInfo,
bool bMayHaveChildren,
bool bAlwaysTransparent /* default: false */ ) :
impl::AccessibleBase_Base( m_aMutex ),
m_bIsDisposed( false ),
m_bMayHaveChildren( bMayHaveChildren ),
m_bChildrenInitialized( false ),
m_nEventNotifierId(0),
m_pStateSetHelper( new ::utl::AccessibleStateSetHelper() ),
m_aStateSet( m_pStateSetHelper ),
m_aAccInfo( rAccInfo ),
m_bAlwaysTransparent( bAlwaysTransparent ),
m_bStateSetInitialized( false )
{
// initialize some states
OSL_ASSERT( m_pStateSetHelper );
m_pStateSetHelper->AddState( AccessibleStateType::ENABLED );
m_pStateSetHelper->AddState( AccessibleStateType::SHOWING );
m_pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
m_pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
m_pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
}
AccessibleBase::~AccessibleBase()
{
OSL_ASSERT( m_bIsDisposed );
}
bool AccessibleBase::CheckDisposeState( bool bThrowException /* default: true */ ) const
throw (lang::DisposedException)
{
if( bThrowException &&
m_bIsDisposed )
{
throw lang::DisposedException("component has state DEFUNC",
static_cast< uno::XWeak * >( const_cast< AccessibleBase * >( this )));
}
return m_bIsDisposed;
}
bool AccessibleBase::NotifyEvent( EventType eEventType, const AccessibleUniqueId & rId )
{
if( GetId() == rId )
{
// event is addressed to this object
css::uno::Any aEmpty;
css::uno::Any aSelected;
aSelected <<= AccessibleStateType::SELECTED;
switch( eEventType )
{
case OBJECT_CHANGE:
{
BroadcastAccEvent( AccessibleEventId::VISIBLE_DATA_CHANGED, aEmpty, aEmpty );
SAL_INFO("chart2.accessibility", "Visible data event sent by: " << getAccessibleName());
}
break;
case GOT_SELECTION:
{
AddState( AccessibleStateType::SELECTED );
BroadcastAccEvent( AccessibleEventId::STATE_CHANGED, aSelected, aEmpty );
AddState( AccessibleStateType::FOCUSED );
aSelected <<= AccessibleStateType::FOCUSED;
BroadcastAccEvent( AccessibleEventId::STATE_CHANGED, aSelected, aEmpty, true );
SAL_INFO("chart2.accessibility", "Selection acquired by: " << getAccessibleName());
}
break;
case LOST_SELECTION:
{
RemoveState( AccessibleStateType::SELECTED );
BroadcastAccEvent( AccessibleEventId::STATE_CHANGED, aEmpty, aSelected );
AddState( AccessibleStateType::FOCUSED );
aSelected <<= AccessibleStateType::FOCUSED;
BroadcastAccEvent( AccessibleEventId::STATE_CHANGED, aEmpty, aSelected, true );
SAL_INFO("chart2.accessibility", "Selection lost by: " << getAccessibleName());
}
break;
case PROPERTY_CHANGE:
{
//not implemented --> rebuild all
}
break;
}
return true;
}
else if( m_bMayHaveChildren )
{
bool bStop = false;
ClearableMutexGuard aGuard( GetMutex() );
// make local copy for notification
ChildListVectorType aLocalChildList( m_aChildList );
aGuard.clear();
ChildListVectorType::iterator aEndIter = aLocalChildList.end();
for( ChildListVectorType::iterator aIter = aLocalChildList.begin() ;
( aIter != aEndIter ) && ( ! bStop ) ;
++aIter )
{
// Note: at this place we must be sure to have an AccessibleBase
// object in the UNO reference to XAccessible !
bStop = (*static_cast< AccessibleBase * >
( (*aIter).get() )).NotifyEvent( eEventType, rId );
}
return bStop;
}
return false;
}
void AccessibleBase::AddState( sal_Int16 aState )
throw (RuntimeException)
{
CheckDisposeState();
OSL_ASSERT( m_pStateSetHelper );
m_pStateSetHelper->AddState( aState );
}
void AccessibleBase::RemoveState( sal_Int16 aState )
throw (RuntimeException)
{
CheckDisposeState();
OSL_ASSERT( m_pStateSetHelper );
m_pStateSetHelper->RemoveState( aState );
}
bool AccessibleBase::UpdateChildren()
{
bool bMustUpdateChildren = false;
{
MutexGuard aGuard( GetMutex() );
if( ! m_bMayHaveChildren ||
m_bIsDisposed )
return false;
bMustUpdateChildren = ( m_bMayHaveChildren &&
! m_bChildrenInitialized );
}
// update unguarded
if( bMustUpdateChildren )
m_bChildrenInitialized = ImplUpdateChildren();
return m_bChildrenInitialized;
}
bool AccessibleBase::ImplUpdateChildren()
{
bool bResult = false;
if( m_aAccInfo.m_spObjectHierarchy )
{
ObjectHierarchy::tChildContainer aModelChildren(
m_aAccInfo.m_spObjectHierarchy->getChildren( GetId() ));
::std::vector< ChildOIDMap::key_type > aAccChildren;
aAccChildren.reserve( aModelChildren.size());
::std::transform( m_aChildOIDMap.begin(), m_aChildOIDMap.end(),
::std::back_inserter( aAccChildren ),
::o3tl::select1st< ChildOIDMap::value_type >() );
::std::sort( aModelChildren.begin(), aModelChildren.end());
::std::vector< ObjectHierarchy::tOID > aChildrenToRemove, aChildrenToAdd;
::std::set_difference( aModelChildren.begin(), aModelChildren.end(),
aAccChildren.begin(), aAccChildren.end(),
::std::back_inserter( aChildrenToAdd ));
::std::set_difference( aAccChildren.begin(), aAccChildren.end(),
aModelChildren.begin(), aModelChildren.end(),
::std::back_inserter( aChildrenToRemove ));
::std::vector< ObjectHierarchy::tOID >::const_iterator aIt( aChildrenToRemove.begin());
for( ; aIt != aChildrenToRemove.end(); ++aIt )
{
RemoveChildByOId( *aIt );
}
AccessibleElementInfo aAccInfo( GetInfo());
aAccInfo.m_pParent = this;
for( aIt = aChildrenToAdd.begin(); aIt != aChildrenToAdd.end(); ++aIt )
{
aAccInfo.m_aOID = *aIt;
if ( aIt->isAutoGeneratedObject() )
{
AddChild( ChartElementFactory::CreateChartElement( aAccInfo ) );
}
else if ( aIt->isAdditionalShape() )
{
AddChild( new AccessibleChartShape( aAccInfo ) );
}
}
bResult = true;
}
return bResult;
}
void AccessibleBase::AddChild( AccessibleBase * pChild )
{
OSL_ENSURE( pChild != nullptr, "Invalid Child" );
if( pChild )
{
ClearableMutexGuard aGuard( GetMutex() );
Reference< XAccessible > xChild( pChild );
m_aChildList.push_back( xChild );
m_aChildOIDMap[ pChild->GetId() ] = xChild;
// inform listeners of new child
if( m_bChildrenInitialized )
{
Any aEmpty, aNew;
aNew <<= xChild;
aGuard.clear();
BroadcastAccEvent( AccessibleEventId::CHILD, aNew, aEmpty );
}
}
}
/** in this method we imply that the Reference< XAccessible > elements in the
vector are AccessibleBase objects !
*/
void AccessibleBase::RemoveChildByOId( const ObjectIdentifier& rOId )
{
ClearableMutexGuard aGuard( GetMutex() );
ChildOIDMap::iterator aIt( m_aChildOIDMap.find( rOId ));
if( aIt != m_aChildOIDMap.end())
{
Reference< XAccessible > xChild( aIt->second );
// remove from map
m_aChildOIDMap.erase( aIt );
// search child in vector
ChildListVectorType::iterator aVecIter =
::std::find( m_aChildList.begin(), m_aChildList.end(), xChild );
OSL_ENSURE( aVecIter != m_aChildList.end(),
"Inconsistent ChildMap" );
// remove child from vector
m_aChildList.erase( aVecIter );
bool bInitialized = m_bChildrenInitialized;
// call listeners unguarded
aGuard.clear();
// inform listeners of removed child
if( bInitialized )
{
Any aEmpty, aOld;
aOld <<= xChild;
BroadcastAccEvent( AccessibleEventId::CHILD, aEmpty, aOld );
}
// dispose the child
Reference< lang::XComponent > xComp( xChild, UNO_QUERY );
if( xComp.is())
xComp->dispose();
}
}
awt::Point AccessibleBase::GetUpperLeftOnScreen() const
{
awt::Point aResult;
if( m_aAccInfo.m_pParent )
{
ClearableMutexGuard aGuard( GetMutex() );
AccessibleBase * pParent = m_aAccInfo.m_pParent;
aGuard.clear();
if( pParent )
{
aResult = pParent->GetUpperLeftOnScreen();
}
else
OSL_FAIL( "Default position used is probably incorrect." );
}
return aResult;
}
void AccessibleBase::BroadcastAccEvent(
sal_Int16 nId,
const Any & rNew,
const Any & rOld,
bool bSendGlobally ) const
{
ClearableMutexGuard aGuard( GetMutex() );
if ( !m_nEventNotifierId && !bSendGlobally )
return;
// if we don't have a client id for the notifier, then we don't have listeners, then
// we don't need to notify anything
//except SendGlobally for focus handling?
// the const cast is needed, because UNO parameters are never const
const AccessibleEventObject aEvent(
const_cast< uno::XWeak * >( static_cast< const uno::XWeak * >( this )),
nId, rNew, rOld );
if ( m_nEventNotifierId ) // let the notifier handle this event
::comphelper::AccessibleEventNotifier::addEvent( m_nEventNotifierId, aEvent );
aGuard.clear();
// send event to global message queue
if( bSendGlobally )
{
vcl::unohelper::NotifyAccessibleStateEventGlobally( aEvent );
}
}
void AccessibleBase::KillAllChildren()
{
ClearableMutexGuard aGuard( GetMutex() );
// make local copy for notification
ChildListVectorType aLocalChildList( m_aChildList );
// remove all children
m_aChildList.clear();
m_aChildOIDMap.clear();
aGuard.clear();
// call dispose for all children
// and notify listeners
Reference< lang::XComponent > xComp;
Any aEmpty, aOld;
ChildListVectorType::const_iterator aEndIter = aLocalChildList.end();
for( ChildListVectorType::const_iterator aIter = aLocalChildList.begin();
aIter != aEndIter; ++aIter )
{
aOld <<= (*aIter);
BroadcastAccEvent( AccessibleEventId::CHILD, aEmpty, aOld );
xComp.set( *aIter, UNO_QUERY );
if( xComp.is())
xComp->dispose();
}
m_bChildrenInitialized = false;
}
void AccessibleBase::SetInfo( const AccessibleElementInfo & rNewInfo )
{
m_aAccInfo = rNewInfo;
if( m_bMayHaveChildren )
{
KillAllChildren();
}
BroadcastAccEvent( AccessibleEventId::INVALIDATE_ALL_CHILDREN, uno::Any(), uno::Any(),
true /* global notification */ );
}
// ________ (XComponent::dispose) ________
void SAL_CALL AccessibleBase::disposing()
{
ClearableMutexGuard aGuard( GetMutex() );
OSL_ENSURE( ! m_bIsDisposed, "dispose() called twice" );
// notify disposing to all AccessibleEvent listeners asynchron
if ( m_nEventNotifierId )
{
::comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( m_nEventNotifierId, *this );
m_nEventNotifierId = 0;
}
// reset pointers
m_aAccInfo.m_pParent = nullptr;
// invalidate implementation for helper, but keep UNO reference to still
// allow a tool to query the DEFUNC state.
// Note: The object will be deleted when the last reference is released
m_pStateSetHelper = nullptr;
// attach new empty state set helper to member reference
::utl::AccessibleStateSetHelper * pHelper = new ::utl::AccessibleStateSetHelper();
pHelper->AddState( AccessibleStateType::DEFUNC );
// release old helper and attach new one
m_aStateSet.set( pHelper );
m_bIsDisposed = true;
// call listeners unguarded
aGuard.clear();
if( m_bMayHaveChildren )
{
KillAllChildren();
}
else
OSL_ENSURE( m_aChildList.empty(), "Child list should be empty" );
}
// ________ XAccessible ________
Reference< XAccessibleContext > SAL_CALL AccessibleBase::getAccessibleContext()
throw (RuntimeException, std::exception)
{
return this;
}
// ________ AccessibleBase::XAccessibleContext ________
sal_Int32 SAL_CALL AccessibleBase::getAccessibleChildCount()
throw (RuntimeException, std::exception)
{
ClearableMutexGuard aGuard( GetMutex() );
if( ! m_bMayHaveChildren ||
m_bIsDisposed )
return 0;
bool bMustUpdateChildren = ( m_bMayHaveChildren &&
! m_bChildrenInitialized );
aGuard.clear();
// update unguarded
if( bMustUpdateChildren )
UpdateChildren();
return ImplGetAccessibleChildCount();
}
sal_Int32 AccessibleBase::ImplGetAccessibleChildCount() const
throw (RuntimeException)
{
return m_aChildList.size();
}
Reference< XAccessible > SAL_CALL AccessibleBase::getAccessibleChild( sal_Int32 i )
throw (lang::IndexOutOfBoundsException, RuntimeException, std::exception)
{
CheckDisposeState();
Reference< XAccessible > xResult;
ResettableMutexGuard aGuard( GetMutex() );
bool bMustUpdateChildren = ( m_bMayHaveChildren &&
! m_bChildrenInitialized );
aGuard.clear();
if( bMustUpdateChildren )
UpdateChildren();
xResult.set( ImplGetAccessibleChildById( i ));
return xResult;
}
Reference< XAccessible > AccessibleBase::ImplGetAccessibleChildById( sal_Int32 i ) const
throw (lang::IndexOutOfBoundsException, RuntimeException)
{
Reference< XAccessible > xResult;
MutexGuard aGuard( GetMutex());
if( ! m_bMayHaveChildren ||
i < 0 ||
static_cast< ChildListVectorType::size_type >( i ) >= m_aChildList.size() )
{
OUString aBuf = "Index " + OUString::number( i ) + " is invalid for range [ 0, " +
OUString::number( m_aChildList.size() - 1 ) +
" ]";
lang::IndexOutOfBoundsException aEx( aBuf,
const_cast< ::cppu::OWeakObject * >(
static_cast< const ::cppu::OWeakObject * >( this )));
throw aEx;
}
else
xResult.set( m_aChildList[ i ] );
return xResult;
}
Reference< XAccessible > SAL_CALL AccessibleBase::getAccessibleParent()
throw (RuntimeException, std::exception)
{
CheckDisposeState();
Reference< XAccessible > aResult;
if( m_aAccInfo.m_pParent )
aResult.set( m_aAccInfo.m_pParent );
return aResult;
}
sal_Int32 SAL_CALL AccessibleBase::getAccessibleIndexInParent()
throw (RuntimeException, std::exception)
{
CheckDisposeState();
if( m_aAccInfo.m_spObjectHierarchy )
return m_aAccInfo.m_spObjectHierarchy->getIndexInParent( GetId() );
return -1;
}
sal_Int16 SAL_CALL AccessibleBase::getAccessibleRole()
throw (RuntimeException, std::exception)
{
return AccessibleRole::SHAPE;
}
Reference< XAccessibleRelationSet > SAL_CALL AccessibleBase::getAccessibleRelationSet()
throw (RuntimeException, std::exception)
{
Reference< XAccessibleRelationSet > aResult;
return aResult;
}
Reference< XAccessibleStateSet > SAL_CALL AccessibleBase::getAccessibleStateSet()
throw (RuntimeException, std::exception)
{
if( ! m_bStateSetInitialized )
{
Reference< view::XSelectionSupplier > xSelSupp( GetInfo().m_xSelectionSupplier );
if ( xSelSupp.is() )
{
ObjectIdentifier aOID( xSelSupp->getSelection() );
if ( aOID.isValid() && GetId() == aOID )
{
AddState( AccessibleStateType::SELECTED );
AddState( AccessibleStateType::FOCUSED );
}
}
m_bStateSetInitialized = true;
}
return m_aStateSet;
}
lang::Locale SAL_CALL AccessibleBase::getLocale()
throw (IllegalAccessibleComponentStateException, RuntimeException, std::exception)
{
CheckDisposeState();
return Application::GetSettings().GetLanguageTag().getLocale();
}
// ________ AccessibleBase::XAccessibleComponent ________
sal_Bool SAL_CALL AccessibleBase::containsPoint( const awt::Point& aPoint )
throw (RuntimeException, std::exception)
{
awt::Rectangle aRect( getBounds() );
// contains() works with relative coordinates
aRect.X = 0;
aRect.Y = 0;
return ( aPoint.X >= aRect.X &&
aPoint.Y >= aRect.Y &&
aPoint.X < (aRect.X + aRect.Width) &&
aPoint.Y < (aRect.Y + aRect.Height) );
}
Reference< XAccessible > SAL_CALL AccessibleBase::getAccessibleAtPoint( const awt::Point& aPoint )
throw (RuntimeException, std::exception)
{
CheckDisposeState();
Reference< XAccessible > aResult;
awt::Rectangle aRect( getBounds());
// children are positioned relative to this object, so translate bound rect
aRect.X = 0;
aRect.Y = 0;
// children must be inside the own bound rect
if( ( aRect.X <= aPoint.X && aPoint.X <= (aRect.X + aRect.Width) ) &&
( aRect.Y <= aPoint.Y && aPoint.Y <= (aRect.Y + aRect.Height)))
{
ClearableMutexGuard aGuard( GetMutex() );
ChildListVectorType aLocalChildList( m_aChildList );
aGuard.clear();
Reference< XAccessibleComponent > aComp;
for( ChildListVectorType::const_iterator aIter = aLocalChildList.begin();
aIter != aLocalChildList.end(); ++aIter )
{
aComp.set( *aIter, UNO_QUERY );
if( aComp.is())
{
aRect = aComp->getBounds();
if( ( aRect.X <= aPoint.X && aPoint.X <= (aRect.X + aRect.Width) ) &&
( aRect.Y <= aPoint.Y && aPoint.Y <= (aRect.Y + aRect.Height)))
{
aResult = (*aIter);
break;
}
}
}
}
return aResult;
}
awt::Rectangle SAL_CALL AccessibleBase::getBounds()
throw (RuntimeException, std::exception)
{
ExplicitValueProvider *pExplicitValueProvider(
ExplicitValueProvider::getExplicitValueProvider( m_aAccInfo.m_xView ));
if( pExplicitValueProvider )
{
vcl::Window* pWindow( VCLUnoHelper::GetWindow( m_aAccInfo.m_xWindow ));
awt::Rectangle aLogicRect( pExplicitValueProvider->getRectangleOfObject( m_aAccInfo.m_aOID.getObjectCID() ));
if( pWindow )
{
Rectangle aRect( aLogicRect.X, aLogicRect.Y,
aLogicRect.X + aLogicRect.Width,
aLogicRect.Y + aLogicRect.Height );
SolarMutexGuard aSolarGuard;
aRect = pWindow->LogicToPixel( aRect );
// aLogicRect is relative to the page, but we need a value relative
// to the parent object
awt::Point aParentLocOnScreen;
uno::Reference< XAccessibleComponent > xParent( getAccessibleParent(), uno::UNO_QUERY );
if( xParent.is() )
aParentLocOnScreen = xParent->getLocationOnScreen();
awt::Point aULOnScreen = GetUpperLeftOnScreen();
awt::Point aOffset( aParentLocOnScreen.X - aULOnScreen.X,
aParentLocOnScreen.Y - aULOnScreen.Y );
return awt::Rectangle( aRect.getX() - aOffset.X, aRect.getY() - aOffset.Y,
aRect.getWidth(), aRect.getHeight());
}
}
return awt::Rectangle();
}
awt::Point SAL_CALL AccessibleBase::getLocation()
throw (RuntimeException, std::exception)
{
CheckDisposeState();
awt::Rectangle aBBox( getBounds() );
return awt::Point( aBBox.X, aBBox.Y );
}
awt::Point SAL_CALL AccessibleBase::getLocationOnScreen()
throw (RuntimeException, std::exception)
{
CheckDisposeState();
if( m_aAccInfo.m_pParent != nullptr )
{
AccessibleBase * pParent = m_aAccInfo.m_pParent;
awt::Point aLocThisRel( getLocation());
awt::Point aUpperLeft;
if( pParent != nullptr )
aUpperLeft = pParent->getLocationOnScreen();
return awt::Point( aUpperLeft.X + aLocThisRel.X,
aUpperLeft.Y + aLocThisRel.Y );
}
else
return getLocation();
}
awt::Size SAL_CALL AccessibleBase::getSize()
throw (RuntimeException, std::exception)
{
CheckDisposeState();
awt::Rectangle aBBox( getBounds() );
return awt::Size( aBBox.Width, aBBox.Height );
}
void SAL_CALL AccessibleBase::grabFocus()
throw (RuntimeException, std::exception)
{
CheckDisposeState();
Reference< view::XSelectionSupplier > xSelSupp( GetInfo().m_xSelectionSupplier );
if ( xSelSupp.is() )
{
xSelSupp->select( GetId().getAny() );
}
}
sal_Int32 SAL_CALL AccessibleBase::getForeground()
throw (RuntimeException, std::exception)
{
return getColor( ACC_BASE_FOREGROUND );
}
sal_Int32 SAL_CALL AccessibleBase::getBackground()
throw (RuntimeException, std::exception)
{
return getColor( ACC_BASE_BACKGROUND );
}
sal_Int32 AccessibleBase::getColor( eColorType eColType )
{
sal_Int32 nResult = static_cast< sal_Int32 >( Color( COL_TRANSPARENT ).GetColor());
if( m_bAlwaysTransparent )
return nResult;
ObjectIdentifier aOID( m_aAccInfo.m_aOID );
ObjectType eType( aOID.getObjectType() );
Reference< beans::XPropertySet > xObjProp;
OUString aObjectCID = aOID.getObjectCID();
if( eType == OBJECTTYPE_LEGEND_ENTRY )
{
// for colors get the data series/point properties
OUString aParentParticle( ObjectIdentifier::getFullParentParticle( aObjectCID ));
aObjectCID = ObjectIdentifier::createClassifiedIdentifierForParticle( aParentParticle );
}
xObjProp.set(
ObjectIdentifier::getObjectPropertySet(
aObjectCID, Reference< chart2::XChartDocument >( m_aAccInfo.m_xChartDocument )), uno::UNO_QUERY );
if( xObjProp.is())
{
try
{
OUString aPropName;
OUString aStylePropName;
switch( eType )
{
case OBJECTTYPE_LEGEND_ENTRY:
case OBJECTTYPE_DATA_SERIES:
case OBJECTTYPE_DATA_POINT:
if( eColType == ACC_BASE_FOREGROUND )
{
aPropName = "BorderColor";
aStylePropName = "BorderTransparency";
}
else
{
aPropName = "Color";
aStylePropName = "Transparency";
}
break;
default:
if( eColType == ACC_BASE_FOREGROUND )
{
aPropName = "LineColor";
aStylePropName = "LineTransparence";
}
else
{
aPropName = "FillColor";
aStylePropName = "FillTransparence";
}
break;
}
bool bTransparent = m_bAlwaysTransparent;
Reference< beans::XPropertySetInfo > xInfo( xObjProp->getPropertySetInfo(), uno::UNO_QUERY );
if( xInfo.is() &&
xInfo->hasPropertyByName( aStylePropName ))
{
if( eColType == ACC_BASE_FOREGROUND )
{
drawing::LineStyle aLStyle;
if( xObjProp->getPropertyValue( aStylePropName ) >>= aLStyle )
bTransparent = (aLStyle == drawing::LineStyle_NONE);
}
else
{
drawing::FillStyle aFStyle;
if( xObjProp->getPropertyValue( aStylePropName ) >>= aFStyle )
bTransparent = (aFStyle == drawing::FillStyle_NONE);
}
}
if( !bTransparent &&
xInfo.is() &&
xInfo->hasPropertyByName( aPropName ))
{
xObjProp->getPropertyValue( aPropName ) >>= nResult;
}
}
catch( const uno::Exception & ex )
{
ASSERT_EXCEPTION( ex );
}
}
return nResult;
}
// ________ AccessibleBase::XServiceInfo ________
OUString SAL_CALL AccessibleBase::getImplementationName()
throw (RuntimeException, std::exception)
{
return OUString( "AccessibleBase" );
}
sal_Bool SAL_CALL AccessibleBase::supportsService( const OUString& ServiceName )
throw (RuntimeException, std::exception)
{
return cppu::supportsService( this, ServiceName );
}
uno::Sequence< OUString > SAL_CALL AccessibleBase::getSupportedServiceNames()
throw (RuntimeException, std::exception)
{
uno::Sequence< OUString > aSeq( 2 );
OUString* pStr = aSeq.getArray();
pStr[ 0 ] = "com.sun.star.accessibility.Accessible";
pStr[ 1 ] = "com.sun.star.accessibility.AccessibleContext";
return aSeq;
}
// ________ AccessibleBase::XEventListener ________
void SAL_CALL AccessibleBase::disposing( const lang::EventObject& /*Source*/ )
throw (RuntimeException, std::exception)
{
}
// ________ XAccessibleEventBroadcasters ________
void SAL_CALL AccessibleBase::addAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
throw (RuntimeException, std::exception)
{
MutexGuard aGuard( GetMutex() );
if ( xListener.is() )
{
if ( !m_nEventNotifierId )
m_nEventNotifierId = ::comphelper::AccessibleEventNotifier::registerClient();
::comphelper::AccessibleEventNotifier::addEventListener( m_nEventNotifierId, xListener );
}
}
void SAL_CALL AccessibleBase::removeAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
throw (RuntimeException, std::exception)
{
MutexGuard aGuard( GetMutex() );
if ( xListener.is() )
{
sal_Int32 nListenerCount = ::comphelper::AccessibleEventNotifier::removeEventListener( m_nEventNotifierId, xListener );
if ( !nListenerCount )
{
// no listeners anymore
::comphelper::AccessibleEventNotifier::revokeClient( m_nEventNotifierId );
m_nEventNotifierId = 0;
}
}
}
} // namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|