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 .
22 #include <com/sun/star/accessibility/XAccessible.hpp>
23 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
24 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
25 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <cppuhelper/interfacecontainer.h>
30 #include <svl/lstner.hxx>
31 #include <cppuhelper/basemutex.hxx>
32 #include <cppuhelper/compbase.hxx>
33 #include <cppuhelper/implbase1.hxx>
34 #include <rtl/ref.hxx>
36 namespace tools
{ class Rectangle
; }
37 class AbsoluteScreenPixelRectangle
;
40 This base class provides an implementation of the
41 <code>AccessibleContext</code> service.
43 typedef cppu::WeakComponentImplHelper
<
44 css::accessibility::XAccessible
,
45 css::accessibility::XAccessibleComponent
,
46 css::accessibility::XAccessibleContext
,
47 css::accessibility::XAccessibleEventBroadcaster
,
48 css::lang::XServiceInfo
49 > ScAccessibleContextBaseWeakImpl
;
51 class ScAccessibleContextBase
52 : public cppu::BaseMutex
,
53 public ScAccessibleContextBaseWeakImpl
,
56 class ScAccessibleContextBaseEventListener
;
59 //===== internal ========================================================
60 ScAccessibleContextBase(
61 css::uno::Reference
<css::accessibility::XAccessible
> xParent
,
62 const sal_Int16 aRole
);
65 virtual void SAL_CALL
disposing() override
;
67 virtual ~ScAccessibleContextBase() override
;
70 /// @throws css::uno::RuntimeException
73 /// @throws css::uno::RuntimeException
74 virtual bool isVisible();
76 ///===== SfxListener =====================================================
78 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
80 ///===== XAccessible =====================================================
82 /// Return the XAccessibleContext.
83 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
84 getAccessibleContext() override
;
86 ///===== XAccessibleComponent ============================================
88 virtual sal_Bool SAL_CALL
containsPoint(
89 const css::awt::Point
& rPoint
) override
;
91 virtual css::uno::Reference
< css::accessibility::XAccessible
>
92 SAL_CALL
getAccessibleAtPoint(
93 const css::awt::Point
& rPoint
) override
;
95 virtual css::awt::Rectangle SAL_CALL
getBounds( ) override
;
97 virtual css::awt::Point SAL_CALL
getLocation( ) override
;
99 virtual css::awt::Point SAL_CALL
getLocationOnScreen( ) override
;
101 virtual css::awt::Size SAL_CALL
getSize( ) override
;
103 virtual void SAL_CALL
grabFocus( ) override
;
105 virtual sal_Int32 SAL_CALL
getForeground( ) override
;
107 virtual sal_Int32 SAL_CALL
getBackground( ) override
;
109 ///===== XAccessibleContext ==============================================
111 /// Return the number of currently visible children.
112 virtual sal_Int64 SAL_CALL
getAccessibleChildCount() override
;
114 /// Return the specified child or NULL if index is invalid.
115 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
116 getAccessibleChild(sal_Int64 nIndex
) override
;
118 /// Return a reference to the parent.
119 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
120 getAccessibleParent() override
;
122 /// Return this objects index among the parents children.
123 virtual sal_Int64 SAL_CALL
124 getAccessibleIndexInParent() override
;
126 /// Return this object's role.
127 virtual sal_Int16 SAL_CALL
128 getAccessibleRole() override
;
130 /// Return this object's description.
131 virtual OUString SAL_CALL
132 getAccessibleDescription() override
;
134 /// Return the object's current name.
135 virtual OUString SAL_CALL
136 getAccessibleName() override
;
138 /// Return NULL to indicate that an empty relation set.
139 virtual css::uno::Reference
<css::accessibility::XAccessibleRelationSet
> SAL_CALL
140 getAccessibleRelationSet() override
;
142 /// Return the set of current states.
143 virtual sal_Int64 SAL_CALL
getAccessibleStateSet() override
;
145 /** Return the parents locale or throw exception if this object has no
148 virtual css::lang::Locale SAL_CALL
149 getLocale() override
;
151 ///===== XAccessibleEventBroadcaster =====================================
153 /** Add listener that is informed of future changes of name,
154 description and so on events.
156 virtual void SAL_CALL
157 addAccessibleEventListener(
158 const css::uno::Reference
<css::accessibility::XAccessibleEventListener
>& xListener
) override
;
160 // Remove an existing event listener.
161 virtual void SAL_CALL
162 removeAccessibleEventListener(
163 const css::uno::Reference
<css::accessibility::XAccessibleEventListener
>& xListener
) override
;
165 ///===== XServiceInfo ====================================================
167 /** Returns an identifier for the implementation of this object.
169 virtual OUString SAL_CALL
170 getImplementationName() override
;
172 /** Return whether the specified service is supported by this class.
174 virtual sal_Bool SAL_CALL
175 supportsService(const OUString
& sServiceName
) override
;
177 /** Returns a list of all supported services. In this case that is just
178 the AccessibleContext and Accessible service.
180 virtual css::uno::Sequence
< OUString
> SAL_CALL
181 getSupportedServiceNames() override
;
184 /// Return this object's description.
186 /// @throws css::uno::RuntimeException
188 createAccessibleDescription();
190 /// Return the object's current name.
192 /// @throws css::uno::RuntimeException
194 createAccessibleName();
196 /// Return the object's current bounding box relative to the desktop.
198 /// @throws css::uno::RuntimeException
199 virtual AbsoluteScreenPixelRectangle
GetBoundingBoxOnScreen() const;
201 /// Return the object's current bounding box relative to the parent object.
203 /// @throws css::uno::RuntimeException
204 virtual tools::Rectangle
GetBoundingBox() const;
207 /// Calls all Listener to tell they the change.
209 CommitChange(const css::accessibility::AccessibleEventObject
& rEvent
) const;
211 /// Use this method to set initial Name without notification
212 void SetName(const OUString
& rName
) { msName
= rName
; }
214 /// Use this method to set initial Description without notification
215 void SetDescription(const OUString
& rDesc
) { msDescription
= rDesc
; }
217 void SetParent(const css::uno::Reference
<css::accessibility::XAccessible
>& rParent
) { mxParent
= rParent
; }
220 /// Calls all FocusListener to tell they that the focus is gained.
221 void CommitFocusGained() const;
223 /// Calls all FocusListener to tell they that the focus is lost.
224 void CommitFocusLost() const;
226 bool IsDefunc() const { return rBHelper
.bDisposed
; }
228 /// @throws css::lang::DisposedException
229 void IsObjectValid() const;
231 /// Reference to the parent object.
232 css::uno::Reference
<css::accessibility::XAccessible
> mxParent
;
235 /** Description of this object. This is not a constant because it can
236 be set from the outside. Furthermore, it changes according to the
237 draw page's display mode.
239 OUString msDescription
;
241 /** Name of this object. It changes according the draw page's
246 /// client id in the AccessibleEventNotifier queue
247 sal_uInt32 mnClientId
;
249 /** This is the role of this object.
253 rtl::Reference
<ScAccessibleContextBaseEventListener
> mxEventListener
;
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */