bump product version to 4.1.6.2
[LibreOffice.git] / toolkit / source / awt / vclxaccessiblecomponent.cxx
blobd18915805224b73f4b22150b9b9dc1fee3bd7386
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 <toolkit/awt/vclxaccessiblecomponent.hxx>
26 #include <toolkit/helper/externallock.hxx>
27 #include <toolkit/awt/vclxwindow.hxx>
28 #include <toolkit/helper/convert.hxx>
29 #include <toolkit/awt/vclxfont.hxx>
30 #include <vcl/dialog.hxx>
31 #include <vcl/vclevent.hxx>
32 #include <vcl/window.hxx>
33 #include <tools/debug.hxx>
34 #include <unotools/accessiblestatesethelper.hxx>
35 #include <unotools/accessiblerelationsethelper.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/menu.hxx>
39 using namespace ::com::sun::star;
40 using namespace ::comphelper;
43 DBG_NAME(VCLXAccessibleComponent)
46 VCLXAccessibleComponent::VCLXAccessibleComponent( VCLXWindow* pVCLXindow )
47 : AccessibleExtendedComponentHelper_BASE( new VCLExternalSolarLock() )
48 , OAccessibleImplementationAccess( )
50 DBG_CTOR( VCLXAccessibleComponent, 0 );
51 mpVCLXindow = pVCLXindow;
52 mxWindow = pVCLXindow;
54 m_pSolarLock = static_cast< VCLExternalSolarLock* >( getExternalLock( ) );
56 DBG_ASSERT( pVCLXindow->GetWindow(), "VCLXAccessibleComponent - no window!" );
57 if ( pVCLXindow->GetWindow() )
59 pVCLXindow->GetWindow()->AddEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
60 pVCLXindow->GetWindow()->AddChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
63 // announce the XAccessible of our creator to the base class
64 lateInit( pVCLXindow );
67 VCLXAccessibleComponent::~VCLXAccessibleComponent()
69 DBG_DTOR( VCLXAccessibleComponent, 0 );
71 ensureDisposed();
73 if ( mpVCLXindow && mpVCLXindow->GetWindow() )
75 mpVCLXindow->GetWindow()->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
76 mpVCLXindow->GetWindow()->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
79 delete m_pSolarLock;
80 m_pSolarLock = NULL;
81 // This is not completely safe. If we assume that the base class dtor calls some method which
82 // uses this lock, the we crash. However, as the base class' dtor does not have a chance to call _out_
83 // virtual methods, this is no problem as long as the base class is safe, i.e. does not use the external
84 // lock from within it's dtor. At the moment, we _know_ the base class is safe in this respect, so
85 // let's assume it keeps this way.
86 // @see OAccessibleContextHelper::OAccessibleContextHelper( IMutex* )
89 IMPLEMENT_FORWARD_XINTERFACE3( VCLXAccessibleComponent, AccessibleExtendedComponentHelper_BASE, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE )
90 IMPLEMENT_FORWARD_XTYPEPROVIDER3( VCLXAccessibleComponent, AccessibleExtendedComponentHelper_BASE, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE )
92 OUString VCLXAccessibleComponent::getImplementationName() throw (uno::RuntimeException)
94 return OUString("com.sun.star.comp.toolkit.AccessibleWindow");
97 sal_Bool VCLXAccessibleComponent::supportsService( const OUString& rServiceName ) throw (uno::RuntimeException)
99 uno::Sequence< OUString > aNames( getSupportedServiceNames() );
100 const OUString* pNames = aNames.getConstArray();
101 const OUString* pEnd = pNames + aNames.getLength();
102 for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
105 return pNames != pEnd;
108 uno::Sequence< OUString > VCLXAccessibleComponent::getSupportedServiceNames() throw (uno::RuntimeException)
110 uno::Sequence< OUString > aNames(1);
111 aNames[0] = OUString("com.sun.star.awt.AccessibleWindow");
112 return aNames;
115 IMPL_LINK( VCLXAccessibleComponent, WindowEventListener, VclSimpleEvent*, pEvent )
117 DBG_CHKTHIS(VCLXAccessibleComponent,0);
119 DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
121 /* Ignore VCLEVENT_WINDOW_ENDPOPUPMODE, because the UNO accessibility wrapper
122 * might have been destroyed by the previous VCLEventListener (if no AT tool
123 * is running), e.g. sub-toolbars in impress.
125 if ( pEvent && pEvent->ISA( VclWindowEvent ) && mxWindow.is() /* #122218# */ && (pEvent->GetId() != VCLEVENT_WINDOW_ENDPOPUPMODE) )
127 DBG_ASSERT( ((VclWindowEvent*)pEvent)->GetWindow(), "Window???" );
128 if( !((VclWindowEvent*)pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() || ( pEvent->GetId() == VCLEVENT_OBJECT_DYING ) )
130 ProcessWindowEvent( *(VclWindowEvent*)pEvent );
133 return 0;
136 IMPL_LINK( VCLXAccessibleComponent, WindowChildEventListener, VclSimpleEvent*, pEvent )
138 DBG_CHKTHIS(VCLXAccessibleComponent,0);
140 DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
141 if ( pEvent && pEvent->ISA( VclWindowEvent ) && mxWindow.is() /* #i68079# */ )
143 DBG_ASSERT( ((VclWindowEvent*)pEvent)->GetWindow(), "Window???" );
144 if( !((VclWindowEvent*)pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() )
146 // #103087# to prevent an early release of the component
147 uno::Reference< accessibility::XAccessibleContext > xTmp = this;
149 ProcessWindowChildEvent( *(VclWindowEvent*)pEvent );
152 return 0;
155 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::GetChildAccessible( const VclWindowEvent& rVclWindowEvent )
157 // checks if the data in the window event is our direct child
158 // and returns its accessible
160 // MT: Change this later, normaly a show/hide event shouldn't have the Window* in pData.
161 Window* pChildWindow = (Window *) rVclWindowEvent.GetData();
162 if( pChildWindow && GetWindow() == pChildWindow->GetAccessibleParentWindow() )
163 return pChildWindow->GetAccessible( rVclWindowEvent.GetId() == VCLEVENT_WINDOW_SHOW );
164 else
165 return uno::Reference< accessibility::XAccessible > ();
168 void VCLXAccessibleComponent::ProcessWindowChildEvent( const VclWindowEvent& rVclWindowEvent )
170 uno::Any aOldValue, aNewValue;
171 uno::Reference< accessibility::XAccessible > xAcc;
173 switch ( rVclWindowEvent.GetId() )
175 case VCLEVENT_WINDOW_SHOW: // send create on show for direct accessible children
177 xAcc = GetChildAccessible( rVclWindowEvent );
178 if( xAcc.is() )
180 aNewValue <<= xAcc;
181 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
184 break;
185 case VCLEVENT_WINDOW_HIDE: // send destroy on hide for direct accessible children
187 xAcc = GetChildAccessible( rVclWindowEvent );
188 if( xAcc.is() )
190 aOldValue <<= xAcc;
191 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
194 break;
198 void VCLXAccessibleComponent::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
200 uno::Any aOldValue, aNewValue;
202 Window* pAccWindow = rVclWindowEvent.GetWindow();
203 DBG_ASSERT( pAccWindow, "VCLXAccessibleComponent::ProcessWindowEvent - Window?" );
205 switch ( rVclWindowEvent.GetId() )
207 case VCLEVENT_OBJECT_DYING:
209 pAccWindow->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
210 pAccWindow->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
211 mxWindow.clear();
212 mpVCLXindow = NULL;
214 break;
215 case VCLEVENT_WINDOW_CHILDDESTROYED:
217 Window* pWindow = (Window*) rVclWindowEvent.GetData();
218 DBG_ASSERT( pWindow, "VCLEVENT_WINDOW_CHILDDESTROYED - Window=?" );
219 if ( pWindow->GetAccessible( sal_False ).is() )
221 aOldValue <<= pWindow->GetAccessible( sal_False );
222 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
225 break;
226 case VCLEVENT_WINDOW_ACTIVATE:
228 // avoid notification if a child frame is already active
229 // only one frame may be active at a given time
230 if ( !pAccWindow->HasActiveChildFrame() &&
231 ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||
232 getAccessibleRole() == accessibility::AccessibleRole::ALERT ||
233 getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) ) // #i18891#
235 aNewValue <<= accessibility::AccessibleStateType::ACTIVE;
236 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
239 break;
240 case VCLEVENT_WINDOW_DEACTIVATE:
242 if ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||
243 getAccessibleRole() == accessibility::AccessibleRole::ALERT ||
244 getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) // #i18891#
246 aOldValue <<= accessibility::AccessibleStateType::ACTIVE;
247 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
250 break;
251 case VCLEVENT_WINDOW_GETFOCUS:
252 case VCLEVENT_CONTROL_GETFOCUS:
254 if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_CONTROL_GETFOCUS) ||
255 (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_WINDOW_GETFOCUS) )
257 // if multiple listeners were registered it is possible that the
258 // focus was changed during event processing (eg SfxTopWindow )
259 // #106082# allow ChildPathFocus only for CompoundControls, for windows the focus must be in the window itself
260 if( (pAccWindow->IsCompoundControl() && pAccWindow->HasChildPathFocus()) ||
261 (!pAccWindow->IsCompoundControl() && pAccWindow->HasFocus()) )
263 aNewValue <<= accessibility::AccessibleStateType::FOCUSED;
264 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
268 break;
269 case VCLEVENT_WINDOW_LOSEFOCUS:
270 case VCLEVENT_CONTROL_LOSEFOCUS:
272 if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_CONTROL_LOSEFOCUS) ||
273 (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_WINDOW_LOSEFOCUS) )
275 aOldValue <<= accessibility::AccessibleStateType::FOCUSED;
276 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
279 break;
280 case VCLEVENT_WINDOW_FRAMETITLECHANGED:
282 OUString aOldName( *((OUString*) rVclWindowEvent.GetData()) );
283 OUString aNewName( getAccessibleName() );
284 aOldValue <<= aOldName;
285 aNewValue <<= aNewName;
286 NotifyAccessibleEvent( accessibility::AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
288 break;
289 case VCLEVENT_WINDOW_ENABLED:
291 aNewValue <<= accessibility::AccessibleStateType::ENABLED;
292 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
293 aNewValue <<= accessibility::AccessibleStateType::SENSITIVE;
294 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
296 break;
297 case VCLEVENT_WINDOW_DISABLED:
299 aOldValue <<= accessibility::AccessibleStateType::SENSITIVE;
300 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
302 aOldValue <<= accessibility::AccessibleStateType::ENABLED;
303 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
305 break;
306 case VCLEVENT_WINDOW_MOVE:
307 case VCLEVENT_WINDOW_RESIZE:
309 NotifyAccessibleEvent( accessibility::AccessibleEventId::BOUNDRECT_CHANGED, aOldValue, aNewValue );
311 break;
312 case VCLEVENT_WINDOW_MENUBARADDED:
314 MenuBar* pMenuBar = (MenuBar*) rVclWindowEvent.GetData();
315 if ( pMenuBar )
317 uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() );
318 if ( xChild.is() )
320 aNewValue <<= xChild;
321 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
325 break;
326 case VCLEVENT_WINDOW_MENUBARREMOVED:
328 MenuBar* pMenuBar = (MenuBar*) rVclWindowEvent.GetData();
329 if ( pMenuBar )
331 uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() );
332 if ( xChild.is() )
334 aOldValue <<= xChild;
335 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
339 break;
340 case VCLEVENT_WINDOW_MINIMIZE:
342 aNewValue <<= accessibility::AccessibleStateType::ICONIFIED;
343 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
345 break;
346 case VCLEVENT_WINDOW_NORMALIZE:
348 aOldValue <<= accessibility::AccessibleStateType::ICONIFIED;
349 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
351 break;
352 default:
355 break;
359 void VCLXAccessibleComponent::disposing()
361 if ( mpVCLXindow && mpVCLXindow->GetWindow() )
363 mpVCLXindow->GetWindow()->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
364 mpVCLXindow->GetWindow()->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
367 AccessibleExtendedComponentHelper_BASE::disposing();
369 mxWindow.clear();
370 mpVCLXindow = NULL;
373 Window* VCLXAccessibleComponent::GetWindow() const
375 return GetVCLXWindow() ? GetVCLXWindow()->GetWindow() : NULL;
378 void VCLXAccessibleComponent::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet )
380 Window* pWindow = GetWindow();
381 if ( pWindow )
383 Window *pLabeledBy = pWindow->GetAccessibleRelationLabeledBy();
384 if ( pLabeledBy && pLabeledBy != pWindow )
386 uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
387 aSequence[0] = pLabeledBy->GetAccessible();
388 rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABELED_BY, aSequence ) );
391 Window* pLabelFor = pWindow->GetAccessibleRelationLabelFor();
392 if ( pLabelFor && pLabelFor != pWindow )
394 uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
395 aSequence[0] = pLabelFor->GetAccessible();
396 rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABEL_FOR, aSequence ) );
399 Window* pMemberOf = pWindow->GetAccessibleRelationMemberOf();
400 if ( pMemberOf && pMemberOf != pWindow )
402 uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
403 aSequence[0] = pMemberOf->GetAccessible();
404 rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::MEMBER_OF, aSequence ) );
409 void VCLXAccessibleComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
411 Window* pWindow = GetWindow();
412 if ( pWindow )
414 if ( pWindow->IsVisible() )
416 rStateSet.AddState( accessibility::AccessibleStateType::VISIBLE );
417 rStateSet.AddState( accessibility::AccessibleStateType::SHOWING );
419 else
421 rStateSet.AddState( accessibility::AccessibleStateType::INVALID );
424 if ( pWindow->IsEnabled() )
426 rStateSet.AddState( accessibility::AccessibleStateType::ENABLED );
427 rStateSet.AddState( accessibility::AccessibleStateType::SENSITIVE );
430 if ( pWindow->HasChildPathFocus() &&
431 ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||
432 getAccessibleRole() == accessibility::AccessibleRole::ALERT ||
433 getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) ) // #i18891#
434 rStateSet.AddState( accessibility::AccessibleStateType::ACTIVE );
436 if ( pWindow->HasFocus() || ( pWindow->IsCompoundControl() && pWindow->HasChildPathFocus() ) )
437 rStateSet.AddState( accessibility::AccessibleStateType::FOCUSED );
439 if ( pWindow->IsWait() )
440 rStateSet.AddState( accessibility::AccessibleStateType::BUSY );
442 if ( pWindow->GetStyle() & WB_SIZEABLE )
443 rStateSet.AddState( accessibility::AccessibleStateType::RESIZABLE );
445 if( pWindow->IsDialog() )
447 Dialog *pDlg = static_cast< Dialog* >( pWindow );
448 if( pDlg->IsInExecute() )
449 rStateSet.AddState( accessibility::AccessibleStateType::MODAL );
452 else
454 rStateSet.AddState( accessibility::AccessibleStateType::DEFUNC );
459 MUST BE SET FROM DERIVED CLASSES:
461 CHECKED
462 COLLAPSED
463 EXPANDED
464 EXPANDABLE
465 EDITABLE
466 FOCUSABLE
467 HORIZONTAL
468 VERTICAL
469 ICONIFIED
470 MULTILINE
471 MULTI_SELECTABLE
472 PRESSED
473 SELECTABLE
474 SELECTED
475 SINGLE_LINE
476 TRANSIENT
482 // accessibility::XAccessibleContext
483 sal_Int32 VCLXAccessibleComponent::getAccessibleChildCount() throw (uno::RuntimeException)
485 OExternalLockGuard aGuard( this );
487 sal_Int32 nChildren = 0;
488 if ( GetWindow() )
489 nChildren = GetWindow()->GetAccessibleChildWindowCount();
491 return nChildren;
494 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleChild( sal_Int32 i ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
496 OExternalLockGuard aGuard( this );
498 if ( i >= getAccessibleChildCount() )
499 throw lang::IndexOutOfBoundsException();
501 uno::Reference< accessibility::XAccessible > xAcc;
502 if ( GetWindow() )
504 Window* pChild = GetWindow()->GetAccessibleChildWindow( (sal_uInt16)i );
505 if ( pChild )
506 xAcc = pChild->GetAccessible();
509 return xAcc;
512 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getVclParent() const
514 uno::Reference< accessibility::XAccessible > xAcc;
515 if ( GetWindow() )
517 Window* pParent = GetWindow()->GetAccessibleParentWindow();
518 if ( pParent )
519 xAcc = pParent->GetAccessible();
521 return xAcc;
524 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleParent( ) throw (uno::RuntimeException)
526 OExternalLockGuard aGuard( this );
528 uno::Reference< accessibility::XAccessible > xAcc( implGetForeignControlledParent() );
529 if ( !xAcc.is() )
530 // we do _not_ have a foreign-controlled parent -> default to our VCL parent
531 xAcc = getVclParent();
533 return xAcc;
536 sal_Int32 VCLXAccessibleComponent::getAccessibleIndexInParent( ) throw (uno::RuntimeException)
538 OExternalLockGuard aGuard( this );
540 sal_Int32 nIndex = -1;
542 uno::Reference< accessibility::XAccessible > xAcc( implGetForeignControlledParent() );
543 if ( xAcc.is() )
544 { // we _do_ have a foreign-controlled parent -> use the base class' implementation,
545 // which goes the UNO way
546 nIndex = AccessibleExtendedComponentHelper_BASE::getAccessibleIndexInParent( );
548 else
550 if ( GetWindow() )
552 Window* pParent = GetWindow()->GetAccessibleParentWindow();
553 if ( pParent )
555 // Iterate over all the parent's children and search for this object.
556 // this should be compatible with the code in SVX
557 uno::Reference< accessibility::XAccessible > xParentAcc( pParent->GetAccessible() );
558 if ( xParentAcc.is() )
560 uno::Reference< accessibility::XAccessibleContext > xParentContext ( xParentAcc->getAccessibleContext() );
561 if ( xParentContext.is() )
563 sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
564 for ( sal_Int32 i=0; i<nChildCount; i++ )
566 uno::Reference< accessibility::XAccessible > xChild( xParentContext->getAccessibleChild(i) );
567 if ( xChild.is() )
569 uno::Reference< accessibility::XAccessibleContext > xChildContext = xChild->getAccessibleContext();
570 if ( xChildContext == (accessibility::XAccessibleContext*) this )
572 nIndex = i;
573 break;
582 return nIndex;
585 sal_Int16 VCLXAccessibleComponent::getAccessibleRole( ) throw (uno::RuntimeException)
587 OExternalLockGuard aGuard( this );
589 sal_Int16 nRole = 0;
591 if ( GetWindow() )
592 nRole = GetWindow()->GetAccessibleRole();
594 return nRole;
597 OUString VCLXAccessibleComponent::getAccessibleDescription( ) throw (uno::RuntimeException)
599 OExternalLockGuard aGuard( this );
601 OUString aDescription;
603 if ( GetWindow() )
604 aDescription = GetWindow()->GetAccessibleDescription();
606 return aDescription;
609 OUString VCLXAccessibleComponent::getAccessibleName( ) throw (uno::RuntimeException)
611 OExternalLockGuard aGuard( this );
613 OUString aName;
614 if ( GetWindow() )
616 aName = GetWindow()->GetAccessibleName();
617 #if OSL_DEBUG_LEVEL > 1
618 aName += OUString(" (Type = ");
619 aName += OUString::valueOf(static_cast<sal_Int32>(GetWindow()->GetType()));
620 aName += OUString( ")");
621 #endif
623 return aName;
626 uno::Reference< accessibility::XAccessibleRelationSet > VCLXAccessibleComponent::getAccessibleRelationSet( ) throw (uno::RuntimeException)
628 OExternalLockGuard aGuard( this );
630 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
631 uno::Reference< accessibility::XAccessibleRelationSet > xSet = pRelationSetHelper;
632 FillAccessibleRelationSet( *pRelationSetHelper );
633 return xSet;
636 uno::Reference< accessibility::XAccessibleStateSet > VCLXAccessibleComponent::getAccessibleStateSet( ) throw (uno::RuntimeException)
638 OExternalLockGuard aGuard( this );
640 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
641 uno::Reference< accessibility::XAccessibleStateSet > xSet = pStateSetHelper;
642 FillAccessibleStateSet( *pStateSetHelper );
643 return xSet;
646 lang::Locale VCLXAccessibleComponent::getLocale() throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException)
648 OExternalLockGuard aGuard( this );
650 return Application::GetSettings().GetLanguageTag().getLocale();
653 uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleAtPoint( const awt::Point& rPoint ) throw (uno::RuntimeException)
655 OExternalLockGuard aGuard( this );
657 uno::Reference< accessibility::XAccessible > xChild;
658 for ( sal_uInt32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
660 uno::Reference< accessibility::XAccessible > xAcc = getAccessibleChild( i );
661 if ( xAcc.is() )
663 uno::Reference< accessibility::XAccessibleComponent > xComp( xAcc->getAccessibleContext(), uno::UNO_QUERY );
664 if ( xComp.is() )
666 Rectangle aRect = VCLRectangle( xComp->getBounds() );
667 Point aPos = VCLPoint( rPoint );
668 if ( aRect.IsInside( aPos ) )
670 xChild = xAcc;
671 break;
677 return xChild;
680 // accessibility::XAccessibleComponent
681 awt::Rectangle VCLXAccessibleComponent::implGetBounds() throw (uno::RuntimeException)
683 awt::Rectangle aBounds ( 0, 0, 0, 0 );
685 Window* pWindow = GetWindow();
686 if ( pWindow )
688 Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
689 aBounds = AWTRectangle( aRect );
690 Window* pParent = pWindow->GetAccessibleParentWindow();
691 if ( pParent )
693 Rectangle aParentRect = pParent->GetWindowExtentsRelative( NULL );
694 awt::Point aParentScreenLoc = AWTPoint( aParentRect.TopLeft() );
695 aBounds.X -= aParentScreenLoc.X;
696 aBounds.Y -= aParentScreenLoc.Y;
700 uno::Reference< accessibility::XAccessible > xParent( implGetForeignControlledParent() );
701 if ( xParent.is() )
702 { // hmm, we can't rely on our VCL coordinates, as in the Accessibility Hierarchy, somebody gave
703 // us a parent which is different from our VCL parent
704 // (actually, we did not check if it's really different ...)
706 // the screen location of the foreign parent
707 uno::Reference< accessibility::XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), uno::UNO_QUERY );
708 DBG_ASSERT( xParentComponent.is(), "VCLXAccessibleComponent::implGetBounds: invalid (foreign) parent component!" );
710 awt::Point aScreenLocForeign( 0, 0 );
711 if ( xParentComponent.is() )
712 aScreenLocForeign = xParentComponent->getLocationOnScreen();
714 // the screen location of the VCL parent
715 xParent = getVclParent();
716 if ( xParent.is() )
717 xParentComponent = xParentComponent.query( xParent->getAccessibleContext() );
719 awt::Point aScreenLocVCL( 0, 0 );
720 if ( xParentComponent.is() )
721 aScreenLocVCL = xParentComponent->getLocationOnScreen();
723 // the difference between them
724 awt::Size aOffset( aScreenLocVCL.X - aScreenLocForeign.X, aScreenLocVCL.Y - aScreenLocForeign.Y );
725 // move the bounds
726 aBounds.X += aOffset.Width;
727 aBounds.Y += aOffset.Height;
730 return aBounds;
733 awt::Point VCLXAccessibleComponent::getLocationOnScreen( ) throw (uno::RuntimeException)
735 OExternalLockGuard aGuard( this );
737 awt::Point aPos;
738 if ( GetWindow() )
740 Rectangle aRect = GetWindow()->GetWindowExtentsRelative( NULL );
741 aPos.X = aRect.Left();
742 aPos.Y = aRect.Top();
745 return aPos;
748 void VCLXAccessibleComponent::grabFocus( ) throw (uno::RuntimeException)
750 OExternalLockGuard aGuard( this );
752 uno::Reference< accessibility::XAccessibleStateSet > xStates = getAccessibleStateSet();
753 if ( mxWindow.is() && xStates.is() && xStates->contains( accessibility::AccessibleStateType::FOCUSABLE ) )
754 mxWindow->setFocus();
757 sal_Int32 SAL_CALL VCLXAccessibleComponent::getForeground( ) throw (uno::RuntimeException)
759 OExternalLockGuard aGuard( this );
761 sal_Int32 nColor = 0;
762 Window* pWindow = GetWindow();
763 if ( pWindow )
765 if ( pWindow->IsControlForeground() )
766 nColor = pWindow->GetControlForeground().GetColor();
767 else
769 Font aFont;
770 if ( pWindow->IsControlFont() )
771 aFont = pWindow->GetControlFont();
772 else
773 aFont = pWindow->GetFont();
774 nColor = aFont.GetColor().GetColor();
778 return nColor;
781 sal_Int32 SAL_CALL VCLXAccessibleComponent::getBackground( ) throw (uno::RuntimeException)
783 OExternalLockGuard aGuard( this );
785 sal_Int32 nColor = 0;
786 Window* pWindow = GetWindow();
787 if ( pWindow )
789 if ( pWindow->IsControlBackground() )
790 nColor = pWindow->GetControlBackground().GetColor();
791 else
792 nColor = pWindow->GetBackground().GetColor().GetColor();
795 return nColor;
798 // XAccessibleExtendedComponent
800 uno::Reference< awt::XFont > SAL_CALL VCLXAccessibleComponent::getFont( ) throw (uno::RuntimeException)
802 OExternalLockGuard aGuard( this );
804 uno::Reference< awt::XFont > xFont;
805 Window* pWindow = GetWindow();
806 if ( pWindow )
808 uno::Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), uno::UNO_QUERY );
809 if ( xDev.is() )
811 Font aFont;
812 if ( pWindow->IsControlFont() )
813 aFont = pWindow->GetControlFont();
814 else
815 aFont = pWindow->GetFont();
816 VCLXFont* pVCLXFont = new VCLXFont;
817 pVCLXFont->Init( *xDev.get(), aFont );
818 xFont = pVCLXFont;
822 return xFont;
825 OUString SAL_CALL VCLXAccessibleComponent::getTitledBorderText( ) throw (uno::RuntimeException)
827 OExternalLockGuard aGuard( this );
829 OUString sRet;
830 if ( GetWindow() )
831 sRet = GetWindow()->GetText();
833 return sRet;
836 OUString SAL_CALL VCLXAccessibleComponent::getToolTipText( ) throw (uno::RuntimeException)
838 OExternalLockGuard aGuard( this );
840 OUString sRet;
841 if ( GetWindow() )
842 sRet = GetWindow()->GetQuickHelpText();
844 return sRet;
847 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */