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/vclunohelper.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/unohelp.hxx>
28 #include <osl/mutex.hxx>
29 #include <tools/gen.hxx>
31 #include <svtools/ruler.hxx>
32 #include "accessibleruler.hxx"
34 using namespace ::cppu
;
35 using namespace ::osl
;
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::accessibility
;
41 //===== internal ============================================================
43 SvtRulerAccessible::SvtRulerAccessible(
44 uno::Reference
< XAccessible
> xParent
, Ruler
& rRepr
, OUString aName
) :
46 msName(std::move( aName
)),
47 mxParent(std::move( xParent
)),
53 SvtRulerAccessible::~SvtRulerAccessible()
57 osl_atomic_increment( &m_refCount
);
58 dispose(); // set mpRepr = NULL & release all children
62 //===== XAccessible =========================================================
64 uno::Reference
< XAccessibleContext
> SAL_CALL
SvtRulerAccessible::getAccessibleContext()
69 //===== XAccessibleComponent ================================================
71 sal_Bool SAL_CALL
SvtRulerAccessible::containsPoint( const awt::Point
& rPoint
)
73 // no guard -> done in getBounds()
74 // return GetBoundingBox().IsInside( vcl::unohelper::ConvertToVCLPoint( rPoint ) );
75 return tools::Rectangle(Point(0, 0), GetBoundingBox().GetSize())
76 .Contains(vcl::unohelper::ConvertToVCLPoint(rPoint
));
79 uno::Reference
< XAccessible
> SAL_CALL
SvtRulerAccessible::getAccessibleAtPoint( const awt::Point
& )
81 std::unique_lock
aGuard( m_aMutex
);
82 throwIfDisposed(aGuard
);
84 return uno::Reference
< XAccessible
>();
87 awt::Rectangle SAL_CALL
SvtRulerAccessible::getBounds()
89 // no guard -> done in GetBoundingBox()
90 return vcl::unohelper::ConvertToAWTRect(GetBoundingBox());
93 awt::Point SAL_CALL
SvtRulerAccessible::getLocation()
95 // no guard -> done in GetBoundingBox()
96 return vcl::unohelper::ConvertToAWTPoint(GetBoundingBox().TopLeft());
99 awt::Point SAL_CALL
SvtRulerAccessible::getLocationOnScreen()
101 // no guard -> done in GetBoundingBoxOnScreen()
102 return vcl::unohelper::ConvertToAWTPoint(GetBoundingBoxOnScreen().TopLeft());
105 awt::Size SAL_CALL
SvtRulerAccessible::getSize()
107 // no guard -> done in GetBoundingBox()
108 return vcl::unohelper::ConvertToAWTSize(GetBoundingBox().GetSize());
111 //===== XAccessibleContext ==================================================
112 sal_Int64 SAL_CALL
SvtRulerAccessible::getAccessibleChildCount()
114 std::unique_lock
aGuard( m_aMutex
);
115 throwIfDisposed(aGuard
);
120 uno::Reference
< XAccessible
> SAL_CALL
SvtRulerAccessible::getAccessibleChild( sal_Int64
)
122 uno::Reference
< XAccessible
> xChild
;
127 uno::Reference
< XAccessible
> SAL_CALL
SvtRulerAccessible::getAccessibleParent()
132 sal_Int64 SAL_CALL
SvtRulerAccessible::getAccessibleIndexInParent()
134 std::unique_lock
aGuard( m_aMutex
);
136 // Use a simple but slow solution for now. Optimize later.
138 // Iterate over all the parent's children and search for this object.
141 uno::Reference
< XAccessibleContext
> xParentContext( mxParent
->getAccessibleContext() );
142 if( xParentContext
.is() )
144 sal_Int64 nChildCount
= xParentContext
->getAccessibleChildCount();
145 for( sal_Int64 i
= 0 ; i
< nChildCount
; ++i
)
147 uno::Reference
< XAccessible
> xChild( xParentContext
->getAccessibleChild( i
) );
148 if( xChild
.get() == static_cast<XAccessible
*>(this) )
154 // Return -1 to indicate that this object's parent does not know about the
159 sal_Int16 SAL_CALL
SvtRulerAccessible::getAccessibleRole()
161 return AccessibleRole::RULER
;
164 OUString SAL_CALL
SvtRulerAccessible::getAccessibleDescription()
169 OUString SAL_CALL
SvtRulerAccessible::getAccessibleName()
174 /** Return empty uno::Reference to indicate that the relation set is not
177 uno::Reference
< XAccessibleRelationSet
> SAL_CALL
SvtRulerAccessible::getAccessibleRelationSet()
179 return uno::Reference
< XAccessibleRelationSet
>();
183 sal_Int64 SAL_CALL
SvtRulerAccessible::getAccessibleStateSet()
185 std::unique_lock
aGuard( m_aMutex
);
187 sal_Int64 nStateSet
= 0;
191 nStateSet
|= AccessibleStateType::ENABLED
;
193 nStateSet
|= AccessibleStateType::SHOWING
;
195 if( mpRepr
->IsVisible() )
196 nStateSet
|= AccessibleStateType::VISIBLE
;
198 if ( mpRepr
->GetStyle() & WB_HORZ
)
199 nStateSet
|= AccessibleStateType::HORIZONTAL
;
201 nStateSet
|= AccessibleStateType::VERTICAL
;
207 lang::Locale SAL_CALL
SvtRulerAccessible::getLocale()
209 std::unique_lock
aGuard( m_aMutex
);
213 uno::Reference
< XAccessibleContext
> xParentContext( mxParent
->getAccessibleContext() );
214 if( xParentContext
.is() )
215 return xParentContext
->getLocale();
218 // No parent. Therefore throw exception to indicate this cluelessness.
219 throw IllegalAccessibleComponentStateException();
222 void SAL_CALL
SvtRulerAccessible::addAccessibleEventListener( const uno::Reference
< XAccessibleEventListener
>& xListener
)
226 std::unique_lock
aGuard( m_aMutex
);
228 mnClientId
= comphelper::AccessibleEventNotifier::registerClient( );
229 comphelper::AccessibleEventNotifier::addEventListener( mnClientId
, xListener
);
233 void SAL_CALL
SvtRulerAccessible::removeAccessibleEventListener( const uno::Reference
< XAccessibleEventListener
>& xListener
)
238 std::unique_lock
aGuard( m_aMutex
);
243 sal_Int32 nListenerCount
= comphelper::AccessibleEventNotifier::removeEventListener( mnClientId
, xListener
);
244 if ( !nListenerCount
)
246 // no listeners anymore
247 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
248 // and at least to us not firing any events anymore, in case somebody calls
249 // NotifyAccessibleEvent, again
250 comphelper::AccessibleEventNotifier::revokeClient( mnClientId
);
255 void SAL_CALL
SvtRulerAccessible::grabFocus()
259 std::unique_lock
aGuard( m_aMutex
);
263 throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject
*>(this));
265 SolarMutexGuard aSolarGuard
;
269 sal_Int32
SvtRulerAccessible::getForeground( )
273 std::unique_lock
aGuard( m_aMutex
);
277 throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject
*>(this));
279 SolarMutexGuard aSolarGuard
;
280 return sal_Int32(xRepr
->GetControlForeground());
282 sal_Int32
SvtRulerAccessible::getBackground( )
286 std::unique_lock
aGuard( m_aMutex
);
290 throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject
*>(this));
292 SolarMutexGuard aSolarGuard
;
293 return sal_Int32(xRepr
->GetControlBackground());
297 OUString SAL_CALL
SvtRulerAccessible::getImplementationName()
299 return u
"com.sun.star.comp.ui.SvtRulerAccessible"_ustr
;
302 sal_Bool SAL_CALL
SvtRulerAccessible::supportsService( const OUString
& sServiceName
)
304 return cppu::supportsService( this, sServiceName
);
307 Sequence
< OUString
> SAL_CALL
SvtRulerAccessible::getSupportedServiceNames()
309 return { u
"com.sun.star.accessibility.AccessibleContext"_ustr
};
312 //===== XTypeProvider =======================================================
313 Sequence
< sal_Int8
> SAL_CALL
SvtRulerAccessible::getImplementationId()
315 return css::uno::Sequence
<sal_Int8
>();
318 void SvtRulerAccessible::disposing(std::unique_lock
<std::mutex
>&)
320 mpRepr
= nullptr; // object dies with representation
322 // Send a disposing to all listeners.
325 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId
, *this );
331 tools::Rectangle
SvtRulerAccessible::GetBoundingBoxOnScreen()
335 std::unique_lock
aGuard( m_aMutex
);
339 throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject
*>(this));
341 SolarMutexGuard aSolarGuard
;
342 return tools::Rectangle( xRepr
->GetParent()->OutputToAbsoluteScreenPixel( xRepr
->GetPosPixel() ), xRepr
->GetSizePixel() );
345 tools::Rectangle
SvtRulerAccessible::GetBoundingBox()
349 std::unique_lock
aGuard( m_aMutex
);
353 throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject
*>(this));
355 SolarMutexGuard aSolarGuard
;
356 return tools::Rectangle( xRepr
->GetPosPixel(), xRepr
->GetSizePixel() );
359 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */