bump product version to 6.3.0.0.beta1
[LibreOffice.git] / toolkit / source / awt / vclxaccessiblecomponent.cxx
blobf9b55d2786550c1f03a45d5036ded3aa228a38e2
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 <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <i18nlangtag/languagetag.hxx>
28 #include <toolkit/awt/vclxaccessiblecomponent.hxx>
29 #include <toolkit/awt/vclxwindow.hxx>
30 #include <toolkit/helper/convert.hxx>
31 #include <toolkit/awt/vclxfont.hxx>
32 #include <vcl/dialog.hxx>
33 #include <vcl/vclevent.hxx>
34 #include <vcl/window.hxx>
35 #include <vcl/edit.hxx>
36 #include <vcl/settings.hxx>
37 #include <tools/debug.hxx>
38 #include <unotools/accessiblestatesethelper.hxx>
39 #include <unotools/accessiblerelationsethelper.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vcl/menu.hxx>
43 using namespace ::com::sun::star;
44 using namespace ::comphelper;
46 VCLXAccessibleComponent::VCLXAccessibleComponent( VCLXWindow* pVCLXWindow )
48 m_xVCLXWindow = pVCLXWindow;
50 DBG_ASSERT( pVCLXWindow->GetWindow(), "VCLXAccessibleComponent - no window!" );
51 m_xEventSource = pVCLXWindow->GetWindow();
52 if ( m_xEventSource )
54 m_xEventSource->AddEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
55 m_xEventSource->AddChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
58 // announce the XAccessible of our creator to the base class
59 lateInit( pVCLXWindow );
62 VCLXWindow* VCLXAccessibleComponent::GetVCLXWindow() const
64 return m_xVCLXWindow.get();
67 void VCLXAccessibleComponent::DisconnectEvents()
69 if ( m_xEventSource )
71 m_xEventSource->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
72 m_xEventSource->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
73 m_xEventSource.clear();
77 VCLXAccessibleComponent::~VCLXAccessibleComponent()
79 ensureDisposed();
80 DisconnectEvents();
83 IMPLEMENT_FORWARD_XINTERFACE3( VCLXAccessibleComponent, OAccessibleExtendedComponentHelper, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE )
84 IMPLEMENT_FORWARD_XTYPEPROVIDER3( VCLXAccessibleComponent, OAccessibleExtendedComponentHelper, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE )
86 OUString VCLXAccessibleComponent::getImplementationName()
88 return OUString("com.sun.star.comp.toolkit.AccessibleWindow");
91 sal_Bool VCLXAccessibleComponent::supportsService( const OUString& rServiceName )
93 return cppu::supportsService(this, rServiceName);
96 uno::Sequence< OUString > VCLXAccessibleComponent::getSupportedServiceNames()
98 uno::Sequence< OUString > aNames { "com.sun.star.awt.AccessibleWindow" };
99 return aNames;
102 IMPL_LINK( VCLXAccessibleComponent, WindowEventListener, VclWindowEvent&, rEvent, void )
104 /* Ignore VclEventId::WindowEndPopupMode, because the UNO accessibility wrapper
105 * might have been destroyed by the previous VCLEventListener (if no AT tool
106 * is running), e.g. sub-toolbars in impress.
108 if ( m_xVCLXWindow.is() /* #122218# */ && (rEvent.GetId() != VclEventId::WindowEndPopupMode) )
110 DBG_ASSERT( rEvent.GetWindow(), "Window???" );
111 if( !rEvent.GetWindow()->IsAccessibilityEventsSuppressed() || ( rEvent.GetId() == VclEventId::ObjectDying ) )
113 ProcessWindowEvent( rEvent );
118 IMPL_LINK( VCLXAccessibleComponent, WindowChildEventListener, VclWindowEvent&, rEvent, void )
120 if ( m_xVCLXWindow.is() /* #i68079# */ )
122 DBG_ASSERT( rEvent.GetWindow(), "Window???" );
123 if( !rEvent.GetWindow()->IsAccessibilityEventsSuppressed() )
125 // #103087# to prevent an early release of the component
126 uno::Reference< accessibility::XAccessibleContext > xTmp = this;
128 ProcessWindowChildEvent( rEvent );
133 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::GetChildAccessible( const VclWindowEvent& rVclWindowEvent )
135 // checks if the data in the window event is our direct child
136 // and returns its accessible
138 // MT: Change this later, normally a show/hide event shouldn't have the vcl::Window* in pData.
139 vcl::Window* pChildWindow = static_cast<vcl::Window *>(rVclWindowEvent.GetData());
140 if( pChildWindow && GetWindow() == pChildWindow->GetAccessibleParentWindow() )
141 return pChildWindow->GetAccessible( rVclWindowEvent.GetId() == VclEventId::WindowShow );
142 else
143 return uno::Reference< accessibility::XAccessible > ();
146 void VCLXAccessibleComponent::ProcessWindowChildEvent( const VclWindowEvent& rVclWindowEvent )
148 uno::Any aOldValue, aNewValue;
149 uno::Reference< accessibility::XAccessible > xAcc;
151 switch ( rVclWindowEvent.GetId() )
153 case VclEventId::WindowShow: // send create on show for direct accessible children
155 xAcc = GetChildAccessible( rVclWindowEvent );
156 if( xAcc.is() )
158 aNewValue <<= xAcc;
159 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
162 break;
163 case VclEventId::WindowHide: // send destroy on hide for direct accessible children
165 xAcc = GetChildAccessible( rVclWindowEvent );
166 if( xAcc.is() )
168 aOldValue <<= xAcc;
169 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
172 break;
173 default: break;
177 void VCLXAccessibleComponent::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
179 uno::Any aOldValue, aNewValue;
181 vcl::Window* pAccWindow = rVclWindowEvent.GetWindow();
182 assert(pAccWindow && "VCLXAccessibleComponent::ProcessWindowEvent - Window?");
184 switch ( rVclWindowEvent.GetId() )
186 case VclEventId::ObjectDying:
188 DisconnectEvents();
189 m_xVCLXWindow.clear();
191 break;
192 case VclEventId::WindowChildDestroyed:
194 vcl::Window* pWindow = static_cast<vcl::Window*>(rVclWindowEvent.GetData());
195 DBG_ASSERT( pWindow, "VclEventId::WindowChildDestroyed - Window=?" );
196 if ( pWindow->GetAccessible( false ).is() )
198 aOldValue <<= pWindow->GetAccessible( false );
199 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
202 break;
203 case VclEventId::WindowActivate:
205 sal_Int16 aAccessibleRole = getAccessibleRole();
206 // avoid notification if a child frame is already active
207 // only one frame may be active at a given time
208 if ( !pAccWindow->HasActiveChildFrame() &&
209 ( aAccessibleRole == accessibility::AccessibleRole::FRAME ||
210 aAccessibleRole == accessibility::AccessibleRole::ALERT ||
211 aAccessibleRole == accessibility::AccessibleRole::DIALOG ) ) // #i18891#
213 aNewValue <<= accessibility::AccessibleStateType::ACTIVE;
214 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
217 break;
218 case VclEventId::WindowDeactivate:
220 sal_Int16 aAccessibleRole = getAccessibleRole();
221 if ( aAccessibleRole == accessibility::AccessibleRole::FRAME ||
222 aAccessibleRole == accessibility::AccessibleRole::ALERT ||
223 aAccessibleRole == accessibility::AccessibleRole::DIALOG ) // #i18891#
225 aOldValue <<= accessibility::AccessibleStateType::ACTIVE;
226 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
229 break;
230 case VclEventId::WindowGetFocus:
231 case VclEventId::ControlGetFocus:
233 if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VclEventId::ControlGetFocus) ||
234 (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VclEventId::WindowGetFocus) )
236 // if multiple listeners were registered it is possible that the
237 // focus was changed during event processing (eg SfxTopWindow )
238 // #106082# allow ChildPathFocus only for CompoundControls, for windows the focus must be in the window itself
239 if( (pAccWindow->IsCompoundControl() && pAccWindow->HasChildPathFocus()) ||
240 (!pAccWindow->IsCompoundControl() && pAccWindow->HasFocus()) )
242 aNewValue <<= accessibility::AccessibleStateType::FOCUSED;
243 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
247 break;
248 case VclEventId::WindowLoseFocus:
249 case VclEventId::ControlLoseFocus:
251 if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VclEventId::ControlLoseFocus) ||
252 (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VclEventId::WindowLoseFocus) )
254 aOldValue <<= accessibility::AccessibleStateType::FOCUSED;
255 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
258 break;
259 case VclEventId::WindowFrameTitleChanged:
261 OUString aOldName( *static_cast<OUString*>(rVclWindowEvent.GetData()) );
262 OUString aNewName( getAccessibleName() );
263 aOldValue <<= aOldName;
264 aNewValue <<= aNewName;
265 NotifyAccessibleEvent( accessibility::AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
267 break;
268 case VclEventId::WindowEnabled:
270 aNewValue <<= accessibility::AccessibleStateType::ENABLED;
271 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
272 aNewValue <<= accessibility::AccessibleStateType::SENSITIVE;
273 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
275 break;
276 case VclEventId::WindowDisabled:
278 aOldValue <<= accessibility::AccessibleStateType::SENSITIVE;
279 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
281 aOldValue <<= accessibility::AccessibleStateType::ENABLED;
282 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
284 break;
285 case VclEventId::WindowMove:
286 case VclEventId::WindowResize:
288 NotifyAccessibleEvent( accessibility::AccessibleEventId::BOUNDRECT_CHANGED, aOldValue, aNewValue );
290 break;
291 case VclEventId::WindowMenubarAdded:
293 MenuBar* pMenuBar = static_cast<MenuBar*>(rVclWindowEvent.GetData());
294 if ( pMenuBar )
296 uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() );
297 if ( xChild.is() )
299 aNewValue <<= xChild;
300 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
304 break;
305 case VclEventId::WindowMenubarRemoved:
307 MenuBar* pMenuBar = static_cast<MenuBar*>(rVclWindowEvent.GetData());
308 if ( pMenuBar )
310 uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() );
311 if ( xChild.is() )
313 aOldValue <<= xChild;
314 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
318 break;
319 case VclEventId::WindowMinimize:
321 aNewValue <<= accessibility::AccessibleStateType::ICONIFIED;
322 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
324 break;
325 case VclEventId::WindowNormalize:
327 aOldValue <<= accessibility::AccessibleStateType::ICONIFIED;
328 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
330 break;
331 default:
334 break;
338 void VCLXAccessibleComponent::disposing()
340 DisconnectEvents();
342 OAccessibleExtendedComponentHelper::disposing();
344 m_xVCLXWindow.clear();
347 VclPtr<vcl::Window> VCLXAccessibleComponent::GetWindow() const
349 return GetVCLXWindow() ? GetVCLXWindow()->GetWindow()
350 : VclPtr<vcl::Window>();
353 void VCLXAccessibleComponent::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet )
355 VclPtr<vcl::Window> pWindow = GetWindow();
356 if ( pWindow )
358 vcl::Window *pLabeledBy = pWindow->GetAccessibleRelationLabeledBy();
359 if ( pLabeledBy && pLabeledBy != pWindow )
361 uno::Sequence< uno::Reference< uno::XInterface > > aSequence { pLabeledBy->GetAccessible() };
362 rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABELED_BY, aSequence ) );
365 vcl::Window* pLabelFor = pWindow->GetAccessibleRelationLabelFor();
366 if ( pLabelFor && pLabelFor != pWindow )
368 uno::Sequence< uno::Reference< uno::XInterface > > aSequence { pLabelFor->GetAccessible() };
369 rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABEL_FOR, aSequence ) );
372 vcl::Window* pMemberOf = pWindow->GetAccessibleRelationMemberOf();
373 if ( pMemberOf && pMemberOf != pWindow )
375 uno::Sequence< uno::Reference< uno::XInterface > > aSequence { pMemberOf->GetAccessible() };
376 rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::MEMBER_OF, aSequence ) );
379 for (const auto& rExtraRelation : pWindow->GetExtraAccessibleRelations())
380 rRelationSet.AddRelation(rExtraRelation);
384 void VCLXAccessibleComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
386 VclPtr<vcl::Window> pWindow = GetWindow();
387 if ( pWindow )
389 if ( pWindow->IsVisible() )
391 rStateSet.AddState( accessibility::AccessibleStateType::VISIBLE );
392 rStateSet.AddState( accessibility::AccessibleStateType::SHOWING );
394 else
396 rStateSet.AddState( accessibility::AccessibleStateType::INVALID );
399 if ( pWindow->IsEnabled() )
401 rStateSet.AddState( accessibility::AccessibleStateType::ENABLED );
402 rStateSet.AddState( accessibility::AccessibleStateType::SENSITIVE );
405 if ( pWindow->HasChildPathFocus() &&
406 ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||
407 getAccessibleRole() == accessibility::AccessibleRole::ALERT ||
408 getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) ) // #i18891#
409 rStateSet.AddState( accessibility::AccessibleStateType::ACTIVE );
411 if ( pWindow->HasFocus() || ( pWindow->IsCompoundControl() && pWindow->HasChildPathFocus() ) )
412 rStateSet.AddState( accessibility::AccessibleStateType::FOCUSED );
414 if ( pWindow->IsWait() )
415 rStateSet.AddState( accessibility::AccessibleStateType::BUSY );
417 if ( pWindow->GetStyle() & WB_SIZEABLE )
418 rStateSet.AddState( accessibility::AccessibleStateType::RESIZABLE );
419 // 6. frame doesn't have MOVABLE state
420 // 10. for password text, where is the sensitive state?
421 if( ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||getAccessibleRole() == accessibility::AccessibleRole::DIALOG )&& pWindow->GetStyle() & WB_MOVEABLE )
422 rStateSet.AddState( accessibility::AccessibleStateType::MOVEABLE );
423 if( pWindow->IsDialog() )
425 Dialog *pDlg = static_cast< Dialog* >( pWindow.get() );
426 if( pDlg->IsInExecute() )
427 rStateSet.AddState( accessibility::AccessibleStateType::MODAL );
429 //If a combobox or list's edit child isn't read-only,EDITABLE state
430 //should be set.
431 if( pWindow && pWindow->GetType() == WindowType::COMBOBOX )
433 if( !( pWindow->GetStyle() & WB_READONLY) ||
434 !static_cast<Edit*>(pWindow.get())->IsReadOnly() )
435 rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE );
438 VclPtr<vcl::Window> pChild = pWindow->GetWindow( GetWindowType::FirstChild );
440 while( pWindow && pChild )
442 VclPtr<vcl::Window> pWinTemp = pChild->GetWindow( GetWindowType::FirstChild );
443 if( pWinTemp && pWinTemp->GetType() == WindowType::EDIT )
445 if( !( pWinTemp->GetStyle() & WB_READONLY) ||
446 !static_cast<Edit*>(pWinTemp.get())->IsReadOnly() )
447 rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE );
448 break;
450 if( pChild->GetType() == WindowType::EDIT )
452 if( !( pChild->GetStyle() & WB_READONLY) ||
453 !static_cast<Edit*>(pChild.get())->IsReadOnly())
454 rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE );
455 break;
457 pChild = pChild->GetWindow( GetWindowType::Next );
460 else
462 rStateSet.AddState( accessibility::AccessibleStateType::DEFUNC );
467 MUST BE SET FROM DERIVED CLASSES:
469 CHECKED
470 COLLAPSED
471 EXPANDED
472 EXPANDABLE
473 EDITABLE
474 FOCUSABLE
475 HORIZONTAL
476 VERTICAL
477 ICONIFIED
478 MULTILINE
479 MULTI_SELECTABLE
480 PRESSED
481 SELECTABLE
482 SELECTED
483 SINGLE_LINE
484 TRANSIENT
490 // accessibility::XAccessibleContext
491 sal_Int32 VCLXAccessibleComponent::getAccessibleChildCount()
493 OExternalLockGuard aGuard( this );
495 sal_Int32 nChildren = 0;
496 if ( GetWindow() )
497 nChildren = GetWindow()->GetAccessibleChildWindowCount();
499 return nChildren;
502 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleChild( sal_Int32 i )
504 OExternalLockGuard aGuard( this );
506 if ( i >= getAccessibleChildCount() )
507 throw lang::IndexOutOfBoundsException();
509 uno::Reference< accessibility::XAccessible > xAcc;
510 if ( GetWindow() )
512 vcl::Window* pChild = GetWindow()->GetAccessibleChildWindow( static_cast<sal_uInt16>(i) );
513 if ( pChild )
514 xAcc = pChild->GetAccessible();
517 return xAcc;
520 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getVclParent() const
522 uno::Reference< accessibility::XAccessible > xAcc;
523 if ( GetWindow() )
525 vcl::Window* pParent = GetWindow()->GetAccessibleParentWindow();
526 if ( pParent )
527 xAcc = pParent->GetAccessible();
529 return xAcc;
532 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleParent( )
534 OExternalLockGuard aGuard( this );
536 // we do _not_ have a foreign-controlled parent -> default to our VCL parent
537 uno::Reference< accessibility::XAccessible > xAcc = getVclParent();
539 return xAcc;
542 sal_Int32 VCLXAccessibleComponent::getAccessibleIndexInParent( )
544 OExternalLockGuard aGuard( this );
546 sal_Int32 nIndex = -1;
548 if ( GetWindow() )
550 vcl::Window* pParent = GetWindow()->GetAccessibleParentWindow();
551 if ( pParent )
553 // Iterate over all the parent's children and search for this object.
554 // this should be compatible with the code in SVX
555 uno::Reference< accessibility::XAccessible > xParentAcc( pParent->GetAccessible() );
556 if ( xParentAcc.is() )
558 uno::Reference< accessibility::XAccessibleContext > xParentContext ( xParentAcc->getAccessibleContext() );
559 if ( xParentContext.is() )
561 sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
562 for ( sal_Int32 i=0; i<nChildCount; i++ )
564 uno::Reference< accessibility::XAccessible > xChild( xParentContext->getAccessibleChild(i) );
565 if ( xChild.is() )
567 uno::Reference< accessibility::XAccessibleContext > xChildContext = xChild->getAccessibleContext();
568 if ( xChildContext == static_cast<accessibility::XAccessibleContext*>(this) )
570 nIndex = i;
571 break;
579 return nIndex;
582 sal_Int16 VCLXAccessibleComponent::getAccessibleRole( )
584 OExternalLockGuard aGuard( this );
586 sal_Int16 nRole = 0;
588 if ( GetWindow() )
589 nRole = GetWindow()->GetAccessibleRole();
591 return nRole;
594 OUString VCLXAccessibleComponent::getAccessibleDescription( )
596 OExternalLockGuard aGuard( this );
598 OUString aDescription;
600 if ( GetWindow() )
601 aDescription = GetWindow()->GetAccessibleDescription();
603 return aDescription;
606 OUString VCLXAccessibleComponent::getAccessibleName( )
608 OExternalLockGuard aGuard( this );
610 OUString aName;
611 if ( GetWindow() )
613 aName = GetWindow()->GetAccessibleName();
614 #if OSL_DEBUG_LEVEL > 0
615 aName += " (Type = ";
616 aName += OUString::number(static_cast<sal_Int32>(GetWindow()->GetType()));
617 aName += ")";
618 #endif
620 return aName;
623 OUString VCLXAccessibleComponent::getAccessibleId( )
625 OExternalLockGuard aGuard( this );
627 OUString aId;
628 if ( GetWindow() )
630 const OUString &aWindowId = GetWindow()->get_id();
631 aId = aWindowId;
633 return aId;
636 uno::Reference< accessibility::XAccessibleRelationSet > VCLXAccessibleComponent::getAccessibleRelationSet( )
638 OExternalLockGuard aGuard( this );
640 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
641 uno::Reference< accessibility::XAccessibleRelationSet > xSet = pRelationSetHelper;
642 FillAccessibleRelationSet( *pRelationSetHelper );
643 return xSet;
646 uno::Reference< accessibility::XAccessibleStateSet > VCLXAccessibleComponent::getAccessibleStateSet( )
648 OExternalLockGuard aGuard( this );
650 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
651 uno::Reference< accessibility::XAccessibleStateSet > xSet = pStateSetHelper;
652 FillAccessibleStateSet( *pStateSetHelper );
653 return xSet;
656 lang::Locale VCLXAccessibleComponent::getLocale()
658 OExternalLockGuard aGuard( this );
660 return Application::GetSettings().GetLanguageTag().getLocale();
663 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleAtPoint( const awt::Point& rPoint )
665 OExternalLockGuard aGuard( this );
667 uno::Reference< accessibility::XAccessible > xChild;
668 for ( sal_uInt32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
670 uno::Reference< accessibility::XAccessible > xAcc = getAccessibleChild( i );
671 if ( xAcc.is() )
673 uno::Reference< accessibility::XAccessibleComponent > xComp( xAcc->getAccessibleContext(), uno::UNO_QUERY );
674 if ( xComp.is() )
676 tools::Rectangle aRect = VCLRectangle( xComp->getBounds() );
677 Point aPos = VCLPoint( rPoint );
678 if ( aRect.IsInside( aPos ) )
680 xChild = xAcc;
681 break;
687 return xChild;
690 // accessibility::XAccessibleComponent
691 awt::Rectangle VCLXAccessibleComponent::implGetBounds()
693 awt::Rectangle aBounds ( 0, 0, 0, 0 );
695 VclPtr<vcl::Window> pWindow = GetWindow();
696 if ( pWindow )
698 tools::Rectangle aRect = pWindow->GetWindowExtentsRelative( nullptr );
699 aBounds = AWTRectangle( aRect );
700 vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
701 if ( pParent )
703 tools::Rectangle aParentRect = pParent->GetWindowExtentsRelative( nullptr );
704 awt::Point aParentScreenLoc = AWTPoint( aParentRect.TopLeft() );
705 aBounds.X -= aParentScreenLoc.X;
706 aBounds.Y -= aParentScreenLoc.Y;
710 return aBounds;
713 awt::Point VCLXAccessibleComponent::getLocationOnScreen( )
715 OExternalLockGuard aGuard( this );
717 awt::Point aPos;
718 if ( GetWindow() )
720 tools::Rectangle aRect = GetWindow()->GetWindowExtentsRelative( nullptr );
721 aPos.X = aRect.Left();
722 aPos.Y = aRect.Top();
725 return aPos;
728 void VCLXAccessibleComponent::grabFocus( )
730 OExternalLockGuard aGuard( this );
732 uno::Reference< accessibility::XAccessibleStateSet > xStates = getAccessibleStateSet();
733 if ( m_xVCLXWindow.is() && xStates.is() && xStates->contains( accessibility::AccessibleStateType::FOCUSABLE ) )
734 m_xVCLXWindow->setFocus();
737 sal_Int32 SAL_CALL VCLXAccessibleComponent::getForeground( )
739 OExternalLockGuard aGuard( this );
741 Color nColor;
742 VclPtr<vcl::Window> pWindow = GetWindow();
743 if ( pWindow )
745 if ( pWindow->IsControlForeground() )
746 nColor = pWindow->GetControlForeground();
747 else
749 vcl::Font aFont;
750 if ( pWindow->IsControlFont() )
751 aFont = pWindow->GetControlFont();
752 else
753 aFont = pWindow->GetFont();
754 nColor = aFont.GetColor();
755 // COL_AUTO is not very meaningful for AT
756 if ( nColor == COL_AUTO)
757 nColor = pWindow->GetTextColor();
761 return sal_Int32(nColor);
764 sal_Int32 SAL_CALL VCLXAccessibleComponent::getBackground( )
766 OExternalLockGuard aGuard( this );
768 Color nColor;
769 VclPtr<vcl::Window> pWindow = GetWindow();
770 if ( pWindow )
772 if ( pWindow->IsControlBackground() )
773 nColor = pWindow->GetControlBackground();
774 else
775 nColor = pWindow->GetBackground().GetColor();
778 return sal_Int32(nColor);
781 // XAccessibleExtendedComponent
783 uno::Reference< awt::XFont > SAL_CALL VCLXAccessibleComponent::getFont( )
785 OExternalLockGuard aGuard( this );
787 uno::Reference< awt::XFont > xFont;
788 VclPtr<vcl::Window> pWindow = GetWindow();
789 if ( pWindow )
791 uno::Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), uno::UNO_QUERY );
792 if ( xDev.is() )
794 vcl::Font aFont;
795 if ( pWindow->IsControlFont() )
796 aFont = pWindow->GetControlFont();
797 else
798 aFont = pWindow->GetFont();
799 VCLXFont* pVCLXFont = new VCLXFont;
800 pVCLXFont->Init( *xDev, aFont );
801 xFont = pVCLXFont;
805 return xFont;
808 OUString SAL_CALL VCLXAccessibleComponent::getTitledBorderText( )
810 OExternalLockGuard aGuard( this );
812 OUString sRet;
813 if ( GetWindow() )
814 sRet = GetWindow()->GetText();
816 return sRet;
819 OUString SAL_CALL VCLXAccessibleComponent::getToolTipText( )
821 OExternalLockGuard aGuard( this );
823 OUString sRet;
824 if ( GetWindow() )
825 sRet = GetWindow()->GetQuickHelpText();
827 return sRet;
830 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */