nss: upgrade to release 3.73
[LibreOffice.git] / include / editeng / AccessibleContextBase.hxx
blob183c097fed0ee121998e397f5a1612355235455b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <osl/mutex.hxx>
29 #include <cppuhelper/compbase.hxx>
30 #include <editeng/editengdllapi.h>
32 namespace com::sun::star::accessibility { class XAccessibleStateSet; }
33 namespace com::sun::star::accessibility { class XAccessibleRelationSet; }
34 namespace com::sun::star::accessibility { struct AccessibleEventObject; }
36 namespace accessibility {
38 struct MutexOwner {mutable ::osl::Mutex maMutex;};
40 /** @descr
41 This base class provides an implementation of the
42 AccessibleContext service. Apart from the
43 <type>XXAccessible<type> and XAccessibleContextContext
44 interfaces it supports the XServiceInfo interface.
46 class EDITENG_DLLPUBLIC AccessibleContextBase
47 : public MutexOwner,
48 public cppu::WeakComponentImplHelper<
49 css::accessibility::XAccessible,
50 css::accessibility::XAccessibleContext,
51 css::accessibility::XAccessibleEventBroadcaster,
52 css::lang::XServiceInfo
55 public:
57 //===== internal ========================================================
59 /** The origin of the accessible name or description.
61 enum StringOrigin {
62 ManuallySet,
63 FromShape,
64 AutomaticallyCreated,
65 NotSet
68 AccessibleContextBase (
69 const css::uno::Reference< css::accessibility::XAccessible>& rxParent,
70 const sal_Int16 aRole);
71 virtual ~AccessibleContextBase() override;
74 /** Call all accessibility event listeners to inform them about the
75 specified event.
76 @param aEventId
77 Id of the event type.
78 @param rNewValue
79 New value of the modified attribute. Pass empty structure if
80 not applicable.
81 @param rOldValue
82 Old value of the modified attribute. Pass empty structure if
83 not applicable.
85 void CommitChange (sal_Int16 aEventId,
86 const css::uno::Any& rNewValue,
87 const css::uno::Any& rOldValue);
89 /** Set a new description and, provided that the new name differs from
90 the old one, broadcast an accessibility event.
91 @param rsDescription
92 The new description.
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
97 value.
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.
106 @param rsName
107 The new name.
108 @param eNameOrigin
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.
121 @param aState
122 The state to turn on.
124 @return
125 If the specified state changed its value due to this call
126 <TRUE/> is returned, otherwise <FALSE/>.
128 virtual bool SetState (sal_Int16 aState);
130 /** Reset the specified state (turn it off) and send events to all
131 listeners to inform them of the change.
133 @param aState
134 The state to turn off.
136 @return
137 If the specified state changed its value due to this call
138 <TRUE/> is returned, otherwise <FALSE/>.
140 virtual bool ResetState (sal_Int16 aState);
142 /** Return the state of the specified state.
144 @param aState
145 The state for which to return its value.
147 @return
148 A value of <TRUE/> indicates that the state is set. A <FALSE/>
149 value indicates an unset state.
151 bool GetState (sal_Int16 aState);
153 /** Replace the current relation set with the specified one. Send
154 events for relations that are not in both sets.
156 @param rRelationSet
157 The new relation set that replaces the old one.
159 @throws css::uno::RuntimeException
161 void SetRelationSet (
162 const css::uno::Reference< css::accessibility::XAccessibleRelationSet>& 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_Int32 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_Int32 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_Int32 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 css::uno::Reference< css::accessibility::XAccessibleStateSet> SAL_CALL
208 getAccessibleStateSet() override;
210 /** Return the parents locale or throw exception if this object has no
211 parent yet/anymore.
213 virtual css::lang::Locale SAL_CALL
214 getLocale() override;
216 //===== XAccessibleEventBroadcaster ========================================
218 virtual void SAL_CALL
219 addAccessibleEventListener (
220 const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener) override;
222 virtual void SAL_CALL
223 removeAccessibleEventListener (
224 const css::uno::Reference< css::accessibility::XAccessibleEventListener >& xListener) override;
227 //===== XServiceInfo ====================================================
229 /** Returns an identifier for the implementation of this object.
231 virtual OUString SAL_CALL
232 getImplementationName() override;
234 /** Return whether the specified service is supported by this class.
236 virtual sal_Bool SAL_CALL
237 supportsService (const OUString& sServiceName) override;
239 /** Returns a list of all supported services. In this case that is just
240 the AccessibleContext service.
242 virtual css::uno::Sequence< OUString> SAL_CALL
243 getSupportedServiceNames() override;
246 //===== XTypeProvider ===================================================
248 /** Returns an implementation id.
250 virtual css::uno::Sequence<sal_Int8> SAL_CALL
251 getImplementationId() override;
253 /** Check whether or not the object has been disposed (or is in the
254 state of being disposed).
256 @return TRUE, if the object is disposed or in the course
257 of being disposed. Otherwise, FALSE is returned.
259 bool IsDisposed() const;
261 protected:
262 /** The state set.
264 css::uno::Reference< css::accessibility::XAccessibleStateSet> mxStateSet;
266 /** The relation set. Relations can be set or removed by calling the
267 <member>AddRelation</member> and <member>RemoveRelation</member> methods.
269 css::uno::Reference< css::accessibility::XAccessibleRelationSet> mxRelationSet;
271 // This method is called from the component helper base class while disposing.
272 virtual void SAL_CALL disposing() override;
274 /** Create the accessible object's name. This method may be called more
275 than once for a single object.
276 @return
277 The returned string is a unique (among the accessible object's
278 siblings) name.
279 @throws css::uno::RuntimeException
281 virtual OUString CreateAccessibleName();
283 void FireEvent (const css::accessibility::AccessibleEventObject& aEvent);
285 /** Check whether or not the object has been disposed (or is in the
286 state of being disposed). If that is the case then
287 DisposedException is thrown to inform the (indirect) caller of the
288 foul deed.
289 @throws css::lang::DisposedException
291 void ThrowIfDisposed();
293 /** sets the role as returned by XaccessibleContext::getAccessibleRole
295 <p>Caution: This is only to be used in the construction phase (means within
296 the ctor or late ctor), <em>never</em> when the object is still alive and part
297 of an Accessibility hierarchy.</p>
299 void SetAccessibleRole( sal_Int16 _nRole );
301 private:
302 /// Reference to the parent object.
303 css::uno::Reference< css::accessibility::XAccessible> mxParent;
305 /** Description of this object. This is not a constant because it can
306 be set from the outside. Furthermore, it changes according to the
307 draw page's display mode.
309 OUString msDescription;
311 /** The origin of the description is used to determine whether new
312 descriptions given to the SetAccessibleDescription is ignored or
313 whether that replaces the old value in msDescription.
315 StringOrigin meDescriptionOrigin;
317 /** Name of this object. It changes according the draw page's
318 display mode.
320 OUString msName;
322 /** The origin of the name is used to determine whether new
323 name given to the SetAccessibleName is ignored or
324 whether that replaces the old value in msName.
326 StringOrigin meNameOrigin;
328 /** client id in the AccessibleEventNotifier queue
330 sal_uInt32 mnClientId;
332 /** This is the role of this object.
334 sal_Int16 maRole;
339 #endif
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */