1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_accessibility.hxx" 30 #include <accessibility/extended/accessibletabbar.hxx> 31 #include <svtools/tabbar.hxx> 32 #include <accessibility/extended/accessibletabbarpagelist.hxx> 33 #include <com/sun/star/accessibility/AccessibleEventId.hpp> 34 #include <com/sun/star/accessibility/AccessibleRole.hpp> 35 #include <com/sun/star/accessibility/AccessibleStateType.hpp> 36 #include <unotools/accessiblestatesethelper.hxx> 37 #include <unotools/accessiblerelationsethelper.hxx> 38 #include <vcl/svapp.hxx> 39 #include <toolkit/awt/vclxfont.hxx> 40 #include <toolkit/helper/convert.hxx> 41 42 #include <vector> 43 44 45 //......................................................................... 46 namespace accessibility 47 { 48 //......................................................................... 49 50 using namespace ::com::sun::star; 51 using namespace ::com::sun::star::uno; 52 using namespace ::com::sun::star::lang; 53 using namespace ::com::sun::star::accessibility; 54 using namespace ::comphelper; 55 56 DBG_NAME( AccessibleTabBar ) 57 58 // ---------------------------------------------------- 59 // class AccessibleTabBar 60 // ---------------------------------------------------- 61 62 AccessibleTabBar::AccessibleTabBar( TabBar* pTabBar ) 63 :AccessibleTabBarBase( pTabBar ) 64 { 65 DBG_CTOR( AccessibleTabBar, NULL ); 66 67 if ( m_pTabBar ) 68 m_aAccessibleChildren.assign( m_pTabBar->GetAccessibleChildWindowCount() + 1, Reference< XAccessible >() ); 69 } 70 71 // ----------------------------------------------------------------------------- 72 73 AccessibleTabBar::~AccessibleTabBar() 74 { 75 DBG_DTOR( AccessibleTabBar, NULL ); 76 } 77 78 // ----------------------------------------------------------------------------- 79 80 void AccessibleTabBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) 81 { 82 Any aOldValue, aNewValue; 83 84 switch ( rVclWindowEvent.GetId() ) 85 { 86 case VCLEVENT_WINDOW_ENABLED: 87 { 88 aNewValue <<= AccessibleStateType::SENSITIVE; 89 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 90 aNewValue <<= AccessibleStateType::ENABLED; 91 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 92 } 93 break; 94 case VCLEVENT_WINDOW_DISABLED: 95 { 96 aOldValue <<= AccessibleStateType::ENABLED; 97 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 98 aOldValue <<= AccessibleStateType::SENSITIVE; 99 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 100 } 101 break; 102 case VCLEVENT_WINDOW_GETFOCUS: 103 { 104 aNewValue <<= AccessibleStateType::FOCUSED; 105 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 106 } 107 break; 108 case VCLEVENT_WINDOW_LOSEFOCUS: 109 { 110 aOldValue <<= AccessibleStateType::FOCUSED; 111 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 112 } 113 break; 114 case VCLEVENT_WINDOW_SHOW: 115 { 116 aNewValue <<= AccessibleStateType::SHOWING; 117 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 118 } 119 break; 120 case VCLEVENT_WINDOW_HIDE: 121 { 122 aOldValue <<= AccessibleStateType::SHOWING; 123 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 124 } 125 break; 126 default: 127 { 128 AccessibleTabBarBase::ProcessWindowEvent( rVclWindowEvent ); 129 } 130 break; 131 } 132 } 133 134 // ----------------------------------------------------------------------------- 135 136 void AccessibleTabBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) 137 { 138 if ( m_pTabBar ) 139 { 140 if ( m_pTabBar->IsEnabled() ) 141 { 142 rStateSet.AddState( AccessibleStateType::ENABLED ); 143 rStateSet.AddState( AccessibleStateType::SENSITIVE ); 144 } 145 146 rStateSet.AddState( AccessibleStateType::FOCUSABLE ); 147 148 if ( m_pTabBar->HasFocus() ) 149 rStateSet.AddState( AccessibleStateType::FOCUSED ); 150 151 rStateSet.AddState( AccessibleStateType::VISIBLE ); 152 153 if ( m_pTabBar->IsVisible() ) 154 rStateSet.AddState( AccessibleStateType::SHOWING ); 155 156 if ( m_pTabBar->GetStyle() & WB_SIZEABLE ) 157 rStateSet.AddState( AccessibleStateType::RESIZABLE ); 158 } 159 } 160 161 // ----------------------------------------------------------------------------- 162 // OCommonAccessibleComponent 163 // ----------------------------------------------------------------------------- 164 165 awt::Rectangle AccessibleTabBar::implGetBounds() throw (RuntimeException) 166 { 167 awt::Rectangle aBounds; 168 if ( m_pTabBar ) 169 aBounds = AWTRectangle( Rectangle( m_pTabBar->GetPosPixel(), m_pTabBar->GetSizePixel() ) ); 170 171 return aBounds; 172 } 173 174 // ----------------------------------------------------------------------------- 175 // XInterface 176 // ----------------------------------------------------------------------------- 177 178 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBar, AccessibleExtendedComponentHelper_BASE, AccessibleTabBar_BASE ) 179 180 // ----------------------------------------------------------------------------- 181 // XTypeProvider 182 // ----------------------------------------------------------------------------- 183 184 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBar, AccessibleExtendedComponentHelper_BASE, AccessibleTabBar_BASE ) 185 186 // ----------------------------------------------------------------------------- 187 // XComponent 188 // ----------------------------------------------------------------------------- 189 190 void AccessibleTabBar::disposing() 191 { 192 AccessibleTabBarBase::disposing(); 193 194 // dispose all children 195 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i ) 196 { 197 Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY ); 198 if ( xComponent.is() ) 199 xComponent->dispose(); 200 } 201 m_aAccessibleChildren.clear(); 202 } 203 204 // ----------------------------------------------------------------------------- 205 // XServiceInfo 206 // ----------------------------------------------------------------------------- 207 208 ::rtl::OUString AccessibleTabBar::getImplementationName() throw (RuntimeException) 209 { 210 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.svtools.AccessibleTabBar" ); 211 } 212 213 // ----------------------------------------------------------------------------- 214 215 sal_Bool AccessibleTabBar::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) 216 { 217 Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); 218 const ::rtl::OUString* pNames = aNames.getConstArray(); 219 const ::rtl::OUString* pEnd = pNames + aNames.getLength(); 220 for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) 221 ; 222 223 return pNames != pEnd; 224 } 225 226 // ----------------------------------------------------------------------------- 227 228 Sequence< ::rtl::OUString > AccessibleTabBar::getSupportedServiceNames() throw (RuntimeException) 229 { 230 Sequence< ::rtl::OUString > aNames(1); 231 aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleTabBar" ); 232 return aNames; 233 } 234 235 // ----------------------------------------------------------------------------- 236 // XAccessible 237 // ----------------------------------------------------------------------------- 238 239 Reference< XAccessibleContext > AccessibleTabBar::getAccessibleContext( ) throw (RuntimeException) 240 { 241 OExternalLockGuard aGuard( this ); 242 243 return this; 244 } 245 246 // ----------------------------------------------------------------------------- 247 // XAccessibleContext 248 // ----------------------------------------------------------------------------- 249 250 sal_Int32 AccessibleTabBar::getAccessibleChildCount() throw (RuntimeException) 251 { 252 OExternalLockGuard aGuard( this ); 253 254 return m_aAccessibleChildren.size(); 255 } 256 257 // ----------------------------------------------------------------------------- 258 259 Reference< XAccessible > AccessibleTabBar::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException) 260 { 261 OExternalLockGuard aGuard( this ); 262 263 if ( i < 0 || i >= getAccessibleChildCount() ) 264 throw IndexOutOfBoundsException(); 265 266 Reference< XAccessible > xChild = m_aAccessibleChildren[i]; 267 if ( !xChild.is() ) 268 { 269 if ( m_pTabBar ) 270 { 271 sal_Int32 nCount = m_pTabBar->GetAccessibleChildWindowCount(); 272 273 if ( i < nCount ) 274 { 275 Window* pChild = m_pTabBar->GetAccessibleChildWindow( (sal_uInt16)i ); 276 if ( pChild ) 277 xChild = pChild->GetAccessible(); 278 } 279 else if ( i == nCount ) 280 { 281 xChild = new AccessibleTabBarPageList( m_pTabBar, i ); 282 } 283 284 // insert into child list 285 m_aAccessibleChildren[i] = xChild; 286 } 287 } 288 289 return xChild; 290 } 291 292 // ----------------------------------------------------------------------------- 293 294 Reference< XAccessible > AccessibleTabBar::getAccessibleParent( ) throw (RuntimeException) 295 { 296 OExternalLockGuard aGuard( this ); 297 298 Reference< XAccessible > xParent; 299 if ( m_pTabBar ) 300 { 301 Window* pParent = m_pTabBar->GetAccessibleParentWindow(); 302 if ( pParent ) 303 xParent = pParent->GetAccessible(); 304 } 305 306 return xParent; 307 } 308 309 // ----------------------------------------------------------------------------- 310 311 sal_Int32 AccessibleTabBar::getAccessibleIndexInParent( ) throw (RuntimeException) 312 { 313 OExternalLockGuard aGuard( this ); 314 315 sal_Int32 nIndexInParent = -1; 316 if ( m_pTabBar ) 317 { 318 Window* pParent = m_pTabBar->GetAccessibleParentWindow(); 319 if ( pParent ) 320 { 321 for ( sal_uInt16 i = 0, nCount = pParent->GetAccessibleChildWindowCount(); i < nCount; ++i ) 322 { 323 Window* pChild = pParent->GetAccessibleChildWindow( i ); 324 if ( pChild == static_cast< Window* >( m_pTabBar ) ) 325 { 326 nIndexInParent = i; 327 break; 328 } 329 } 330 } 331 } 332 333 return nIndexInParent; 334 } 335 336 // ----------------------------------------------------------------------------- 337 338 sal_Int16 AccessibleTabBar::getAccessibleRole( ) throw (RuntimeException) 339 { 340 OExternalLockGuard aGuard( this ); 341 342 return AccessibleRole::PANEL; 343 } 344 345 // ----------------------------------------------------------------------------- 346 347 ::rtl::OUString AccessibleTabBar::getAccessibleDescription( ) throw (RuntimeException) 348 { 349 OExternalLockGuard aGuard( this ); 350 351 ::rtl::OUString sDescription; 352 if ( m_pTabBar ) 353 sDescription = m_pTabBar->GetAccessibleDescription(); 354 355 return sDescription; 356 } 357 358 // ----------------------------------------------------------------------------- 359 360 ::rtl::OUString AccessibleTabBar::getAccessibleName( ) throw (RuntimeException) 361 { 362 OExternalLockGuard aGuard( this ); 363 364 ::rtl::OUString sName; 365 if ( m_pTabBar ) 366 sName = m_pTabBar->GetAccessibleName(); 367 368 return sName; 369 } 370 371 // ----------------------------------------------------------------------------- 372 373 Reference< XAccessibleRelationSet > AccessibleTabBar::getAccessibleRelationSet( ) throw (RuntimeException) 374 { 375 OExternalLockGuard aGuard( this ); 376 377 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper; 378 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper; 379 return xSet; 380 } 381 382 // ----------------------------------------------------------------------------- 383 384 Reference< XAccessibleStateSet > AccessibleTabBar::getAccessibleStateSet( ) throw (RuntimeException) 385 { 386 OExternalLockGuard aGuard( this ); 387 388 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper; 389 Reference< XAccessibleStateSet > xSet = pStateSetHelper; 390 391 if ( !rBHelper.bDisposed && !rBHelper.bInDispose ) 392 { 393 FillAccessibleStateSet( *pStateSetHelper ); 394 } 395 else 396 { 397 pStateSetHelper->AddState( AccessibleStateType::DEFUNC ); 398 } 399 400 return xSet; 401 } 402 403 // ----------------------------------------------------------------------------- 404 405 Locale AccessibleTabBar::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException) 406 { 407 OExternalLockGuard aGuard( this ); 408 409 return Application::GetSettings().GetLocale(); 410 } 411 412 // ----------------------------------------------------------------------------- 413 // XAccessibleComponent 414 // ----------------------------------------------------------------------------- 415 416 Reference< XAccessible > AccessibleTabBar::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException) 417 { 418 OExternalLockGuard aGuard( this ); 419 420 Reference< XAccessible > xChild; 421 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i ) 422 { 423 Reference< XAccessible > xAcc = getAccessibleChild( i ); 424 if ( xAcc.is() ) 425 { 426 Reference< XAccessibleComponent > xComp( xAcc->getAccessibleContext(), UNO_QUERY ); 427 if ( xComp.is() ) 428 { 429 Rectangle aRect = VCLRectangle( xComp->getBounds() ); 430 Point aPos = VCLPoint( rPoint ); 431 if ( aRect.IsInside( aPos ) ) 432 { 433 xChild = xAcc; 434 break; 435 } 436 } 437 } 438 } 439 440 return xChild; 441 } 442 443 // ----------------------------------------------------------------------------- 444 445 void AccessibleTabBar::grabFocus( ) throw (RuntimeException) 446 { 447 OExternalLockGuard aGuard( this ); 448 449 if ( m_pTabBar ) 450 m_pTabBar->GrabFocus(); 451 } 452 453 // ----------------------------------------------------------------------------- 454 455 sal_Int32 AccessibleTabBar::getForeground( ) throw (RuntimeException) 456 { 457 OExternalLockGuard aGuard( this ); 458 459 sal_Int32 nColor = 0; 460 if ( m_pTabBar ) 461 { 462 if ( m_pTabBar->IsControlForeground() ) 463 nColor = m_pTabBar->GetControlForeground().GetColor(); 464 else 465 { 466 Font aFont; 467 if ( m_pTabBar->IsControlFont() ) 468 aFont = m_pTabBar->GetControlFont(); 469 else 470 aFont = m_pTabBar->GetFont(); 471 nColor = aFont.GetColor().GetColor(); 472 } 473 } 474 475 return nColor; 476 } 477 478 // ----------------------------------------------------------------------------- 479 480 sal_Int32 AccessibleTabBar::getBackground( ) throw (RuntimeException) 481 { 482 OExternalLockGuard aGuard( this ); 483 484 sal_Int32 nColor = 0; 485 if ( m_pTabBar ) 486 { 487 if ( m_pTabBar->IsControlBackground() ) 488 nColor = m_pTabBar->GetControlBackground().GetColor(); 489 else 490 nColor = m_pTabBar->GetBackground().GetColor().GetColor(); 491 } 492 493 return nColor; 494 } 495 496 // ----------------------------------------------------------------------------- 497 // XAccessibleExtendedComponent 498 // ----------------------------------------------------------------------------- 499 500 Reference< awt::XFont > AccessibleTabBar::getFont( ) throw (RuntimeException) 501 { 502 OExternalLockGuard aGuard( this ); 503 504 Reference< awt::XFont > xFont; 505 if ( m_pTabBar ) 506 { 507 Reference< awt::XDevice > xDev( m_pTabBar->GetComponentInterface(), UNO_QUERY ); 508 if ( xDev.is() ) 509 { 510 Font aFont; 511 if ( m_pTabBar->IsControlFont() ) 512 aFont = m_pTabBar->GetControlFont(); 513 else 514 aFont = m_pTabBar->GetFont(); 515 VCLXFont* pVCLXFont = new VCLXFont; 516 pVCLXFont->Init( *xDev.get(), aFont ); 517 xFont = pVCLXFont; 518 } 519 } 520 521 return xFont; 522 } 523 524 // ----------------------------------------------------------------------------- 525 526 ::rtl::OUString AccessibleTabBar::getTitledBorderText( ) throw (RuntimeException) 527 { 528 OExternalLockGuard aGuard( this ); 529 530 ::rtl::OUString sText; 531 if ( m_pTabBar ) 532 sText = m_pTabBar->GetText(); 533 534 return sText; 535 } 536 537 // ----------------------------------------------------------------------------- 538 539 ::rtl::OUString AccessibleTabBar::getToolTipText( ) throw (RuntimeException) 540 { 541 OExternalLockGuard aGuard( this ); 542 543 ::rtl::OUString sText; 544 if ( m_pTabBar ) 545 sText = m_pTabBar->GetQuickHelpText(); 546 547 return sText; 548 } 549 550 // ----------------------------------------------------------------------------- 551 552 //......................................................................... 553 } // namespace accessibility 554 //......................................................................... 555