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/standard/vclxaccessiblestatusbaritem.hxx> 27 #include <toolkit/helper/externallock.hxx> 28 #include <toolkit/helper/convert.hxx> 29 #include <accessibility/helper/characterattributeshelper.hxx> 30 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 <com/sun/star/datatransfer/clipboard/XClipboard.hpp> 35 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp> 36 37 #include <unotools/accessiblestatesethelper.hxx> 38 #include <unotools/accessiblerelationsethelper.hxx> 39 #include <vcl/svapp.hxx> 40 #include <vcl/unohelp2.hxx> 41 #include <vcl/status.hxx> 42 #include <vcl/controllayout.hxx> 43 44 #include <memory> 45 46 47 using namespace ::com::sun::star::accessibility; 48 using namespace ::com::sun::star::uno; 49 using namespace ::com::sun::star::lang; 50 using namespace ::com::sun::star::beans; 51 using namespace ::com::sun::star; 52 using namespace ::comphelper; 53 54 55 // ----------------------------------------------------------------------------- 56 // class VCLXAccessibleStatusBarItem 57 // ----------------------------------------------------------------------------- 58 59 VCLXAccessibleStatusBarItem::VCLXAccessibleStatusBarItem( StatusBar* pStatusBar, sal_uInt16 nItemId ) 60 :AccessibleTextHelper_BASE( new VCLExternalSolarLock() ) 61 ,m_pStatusBar( pStatusBar ) 62 ,m_nItemId( nItemId ) 63 { 64 m_pExternalLock = static_cast< VCLExternalSolarLock* >( getExternalLock() ); 65 66 m_sItemName = GetItemName(); 67 m_sItemText = GetItemText(); 68 m_bShowing = IsShowing(); 69 } 70 71 // ----------------------------------------------------------------------------- 72 73 VCLXAccessibleStatusBarItem::~VCLXAccessibleStatusBarItem() 74 { 75 delete m_pExternalLock; 76 m_pExternalLock = NULL; 77 } 78 79 // ----------------------------------------------------------------------------- 80 81 sal_Bool VCLXAccessibleStatusBarItem::IsShowing() 82 { 83 sal_Bool bShowing = sal_False; 84 85 if ( m_pStatusBar ) 86 bShowing = m_pStatusBar->IsItemVisible( m_nItemId ); 87 88 return bShowing; 89 } 90 91 // ----------------------------------------------------------------------------- 92 93 void VCLXAccessibleStatusBarItem::SetShowing( sal_Bool bShowing ) 94 { 95 if ( m_bShowing != bShowing ) 96 { 97 Any aOldValue, aNewValue; 98 if ( m_bShowing ) 99 aOldValue <<= AccessibleStateType::SHOWING; 100 else 101 aNewValue <<= AccessibleStateType::SHOWING; 102 m_bShowing = bShowing; 103 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 104 } 105 } 106 107 // ----------------------------------------------------------------------------- 108 109 void VCLXAccessibleStatusBarItem::SetItemName( const ::rtl::OUString& sItemName ) 110 { 111 if ( !m_sItemName.equals( sItemName ) ) 112 { 113 Any aOldValue, aNewValue; 114 aOldValue <<= m_sItemName; 115 aNewValue <<= sItemName; 116 m_sItemName = sItemName; 117 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue ); 118 } 119 } 120 121 // ----------------------------------------------------------------------------- 122 123 ::rtl::OUString VCLXAccessibleStatusBarItem::GetItemName() 124 { 125 ::rtl::OUString sName; 126 if ( m_pStatusBar ) 127 sName = m_pStatusBar->GetAccessibleName( m_nItemId ); 128 129 return sName; 130 } 131 132 // ----------------------------------------------------------------------------- 133 134 void VCLXAccessibleStatusBarItem::SetItemText( const ::rtl::OUString& sItemText ) 135 { 136 Any aOldValue, aNewValue; 137 if ( implInitTextChangedEvent( m_sItemText, sItemText, aOldValue, aNewValue ) ) 138 { 139 m_sItemText = sItemText; 140 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED, aOldValue, aNewValue ); 141 } 142 } 143 144 // ----------------------------------------------------------------------------- 145 146 ::rtl::OUString VCLXAccessibleStatusBarItem::GetItemText() 147 { 148 ::rtl::OUString sText; 149 ::vcl::ControlLayoutData aLayoutData; 150 if ( m_pStatusBar ) 151 { 152 Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId ); 153 m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect ); 154 sText = aLayoutData.m_aDisplayText; 155 } 156 157 return sText; 158 } 159 160 // ----------------------------------------------------------------------------- 161 162 void VCLXAccessibleStatusBarItem::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) 163 { 164 rStateSet.AddState( AccessibleStateType::ENABLED ); 165 rStateSet.AddState( AccessibleStateType::SENSITIVE ); 166 167 rStateSet.AddState( AccessibleStateType::VISIBLE ); 168 169 if ( IsShowing() ) 170 rStateSet.AddState( AccessibleStateType::SHOWING ); 171 } 172 173 // ----------------------------------------------------------------------------- 174 // OCommonAccessibleComponent 175 // ----------------------------------------------------------------------------- 176 177 awt::Rectangle VCLXAccessibleStatusBarItem::implGetBounds() throw (RuntimeException) 178 { 179 awt::Rectangle aBounds( 0, 0, 0, 0 ); 180 181 if ( m_pStatusBar ) 182 aBounds = AWTRectangle( m_pStatusBar->GetItemRect( m_nItemId ) ); 183 184 return aBounds; 185 } 186 187 // ----------------------------------------------------------------------------- 188 // OCommonAccessibleText 189 // ----------------------------------------------------------------------------- 190 191 ::rtl::OUString VCLXAccessibleStatusBarItem::implGetText() 192 { 193 return GetItemText(); 194 } 195 196 // ----------------------------------------------------------------------------- 197 198 lang::Locale VCLXAccessibleStatusBarItem::implGetLocale() 199 { 200 return Application::GetSettings().GetLocale(); 201 } 202 203 // ----------------------------------------------------------------------------- 204 205 void VCLXAccessibleStatusBarItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) 206 { 207 nStartIndex = 0; 208 nEndIndex = 0; 209 } 210 211 // ----------------------------------------------------------------------------- 212 // XInterface 213 // ----------------------------------------------------------------------------- 214 215 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleStatusBarItem, AccessibleTextHelper_BASE, VCLXAccessibleStatusBarItem_BASE ) 216 217 // ----------------------------------------------------------------------------- 218 // XTypeProvider 219 // ----------------------------------------------------------------------------- 220 221 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleStatusBarItem, AccessibleTextHelper_BASE, VCLXAccessibleStatusBarItem_BASE ) 222 223 // ----------------------------------------------------------------------------- 224 // XComponent 225 // ----------------------------------------------------------------------------- 226 227 void VCLXAccessibleStatusBarItem::disposing() 228 { 229 AccessibleTextHelper_BASE::disposing(); 230 231 m_pStatusBar = NULL; 232 m_sItemName = ::rtl::OUString(); 233 m_sItemText = ::rtl::OUString(); 234 } 235 236 // ----------------------------------------------------------------------------- 237 // XServiceInfo 238 // ----------------------------------------------------------------------------- 239 240 ::rtl::OUString VCLXAccessibleStatusBarItem::getImplementationName() throw (RuntimeException) 241 { 242 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleStatusBarItem" ); 243 } 244 245 // ----------------------------------------------------------------------------- 246 247 sal_Bool VCLXAccessibleStatusBarItem::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) 248 { 249 Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); 250 const ::rtl::OUString* pNames = aNames.getConstArray(); 251 const ::rtl::OUString* pEnd = pNames + aNames.getLength(); 252 for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) 253 ; 254 255 return pNames != pEnd; 256 } 257 258 // ----------------------------------------------------------------------------- 259 260 Sequence< ::rtl::OUString > VCLXAccessibleStatusBarItem::getSupportedServiceNames() throw (RuntimeException) 261 { 262 Sequence< ::rtl::OUString > aNames(1); 263 aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleStatusBarItem" ); 264 return aNames; 265 } 266 267 // ----------------------------------------------------------------------------- 268 // XAccessible 269 // ----------------------------------------------------------------------------- 270 271 Reference< XAccessibleContext > VCLXAccessibleStatusBarItem::getAccessibleContext( ) throw (RuntimeException) 272 { 273 OExternalLockGuard aGuard( this ); 274 275 return this; 276 } 277 278 // ----------------------------------------------------------------------------- 279 // XAccessibleContext 280 // ----------------------------------------------------------------------------- 281 282 sal_Int32 VCLXAccessibleStatusBarItem::getAccessibleChildCount() throw (RuntimeException) 283 { 284 OExternalLockGuard aGuard( this ); 285 286 return 0; 287 } 288 289 // ----------------------------------------------------------------------------- 290 291 Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException) 292 { 293 OExternalLockGuard aGuard( this ); 294 295 if ( i < 0 || i >= getAccessibleChildCount() ) 296 throw IndexOutOfBoundsException(); 297 298 return Reference< XAccessible >(); 299 } 300 301 // ----------------------------------------------------------------------------- 302 303 Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleParent( ) throw (RuntimeException) 304 { 305 OExternalLockGuard aGuard( this ); 306 307 Reference< XAccessible > xParent; 308 if ( m_pStatusBar ) 309 xParent = m_pStatusBar->GetAccessible(); 310 311 return xParent; 312 } 313 314 // ----------------------------------------------------------------------------- 315 316 sal_Int32 VCLXAccessibleStatusBarItem::getAccessibleIndexInParent( ) throw (RuntimeException) 317 { 318 OExternalLockGuard aGuard( this ); 319 320 sal_Int32 nIndexInParent = -1; 321 if ( m_pStatusBar ) 322 nIndexInParent = m_pStatusBar->GetItemPos( m_nItemId ); 323 324 return nIndexInParent; 325 } 326 327 // ----------------------------------------------------------------------------- 328 329 sal_Int16 VCLXAccessibleStatusBarItem::getAccessibleRole( ) throw (RuntimeException) 330 { 331 OExternalLockGuard aGuard( this ); 332 333 return AccessibleRole::LABEL; 334 } 335 336 // ----------------------------------------------------------------------------- 337 338 ::rtl::OUString VCLXAccessibleStatusBarItem::getAccessibleDescription( ) throw (RuntimeException) 339 { 340 OExternalLockGuard aGuard( this ); 341 342 ::rtl::OUString sDescription; 343 if ( m_pStatusBar ) 344 sDescription = m_pStatusBar->GetHelpText( m_nItemId ); 345 346 return sDescription; 347 } 348 349 // ----------------------------------------------------------------------------- 350 351 ::rtl::OUString VCLXAccessibleStatusBarItem::getAccessibleName( ) throw (RuntimeException) 352 { 353 OExternalLockGuard aGuard( this ); 354 355 return GetItemName(); 356 } 357 358 // ----------------------------------------------------------------------------- 359 360 Reference< XAccessibleRelationSet > VCLXAccessibleStatusBarItem::getAccessibleRelationSet( ) throw (RuntimeException) 361 { 362 OExternalLockGuard aGuard( this ); 363 364 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper; 365 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper; 366 return xSet; 367 } 368 369 // ----------------------------------------------------------------------------- 370 371 Reference< XAccessibleStateSet > VCLXAccessibleStatusBarItem::getAccessibleStateSet( ) throw (RuntimeException) 372 { 373 OExternalLockGuard aGuard( this ); 374 375 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper; 376 Reference< XAccessibleStateSet > xSet = pStateSetHelper; 377 378 if ( !rBHelper.bDisposed && !rBHelper.bInDispose ) 379 { 380 FillAccessibleStateSet( *pStateSetHelper ); 381 } 382 else 383 { 384 pStateSetHelper->AddState( AccessibleStateType::DEFUNC ); 385 } 386 387 return xSet; 388 } 389 390 // ----------------------------------------------------------------------------- 391 392 Locale VCLXAccessibleStatusBarItem::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException) 393 { 394 OExternalLockGuard aGuard( this ); 395 396 return Application::GetSettings().GetLocale(); 397 } 398 399 // ----------------------------------------------------------------------------- 400 // XAccessibleComponent 401 // ----------------------------------------------------------------------------- 402 403 Reference< XAccessible > VCLXAccessibleStatusBarItem::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException) 404 { 405 OExternalLockGuard aGuard( this ); 406 407 return Reference< XAccessible >(); 408 } 409 410 // ----------------------------------------------------------------------------- 411 412 void VCLXAccessibleStatusBarItem::grabFocus( ) throw (RuntimeException) 413 { 414 // no focus for status bar items 415 } 416 417 // ----------------------------------------------------------------------------- 418 419 sal_Int32 VCLXAccessibleStatusBarItem::getForeground( ) throw (RuntimeException) 420 { 421 OExternalLockGuard aGuard( this ); 422 423 sal_Int32 nColor = 0; 424 Reference< XAccessible > xParent = getAccessibleParent(); 425 if ( xParent.is() ) 426 { 427 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY ); 428 if ( xParentComp.is() ) 429 nColor = xParentComp->getForeground(); 430 } 431 432 return nColor; 433 } 434 435 // ----------------------------------------------------------------------------- 436 437 sal_Int32 VCLXAccessibleStatusBarItem::getBackground( ) throw (RuntimeException) 438 { 439 OExternalLockGuard aGuard( this ); 440 441 sal_Int32 nColor = 0; 442 Reference< XAccessible > xParent = getAccessibleParent(); 443 if ( xParent.is() ) 444 { 445 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY ); 446 if ( xParentComp.is() ) 447 nColor = xParentComp->getBackground(); 448 } 449 450 return nColor; 451 } 452 453 // ----------------------------------------------------------------------------- 454 // XAccessibleExtendedComponent 455 // ----------------------------------------------------------------------------- 456 457 Reference< awt::XFont > VCLXAccessibleStatusBarItem::getFont( ) throw (RuntimeException) 458 { 459 OExternalLockGuard aGuard( this ); 460 461 Reference< awt::XFont > xFont; 462 Reference< XAccessible > xParent = getAccessibleParent(); 463 if ( xParent.is() ) 464 { 465 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY ); 466 if ( xParentComp.is() ) 467 xFont = xParentComp->getFont(); 468 } 469 470 return xFont; 471 } 472 473 // ----------------------------------------------------------------------------- 474 475 ::rtl::OUString VCLXAccessibleStatusBarItem::getTitledBorderText( ) throw (RuntimeException) 476 { 477 OExternalLockGuard aGuard( this ); 478 479 return GetItemText(); 480 } 481 482 // ----------------------------------------------------------------------------- 483 484 ::rtl::OUString VCLXAccessibleStatusBarItem::getToolTipText( ) throw (RuntimeException) 485 { 486 OExternalLockGuard aGuard( this ); 487 488 return ::rtl::OUString(); 489 } 490 491 // ----------------------------------------------------------------------------- 492 // XAccessibleText 493 // ----------------------------------------------------------------------------- 494 495 sal_Int32 VCLXAccessibleStatusBarItem::getCaretPosition() throw (RuntimeException) 496 { 497 OExternalLockGuard aGuard( this ); 498 499 return -1; 500 } 501 502 // ----------------------------------------------------------------------------- 503 504 sal_Bool VCLXAccessibleStatusBarItem::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 505 { 506 OExternalLockGuard aGuard( this ); 507 508 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) ) 509 throw IndexOutOfBoundsException(); 510 511 return sal_False; 512 } 513 514 // ----------------------------------------------------------------------------- 515 516 Sequence< PropertyValue > VCLXAccessibleStatusBarItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& aRequestedAttributes ) throw (IndexOutOfBoundsException, RuntimeException) 517 { 518 OExternalLockGuard aGuard( this ); 519 520 Sequence< PropertyValue > aValues; 521 ::rtl::OUString sText( implGetText() ); 522 523 if ( !implIsValidIndex( nIndex, sText.getLength() ) ) 524 throw IndexOutOfBoundsException(); 525 526 if ( m_pStatusBar ) 527 { 528 Font aFont = m_pStatusBar->GetFont(); 529 sal_Int32 nBackColor = getBackground(); 530 sal_Int32 nColor = getForeground(); 531 ::std::auto_ptr< CharacterAttributesHelper > pHelper( new CharacterAttributesHelper( aFont, nBackColor, nColor ) ); 532 aValues = pHelper->GetCharacterAttributes( aRequestedAttributes ); 533 } 534 535 return aValues; 536 } 537 538 // ----------------------------------------------------------------------------- 539 540 awt::Rectangle VCLXAccessibleStatusBarItem::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 541 { 542 OExternalLockGuard aGuard( this ); 543 544 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) ) 545 throw IndexOutOfBoundsException(); 546 547 awt::Rectangle aBounds( 0, 0, 0, 0 ); 548 if ( m_pStatusBar ) 549 { 550 ::vcl::ControlLayoutData aLayoutData; 551 Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId ); 552 m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect ); 553 Rectangle aCharRect = aLayoutData.GetCharacterBounds( nIndex ); 554 aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() ); 555 aBounds = AWTRectangle( aCharRect ); 556 } 557 558 return aBounds; 559 } 560 561 // ----------------------------------------------------------------------------- 562 563 sal_Int32 VCLXAccessibleStatusBarItem::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException) 564 { 565 OExternalLockGuard aGuard( this ); 566 567 sal_Int32 nIndex = -1; 568 if ( m_pStatusBar ) 569 { 570 ::vcl::ControlLayoutData aLayoutData; 571 Rectangle aItemRect = m_pStatusBar->GetItemRect( m_nItemId ); 572 m_pStatusBar->RecordLayoutData( &aLayoutData, aItemRect ); 573 Point aPnt( VCLPoint( aPoint ) ); 574 aPnt += aItemRect.TopLeft(); 575 nIndex = aLayoutData.GetIndexForPoint( aPnt ); 576 } 577 578 return nIndex; 579 } 580 581 // ----------------------------------------------------------------------------- 582 583 sal_Bool VCLXAccessibleStatusBarItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 584 { 585 OExternalLockGuard aGuard( this ); 586 587 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) ) 588 throw IndexOutOfBoundsException(); 589 590 return sal_False; 591 } 592 593 // ----------------------------------------------------------------------------- 594 595 sal_Bool VCLXAccessibleStatusBarItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException) 596 { 597 OExternalLockGuard aGuard( this ); 598 599 sal_Bool bReturn = sal_False; 600 601 if ( m_pStatusBar ) 602 { 603 Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pStatusBar->GetClipboard(); 604 if ( xClipboard.is() ) 605 { 606 ::rtl::OUString sText( getTextRange( nStartIndex, nEndIndex ) ); 607 608 ::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText ); 609 const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 610 xClipboard->setContents( pDataObj, NULL ); 611 612 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY ); 613 if( xFlushableClipboard.is() ) 614 xFlushableClipboard->flushClipboard(); 615 616 Application::AcquireSolarMutex( nRef ); 617 618 bReturn = sal_True; 619 } 620 } 621 622 return bReturn; 623 } 624 625 // ----------------------------------------------------------------------------- 626