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 ScAccessibleContextBaseWeakImpl::disposing();
100}
101
102//===== XInterface =====================================================
103
105{
108}
109
111 noexcept
112{
114}
115
117 noexcept
118{
120}
121
122//===== SfxListener =====================================================
123
125{
126 if (rHint.GetId() == SfxHintId::Dying)
127 {
128 // it seems the Broadcaster is dying, since the view is dying
129 dispose();
130 }
131}
132
133//===== XAccessible =========================================================
134
135uno::Reference< XAccessibleContext> SAL_CALL
137{
138 return this;
139}
140
141//===== XAccessibleComponent ================================================
142
143sal_Bool SAL_CALL ScAccessibleContextBase::containsPoint(const awt::Point& rPoint )
144{
145 SolarMutexGuard aGuard;
147 return tools::Rectangle (Point(), GetBoundingBox().GetSize()).Contains(VCLPoint(rPoint));
148}
149
150uno::Reference< XAccessible > SAL_CALL ScAccessibleContextBase::getAccessibleAtPoint(
151 const awt::Point& /* rPoint */ )
152{
153 OSL_FAIL("not implemented");
154 return uno::Reference<XAccessible>();
155}
156
157awt::Rectangle SAL_CALL ScAccessibleContextBase::getBounds( )
158{
159 SolarMutexGuard aGuard;
162}
163
165{
166 SolarMutexGuard aGuard;
168 return AWTPoint(GetBoundingBox().TopLeft());
169}
170
172{
173 SolarMutexGuard aGuard;
176}
177
179{
180 SolarMutexGuard aGuard;
182 return AWTSize(GetBoundingBox().GetSize());
183}
184
186{
187 SolarMutexGuard aGuard;
189 bool bShowing(false);
190 if (mxParent.is())
191 {
192 uno::Reference<XAccessibleComponent> xParentComponent (mxParent->getAccessibleContext(), uno::UNO_QUERY);
193 if (xParentComponent.is())
194 {
195 tools::Rectangle aParentBounds(VCLRectangle(xParentComponent->getBounds()));
197 bShowing = aBounds.Overlaps(aParentBounds);
198 }
199 }
200 return bShowing;
201}
202
204{
205 return true;
206}
207
209{
210 OSL_FAIL("not implemented");
211}
212
214{
215 return sal_Int32(COL_BLACK);
216}
217
219{
220 return sal_Int32(COL_WHITE);
221}
222
223//===== XAccessibleContext ==================================================
224
226{
227 OSL_FAIL("should be implemented in the abrevated class");
228 return 0;
229}
230
231uno::Reference<XAccessible> SAL_CALL
233{
234 OSL_FAIL("should be implemented in the abrevated class");
235 return uno::Reference<XAccessible>();
236}
237
238uno::Reference<XAccessible> SAL_CALL
240{
241 return mxParent;
242}
243
244sal_Int64 SAL_CALL
246{
247 SolarMutexGuard aGuard;
249 // Use a simple but slow solution for now. Optimize later.
250 // Return -1 to indicate that this object's parent does not know about the
251 // object.
252 sal_Int64 nIndex(-1);
253
254 // Iterate over all the parent's children and search for this object.
255 if (mxParent.is())
256 {
257 uno::Reference<XAccessibleContext> xParentContext (
258 mxParent->getAccessibleContext());
259 if (xParentContext.is())
260 {
261 sal_Int64 nChildCount = xParentContext->getAccessibleChildCount();
262 for (sal_Int64 i=0; i<nChildCount; ++i)
263 {
264 uno::Reference<XAccessible> xChild (xParentContext->getAccessibleChild (i));
265 if (xChild.is() && xChild.get() == this)
266 nIndex = i;
267 }
268 }
269 }
270
271 return nIndex;
272}
273
274sal_Int16 SAL_CALL
276{
277 return maRole;
278}
279
280OUString SAL_CALL
282{
283 SolarMutexGuard aGuard;
285 if (msDescription.isEmpty())
286 {
287 OUString sDescription(createAccessibleDescription());
288
289 if (msDescription != sDescription)
290 {
291 AccessibleEventObject aEvent;
292 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
293 aEvent.Source = uno::Reference< XAccessibleContext >(this);
294 aEvent.OldValue <<= msDescription;
295 aEvent.NewValue <<= sDescription;
296
297 msDescription = sDescription;
298
300 }
301 }
302 return msDescription;
303}
304
305OUString SAL_CALL
307{
308 SolarMutexGuard aGuard;
310 if (msName.isEmpty())
311 {
312 OUString sName(createAccessibleName());
313 OSL_ENSURE(!sName.isEmpty(), "We should give always a name.");
314
315 if (msName != sName)
316 {
317 AccessibleEventObject aEvent;
318 aEvent.EventId = AccessibleEventId::NAME_CHANGED;
319 aEvent.Source = uno::Reference< XAccessibleContext >(this);
320 aEvent.OldValue <<= msName;
321 aEvent.NewValue <<= sName;
322
323 msName = sName;
324
326 }
327 }
328 return msName;
329}
330
331uno::Reference<XAccessibleRelationSet> SAL_CALL
333{
335}
336
338{
339 return 0;
340}
341
342lang::Locale SAL_CALL
344{
345 SolarMutexGuard aGuard;
347 if (mxParent.is())
348 {
349 uno::Reference<XAccessibleContext> xParentContext (
350 mxParent->getAccessibleContext());
351 if (xParentContext.is())
352 return xParentContext->getLocale ();
353 }
354
355 // No locale and no parent. Therefore throw exception to indicate this
356 // cluelessness.
357 throw IllegalAccessibleComponentStateException ();
358}
359
360 //===== XAccessibleEventBroadcaster =====================================
361
362void SAL_CALL
364 const uno::Reference<XAccessibleEventListener>& xListener)
365{
366 if (xListener.is())
367 {
368 SolarMutexGuard aGuard;
370 if (!IsDefunc())
371 {
372 if (!mnClientId)
375 }
376 }
377}
378
379void SAL_CALL
381 const uno::Reference<XAccessibleEventListener>& xListener)
382{
383 if (!xListener.is())
384 return;
385
386 SolarMutexGuard aGuard;
387 if (IsDefunc() || !mnClientId)
388 return;
389
390 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
391 if ( !nListenerCount )
392 {
393 // no listeners anymore
394 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
395 // and at least to us not firing any events anymore, in case somebody calls
396 // NotifyAccessibleEvent, again
398 mnClientId = 0;
399 }
400}
401
402 //===== XAccessibleEventListener ========================================
403
405 const lang::EventObject& rSource )
406{
407 SolarMutexGuard aGuard;
408 if (rSource.Source == mxParent)
409 dispose();
410}
411
413 const AccessibleEventObject& /* aEvent */ )
414{
415}
416
417// XServiceInfo
419{
420 return "ScAccessibleContextBase";
421}
422
423sal_Bool SAL_CALL ScAccessibleContextBase::supportsService(const OUString& sServiceName)
424{
426}
427
428uno::Sequence< OUString> SAL_CALL
430{
431 return {"com.sun.star.accessibility.Accessible",
432 "com.sun.star.accessibility.AccessibleContext"};
433}
434
435//===== XTypeProvider =======================================================
436
437uno::Sequence< uno::Type > SAL_CALL ScAccessibleContextBase::getTypes()
438{
440}
441
442uno::Sequence<sal_Int8> SAL_CALL
444{
445 return css::uno::Sequence<sal_Int8>();
446}
447
448//===== internal ============================================================
449
450OUString
452{
453 OSL_FAIL("should be implemented in the abrevated class");
454 return OUString();
455}
456
458{
459 OSL_FAIL("should be implemented in the abrevated class");
460 return OUString();
461}
462
463void ScAccessibleContextBase::CommitChange(const AccessibleEventObject& rEvent) const
464{
465 if (mnClientId)
467}
468
470{
471 AccessibleEventObject aEvent;
472 aEvent.EventId = AccessibleEventId::STATE_CHANGED;
473 aEvent.Source = uno::Reference< XAccessibleContext >(const_cast<ScAccessibleContextBase*>(this));
474 aEvent.NewValue <<= AccessibleStateType::FOCUSED;
475
477}
478
480{
481 AccessibleEventObject aEvent;
482 aEvent.EventId = AccessibleEventId::STATE_CHANGED;
483 aEvent.Source = uno::Reference< XAccessibleContext >(const_cast<ScAccessibleContextBase*>(this));
484 aEvent.OldValue <<= AccessibleStateType::FOCUSED;
485
487}
488
490{
491 OSL_FAIL("not implemented");
492 return tools::Rectangle();
493}
494
496{
497 OSL_FAIL("not implemented");
498 return tools::Rectangle();
499}
500
502{
503 if (rBHelper.bDisposed || rBHelper.bInDispose)
504 throw lang::DisposedException();
505}
506
507/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
WeakReference< XInterface > 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 css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) override
===== XInterface =====================================================
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::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
===== XTypeProvider ===================================================
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.
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Returns an implementation id.
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 void SAL_CALL release() noexcept override
virtual OUString SAL_CALL getAccessibleName() override
Return the object's current name.
virtual void SAL_CALL acquire() noexcept override
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)
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
virtual void SAL_CALL release() SAL_NOEXCEPT SAL_OVERRIDE
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
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
std::mutex m_aMutex
sal_Int32 nIndex
const char * sName
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
void dispose()
bool hasValue()
unsigned char sal_Bool