Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _SVX_ACCESSIBILITY_ACCESSIBLE_CONTEXT_BASE_HXX
30 : : #define _SVX_ACCESSIBILITY_ACCESSIBLE_CONTEXT_BASE_HXX
31 : :
32 : : #include <com/sun/star/accessibility/XAccessible.hpp>
33 : : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
34 : : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
35 : : #include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
36 : : #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
37 : : #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
38 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
39 : : #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
40 : : #include <com/sun/star/uno/Reference.hxx>
41 : : #include <com/sun/star/lang/XComponent.hpp>
42 : : #include <cppuhelper/weak.hxx>
43 : : #include <com/sun/star/lang/XServiceInfo.hpp>
44 : : #include <com/sun/star/lang/XTypeProvider.hpp>
45 : : #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
46 : : #include <com/sun/star/lang/DisposedException.hpp>
47 : : #include <osl/mutex.hxx>
48 : : #include <cppuhelper/compbase4.hxx>
49 : : #include <editeng/editengdllapi.h>
50 : :
51 : :
52 : : namespace accessibility {
53 : :
54 : 68 : struct MutexOwner {mutable ::osl::Mutex maMutex;};
55 : :
56 : : /** @descr
57 : : This base class provides an implementation of the
58 : : <type>AccessibleContext</type> service. Appart from the
59 : : <type>XXAccessible<type> and <type>XAccessibleContextContext</type>
60 : : interfaces it supports the <type>XServiceInfo</type> interface.
61 : : */
62 : : class EDITENG_DLLPUBLIC AccessibleContextBase
63 : : : public MutexOwner,
64 : : public cppu::PartialWeakComponentImplHelper4<
65 : : ::com::sun::star::accessibility::XAccessible,
66 : : ::com::sun::star::accessibility::XAccessibleContext,
67 : : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
68 : : ::com::sun::star::lang::XServiceInfo
69 : : >
70 : : {
71 : : public:
72 : :
73 : : //===== internal ========================================================
74 : :
75 : : /** The origin of the accessible name or description.
76 : : */
77 : : enum StringOrigin {
78 : : ManuallySet,
79 : : FromShape,
80 : : AutomaticallyCreated,
81 : : NotSet
82 : : };
83 : :
84 : : AccessibleContextBase (
85 : : const ::com::sun::star::uno::Reference<
86 : : ::com::sun::star::accessibility::XAccessible>& rxParent,
87 : : const sal_Int16 aRole);
88 : : virtual ~AccessibleContextBase (void);
89 : :
90 : :
91 : : /** Call all accessiblity event listeners to inform them about the
92 : : specified event.
93 : : @param aEventId
94 : : Id of the event type.
95 : : @param rNewValue
96 : : New value of the modified attribute. Pass empty structure if
97 : : not applicable.
98 : : @param rOldValue
99 : : Old value of the modified attribute. Pass empty structure if
100 : : not applicable.
101 : : */
102 : : void CommitChange (sal_Int16 aEventId,
103 : : const ::com::sun::star::uno::Any& rNewValue,
104 : : const ::com::sun::star::uno::Any& rOldValue);
105 : :
106 : : /** Set a new description and, provided that the new name differs from
107 : : the old one, broadcast an accessibility event.
108 : : @param rsDescription
109 : : The new description.
110 : : @param eDescriptionOrigin
111 : : The origin of the description. This is used to determine
112 : : whether the given description overrules the existing one. An
113 : : origin with a lower numerical value overrides one with a higher
114 : : value.
115 : : */
116 : : void SetAccessibleDescription (
117 : : const ::rtl::OUString& rsDescription,
118 : : StringOrigin eDescriptionOrigin)
119 : : throw (::com::sun::star::uno::RuntimeException);
120 : :
121 : : /** Set a new description and, provided that the new name differs from
122 : : the old one, broadcast an accessibility event.
123 : : @param rsName
124 : : The new name.
125 : : @param eNameOrigin
126 : : The origin of the name. This is used to determine whether the
127 : : given name overrules the existing one. An origin with a lower
128 : : numerical value overrides one with a higher value.
129 : : */
130 : : void SetAccessibleName (
131 : : const ::rtl::OUString& rsName,
132 : : StringOrigin eNameOrigin)
133 : : throw (::com::sun::star::uno::RuntimeException);
134 : :
135 : : /** Set the specified state (turn it on) and send events to all
136 : : listeners to inform them of the change.
137 : :
138 : : @param aState
139 : : The state to turn on.
140 : :
141 : : @return
142 : : If the specified state changed its value due to this call
143 : : <TRUE/> is returned, otherwise <FALSE/>.
144 : : */
145 : : virtual sal_Bool SetState (sal_Int16 aState);
146 : :
147 : : /** Reset the specified state (turn it off) and send events to all
148 : : listeners to inform them of the change.
149 : :
150 : : @param aState
151 : : The state to turn off.
152 : :
153 : : @return
154 : : If the specified state changed its value due to this call
155 : : <TRUE/> is returned, otherwise <FALSE/>.
156 : : */
157 : : virtual sal_Bool ResetState (sal_Int16 aState);
158 : :
159 : : /** Return the state of the specified state.
160 : :
161 : : @param aState
162 : : The state for which to return its value.
163 : :
164 : : @return
165 : : A value of <TRUE/> indicates that the state is set. A <FALSE/>
166 : : value indicates an unset state.
167 : : */
168 : : sal_Bool GetState (sal_Int16 aState);
169 : :
170 : : /** Replace the current relation set with the specified one. Send
171 : : events for relations that are not in both sets.
172 : :
173 : : @param rRelationSet
174 : : The new relation set that replaces the old one.
175 : : */
176 : : virtual void SetRelationSet (
177 : : const ::com::sun::star::uno::Reference<
178 : : ::com::sun::star::accessibility::XAccessibleRelationSet>& rxRelationSet)
179 : : throw (::com::sun::star::uno::RuntimeException);
180 : :
181 : :
182 : : //===== XAccessible =====================================================
183 : :
184 : : /// Return the XAccessibleContext.
185 : : virtual ::com::sun::star::uno::Reference<
186 : : ::com::sun::star::accessibility::XAccessibleContext> SAL_CALL
187 : : getAccessibleContext (void) throw (::com::sun::star::uno::RuntimeException);
188 : :
189 : :
190 : : //===== XAccessibleContext ==============================================
191 : :
192 : : /// Return the number of currently visible children.
193 : : virtual sal_Int32 SAL_CALL
194 : : getAccessibleChildCount (void) throw (::com::sun::star::uno::RuntimeException);
195 : :
196 : : /// Return the specified child or throw exception.
197 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
198 : : getAccessibleChild (sal_Int32 nIndex)
199 : : throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
200 : :
201 : : /// Return a reference to the parent.
202 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
203 : : getAccessibleParent (void)
204 : : throw (::com::sun::star::uno::RuntimeException);
205 : :
206 : : /// Return this objects index among the parents children.
207 : : virtual sal_Int32 SAL_CALL
208 : : getAccessibleIndexInParent (void)
209 : : throw (::com::sun::star::uno::RuntimeException);
210 : :
211 : : /// Return this object's role.
212 : : virtual sal_Int16 SAL_CALL
213 : : getAccessibleRole (void)
214 : : throw (::com::sun::star::uno::RuntimeException);
215 : :
216 : : /// Return this object's description.
217 : : virtual ::rtl::OUString SAL_CALL
218 : : getAccessibleDescription (void)
219 : : throw (::com::sun::star::uno::RuntimeException);
220 : :
221 : : /// Return the object's current name.
222 : : virtual ::rtl::OUString SAL_CALL
223 : : getAccessibleName (void)
224 : : throw (::com::sun::star::uno::RuntimeException);
225 : :
226 : : /// Return NULL to indicate that an empty relation set.
227 : : virtual ::com::sun::star::uno::Reference<
228 : : ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL
229 : : getAccessibleRelationSet (void)
230 : : throw (::com::sun::star::uno::RuntimeException);
231 : :
232 : : /// Return the set of current states.
233 : : virtual ::com::sun::star::uno::Reference<
234 : : ::com::sun::star::accessibility::XAccessibleStateSet> SAL_CALL
235 : : getAccessibleStateSet (void)
236 : : throw (::com::sun::star::uno::RuntimeException);
237 : :
238 : : /** Return the parents locale or throw exception if this object has no
239 : : parent yet/anymore.
240 : : */
241 : : virtual ::com::sun::star::lang::Locale SAL_CALL
242 : : getLocale (void)
243 : : throw (::com::sun::star::uno::RuntimeException,
244 : : ::com::sun::star::accessibility::IllegalAccessibleComponentStateException);
245 : :
246 : : //===== XComponent ========================================================
247 : :
248 : : using WeakComponentImplHelperBase::addEventListener;
249 : : using WeakComponentImplHelperBase::removeEventListener;
250 : :
251 : : //===== XAccessibleEventBroadcaster ========================================
252 : :
253 : : virtual void SAL_CALL
254 : : addEventListener (
255 : : const ::com::sun::star::uno::Reference<
256 : : ::com::sun::star::accessibility::XAccessibleEventListener >& xListener)
257 : : throw (::com::sun::star::uno::RuntimeException);
258 : :
259 : : virtual void SAL_CALL
260 : : removeEventListener (
261 : : const ::com::sun::star::uno::Reference<
262 : : ::com::sun::star::accessibility::XAccessibleEventListener >& xListener)
263 : : throw (::com::sun::star::uno::RuntimeException);
264 : :
265 : :
266 : : //===== XServiceInfo ====================================================
267 : :
268 : : /** Returns an identifier for the implementation of this object.
269 : : */
270 : : virtual ::rtl::OUString SAL_CALL
271 : : getImplementationName (void)
272 : : throw (::com::sun::star::uno::RuntimeException);
273 : :
274 : : /** Return whether the specified service is supported by this class.
275 : : */
276 : : virtual sal_Bool SAL_CALL
277 : : supportsService (const ::rtl::OUString& sServiceName)
278 : : throw (::com::sun::star::uno::RuntimeException);
279 : :
280 : : /** Returns a list of all supported services. In this case that is just
281 : : the AccessibleContext service.
282 : : */
283 : : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
284 : : getSupportedServiceNames (void)
285 : : throw (::com::sun::star::uno::RuntimeException);
286 : :
287 : :
288 : : //===== XTypeProvider ===================================================
289 : :
290 : : /** Returns a sequence of all supported interfaces.
291 : : */
292 : : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> SAL_CALL
293 : : getTypes (void)
294 : : throw (::com::sun::star::uno::RuntimeException);
295 : :
296 : : /** Returns a implementation id.
297 : : */
298 : : virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL
299 : : getImplementationId (void)
300 : : throw (::com::sun::star::uno::RuntimeException);
301 : :
302 : : protected:
303 : : /** The state set.
304 : : */
305 : : ::com::sun::star::uno::Reference<
306 : : ::com::sun::star::accessibility::XAccessibleStateSet> mxStateSet;
307 : :
308 : : /** The relation set. Relations can be set or removed by calling the
309 : : <member>AddRelation</member> and <member>RemoveRelation</member> methods.
310 : : */
311 : : ::com::sun::star::uno::Reference<
312 : : ::com::sun::star::accessibility::XAccessibleRelationSet> mxRelationSet;
313 : :
314 : : // This method is called from the component helper base class while disposing.
315 : : virtual void SAL_CALL disposing (void);
316 : :
317 : : /** Create the accessible object's name. This method may be called more
318 : : than once for a single object.
319 : : @return
320 : : The returned string is a unique (among the accessible object's
321 : : siblings) name.
322 : : */
323 : : virtual ::rtl::OUString CreateAccessibleName (void)
324 : : throw (::com::sun::star::uno::RuntimeException);
325 : :
326 : : /** Create the accessible object's descriptive string. May be called
327 : : more than once.
328 : : @return
329 : : Descriptive string. Not necessarily unique.
330 : : */
331 : : virtual ::rtl::OUString
332 : : CreateAccessibleDescription (void)
333 : : throw (::com::sun::star::uno::RuntimeException);
334 : :
335 : : void FireEvent (const ::com::sun::star::accessibility::AccessibleEventObject& aEvent);
336 : :
337 : : /** Check whether or not the object has been disposed (or is in the
338 : : state of beeing disposed). If that is the case then
339 : : DisposedException is thrown to inform the (indirect) caller of the
340 : : foul deed.
341 : : */
342 : : void ThrowIfDisposed (void)
343 : : throw (::com::sun::star::lang::DisposedException);
344 : :
345 : : /** Check whether or not the object has been disposed (or is in the
346 : : state of beeing disposed).
347 : :
348 : : @return TRUE, if the object is disposed or in the course
349 : : of being disposed. Otherwise, FALSE is returned.
350 : : */
351 : : sal_Bool IsDisposed (void);
352 : :
353 : : /** sets the role as returned by XaccessibleContext::getAccessibleRole
354 : :
355 : : <p>Caution: This is only to be used in the construction phase (means within
356 : : the ctor or late ctor), <em>never</em> when the object is still alive and part
357 : : of an Accessibility hierarchy.</p>
358 : : */
359 : : void SetAccessibleRole( sal_Int16 _nRole );
360 : :
361 : : private:
362 : : /// Reference to the parent object.
363 : : ::com::sun::star::uno::Reference<
364 : : ::com::sun::star::accessibility::XAccessible> mxParent;
365 : :
366 : : /** Description of this object. This is not a constant because it can
367 : : be set from the outside. Furthermore, it changes according the the
368 : : draw page's display mode.
369 : : */
370 : : ::rtl::OUString msDescription;
371 : :
372 : : /** The origin of the description is used to determine whether new
373 : : descriptions given to the SetAccessibleDescription is ignored or
374 : : whether that replaces the old value in msDescription.
375 : : */
376 : : StringOrigin meDescriptionOrigin;
377 : :
378 : : /** Name of this object. It changes according the the draw page's
379 : : display mode.
380 : : */
381 : : ::rtl::OUString msName;
382 : :
383 : : /** The origin of the name is used to determine whether new
384 : : name given to the SetAccessibleName is ignored or
385 : : whether that replaces the old value in msName.
386 : : */
387 : : StringOrigin meNameOrigin;
388 : :
389 : : /** client id in the AccessibleEventNotifier queue
390 : : */
391 : : sal_uInt32 mnClientId;
392 : :
393 : : /** This is the role of this object.
394 : : */
395 : : sal_Int16 maRole;
396 : : };
397 : :
398 : : }
399 : :
400 : : #endif
401 : :
402 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|