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/accessibletabbarpage.hxx> 31 #include <svtools/tabbar.hxx> 32 #include <com/sun/star/accessibility/AccessibleEventId.hpp> 33 #include <com/sun/star/accessibility/AccessibleRole.hpp> 34 #include <com/sun/star/accessibility/AccessibleStateType.hpp> 35 #include <unotools/accessiblestatesethelper.hxx> 36 #include <unotools/accessiblerelationsethelper.hxx> 37 #include <vcl/svapp.hxx> 38 #include <toolkit/helper/convert.hxx> 39 40 41 //......................................................................... 42 namespace accessibility 43 { 44 //......................................................................... 45 46 using namespace ::com::sun::star::accessibility; 47 using namespace ::com::sun::star::uno; 48 using namespace ::com::sun::star::lang; 49 using namespace ::com::sun::star; 50 using namespace ::comphelper; 51 52 // ----------------------------------------------------------------------------- 53 // class AccessibleTabBarPage 54 // ----------------------------------------------------------------------------- 55 56 AccessibleTabBarPage::AccessibleTabBarPage( TabBar* pTabBar, sal_uInt16 nPageId, const Reference< XAccessible >& rxParent ) 57 :AccessibleTabBarBase( pTabBar ) 58 ,m_nPageId( nPageId ) 59 ,m_xParent( rxParent ) 60 { 61 m_bEnabled = IsEnabled(); 62 m_bShowing = IsShowing(); 63 m_bSelected = IsSelected(); 64 65 if ( m_pTabBar ) 66 m_sPageText = m_pTabBar->GetPageText( m_nPageId ); 67 } 68 69 // ----------------------------------------------------------------------------- 70 71 AccessibleTabBarPage::~AccessibleTabBarPage() 72 { 73 } 74 75 // ----------------------------------------------------------------------------- 76 77 sal_Bool AccessibleTabBarPage::IsEnabled() 78 { 79 OExternalLockGuard aGuard( this ); 80 81 sal_Bool bEnabled = sal_False; 82 if ( m_pTabBar ) 83 bEnabled = m_pTabBar->IsPageEnabled( m_nPageId ); 84 85 return bEnabled; 86 } 87 88 // ----------------------------------------------------------------------------- 89 90 sal_Bool AccessibleTabBarPage::IsShowing() 91 { 92 sal_Bool bShowing = sal_False; 93 94 if ( m_pTabBar && m_pTabBar->IsVisible() ) 95 bShowing = sal_True; 96 97 return bShowing; 98 } 99 100 // ----------------------------------------------------------------------------- 101 102 sal_Bool AccessibleTabBarPage::IsSelected() 103 { 104 sal_Bool bSelected = sal_False; 105 106 if ( m_pTabBar && m_pTabBar->GetCurPageId() == m_nPageId ) 107 bSelected = sal_True; 108 109 return bSelected; 110 } 111 112 // ----------------------------------------------------------------------------- 113 114 void AccessibleTabBarPage::SetEnabled( sal_Bool bEnabled ) 115 { 116 if ( m_bEnabled != bEnabled ) 117 { 118 Any aOldValue[2], aNewValue[2]; 119 if ( m_bEnabled ) 120 { 121 aOldValue[0] <<= AccessibleStateType::SENSITIVE; 122 aOldValue[1] <<= AccessibleStateType::ENABLED; 123 } 124 else 125 { 126 127 aNewValue[0] <<= AccessibleStateType::ENABLED; 128 aNewValue[1] <<= AccessibleStateType::SENSITIVE; 129 } 130 m_bEnabled = bEnabled; 131 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[0], aNewValue[0] ); 132 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[1], aNewValue[1] ); 133 } 134 } 135 136 // ----------------------------------------------------------------------------- 137 138 void AccessibleTabBarPage::SetShowing( sal_Bool bShowing ) 139 { 140 if ( m_bShowing != bShowing ) 141 { 142 Any aOldValue, aNewValue; 143 if ( m_bShowing ) 144 aOldValue <<= AccessibleStateType::SHOWING; 145 else 146 aNewValue <<= AccessibleStateType::SHOWING; 147 m_bShowing = bShowing; 148 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 149 } 150 } 151 152 // ----------------------------------------------------------------------------- 153 154 void AccessibleTabBarPage::SetSelected( sal_Bool bSelected ) 155 { 156 if ( m_bSelected != bSelected ) 157 { 158 Any aOldValue, aNewValue; 159 if ( m_bSelected ) 160 aOldValue <<= AccessibleStateType::SELECTED; 161 else 162 aNewValue <<= AccessibleStateType::SELECTED; 163 m_bSelected = bSelected; 164 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue ); 165 } 166 } 167 168 // ----------------------------------------------------------------------------- 169 170 void AccessibleTabBarPage::SetPageText( const ::rtl::OUString& sPageText ) 171 { 172 if ( !m_sPageText.equals( sPageText ) ) 173 { 174 Any aOldValue, aNewValue; 175 aOldValue <<= m_sPageText; 176 aNewValue <<= sPageText; 177 m_sPageText = sPageText; 178 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue ); 179 } 180 } 181 182 // ----------------------------------------------------------------------------- 183 184 void AccessibleTabBarPage::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) 185 { 186 if ( IsEnabled() ) 187 { 188 rStateSet.AddState( AccessibleStateType::ENABLED ); 189 rStateSet.AddState( AccessibleStateType::SENSITIVE ); 190 } 191 192 rStateSet.AddState( AccessibleStateType::VISIBLE ); 193 194 if ( IsShowing() ) 195 rStateSet.AddState( AccessibleStateType::SHOWING ); 196 197 rStateSet.AddState( AccessibleStateType::SELECTABLE ); 198 199 if ( IsSelected() ) 200 rStateSet.AddState( AccessibleStateType::SELECTED ); 201 } 202 203 // ----------------------------------------------------------------------------- 204 // OCommonAccessibleComponent 205 // ----------------------------------------------------------------------------- 206 207 awt::Rectangle AccessibleTabBarPage::implGetBounds() throw (RuntimeException) 208 { 209 awt::Rectangle aBounds; 210 if ( m_pTabBar ) 211 { 212 // get bounding rectangle relative to the AccessibleTabBar 213 aBounds = AWTRectangle( m_pTabBar->GetPageRect( m_nPageId ) ); 214 215 // get position of the AccessibleTabBarPageList relative to the AccessibleTabBar 216 Reference< XAccessible > xParent = getAccessibleParent(); 217 if ( xParent.is() ) 218 { 219 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY ); 220 if ( xParentComponent.is() ) 221 { 222 awt::Point aParentLoc = xParentComponent->getLocation(); 223 224 // calculate bounding rectangle relative to the AccessibleTabBarPageList 225 aBounds.X -= aParentLoc.X; 226 aBounds.Y -= aParentLoc.Y; 227 } 228 } 229 } 230 231 return aBounds; 232 } 233 234 // ----------------------------------------------------------------------------- 235 // XInterface 236 // ----------------------------------------------------------------------------- 237 238 IMPLEMENT_FORWARD_XINTERFACE2( AccessibleTabBarPage, AccessibleExtendedComponentHelper_BASE, AccessibleTabBarPage_BASE ) 239 240 // ----------------------------------------------------------------------------- 241 // XTypeProvider 242 // ----------------------------------------------------------------------------- 243 244 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleTabBarPage, AccessibleExtendedComponentHelper_BASE, AccessibleTabBarPage_BASE ) 245 246 // ----------------------------------------------------------------------------- 247 // XComponent 248 // ----------------------------------------------------------------------------- 249 250 void AccessibleTabBarPage::disposing() 251 { 252 AccessibleTabBarBase::disposing(); 253 m_sPageText = ::rtl::OUString(); 254 } 255 256 // ----------------------------------------------------------------------------- 257 // XServiceInfo 258 // ----------------------------------------------------------------------------- 259 260 ::rtl::OUString AccessibleTabBarPage::getImplementationName() throw (RuntimeException) 261 { 262 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.svtools.AccessibleTabBarPage" ); 263 } 264 265 // ----------------------------------------------------------------------------- 266 267 sal_Bool AccessibleTabBarPage::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) 268 { 269 Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); 270 const ::rtl::OUString* pNames = aNames.getConstArray(); 271 const ::rtl::OUString* pEnd = pNames + aNames.getLength(); 272 for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) 273 ; 274 275 return pNames != pEnd; 276 } 277 278 // ----------------------------------------------------------------------------- 279 280 Sequence< ::rtl::OUString > AccessibleTabBarPage::getSupportedServiceNames() throw (RuntimeException) 281 { 282 Sequence< ::rtl::OUString > aNames(1); 283 aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleTabBarPage" ); 284 return aNames; 285 } 286 287 // ----------------------------------------------------------------------------- 288 // XAccessible 289 // ----------------------------------------------------------------------------- 290 291 Reference< XAccessibleContext > AccessibleTabBarPage::getAccessibleContext( ) throw (RuntimeException) 292 { 293 OExternalLockGuard aGuard( this ); 294 295 return this; 296 } 297 298 // ----------------------------------------------------------------------------- 299 // XAccessibleContext 300 // ----------------------------------------------------------------------------- 301 302 sal_Int32 AccessibleTabBarPage::getAccessibleChildCount() throw (RuntimeException) 303 { 304 OExternalLockGuard aGuard( this ); 305 306 return 0; 307 } 308 309 // ----------------------------------------------------------------------------- 310 311 Reference< XAccessible > AccessibleTabBarPage::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException) 312 { 313 OExternalLockGuard aGuard( this ); 314 315 if ( i < 0 || i >= getAccessibleChildCount() ) 316 throw IndexOutOfBoundsException(); 317 318 return Reference< XAccessible >(); 319 } 320 321 // ----------------------------------------------------------------------------- 322 323 Reference< XAccessible > AccessibleTabBarPage::getAccessibleParent( ) throw (RuntimeException) 324 { 325 OExternalLockGuard aGuard( this ); 326 327 return m_xParent; 328 } 329 330 // ----------------------------------------------------------------------------- 331 332 sal_Int32 AccessibleTabBarPage::getAccessibleIndexInParent( ) throw (RuntimeException) 333 { 334 OExternalLockGuard aGuard( this ); 335 336 sal_Int32 nIndexInParent = -1; 337 if ( m_pTabBar ) 338 nIndexInParent = m_pTabBar->GetPagePos( m_nPageId ); 339 340 return nIndexInParent; 341 } 342 343 // ----------------------------------------------------------------------------- 344 345 sal_Int16 AccessibleTabBarPage::getAccessibleRole( ) throw (RuntimeException) 346 { 347 OExternalLockGuard aGuard( this ); 348 349 return AccessibleRole::PAGE_TAB; 350 } 351 352 // ----------------------------------------------------------------------------- 353 354 ::rtl::OUString AccessibleTabBarPage::getAccessibleDescription( ) throw (RuntimeException) 355 { 356 OExternalLockGuard aGuard( this ); 357 358 ::rtl::OUString sDescription; 359 if ( m_pTabBar ) 360 sDescription = m_pTabBar->GetHelpText( m_nPageId ); 361 362 return sDescription; 363 } 364 365 // ----------------------------------------------------------------------------- 366 367 ::rtl::OUString AccessibleTabBarPage::getAccessibleName( ) throw (RuntimeException) 368 { 369 OExternalLockGuard aGuard( this ); 370 371 return m_sPageText; 372 } 373 374 // ----------------------------------------------------------------------------- 375 376 Reference< XAccessibleRelationSet > AccessibleTabBarPage::getAccessibleRelationSet( ) throw (RuntimeException) 377 { 378 OExternalLockGuard aGuard( this ); 379 380 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper; 381 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper; 382 return xSet; 383 } 384 385 // ----------------------------------------------------------------------------- 386 387 Reference< XAccessibleStateSet > AccessibleTabBarPage::getAccessibleStateSet( ) throw (RuntimeException) 388 { 389 OExternalLockGuard aGuard( this ); 390 391 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper; 392 Reference< XAccessibleStateSet > xSet = pStateSetHelper; 393 394 if ( !rBHelper.bDisposed && !rBHelper.bInDispose ) 395 { 396 FillAccessibleStateSet( *pStateSetHelper ); 397 } 398 else 399 { 400 pStateSetHelper->AddState( AccessibleStateType::DEFUNC ); 401 } 402 403 return xSet; 404 } 405 406 // ----------------------------------------------------------------------------- 407 408 Locale AccessibleTabBarPage::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException) 409 { 410 OExternalLockGuard aGuard( this ); 411 412 return Application::GetSettings().GetLocale(); 413 } 414 415 // ----------------------------------------------------------------------------- 416 // XAccessibleComponent 417 // ----------------------------------------------------------------------------- 418 419 Reference< XAccessible > AccessibleTabBarPage::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException) 420 { 421 OExternalLockGuard aGuard( this ); 422 423 return Reference< XAccessible >(); 424 } 425 426 // ----------------------------------------------------------------------------- 427 428 void AccessibleTabBarPage::grabFocus( ) throw (RuntimeException) 429 { 430 // no focus 431 } 432 433 // ----------------------------------------------------------------------------- 434 435 sal_Int32 AccessibleTabBarPage::getForeground( ) throw (RuntimeException) 436 { 437 OExternalLockGuard aGuard( this ); 438 439 sal_Int32 nColor = 0; 440 Reference< XAccessible > xParent = getAccessibleParent(); 441 if ( xParent.is() ) 442 { 443 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY ); 444 if ( xParentComp.is() ) 445 nColor = xParentComp->getForeground(); 446 } 447 448 return nColor; 449 } 450 451 // ----------------------------------------------------------------------------- 452 453 sal_Int32 AccessibleTabBarPage::getBackground( ) throw (RuntimeException) 454 { 455 OExternalLockGuard aGuard( this ); 456 457 sal_Int32 nColor = 0; 458 Reference< XAccessible > xParent = getAccessibleParent(); 459 if ( xParent.is() ) 460 { 461 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY ); 462 if ( xParentComp.is() ) 463 nColor = xParentComp->getBackground(); 464 } 465 466 return nColor; 467 } 468 469 // ----------------------------------------------------------------------------- 470 // XAccessibleExtendedComponent 471 // ----------------------------------------------------------------------------- 472 473 Reference< awt::XFont > AccessibleTabBarPage::getFont( ) throw (RuntimeException) 474 { 475 OExternalLockGuard aGuard( this ); 476 477 Reference< awt::XFont > xFont; 478 Reference< XAccessible > xParent = getAccessibleParent(); 479 if ( xParent.is() ) 480 { 481 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY ); 482 if ( xParentComp.is() ) 483 xFont = xParentComp->getFont(); 484 } 485 486 return xFont; 487 } 488 489 // ----------------------------------------------------------------------------- 490 491 ::rtl::OUString AccessibleTabBarPage::getTitledBorderText( ) throw (RuntimeException) 492 { 493 OExternalLockGuard aGuard( this ); 494 495 return m_sPageText; 496 } 497 498 // ----------------------------------------------------------------------------- 499 500 ::rtl::OUString AccessibleTabBarPage::getToolTipText( ) throw (RuntimeException) 501 { 502 OExternalLockGuard aGuard( this ); 503 504 return ::rtl::OUString(); 505 } 506 507 // ----------------------------------------------------------------------------- 508 509 //......................................................................... 510 } // namespace accessibility 511 //......................................................................... 512