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