xref: /AOO41X/main/svx/source/accessibility/ChildrenManagerImpl.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _SVX_ACCESSIBILITY_CHILDREN_MANAGER_IMPL_HXX
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <svx/IAccessibleViewForwarderListener.hxx>
31*cdf0e10cSrcweir #include <svx/IAccessibleParent.hxx>
32*cdf0e10cSrcweir #include <svx/AccessibleShapeTreeInfo.hxx>
33*cdf0e10cSrcweir #include <editeng/AccessibleContextBase.hxx>
34*cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx>
35*cdf0e10cSrcweir #include <vos/mutex.hxx>
36*cdf0e10cSrcweir #include <vector>
37*cdf0e10cSrcweir #include <memory>
38*cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/drawing/XShapes.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/document/XEventListener.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/view/XSelectionChangeListener.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessible.hpp>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir using namespace ::com::sun::star;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir namespace accessibility {
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir class AccessibleShape;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir class ChildDescriptor; // See below for declaration.
51*cdf0e10cSrcweir typedef ::std::vector<ChildDescriptor> ChildDescriptorListType;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir // Re-using MutexOwner class defined in AccessibleContextBase.hxx
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir /** This class contains the actual implementation of the children manager.
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     <p>It maintains a set of visible accessible shapes in
58*cdf0e10cSrcweir     <member>maVisibleChildren</member>.  The objects in this list stem from
59*cdf0e10cSrcweir     two sources.  The first is a list of UNO shapes like the list of shapes
60*cdf0e10cSrcweir     in a draw page.  A reference to this list is held in
61*cdf0e10cSrcweir     <member>maShapeList</member>.  Accessible objects for these shapes are
62*cdf0e10cSrcweir     created on demand.  The list can be replaced by calls to the
63*cdf0e10cSrcweir     <member>SetShapeList</member> method.  The second source is a list of
64*cdf0e10cSrcweir     already accessible objects.  It can be modified by calls to the
65*cdf0e10cSrcweir     <member>AddAccessibleShape</member> and
66*cdf0e10cSrcweir     <member>ClearAccessibleShapeList</member> methods.</p>
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     <p>Each call of the <member>Update</member> method leads to a
69*cdf0e10cSrcweir     re-calculation of the visible shapes which then can be queried with the
70*cdf0e10cSrcweir     <member>GetChildCount</member> and <member>GetChild</member> methods.
71*cdf0e10cSrcweir     Events are send informing all listeners about the removed shapes which are
72*cdf0e10cSrcweir     not visible anymore and about the added shapes.</p>
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir     <p> The visible area which is used to determine the visibility of the
75*cdf0e10cSrcweir     shapes is taken from the view forwarder.  Thus, to signal a change of
76*cdf0e10cSrcweir     the visible area call <member>ViewForwarderChanged</member>.</p>
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     <p>The children manager adds itself as disposing() listener at every UNO
79*cdf0e10cSrcweir     shape it creates an accessible object for so that when the UNO shape
80*cdf0e10cSrcweir     passes away it can dispose() the associated accessible object.</p>
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     @see ChildrenManager
83*cdf0e10cSrcweir */
84*cdf0e10cSrcweir class ChildrenManagerImpl
85*cdf0e10cSrcweir     :	public MutexOwner,
86*cdf0e10cSrcweir         public cppu::WeakComponentImplHelper2<
87*cdf0e10cSrcweir             ::com::sun::star::document::XEventListener,
88*cdf0e10cSrcweir             ::com::sun::star::view::XSelectionChangeListener>,
89*cdf0e10cSrcweir         public IAccessibleViewForwarderListener,
90*cdf0e10cSrcweir         public IAccessibleParent
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir public:
93*cdf0e10cSrcweir     /** Create a children manager, which manages the children of the given
94*cdf0e10cSrcweir         parent.  The parent is used for creating accessible objects.  The
95*cdf0e10cSrcweir         list of shapes for which to create those objects is not derived from
96*cdf0e10cSrcweir         the parent and has to be provided seperately by calling one of the
97*cdf0e10cSrcweir         update methods.
98*cdf0e10cSrcweir         @param rxParent
99*cdf0e10cSrcweir             The parent of the accessible objects which will be created
100*cdf0e10cSrcweir             on demand at some point of time in the future.
101*cdf0e10cSrcweir         @param rxShapeList
102*cdf0e10cSrcweir             List of UNO shapes to manage.
103*cdf0e10cSrcweir         @param rShapeTreeInfo
104*cdf0e10cSrcweir             Bundel of information passed down the shape tree.
105*cdf0e10cSrcweir         @param rContext
106*cdf0e10cSrcweir             An accessible context object that is called for fireing events
107*cdf0e10cSrcweir             for new and deleted children, i.e. that holds a list of
108*cdf0e10cSrcweir             listeners to be informed.
109*cdf0e10cSrcweir     */
110*cdf0e10cSrcweir     ChildrenManagerImpl (const ::com::sun::star::uno::Reference<
111*cdf0e10cSrcweir             ::com::sun::star::accessibility::XAccessible>& rxParent,
112*cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
113*cdf0e10cSrcweir             ::com::sun::star::drawing::XShapes>& rxShapeList,
114*cdf0e10cSrcweir         const AccessibleShapeTreeInfo& rShapeTreeInfo,
115*cdf0e10cSrcweir         AccessibleContextBase& rContext);
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     /** If there still are managed children these are disposed and
118*cdf0e10cSrcweir         released.
119*cdf0e10cSrcweir     */
120*cdf0e10cSrcweir     ~ChildrenManagerImpl (void);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     /** Do that part of the initialization that you can not or should not do
123*cdf0e10cSrcweir         in the constructor like registering at broadcasters.
124*cdf0e10cSrcweir     */
125*cdf0e10cSrcweir     void Init (void);
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir     /** Return the number of currently visible accessible children.
128*cdf0e10cSrcweir         @return
129*cdf0e10cSrcweir             If there are no children a 0 is returned.
130*cdf0e10cSrcweir     */
131*cdf0e10cSrcweir     long GetChildCount (void) const throw ();
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     /**	Return the requested accessible child or throw and
134*cdf0e10cSrcweir         IndexOutOfBoundsException if the given index is invalid.
135*cdf0e10cSrcweir         @param nIndex
136*cdf0e10cSrcweir             Index of the requested child.  Call getChildCount for obtaining
137*cdf0e10cSrcweir             the number of children.
138*cdf0e10cSrcweir         @return
139*cdf0e10cSrcweir             In case of a valid index this method returns a reference to the
140*cdf0e10cSrcweir             requested accessible child.  This reference is empty if it has
141*cdf0e10cSrcweir             not been possible to create the accessible object of the
142*cdf0e10cSrcweir             corresponding shape.
143*cdf0e10cSrcweir         @raises
144*cdf0e10cSrcweir             Throws an IndexOutOfBoundsException if the index is not valid.
145*cdf0e10cSrcweir     */
146*cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
147*cdf0e10cSrcweir             ::com::sun::star::accessibility::XAccessible>
148*cdf0e10cSrcweir     	GetChild (long nIndex)
149*cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException,
150*cdf0e10cSrcweir                ::com::sun::star::lang::IndexOutOfBoundsException);
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     /**	Return the requested accessible child.
153*cdf0e10cSrcweir         @param aChildDescriptor
154*cdf0e10cSrcweir             This object contains references to the original shape and its
155*cdf0e10cSrcweir             associated accessible object.
156*cdf0e10cSrcweir 		@param	_nIndex
157*cdf0e10cSrcweir 			The index which will be used in getAccessibleIndexInParent of the accessible shape.
158*cdf0e10cSrcweir         @return
159*cdf0e10cSrcweir             Returns a reference to the requested accessible child.  This
160*cdf0e10cSrcweir             reference is empty if it has not been possible to create the
161*cdf0e10cSrcweir             accessible object of the corresponding shape.
162*cdf0e10cSrcweir     */
163*cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
164*cdf0e10cSrcweir             ::com::sun::star::accessibility::XAccessible>
165*cdf0e10cSrcweir         GetChild (ChildDescriptor& aChildDescriptor,sal_Int32 _nIndex)
166*cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir     /**	Return the requested accessible child given a shape.  This method
169*cdf0e10cSrcweir         searches the list of descriptors for the one that holds the
170*cdf0e10cSrcweir         association of the given shape to the requested accessible object
171*cdf0e10cSrcweir         and returns that.  If no such descriptor is found that is
172*cdf0e10cSrcweir         interpreted so that the specified shape is not visible at the moment.
173*cdf0e10cSrcweir         @param xShape
174*cdf0e10cSrcweir             The shape for which to return the associated accessible object.
175*cdf0e10cSrcweir         @return
176*cdf0e10cSrcweir             Returns a reference to the requested accessible child.  The
177*cdf0e10cSrcweir             reference is empty if there is no shape descriptor that
178*cdf0e10cSrcweir             associates the shape with an accessible object.
179*cdf0e10cSrcweir     */
180*cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
181*cdf0e10cSrcweir             ::com::sun::star::accessibility::XAccessible>
182*cdf0e10cSrcweir         GetChild (const ::com::sun::star::uno::Reference<
183*cdf0e10cSrcweir             ::com::sun::star::drawing::XShape>& xShape)
184*cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     /** Update the child manager.  Take care of a modified set of children
187*cdf0e10cSrcweir         and modified visible area.  This method can optimize the update
188*cdf0e10cSrcweir         process with respect seperate updates of a modified children list
189*cdf0e10cSrcweir         and visible area.
190*cdf0e10cSrcweir         @param bCreateNewObjectsOnDemand
191*cdf0e10cSrcweir             If </true> then accessible objects associated with the visible
192*cdf0e10cSrcweir             shapes are created only when asked for.  No event is sent on
193*cdf0e10cSrcweir             creation.  If </false> then the accessible objects are created
194*cdf0e10cSrcweir             before this method returns and events are sent to inform the
195*cdf0e10cSrcweir             listeners of the new object.
196*cdf0e10cSrcweir     */
197*cdf0e10cSrcweir     void Update (bool bCreateNewObjectsOnDemand = true);
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir     /** Set the list of UNO shapes to the given list.  This removes the old
200*cdf0e10cSrcweir         list and does not add to it.  The list of accessible shapes that is
201*cdf0e10cSrcweir         build up by calls to <member>AddAccessibleShape</member> is not
202*cdf0e10cSrcweir         modified.  Neither is the list of visible children.  Accessible
203*cdf0e10cSrcweir         objects are created on demand.
204*cdf0e10cSrcweir         @param xShapeList
205*cdf0e10cSrcweir             The list of UNO shapes that replaces the old list.
206*cdf0e10cSrcweir     */
207*cdf0e10cSrcweir     void SetShapeList (const ::com::sun::star::uno::Reference<
208*cdf0e10cSrcweir         ::com::sun::star::drawing::XShapes>& xShapeList);
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir     /** Add a accessible shape.  This does not modify the list of UNO shapes
211*cdf0e10cSrcweir         or the list of visible shapes.  Accessible shapes are, at the
212*cdf0e10cSrcweir         moment, not tested against the visible area but are always appended
213*cdf0e10cSrcweir         to the list of visible children.
214*cdf0e10cSrcweir         @param pShape
215*cdf0e10cSrcweir             The new shape that is added to the list of accessible shapes.
216*cdf0e10cSrcweir     */
217*cdf0e10cSrcweir     void AddAccessibleShape (std::auto_ptr<AccessibleShape> pShape);
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir     /** Clear the lists of accessible shapes and that of visible accessible
220*cdf0e10cSrcweir         shapes.  The list of UNO shapes is not modified.
221*cdf0e10cSrcweir     */
222*cdf0e10cSrcweir     void ClearAccessibleShapeList (void);
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir     /** Set a new event shape tree info.  Call this method to inform the
225*cdf0e10cSrcweir         children manager of a change of the info bundle.
226*cdf0e10cSrcweir         @param rShapeTreeInfo
227*cdf0e10cSrcweir             The new info that replaces the current one.
228*cdf0e10cSrcweir     */
229*cdf0e10cSrcweir     void SetInfo (const AccessibleShapeTreeInfo& rShapeTreeInfo);
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     /** Update the SELECTED and FOCUSED states of all visible children
232*cdf0e10cSrcweir         according to the given selection.  This includes setting
233*cdf0e10cSrcweir         <em>and</em> resetting the states.
234*cdf0e10cSrcweir     */
235*cdf0e10cSrcweir     void UpdateSelection (void);
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir     /** Return whether one of the shapes managed by this object has
238*cdf0e10cSrcweir         currently the focus.
239*cdf0e10cSrcweir         @return
240*cdf0e10cSrcweir             Returns <true/> when there is a shape that has the focus and
241*cdf0e10cSrcweir             <false/> when there is no such shape.
242*cdf0e10cSrcweir     */
243*cdf0e10cSrcweir     bool HasFocus (void);
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir     /** When there is a shape that currently has the focus,
246*cdf0e10cSrcweir         i.e. <member>HasFocus()</member> returns <true/> then remove the
247*cdf0e10cSrcweir         focus from that shape.  Otherwise nothing changes.
248*cdf0e10cSrcweir     */
249*cdf0e10cSrcweir     void RemoveFocus (void);
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir     //=====  lang::XEventListener  ============================================
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     virtual void SAL_CALL
254*cdf0e10cSrcweir         disposing (const ::com::sun::star::lang::EventObject& rEventObject)
255*cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     //=====  document::XEventListener  ========================================
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     virtual void SAL_CALL
261*cdf0e10cSrcweir         notifyEvent (const ::com::sun::star::document::EventObject& rEventObject)
262*cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir     //=====  view::XSelectionChangeListener  ==================================
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     virtual void  SAL_CALL
268*cdf0e10cSrcweir         selectionChanged (const ::com::sun::star::lang::EventObject& rEvent)
269*cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir     //=====  IAccessibleViewForwarderListener  ================================
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir     /** Informs this children manager and its children about a change of one
275*cdf0e10cSrcweir         (or more) aspect of the view forwarder.
276*cdf0e10cSrcweir         @param aChangeType
277*cdf0e10cSrcweir             A change type of <const>VISIBLE_AREA</const> leads to a call to
278*cdf0e10cSrcweir             the <member>Update</memeber> which creates accessible objects of
279*cdf0e10cSrcweir             new shapes immediately.  Other change types are passed to the
280*cdf0e10cSrcweir             visible accessible children without calling
281*cdf0e10cSrcweir             <member>Update</memeber>.
282*cdf0e10cSrcweir         @param pViewForwarder
283*cdf0e10cSrcweir             The modified view forwarder.  Use this one from now on.
284*cdf0e10cSrcweir     */
285*cdf0e10cSrcweir     virtual void ViewForwarderChanged (ChangeType aChangeType,
286*cdf0e10cSrcweir         const IAccessibleViewForwarder* pViewForwarder);
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir     //=====  IAccessibleParent  ===============================================
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir     /** Replace the specified child with a replacement.
291*cdf0e10cSrcweir         @param pCurrentChild
292*cdf0e10cSrcweir             This child is to be replaced.
293*cdf0e10cSrcweir         @param pReplacement
294*cdf0e10cSrcweir             The replacement for the current child.
295*cdf0e10cSrcweir         @return
296*cdf0e10cSrcweir             The returned value indicates wether the replacement has been
297*cdf0e10cSrcweir             finished successfully.
298*cdf0e10cSrcweir     */
299*cdf0e10cSrcweir     virtual sal_Bool ReplaceChild (
300*cdf0e10cSrcweir         AccessibleShape* pCurrentChild,
301*cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& _rxShape,
302*cdf0e10cSrcweir 		const long _nIndex,
303*cdf0e10cSrcweir 		const AccessibleShapeTreeInfo& _rShapeTreeInfo
304*cdf0e10cSrcweir 	)	throw (::com::sun::star::uno::RuntimeException);
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir protected:
308*cdf0e10cSrcweir     /** This list holds the descriptors of all currently visible shapes and
309*cdf0e10cSrcweir         associated accessible object.
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir         <p>With the descriptors it maintains a mapping of shapes to
312*cdf0e10cSrcweir         accessible objects.  It acts as a cache in that accessible objects
313*cdf0e10cSrcweir         are only created on demand and released with every update (where the
314*cdf0e10cSrcweir         latter may be optimized by the update methods).<p>
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir         <p>The list is realized as a vector because it remains unchanged
317*cdf0e10cSrcweir         between updates (i.e. complete rebuilds of the list) and allows a
318*cdf0e10cSrcweir         fast (constant time) access to its elements for given indices.</p>
319*cdf0e10cSrcweir     */
320*cdf0e10cSrcweir     ChildDescriptorListType maVisibleChildren;
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir     /** The original list of UNO shapes.  The visible shapes are inserted
323*cdf0e10cSrcweir         into the list of visible children
324*cdf0e10cSrcweir         <member>maVisibleChildren</member>.
325*cdf0e10cSrcweir     */
326*cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
327*cdf0e10cSrcweir         ::com::sun::star::drawing::XShapes> mxShapeList;
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir     /** This list of additional accessible shapes that can or shall not be
330*cdf0e10cSrcweir         created by the shape factory.
331*cdf0e10cSrcweir     */
332*cdf0e10cSrcweir     typedef std::vector< ::com::sun::star::uno::Reference<
333*cdf0e10cSrcweir         ::com::sun::star::accessibility::XAccessible> > AccessibleShapeList;
334*cdf0e10cSrcweir     AccessibleShapeList maAccessibleShapes;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     /** Rectangle that describes the visible area in which a shape has to lie
337*cdf0e10cSrcweir         at least partly, to be accessible through this class.  Used to
338*cdf0e10cSrcweir         detect changes of the visible area after changes of the view forwarder.
339*cdf0e10cSrcweir     */
340*cdf0e10cSrcweir     Rectangle maVisibleArea;
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir     /** The parent of the shapes.  It is used for creating accessible
343*cdf0e10cSrcweir         objects for given shapes.
344*cdf0e10cSrcweir     */
345*cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
346*cdf0e10cSrcweir         ::com::sun::star::accessibility::XAccessible> mxParent;
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir     /** Bundel of information passed down the shape tree.
349*cdf0e10cSrcweir     */
350*cdf0e10cSrcweir     AccessibleShapeTreeInfo maShapeTreeInfo;
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     /** Reference to an accessible context object that is used to inform its
353*cdf0e10cSrcweir         listeners of new and remved children.
354*cdf0e10cSrcweir     */
355*cdf0e10cSrcweir     AccessibleContextBase& mrContext;
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir     /** This method is called from the component helper base class while
358*cdf0e10cSrcweir         disposing.
359*cdf0e10cSrcweir     */
360*cdf0e10cSrcweir     virtual void SAL_CALL disposing (void);
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir     /** Experimental: Get the index of the specified accessible object with
363*cdf0e10cSrcweir         respect to the list of children maintained by this object.
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir         @return
366*cdf0e10cSrcweir             Return the index of the given child or -1 to indicate that the
367*cdf0e10cSrcweir             child is unknown.
368*cdf0e10cSrcweir     */
369*cdf0e10cSrcweir     long GetChildIndex (const ::com::sun::star::uno::Reference<
370*cdf0e10cSrcweir         ::com::sun::star::accessibility::XAccessible>& xChild) const
371*cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir     void impl_dispose (void);
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir private:
376*cdf0e10cSrcweir     /** Names of new accessible objects are disambiguated with this index.
377*cdf0e10cSrcweir         It gets increased every time a new object is created and (at the
378*cdf0e10cSrcweir         moment) never reset.
379*cdf0e10cSrcweir     */
380*cdf0e10cSrcweir     sal_Int32 mnNewNameIndex;
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir     // Don't use the copy constructor or the assignment operator.  They are
383*cdf0e10cSrcweir     // not implemented (and are not intended to be).
384*cdf0e10cSrcweir     ChildrenManagerImpl (const ChildrenManagerImpl&);
385*cdf0e10cSrcweir     ChildrenManagerImpl& operator= (const ChildrenManagerImpl&);
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir     /** This member points to the currently focused shape.  It is NULL when
388*cdf0e10cSrcweir         there is no focused shape.
389*cdf0e10cSrcweir     */
390*cdf0e10cSrcweir     AccessibleShape* mpFocusedShape;
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir     /** Three helper functions for the <member>Update</member> method.
393*cdf0e10cSrcweir     */
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir     /** Create a list of visible shapes from the list of UNO shapes
396*cdf0e10cSrcweir         <member>maShapeList</member> and the list of accessible objects.
397*cdf0e10cSrcweir         @param raChildList
398*cdf0e10cSrcweir             For every visible shape from the two sources mentioned above one
399*cdf0e10cSrcweir             descriptor is added to this list.
400*cdf0e10cSrcweir     */
401*cdf0e10cSrcweir     void CreateListOfVisibleShapes (ChildDescriptorListType& raChildList);
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir     /** From the old list of (former) visible shapes remove those that
404*cdf0e10cSrcweir         are not member of the new list.  Send appropriate events for every
405*cdf0e10cSrcweir         such shape.
406*cdf0e10cSrcweir         @param raNewChildList
407*cdf0e10cSrcweir             The new list of visible children against which the old one
408*cdf0e10cSrcweir             is compared.
409*cdf0e10cSrcweir         @param raOldChildList
410*cdf0e10cSrcweir             The old list of visible children against which the new one
411*cdf0e10cSrcweir             is compared.
412*cdf0e10cSrcweir     */
413*cdf0e10cSrcweir     void RemoveNonVisibleChildren (
414*cdf0e10cSrcweir         const ChildDescriptorListType& raNewChildList,
415*cdf0e10cSrcweir         ChildDescriptorListType& raOldChildList);
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir     /** Merge the information that is already known about the visible shapes
418*cdf0e10cSrcweir         from the current list into the new list.
419*cdf0e10cSrcweir         @param raChildList
420*cdf0e10cSrcweir             Information is merged from the current list of visible children
421*cdf0e10cSrcweir             to this list.
422*cdf0e10cSrcweir     */
423*cdf0e10cSrcweir     void MergeAccessibilityInformation (ChildDescriptorListType& raChildList);
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir     /** If the visible area has changed then send events that signal a
426*cdf0e10cSrcweir         change of their bounding boxes for all shapes that are members of
427*cdf0e10cSrcweir         both the current and the new list of visible shapes.
428*cdf0e10cSrcweir         @param raChildList
429*cdf0e10cSrcweir             Events are sent to all entries of this list that already contain
430*cdf0e10cSrcweir             an accessible object.
431*cdf0e10cSrcweir     */
432*cdf0e10cSrcweir     void SendVisibleAreaEvents (ChildDescriptorListType& raChildList);
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir     /** If children have to be created immediately and not on demand the
435*cdf0e10cSrcweir         create the missing accessible objects now.
436*cdf0e10cSrcweir         @param raDescriptorList
437*cdf0e10cSrcweir             Create an accessible object for every member of this list where
438*cdf0e10cSrcweir             that obejct does not already exist.
439*cdf0e10cSrcweir     */
440*cdf0e10cSrcweir     void CreateAccessibilityObjects (ChildDescriptorListType& raChildList);
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir     /** Add a single shape.  Update all relevant data structures
443*cdf0e10cSrcweir         accordingly.  Use this method instead of <member>Update()</member>
444*cdf0e10cSrcweir         when only a single shape has been added.
445*cdf0e10cSrcweir     */
446*cdf0e10cSrcweir     void AddShape (const ::com::sun::star::uno::Reference<
447*cdf0e10cSrcweir         ::com::sun::star::drawing::XShape>& xShape);
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir     /** Remove a single shape.  Update all relevant data structures
450*cdf0e10cSrcweir         accordingly.  Use this method instead of <member>Update()</member>
451*cdf0e10cSrcweir         when only a single shape has been removed.
452*cdf0e10cSrcweir     */
453*cdf0e10cSrcweir     void RemoveShape (const ::com::sun::star::uno::Reference<
454*cdf0e10cSrcweir         ::com::sun::star::drawing::XShape>& xShape);
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir     /** Add the children manager as dispose listener at the given shape so
457*cdf0e10cSrcweir         that the associated accessible object can be disposed when the shape
458*cdf0e10cSrcweir         is disposed.
459*cdf0e10cSrcweir         @param xShape
460*cdf0e10cSrcweir             Register at this shape as dispose listener.
461*cdf0e10cSrcweir     */
462*cdf0e10cSrcweir     void RegisterAsDisposeListener (const ::com::sun::star::uno::Reference<
463*cdf0e10cSrcweir         ::com::sun::star::drawing::XShape>& xShape);
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir     /** Remove the children manager as dispose listener at the given shape
466*cdf0e10cSrcweir         @param xShape
467*cdf0e10cSrcweir             Unregister at this shape as dispose listener.
468*cdf0e10cSrcweir     */
469*cdf0e10cSrcweir     void UnregisterAsDisposeListener (const ::com::sun::star::uno::Reference<
470*cdf0e10cSrcweir         ::com::sun::star::drawing::XShape>& xShape);
471*cdf0e10cSrcweir };
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir /** A child descriptor holds a reference to a UNO shape and the
477*cdf0e10cSrcweir     corresponding accessible object.  There are two use cases:
478*cdf0e10cSrcweir     <ol><li>The accessible object is only created on demand and is then
479*cdf0e10cSrcweir     initially empty.</li>
480*cdf0e10cSrcweir     <li>There is no UNO shape.  The accessible object is given as argument
481*cdf0e10cSrcweir     to the constructor.</li>
482*cdf0e10cSrcweir     </ol>
483*cdf0e10cSrcweir     In both cases the child descriptor assumes ownership over the accessible
484*cdf0e10cSrcweir     object.
485*cdf0e10cSrcweir */
486*cdf0e10cSrcweir class ChildDescriptor
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir public:
489*cdf0e10cSrcweir     /** Reference to a (partially) visible shape.
490*cdf0e10cSrcweir     */
491*cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
492*cdf0e10cSrcweir         ::com::sun::star::drawing::XShape> mxShape;
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir     /** The corresponding accessible object.  This reference is initially
495*cdf0e10cSrcweir         empty and only replaced by a reference to a new object when that is
496*cdf0e10cSrcweir         requested from the outside.
497*cdf0e10cSrcweir     */
498*cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
499*cdf0e10cSrcweir         ::com::sun::star::accessibility::XAccessible> mxAccessibleShape;
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir     /** Return a pointer to the implementation object of the accessible
502*cdf0e10cSrcweir         shape of this descriptor.
503*cdf0e10cSrcweir         @return
504*cdf0e10cSrcweir             The result is NULL if either the UNO reference to the accessible
505*cdf0e10cSrcweir             shape is empty or it can not be transformed into a pointer to
506*cdf0e10cSrcweir             the desired class.
507*cdf0e10cSrcweir     */
508*cdf0e10cSrcweir     AccessibleShape* GetAccessibleShape (void) const;
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir 	/** set the index _nIndex at the accessible shape
511*cdf0e10cSrcweir 		@param	_nIndex
512*cdf0e10cSrcweir 			The new index in parent.
513*cdf0e10cSrcweir 	*/
514*cdf0e10cSrcweir 	void setIndexAtAccessibleShape(sal_Int32 _nIndex);
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir     /** This flag is set during the visibility calculation and indicates
517*cdf0e10cSrcweir         that at one time in this process an event is sent that informs the
518*cdf0e10cSrcweir         listners of the creation of a new accessible object.  This flags is
519*cdf0e10cSrcweir         not reset afterwards.  Don't use it unless you know exactly what you
520*cdf0e10cSrcweir         are doing.
521*cdf0e10cSrcweir     */
522*cdf0e10cSrcweir     bool mbCreateEventPending;
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir     /** Create a new descriptor for the specified shape with empty reference
525*cdf0e10cSrcweir         to accessible object.
526*cdf0e10cSrcweir     */
527*cdf0e10cSrcweir     explicit ChildDescriptor (const ::com::sun::star::uno::Reference<
528*cdf0e10cSrcweir         ::com::sun::star::drawing::XShape>& xShape);
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir     /** Create a new descriptor for the specified shape with empty reference
531*cdf0e10cSrcweir         to the original shape.
532*cdf0e10cSrcweir     */
533*cdf0e10cSrcweir     explicit ChildDescriptor (const ::com::sun::star::uno::Reference<
534*cdf0e10cSrcweir         ::com::sun::star::accessibility::XAccessible>& rxAccessibleShape);
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir     ~ChildDescriptor (void);
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir     /** Dispose the accessible object of this descriptor.  If that object
539*cdf0e10cSrcweir         does not exist then do nothing.
540*cdf0e10cSrcweir         @param rParent
541*cdf0e10cSrcweir             The parent of the accessible object to dispose.  A child event
542*cdf0e10cSrcweir             is sent in its name.
543*cdf0e10cSrcweir     */
544*cdf0e10cSrcweir     void disposeAccessibleObject (AccessibleContextBase& rParent);
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir 	/** Compare two child descriptors.  Take into account that a child
547*cdf0e10cSrcweir 		descriptor may be based on a UNO shape or, already, on an accessible
548*cdf0e10cSrcweir 		shape.
549*cdf0e10cSrcweir 	*/
550*cdf0e10cSrcweir     inline bool operator == (const ChildDescriptor& aDescriptor) const
551*cdf0e10cSrcweir 	{
552*cdf0e10cSrcweir 		return (
553*cdf0e10cSrcweir                 this == &aDescriptor ||
554*cdf0e10cSrcweir                 (
555*cdf0e10cSrcweir                  (mxShape.get() == aDescriptor.mxShape.get() ) &&
556*cdf0e10cSrcweir                  (mxShape.is() || mxAccessibleShape.get() == aDescriptor.mxAccessibleShape.get())
557*cdf0e10cSrcweir                 )
558*cdf0e10cSrcweir                );
559*cdf0e10cSrcweir 	}
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir 	/** The ordering defined by this operator is only used in order to be able
562*cdf0e10cSrcweir 		to put child descriptors in some STL containers.  The ordering itself is
563*cdf0e10cSrcweir 		not so important, its 'features' are not used.
564*cdf0e10cSrcweir 	*/
565*cdf0e10cSrcweir     inline bool operator < (const ChildDescriptor& aDescriptor) const
566*cdf0e10cSrcweir 	{
567*cdf0e10cSrcweir 		return (mxShape.get() < aDescriptor.mxShape.get());
568*cdf0e10cSrcweir 	}
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir };
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir } // end of namespace accessibility
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir #endif
577*cdf0e10cSrcweir 
578