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