LibreOffice Module svtools (master) 1
accessibleruler.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include <com/sun/star/accessibility/AccessibleRole.hpp>
20#include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
21#include <com/sun/star/accessibility/AccessibleStateType.hpp>
25#include <utility>
26#include <vcl/svapp.hxx>
27#include <osl/mutex.hxx>
28#include <tools/gen.hxx>
29
30#include <svtools/ruler.hxx>
31#include "accessibleruler.hxx"
32
33using namespace ::cppu;
34using namespace ::osl;
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::accessibility;
38
39
40//===== internal ============================================================
41
43 uno::Reference< XAccessible > xParent, Ruler& rRepr, OUString aName ) :
44
46 msName(std::move( aName )),
47 mxParent(std::move( xParent )),
48 mpRepr( &rRepr ),
49 mnClientId( 0 )
50{
51}
52
54{
55
56 if( IsAlive() )
57 {
58 osl_atomic_increment( &m_refCount );
59 dispose(); // set mpRepr = NULL & release all children
60 }
61}
62
63//===== XAccessible =========================================================
64
65uno::Reference< XAccessibleContext > SAL_CALL SvtRulerAccessible::getAccessibleContext()
66{
67 return this;
68}
69
70//===== XAccessibleComponent ================================================
71
72sal_Bool SAL_CALL SvtRulerAccessible::containsPoint( const awt::Point& rPoint )
73{
74 // no guard -> done in getBounds()
75// return GetBoundingBox().IsInside( VCLPoint( rPoint ) );
76 return tools::Rectangle( Point( 0, 0 ), GetBoundingBox().GetSize() ).Contains( VCLPoint( rPoint ) );
77}
78
79uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleAtPoint( const awt::Point& )
80{
81 ::osl::MutexGuard aGuard( m_aMutex );
82
84
85 uno::Reference< XAccessible > xRet;
86
87
88 return xRet;
89}
90
91awt::Rectangle SAL_CALL SvtRulerAccessible::getBounds()
92{
93 // no guard -> done in GetBoundingBox()
94 return AWTRectangle( GetBoundingBox() );
95}
96
98{
99 // no guard -> done in GetBoundingBox()
100 return AWTPoint( GetBoundingBox().TopLeft() );
101}
102
104{
105 // no guard -> done in GetBoundingBoxOnScreen()
107}
108
109awt::Size SAL_CALL SvtRulerAccessible::getSize()
110{
111 // no guard -> done in GetBoundingBox()
112 return AWTSize( GetBoundingBox().GetSize() );
113}
114
116{
117 ::osl::MutexGuard aGuard( m_aMutex );
118
120
121 return mpRepr->IsVisible();
122}
123
124//===== XAccessibleContext ==================================================
126{
127 ::osl::MutexGuard aGuard( m_aMutex );
128
130
131 return 0;
132}
133
134uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleChild( sal_Int64 )
135{
136 uno::Reference< XAccessible > xChild ;
137
138 return xChild;
139}
140
141uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleParent()
142{
143 return mxParent;
144}
145
147{
148 ::osl::MutexGuard aGuard( m_aMutex );
149 // Use a simple but slow solution for now. Optimize later.
150
151 // Iterate over all the parent's children and search for this object.
152 if( mxParent.is() )
153 {
154 uno::Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
155 if( xParentContext.is() )
156 {
157 sal_Int64 nChildCount = xParentContext->getAccessibleChildCount();
158 for( sal_Int64 i = 0 ; i < nChildCount ; ++i )
159 {
160 uno::Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
161 if( xChild.get() == static_cast<XAccessible*>(this) )
162 return i;
163 }
164 }
165 }
166
167 // Return -1 to indicate that this object's parent does not know about the
168 // object.
169 return -1;
170}
171
173{
174 return AccessibleRole::RULER;
175}
176
178{
179 return OUString();
180}
181
183{
184 ::osl::MutexGuard aGuard( m_aMutex );
185 return msName;
186}
187
191uno::Reference< XAccessibleRelationSet > SAL_CALL SvtRulerAccessible::getAccessibleRelationSet()
192{
193 return uno::Reference< XAccessibleRelationSet >();
194}
195
196
198{
199 ::osl::MutexGuard aGuard( m_aMutex );
200 sal_Int64 nStateSet = 0;
201
202 if( IsAlive() )
203 {
204 nStateSet |= AccessibleStateType::ENABLED;
205
206 nStateSet |= AccessibleStateType::SHOWING;
207
208 if( isVisible() )
209 nStateSet |= AccessibleStateType::VISIBLE;
210
211 if ( mpRepr->GetStyle() & WB_HORZ )
212 nStateSet |= AccessibleStateType::HORIZONTAL;
213 else
214 nStateSet |= AccessibleStateType::VERTICAL;
215 }
216
217 return nStateSet;
218}
219
220lang::Locale SAL_CALL SvtRulerAccessible::getLocale()
221{
222 ::osl::MutexGuard aGuard( m_aMutex );
223 if( mxParent.is() )
224 {
225 uno::Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
226 if( xParentContext.is() )
227 return xParentContext->getLocale();
228 }
229
230 // No parent. Therefore throw exception to indicate this cluelessness.
231 throw IllegalAccessibleComponentStateException();
232}
233
234void SAL_CALL SvtRulerAccessible::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
235{
236 if (xListener.is())
237 {
238 ::osl::MutexGuard aGuard( m_aMutex );
239 if (!mnClientId)
242 }
243}
244
245void SAL_CALL SvtRulerAccessible::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
246{
247 if (!(xListener.is() && mnClientId))
248 return;
249
250 ::osl::MutexGuard aGuard( m_aMutex );
251
252 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
253 if ( !nListenerCount )
254 {
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
260 mnClientId = 0;
261 }
262}
263
265{
266 SolarMutexGuard aSolarGuard;
267 ::osl::MutexGuard aGuard( m_aMutex );
268
270
271 mpRepr->GrabFocus();
272}
273
275{
276 SolarMutexGuard aSolarGuard;
277 ::osl::MutexGuard aGuard( m_aMutex );
279
280 return sal_Int32(mpRepr->GetControlForeground());
281}
283{
284 SolarMutexGuard aSolarGuard;
285 ::osl::MutexGuard aGuard( m_aMutex );
287
288 return sal_Int32(mpRepr->GetControlBackground());
289}
290
291// XServiceInfo
293{
294 return "com.sun.star.comp.ui.SvtRulerAccessible";
295}
296
297sal_Bool SAL_CALL SvtRulerAccessible::supportsService( const OUString& sServiceName )
298{
299 return cppu::supportsService( this, sServiceName );
300}
301
302Sequence< OUString > SAL_CALL SvtRulerAccessible::getSupportedServiceNames()
303{
304 return { "com.sun.star.accessibility.AccessibleContext" };
305}
306
307//===== XTypeProvider =======================================================
308Sequence< sal_Int8 > SAL_CALL SvtRulerAccessible::getImplementationId()
309{
310 return css::uno::Sequence<sal_Int8>();
311}
312
314{
315 if( rBHelper.bDisposed )
316 return;
317
318 ::osl::MutexGuard aGuard( m_aMutex );
319 mpRepr = nullptr; // object dies with representation
320
321 // Send a disposing to all listeners.
322 if ( mnClientId )
323 {
325 mnClientId = 0;
326 }
327 mxParent.clear();
328}
329
331{
332 SolarMutexGuard aSolarGuard;
333 ::osl::MutexGuard aGuard( m_aMutex );
334
336 return tools::Rectangle( mpRepr->GetParent()->OutputToAbsoluteScreenPixel( mpRepr->GetPosPixel() ), mpRepr->GetSizePixel() );
337}
338
340{
341 SolarMutexGuard aSolarGuard;
342 ::osl::MutexGuard aGuard( m_aMutex );
343
345
346 return tools::Rectangle( mpRepr->GetPosPixel(), mpRepr->GetSizePixel() );
347}
348
350{
351 if( rBHelper.bDisposed || rBHelper.bInDispose )
352 throw lang::DisposedException();
353}
354
355/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
unotools::WeakReference< AnimationNode > mxParent
Definition: ruler.hxx:609
virtual void SAL_CALL disposing() override
virtual css::awt::Size SAL_CALL getSize() override
tools::Rectangle GetBoundingBoxOnScreen()
@Return the object's current bounding box relative to the desktop.
virtual void SAL_CALL addAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
virtual css::awt::Rectangle SAL_CALL getBounds() override
VclPtr< Ruler > mpRepr
pointer to internal representation
virtual void SAL_CALL grabFocus() override
tools::Rectangle GetBoundingBox()
@Return the object's current bounding box relative to the parent object.
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &rPoint) override
OUString msName
Name of this object.
virtual sal_Int32 SAL_CALL getForeground() override
virtual css::awt::Point SAL_CALL getLocationOnScreen() override
sal_uInt32 mnClientId
client id in the AccessibleEventNotifier queue
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 nIndex) override
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
css::uno::Reference< css::accessibility::XAccessible > mxParent
Reference to the parent object.
virtual sal_Int32 SAL_CALL getBackground() override
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &rPoint) override
virtual void SAL_CALL removeAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual ~SvtRulerAccessible() override
virtual css::lang::Locale SAL_CALL getLocale() override
virtual OUString SAL_CALL getAccessibleDescription() override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual OUString SAL_CALL getAccessibleName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual css::awt::Point SAL_CALL getLocation() override
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
Return empty uno::Reference to indicate that the relation set is not supported.
SvtRulerAccessible(css::uno::Reference< css::accessibility::XAccessible > xParent, Ruler &rRepresentation, OUString aName)
static sal_Int32 addEventListener(const TClientId _nClient, const css::uno::Reference< css::accessibility::XAccessibleEventListener > &_rxListener)
static sal_Int32 removeEventListener(const TClientId _nClient, const css::uno::Reference< css::accessibility::XAccessibleEventListener > &_rxListener)
static void revokeClient(const TClientId _nClient)
static void revokeClientNotifyDisposing(const TClientId _nClient, const css::uno::Reference< css::uno::XInterface > &_rxEventSource)
mutable::osl::Mutex m_aMutex
bool Contains(const Point &rPOINT) const
css::awt::Size AWTSize(const Size &rVCLSize)
css::awt::Point AWTPoint(const ::Point &rVCLPoint)
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
inline ::Point VCLPoint(const css::awt::Point &rAWTPoint)
ULONG m_refCount
std::mutex m_aMutex
OUString aName
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
void dispose()
OUString msName
unsigned char sal_Bool
WinBits const WB_HORZ