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>
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
;
43 namespace accessibility
{
45 using namespace com::sun::star::accessibility::AccessibleStateType
;
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
, std::exception
)
123 ::osl::MutexGuard
aGuard( getOslMutex() );
128 sal_Int32 SAL_CALL
AccessibleBrowseBoxBase::getAccessibleIndexInParent()
129 throw ( uno::RuntimeException
, std::exception
)
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
.set(xParentContext
->getAccessibleChild( nChild
), css::uno::UNO_QUERY
);
153 if ( xMeMyselfAndI
.get() == xChild
.get() )
164 OUString SAL_CALL
AccessibleBrowseBoxBase::getAccessibleDescription()
165 throw ( uno::RuntimeException
, std::exception
)
167 ::osl::MutexGuard
aGuard( getOslMutex() );
169 return maDescription
;
172 OUString SAL_CALL
AccessibleBrowseBoxBase::getAccessibleName()
173 throw ( uno::RuntimeException
, std::exception
)
175 ::osl::MutexGuard
aGuard( getOslMutex() );
180 Reference
< XAccessibleRelationSet
> SAL_CALL
181 AccessibleBrowseBoxBase::getAccessibleRelationSet()
182 throw ( uno::RuntimeException
, std::exception
)
185 // BrowseBox does not have relations.
186 return new utl::AccessibleRelationSetHelper
;
189 Reference
< XAccessibleStateSet
> SAL_CALL
190 AccessibleBrowseBoxBase::getAccessibleStateSet()
191 throw ( uno::RuntimeException
, std::exception
)
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
, std::exception
)
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
, std::exception
)
219 return Rectangle( Point(), getBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint
) );
222 awt::Rectangle SAL_CALL
AccessibleBrowseBoxBase::getBounds()
223 throw ( uno::RuntimeException
, std::exception
)
225 return AWTRectangle( getBoundingBox() );
228 awt::Point SAL_CALL
AccessibleBrowseBoxBase::getLocation()
229 throw ( uno::RuntimeException
, std::exception
)
231 return AWTPoint( getBoundingBox().TopLeft() );
234 awt::Point SAL_CALL
AccessibleBrowseBoxBase::getLocationOnScreen()
235 throw ( uno::RuntimeException
, std::exception
)
237 return AWTPoint( getBoundingBoxOnScreen().TopLeft() );
240 awt::Size SAL_CALL
AccessibleBrowseBoxBase::getSize()
241 throw ( uno::RuntimeException
, std::exception
)
243 return AWTSize( getBoundingBox().GetSize() );
246 void SAL_CALL
AccessibleBrowseBoxBase::focusGained( const ::com::sun::star::awt::FocusEvent
& ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
248 com::sun::star::uno::Any aFocused
;
249 com::sun::star::uno::Any aEmpty
;
250 aFocused
<<= FOCUSED
;
252 commitEvent(AccessibleEventId::STATE_CHANGED
,aFocused
,aEmpty
);
256 void SAL_CALL
AccessibleBrowseBoxBase::focusLost( const ::com::sun::star::awt::FocusEvent
& ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
258 com::sun::star::uno::Any aFocused
;
259 com::sun::star::uno::Any aEmpty
;
260 aFocused
<<= FOCUSED
;
262 commitEvent(AccessibleEventId::STATE_CHANGED
,aEmpty
,aFocused
);
264 // XAccessibleEventBroadcaster ------------------------------------------------
266 void SAL_CALL
AccessibleBrowseBoxBase::addAccessibleEventListener(
267 const Reference
< XAccessibleEventListener
>& _rxListener
)
268 throw ( uno::RuntimeException
, std::exception
)
270 if ( _rxListener
.is() )
272 ::osl::MutexGuard
aGuard( getOslMutex() );
273 if ( !getClientId( ) )
274 setClientId( AccessibleEventNotifier::registerClient( ) );
276 AccessibleEventNotifier::addEventListener( getClientId( ), _rxListener
);
280 void SAL_CALL
AccessibleBrowseBoxBase::removeAccessibleEventListener(
281 const Reference
< XAccessibleEventListener
>& _rxListener
)
282 throw ( uno::RuntimeException
, std::exception
)
284 if( _rxListener
.is() && getClientId( ) )
286 ::osl::MutexGuard
aGuard( getOslMutex() );
287 sal_Int32 nListenerCount
= AccessibleEventNotifier::removeEventListener( getClientId( ), _rxListener
);
288 if ( !nListenerCount
)
290 // no listeners anymore
291 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
292 // and at least to us not firing any events anymore, in case somebody calls
293 // NotifyAccessibleEvent, again
295 AccessibleEventNotifier::TClientId
nId( getClientId( ) );
297 AccessibleEventNotifier::revokeClient( nId
);
302 // XTypeProvider --------------------------------------------------------------
304 Sequence
< sal_Int8
> SAL_CALL
AccessibleBrowseBoxBase::getImplementationId()
305 throw ( uno::RuntimeException
, std::exception
)
307 return css::uno::Sequence
<sal_Int8
>();
310 // XServiceInfo ---------------------------------------------------------------
312 sal_Bool SAL_CALL
AccessibleBrowseBoxBase::supportsService(
313 const OUString
& rServiceName
)
314 throw ( uno::RuntimeException
, std::exception
)
316 return cppu::supportsService(this, rServiceName
);
319 Sequence
< OUString
> SAL_CALL
AccessibleBrowseBoxBase::getSupportedServiceNames()
320 throw ( uno::RuntimeException
, std::exception
)
322 const OUString
aServiceName( "com.sun.star.accessibility.AccessibleContext" );
323 return Sequence
< OUString
>( &aServiceName
, 1 );
326 // other public methods -------------------------------------------------------
328 void AccessibleBrowseBoxBase::setAccessibleName( const OUString
& rName
)
330 ::osl::ClearableMutexGuard
aGuard( getOslMutex() );
338 AccessibleEventId::NAME_CHANGED
,
339 uno::makeAny( maName
),
343 void AccessibleBrowseBoxBase::setAccessibleDescription( const OUString
& rDescription
)
345 ::osl::ClearableMutexGuard
aGuard( getOslMutex() );
347 aOld
<<= maDescription
;
348 maDescription
= rDescription
;
353 AccessibleEventId::DESCRIPTION_CHANGED
,
354 uno::makeAny( maDescription
),
358 // internal virtual methods ---------------------------------------------------
360 bool AccessibleBrowseBoxBase::implIsShowing()
362 bool bShowing
= false;
365 Reference
< XAccessibleComponent
>
366 xParentComp( mxParent
->getAccessibleContext(), uno::UNO_QUERY
);
367 if( xParentComp
.is() )
368 bShowing
= implGetBoundingBox().IsOver(
369 VCLRectangle( xParentComp
->getBounds() ) );
374 ::utl::AccessibleStateSetHelper
* AccessibleBrowseBoxBase::implCreateStateSetHelper()
376 ::utl::AccessibleStateSetHelper
*
377 pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
381 // SHOWING done with mxParent
382 if( implIsShowing() )
383 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
384 // BrowseBox fills StateSet with states depending on object type
385 mpBrowseBox
->FillAccessibleStateSet( *pStateSetHelper
, getType() );
388 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
390 return pStateSetHelper
;
393 // internal helper methods ----------------------------------------------------
395 bool AccessibleBrowseBoxBase::isAlive() const
397 return !rBHelper
.bDisposed
&& !rBHelper
.bInDispose
&& mpBrowseBox
;
400 void AccessibleBrowseBoxBase::ensureIsAlive() const
401 throw ( lang::DisposedException
)
404 throw lang::DisposedException();
407 Rectangle
AccessibleBrowseBoxBase::getBoundingBox()
408 throw ( lang::DisposedException
)
410 SolarMutexGuard aSolarGuard
;
411 ::osl::MutexGuard
aGuard( getOslMutex() );
413 Rectangle aRect
= implGetBoundingBox();
414 if ( 0 == aRect
.Left() && 0 == aRect
.Top() && 0 == aRect
.Right() && 0 == aRect
.Bottom() )
416 SAL_WARN( "accessibility", "rectangle doesn't exist" );
421 Rectangle
AccessibleBrowseBoxBase::getBoundingBoxOnScreen()
422 throw ( lang::DisposedException
)
424 SolarMutexGuard aSolarGuard
;
425 ::osl::MutexGuard
aGuard( getOslMutex() );
427 Rectangle aRect
= implGetBoundingBoxOnScreen();
428 if ( 0 == aRect
.Left() && 0 == aRect
.Top() && 0 == aRect
.Right() && 0 == aRect
.Bottom() )
430 SAL_WARN( "accessibility", "rectangle doesn't exist" );
435 void AccessibleBrowseBoxBase::commitEvent(
436 sal_Int16 _nEventId
, const Any
& _rNewValue
, const Any
& _rOldValue
)
438 ::osl::ClearableMutexGuard
aGuard( getOslMutex() );
439 if ( !getClientId( ) )
440 // if we don't have a client id for the notifier, then we don't have listeners, then
441 // we don't need to notify anything
444 // build an event object
445 AccessibleEventObject aEvent
;
446 aEvent
.Source
= *this;
447 aEvent
.EventId
= _nEventId
;
448 aEvent
.OldValue
= _rOldValue
;
449 aEvent
.NewValue
= _rNewValue
;
451 // let the notifier handle this event
453 AccessibleEventNotifier::addEvent( getClientId( ), aEvent
);
456 sal_Int16 SAL_CALL
AccessibleBrowseBoxBase::getAccessibleRole()
457 throw ( uno::RuntimeException
, std::exception
)
460 sal_Int16 nRole
= AccessibleRole::UNKNOWN
;
463 case BBTYPE_ROWHEADERCELL
:
464 nRole
= AccessibleRole::ROW_HEADER
;
466 case BBTYPE_COLUMNHEADERCELL
:
467 nRole
= AccessibleRole::COLUMN_HEADER
;
469 case BBTYPE_COLUMNHEADERBAR
:
470 case BBTYPE_ROWHEADERBAR
:
472 nRole
= AccessibleRole::TABLE
;
474 case BBTYPE_TABLECELL
:
475 nRole
= AccessibleRole::TABLE_CELL
;
477 case BBTYPE_BROWSEBOX
:
478 nRole
= AccessibleRole::PANEL
;
480 case BBTYPE_CHECKBOXCELL
:
481 nRole
= AccessibleRole::CHECK_BOX
;
487 Reference
<XAccessible
> SAL_CALL
AccessibleBrowseBoxBase::getAccessibleAtPoint( const ::com::sun::star::awt::Point
& )
488 throw ( uno::RuntimeException
, std::exception
)
493 void SAL_CALL
AccessibleBrowseBoxBase::disposing( const ::com::sun::star::lang::EventObject
& ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
495 m_xFocusWindow
= NULL
;
498 sal_Int32 SAL_CALL
AccessibleBrowseBoxBase::getForeground( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
500 SolarMutexGuard aSolarGuard
;
501 ::osl::MutexGuard
aGuard( getOslMutex() );
504 sal_Int32 nColor
= 0;
505 vcl::Window
* pInst
= mpBrowseBox
->GetWindowInstance();
508 if ( pInst
->IsControlForeground() )
509 nColor
= pInst
->GetControlForeground().GetColor();
513 if ( pInst
->IsControlFont() )
514 aFont
= pInst
->GetControlFont();
516 aFont
= pInst
->GetFont();
517 nColor
= aFont
.GetColor().GetColor();
524 sal_Int32 SAL_CALL
AccessibleBrowseBoxBase::getBackground( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
526 SolarMutexGuard aSolarGuard
;
527 ::osl::MutexGuard
aGuard( getOslMutex() );
529 sal_Int32 nColor
= 0;
530 vcl::Window
* pInst
= mpBrowseBox
->GetWindowInstance();
533 if ( pInst
->IsControlBackground() )
534 nColor
= pInst
->GetControlBackground().GetColor();
536 nColor
= pInst
->GetBackground().GetColor().GetColor();
543 // XInterface -----------------------------------------------------------------
544 IMPLEMENT_FORWARD_XINTERFACE2( BrowseBoxAccessibleElement
, AccessibleBrowseBoxBase
, BrowseBoxAccessibleElement_Base
)
546 // XTypeProvider --------------------------------------------------------------
547 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BrowseBoxAccessibleElement
, AccessibleBrowseBoxBase
, BrowseBoxAccessibleElement_Base
)
549 // XAccessible ----------------------------------------------------------------
551 Reference
< XAccessibleContext
> SAL_CALL
BrowseBoxAccessibleElement::getAccessibleContext() throw ( uno::RuntimeException
, std::exception
)
558 BrowseBoxAccessibleElement::BrowseBoxAccessibleElement( const Reference
< XAccessible
>& rxParent
, IAccessibleTableProvider
& rBrowseBox
,
559 const Reference
< awt::XWindow
>& _xFocusWindow
, AccessibleBrowseBoxObjType eObjType
)
560 :AccessibleBrowseBoxBase( rxParent
, rBrowseBox
, _xFocusWindow
, eObjType
)
565 BrowseBoxAccessibleElement::BrowseBoxAccessibleElement( const Reference
< XAccessible
>& rxParent
, IAccessibleTableProvider
& rBrowseBox
,
566 const Reference
< awt::XWindow
>& _xFocusWindow
, AccessibleBrowseBoxObjType eObjType
,
567 const OUString
& rName
, const OUString
& rDescription
)
568 :AccessibleBrowseBoxBase( rxParent
, rBrowseBox
, _xFocusWindow
, eObjType
, rName
, rDescription
)
573 BrowseBoxAccessibleElement::~BrowseBoxAccessibleElement( )
579 } // namespace accessibility
583 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */