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