1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "accessibility/extended/AccessibleBrowseBoxBase.hxx"
21 #include <svtools/accessibletableprovider.hxx>
22 #include <comphelper/servicehelper.hxx>
23 #include <cppuhelper/supportsservice.hxx>
25 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <unotools/accessiblerelationsethelper.hxx>
29 // ============================================================================
31 using ::com::sun::star::uno::Reference
;
32 using ::com::sun::star::uno::Sequence
;
33 using ::com::sun::star::uno::Any
;
35 using namespace ::com::sun::star
;
36 using namespace ::com::sun::star::accessibility
;
37 using namespace ::comphelper
;
38 using namespace ::svt
;
41 // ============================================================================
43 namespace accessibility
{
45 using namespace com::sun::star::accessibility::AccessibleStateType
;
46 // ============================================================================
48 // Ctor/Dtor/disposing --------------------------------------------------------
50 AccessibleBrowseBoxBase::AccessibleBrowseBoxBase(
51 const Reference
< XAccessible
>& rxParent
,
52 IAccessibleTableProvider
& rBrowseBox
,
53 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& _xFocusWindow
,
54 AccessibleBrowseBoxObjType eObjType
) :
55 AccessibleBrowseBoxImplHelper( m_aMutex
),
57 mpBrowseBox( &rBrowseBox
),
58 m_xFocusWindow(_xFocusWindow
),
59 maName( rBrowseBox
.GetAccessibleObjectName( eObjType
) ),
60 maDescription( rBrowseBox
.GetAccessibleObjectDescription( eObjType
) ),
61 meObjType( eObjType
),
64 if ( m_xFocusWindow
.is() )
65 m_xFocusWindow
->addFocusListener( this );
68 AccessibleBrowseBoxBase::AccessibleBrowseBoxBase(
69 const Reference
< XAccessible
>& rxParent
,
70 IAccessibleTableProvider
& rBrowseBox
,
71 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& _xFocusWindow
,
72 AccessibleBrowseBoxObjType eObjType
,
73 const OUString
& rName
,
74 const OUString
& rDescription
) :
75 AccessibleBrowseBoxImplHelper( m_aMutex
),
77 mpBrowseBox( &rBrowseBox
),
78 m_xFocusWindow(_xFocusWindow
),
80 maDescription( rDescription
),
81 meObjType( eObjType
),
84 if ( m_xFocusWindow
.is() )
85 m_xFocusWindow
->addFocusListener( this );
88 AccessibleBrowseBoxBase::~AccessibleBrowseBoxBase()
92 // increment ref count to prevent double call of Dtor
93 osl_atomic_increment( &m_refCount
);
98 void SAL_CALL
AccessibleBrowseBoxBase::disposing()
100 ::osl::MutexGuard
aGuard( getOslMutex() );
101 if ( m_xFocusWindow
.is() )
103 SolarMutexGuard aSolarGuard
;
104 m_xFocusWindow
->removeFocusListener( this );
107 if ( getClientId( ) )
109 AccessibleEventNotifier::TClientId
nId( getClientId( ) );
111 AccessibleEventNotifier::revokeClientNotifyDisposing( nId
, *this );
118 // XAccessibleContext ---------------------------------------------------------
120 Reference
< XAccessible
> SAL_CALL
AccessibleBrowseBoxBase::getAccessibleParent()
121 throw ( uno::RuntimeException
)
123 ::osl::MutexGuard
aGuard( getOslMutex() );
128 sal_Int32 SAL_CALL
AccessibleBrowseBoxBase::getAccessibleIndexInParent()
129 throw ( uno::RuntimeException
)
131 ::osl::MutexGuard
aGuard( getOslMutex() );
134 // -1 for child not found/no parent (according to specification)
137 Reference
< uno::XInterface
> xMeMyselfAndI( static_cast< XAccessibleContext
* >( this ), uno::UNO_QUERY
);
139 // iterate over parent's children and search for this object
142 Reference
< XAccessibleContext
>
143 xParentContext( mxParent
->getAccessibleContext() );
144 if( xParentContext
.is() )
146 Reference
< uno::XInterface
> xChild
;
148 sal_Int32 nChildCount
= xParentContext
->getAccessibleChildCount();
149 for( sal_Int32 nChild
= 0; nChild
< nChildCount
; ++nChild
)
151 xChild
= xChild
.query( xParentContext
->getAccessibleChild( nChild
) );
153 if ( xMeMyselfAndI
.get() == xChild
.get() )
164 OUString SAL_CALL
AccessibleBrowseBoxBase::getAccessibleDescription()
165 throw ( uno::RuntimeException
)
167 ::osl::MutexGuard
aGuard( getOslMutex() );
169 return maDescription
;
172 OUString SAL_CALL
AccessibleBrowseBoxBase::getAccessibleName()
173 throw ( uno::RuntimeException
)
175 ::osl::MutexGuard
aGuard( getOslMutex() );
180 Reference
< XAccessibleRelationSet
> SAL_CALL
181 AccessibleBrowseBoxBase::getAccessibleRelationSet()
182 throw ( uno::RuntimeException
)
185 // BrowseBox does not have relations.
186 return new utl::AccessibleRelationSetHelper
;
189 Reference
< XAccessibleStateSet
> SAL_CALL
190 AccessibleBrowseBoxBase::getAccessibleStateSet()
191 throw ( uno::RuntimeException
)
193 SolarMutexGuard aSolarGuard
;
194 ::osl::MutexGuard
aGuard( getOslMutex() );
195 // don't check whether alive -> StateSet may contain DEFUNC
196 return implCreateStateSetHelper();
199 lang::Locale SAL_CALL
AccessibleBrowseBoxBase::getLocale()
200 throw ( IllegalAccessibleComponentStateException
, uno::RuntimeException
)
202 ::osl::MutexGuard
aGuard( getOslMutex() );
206 Reference
< XAccessibleContext
>
207 xParentContext( mxParent
->getAccessibleContext() );
208 if( xParentContext
.is() )
209 return xParentContext
->getLocale();
211 throw IllegalAccessibleComponentStateException();
214 // XAccessibleComponent -------------------------------------------------------
216 sal_Bool SAL_CALL
AccessibleBrowseBoxBase::containsPoint( const awt::Point
& rPoint
)
217 throw ( uno::RuntimeException
)
219 return Rectangle( Point(), getBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint
) );
222 awt::Rectangle SAL_CALL
AccessibleBrowseBoxBase::getBounds()
223 throw ( uno::RuntimeException
)
225 return AWTRectangle( getBoundingBox() );
228 awt::Point SAL_CALL
AccessibleBrowseBoxBase::getLocation()
229 throw ( uno::RuntimeException
)
231 return AWTPoint( getBoundingBox().TopLeft() );
234 awt::Point SAL_CALL
AccessibleBrowseBoxBase::getLocationOnScreen()
235 throw ( uno::RuntimeException
)
237 return AWTPoint( getBoundingBoxOnScreen().TopLeft() );
240 awt::Size SAL_CALL
AccessibleBrowseBoxBase::getSize()
241 throw ( uno::RuntimeException
)
243 return AWTSize( getBoundingBox().GetSize() );
246 sal_Bool SAL_CALL
AccessibleBrowseBoxBase::isShowing()
247 throw ( uno::RuntimeException
)
249 SolarMutexGuard aSolarGuard
;
250 ::osl::MutexGuard
aGuard( getOslMutex() );
252 return implIsShowing();
255 sal_Bool SAL_CALL
AccessibleBrowseBoxBase::isVisible()
256 throw ( uno::RuntimeException
)
258 Reference
< XAccessibleStateSet
> xStateSet
= getAccessibleStateSet();
259 return xStateSet
.is() ?
260 xStateSet
->contains( AccessibleStateType::VISIBLE
) : sal_False
;
263 sal_Bool SAL_CALL
AccessibleBrowseBoxBase::isFocusTraversable()
264 throw ( uno::RuntimeException
)
266 Reference
< XAccessibleStateSet
> xStateSet
= getAccessibleStateSet();
267 return xStateSet
.is() ?
268 xStateSet
->contains( AccessibleStateType::FOCUSABLE
) : sal_False
;
271 void SAL_CALL
AccessibleBrowseBoxBase::focusGained( const ::com::sun::star::awt::FocusEvent
& ) throw (::com::sun::star::uno::RuntimeException
)
273 com::sun::star::uno::Any aFocused
;
274 com::sun::star::uno::Any aEmpty
;
275 aFocused
<<= FOCUSED
;
277 commitEvent(AccessibleEventId::STATE_CHANGED
,aFocused
,aEmpty
);
279 // -----------------------------------------------------------------------------
281 void SAL_CALL
AccessibleBrowseBoxBase::focusLost( const ::com::sun::star::awt::FocusEvent
& ) throw (::com::sun::star::uno::RuntimeException
)
283 com::sun::star::uno::Any aFocused
;
284 com::sun::star::uno::Any aEmpty
;
285 aFocused
<<= FOCUSED
;
287 commitEvent(AccessibleEventId::STATE_CHANGED
,aEmpty
,aFocused
);
289 // XAccessibleEventBroadcaster ------------------------------------------------
291 void SAL_CALL
AccessibleBrowseBoxBase::addAccessibleEventListener(
292 const Reference
< XAccessibleEventListener
>& _rxListener
)
293 throw ( uno::RuntimeException
)
295 if ( _rxListener
.is() )
297 ::osl::MutexGuard
aGuard( getOslMutex() );
298 if ( !getClientId( ) )
299 setClientId( AccessibleEventNotifier::registerClient( ) );
301 AccessibleEventNotifier::addEventListener( getClientId( ), _rxListener
);
305 void SAL_CALL
AccessibleBrowseBoxBase::removeAccessibleEventListener(
306 const Reference
< XAccessibleEventListener
>& _rxListener
)
307 throw ( uno::RuntimeException
)
309 if( _rxListener
.is() && getClientId( ) )
311 ::osl::MutexGuard
aGuard( getOslMutex() );
312 sal_Int32 nListenerCount
= AccessibleEventNotifier::removeEventListener( getClientId( ), _rxListener
);
313 if ( !nListenerCount
)
315 // no listeners anymore
316 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
317 // and at least to us not firing any events anymore, in case somebody calls
318 // NotifyAccessibleEvent, again
320 AccessibleEventNotifier::TClientId
nId( getClientId( ) );
322 AccessibleEventNotifier::revokeClient( nId
);
327 // XTypeProvider --------------------------------------------------------------
331 class theAccessibleBrowseBoxBaseImplementationId
: public rtl::Static
< UnoTunnelIdInit
, theAccessibleBrowseBoxBaseImplementationId
> {};
334 Sequence
< sal_Int8
> SAL_CALL
AccessibleBrowseBoxBase::getImplementationId()
335 throw ( uno::RuntimeException
)
337 return theAccessibleBrowseBoxBaseImplementationId::get().getSeq();
340 // XServiceInfo ---------------------------------------------------------------
342 sal_Bool SAL_CALL
AccessibleBrowseBoxBase::supportsService(
343 const OUString
& rServiceName
)
344 throw ( uno::RuntimeException
)
346 return cppu::supportsService(this, rServiceName
);
349 Sequence
< OUString
> SAL_CALL
AccessibleBrowseBoxBase::getSupportedServiceNames()
350 throw ( uno::RuntimeException
)
352 const OUString
aServiceName( "com.sun.star.accessibility.AccessibleContext" );
353 return Sequence
< OUString
>( &aServiceName
, 1 );
356 // other public methods -------------------------------------------------------
358 void AccessibleBrowseBoxBase::setAccessibleName( const OUString
& rName
)
360 ::osl::ClearableMutexGuard
aGuard( getOslMutex() );
368 AccessibleEventId::NAME_CHANGED
,
369 uno::makeAny( maName
),
373 void AccessibleBrowseBoxBase::setAccessibleDescription( const OUString
& rDescription
)
375 ::osl::ClearableMutexGuard
aGuard( getOslMutex() );
377 aOld
<<= maDescription
;
378 maDescription
= rDescription
;
383 AccessibleEventId::DESCRIPTION_CHANGED
,
384 uno::makeAny( maDescription
),
388 // internal virtual methods ---------------------------------------------------
390 sal_Bool
AccessibleBrowseBoxBase::implIsShowing()
392 sal_Bool bShowing
= sal_False
;
395 Reference
< XAccessibleComponent
>
396 xParentComp( mxParent
->getAccessibleContext(), uno::UNO_QUERY
);
397 if( xParentComp
.is() )
398 bShowing
= implGetBoundingBox().IsOver(
399 VCLRectangle( xParentComp
->getBounds() ) );
404 ::utl::AccessibleStateSetHelper
* AccessibleBrowseBoxBase::implCreateStateSetHelper()
406 ::utl::AccessibleStateSetHelper
*
407 pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
411 // SHOWING done with mxParent
412 if( implIsShowing() )
413 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
414 // BrowseBox fills StateSet with states depending on object type
415 mpBrowseBox
->FillAccessibleStateSet( *pStateSetHelper
, getType() );
418 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
420 return pStateSetHelper
;
423 // internal helper methods ----------------------------------------------------
425 sal_Bool
AccessibleBrowseBoxBase::isAlive() const
427 return !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
&& mpBrowseBox
;
430 void AccessibleBrowseBoxBase::ensureIsAlive() const
431 throw ( lang::DisposedException
)
434 throw lang::DisposedException();
437 Rectangle
AccessibleBrowseBoxBase::getBoundingBox()
438 throw ( lang::DisposedException
)
440 SolarMutexGuard aSolarGuard
;
441 ::osl::MutexGuard
aGuard( getOslMutex() );
443 Rectangle aRect
= implGetBoundingBox();
444 if ( 0 == aRect
.Left() && 0 == aRect
.Top() && 0 == aRect
.Right() && 0 == aRect
.Bottom() )
446 SAL_WARN( "accessibility", "rectangle doesn't exist" );
451 Rectangle
AccessibleBrowseBoxBase::getBoundingBoxOnScreen()
452 throw ( lang::DisposedException
)
454 SolarMutexGuard aSolarGuard
;
455 ::osl::MutexGuard
aGuard( getOslMutex() );
457 Rectangle aRect
= implGetBoundingBoxOnScreen();
458 if ( 0 == aRect
.Left() && 0 == aRect
.Top() && 0 == aRect
.Right() && 0 == aRect
.Bottom() )
460 SAL_WARN( "accessibility", "rectangle doesn't exist" );
465 void AccessibleBrowseBoxBase::commitEvent(
466 sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
468 ::osl::ClearableMutexGuard
aGuard( getOslMutex() );
469 if ( !getClientId( ) )
470 // if we don't have a client id for the notifier, then we don't have listeners, then
471 // we don't need to notify anything
474 // build an event object
475 AccessibleEventObject aEvent
;
476 aEvent
.Source
= *this;
477 aEvent
.EventId
= _nEventId
;
478 aEvent
.OldValue
= _rOldValue
;
479 aEvent
.NewValue
= _rNewValue
;
481 // let the notifier handle this event
483 AccessibleEventNotifier::addEvent( getClientId( ), aEvent
);
486 sal_Int16 SAL_CALL
AccessibleBrowseBoxBase::getAccessibleRole()
487 throw ( uno::RuntimeException
)
490 sal_Int16 nRole
= AccessibleRole::UNKNOWN
;
493 case BBTYPE_ROWHEADERCELL
:
494 nRole
= AccessibleRole::ROW_HEADER
;
496 case BBTYPE_COLUMNHEADERCELL
:
497 nRole
= AccessibleRole::COLUMN_HEADER
;
499 case BBTYPE_COLUMNHEADERBAR
:
500 case BBTYPE_ROWHEADERBAR
:
502 nRole
= AccessibleRole::TABLE
;
504 case BBTYPE_TABLECELL
:
505 nRole
= AccessibleRole::TABLE_CELL
;
507 case BBTYPE_BROWSEBOX
:
508 nRole
= AccessibleRole::PANEL
;
510 case BBTYPE_CHECKBOXCELL
:
511 nRole
= AccessibleRole::CHECK_BOX
;
516 // -----------------------------------------------------------------------------
517 Any SAL_CALL
AccessibleBrowseBoxBase::getAccessibleKeyBinding()
518 throw ( uno::RuntimeException
)
522 // -----------------------------------------------------------------------------
523 Reference
<XAccessible
> SAL_CALL
AccessibleBrowseBoxBase::getAccessibleAtPoint( const ::com::sun::star::awt::Point
& )
524 throw ( uno::RuntimeException
)
528 // -----------------------------------------------------------------------------
529 void SAL_CALL
AccessibleBrowseBoxBase::disposing( const ::com::sun::star::lang::EventObject
& ) throw (::com::sun::star::uno::RuntimeException
)
531 m_xFocusWindow
= NULL
;
533 // -----------------------------------------------------------------------------
534 sal_Int32 SAL_CALL
AccessibleBrowseBoxBase::getForeground( ) throw (::com::sun::star::uno::RuntimeException
)
536 SolarMutexGuard aSolarGuard
;
537 ::osl::MutexGuard
aGuard( getOslMutex() );
540 sal_Int32 nColor
= 0;
541 Window
* pInst
= mpBrowseBox
->GetWindowInstance();
544 if ( pInst
->IsControlForeground() )
545 nColor
= pInst
->GetControlForeground().GetColor();
549 if ( pInst
->IsControlFont() )
550 aFont
= pInst
->GetControlFont();
552 aFont
= pInst
->GetFont();
553 nColor
= aFont
.GetColor().GetColor();
559 // -----------------------------------------------------------------------------
560 sal_Int32 SAL_CALL
AccessibleBrowseBoxBase::getBackground( ) throw (::com::sun::star::uno::RuntimeException
)
562 SolarMutexGuard aSolarGuard
;
563 ::osl::MutexGuard
aGuard( getOslMutex() );
565 sal_Int32 nColor
= 0;
566 Window
* pInst
= mpBrowseBox
->GetWindowInstance();
569 if ( pInst
->IsControlBackground() )
570 nColor
= pInst
->GetControlBackground().GetColor();
572 nColor
= pInst
->GetBackground().GetColor().GetColor();
578 // ============================================================================
579 // XInterface -----------------------------------------------------------------
580 IMPLEMENT_FORWARD_XINTERFACE2( BrowseBoxAccessibleElement
, AccessibleBrowseBoxBase
, BrowseBoxAccessibleElement_Base
)
582 // XTypeProvider --------------------------------------------------------------
583 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BrowseBoxAccessibleElement
, AccessibleBrowseBoxBase
, BrowseBoxAccessibleElement_Base
)
585 // XAccessible ----------------------------------------------------------------
587 Reference
< XAccessibleContext
> SAL_CALL
BrowseBoxAccessibleElement::getAccessibleContext() throw ( uno::RuntimeException
)
593 // ----------------------------------------------------------------------------
594 BrowseBoxAccessibleElement::BrowseBoxAccessibleElement( const Reference
< XAccessible
>& rxParent
, IAccessibleTableProvider
& rBrowseBox
,
595 const Reference
< awt::XWindow
>& _xFocusWindow
, AccessibleBrowseBoxObjType eObjType
)
596 :AccessibleBrowseBoxBase( rxParent
, rBrowseBox
, _xFocusWindow
, eObjType
)
600 // ----------------------------------------------------------------------------
601 BrowseBoxAccessibleElement::BrowseBoxAccessibleElement( const Reference
< XAccessible
>& rxParent
, IAccessibleTableProvider
& rBrowseBox
,
602 const Reference
< awt::XWindow
>& _xFocusWindow
, AccessibleBrowseBoxObjType eObjType
,
603 const OUString
& rName
, const OUString
& rDescription
)
604 :AccessibleBrowseBoxBase( rxParent
, rBrowseBox
, _xFocusWindow
, eObjType
, rName
, rDescription
)
608 // ----------------------------------------------------------------------------
609 BrowseBoxAccessibleElement::~BrowseBoxAccessibleElement( )
613 // ============================================================================
615 } // namespace accessibility
617 // ============================================================================
619 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */