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 .
20 #ifndef INCLUDED_EDITENG_ACCESSIBLECONTEXTBASE_HXX
21 #define INCLUDED_EDITENG_ACCESSIBLECONTEXTBASE_HXX
23 #include <com/sun/star/accessibility/XAccessible.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/compbase.hxx>
29 #include <cppuhelper/basemutex.hxx>
30 #include <editeng/editengdllapi.h>
31 #include <rtl/ref.hxx>
33 namespace com::sun::star::accessibility
{ class XAccessibleRelationSet
; }
34 namespace com::sun::star::accessibility
{ struct AccessibleEventObject
; }
35 namespace utl
{ class AccessibleRelationSetHelper
; }
37 namespace accessibility
{
40 This base class provides an implementation of the
41 AccessibleContext service. Apart from the
42 <type>XXAccessible<type> and XAccessibleContextContext
43 interfaces it supports the XServiceInfo interface.
45 class EDITENG_DLLPUBLIC AccessibleContextBase
46 : public cppu::BaseMutex
,
47 public cppu::WeakComponentImplHelper
<
48 css::accessibility::XAccessible
,
49 css::accessibility::XAccessibleContext
,
50 css::accessibility::XAccessibleEventBroadcaster
,
51 css::lang::XServiceInfo
56 //===== internal ========================================================
58 /** The origin of the accessible name or description.
67 AccessibleContextBase (
68 css::uno::Reference
< css::accessibility::XAccessible
> xParent
,
69 const sal_Int16 aRole
);
70 virtual ~AccessibleContextBase() override
;
73 /** Call all accessibility event listeners to inform them about the
78 New value of the modified attribute. Pass empty structure if
81 Old value of the modified attribute. Pass empty structure if
84 void CommitChange (sal_Int16 aEventId
,
85 const css::uno::Any
& rNewValue
,
86 const css::uno::Any
& rOldValue
,
87 sal_Int32 nValueIndex
);
89 /** Set a new description and, provided that the new name differs from
90 the old one, broadcast an accessibility event.
93 @param eDescriptionOrigin
94 The origin of the description. This is used to determine
95 whether the given description overrules the existing one. An
96 origin with a lower numerical value overrides one with a higher
98 @throws css::uno::RuntimeException
100 void SetAccessibleDescription (
101 const OUString
& rsDescription
,
102 StringOrigin eDescriptionOrigin
);
104 /** Set a new description and, provided that the new name differs from
105 the old one, broadcast an accessibility event.
109 The origin of the name. This is used to determine whether the
110 given name overrules the existing one. An origin with a lower
111 numerical value overrides one with a higher value.
112 @throws css::uno::RuntimeException
114 void SetAccessibleName (
115 const OUString
& rsName
,
116 StringOrigin eNameOrigin
);
118 /** Set the specified state (turn it on) and send events to all
119 listeners to inform them of the change.
122 The state to turn on.
125 If the specified state changed its value due to this call
126 <TRUE/> is returned, otherwise <FALSE/>.
128 virtual bool SetState (sal_Int64 aState
);
130 /** Reset the specified state (turn it off) and send events to all
131 listeners to inform them of the change.
134 The state to turn off.
137 If the specified state changed its value due to this call
138 <TRUE/> is returned, otherwise <FALSE/>.
140 virtual bool ResetState (sal_Int64 aState
);
142 /** Return the state of the specified state.
145 The state for which to return its value.
148 A value of <TRUE/> indicates that the state is set. A <FALSE/>
149 value indicates an unset state.
151 bool GetState (sal_Int64 aState
);
153 /** Replace the current relation set with the specified one. Send
154 events for relations that are not in both sets.
157 The new relation set that replaces the old one.
159 @throws css::uno::RuntimeException
161 void SetRelationSet (
162 const rtl::Reference
< utl::AccessibleRelationSetHelper
>& rxRelationSet
);
165 //===== XAccessible =====================================================
167 /// Return the XAccessibleContext.
168 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
169 getAccessibleContext() override
;
172 //===== XAccessibleContext ==============================================
174 /// Return the number of currently visible children.
175 virtual sal_Int64 SAL_CALL
176 getAccessibleChildCount() override
;
178 /// Return the specified child or throw exception.
179 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
180 getAccessibleChild (sal_Int64 nIndex
) override
;
182 /// Return a reference to the parent.
183 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
184 getAccessibleParent() override
;
186 /// Return this objects index among the parents children.
187 virtual sal_Int64 SAL_CALL
188 getAccessibleIndexInParent() override
;
190 /// Return this object's role.
191 virtual sal_Int16 SAL_CALL
192 getAccessibleRole() override
;
194 /// Return this object's description.
195 virtual OUString SAL_CALL
196 getAccessibleDescription() override
;
198 /// Return the object's current name.
199 virtual OUString SAL_CALL
200 getAccessibleName() override
;
202 /// Return NULL to indicate that an empty relation set.
203 virtual css::uno::Reference
< css::accessibility::XAccessibleRelationSet
> SAL_CALL
204 getAccessibleRelationSet() override
;
206 /// Return the set of current states.
207 virtual sal_Int64 SAL_CALL
getAccessibleStateSet() override
;
209 /** Return the parents locale or throw exception if this object has no
212 virtual css::lang::Locale SAL_CALL
213 getLocale() override
;
215 //===== XAccessibleEventBroadcaster ========================================
217 virtual void SAL_CALL
218 addAccessibleEventListener (
219 const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
) override
;
221 virtual void SAL_CALL
222 removeAccessibleEventListener (
223 const css::uno::Reference
< css::accessibility::XAccessibleEventListener
>& xListener
) override
;
226 //===== XServiceInfo ====================================================
228 /** Returns an identifier for the implementation of this object.
230 virtual OUString SAL_CALL
231 getImplementationName() override
;
233 /** Return whether the specified service is supported by this class.
235 virtual sal_Bool SAL_CALL
236 supportsService (const OUString
& sServiceName
) override final
;
238 /** Returns a list of all supported services. In this case that is just
239 the AccessibleContext service.
241 virtual css::uno::Sequence
< OUString
> SAL_CALL
242 getSupportedServiceNames() override
;
245 //===== XTypeProvider ===================================================
247 /** Returns an implementation id.
249 virtual css::uno::Sequence
<sal_Int8
> SAL_CALL
250 getImplementationId() override
;
252 /** Check whether or not the object has been disposed (or is in the
253 state of being disposed).
255 @return TRUE, if the object is disposed or in the course
256 of being disposed. Otherwise, FALSE is returned.
258 bool IsDisposed() const;
263 sal_Int64 mnStateSet
;
265 /** The relation set. Relations can be set or removed by calling the
266 <member>AddRelation</member> and <member>RemoveRelation</member> methods.
268 rtl::Reference
<utl::AccessibleRelationSetHelper
> mxRelationSet
;
270 // This method is called from the component helper base class while disposing.
271 virtual void SAL_CALL
disposing() override
;
273 /** Create the accessible object's name. This method may be called more
274 than once for a single object.
276 The returned string is a unique (among the accessible object's
278 @throws css::uno::RuntimeException
280 virtual OUString
CreateAccessibleName();
282 void FireEvent (const css::accessibility::AccessibleEventObject
& aEvent
);
284 /** Check whether or not the object has been disposed (or is in the
285 state of being disposed). If that is the case then
286 DisposedException is thrown to inform the (indirect) caller of the
288 @throws css::lang::DisposedException
290 void ThrowIfDisposed();
292 /** sets the role as returned by XaccessibleContext::getAccessibleRole
294 <p>Caution: This is only to be used in the construction phase (means within
295 the ctor or late ctor), <em>never</em> when the object is still alive and part
296 of an Accessibility hierarchy.</p>
298 void SetAccessibleRole( sal_Int16 _nRole
);
301 /// Reference to the parent object.
302 css::uno::Reference
< css::accessibility::XAccessible
> mxParent
;
304 /** Description of this object. This is not a constant because it can
305 be set from the outside. Furthermore, it changes according to the
306 draw page's display mode.
308 OUString msDescription
;
310 /** The origin of the description is used to determine whether new
311 descriptions given to the SetAccessibleDescription is ignored or
312 whether that replaces the old value in msDescription.
314 StringOrigin meDescriptionOrigin
;
316 /** Name of this object. It changes according the draw page's
321 /** The origin of the name is used to determine whether new
322 name given to the SetAccessibleName is ignored or
323 whether that replaces the old value in msName.
325 StringOrigin meNameOrigin
;
327 /** client id in the AccessibleEventNotifier queue
329 sal_uInt32 mnClientId
;
331 /** This is the role of this object.
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */