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/accessiblemenucomponent.hxx> 27 28 #include <toolkit/awt/vclxfont.hxx> 29 #include <toolkit/helper/convert.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 35 #include <unotools/accessiblestatesethelper.hxx> 36 #include <unotools/accessiblerelationsethelper.hxx> 37 #include <cppuhelper/typeprovider.hxx> 38 #include <comphelper/sequence.hxx> 39 #include <vcl/svapp.hxx> 40 #include <vcl/window.hxx> 41 #include <vcl/menu.hxx> 42 #include <vcl/unohelp2.hxx> 43 44 45 using namespace ::com::sun::star::accessibility; 46 using namespace ::com::sun::star::uno; 47 using namespace ::com::sun::star::lang; 48 using namespace ::com::sun::star; 49 using namespace ::comphelper; 50 51 52 // ----------------------------------------------------------------------------- 53 // class OAccessibleMenuComponent 54 // ----------------------------------------------------------------------------- 55 56 OAccessibleMenuComponent::OAccessibleMenuComponent( Menu* pMenu ) 57 :OAccessibleMenuBaseComponent( pMenu ) 58 { 59 } 60 61 // ----------------------------------------------------------------------------- 62 63 OAccessibleMenuComponent::~OAccessibleMenuComponent() 64 { 65 } 66 67 // ----------------------------------------------------------------------------- 68 69 sal_Bool OAccessibleMenuComponent::IsEnabled() 70 { 71 return sal_True; 72 } 73 74 // ----------------------------------------------------------------------------- 75 76 sal_Bool OAccessibleMenuComponent::IsVisible() 77 { 78 sal_Bool bVisible = sal_False; 79 80 if ( m_pMenu ) 81 bVisible = m_pMenu->IsMenuVisible(); 82 83 return bVisible; 84 } 85 86 // ----------------------------------------------------------------------------- 87 88 void OAccessibleMenuComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) 89 { 90 if ( IsEnabled() ) 91 { 92 rStateSet.AddState( AccessibleStateType::ENABLED ); 93 rStateSet.AddState( AccessibleStateType::SENSITIVE ); 94 } 95 96 rStateSet.AddState( AccessibleStateType::FOCUSABLE ); 97 98 if ( IsFocused() ) 99 rStateSet.AddState( AccessibleStateType::FOCUSED ); 100 101 if ( IsVisible() ) 102 { 103 rStateSet.AddState( AccessibleStateType::VISIBLE ); 104 rStateSet.AddState( AccessibleStateType::SHOWING ); 105 } 106 107 rStateSet.AddState( AccessibleStateType::OPAQUE ); 108 } 109 110 // ----------------------------------------------------------------------------- 111 // OCommonAccessibleComponent 112 // ----------------------------------------------------------------------------- 113 114 awt::Rectangle OAccessibleMenuComponent::implGetBounds() throw (RuntimeException) 115 { 116 awt::Rectangle aBounds( 0, 0, 0, 0 ); 117 118 if ( m_pMenu ) 119 { 120 Window* pWindow = m_pMenu->GetWindow(); 121 if ( pWindow ) 122 { 123 // get bounding rectangle of the window in screen coordinates 124 Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL ); 125 aBounds = AWTRectangle( aRect ); 126 127 // get position of the accessible parent in screen coordinates 128 Reference< XAccessible > xParent = getAccessibleParent(); 129 if ( xParent.is() ) 130 { 131 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY ); 132 if ( xParentComponent.is() ) 133 { 134 awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen(); 135 136 // calculate position of the window relative to the accessible parent 137 aBounds.X -= aParentScreenLoc.X; 138 aBounds.Y -= aParentScreenLoc.Y; 139 } 140 } 141 } 142 } 143 144 return aBounds; 145 } 146 147 // ----------------------------------------------------------------------------- 148 // XInterface 149 // ----------------------------------------------------------------------------- 150 151 IMPLEMENT_FORWARD_XINTERFACE2( OAccessibleMenuComponent, OAccessibleMenuBaseComponent, OAccessibleMenuComponent_BASE ) 152 153 // ----------------------------------------------------------------------------- 154 // XTypeProvider 155 // ----------------------------------------------------------------------------- 156 157 IMPLEMENT_FORWARD_XTYPEPROVIDER2( OAccessibleMenuComponent, OAccessibleMenuBaseComponent, OAccessibleMenuComponent_BASE ) 158 159 // ----------------------------------------------------------------------------- 160 // XAccessibleContext 161 // ----------------------------------------------------------------------------- 162 163 sal_Int32 OAccessibleMenuComponent::getAccessibleChildCount() throw (RuntimeException) 164 { 165 OExternalLockGuard aGuard( this ); 166 167 return GetChildCount(); 168 } 169 170 // ----------------------------------------------------------------------------- 171 172 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException) 173 { 174 OExternalLockGuard aGuard( this ); 175 176 if ( i < 0 || i >= GetChildCount() ) 177 throw IndexOutOfBoundsException(); 178 179 return GetChild( i ); 180 } 181 182 // ----------------------------------------------------------------------------- 183 184 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleParent( ) throw (RuntimeException) 185 { 186 OExternalLockGuard aGuard( this ); 187 188 Reference< XAccessible > xParent; 189 190 if ( m_pMenu ) 191 { 192 Window* pWindow = m_pMenu->GetWindow(); 193 if ( pWindow ) 194 { 195 Window* pParent = pWindow->GetAccessibleParentWindow(); 196 if ( pParent ) 197 xParent = pParent->GetAccessible(); 198 } 199 } 200 201 return xParent; 202 } 203 204 // ----------------------------------------------------------------------------- 205 206 sal_Int16 OAccessibleMenuComponent::getAccessibleRole( ) throw (RuntimeException) 207 { 208 OExternalLockGuard aGuard( this ); 209 210 return AccessibleRole::UNKNOWN; 211 } 212 213 // ----------------------------------------------------------------------------- 214 215 ::rtl::OUString OAccessibleMenuComponent::getAccessibleDescription( ) throw (RuntimeException) 216 { 217 OExternalLockGuard aGuard( this ); 218 219 ::rtl::OUString sDescription; 220 if ( m_pMenu ) 221 { 222 Window* pWindow = m_pMenu->GetWindow(); 223 if ( pWindow ) 224 sDescription = pWindow->GetAccessibleDescription(); 225 } 226 227 return sDescription; 228 } 229 230 // ----------------------------------------------------------------------------- 231 232 ::rtl::OUString OAccessibleMenuComponent::getAccessibleName( ) throw (RuntimeException) 233 { 234 OExternalLockGuard aGuard( this ); 235 236 return ::rtl::OUString(); 237 } 238 239 // ----------------------------------------------------------------------------- 240 241 Reference< XAccessibleRelationSet > OAccessibleMenuComponent::getAccessibleRelationSet( ) throw (RuntimeException) 242 { 243 OExternalLockGuard aGuard( this ); 244 245 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper; 246 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper; 247 return xSet; 248 } 249 250 // ----------------------------------------------------------------------------- 251 252 Locale OAccessibleMenuComponent::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException) 253 { 254 OExternalLockGuard aGuard( this ); 255 256 return Application::GetSettings().GetLocale(); 257 } 258 259 // ----------------------------------------------------------------------------- 260 // XAccessibleComponent 261 // ----------------------------------------------------------------------------- 262 263 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException) 264 { 265 OExternalLockGuard aGuard( this ); 266 267 return GetChildAt( rPoint ); 268 } 269 270 // ----------------------------------------------------------------------------- 271 272 awt::Point OAccessibleMenuComponent::getLocationOnScreen( ) throw (RuntimeException) 273 { 274 OExternalLockGuard aGuard( this ); 275 276 awt::Point aPos; 277 278 if ( m_pMenu ) 279 { 280 Window* pWindow = m_pMenu->GetWindow(); 281 if ( pWindow ) 282 { 283 Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL ); 284 aPos = AWTPoint( aRect.TopLeft() ); 285 } 286 } 287 288 return aPos; 289 } 290 291 // ----------------------------------------------------------------------------- 292 293 void OAccessibleMenuComponent::grabFocus( ) throw (RuntimeException) 294 { 295 OExternalLockGuard aGuard( this ); 296 297 if ( m_pMenu ) 298 { 299 Window* pWindow = m_pMenu->GetWindow(); 300 if ( pWindow ) 301 pWindow->GrabFocus(); 302 } 303 } 304 305 // ----------------------------------------------------------------------------- 306 307 sal_Int32 OAccessibleMenuComponent::getForeground( ) throw (RuntimeException) 308 { 309 OExternalLockGuard aGuard( this ); 310 311 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 312 sal_Int32 nColor = rStyleSettings.GetMenuTextColor().GetColor(); 313 314 return nColor; 315 } 316 317 // ----------------------------------------------------------------------------- 318 319 sal_Int32 OAccessibleMenuComponent::getBackground( ) throw (RuntimeException) 320 { 321 OExternalLockGuard aGuard( this ); 322 323 return 0; 324 } 325 326 // ----------------------------------------------------------------------------- 327 // XAccessibleExtendedComponent 328 // ----------------------------------------------------------------------------- 329 330 Reference< awt::XFont > OAccessibleMenuComponent::getFont( ) throw (RuntimeException) 331 { 332 OExternalLockGuard aGuard( this ); 333 334 Reference< awt::XFont > xFont; 335 336 if ( m_pMenu ) 337 { 338 Window* pWindow = m_pMenu->GetWindow(); 339 if ( pWindow ) 340 { 341 Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY ); 342 if ( xDev.is() ) 343 { 344 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); 345 VCLXFont* pVCLXFont = new VCLXFont; 346 pVCLXFont->Init( *xDev.get(), rStyleSettings.GetMenuFont() ); 347 xFont = pVCLXFont; 348 } 349 } 350 } 351 352 return xFont; 353 } 354 355 // ----------------------------------------------------------------------------- 356 357 ::rtl::OUString OAccessibleMenuComponent::getTitledBorderText( ) throw (RuntimeException) 358 { 359 OExternalLockGuard aGuard( this ); 360 361 return ::rtl::OUString(); 362 } 363 364 // ----------------------------------------------------------------------------- 365 366 ::rtl::OUString OAccessibleMenuComponent::getToolTipText( ) throw (RuntimeException) 367 { 368 OExternalLockGuard aGuard( this ); 369 370 return ::rtl::OUString(); 371 } 372 373 // ----------------------------------------------------------------------------- 374 // XAccessibleSelection 375 // ----------------------------------------------------------------------------- 376 377 void OAccessibleMenuComponent::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException) 378 { 379 OExternalLockGuard aGuard( this ); 380 381 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) 382 throw IndexOutOfBoundsException(); 383 384 SelectChild( nChildIndex ); 385 } 386 387 // ----------------------------------------------------------------------------- 388 389 sal_Bool OAccessibleMenuComponent::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException) 390 { 391 OExternalLockGuard aGuard( this ); 392 393 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) 394 throw IndexOutOfBoundsException(); 395 396 return IsChildSelected( nChildIndex ); 397 } 398 399 // ----------------------------------------------------------------------------- 400 401 void OAccessibleMenuComponent::clearAccessibleSelection( ) throw (RuntimeException) 402 { 403 OExternalLockGuard aGuard( this ); 404 405 DeSelectAll(); 406 } 407 408 // ----------------------------------------------------------------------------- 409 410 void OAccessibleMenuComponent::selectAllAccessibleChildren( ) throw (RuntimeException) 411 { 412 // This method makes no sense in a menu, and so does nothing. 413 } 414 415 // ----------------------------------------------------------------------------- 416 417 sal_Int32 OAccessibleMenuComponent::getSelectedAccessibleChildCount( ) throw (RuntimeException) 418 { 419 OExternalLockGuard aGuard( this ); 420 421 sal_Int32 nRet = 0; 422 423 for ( sal_Int32 i = 0, nCount = GetChildCount(); i < nCount; i++ ) 424 { 425 if ( IsChildSelected( i ) ) 426 ++nRet; 427 } 428 429 return nRet; 430 } 431 432 // ----------------------------------------------------------------------------- 433 434 Reference< XAccessible > OAccessibleMenuComponent::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException) 435 { 436 OExternalLockGuard aGuard( this ); 437 438 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() ) 439 throw IndexOutOfBoundsException(); 440 441 Reference< XAccessible > xChild; 442 443 for ( sal_Int32 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ ) 444 { 445 if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) ) 446 { 447 xChild = GetChild( i ); 448 break; 449 } 450 } 451 452 return xChild; 453 } 454 455 // ----------------------------------------------------------------------------- 456 457 void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException) 458 { 459 OExternalLockGuard aGuard( this ); 460 461 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) 462 throw IndexOutOfBoundsException(); 463 464 DeSelectAll(); 465 } 466 467 // ----------------------------------------------------------------------------- 468