LibreOffice Module sc (master) 1
AccessibleContextBase.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
20#include <AccessibleContextBase.hxx>
21#include <com/sun/star/accessibility/AccessibleEventId.hpp>
22#include <com/sun/star/accessibility/AccessibleStateType.hpp>
23#include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
24#include <tools/gen.hxx>
25#include <tools/color.hxx>
27#include <svl/hint.hxx>
31#include <utility>
32#include <vcl/unohelp.hxx>
34#include <vcl/svapp.hxx>
35
36using namespace ::com::sun::star;
37using namespace ::com::sun::star::accessibility;
38
40 uno::Reference<XAccessible> xParent,
41 const sal_Int16 aRole)
42 :
44 mxParent(std::move(xParent)),
45 mnClientId(0),
46 maRole(aRole)
47{
48}
49
51{
52 if (!IsDefunc() && !rBHelper.bInDispose)
53 {
54 // increment refcount to prevent double call off dtor
55 osl_atomic_increment( &m_refCount );
56 // call dispose to inform object which have a weak reference to this object
57 dispose();
58 }
59}
60
62{
63 // hold reference to make sure that the destructor is not called
64 uno::Reference< XAccessibleContext > xKeepAlive(this);
65
66 if (mxParent.is())
67 {
68 uno::Reference< XAccessibleEventBroadcaster > xBroadcaster (mxParent->getAccessibleContext(), uno::UNO_QUERY);
69 if (xBroadcaster.is())
70 xBroadcaster->addAccessibleEventListener(this);
71 }
74}
75
77{
78 SolarMutexGuard aGuard;
79// CommitDefunc(); not necessary and should not be send, because it cost a lot of time
80
81 // hold reference to make sure that the destructor is not called
82 uno::Reference< XAccessibleContext > xKeepAlive(this);
83
84 if ( mnClientId )
85 {
86 sal_Int32 nTemClientId(mnClientId);
87 mnClientId = 0;
89 }
90
91 if (mxParent.is())
92 {
93 uno::Reference< XAccessibleEventBroadcaster > xBroadcaster (mxParent->getAccessibleContext(), uno::UNO_QUERY);
94 if (xBroadcaster.is())
95 xBroadcaster->removeAccessibleEventListener(this);
96 mxParent = nullptr;
97 }
98}
99
100
101//===== SfxListener =====================================================
102
104{
105 if (rHint.GetId() == SfxHintId::Dying)
106 {
107 // it seems the Broadcaster is dying, since the view is dying
108 dispose();
109 }
110}
111
112//===== XAccessible =========================================================
113
114uno::Reference< XAccessibleContext> SAL_CALL
116{
117 return this;
118}
119
120//===== XAccessibleComponent ================================================
121
122sal_Bool SAL_CALL ScAccessibleContextBase::containsPoint(const awt::Point& rPoint )
123{
124 SolarMutexGuard aGuard;
126 return tools::Rectangle (Point(), GetBoundingBox().GetSize()).Contains(VCLPoint(rPoint));
127}
128
129uno::Reference< XAccessible > SAL_CALL ScAccessibleContextBase::getAccessibleAtPoint(
130 const awt::Point& /* rPoint */ )
131{
132 OSL_FAIL("not implemented");
133 return uno::Reference<XAccessible>();
134}
135
136awt::Rectangle SAL_CALL ScAccessibleContextBase::getBounds( )
137{
138 SolarMutexGuard aGuard;
141}
142
144{
145 SolarMutexGuard aGuard;
147 return AWTPoint(GetBoundingBox().TopLeft());
148}
149
151{
152 SolarMutexGuard aGuard;
155}
156
158{
159 SolarMutexGuard aGuard;
161 return AWTSize(GetBoundingBox().GetSize());
162}
163
165{
166 SolarMutexGuard aGuard;
168 bool bShowing(false);
169 if (mxParent.is())
170 {
171 uno::Reference<XAccessibleComponent> xParentComponent (mxParent->getAccessibleContext(), uno::UNO_QUERY);
172 if (xParentComponent.is())
173 {
174 tools::Rectangle aParentBounds(VCLRectangle(xParentComponent->getBounds()));
176 bShowing = aBounds.Overlaps(aParentBounds);
177 }
178 }
179 return bShowing;
180}
181
183{
184 return true;
185}
186
188{
189 OSL_FAIL("not implemented");
190}
191
193{
194 return sal_Int32(COL_BLACK);
195}
196
198{
199 return sal_Int32(COL_WHITE);
200}
201
202//===== XAccessibleContext ==================================================
203
205{
206 OSL_FAIL("should be implemented in the abrevated class");
207 return 0;
208}
209
210uno::Reference<XAccessible> SAL_CALL
212{
213 OSL_FAIL("should be implemented in the abrevated class");
214 return uno::Reference<XAccessible>();
215}
216
217uno::Reference<XAccessible> SAL_CALL
219{
220 return mxParent;
221}
222
223sal_Int64 SAL_CALL
225{
226 SolarMutexGuard aGuard;
228 // Use a simple but slow solution for now. Optimize later.
229 // Return -1 to indicate that this object's parent does not know about the
230 // object.
231 sal_Int64 nIndex(-1);
232
233 // Iterate over all the parent's children and search for this object.
234 if (mxParent.is())
235 {
236 uno::Reference<XAccessibleContext> xParentContext (
237 mxParent->getAccessibleContext());
238 if (xParentContext.is())
239 {
240 sal_Int64 nChildCount = xParentContext->getAccessibleChildCount();
241 for (sal_Int64 i=0; i<nChildCount; ++i)
242 {
243 uno::Reference<XAccessible> xChild (xParentContext->getAccessibleChild (i));
244 if (xChild.is() && xChild.get() == this)
245 nIndex = i;
246 }
247 }
248 }
249
250 return nIndex;
251}
252
253sal_Int16 SAL_CALL
255{
256 return maRole;
257}
258
259OUString SAL_CALL
261{
262 SolarMutexGuard aGuard;
264 if (msDescription.isEmpty())
265 {
266 OUString sDescription(createAccessibleDescription());
267
268 if (msDescription != sDescription)
269 {
270 AccessibleEventObject aEvent;
271 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
272 aEvent.Source = uno::Reference< XAccessibleContext >(this);
273 aEvent.OldValue <<= msDescription;
274 aEvent.NewValue <<= sDescription;
275
276 msDescription = sDescription;
277
279 }
280 }
281 return msDescription;
282}
283
284OUString SAL_CALL
286{
287 SolarMutexGuard aGuard;
289 if (msName.isEmpty())
290 {
291 OUString sName(createAccessibleName());
292 OSL_ENSURE(!sName.isEmpty(), "We should give always a name.");
293
294 if (msName != sName)
295 {
296 AccessibleEventObject aEvent;
297 aEvent.EventId = AccessibleEventId::NAME_CHANGED;
298 aEvent.Source = uno::Reference< XAccessibleContext >(this);
299 aEvent.OldValue <<= msName;
300 aEvent.NewValue <<= sName;
301
302 msName = sName;
303
305 }
306 }
307 return msName;
308}
309
310uno::Reference<XAccessibleRelationSet> SAL_CALL
312{
314}
315
317{
318 return 0;
319}
320
321lang::Locale SAL_CALL
323{
324 SolarMutexGuard aGuard;
326 if (mxParent.is())
327 {
328 uno::Reference<XAccessibleContext> xParentContext (
329 mxParent->getAccessibleContext());
330 if (xParentContext.is())
331 return xParentContext->getLocale ();
332 }
333
334 // No locale and no parent. Therefore throw exception to indicate this
335 // cluelessness.
336 throw IllegalAccessibleComponentStateException ();
337}
338
339 //===== XAccessibleEventBroadcaster =====================================
340
341void SAL_CALL
343 const uno::Reference<XAccessibleEventListener>& xListener)
344{
345 if (xListener.is())
346 {
347 SolarMutexGuard aGuard;
349 if (!IsDefunc())
350 {
351 if (!mnClientId)
354 }
355 }
356}
357
358void SAL_CALL
360 const uno::Reference<XAccessibleEventListener>& xListener)
361{
362 if (!xListener.is())
363 return;
364
365 SolarMutexGuard aGuard;
366 if (IsDefunc() || !mnClientId)
367 return;
368
369 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
370 if ( !nListenerCount )
371 {
372 // no listeners anymore
373 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
374 // and at least to us not firing any events anymore, in case somebody calls
375 // NotifyAccessibleEvent, again
377 mnClientId = 0;
378 }
379}
380
381 //===== XAccessibleEventListener ========================================
382
384 const lang::EventObject& rSource )
385{
386 SolarMutexGuard aGuard;
387 if (rSource.Source == mxParent)
388 dispose();
389}
390
392 const AccessibleEventObject& /* aEvent */ )
393{
394}
395
396// XServiceInfo
398{
399 return "ScAccessibleContextBase";
400}
401
402sal_Bool SAL_CALL ScAccessibleContextBase::supportsService(const OUString& sServiceName)
403{
405}
406
407uno::Sequence< OUString> SAL_CALL
409{
410 return {"com.sun.star.accessibility.Accessible",
411 "com.sun.star.accessibility.AccessibleContext"};
412}
413
414//===== internal ============================================================
415
416OUString
418{
419 OSL_FAIL("should be implemented in the abrevated class");
420 return OUString();
421}
422
424{
425 OSL_FAIL("should be implemented in the abrevated class");
426 return OUString();
427}
428
429void ScAccessibleContextBase::CommitChange(const AccessibleEventObject& rEvent) const
430{
431 if (mnClientId)
433}
434
436{
437 AccessibleEventObject aEvent;
438 aEvent.EventId = AccessibleEventId::STATE_CHANGED;
439 aEvent.Source = uno::Reference< XAccessibleContext >(const_cast<ScAccessibleContextBase*>(this));
440 aEvent.NewValue <<= AccessibleStateType::FOCUSED;
441
443}
444
446{
447 AccessibleEventObject aEvent;
448 aEvent.EventId = AccessibleEventId::STATE_CHANGED;
449 aEvent.Source = uno::Reference< XAccessibleContext >(const_cast<ScAccessibleContextBase*>(this));
450 aEvent.OldValue <<= AccessibleStateType::FOCUSED;
451
453}
454
456{
457 OSL_FAIL("not implemented");
458 return tools::Rectangle();
459}
460
462{
463 OSL_FAIL("not implemented");
464 return tools::Rectangle();
465}
466
468{
469 if (rBHelper.bDisposed || rBHelper.bInDispose)
470 throw lang::DisposedException();
471}
472
473/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
cppu::WeakComponentImplHelper< css::accessibility::XAccessible, css::accessibility::XAccessibleComponent, css::accessibility::XAccessibleContext, css::accessibility::XAccessibleEventBroadcaster, css::lang::XServiceInfo, css::accessibility::XAccessibleEventListener > ScAccessibleContextBaseWeakImpl
@descr This base class provides an implementation of the AccessibleContext service.
constexpr OUStringLiteral sServiceName
unotools::WeakReference< AnimationNode > mxParent
AnyEventRef aEvent
virtual tools::Rectangle GetBoundingBoxOnScreen() const
Return the object's current bounding box relative to the desktop.
virtual ~ScAccessibleContextBase() override
virtual css::awt::Point SAL_CALL getLocationOnScreen() override
virtual sal_Bool SAL_CALL containsPoint(const css::awt::Point &rPoint) override
===== XAccessibleComponent ============================================
OUString msDescription
Description of this object.
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &rPoint) override
virtual css::awt::Size SAL_CALL getSize() override
virtual OUString SAL_CALL getAccessibleDescription() override
Return this object's description.
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
===== XAccessible =====================================================
virtual OUString createAccessibleDescription()
Return this object's description.
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
Return whether the specified service is supported by this class.
virtual void SAL_CALL disposing() override
OUString msName
Name of this object.
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 nIndex) override
Return the specified child or NULL if index is invalid.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Returns a list of all supported services.
virtual void SAL_CALL grabFocus() override
virtual void SAL_CALL addAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
===== XAccessibleEventBroadcaster =====================================
virtual OUString SAL_CALL getImplementationName() override
===== XServiceInfo ====================================================
virtual css::awt::Rectangle SAL_CALL getBounds() override
void CommitFocusLost() const
Calls all FocusListener to tell they that the focus is lost.
sal_uInt32 mnClientId
client id in the AccessibleEventNotifier queue
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
===== SfxListener =====================================================
virtual css::lang::Locale SAL_CALL getLocale() override
Return the parents locale or throw exception if this object has no parent yet/anymore.
virtual css::awt::Point SAL_CALL getLocation() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
Return a reference to the parent.
void CommitFocusGained() const
Calls all FocusListener to tell they that the focus is gained.
css::uno::Reference< css::accessibility::XAccessible > mxParent
Reference to the parent object.
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
Return this objects index among the parents children.
virtual sal_Int32 SAL_CALL getBackground() override
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
Return the set of current states.
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
===== XAccessibleContext ==============================================
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
Return NULL to indicate that an empty relation set.
virtual OUString createAccessibleName()
Return the object's current name.
virtual sal_Int16 SAL_CALL getAccessibleRole() override
Return this object's role.
virtual tools::Rectangle GetBoundingBox() const
Return the object's current bounding box relative to the parent object.
ScAccessibleContextBase(css::uno::Reference< css::accessibility::XAccessible > xParent, const sal_Int16 aRole)
void CommitChange(const css::accessibility::AccessibleEventObject &rEvent) const
Calls all Listener to tell they the change.
virtual void SAL_CALL removeAccessibleEventListener(const css::uno::Reference< css::accessibility::XAccessibleEventListener > &xListener) override
virtual sal_Int32 SAL_CALL getForeground() override
sal_Int16 maRole
This is the role of this object.
virtual OUString SAL_CALL getAccessibleName() override
Return the object's current name.
virtual void SAL_CALL notifyEvent(const css::accessibility::AccessibleEventObject &aEvent) override
SfxHintId GetId() const
static sal_Int32 addEventListener(const TClientId _nClient, const css::uno::Reference< css::accessibility::XAccessibleEventListener > &_rxListener)
static void addEvent(const TClientId _nClient, const css::accessibility::AccessibleEventObject &_rEvent)
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)
bool Contains(const Point &rPOINT) const
bool Overlaps(const tools::Rectangle &rRect) const
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
css::awt::Size AWTSize(const Size &rVCLSize)
css::awt::Point AWTPoint(const ::Point &rVCLPoint)
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
inline ::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
inline ::Point VCLPoint(const css::awt::Point &rAWTPoint)
ULONG m_refCount
OUString sName
std::mutex m_aMutex
sal_Int32 nIndex
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
void dispose()
unsigned char sal_Bool