Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / toolkit / source / awt / vclxaccessiblecomponent.cxx
blobc182d56349167ea3f31d2192fe532021b08aa593
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/accessibility/AccessibleRole.hpp>
21 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
22 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
23 #include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
24 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <toolkit/awt/vclxaccessiblecomponent.hxx>
27 #include <toolkit/helper/externallock.hxx>
28 #include <toolkit/awt/vclxwindow.hxx>
29 #include <toolkit/helper/convert.hxx>
30 #include <toolkit/awt/vclxfont.hxx>
31 #include <vcl/dialog.hxx>
32 #include <vcl/vclevent.hxx>
33 #include <vcl/window.hxx>
34 #include <vcl/edit.hxx>
35 #include <vcl/settings.hxx>
36 #include <tools/debug.hxx>
37 #include <unotools/accessiblestatesethelper.hxx>
38 #include <unotools/accessiblerelationsethelper.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/menu.hxx>
42 using namespace ::com::sun::star;
43 using namespace ::comphelper;
45 VCLXAccessibleComponent::VCLXAccessibleComponent( VCLXWindow* pVCLXWindow )
46 : OAccessibleExtendedComponentHelper( new VCLExternalSolarLock() )
47 , OAccessibleImplementationAccess( )
49 m_xVCLXWindow = pVCLXWindow;
51 m_pSolarLock = static_cast< VCLExternalSolarLock* >( getExternalLock( ) );
53 DBG_ASSERT( pVCLXWindow->GetWindow(), "VCLXAccessibleComponent - no window!" );
54 m_xEventSource = pVCLXWindow->GetWindow();
55 if ( m_xEventSource )
57 m_xEventSource->AddEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
58 m_xEventSource->AddChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
61 // announce the XAccessible of our creator to the base class
62 lateInit( pVCLXWindow );
65 VCLXWindow* VCLXAccessibleComponent::GetVCLXWindow() const
67 return m_xVCLXWindow.get();
70 void VCLXAccessibleComponent::DisconnectEvents()
72 if ( m_xEventSource )
74 m_xEventSource->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
75 m_xEventSource->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
76 m_xEventSource.clear();
80 VCLXAccessibleComponent::~VCLXAccessibleComponent()
82 ensureDisposed();
83 DisconnectEvents();
85 delete m_pSolarLock;
86 m_pSolarLock = nullptr;
87 // This is not completely safe. If we assume that the base class dtor calls some method which
88 // uses this lock, the we crash. However, as the base class' dtor does not have a chance to call _out_
89 // virtual methods, this is no problem as long as the base class is safe, i.e. does not use the external
90 // lock from within it's dtor. At the moment, we _know_ the base class is safe in this respect, so
91 // let's assume it keeps this way.
92 // @see OAccessibleContextHelper::OAccessibleContextHelper( IMutex* )
95 IMPLEMENT_FORWARD_XINTERFACE3( VCLXAccessibleComponent, OAccessibleExtendedComponentHelper, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE )
96 IMPLEMENT_FORWARD_XTYPEPROVIDER3( VCLXAccessibleComponent, OAccessibleExtendedComponentHelper, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE )
98 OUString VCLXAccessibleComponent::getImplementationName() throw (uno::RuntimeException, std::exception)
100 return OUString("com.sun.star.comp.toolkit.AccessibleWindow");
103 sal_Bool VCLXAccessibleComponent::supportsService( const OUString& rServiceName ) throw (uno::RuntimeException, std::exception)
105 return cppu::supportsService(this, rServiceName);
108 uno::Sequence< OUString > VCLXAccessibleComponent::getSupportedServiceNames() throw (uno::RuntimeException, std::exception)
110 uno::Sequence< OUString > aNames { "com.sun.star.awt.AccessibleWindow" };
111 return aNames;
114 IMPL_LINK_TYPED( VCLXAccessibleComponent, WindowEventListener, VclWindowEvent&, rEvent, void )
116 /* Ignore VCLEVENT_WINDOW_ENDPOPUPMODE, because the UNO accessibility wrapper
117 * might have been destroyed by the previous VCLEventListener (if no AT tool
118 * is running), e.g. sub-toolbars in impress.
120 if ( m_xVCLXWindow.is() /* #122218# */ && (rEvent.GetId() != VCLEVENT_WINDOW_ENDPOPUPMODE) )
122 DBG_ASSERT( rEvent.GetWindow(), "Window???" );
123 if( !rEvent.GetWindow()->IsAccessibilityEventsSuppressed() || ( rEvent.GetId() == VCLEVENT_OBJECT_DYING ) )
125 ProcessWindowEvent( rEvent );
130 IMPL_LINK_TYPED( VCLXAccessibleComponent, WindowChildEventListener, VclWindowEvent&, rEvent, void )
132 if ( m_xVCLXWindow.is() /* #i68079# */ )
134 DBG_ASSERT( rEvent.GetWindow(), "Window???" );
135 if( !rEvent.GetWindow()->IsAccessibilityEventsSuppressed() )
137 // #103087# to prevent an early release of the component
138 uno::Reference< accessibility::XAccessibleContext > xTmp = this;
140 ProcessWindowChildEvent( rEvent );
145 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::GetChildAccessible( const VclWindowEvent& rVclWindowEvent )
147 // checks if the data in the window event is our direct child
148 // and returns its accessible
150 // MT: Change this later, normally a show/hide event shouldn't have the vcl::Window* in pData.
151 vcl::Window* pChildWindow = static_cast<vcl::Window *>(rVclWindowEvent.GetData());
152 if( pChildWindow && GetWindow() == pChildWindow->GetAccessibleParentWindow() )
153 return pChildWindow->GetAccessible( rVclWindowEvent.GetId() == VCLEVENT_WINDOW_SHOW );
154 else
155 return uno::Reference< accessibility::XAccessible > ();
158 void VCLXAccessibleComponent::ProcessWindowChildEvent( const VclWindowEvent& rVclWindowEvent )
160 uno::Any aOldValue, aNewValue;
161 uno::Reference< accessibility::XAccessible > xAcc;
163 switch ( rVclWindowEvent.GetId() )
165 case VCLEVENT_WINDOW_SHOW: // send create on show for direct accessible children
167 xAcc = GetChildAccessible( rVclWindowEvent );
168 if( xAcc.is() )
170 aNewValue <<= xAcc;
171 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
174 break;
175 case VCLEVENT_WINDOW_HIDE: // send destroy on hide for direct accessible children
177 xAcc = GetChildAccessible( rVclWindowEvent );
178 if( xAcc.is() )
180 aOldValue <<= xAcc;
181 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
184 break;
188 void VCLXAccessibleComponent::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
190 uno::Any aOldValue, aNewValue;
192 vcl::Window* pAccWindow = rVclWindowEvent.GetWindow();
193 assert(pAccWindow && "VCLXAccessibleComponent::ProcessWindowEvent - Window?");
195 switch ( rVclWindowEvent.GetId() )
197 case VCLEVENT_OBJECT_DYING:
199 DisconnectEvents();
200 m_xVCLXWindow.clear();
202 break;
203 case VCLEVENT_WINDOW_CHILDDESTROYED:
205 vcl::Window* pWindow = static_cast<vcl::Window*>(rVclWindowEvent.GetData());
206 DBG_ASSERT( pWindow, "VCLEVENT_WINDOW_CHILDDESTROYED - Window=?" );
207 if ( pWindow->GetAccessible( false ).is() )
209 aOldValue <<= pWindow->GetAccessible( false );
210 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
213 break;
214 case VCLEVENT_WINDOW_ACTIVATE:
216 // avoid notification if a child frame is already active
217 // only one frame may be active at a given time
218 if ( !pAccWindow->HasActiveChildFrame() &&
219 ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||
220 getAccessibleRole() == accessibility::AccessibleRole::ALERT ||
221 getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) ) // #i18891#
223 aNewValue <<= accessibility::AccessibleStateType::ACTIVE;
224 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
227 break;
228 case VCLEVENT_WINDOW_DEACTIVATE:
230 if ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||
231 getAccessibleRole() == accessibility::AccessibleRole::ALERT ||
232 getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) // #i18891#
234 aOldValue <<= accessibility::AccessibleStateType::ACTIVE;
235 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
238 break;
239 case VCLEVENT_WINDOW_GETFOCUS:
240 case VCLEVENT_CONTROL_GETFOCUS:
242 if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_CONTROL_GETFOCUS) ||
243 (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_WINDOW_GETFOCUS) )
245 // if multiple listeners were registered it is possible that the
246 // focus was changed during event processing (eg SfxTopWindow )
247 // #106082# allow ChildPathFocus only for CompoundControls, for windows the focus must be in the window itself
248 if( (pAccWindow->IsCompoundControl() && pAccWindow->HasChildPathFocus()) ||
249 (!pAccWindow->IsCompoundControl() && pAccWindow->HasFocus()) )
251 aNewValue <<= accessibility::AccessibleStateType::FOCUSED;
252 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
256 break;
257 case VCLEVENT_WINDOW_LOSEFOCUS:
258 case VCLEVENT_CONTROL_LOSEFOCUS:
260 if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_CONTROL_LOSEFOCUS) ||
261 (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_WINDOW_LOSEFOCUS) )
263 aOldValue <<= accessibility::AccessibleStateType::FOCUSED;
264 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
267 break;
268 case VCLEVENT_WINDOW_FRAMETITLECHANGED:
270 OUString aOldName( *static_cast<OUString*>(rVclWindowEvent.GetData()) );
271 OUString aNewName( getAccessibleName() );
272 aOldValue <<= aOldName;
273 aNewValue <<= aNewName;
274 NotifyAccessibleEvent( accessibility::AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
276 break;
277 case VCLEVENT_WINDOW_ENABLED:
279 aNewValue <<= accessibility::AccessibleStateType::ENABLED;
280 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
281 aNewValue <<= accessibility::AccessibleStateType::SENSITIVE;
282 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
284 break;
285 case VCLEVENT_WINDOW_DISABLED:
287 aOldValue <<= accessibility::AccessibleStateType::SENSITIVE;
288 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
290 aOldValue <<= accessibility::AccessibleStateType::ENABLED;
291 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
293 break;
294 case VCLEVENT_WINDOW_MOVE:
295 case VCLEVENT_WINDOW_RESIZE:
297 NotifyAccessibleEvent( accessibility::AccessibleEventId::BOUNDRECT_CHANGED, aOldValue, aNewValue );
299 break;
300 case VCLEVENT_WINDOW_MENUBARADDED:
302 MenuBar* pMenuBar = static_cast<MenuBar*>(rVclWindowEvent.GetData());
303 if ( pMenuBar )
305 uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() );
306 if ( xChild.is() )
308 aNewValue <<= xChild;
309 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
313 break;
314 case VCLEVENT_WINDOW_MENUBARREMOVED:
316 MenuBar* pMenuBar = static_cast<MenuBar*>(rVclWindowEvent.GetData());
317 if ( pMenuBar )
319 uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() );
320 if ( xChild.is() )
322 aOldValue <<= xChild;
323 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
327 break;
328 case VCLEVENT_WINDOW_MINIMIZE:
330 aNewValue <<= accessibility::AccessibleStateType::ICONIFIED;
331 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
333 break;
334 case VCLEVENT_WINDOW_NORMALIZE:
336 aOldValue <<= accessibility::AccessibleStateType::ICONIFIED;
337 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
339 break;
340 default:
343 break;
347 void VCLXAccessibleComponent::disposing()
349 DisconnectEvents();
351 OAccessibleExtendedComponentHelper::disposing();
353 m_xVCLXWindow.clear();
356 VclPtr<vcl::Window> VCLXAccessibleComponent::GetWindow() const
358 return GetVCLXWindow() ? GetVCLXWindow()->GetWindow()
359 : VclPtr<vcl::Window>();
362 void VCLXAccessibleComponent::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet )
364 VclPtr<vcl::Window> pWindow = GetWindow();
365 if ( pWindow )
367 vcl::Window *pLabeledBy = pWindow->GetAccessibleRelationLabeledBy();
368 if ( pLabeledBy && pLabeledBy != pWindow )
370 uno::Sequence< uno::Reference< uno::XInterface > > aSequence { pLabeledBy->GetAccessible() };
371 rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABELED_BY, aSequence ) );
374 vcl::Window* pLabelFor = pWindow->GetAccessibleRelationLabelFor();
375 if ( pLabelFor && pLabelFor != pWindow )
377 uno::Sequence< uno::Reference< uno::XInterface > > aSequence { pLabelFor->GetAccessible() };
378 rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABEL_FOR, aSequence ) );
381 vcl::Window* pMemberOf = pWindow->GetAccessibleRelationMemberOf();
382 if ( pMemberOf && pMemberOf != pWindow )
384 uno::Sequence< uno::Reference< uno::XInterface > > aSequence { pMemberOf->GetAccessible() };
385 rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::MEMBER_OF, aSequence ) );
390 void VCLXAccessibleComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
392 VclPtr<vcl::Window> pWindow = GetWindow();
393 if ( pWindow )
395 if ( pWindow->IsVisible() )
397 rStateSet.AddState( accessibility::AccessibleStateType::VISIBLE );
398 rStateSet.AddState( accessibility::AccessibleStateType::SHOWING );
400 else
402 rStateSet.AddState( accessibility::AccessibleStateType::INVALID );
405 if ( pWindow->IsEnabled() )
407 rStateSet.AddState( accessibility::AccessibleStateType::ENABLED );
408 rStateSet.AddState( accessibility::AccessibleStateType::SENSITIVE );
411 if ( pWindow->HasChildPathFocus() &&
412 ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||
413 getAccessibleRole() == accessibility::AccessibleRole::ALERT ||
414 getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) ) // #i18891#
415 rStateSet.AddState( accessibility::AccessibleStateType::ACTIVE );
417 if ( pWindow->HasFocus() || ( pWindow->IsCompoundControl() && pWindow->HasChildPathFocus() ) )
418 rStateSet.AddState( accessibility::AccessibleStateType::FOCUSED );
420 if ( pWindow->IsWait() )
421 rStateSet.AddState( accessibility::AccessibleStateType::BUSY );
423 if ( pWindow->GetStyle() & WB_SIZEABLE )
424 rStateSet.AddState( accessibility::AccessibleStateType::RESIZABLE );
425 // 6. frame doesn't have MOVABLE state
426 // 10. for password text, where is the sensitive state?
427 if( ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||getAccessibleRole() == accessibility::AccessibleRole::DIALOG )&& pWindow->GetStyle() & WB_MOVEABLE )
428 rStateSet.AddState( accessibility::AccessibleStateType::MOVEABLE );
429 if( pWindow->IsDialog() )
431 Dialog *pDlg = static_cast< Dialog* >( pWindow.get() );
432 if( pDlg->IsInExecute() )
433 rStateSet.AddState( accessibility::AccessibleStateType::MODAL );
435 //If a combobox or list's edit child isn't read-only,EDITABLE state
436 //should be set.
437 if( pWindow && pWindow->GetType() == WINDOW_COMBOBOX )
439 if( !( pWindow->GetStyle() & WB_READONLY) ||
440 !static_cast<Edit*>(pWindow.get())->IsReadOnly() )
441 rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE );
444 VclPtr<vcl::Window> pChild = pWindow->GetWindow( GetWindowType::FirstChild );
446 while( pWindow && pChild )
448 VclPtr<vcl::Window> pWinTemp = pChild->GetWindow( GetWindowType::FirstChild );
449 if( pWinTemp && pWinTemp->GetType() == WINDOW_EDIT )
451 if( !( pWinTemp->GetStyle() & WB_READONLY) ||
452 !static_cast<Edit*>(pWinTemp.get())->IsReadOnly() )
453 rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE );
454 break;
456 if( pChild->GetType() == WINDOW_EDIT )
458 if( !( pChild->GetStyle() & WB_READONLY) ||
459 !static_cast<Edit*>(pChild.get())->IsReadOnly())
460 rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE );
461 break;
463 pChild = pChild->GetWindow( GetWindowType::Next );
466 else
468 rStateSet.AddState( accessibility::AccessibleStateType::DEFUNC );
473 MUST BE SET FROM DERIVED CLASSES:
475 CHECKED
476 COLLAPSED
477 EXPANDED
478 EXPANDABLE
479 EDITABLE
480 FOCUSABLE
481 HORIZONTAL
482 VERTICAL
483 ICONIFIED
484 MULTILINE
485 MULTI_SELECTABLE
486 PRESSED
487 SELECTABLE
488 SELECTED
489 SINGLE_LINE
490 TRANSIENT
496 // accessibility::XAccessibleContext
497 sal_Int32 VCLXAccessibleComponent::getAccessibleChildCount() throw (uno::RuntimeException, std::exception)
499 OExternalLockGuard aGuard( this );
501 sal_Int32 nChildren = 0;
502 if ( GetWindow() )
503 nChildren = GetWindow()->GetAccessibleChildWindowCount();
505 return nChildren;
508 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleChild( sal_Int32 i ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
510 OExternalLockGuard aGuard( this );
512 if ( i >= getAccessibleChildCount() )
513 throw lang::IndexOutOfBoundsException();
515 uno::Reference< accessibility::XAccessible > xAcc;
516 if ( GetWindow() )
518 vcl::Window* pChild = GetWindow()->GetAccessibleChildWindow( (sal_uInt16)i );
519 if ( pChild )
520 xAcc = pChild->GetAccessible();
523 return xAcc;
526 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getVclParent() const
528 uno::Reference< accessibility::XAccessible > xAcc;
529 if ( GetWindow() )
531 vcl::Window* pParent = GetWindow()->GetAccessibleParentWindow();
532 if ( pParent )
533 xAcc = pParent->GetAccessible();
535 return xAcc;
538 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleParent( ) throw (uno::RuntimeException, std::exception)
540 OExternalLockGuard aGuard( this );
542 uno::Reference< accessibility::XAccessible > xAcc( implGetForeignControlledParent() );
543 if ( !xAcc.is() )
544 // we do _not_ have a foreign-controlled parent -> default to our VCL parent
545 xAcc = getVclParent();
547 return xAcc;
550 sal_Int32 VCLXAccessibleComponent::getAccessibleIndexInParent( ) throw (uno::RuntimeException, std::exception)
552 OExternalLockGuard aGuard( this );
554 sal_Int32 nIndex = -1;
556 uno::Reference< accessibility::XAccessible > xAcc( implGetForeignControlledParent() );
557 if ( xAcc.is() )
558 { // we _do_ have a foreign-controlled parent -> use the base class' implementation,
559 // which goes the UNO way
560 nIndex = OAccessibleExtendedComponentHelper::getAccessibleIndexInParent( );
562 else
564 if ( GetWindow() )
566 vcl::Window* pParent = GetWindow()->GetAccessibleParentWindow();
567 if ( pParent )
569 // Iterate over all the parent's children and search for this object.
570 // this should be compatible with the code in SVX
571 uno::Reference< accessibility::XAccessible > xParentAcc( pParent->GetAccessible() );
572 if ( xParentAcc.is() )
574 uno::Reference< accessibility::XAccessibleContext > xParentContext ( xParentAcc->getAccessibleContext() );
575 if ( xParentContext.is() )
577 sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
578 for ( sal_Int32 i=0; i<nChildCount; i++ )
580 uno::Reference< accessibility::XAccessible > xChild( xParentContext->getAccessibleChild(i) );
581 if ( xChild.is() )
583 uno::Reference< accessibility::XAccessibleContext > xChildContext = xChild->getAccessibleContext();
584 if ( xChildContext == static_cast<accessibility::XAccessibleContext*>(this) )
586 nIndex = i;
587 break;
596 return nIndex;
599 sal_Int16 VCLXAccessibleComponent::getAccessibleRole( ) throw (uno::RuntimeException, std::exception)
601 OExternalLockGuard aGuard( this );
603 sal_Int16 nRole = 0;
605 if ( GetWindow() )
606 nRole = GetWindow()->GetAccessibleRole();
608 return nRole;
611 OUString VCLXAccessibleComponent::getAccessibleDescription( ) throw (uno::RuntimeException, std::exception)
613 OExternalLockGuard aGuard( this );
615 OUString aDescription;
617 if ( GetWindow() )
618 aDescription = GetWindow()->GetAccessibleDescription();
620 return aDescription;
623 OUString VCLXAccessibleComponent::getAccessibleName( ) throw (uno::RuntimeException, std::exception)
625 OExternalLockGuard aGuard( this );
627 OUString aName;
628 if ( GetWindow() )
630 aName = GetWindow()->GetAccessibleName();
631 #if OSL_DEBUG_LEVEL > 0
632 aName += " (Type = ";
633 aName += OUString::number(static_cast<sal_Int32>(GetWindow()->GetType()));
634 aName += ")";
635 #endif
637 return aName;
640 uno::Reference< accessibility::XAccessibleRelationSet > VCLXAccessibleComponent::getAccessibleRelationSet( ) throw (uno::RuntimeException, std::exception)
642 OExternalLockGuard aGuard( this );
644 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
645 uno::Reference< accessibility::XAccessibleRelationSet > xSet = pRelationSetHelper;
646 FillAccessibleRelationSet( *pRelationSetHelper );
647 return xSet;
650 uno::Reference< accessibility::XAccessibleStateSet > VCLXAccessibleComponent::getAccessibleStateSet( ) throw (uno::RuntimeException, std::exception)
652 OExternalLockGuard aGuard( this );
654 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
655 uno::Reference< accessibility::XAccessibleStateSet > xSet = pStateSetHelper;
656 FillAccessibleStateSet( *pStateSetHelper );
657 return xSet;
660 lang::Locale VCLXAccessibleComponent::getLocale() throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException, std::exception)
662 OExternalLockGuard aGuard( this );
664 return Application::GetSettings().GetLanguageTag().getLocale();
667 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleAtPoint( const awt::Point& rPoint ) throw (uno::RuntimeException, std::exception)
669 OExternalLockGuard aGuard( this );
671 uno::Reference< accessibility::XAccessible > xChild;
672 for ( sal_uInt32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
674 uno::Reference< accessibility::XAccessible > xAcc = getAccessibleChild( i );
675 if ( xAcc.is() )
677 uno::Reference< accessibility::XAccessibleComponent > xComp( xAcc->getAccessibleContext(), uno::UNO_QUERY );
678 if ( xComp.is() )
680 Rectangle aRect = VCLRectangle( xComp->getBounds() );
681 Point aPos = VCLPoint( rPoint );
682 if ( aRect.IsInside( aPos ) )
684 xChild = xAcc;
685 break;
691 return xChild;
694 // accessibility::XAccessibleComponent
695 awt::Rectangle VCLXAccessibleComponent::implGetBounds() throw (uno::RuntimeException)
697 awt::Rectangle aBounds ( 0, 0, 0, 0 );
699 vcl::Window* pWindow = GetWindow();
700 if ( pWindow )
702 Rectangle aRect = pWindow->GetWindowExtentsRelative( nullptr );
703 aBounds = AWTRectangle( aRect );
704 vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
705 if ( pParent )
707 Rectangle aParentRect = pParent->GetWindowExtentsRelative( nullptr );
708 awt::Point aParentScreenLoc = AWTPoint( aParentRect.TopLeft() );
709 aBounds.X -= aParentScreenLoc.X;
710 aBounds.Y -= aParentScreenLoc.Y;
714 uno::Reference< accessibility::XAccessible > xParent( implGetForeignControlledParent() );
715 if ( xParent.is() )
716 { // hmm, we can't rely on our VCL coordinates, as in the Accessibility Hierarchy, somebody gave
717 // us a parent which is different from our VCL parent
718 // (actually, we did not check if it's really different ...)
720 // the screen location of the foreign parent
721 uno::Reference< accessibility::XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), uno::UNO_QUERY );
722 DBG_ASSERT( xParentComponent.is(), "VCLXAccessibleComponent::implGetBounds: invalid (foreign) parent component!" );
724 awt::Point aScreenLocForeign( 0, 0 );
725 if ( xParentComponent.is() )
726 aScreenLocForeign = xParentComponent->getLocationOnScreen();
728 // the screen location of the VCL parent
729 xParent = getVclParent();
730 if ( xParent.is() )
731 xParentComponent.set(xParent->getAccessibleContext(), css::uno::UNO_QUERY);
733 awt::Point aScreenLocVCL( 0, 0 );
734 if ( xParentComponent.is() )
735 aScreenLocVCL = xParentComponent->getLocationOnScreen();
737 // the difference between them
738 awt::Size aOffset( aScreenLocVCL.X - aScreenLocForeign.X, aScreenLocVCL.Y - aScreenLocForeign.Y );
739 // move the bounds
740 aBounds.X += aOffset.Width;
741 aBounds.Y += aOffset.Height;
744 return aBounds;
747 awt::Point VCLXAccessibleComponent::getLocationOnScreen( ) throw (uno::RuntimeException, std::exception)
749 OExternalLockGuard aGuard( this );
751 awt::Point aPos;
752 if ( GetWindow() )
754 Rectangle aRect = GetWindow()->GetWindowExtentsRelative( nullptr );
755 aPos.X = aRect.Left();
756 aPos.Y = aRect.Top();
759 return aPos;
762 void VCLXAccessibleComponent::grabFocus( ) throw (uno::RuntimeException, std::exception)
764 OExternalLockGuard aGuard( this );
766 uno::Reference< accessibility::XAccessibleStateSet > xStates = getAccessibleStateSet();
767 if ( m_xVCLXWindow.is() && xStates.is() && xStates->contains( accessibility::AccessibleStateType::FOCUSABLE ) )
768 m_xVCLXWindow->setFocus();
771 sal_Int32 SAL_CALL VCLXAccessibleComponent::getForeground( ) throw (uno::RuntimeException, std::exception)
773 OExternalLockGuard aGuard( this );
775 sal_Int32 nColor = 0;
776 vcl::Window* pWindow = GetWindow();
777 if ( pWindow )
779 if ( pWindow->IsControlForeground() )
780 nColor = pWindow->GetControlForeground().GetColor();
781 else
783 vcl::Font aFont;
784 if ( pWindow->IsControlFont() )
785 aFont = pWindow->GetControlFont();
786 else
787 aFont = pWindow->GetFont();
788 nColor = aFont.GetColor().GetColor();
789 // COL_AUTO is not very meaningful for AT
790 if ( nColor == (sal_Int32)COL_AUTO)
791 nColor = pWindow->GetTextColor().GetColor();
795 return nColor;
798 sal_Int32 SAL_CALL VCLXAccessibleComponent::getBackground( ) throw (uno::RuntimeException, std::exception)
800 OExternalLockGuard aGuard( this );
802 sal_Int32 nColor = 0;
803 vcl::Window* pWindow = GetWindow();
804 if ( pWindow )
806 if ( pWindow->IsControlBackground() )
807 nColor = pWindow->GetControlBackground().GetColor();
808 else
809 nColor = pWindow->GetBackground().GetColor().GetColor();
812 return nColor;
815 // XAccessibleExtendedComponent
817 uno::Reference< awt::XFont > SAL_CALL VCLXAccessibleComponent::getFont( ) throw (uno::RuntimeException, std::exception)
819 OExternalLockGuard aGuard( this );
821 uno::Reference< awt::XFont > xFont;
822 vcl::Window* pWindow = GetWindow();
823 if ( pWindow )
825 uno::Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), uno::UNO_QUERY );
826 if ( xDev.is() )
828 vcl::Font aFont;
829 if ( pWindow->IsControlFont() )
830 aFont = pWindow->GetControlFont();
831 else
832 aFont = pWindow->GetFont();
833 VCLXFont* pVCLXFont = new VCLXFont;
834 pVCLXFont->Init( *xDev.get(), aFont );
835 xFont = pVCLXFont;
839 return xFont;
842 OUString SAL_CALL VCLXAccessibleComponent::getTitledBorderText( ) throw (uno::RuntimeException, std::exception)
844 OExternalLockGuard aGuard( this );
846 OUString sRet;
847 if ( GetWindow() )
848 sRet = GetWindow()->GetText();
850 return sRet;
853 OUString SAL_CALL VCLXAccessibleComponent::getToolTipText( ) throw (uno::RuntimeException, std::exception)
855 OExternalLockGuard aGuard( this );
857 OUString sRet;
858 if ( GetWindow() )
859 sRet = GetWindow()->GetQuickHelpText();
861 return sRet;
864 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */