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 .
21 #ifndef INCLUDED_SVX_ACCESSIBLESHAPE_HXX
22 #define INCLUDED_SVX_ACCESSIBLESHAPE_HXX
24 #include <editeng/AccessibleContextBase.hxx>
25 #include <editeng/AccessibleComponentBase.hxx>
26 #include <svx/IAccessibleViewForwarderListener.hxx>
27 #include <com/sun/star/document/XEventListener.hpp>
28 #include <com/sun/star/accessibility/XAccessible.hpp>
29 #include <com/sun/star/accessibility/XAccessibleExtendedComponent.hpp>
30 #include <com/sun/star/accessibility/AccessibleRole.hpp>
31 #include <com/sun/star/drawing/XShape.hpp>
32 #include <com/sun/star/lang/XEventListener.hpp>
33 #include <com/sun/star/lang/XUnoTunnel.hpp>
34 #include <svx/AccessibleTextHelper.hxx>
35 #include <svx/svxdllapi.h>
36 #include <svx/ChildrenManager.hxx>
40 namespace accessibility
{
42 class AccessibleShapeInfo
;
43 class AccessibleShapeTreeInfo
;
44 class IAccessibleParent
;
46 /** This base class provides a base implementation for all shapes. For more
47 detailed documentation about the methods refer to the descriptions of
48 the implemented interfaces. These are, among others,
49 XAccessible, <type>XAccessibleContext</type>,
50 XAccessibleComponent and
51 XAccessibleExtendedComponent.
53 <p>The children of a shape can stem from two sources which, in case of
54 SVX and SD shapes, are mutually exclusive. This implementation,
55 however, handles both simultaniously to cope with future extensions or
56 shapes from other projects.
58 <li>If this shape is a group shape, i.e. a
59 SvxShapeGroup or a <type>Svx3DSceneObject</type>, it
60 can have nested shapes.</li>
61 <li>If this shape is a descendant from SvxShapeText
62 then the text paragraphs are its children.</li>
66 <p>Accessible shapes do not listen for disposing() calls of the UNO
67 shapes they make accessible. This is the task of their owner, usually a
68 container, who can then call dispose() at the accessible object.</p>
70 class SVX_DLLPUBLIC AccessibleShape
71 : public AccessibleContextBase
,
72 public AccessibleComponentBase
,
73 public IAccessibleViewForwarderListener
,
74 public ::com::sun::star::document::XEventListener
,
75 public ::com::sun::star::lang::XUnoTunnel
78 //===== internal ========================================================
80 /** Create a new accessible object that makes the given shape accessible.
82 This object contains all information specific to the new
83 accessible shape. That are e.g. the shape to be made accessible
84 and the accessible object that will become the parent of the new
87 Bundel of information passed to this shape and all of its desendants.
89 Always call the <member>init</member> method after creating a
90 new accessible shape. This is one way to overcome the potential
91 problem of registering the new object with e.g. event
92 broadcasters. That would delete the new object if a broadcaster
93 would not keep a strong reference to the new object.
96 const AccessibleShapeInfo
& rShapeInfo
,
97 const AccessibleShapeTreeInfo
& rShapeTreeInfo
);
99 /** The destructor releases its children manager and text engine if
100 still existent. These are responsible to send appropriate events.
102 virtual ~AccessibleShape (void);
104 /** Initialize a new shape. See the documentation of the constructor
105 for the reason of this method's existence.
107 virtual void Init (void);
109 /** Compare two accessible shapes using object identity
111 This is the second operand.
113 Returns true if both shapes are the same object.
115 virtual bool operator== (const AccessibleShape
& rShape
);
117 /** Set the specified state. If the state is <const>FOCUSED</const>
118 then, additionally to the inherited functionality, the focus
119 listeners registered with the XAccessibleComponent
120 interface are called (if that state really changes).
123 The state to turn on.
126 The returned flag indicates whether the specified state has been
127 changed (<TRUE/>), i.e. it has formerly not been set.
129 virtual sal_Bool
SetState (sal_Int16 aState
);
131 /** Reset the specified state. If the state is <const>FOCUSED</const>
132 then, additionally to the inherited functionality, the focus
133 listeners registered with the XAccessibleComponent
134 interface are called (if that state really changes).
137 The state to turn off.
140 The returned flag indicates whether the specified state has been
141 changed (<TRUE/>), i.e. it has formerly been set.
143 virtual sal_Bool
ResetState (sal_Int16 aState
);
145 /** Return the state of the specified state. Take the
146 <const>FOCUSED</const> state from the accessible edit engine.
149 The state for which to return its value.
151 A value of <TRUE/> indicates that the state is set. A <FALSE/>
152 value indicates an unset state or the inability to access the
153 entity that manages the state set.
156 sal_Bool
GetState (sal_Int16 aState
);
159 //===== XAccessibleContext ==============================================
161 /// Return the number of currently visible children.
162 virtual sal_Int32 SAL_CALL
163 getAccessibleChildCount (void)
164 throw (::com::sun::star::uno::RuntimeException
);
166 /** Return the specified child.
168 Index of the requested child.
170 Reference of the requested child which is the accessible object
172 @raises IndexOutOfBoundsException
173 Throws an exception if the index is not valid.
175 virtual ::com::sun::star::uno::Reference
<
176 ::com::sun::star::accessibility::XAccessible
> SAL_CALL
177 getAccessibleChild (sal_Int32 nIndex
)
178 throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
181 /// Return the set of current states.
182 virtual ::com::sun::star::uno::Reference
<
183 ::com::sun::star::accessibility::XAccessibleStateSet
> SAL_CALL
184 getAccessibleStateSet (void)
185 throw (::com::sun::star::uno::RuntimeException
);
187 /// Return this objects index among the parents children.
188 virtual sal_Int32 SAL_CALL
189 getAccessibleIndexInParent (void)
190 throw (::com::sun::star::uno::RuntimeException
);
192 //===== XAccessibleComponent ============================================
194 virtual ::com::sun::star::uno::Reference
<
195 ::com::sun::star::accessibility::XAccessible
> SAL_CALL
196 getAccessibleAtPoint (const ::com::sun::star::awt::Point
& aPoint
)
197 throw (::com::sun::star::uno::RuntimeException
);
199 virtual ::com::sun::star::awt::Rectangle SAL_CALL
getBounds (void)
200 throw (::com::sun::star::uno::RuntimeException
);
202 virtual ::com::sun::star::awt::Point SAL_CALL
getLocation (void)
203 throw (::com::sun::star::uno::RuntimeException
);
205 virtual ::com::sun::star::awt::Point SAL_CALL
getLocationOnScreen (void)
206 throw (::com::sun::star::uno::RuntimeException
);
208 virtual ::com::sun::star::awt::Size SAL_CALL
getSize (void)
209 throw (::com::sun::star::uno::RuntimeException
);
211 virtual sal_Int32 SAL_CALL
getForeground (void)
212 throw (::com::sun::star::uno::RuntimeException
);
214 virtual sal_Int32 SAL_CALL
getBackground (void)
215 throw (::com::sun::star::uno::RuntimeException
);
217 //===== XAccessibleEventBroadcaster =====================================
219 /** This call is forwarded to a) the base class and b) to the
220 accessible edit engine if it is present.
223 This listener is informed about accessibility events.
225 virtual void SAL_CALL
226 addAccessibleEventListener (
227 const ::com::sun::star::uno::Reference
<
228 ::com::sun::star::accessibility::XAccessibleEventListener
>& rxListener
)
229 throw (::com::sun::star::uno::RuntimeException
);
231 /** This call is forwarded to a) the base class and b) to the
232 accessible edit engine if it is present.
235 This listener will not be informed about accessibility events
238 virtual void SAL_CALL
239 removeAccessibleEventListener (
240 const ::com::sun::star::uno::Reference
<
241 ::com::sun::star::accessibility::XAccessibleEventListener
>& rxListener
)
242 throw (::com::sun::star::uno::RuntimeException
);
245 //===== XInterface ======================================================
247 virtual com::sun::star::uno::Any SAL_CALL
248 queryInterface (const com::sun::star::uno::Type
& rType
)
249 throw (::com::sun::star::uno::RuntimeException
);
251 virtual void SAL_CALL
255 virtual void SAL_CALL
260 //===== XServiceInfo ====================================================
262 /** Returns an identifier for the implementation of this object.
264 virtual OUString SAL_CALL
265 getImplementationName (void)
266 throw (::com::sun::star::uno::RuntimeException
);
268 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
269 getSupportedServiceNames (void)
270 throw (::com::sun::star::uno::RuntimeException
);
272 //===== XTypeProvider ===================================================
274 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
276 throw (::com::sun::star::uno::RuntimeException
);
278 //===== IAccessibleViewForwarderListener ================================
279 virtual void ViewForwarderChanged (ChangeType aChangeType
,
280 const IAccessibleViewForwarder
* pViewForwarder
);
282 //===== lang::XEventListener ============================================
284 /** Listen for disposing events of the model. The accessible shape
285 remains functional when this happens.
287 virtual void SAL_CALL
288 disposing (const ::com::sun::star::lang::EventObject
& Source
)
289 throw (::com::sun::star::uno::RuntimeException
);
291 //===== document::XEventListener ========================================
293 virtual void SAL_CALL
294 notifyEvent (const ::com::sun::star::document::EventObject
& rEventObject
)
295 throw (::com::sun::star::uno::RuntimeException
);
298 //===== XUnoTunnel ========================================================
300 static const ::com::sun::star::uno::Sequence
< sal_Int8
>& getUnoTunnelImplementationId() throw();
301 static AccessibleShape
* getImplementation( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxIFace
) throw();
302 sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& _rIdentifier
) throw(::com::sun::star::uno::RuntimeException
);
304 //===== Misc ========================================================
306 ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>
309 /** set the index _nIndex at the accessible shape
311 The new index in parent.
313 inline void setIndexInParent(sal_Int32 _nIndex
) { m_nIndexInParent
= _nIndex
; }
316 /// Children manager. May be empty if there are no children.
317 ChildrenManager
* mpChildrenManager
;
319 /// Reference to the actual shape.
320 ::com::sun::star::uno::Reference
<
321 ::com::sun::star::drawing::XShape
> mxShape
;
323 /** Bundle of information passed to all shapes in a document tree.
325 AccessibleShapeTreeInfo maShapeTreeInfo
;
327 /** Index that is appended to the object's name to disambiguate between
328 different names with the otherwise same name.
332 /** the index in parent.
334 sal_Int32 m_nIndexInParent
;
336 /** The accessible text engine. May be NULL if it can not be created.
338 AccessibleTextHelper
* mpText
;
340 /** This object can be used to modify the child list of our parent.
342 IAccessibleParent
* mpParent
;
344 /** This object can be removed when we have an extra interface to ask if the shape is selected
348 /** This method is called from the component helper base class while
351 virtual void SAL_CALL
disposing (void);
353 /** Create a base name string that contains the accessible name.
356 CreateAccessibleBaseName (void)
357 throw (::com::sun::star::uno::RuntimeException
);
359 /** Create a unique name string that contains the accessible name. The
360 name consists of the base name and the index.
363 CreateAccessibleName (void)
364 throw (::com::sun::star::uno::RuntimeException
);
366 /// Create a description string that contains the accessible description.
368 CreateAccessibleDescription (void)
369 throw (::com::sun::star::uno::RuntimeException
);
371 /** Update the <const>OPAQUE</const> and <const>SELECTED</const> state.
373 virtual void UpdateStates (void);
376 /** Don't use the default constructor. Use the public constructor that
377 takes the original shape and the parent as arguments instead.
379 SVX_DLLPRIVATE
explicit AccessibleShape (void);
380 /// Don't use the copy constructor. Is there any use for it?
381 SVX_DLLPRIVATE
explicit AccessibleShape (const AccessibleShape
&);
382 /// Don't use the assignment operator. Do we need this?
383 SVX_DLLPRIVATE AccessibleShape
& operator= (const AccessibleShape
&);
385 /** Call this method when the title, name, or description of the mxShape
386 member (may) have been changed.
387 This method adapts the name and description members of the
388 AccessibleContextBase base class.
390 void UpdateNameAndDescription (void);
393 } // end of namespace accessibility
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */