1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_accessibility.hxx" 26 #include <accessibility/extended/accessibleiconchoicectrlentry.hxx> 27 #include <svtools/ivctrl.hxx> 28 #include <com/sun/star/awt/Point.hpp> 29 #include <com/sun/star/awt/Rectangle.hpp> 30 #include <com/sun/star/awt/Size.hpp> 31 #include <com/sun/star/accessibility/AccessibleEventId.hpp> 32 #include <com/sun/star/accessibility/AccessibleRole.hpp> 33 #include <com/sun/star/accessibility/AccessibleStateType.hpp> 34 #include <tools/debug.hxx> 35 #include <vcl/svapp.hxx> 36 #include <vcl/controllayout.hxx> 37 #include <toolkit/awt/vclxwindow.hxx> 38 #include <toolkit/helper/convert.hxx> 39 #include <unotools/accessiblestatesethelper.hxx> 40 #include <unotools/accessiblerelationsethelper.hxx> 41 #include <cppuhelper/typeprovider.hxx> 42 #include <comphelper/sequence.hxx> 43 #include <svtools/stringtransfer.hxx> 44 #include <comphelper/accessibleeventnotifier.hxx> 45 46 #define ACCESSIBLE_ACTION_COUNT 1 47 #define AID_EXPAND 0 48 #define AID_COLLAPSE 1 49 50 namespace 51 { checkActionIndex_Impl(sal_Int32 _nIndex)52 void checkActionIndex_Impl( sal_Int32 _nIndex ) 53 { 54 if ( _nIndex < 0 || _nIndex >= ACCESSIBLE_ACTION_COUNT ) 55 // only three actions 56 throw ::com::sun::star::lang::IndexOutOfBoundsException(); 57 } 58 } 59 60 //........................................................................ 61 namespace accessibility 62 { 63 //........................................................................ 64 // class ALBSolarGuard --------------------------------------------------------- 65 66 /** Acquire the solar mutex. */ 67 class ALBSolarGuard : public ::vos::OGuard 68 { 69 public: ALBSolarGuard()70 inline ALBSolarGuard() : ::vos::OGuard( Application::GetSolarMutex() ) {} 71 }; 72 73 // class AccessibleIconChoiceCtrlEntry ----------------------------------------------------- 74 75 using namespace ::com::sun::star::accessibility; 76 using namespace ::com::sun::star::uno; 77 using namespace ::com::sun::star::lang; 78 using namespace ::com::sun::star; 79 DBG_NAME(AccessibleIconChoiceCtrlEntry)80 DBG_NAME(AccessibleIconChoiceCtrlEntry) 81 82 // ----------------------------------------------------------------------------- 83 // Ctor() and Dtor() 84 // ----------------------------------------------------------------------------- 85 AccessibleIconChoiceCtrlEntry::AccessibleIconChoiceCtrlEntry( SvtIconChoiceCtrl& _rIconCtrl, 86 sal_uLong _nPos, 87 const Reference< XAccessible >& _xParent ) : 88 89 AccessibleIconChoiceCtrlEntry_BASE ( m_aMutex ), 90 91 m_pIconCtrl ( &_rIconCtrl ), 92 m_nIndex ( _nPos ), 93 m_nClientId ( 0 ), 94 m_xParent ( _xParent ) 95 96 { 97 osl_incrementInterlockedCount( &m_refCount ); 98 { 99 Reference< XComponent > xComp( m_xParent, UNO_QUERY ); 100 if ( xComp.is() ) 101 xComp->addEventListener( this ); 102 } 103 osl_decrementInterlockedCount( &m_refCount ); 104 105 DBG_CTOR( AccessibleIconChoiceCtrlEntry, NULL ); 106 } 107 // ----------------------------------------------------------------------------- disposing(const EventObject & _rSource)108 void AccessibleIconChoiceCtrlEntry::disposing( const EventObject& _rSource ) 109 { 110 if ( _rSource.Source == m_xParent ) 111 { 112 dispose(); 113 DBG_ASSERT( !m_xParent.is() && ( NULL == m_pIconCtrl ), "" ); 114 } 115 } 116 // ----------------------------------------------------------------------------- ~AccessibleIconChoiceCtrlEntry()117 AccessibleIconChoiceCtrlEntry::~AccessibleIconChoiceCtrlEntry() 118 { 119 DBG_DTOR( AccessibleIconChoiceCtrlEntry, NULL ); 120 121 if ( IsAlive_Impl() ) 122 { 123 // increment ref count to prevent double call of Dtor 124 osl_incrementInterlockedCount( &m_refCount ); 125 dispose(); 126 } 127 } 128 #ifdef ACCESSIBLE_EVENT_NOTIFICATION_ENABLED 129 // (the following method is unused currently. If you need it, simply remove the #ifdef thing here and 130 // in the hxx) 131 // ----------------------------------------------------------------------------- NotifyAccessibleEvent(sal_Int16 _nEventId,const::com::sun::star::uno::Any & _aOldValue,const::com::sun::star::uno::Any & _aNewValue)132 void AccessibleIconChoiceCtrlEntry::NotifyAccessibleEvent( sal_Int16 _nEventId, 133 const ::com::sun::star::uno::Any& _aOldValue, 134 const ::com::sun::star::uno::Any& _aNewValue ) 135 { 136 Reference< uno::XInterface > xSource( *this ); 137 AccessibleEventObject aEventObj( xSource, _nEventId, _aNewValue, _aOldValue ); 138 139 if (m_nClientId) 140 comphelper::AccessibleEventNotifier::addEvent( m_nClientId, aEventObj ); 141 } 142 #endif 143 // ----------------------------------------------------------------------------- GetBoundingBox_Impl() const144 Rectangle AccessibleIconChoiceCtrlEntry::GetBoundingBox_Impl() const 145 { 146 Rectangle aRect; 147 SvxIconChoiceCtrlEntry* pEntry = m_pIconCtrl->GetEntry( m_nIndex ); 148 if ( pEntry ) 149 aRect = m_pIconCtrl->GetBoundingBox( pEntry ); 150 151 return aRect; 152 } 153 // ----------------------------------------------------------------------------- GetBoundingBoxOnScreen_Impl() const154 Rectangle AccessibleIconChoiceCtrlEntry::GetBoundingBoxOnScreen_Impl() const 155 { 156 Rectangle aRect; 157 SvxIconChoiceCtrlEntry* pEntry = m_pIconCtrl->GetEntry( m_nIndex ); 158 if ( pEntry ) 159 { 160 aRect = m_pIconCtrl->GetBoundingBox( pEntry ); 161 Point aTopLeft = aRect.TopLeft(); 162 aTopLeft += m_pIconCtrl->GetWindowExtentsRelative( NULL ).TopLeft(); 163 aRect = Rectangle( aTopLeft, aRect.GetSize() ); 164 } 165 166 return aRect; 167 } 168 // ----------------------------------------------------------------------------- IsAlive_Impl() const169 sal_Bool AccessibleIconChoiceCtrlEntry::IsAlive_Impl() const 170 { 171 return ( !rBHelper.bDisposed && !rBHelper.bInDispose && m_pIconCtrl ); 172 } 173 // ----------------------------------------------------------------------------- IsShowing_Impl() const174 sal_Bool AccessibleIconChoiceCtrlEntry::IsShowing_Impl() const 175 { 176 sal_Bool bShowing = sal_False; 177 Reference< XAccessibleContext > m_xParentContext = 178 m_xParent.is() ? m_xParent->getAccessibleContext() : Reference< XAccessibleContext >(); 179 if( m_xParentContext.is() ) 180 { 181 Reference< XAccessibleComponent > xParentComp( m_xParentContext, uno::UNO_QUERY ); 182 if( xParentComp.is() ) 183 bShowing = GetBoundingBox_Impl().IsOver( VCLRectangle( xParentComp->getBounds() ) ); 184 } 185 186 return bShowing; 187 } 188 // ----------------------------------------------------------------------------- GetBoundingBox()189 Rectangle AccessibleIconChoiceCtrlEntry::GetBoundingBox() 190 { 191 ALBSolarGuard aSolarGuard; 192 ::osl::MutexGuard aGuard( m_aMutex ); 193 194 EnsureIsAlive(); 195 return GetBoundingBox_Impl(); 196 } 197 // ----------------------------------------------------------------------------- GetBoundingBoxOnScreen()198 Rectangle AccessibleIconChoiceCtrlEntry::GetBoundingBoxOnScreen() 199 { 200 ALBSolarGuard aSolarGuard; 201 ::osl::MutexGuard aGuard( m_aMutex ); 202 203 EnsureIsAlive(); 204 return GetBoundingBoxOnScreen_Impl(); 205 } 206 // ----------------------------------------------------------------------------- EnsureIsAlive() const207 void AccessibleIconChoiceCtrlEntry::EnsureIsAlive() const 208 { 209 if ( !IsAlive_Impl() ) 210 throw lang::DisposedException(); 211 } 212 // ----------------------------------------------------------------------------- implGetText()213 ::rtl::OUString AccessibleIconChoiceCtrlEntry::implGetText() 214 { 215 ::rtl::OUString sRet; 216 SvxIconChoiceCtrlEntry* pEntry = m_pIconCtrl->GetEntry( m_nIndex ); 217 if ( pEntry ) 218 sRet = pEntry->GetDisplayText(); 219 return sRet; 220 } 221 // ----------------------------------------------------------------------------- implGetLocale()222 Locale AccessibleIconChoiceCtrlEntry::implGetLocale() 223 { 224 Locale aLocale; 225 aLocale = Application::GetSettings().GetUILocale(); 226 227 return aLocale; 228 } implGetSelection(sal_Int32 & nStartIndex,sal_Int32 & nEndIndex)229 void AccessibleIconChoiceCtrlEntry::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) 230 { 231 nStartIndex = 0; 232 nEndIndex = 0; 233 } 234 // ----------------------------------------------------------------------------- 235 // XTypeProvider 236 // ----------------------------------------------------------------------------- 237 // ----------------------------------------------------------------------------- getImplementationId()238 Sequence< sal_Int8 > AccessibleIconChoiceCtrlEntry::getImplementationId() 239 { 240 static ::cppu::OImplementationId* pId = NULL; 241 242 if ( !pId ) 243 { 244 ::osl::Guard< ::osl::Mutex > aGuard( m_aMutex ); 245 246 if ( !pId ) 247 { 248 static ::cppu::OImplementationId aId; 249 pId = &aId; 250 } 251 } 252 return pId->getImplementationId(); 253 } 254 // ----------------------------------------------------------------------------- 255 // XComponent 256 // ----------------------------------------------------------------------------- disposing()257 void SAL_CALL AccessibleIconChoiceCtrlEntry::disposing() 258 { 259 ::osl::MutexGuard aGuard( m_aMutex ); 260 261 // Send a disposing to all listeners. 262 if ( m_nClientId ) 263 { 264 sal_uInt32 nId = m_nClientId; 265 m_nClientId = 0; 266 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nId, *this ); 267 } 268 269 Reference< XComponent > xComp( m_xParent, UNO_QUERY ); 270 if ( xComp.is() ) 271 xComp->removeEventListener( this ); 272 273 m_pIconCtrl = NULL; 274 m_xParent = NULL; 275 } 276 // ----------------------------------------------------------------------------- 277 // XServiceInfo 278 // ----------------------------------------------------------------------------- getImplementationName()279 ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrlEntry::getImplementationName() 280 { 281 return getImplementationName_Static(); 282 } 283 // ----------------------------------------------------------------------------- getSupportedServiceNames()284 Sequence< ::rtl::OUString > SAL_CALL AccessibleIconChoiceCtrlEntry::getSupportedServiceNames() 285 { 286 return getSupportedServiceNames_Static(); 287 } 288 // ----------------------------------------------------------------------------- supportsService(const::rtl::OUString & _rServiceName)289 sal_Bool SAL_CALL AccessibleIconChoiceCtrlEntry::supportsService( const ::rtl::OUString& _rServiceName ) 290 { 291 Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() ); 292 const ::rtl::OUString* pSupported = aSupported.getConstArray(); 293 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); 294 for ( ; pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported ) 295 ; 296 297 return pSupported != pEnd; 298 } 299 // ----------------------------------------------------------------------------- 300 // XServiceInfo - static methods 301 // ----------------------------------------------------------------------------- getSupportedServiceNames_Static(void)302 Sequence< ::rtl::OUString > AccessibleIconChoiceCtrlEntry::getSupportedServiceNames_Static(void) 303 { 304 Sequence< ::rtl::OUString > aSupported(3); 305 aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleContext") ); 306 aSupported[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleComponent") ); 307 aSupported[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.AccessibleIconChoiceControlEntry") ); 308 return aSupported; 309 } 310 // ----------------------------------------------------------------------------- getImplementationName_Static(void)311 ::rtl::OUString AccessibleIconChoiceCtrlEntry::getImplementationName_Static(void) 312 { 313 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.svtools.AccessibleIconChoiceControlEntry") ); 314 } 315 // ----------------------------------------------------------------------------- 316 // XAccessible 317 // ----------------------------------------------------------------------------- getAccessibleContext()318 Reference< XAccessibleContext > SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleContext( ) 319 { 320 EnsureIsAlive(); 321 return this; 322 } 323 // ----------------------------------------------------------------------------- 324 // XAccessibleContext 325 // ----------------------------------------------------------------------------- getAccessibleChildCount()326 sal_Int32 SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleChildCount( ) 327 { 328 return 0; // no children 329 } 330 // ----------------------------------------------------------------------------- getAccessibleChild(sal_Int32)331 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleChild( sal_Int32 ) 332 { 333 throw IndexOutOfBoundsException(); 334 } 335 // ----------------------------------------------------------------------------- getAccessibleParent()336 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleParent( ) 337 { 338 ::osl::MutexGuard aGuard( m_aMutex ); 339 340 EnsureIsAlive(); 341 return m_xParent; 342 } 343 // ----------------------------------------------------------------------------- getAccessibleIndexInParent()344 sal_Int32 SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleIndexInParent( ) 345 { 346 ::osl::MutexGuard aGuard( m_aMutex ); 347 348 return m_nIndex; 349 } 350 // ----------------------------------------------------------------------------- getAccessibleRole()351 sal_Int16 SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleRole( ) 352 { 353 //return AccessibleRole::LABEL; 354 return AccessibleRole::LIST_ITEM; 355 } 356 // ----------------------------------------------------------------------------- getAccessibleDescription()357 ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleDescription( ) 358 { 359 // no description for every item 360 return ::rtl::OUString(); 361 } 362 // ----------------------------------------------------------------------------- getAccessibleName()363 ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleName( ) 364 { 365 ::osl::MutexGuard aGuard( m_aMutex ); 366 367 EnsureIsAlive(); 368 return implGetText(); 369 } 370 // ----------------------------------------------------------------------------- getAccessibleRelationSet()371 Reference< XAccessibleRelationSet > SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleRelationSet( ) 372 { 373 return new utl::AccessibleRelationSetHelper; 374 } 375 // ----------------------------------------------------------------------------- getAccessibleStateSet()376 Reference< XAccessibleStateSet > SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleStateSet( ) 377 { 378 ALBSolarGuard aSolarGuard; 379 ::osl::MutexGuard aGuard( m_aMutex ); 380 381 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper; 382 Reference< XAccessibleStateSet > xStateSet = pStateSetHelper; 383 384 if ( IsAlive_Impl() ) 385 { 386 pStateSetHelper->AddState( AccessibleStateType::TRANSIENT ); 387 pStateSetHelper->AddState( AccessibleStateType::SELECTABLE ); 388 pStateSetHelper->AddState( AccessibleStateType::ENABLED ); 389 pStateSetHelper->AddState( AccessibleStateType::SENSITIVE ); 390 if ( IsShowing_Impl() ) 391 { 392 pStateSetHelper->AddState( AccessibleStateType::SHOWING ); 393 pStateSetHelper->AddState( AccessibleStateType::VISIBLE ); 394 } 395 396 if ( m_pIconCtrl && m_pIconCtrl->GetCursor() == m_pIconCtrl->GetEntry( m_nIndex ) ) 397 pStateSetHelper->AddState( AccessibleStateType::SELECTED ); 398 } 399 else 400 pStateSetHelper->AddState( AccessibleStateType::DEFUNC ); 401 402 return xStateSet; 403 } 404 // ----------------------------------------------------------------------------- getLocale()405 Locale SAL_CALL AccessibleIconChoiceCtrlEntry::getLocale( ) 406 { 407 ALBSolarGuard aSolarGuard; 408 ::osl::MutexGuard aGuard( m_aMutex ); 409 410 return implGetLocale(); 411 } 412 // ----------------------------------------------------------------------------- 413 // XAccessibleComponent 414 // ----------------------------------------------------------------------------- containsPoint(const awt::Point & rPoint)415 sal_Bool SAL_CALL AccessibleIconChoiceCtrlEntry::containsPoint( const awt::Point& rPoint ) 416 { 417 return Rectangle( Point(), GetBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) ); 418 } 419 // ----------------------------------------------------------------------------- getAccessibleAtPoint(const awt::Point &)420 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleAtPoint( const awt::Point& ) 421 { 422 return Reference< XAccessible >(); 423 } 424 // ----------------------------------------------------------------------------- getBounds()425 awt::Rectangle SAL_CALL AccessibleIconChoiceCtrlEntry::getBounds( ) 426 { 427 return AWTRectangle( GetBoundingBox() ); 428 } 429 // ----------------------------------------------------------------------------- getLocation()430 awt::Point SAL_CALL AccessibleIconChoiceCtrlEntry::getLocation( ) 431 { 432 return AWTPoint( GetBoundingBox().TopLeft() ); 433 } 434 // ----------------------------------------------------------------------------- getLocationOnScreen()435 awt::Point SAL_CALL AccessibleIconChoiceCtrlEntry::getLocationOnScreen( ) 436 { 437 return AWTPoint( GetBoundingBoxOnScreen().TopLeft() ); 438 } 439 // ----------------------------------------------------------------------------- getSize()440 awt::Size SAL_CALL AccessibleIconChoiceCtrlEntry::getSize( ) 441 { 442 return AWTSize( GetBoundingBox().GetSize() ); 443 } 444 // ----------------------------------------------------------------------------- grabFocus()445 void SAL_CALL AccessibleIconChoiceCtrlEntry::grabFocus( ) 446 { 447 // do nothing, because no focus for each item 448 } 449 // ----------------------------------------------------------------------------- getForeground()450 sal_Int32 AccessibleIconChoiceCtrlEntry::getForeground( ) 451 { 452 ALBSolarGuard aSolarGuard; 453 ::osl::MutexGuard aGuard( m_aMutex ); 454 455 sal_Int32 nColor = 0; 456 Reference< XAccessible > xParent = getAccessibleParent(); 457 if ( xParent.is() ) 458 { 459 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY ); 460 if ( xParentComp.is() ) 461 nColor = xParentComp->getForeground(); 462 } 463 464 return nColor; 465 } 466 // ----------------------------------------------------------------------------- getBackground()467 sal_Int32 AccessibleIconChoiceCtrlEntry::getBackground( ) 468 { 469 ALBSolarGuard aSolarGuard; 470 ::osl::MutexGuard aGuard( m_aMutex ); 471 472 sal_Int32 nColor = 0; 473 Reference< XAccessible > xParent = getAccessibleParent(); 474 if ( xParent.is() ) 475 { 476 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY ); 477 if ( xParentComp.is() ) 478 nColor = xParentComp->getBackground(); 479 } 480 481 return nColor; 482 } 483 // ----------------------------------------------------------------------------- 484 // XAccessibleText 485 // ----------------------------------------------------------------------------- 486 // ----------------------------------------------------------------------------- getCharacterBounds(sal_Int32 _nIndex)487 awt::Rectangle SAL_CALL AccessibleIconChoiceCtrlEntry::getCharacterBounds( sal_Int32 _nIndex ) 488 { 489 ALBSolarGuard aSolarGuard; 490 ::osl::MutexGuard aGuard( m_aMutex ); 491 492 if ( ( 0 > _nIndex ) || ( getCharacterCount() <= _nIndex ) ) 493 throw IndexOutOfBoundsException(); 494 495 awt::Rectangle aBounds( 0, 0, 0, 0 ); 496 if ( m_pIconCtrl ) 497 { 498 Rectangle aItemRect = GetBoundingBox_Impl(); 499 Rectangle aCharRect = m_pIconCtrl->GetEntryCharacterBounds( m_nIndex, _nIndex ); 500 aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() ); 501 aBounds = AWTRectangle( aCharRect ); 502 } 503 504 return aBounds; 505 } 506 // ----------------------------------------------------------------------------- getIndexAtPoint(const awt::Point & aPoint)507 sal_Int32 SAL_CALL AccessibleIconChoiceCtrlEntry::getIndexAtPoint( const awt::Point& aPoint ) 508 { 509 ALBSolarGuard aSolarGuard; 510 ::osl::MutexGuard aGuard( m_aMutex ); 511 512 sal_Int32 nIndex = -1; 513 if ( m_pIconCtrl ) 514 { 515 ::vcl::ControlLayoutData aLayoutData; 516 Rectangle aItemRect = GetBoundingBox_Impl(); 517 m_pIconCtrl->RecordLayoutData( &aLayoutData, aItemRect ); 518 Point aPnt( VCLPoint( aPoint ) ); 519 aPnt += aItemRect.TopLeft(); 520 nIndex = aLayoutData.GetIndexForPoint( aPnt ); 521 522 long nLen = aLayoutData.m_aUnicodeBoundRects.size(); 523 for ( long i = 0; i < nLen; ++i ) 524 { 525 Rectangle aRect = aLayoutData.GetCharacterBounds(i); 526 sal_Bool bInside = aRect.IsInside( aPnt ); 527 528 if ( bInside ) 529 break; 530 } 531 } 532 533 return nIndex; 534 } 535 // ----------------------------------------------------------------------------- copyText(sal_Int32 nStartIndex,sal_Int32 nEndIndex)536 sal_Bool SAL_CALL AccessibleIconChoiceCtrlEntry::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) 537 { 538 ALBSolarGuard aSolarGuard; 539 ::osl::MutexGuard aGuard( m_aMutex ); 540 541 String sText = getText(); 542 if ( ( 0 > nStartIndex ) || ( sText.Len() <= nStartIndex ) 543 || ( 0 > nEndIndex ) || ( sText.Len() <= nEndIndex ) ) 544 throw IndexOutOfBoundsException(); 545 546 sal_Int32 nLen = nEndIndex - nStartIndex + 1; 547 ::svt::OStringTransfer::CopyString( sText.Copy( (sal_uInt16)nStartIndex, (sal_uInt16)nLen ), m_pIconCtrl ); 548 549 return sal_True; 550 } 551 // ----------------------------------------------------------------------------- 552 // XAccessibleEventBroadcaster 553 // ----------------------------------------------------------------------------- addEventListener(const Reference<XAccessibleEventListener> & xListener)554 void SAL_CALL AccessibleIconChoiceCtrlEntry::addEventListener( const Reference< XAccessibleEventListener >& xListener ) 555 { 556 if (xListener.is()) 557 { 558 ::osl::MutexGuard aGuard( m_aMutex ); 559 if (!m_nClientId) 560 m_nClientId = comphelper::AccessibleEventNotifier::registerClient( ); 561 comphelper::AccessibleEventNotifier::addEventListener( m_nClientId, xListener ); 562 } 563 } 564 // ----------------------------------------------------------------------------- removeEventListener(const Reference<XAccessibleEventListener> & xListener)565 void SAL_CALL AccessibleIconChoiceCtrlEntry::removeEventListener( const Reference< XAccessibleEventListener >& xListener ) 566 { 567 if (xListener.is()) 568 { 569 ::osl::MutexGuard aGuard( m_aMutex ); 570 571 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId, xListener ); 572 if ( !nListenerCount ) 573 { 574 // no listeners anymore 575 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client), 576 // and at least to us not firing any events anymore, in case somebody calls 577 // NotifyAccessibleEvent, again 578 sal_Int32 nId = m_nClientId; 579 m_nClientId = 0; 580 comphelper::AccessibleEventNotifier::revokeClient( nId ); 581 } 582 } 583 } 584 getCaretPosition()585 sal_Int32 SAL_CALL AccessibleIconChoiceCtrlEntry::getCaretPosition( ) 586 { 587 return -1; 588 } setCaretPosition(sal_Int32 nIndex)589 sal_Bool SAL_CALL AccessibleIconChoiceCtrlEntry::setCaretPosition ( sal_Int32 nIndex ) 590 { 591 ALBSolarGuard aSolarGuard; 592 ::osl::MutexGuard aGuard( m_aMutex ); 593 EnsureIsAlive(); 594 595 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) ) 596 throw IndexOutOfBoundsException(); 597 598 return sal_False; 599 } getCharacter(sal_Int32 nIndex)600 sal_Unicode SAL_CALL AccessibleIconChoiceCtrlEntry::getCharacter( sal_Int32 nIndex ) 601 { 602 ALBSolarGuard aSolarGuard; 603 ::osl::MutexGuard aGuard( m_aMutex ); 604 EnsureIsAlive(); 605 return OCommonAccessibleText::getCharacter( nIndex ); 606 } getCharacterAttributes(sal_Int32 nIndex,const::com::sun::star::uno::Sequence<::rtl::OUString> &)607 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL AccessibleIconChoiceCtrlEntry::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& ) 608 { 609 ALBSolarGuard aSolarGuard; 610 ::osl::MutexGuard aGuard( m_aMutex ); 611 EnsureIsAlive(); 612 613 ::rtl::OUString sText( implGetText() ); 614 615 if ( !implIsValidIndex( nIndex, sText.getLength() ) ) 616 throw IndexOutOfBoundsException(); 617 618 return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >(); 619 } getCharacterCount()620 sal_Int32 SAL_CALL AccessibleIconChoiceCtrlEntry::getCharacterCount( ) 621 { 622 ALBSolarGuard aSolarGuard; 623 ::osl::MutexGuard aGuard( m_aMutex ); 624 EnsureIsAlive(); 625 return OCommonAccessibleText::getCharacterCount( ); 626 } 627 getSelectedText()628 ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrlEntry::getSelectedText( ) 629 { 630 ALBSolarGuard aSolarGuard; 631 ::osl::MutexGuard aGuard( m_aMutex ); 632 EnsureIsAlive(); 633 return OCommonAccessibleText::getSelectedText( ); 634 } getSelectionStart()635 sal_Int32 SAL_CALL AccessibleIconChoiceCtrlEntry::getSelectionStart( ) 636 { 637 ALBSolarGuard aSolarGuard; 638 ::osl::MutexGuard aGuard( m_aMutex ); 639 EnsureIsAlive(); 640 return OCommonAccessibleText::getSelectionStart( ); 641 } getSelectionEnd()642 sal_Int32 SAL_CALL AccessibleIconChoiceCtrlEntry::getSelectionEnd( ) 643 { 644 ALBSolarGuard aSolarGuard; 645 ::osl::MutexGuard aGuard( m_aMutex ); 646 EnsureIsAlive(); 647 return OCommonAccessibleText::getSelectionEnd( ); 648 } setSelection(sal_Int32 nStartIndex,sal_Int32 nEndIndex)649 sal_Bool SAL_CALL AccessibleIconChoiceCtrlEntry::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) 650 { 651 ALBSolarGuard aSolarGuard; 652 ::osl::MutexGuard aGuard( m_aMutex ); 653 EnsureIsAlive(); 654 655 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) ) 656 throw IndexOutOfBoundsException(); 657 658 return sal_False; 659 } getText()660 ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrlEntry::getText( ) 661 { 662 ALBSolarGuard aSolarGuard; 663 ::osl::MutexGuard aGuard( m_aMutex ); 664 EnsureIsAlive(); 665 return OCommonAccessibleText::getText( ); 666 } getTextRange(sal_Int32 nStartIndex,sal_Int32 nEndIndex)667 ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrlEntry::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) 668 { 669 ALBSolarGuard aSolarGuard; 670 ::osl::MutexGuard aGuard( m_aMutex ); 671 EnsureIsAlive(); 672 return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex ); 673 } getTextAtIndex(sal_Int32 nIndex,sal_Int16 aTextType)674 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleIconChoiceCtrlEntry::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) 675 { 676 ALBSolarGuard aSolarGuard; 677 ::osl::MutexGuard aGuard( m_aMutex ); 678 EnsureIsAlive(); 679 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType); 680 } getTextBeforeIndex(sal_Int32 nIndex,sal_Int16 aTextType)681 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleIconChoiceCtrlEntry::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) 682 { 683 ALBSolarGuard aSolarGuard; 684 ::osl::MutexGuard aGuard( m_aMutex ); 685 EnsureIsAlive(); 686 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType); 687 } getTextBehindIndex(sal_Int32 nIndex,sal_Int16 aTextType)688 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleIconChoiceCtrlEntry::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) 689 { 690 ALBSolarGuard aSolarGuard; 691 ::osl::MutexGuard aGuard( m_aMutex ); 692 EnsureIsAlive(); 693 694 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType); 695 } 696 697 // ----------------------------------------------------------------------------- 698 // XAccessibleAction 699 // ----------------------------------------------------------------------------- getAccessibleActionCount()700 sal_Int32 SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleActionCount( ) 701 { 702 ::osl::MutexGuard aGuard( m_aMutex ); 703 704 // three actions supported 705 return ACCESSIBLE_ACTION_COUNT; 706 } 707 // ----------------------------------------------------------------------------- doAccessibleAction(sal_Int32 nIndex)708 sal_Bool SAL_CALL AccessibleIconChoiceCtrlEntry::doAccessibleAction( sal_Int32 nIndex ) 709 { 710 ALBSolarGuard aSolarGuard; 711 ::osl::MutexGuard aGuard( m_aMutex ); 712 713 sal_Bool bRet = sal_False; 714 checkActionIndex_Impl( nIndex ); 715 EnsureIsAlive(); 716 717 SvxIconChoiceCtrlEntry* pEntry = m_pIconCtrl->GetEntry( m_nIndex ); 718 if ( pEntry && !pEntry->IsSelected() ) 719 { 720 m_pIconCtrl->SetNoSelection(); 721 m_pIconCtrl->SetCursor( pEntry ); 722 bRet = sal_True; 723 } 724 725 return bRet; 726 } 727 // ----------------------------------------------------------------------------- getAccessibleActionDescription(sal_Int32 nIndex)728 ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrlEntry::getAccessibleActionDescription( sal_Int32 nIndex ) 729 { 730 ALBSolarGuard aSolarGuard; 731 ::osl::MutexGuard aGuard( m_aMutex ); 732 733 checkActionIndex_Impl( nIndex ); 734 EnsureIsAlive(); 735 736 static const ::rtl::OUString sActionDesc( RTL_CONSTASCII_USTRINGPARAM( "Select" ) ); 737 return sActionDesc; 738 } 739 // ----------------------------------------------------------------------------- getAccessibleActionKeyBinding(sal_Int32 nIndex)740 Reference< XAccessibleKeyBinding > AccessibleIconChoiceCtrlEntry::getAccessibleActionKeyBinding( sal_Int32 nIndex ) 741 { 742 ::osl::MutexGuard aGuard( m_aMutex ); 743 744 Reference< XAccessibleKeyBinding > xRet; 745 checkActionIndex_Impl( nIndex ); 746 // ... which key? 747 return xRet; 748 } 749 //........................................................................ 750 }// namespace accessibility 751 //........................................................................ 752