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 .
19 #include <com/sun/star/accessibility/AccessibleRole.hpp>
20 #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
21 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
22 #include <comphelper/accessibleeventnotifier.hxx>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <toolkit/helper/convert.hxx>
26 #include <vcl/svapp.hxx>
27 #include <osl/mutex.hxx>
28 #include <tools/gen.hxx>
30 #include <svtools/ruler.hxx>
31 #include "accessibleruler.hxx"
33 using namespace ::cppu
;
34 using namespace ::osl
;
35 using namespace ::com::sun::star
;
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::accessibility
;
40 //===== internal ============================================================
42 SvtRulerAccessible::SvtRulerAccessible(
43 uno::Reference
< XAccessible
> xParent
, Ruler
& rRepr
, OUString aName
) :
45 SvtRulerAccessible_Base( m_aMutex
),
46 msName(std::move( aName
)),
47 mxParent(std::move( xParent
)),
53 SvtRulerAccessible::~SvtRulerAccessible()
58 osl_atomic_increment( &m_refCount
);
59 dispose(); // set mpRepr = NULL & release all children
63 //===== XAccessible =========================================================
65 uno::Reference
< XAccessibleContext
> SAL_CALL
SvtRulerAccessible::getAccessibleContext()
70 //===== XAccessibleComponent ================================================
72 sal_Bool SAL_CALL
SvtRulerAccessible::containsPoint( const awt::Point
& rPoint
)
74 // no guard -> done in getBounds()
75 // return GetBoundingBox().IsInside( VCLPoint( rPoint ) );
76 return tools::Rectangle( Point( 0, 0 ), GetBoundingBox().GetSize() ).Contains( VCLPoint( rPoint
) );
79 uno::Reference
< XAccessible
> SAL_CALL
SvtRulerAccessible::getAccessibleAtPoint( const awt::Point
& )
81 ::osl::MutexGuard
aGuard( m_aMutex
);
83 ThrowExceptionIfNotAlive();
85 uno::Reference
< XAccessible
> xRet
;
91 awt::Rectangle SAL_CALL
SvtRulerAccessible::getBounds()
93 // no guard -> done in GetBoundingBox()
94 return AWTRectangle( GetBoundingBox() );
97 awt::Point SAL_CALL
SvtRulerAccessible::getLocation()
99 // no guard -> done in GetBoundingBox()
100 return AWTPoint( GetBoundingBox().TopLeft() );
103 awt::Point SAL_CALL
SvtRulerAccessible::getLocationOnScreen()
105 // no guard -> done in GetBoundingBoxOnScreen()
106 return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
109 awt::Size SAL_CALL
SvtRulerAccessible::getSize()
111 // no guard -> done in GetBoundingBox()
112 return AWTSize( GetBoundingBox().GetSize() );
115 bool SvtRulerAccessible::isVisible()
117 ::osl::MutexGuard
aGuard( m_aMutex
);
119 ThrowExceptionIfNotAlive();
121 return mpRepr
->IsVisible();
124 //===== XAccessibleContext ==================================================
125 sal_Int64 SAL_CALL
SvtRulerAccessible::getAccessibleChildCount()
127 ::osl::MutexGuard
aGuard( m_aMutex
);
129 ThrowExceptionIfNotAlive();
134 uno::Reference
< XAccessible
> SAL_CALL
SvtRulerAccessible::getAccessibleChild( sal_Int64
)
136 uno::Reference
< XAccessible
> xChild
;
141 uno::Reference
< XAccessible
> SAL_CALL
SvtRulerAccessible::getAccessibleParent()
146 sal_Int64 SAL_CALL
SvtRulerAccessible::getAccessibleIndexInParent()
148 ::osl::MutexGuard
aGuard( m_aMutex
);
149 // Use a simple but slow solution for now. Optimize later.
151 // Iterate over all the parent's children and search for this object.
154 uno::Reference
< XAccessibleContext
> xParentContext( mxParent
->getAccessibleContext() );
155 if( xParentContext
.is() )
157 sal_Int64 nChildCount
= xParentContext
->getAccessibleChildCount();
158 for( sal_Int64 i
= 0 ; i
< nChildCount
; ++i
)
160 uno::Reference
< XAccessible
> xChild( xParentContext
->getAccessibleChild( i
) );
161 if( xChild
.get() == static_cast<XAccessible
*>(this) )
167 // Return -1 to indicate that this object's parent does not know about the
172 sal_Int16 SAL_CALL
SvtRulerAccessible::getAccessibleRole()
174 return AccessibleRole::RULER
;
177 OUString SAL_CALL
SvtRulerAccessible::getAccessibleDescription()
182 OUString SAL_CALL
SvtRulerAccessible::getAccessibleName()
184 ::osl::MutexGuard
aGuard( m_aMutex
);
188 /** Return empty uno::Reference to indicate that the relation set is not
191 uno::Reference
< XAccessibleRelationSet
> SAL_CALL
SvtRulerAccessible::getAccessibleRelationSet()
193 return uno::Reference
< XAccessibleRelationSet
>();
197 sal_Int64 SAL_CALL
SvtRulerAccessible::getAccessibleStateSet()
199 ::osl::MutexGuard
aGuard( m_aMutex
);
200 sal_Int64 nStateSet
= 0;
204 nStateSet
|= AccessibleStateType::ENABLED
;
206 nStateSet
|= AccessibleStateType::SHOWING
;
209 nStateSet
|= AccessibleStateType::VISIBLE
;
211 if ( mpRepr
->GetStyle() & WB_HORZ
)
212 nStateSet
|= AccessibleStateType::HORIZONTAL
;
214 nStateSet
|= AccessibleStateType::VERTICAL
;
220 lang::Locale SAL_CALL
SvtRulerAccessible::getLocale()
222 ::osl::MutexGuard
aGuard( m_aMutex
);
225 uno::Reference
< XAccessibleContext
> xParentContext( mxParent
->getAccessibleContext() );
226 if( xParentContext
.is() )
227 return xParentContext
->getLocale();
230 // No parent. Therefore throw exception to indicate this cluelessness.
231 throw IllegalAccessibleComponentStateException();
234 void SAL_CALL
SvtRulerAccessible::addAccessibleEventListener( const uno::Reference
< XAccessibleEventListener
>& xListener
)
238 ::osl::MutexGuard
aGuard( m_aMutex
);
240 mnClientId
= comphelper::AccessibleEventNotifier::registerClient( );
241 comphelper::AccessibleEventNotifier::addEventListener( mnClientId
, xListener
);
245 void SAL_CALL
SvtRulerAccessible::removeAccessibleEventListener( const uno::Reference
< XAccessibleEventListener
>& xListener
)
247 if (!(xListener
.is() && mnClientId
))
250 ::osl::MutexGuard
aGuard( m_aMutex
);
252 sal_Int32 nListenerCount
= comphelper::AccessibleEventNotifier::removeEventListener( mnClientId
, xListener
);
253 if ( !nListenerCount
)
255 // no listeners anymore
256 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
257 // and at least to us not firing any events anymore, in case somebody calls
258 // NotifyAccessibleEvent, again
259 comphelper::AccessibleEventNotifier::revokeClient( mnClientId
);
264 void SAL_CALL
SvtRulerAccessible::grabFocus()
266 SolarMutexGuard aSolarGuard
;
267 ::osl::MutexGuard
aGuard( m_aMutex
);
269 ThrowExceptionIfNotAlive();
274 sal_Int32
SvtRulerAccessible::getForeground( )
276 SolarMutexGuard aSolarGuard
;
277 ::osl::MutexGuard
aGuard( m_aMutex
);
278 ThrowExceptionIfNotAlive();
280 return sal_Int32(mpRepr
->GetControlForeground());
282 sal_Int32
SvtRulerAccessible::getBackground( )
284 SolarMutexGuard aSolarGuard
;
285 ::osl::MutexGuard
aGuard( m_aMutex
);
286 ThrowExceptionIfNotAlive();
288 return sal_Int32(mpRepr
->GetControlBackground());
292 OUString SAL_CALL
SvtRulerAccessible::getImplementationName()
294 return "com.sun.star.comp.ui.SvtRulerAccessible";
297 sal_Bool SAL_CALL
SvtRulerAccessible::supportsService( const OUString
& sServiceName
)
299 return cppu::supportsService( this, sServiceName
);
302 Sequence
< OUString
> SAL_CALL
SvtRulerAccessible::getSupportedServiceNames()
304 return { "com.sun.star.accessibility.AccessibleContext" };
307 //===== XTypeProvider =======================================================
308 Sequence
< sal_Int8
> SAL_CALL
SvtRulerAccessible::getImplementationId()
310 return css::uno::Sequence
<sal_Int8
>();
313 void SAL_CALL
SvtRulerAccessible::disposing()
315 if( rBHelper
.bDisposed
)
318 ::osl::MutexGuard
aGuard( m_aMutex
);
319 mpRepr
= nullptr; // object dies with representation
321 // Send a disposing to all listeners.
324 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId
, *this );
330 tools::Rectangle
SvtRulerAccessible::GetBoundingBoxOnScreen()
332 SolarMutexGuard aSolarGuard
;
333 ::osl::MutexGuard
aGuard( m_aMutex
);
335 ThrowExceptionIfNotAlive();
336 return tools::Rectangle( mpRepr
->GetParent()->OutputToAbsoluteScreenPixel( mpRepr
->GetPosPixel() ), mpRepr
->GetSizePixel() );
339 tools::Rectangle
SvtRulerAccessible::GetBoundingBox()
341 SolarMutexGuard aSolarGuard
;
342 ::osl::MutexGuard
aGuard( m_aMutex
);
344 ThrowExceptionIfNotAlive();
346 return tools::Rectangle( mpRepr
->GetPosPixel(), mpRepr
->GetSizePixel() );
349 void SvtRulerAccessible::ThrowExceptionIfNotAlive()
351 if( rBHelper
.bDisposed
|| rBHelper
.bInDispose
)
352 throw lang::DisposedException();
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */