1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "ChildrenManagerImpl.hxx"
28cdf0e10cSrcweir #include <svx/ShapeTypeHandler.hxx>
29cdf0e10cSrcweir #include <svx/AccessibleShapeInfo.hxx>
30cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBLE_ACCESSIBLESTATETYPE_HPP_
31cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <com/sun/star/view/XSelectionSupplier.hpp>
34cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
35cdf0e10cSrcweir #include <comphelper/uno3.hxx>
36cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <rtl/ustring.hxx>
39cdf0e10cSrcweir #include <tools/debug.hxx>
40*9b8096d0SSteve Yin //IAccessibility2 Implementation 2009-----
41*9b8096d0SSteve Yin #ifndef _SVX_ACCESSIBILITY_SVX_SHAPE_TYPES_HXX
42*9b8096d0SSteve Yin #include <svx/SvxShapeTypes.hxx>
43*9b8096d0SSteve Yin #endif
44*9b8096d0SSteve Yin #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
45*9b8096d0SSteve Yin #include <toolkit/unohlp.hxx>
46*9b8096d0SSteve Yin #endif
47cdf0e10cSrcweir 
48*9b8096d0SSteve Yin #ifndef _SV_WINDOW_HXX
49*9b8096d0SSteve Yin #include <vcl/window.hxx>
50*9b8096d0SSteve Yin #endif
51*9b8096d0SSteve Yin //-----IAccessibility2 Implementation 2009
52cdf0e10cSrcweir using namespace ::com::sun::star;
53cdf0e10cSrcweir using namespace	::com::sun::star::accessibility;
54cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
57cdf0e10cSrcweir namespace accessibility {
58cdf0e10cSrcweir 
59cdf0e10cSrcweir namespace
60cdf0e10cSrcweir {
61cdf0e10cSrcweir void adjustIndexInParentOfShapes(ChildDescriptorListType& _rList)
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 	ChildDescriptorListType::iterator aEnd = _rList.end();
64cdf0e10cSrcweir 	sal_Int32 i=0;
65cdf0e10cSrcweir 	for ( ChildDescriptorListType::iterator aIter = _rList.begin(); aIter != aEnd; ++aIter,++i)
66cdf0e10cSrcweir 		aIter->setIndexAtAccessibleShape(i);
67cdf0e10cSrcweir }
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir //=====  AccessibleChildrenManager  ===========================================
71cdf0e10cSrcweir 
72cdf0e10cSrcweir ChildrenManagerImpl::ChildrenManagerImpl (
73cdf0e10cSrcweir     const uno::Reference<XAccessible>& rxParent,
74cdf0e10cSrcweir     const uno::Reference<drawing::XShapes>& rxShapeList,
75cdf0e10cSrcweir     const AccessibleShapeTreeInfo& rShapeTreeInfo,
76cdf0e10cSrcweir     AccessibleContextBase& rContext)
77cdf0e10cSrcweir     : ::cppu::WeakComponentImplHelper2<
78cdf0e10cSrcweir           ::com::sun::star::document::XEventListener,
79cdf0e10cSrcweir           ::com::sun::star::view::XSelectionChangeListener>(maMutex),
80cdf0e10cSrcweir       mxShapeList (rxShapeList),
81cdf0e10cSrcweir       mxParent (rxParent),
82cdf0e10cSrcweir       maShapeTreeInfo (rShapeTreeInfo),
83cdf0e10cSrcweir       mrContext (rContext),
84cdf0e10cSrcweir       mnNewNameIndex(1),
85cdf0e10cSrcweir       mpFocusedShape(NULL)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir ChildrenManagerImpl::~ChildrenManagerImpl (void)
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     DBG_ASSERT (rBHelper.bDisposed || rBHelper.bInDispose,
95cdf0e10cSrcweir         "~AccessibleDrawDocumentView: object has not been disposed");
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
101cdf0e10cSrcweir void ChildrenManagerImpl::Init (void)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     // Register as view::XSelectionChangeListener.
104cdf0e10cSrcweir     Reference<frame::XController> xController(maShapeTreeInfo.GetController());
105cdf0e10cSrcweir     Reference<view::XSelectionSupplier> xSelectionSupplier (
106cdf0e10cSrcweir         xController, uno::UNO_QUERY);
107cdf0e10cSrcweir     if (xSelectionSupplier.is())
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         xController->addEventListener(
110cdf0e10cSrcweir             static_cast<document::XEventListener*>(this));
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         xSelectionSupplier->addSelectionChangeListener (
113cdf0e10cSrcweir             static_cast<view::XSelectionChangeListener*>(this));
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     // Register at model as document::XEventListener.
117cdf0e10cSrcweir     if (maShapeTreeInfo.GetModelBroadcaster().is())
118cdf0e10cSrcweir         maShapeTreeInfo.GetModelBroadcaster()->addEventListener (
119cdf0e10cSrcweir             static_cast<document::XEventListener*>(this));
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 
125cdf0e10cSrcweir long ChildrenManagerImpl::GetChildCount (void) const throw ()
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     return maVisibleChildren.size();
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 
131*9b8096d0SSteve Yin //IAccessibility2 Implementation 2009-----
132*9b8096d0SSteve Yin ::com::sun::star::uno::Reference<
133*9b8096d0SSteve Yin         ::com::sun::star::drawing::XShape> ChildrenManagerImpl::GetChildShape(long nIndex)
134*9b8096d0SSteve Yin     throw (::com::sun::star::uno::RuntimeException)
135*9b8096d0SSteve Yin {
136*9b8096d0SSteve Yin 	uno::Reference<XAccessible> xAcc = GetChild(nIndex);
137*9b8096d0SSteve Yin 	ChildDescriptorListType::iterator I, aEnd = maVisibleChildren.end();
138*9b8096d0SSteve Yin     for (I = maVisibleChildren.begin(); I != aEnd; ++I)
139*9b8096d0SSteve Yin     {
140*9b8096d0SSteve Yin         if (I->mxAccessibleShape == xAcc)
141*9b8096d0SSteve Yin             return I->mxShape;
142*9b8096d0SSteve Yin     }
143*9b8096d0SSteve Yin 	return uno::Reference< drawing::XShape > ();
144*9b8096d0SSteve Yin }
145*9b8096d0SSteve Yin //-----IAccessibility2 Implementation 2009
146cdf0e10cSrcweir 
147cdf0e10cSrcweir /** Return the requested accessible child object.  Create it if it is not
148cdf0e10cSrcweir     yet in the cache.
149cdf0e10cSrcweir */
150cdf0e10cSrcweir uno::Reference<XAccessible>
151cdf0e10cSrcweir     ChildrenManagerImpl::GetChild (long nIndex)
152cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException,
153cdf0e10cSrcweir            ::com::sun::star::lang::IndexOutOfBoundsException)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir     // Check wether the given index is valid.
156cdf0e10cSrcweir     if (nIndex < 0 || (unsigned long)nIndex >= maVisibleChildren.size())
157cdf0e10cSrcweir         throw lang::IndexOutOfBoundsException (
158cdf0e10cSrcweir             ::rtl::OUString::createFromAscii(
159cdf0e10cSrcweir 				"no accessible child with index ") + nIndex,
160cdf0e10cSrcweir             mxParent);
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     return GetChild (maVisibleChildren[nIndex],nIndex);
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 
168cdf0e10cSrcweir /** Return the requested accessible child object.  Create it if it is not
169cdf0e10cSrcweir     yet in the cache.
170cdf0e10cSrcweir */
171cdf0e10cSrcweir uno::Reference<XAccessible>
172cdf0e10cSrcweir     ChildrenManagerImpl::GetChild (ChildDescriptor& rChildDescriptor,sal_Int32 _nIndex)
173cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir     if ( ! rChildDescriptor.mxAccessibleShape.is())
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         ::osl::MutexGuard aGuard (maMutex);
178cdf0e10cSrcweir         // Make sure that the requested accessible object has not been
179cdf0e10cSrcweir         // created while locking the global mutex.
180cdf0e10cSrcweir         if ( ! rChildDescriptor.mxAccessibleShape.is())
181cdf0e10cSrcweir         {
182cdf0e10cSrcweir             AccessibleShapeInfo aShapeInfo(
183cdf0e10cSrcweir                         rChildDescriptor.mxShape,
184cdf0e10cSrcweir                         mxParent,
185cdf0e10cSrcweir                         this,
186cdf0e10cSrcweir                         mnNewNameIndex++);
187cdf0e10cSrcweir             // Create accessible object that corresponds to the descriptor's
188cdf0e10cSrcweir             // shape.
189cdf0e10cSrcweir             AccessibleShape* pShape =
190cdf0e10cSrcweir                 ShapeTypeHandler::Instance().CreateAccessibleObject (
191cdf0e10cSrcweir                     aShapeInfo,
192cdf0e10cSrcweir                     maShapeTreeInfo);
193cdf0e10cSrcweir             rChildDescriptor.mxAccessibleShape = uno::Reference<XAccessible> (
194cdf0e10cSrcweir                 static_cast<uno::XWeak*>(pShape),
195cdf0e10cSrcweir                 uno::UNO_QUERY);
196cdf0e10cSrcweir             // Now that there is a reference to the new accessible shape we
197cdf0e10cSrcweir             // can safely call its Init() method.
198cdf0e10cSrcweir             if ( pShape != NULL )
199cdf0e10cSrcweir 			{
200cdf0e10cSrcweir                 pShape->Init();
201cdf0e10cSrcweir 				pShape->setIndexInParent(_nIndex);
202cdf0e10cSrcweir 			}
203cdf0e10cSrcweir         }
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     return rChildDescriptor.mxAccessibleShape;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 
212cdf0e10cSrcweir uno::Reference<XAccessible>
213cdf0e10cSrcweir     ChildrenManagerImpl::GetChild (const uno::Reference<drawing::XShape>& xShape)
214cdf0e10cSrcweir     throw (uno::RuntimeException)
215cdf0e10cSrcweir {
216cdf0e10cSrcweir     ChildDescriptorListType::iterator I, aEnd = maVisibleChildren.end();
217cdf0e10cSrcweir     for (I = maVisibleChildren.begin(); I != aEnd; ++I)
218cdf0e10cSrcweir     {
219cdf0e10cSrcweir         if ( I->mxShape.get() == xShape.get() )
220cdf0e10cSrcweir             return I->mxAccessibleShape;
221cdf0e10cSrcweir     }
222cdf0e10cSrcweir     return uno::Reference<XAccessible> ();
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 
228cdf0e10cSrcweir /** Find all shapes among the specified shapes that lie fully or partially
229cdf0e10cSrcweir     inside the visible area.  Put those shapes into the cleared cache. The
230cdf0e10cSrcweir     corresponding accessible objects will be created on demand.
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     At the moment, first all accessible objects are removed from the cache
233cdf0e10cSrcweir     and the appropriate listeners are informed of this.  Next, the list is
234cdf0e10cSrcweir     created again.  This should be optimized in the future to not remove and
235cdf0e10cSrcweir     create objects that will be in the list before and after the update
236cdf0e10cSrcweir     method.
237cdf0e10cSrcweir */
238cdf0e10cSrcweir void ChildrenManagerImpl::Update (bool bCreateNewObjectsOnDemand)
239cdf0e10cSrcweir {
240cdf0e10cSrcweir     if (maShapeTreeInfo.GetViewForwarder() == NULL)
241cdf0e10cSrcweir         return;
242cdf0e10cSrcweir     Rectangle aVisibleArea = maShapeTreeInfo.GetViewForwarder()->GetVisibleArea();
243cdf0e10cSrcweir 
244cdf0e10cSrcweir     // 1. Create a local list of visible shapes.
245cdf0e10cSrcweir     ChildDescriptorListType aChildList;
246cdf0e10cSrcweir     CreateListOfVisibleShapes (aChildList);
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     // 2. Merge the information that is already known about the visible
249cdf0e10cSrcweir     // shapes from the current list into the new list.
250cdf0e10cSrcweir     MergeAccessibilityInformation (aChildList);
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     // 3. Replace the current list of visible shapes with the new one.  Do
253cdf0e10cSrcweir     // the same with the visible area.
254cdf0e10cSrcweir     {
255cdf0e10cSrcweir         ::osl::MutexGuard aGuard (maMutex);
256cdf0e10cSrcweir         adjustIndexInParentOfShapes(aChildList);
257cdf0e10cSrcweir 
258cdf0e10cSrcweir         // Use swap to copy the contents of the new list in constant time.
259cdf0e10cSrcweir         maVisibleChildren.swap (aChildList);
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         // aChildList now contains all the old children, while maVisibleChildren
262cdf0e10cSrcweir         // contains all the current children
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         // 4. Find all shapes in the old list that are not in the current list,
265cdf0e10cSrcweir         // send appropriate events and remove the accessible shape.
266cdf0e10cSrcweir         //
267cdf0e10cSrcweir         // Do this *after* we have set our new list of children, because
268cdf0e10cSrcweir         // removing a child may cause
269cdf0e10cSrcweir         //
270cdf0e10cSrcweir         // ChildDescriptor::disposeAccessibleObject -->
271cdf0e10cSrcweir         // AccessibleContextBase::CommitChange -->
272cdf0e10cSrcweir         // AtkListener::notifyEvent ->
273cdf0e10cSrcweir         // AtkListener::handleChildRemoved ->
274cdf0e10cSrcweir         // AtkListener::updateChildList
275cdf0e10cSrcweir         // AccessibleDrawDocumentView::getAccessibleChildCount ->
276cdf0e10cSrcweir         // ChildrenManagerImpl::GetChildCount ->
277cdf0e10cSrcweir         // maVisibleChildren.size()
278cdf0e10cSrcweir         //
279cdf0e10cSrcweir         // to be fired, and so the operations will take place on
280cdf0e10cSrcweir         // the list we are trying to replace
281cdf0e10cSrcweir         //
282cdf0e10cSrcweir         RemoveNonVisibleChildren (maVisibleChildren, aChildList);
283cdf0e10cSrcweir 
284cdf0e10cSrcweir         aChildList.clear();
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         maVisibleArea = aVisibleArea;
287cdf0e10cSrcweir     }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir     // 5. If the visible area has changed then send events that signal a
290cdf0e10cSrcweir     // change of their bounding boxes for all shapes that are members of
291cdf0e10cSrcweir     // both the current and the new list of visible shapes.
292cdf0e10cSrcweir     if (maVisibleArea != aVisibleArea)
293cdf0e10cSrcweir         SendVisibleAreaEvents (maVisibleChildren);
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     // 6. If children have to be created immediately and not on demand then
296cdf0e10cSrcweir     // create the missing accessible objects now.
297cdf0e10cSrcweir     if ( ! bCreateNewObjectsOnDemand)
298cdf0e10cSrcweir         CreateAccessibilityObjects (maVisibleChildren);
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 
304cdf0e10cSrcweir void ChildrenManagerImpl::CreateListOfVisibleShapes (
305cdf0e10cSrcweir     ChildDescriptorListType& raDescriptorList)
306cdf0e10cSrcweir {
307cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
308cdf0e10cSrcweir 
309cdf0e10cSrcweir     OSL_ASSERT (maShapeTreeInfo.GetViewForwarder() != NULL);
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     Rectangle aVisibleArea = maShapeTreeInfo.GetViewForwarder()->GetVisibleArea();
312cdf0e10cSrcweir 
313cdf0e10cSrcweir     // Add the visible shapes for wich the accessible objects already exist.
314cdf0e10cSrcweir     AccessibleShapeList::iterator I,aEnd = maAccessibleShapes.end();
315cdf0e10cSrcweir     for (I=maAccessibleShapes.begin(); I != aEnd; ++I)
316cdf0e10cSrcweir     {
317cdf0e10cSrcweir         if (I->is())
318cdf0e10cSrcweir         {
319cdf0e10cSrcweir             uno::Reference<XAccessibleComponent> xComponent (
320cdf0e10cSrcweir                 (*I)->getAccessibleContext(), uno::UNO_QUERY);
321cdf0e10cSrcweir             if (xComponent.is())
322cdf0e10cSrcweir             {
323cdf0e10cSrcweir                 // The bounding box of the object already is clipped to the
324cdf0e10cSrcweir                 // visible area.  The object is therefore visible if the
325cdf0e10cSrcweir                 // bounding box has non-zero extensions.
326cdf0e10cSrcweir                 awt::Rectangle aPixelBBox (xComponent->getBounds());
327cdf0e10cSrcweir                 if ((aPixelBBox.Width > 0) && (aPixelBBox.Height > 0))
328cdf0e10cSrcweir                     raDescriptorList.push_back (ChildDescriptor (*I));
329cdf0e10cSrcweir             }
330cdf0e10cSrcweir         }
331cdf0e10cSrcweir     }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir     // Add the visible shapes for which only the XShapes exist.
334cdf0e10cSrcweir     uno::Reference<container::XIndexAccess> xShapeAccess (mxShapeList, uno::UNO_QUERY);
335cdf0e10cSrcweir     if (xShapeAccess.is())
336cdf0e10cSrcweir     {
337cdf0e10cSrcweir         sal_Int32 nShapeCount = xShapeAccess->getCount();
338cdf0e10cSrcweir 		raDescriptorList.reserve( nShapeCount );
339cdf0e10cSrcweir 		awt::Point aPos;
340cdf0e10cSrcweir 		awt::Size aSize;
341cdf0e10cSrcweir 		Rectangle aBoundingBox;
342cdf0e10cSrcweir 		uno::Reference<drawing::XShape> xShape;
343cdf0e10cSrcweir         for (sal_Int32 i=0; i<nShapeCount; ++i)
344cdf0e10cSrcweir         {
345cdf0e10cSrcweir             xShapeAccess->getByIndex(i) >>= xShape;
346cdf0e10cSrcweir 			aPos = xShape->getPosition();
347cdf0e10cSrcweir 			aSize = xShape->getSize();
348cdf0e10cSrcweir 
349cdf0e10cSrcweir             aBoundingBox.nLeft = aPos.X;
350cdf0e10cSrcweir 			aBoundingBox.nTop = aPos.Y;
351cdf0e10cSrcweir 			aBoundingBox.nRight = aPos.X + aSize.Width;
352cdf0e10cSrcweir 			aBoundingBox.nBottom = aPos.Y + aSize.Height;
353cdf0e10cSrcweir 
354cdf0e10cSrcweir             // Insert shape if it is visible, i.e. its bounding box overlaps
355cdf0e10cSrcweir             // the visible area.
356cdf0e10cSrcweir             if ( aBoundingBox.IsOver (aVisibleArea) )
357cdf0e10cSrcweir                 raDescriptorList.push_back (ChildDescriptor (xShape));
358cdf0e10cSrcweir         }
359cdf0e10cSrcweir     }
360cdf0e10cSrcweir }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 
365cdf0e10cSrcweir void ChildrenManagerImpl::RemoveNonVisibleChildren (
366cdf0e10cSrcweir     const ChildDescriptorListType& rNewChildList,
367cdf0e10cSrcweir     ChildDescriptorListType& rOldChildList)
368cdf0e10cSrcweir {
369cdf0e10cSrcweir     // Iterate over list of formerly visible children and remove those that
370cdf0e10cSrcweir     // are not visible anymore, i.e. member of the new list of visible
371cdf0e10cSrcweir     // children.
372cdf0e10cSrcweir     ChildDescriptorListType::iterator I, aEnd = rOldChildList.end();
373cdf0e10cSrcweir     for (I=rOldChildList.begin(); I != aEnd; ++I)
374cdf0e10cSrcweir     {
375cdf0e10cSrcweir         if (::std::find(rNewChildList.begin(), rNewChildList.end(), *I) == rNewChildList.end())
376cdf0e10cSrcweir         {
377cdf0e10cSrcweir             // The child is disposed when there is a UNO shape from which
378cdf0e10cSrcweir             // the accessible shape can be created when the shape becomes
379cdf0e10cSrcweir             // visible again.  When there is no such UNO shape then simply
380cdf0e10cSrcweir             // reset the descriptor but keep the accessibility object.
381cdf0e10cSrcweir             if (I->mxShape.is())
382cdf0e10cSrcweir             {
383cdf0e10cSrcweir                 UnregisterAsDisposeListener (I->mxShape);
384cdf0e10cSrcweir                 I->disposeAccessibleObject (mrContext);
385cdf0e10cSrcweir             }
386cdf0e10cSrcweir             else
387cdf0e10cSrcweir             {
388cdf0e10cSrcweir                 AccessibleShape* pAccessibleShape = I->GetAccessibleShape();
389cdf0e10cSrcweir                 pAccessibleShape->ResetState (AccessibleStateType::VISIBLE);
390cdf0e10cSrcweir                 I->mxAccessibleShape = NULL;
391cdf0e10cSrcweir             }
392cdf0e10cSrcweir         }
393cdf0e10cSrcweir     }
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 
399cdf0e10cSrcweir void ChildrenManagerImpl::MergeAccessibilityInformation (
400cdf0e10cSrcweir     ChildDescriptorListType& raNewChildList)
401cdf0e10cSrcweir {
402cdf0e10cSrcweir     ChildDescriptorListType::iterator aOldChildDescriptor;
403cdf0e10cSrcweir     ChildDescriptorListType::iterator I, aEnd = raNewChildList.end();
404cdf0e10cSrcweir     for (I=raNewChildList.begin(); I != aEnd; ++I)
405cdf0e10cSrcweir     {
406cdf0e10cSrcweir         aOldChildDescriptor = ::std::find (maVisibleChildren.begin(), maVisibleChildren.end(), *I);
407cdf0e10cSrcweir 
408cdf0e10cSrcweir         // Copy accessible shape if that exists in the old descriptor.
409cdf0e10cSrcweir         bool bRegistrationIsNecessary = true;
410cdf0e10cSrcweir         if (aOldChildDescriptor != maVisibleChildren.end())
411cdf0e10cSrcweir             if (aOldChildDescriptor->mxAccessibleShape.is())
412cdf0e10cSrcweir             {
413cdf0e10cSrcweir                 I->mxAccessibleShape = aOldChildDescriptor->mxAccessibleShape;
414cdf0e10cSrcweir                 I->mbCreateEventPending = false;
415cdf0e10cSrcweir                 bRegistrationIsNecessary = false;
416cdf0e10cSrcweir             }
417cdf0e10cSrcweir         if (bRegistrationIsNecessary)
418cdf0e10cSrcweir             RegisterAsDisposeListener (I->mxShape);
419cdf0e10cSrcweir     }
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 
423cdf0e10cSrcweir 
424cdf0e10cSrcweir 
425cdf0e10cSrcweir void ChildrenManagerImpl::SendVisibleAreaEvents (
426cdf0e10cSrcweir     ChildDescriptorListType& raNewChildList)
427cdf0e10cSrcweir {
428cdf0e10cSrcweir     ChildDescriptorListType::iterator I,aEnd = raNewChildList.end();
429cdf0e10cSrcweir     for (I=raNewChildList.begin(); I != aEnd; ++I)
430cdf0e10cSrcweir     {
431cdf0e10cSrcweir         // Tell shape of changed visible area.  To do this, fake a
432cdf0e10cSrcweir         // change of the view forwarder.  (Actually we usually get here
433cdf0e10cSrcweir         // as a result of a change of the view forwarder).
434cdf0e10cSrcweir         AccessibleShape* pShape = I->GetAccessibleShape ();
435cdf0e10cSrcweir         if (pShape != NULL)
436cdf0e10cSrcweir             pShape->ViewForwarderChanged (
437cdf0e10cSrcweir                 IAccessibleViewForwarderListener::VISIBLE_AREA,
438cdf0e10cSrcweir                 maShapeTreeInfo.GetViewForwarder());
439cdf0e10cSrcweir     }
440cdf0e10cSrcweir }
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 
445cdf0e10cSrcweir void ChildrenManagerImpl::CreateAccessibilityObjects (
446cdf0e10cSrcweir     ChildDescriptorListType& raNewChildList)
447cdf0e10cSrcweir {
448cdf0e10cSrcweir     ChildDescriptorListType::iterator I, aEnd = raNewChildList.end();
449cdf0e10cSrcweir 	sal_Int32 nPos = 0;
450cdf0e10cSrcweir     for ( I = raNewChildList.begin(); I != aEnd; ++I,++nPos)
451cdf0e10cSrcweir     {
452cdf0e10cSrcweir         // Create the associated accessible object when the flag says so and
453cdf0e10cSrcweir         // it does not yet exist.
454cdf0e10cSrcweir         if ( ! I->mxAccessibleShape.is() )
455cdf0e10cSrcweir             GetChild (*I,nPos);
456cdf0e10cSrcweir         if (I->mxAccessibleShape.is() && I->mbCreateEventPending)
457cdf0e10cSrcweir         {
458cdf0e10cSrcweir             I->mbCreateEventPending = false;
459cdf0e10cSrcweir             mrContext.CommitChange (
460cdf0e10cSrcweir                 AccessibleEventId::CHILD,
461cdf0e10cSrcweir 				uno::makeAny(I->mxAccessibleShape),
462cdf0e10cSrcweir                 uno::Any());
463cdf0e10cSrcweir         }
464cdf0e10cSrcweir     }
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 
470cdf0e10cSrcweir void ChildrenManagerImpl::AddShape (const Reference<drawing::XShape>& rxShape)
471cdf0e10cSrcweir {
472cdf0e10cSrcweir     if (rxShape.is())
473cdf0e10cSrcweir     {
474cdf0e10cSrcweir         ::osl::ClearableMutexGuard aGuard (maMutex);
475cdf0e10cSrcweir 
476cdf0e10cSrcweir         // Test visibility of the shape.
477cdf0e10cSrcweir         Rectangle aVisibleArea = maShapeTreeInfo.GetViewForwarder()->GetVisibleArea();
478cdf0e10cSrcweir 		awt::Point aPos = rxShape->getPosition();
479cdf0e10cSrcweir 		awt::Size aSize = rxShape->getSize();
480cdf0e10cSrcweir 
481cdf0e10cSrcweir         Rectangle aBoundingBox (
482cdf0e10cSrcweir             aPos.X,
483cdf0e10cSrcweir             aPos.Y,
484cdf0e10cSrcweir             aPos.X + aSize.Width,
485cdf0e10cSrcweir             aPos.Y + aSize.Height);
486cdf0e10cSrcweir 
487cdf0e10cSrcweir         // Add the shape only when it belongs to the list of shapes stored
488cdf0e10cSrcweir         // in mxShapeList (which is either a page or a group shape).
489cdf0e10cSrcweir         Reference<container::XChild> xChild (rxShape, uno::UNO_QUERY);
490cdf0e10cSrcweir         if (xChild.is())
491cdf0e10cSrcweir         {
492cdf0e10cSrcweir             Reference<drawing::XShapes> xParent (xChild->getParent(), uno::UNO_QUERY);
493cdf0e10cSrcweir             if (xParent == mxShapeList)
494cdf0e10cSrcweir                 if (aBoundingBox.IsOver (aVisibleArea))
495cdf0e10cSrcweir                 {
496cdf0e10cSrcweir                     // Add shape to list of visible shapes.
497cdf0e10cSrcweir                     maVisibleChildren.push_back (ChildDescriptor (rxShape));
498cdf0e10cSrcweir 
499cdf0e10cSrcweir                     // Create accessibility object.
500cdf0e10cSrcweir                     ChildDescriptor& rDescriptor = maVisibleChildren.back();
501cdf0e10cSrcweir                     GetChild (rDescriptor, maVisibleChildren.size()-1);
502cdf0e10cSrcweir 
503cdf0e10cSrcweir                     // Inform listeners about new child.
504cdf0e10cSrcweir                     uno::Any aNewShape;
505cdf0e10cSrcweir                     aNewShape <<= rDescriptor.mxAccessibleShape;
506cdf0e10cSrcweir                     aGuard.clear();
507cdf0e10cSrcweir                     mrContext.CommitChange (
508cdf0e10cSrcweir                         AccessibleEventId::CHILD,
509cdf0e10cSrcweir                         aNewShape,
510cdf0e10cSrcweir                         uno::Any());
511cdf0e10cSrcweir                     RegisterAsDisposeListener (rDescriptor.mxShape);
512cdf0e10cSrcweir                 }
513cdf0e10cSrcweir         }
514cdf0e10cSrcweir     }
515cdf0e10cSrcweir }
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 
518cdf0e10cSrcweir 
519cdf0e10cSrcweir 
520cdf0e10cSrcweir void ChildrenManagerImpl::RemoveShape (const Reference<drawing::XShape>& rxShape)
521cdf0e10cSrcweir {
522cdf0e10cSrcweir     if (rxShape.is())
523cdf0e10cSrcweir     {
524cdf0e10cSrcweir         ::osl::ClearableMutexGuard aGuard (maMutex);
525cdf0e10cSrcweir 
526cdf0e10cSrcweir         // Search shape in list of visible children.
527cdf0e10cSrcweir         ChildDescriptorListType::iterator I (
528cdf0e10cSrcweir             ::std::find (maVisibleChildren.begin(), maVisibleChildren.end(),
529cdf0e10cSrcweir                 ChildDescriptor (rxShape)));
530cdf0e10cSrcweir         if (I != maVisibleChildren.end())
531cdf0e10cSrcweir         {
532cdf0e10cSrcweir             // Remove descriptor from that list.
533cdf0e10cSrcweir 			Reference<XAccessible> xAccessibleShape (I->mxAccessibleShape);
534cdf0e10cSrcweir 
535cdf0e10cSrcweir             UnregisterAsDisposeListener (I->mxShape);
536cdf0e10cSrcweir             // Dispose the accessible object.
537cdf0e10cSrcweir             I->disposeAccessibleObject (mrContext);
538cdf0e10cSrcweir 
539cdf0e10cSrcweir             // Now we can safely remove the child descriptor and thus
540cdf0e10cSrcweir             // invalidate the iterator.
541cdf0e10cSrcweir             maVisibleChildren.erase (I);
542cdf0e10cSrcweir 
543cdf0e10cSrcweir             adjustIndexInParentOfShapes(maVisibleChildren);
544cdf0e10cSrcweir         }
545cdf0e10cSrcweir     }
546cdf0e10cSrcweir }
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 
550cdf0e10cSrcweir 
551cdf0e10cSrcweir void ChildrenManagerImpl::SetShapeList (const ::com::sun::star::uno::Reference<
552cdf0e10cSrcweir     ::com::sun::star::drawing::XShapes>& xShapeList)
553cdf0e10cSrcweir {
554cdf0e10cSrcweir     mxShapeList = xShapeList;
555cdf0e10cSrcweir }
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 
560cdf0e10cSrcweir void ChildrenManagerImpl::AddAccessibleShape (std::auto_ptr<AccessibleShape> pShape)
561cdf0e10cSrcweir {
562cdf0e10cSrcweir     if (pShape.get() != NULL)
563cdf0e10cSrcweir         maAccessibleShapes.push_back (pShape.release());
564cdf0e10cSrcweir }
565cdf0e10cSrcweir 
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 
569cdf0e10cSrcweir void ChildrenManagerImpl::ClearAccessibleShapeList (void)
570cdf0e10cSrcweir {
571cdf0e10cSrcweir     // Copy the list of (visible) shapes to local lists and clear the
572cdf0e10cSrcweir     // originals.
573cdf0e10cSrcweir     ChildDescriptorListType aLocalVisibleChildren;
574cdf0e10cSrcweir     aLocalVisibleChildren.swap(maVisibleChildren);
575cdf0e10cSrcweir     AccessibleShapeList aLocalAccessibleShapes;
576cdf0e10cSrcweir     aLocalAccessibleShapes.swap(maAccessibleShapes);
577cdf0e10cSrcweir 
578cdf0e10cSrcweir     // Tell the listeners that all children are gone.
579cdf0e10cSrcweir     mrContext.CommitChange (
580cdf0e10cSrcweir         AccessibleEventId::INVALIDATE_ALL_CHILDREN,
581cdf0e10cSrcweir         uno::Any(),
582cdf0e10cSrcweir         uno::Any());
583cdf0e10cSrcweir 
584cdf0e10cSrcweir     // There are no accessible shapes left so the index assigned to new
585cdf0e10cSrcweir     // accessible shapes can be reset.
586cdf0e10cSrcweir     mnNewNameIndex = 1;
587cdf0e10cSrcweir 
588cdf0e10cSrcweir     // Now the objects in the local lists can be safely disposed without
589cdf0e10cSrcweir     // having problems with callers that want to update their child lists.
590cdf0e10cSrcweir 
591cdf0e10cSrcweir     // Clear the list of visible accessible objects.  Objects not created on
592cdf0e10cSrcweir     // demand for XShapes are treated below.
593cdf0e10cSrcweir     ChildDescriptorListType::iterator I,aEnd = aLocalVisibleChildren.end();
594cdf0e10cSrcweir     for (I=aLocalVisibleChildren.begin(); I != aEnd; ++I)
595cdf0e10cSrcweir         if ( I->mxAccessibleShape.is() && I->mxShape.is() )
596cdf0e10cSrcweir         {
597cdf0e10cSrcweir             ::comphelper::disposeComponent(I->mxAccessibleShape);
598cdf0e10cSrcweir             I->mxAccessibleShape = NULL;
599cdf0e10cSrcweir         }
600cdf0e10cSrcweir 
601cdf0e10cSrcweir     // Dispose all objects in the accessible shape list.
602cdf0e10cSrcweir     AccessibleShapeList::iterator J,aEnd2 = aLocalAccessibleShapes.end();
603cdf0e10cSrcweir     for (J=aLocalAccessibleShapes.begin(); J != aEnd2; ++J)
604cdf0e10cSrcweir         if (J->is())
605cdf0e10cSrcweir         {
606cdf0e10cSrcweir             // Dispose the object.
607cdf0e10cSrcweir 			::comphelper::disposeComponent(*J);
608cdf0e10cSrcweir             *J = NULL;
609cdf0e10cSrcweir         }
610cdf0e10cSrcweir }
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 
614cdf0e10cSrcweir 
615cdf0e10cSrcweir /** If the broadcasters change at which this object is registered then
616cdf0e10cSrcweir     unregister at old and register at new broadcasters.
617cdf0e10cSrcweir */
618cdf0e10cSrcweir void ChildrenManagerImpl::SetInfo (const AccessibleShapeTreeInfo& rShapeTreeInfo)
619cdf0e10cSrcweir {
620cdf0e10cSrcweir     // Remember the current broadcasters and exchange the shape tree info.
621cdf0e10cSrcweir     Reference<document::XEventBroadcaster> xCurrentBroadcaster;
622cdf0e10cSrcweir     Reference<frame::XController> xCurrentController;
623cdf0e10cSrcweir     Reference<view::XSelectionSupplier> xCurrentSelectionSupplier;
624cdf0e10cSrcweir     {
625cdf0e10cSrcweir         ::osl::MutexGuard aGuard (maMutex);
626cdf0e10cSrcweir         xCurrentBroadcaster = maShapeTreeInfo.GetModelBroadcaster();
627cdf0e10cSrcweir         xCurrentController = maShapeTreeInfo.GetController();
628cdf0e10cSrcweir         xCurrentSelectionSupplier = Reference<view::XSelectionSupplier> (
629cdf0e10cSrcweir             xCurrentController, uno::UNO_QUERY);
630cdf0e10cSrcweir         maShapeTreeInfo = rShapeTreeInfo;
631cdf0e10cSrcweir     }
632cdf0e10cSrcweir 
633cdf0e10cSrcweir     // Move registration to new model.
634cdf0e10cSrcweir     if (maShapeTreeInfo.GetModelBroadcaster() != xCurrentBroadcaster)
635cdf0e10cSrcweir     {
636cdf0e10cSrcweir         // Register at new broadcaster.
637cdf0e10cSrcweir         if (maShapeTreeInfo.GetModelBroadcaster().is())
638cdf0e10cSrcweir             maShapeTreeInfo.GetModelBroadcaster()->addEventListener (
639cdf0e10cSrcweir                 static_cast<document::XEventListener*>(this));
640cdf0e10cSrcweir 
641cdf0e10cSrcweir         // Unregister at old broadcaster.
642cdf0e10cSrcweir         if (xCurrentBroadcaster.is())
643cdf0e10cSrcweir             xCurrentBroadcaster->removeEventListener (
644cdf0e10cSrcweir                 static_cast<document::XEventListener*>(this));
645cdf0e10cSrcweir     }
646cdf0e10cSrcweir 
647cdf0e10cSrcweir     // Move registration to new selection supplier.
648cdf0e10cSrcweir     Reference<frame::XController> xNewController(maShapeTreeInfo.GetController());
649cdf0e10cSrcweir     Reference<view::XSelectionSupplier> xNewSelectionSupplier (
650cdf0e10cSrcweir         xNewController, uno::UNO_QUERY);
651cdf0e10cSrcweir     if (xNewSelectionSupplier != xCurrentSelectionSupplier)
652cdf0e10cSrcweir     {
653cdf0e10cSrcweir         // Register at new broadcaster.
654cdf0e10cSrcweir         if (xNewSelectionSupplier.is())
655cdf0e10cSrcweir         {
656cdf0e10cSrcweir             xNewController->addEventListener(
657cdf0e10cSrcweir                 static_cast<document::XEventListener*>(this));
658cdf0e10cSrcweir 
659cdf0e10cSrcweir             xNewSelectionSupplier->addSelectionChangeListener (
660cdf0e10cSrcweir                 static_cast<view::XSelectionChangeListener*>(this));
661cdf0e10cSrcweir         }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir         // Unregister at old broadcaster.
664cdf0e10cSrcweir         if (xCurrentSelectionSupplier.is())
665cdf0e10cSrcweir         {
666cdf0e10cSrcweir             xCurrentSelectionSupplier->removeSelectionChangeListener (
667cdf0e10cSrcweir                 static_cast<view::XSelectionChangeListener*>(this));
668cdf0e10cSrcweir 
669cdf0e10cSrcweir             xCurrentController->removeEventListener(
670cdf0e10cSrcweir                 static_cast<document::XEventListener*>(this));
671cdf0e10cSrcweir         }
672cdf0e10cSrcweir     }
673cdf0e10cSrcweir }
674cdf0e10cSrcweir 
675cdf0e10cSrcweir 
676cdf0e10cSrcweir 
677cdf0e10cSrcweir 
678cdf0e10cSrcweir //=====  lang::XEventListener  ================================================
679cdf0e10cSrcweir 
680cdf0e10cSrcweir void SAL_CALL
681cdf0e10cSrcweir     ChildrenManagerImpl::disposing (const lang::EventObject& rEventObject)
682cdf0e10cSrcweir     throw (uno::RuntimeException)
683cdf0e10cSrcweir {
684cdf0e10cSrcweir     if (rEventObject.Source == maShapeTreeInfo.GetModelBroadcaster()
685cdf0e10cSrcweir             || rEventObject.Source == maShapeTreeInfo.GetController())
686cdf0e10cSrcweir     {
687cdf0e10cSrcweir         impl_dispose();
688cdf0e10cSrcweir     }
689cdf0e10cSrcweir 
690cdf0e10cSrcweir     // Handle disposing UNO shapes.
691cdf0e10cSrcweir     else
692cdf0e10cSrcweir     {
693cdf0e10cSrcweir         Reference<drawing::XShape> xShape (rEventObject.Source, uno::UNO_QUERY);
694cdf0e10cSrcweir 
695cdf0e10cSrcweir         // Find the descriptor for the given shape.
696cdf0e10cSrcweir         ChildDescriptorListType::iterator I (
697cdf0e10cSrcweir             ::std::find (maVisibleChildren.begin(), maVisibleChildren.end(),
698cdf0e10cSrcweir                 ChildDescriptor (xShape)));
699cdf0e10cSrcweir         if (I != maVisibleChildren.end())
700cdf0e10cSrcweir         {
701cdf0e10cSrcweir             // Clear the descriptor.
702cdf0e10cSrcweir             I->disposeAccessibleObject (mrContext);
703cdf0e10cSrcweir             I->mxShape = NULL;
704cdf0e10cSrcweir         }
705cdf0e10cSrcweir     }
706cdf0e10cSrcweir }
707cdf0e10cSrcweir 
708cdf0e10cSrcweir 
709cdf0e10cSrcweir 
710cdf0e10cSrcweir 
711cdf0e10cSrcweir //=====  document::XEventListener  ============================================
712cdf0e10cSrcweir 
713cdf0e10cSrcweir /** Listen for new and removed shapes.
714cdf0e10cSrcweir */
715cdf0e10cSrcweir void SAL_CALL
716cdf0e10cSrcweir     ChildrenManagerImpl::notifyEvent (
717cdf0e10cSrcweir 		const document::EventObject& rEventObject)
718cdf0e10cSrcweir     throw (uno::RuntimeException)
719cdf0e10cSrcweir {
720cdf0e10cSrcweir     static const ::rtl::OUString sShapeInserted (
721cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM("ShapeInserted"));
722cdf0e10cSrcweir     static const ::rtl::OUString sShapeRemoved (
723cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM("ShapeRemoved"));
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 
726cdf0e10cSrcweir     if (rEventObject.EventName.equals (sShapeInserted))
727cdf0e10cSrcweir         AddShape (Reference<drawing::XShape>(rEventObject.Source, uno::UNO_QUERY));
728cdf0e10cSrcweir     else if (rEventObject.EventName.equals (sShapeRemoved))
729cdf0e10cSrcweir         RemoveShape (Reference<drawing::XShape>(rEventObject.Source, uno::UNO_QUERY));
730cdf0e10cSrcweir     // else ignore unknown event.
731cdf0e10cSrcweir }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 
735cdf0e10cSrcweir 
736cdf0e10cSrcweir //=====  view::XSelectionChangeListener  ======================================
737cdf0e10cSrcweir 
738cdf0e10cSrcweir void  SAL_CALL
739cdf0e10cSrcweir     ChildrenManagerImpl::selectionChanged (const lang::EventObject& /*rEvent*/)
740cdf0e10cSrcweir         throw (uno::RuntimeException)
741cdf0e10cSrcweir {
742cdf0e10cSrcweir     UpdateSelection ();
743cdf0e10cSrcweir }
744cdf0e10cSrcweir 
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 
747cdf0e10cSrcweir 
748cdf0e10cSrcweir void ChildrenManagerImpl::impl_dispose (void)
749cdf0e10cSrcweir {
750cdf0e10cSrcweir     Reference<frame::XController> xController(maShapeTreeInfo.GetController());
751cdf0e10cSrcweir     // Remove from broadcasters.
752cdf0e10cSrcweir     try
753cdf0e10cSrcweir     {
754cdf0e10cSrcweir         Reference<view::XSelectionSupplier> xSelectionSupplier (
755cdf0e10cSrcweir             xController, uno::UNO_QUERY);
756cdf0e10cSrcweir         if (xSelectionSupplier.is())
757cdf0e10cSrcweir         {
758cdf0e10cSrcweir             xSelectionSupplier->removeSelectionChangeListener (
759cdf0e10cSrcweir                 static_cast<view::XSelectionChangeListener*>(this));
760cdf0e10cSrcweir         }
761cdf0e10cSrcweir     }
762cdf0e10cSrcweir     catch( uno::RuntimeException&)
763cdf0e10cSrcweir     {}
764cdf0e10cSrcweir 
765cdf0e10cSrcweir     try
766cdf0e10cSrcweir     {
767cdf0e10cSrcweir         if (xController.is())
768cdf0e10cSrcweir             xController->removeEventListener(
769cdf0e10cSrcweir                 static_cast<document::XEventListener*>(this));
770cdf0e10cSrcweir     }
771cdf0e10cSrcweir     catch( uno::RuntimeException&)
772cdf0e10cSrcweir     {}
773cdf0e10cSrcweir 
774cdf0e10cSrcweir     maShapeTreeInfo.SetController (NULL);
775cdf0e10cSrcweir 
776cdf0e10cSrcweir     try
777cdf0e10cSrcweir     {
778cdf0e10cSrcweir         // Remove from broadcaster.
779cdf0e10cSrcweir         if (maShapeTreeInfo.GetModelBroadcaster().is())
780cdf0e10cSrcweir             maShapeTreeInfo.GetModelBroadcaster()->removeEventListener (
781cdf0e10cSrcweir                 static_cast<document::XEventListener*>(this));
782cdf0e10cSrcweir         maShapeTreeInfo.SetModelBroadcaster (NULL);
783cdf0e10cSrcweir     }
784cdf0e10cSrcweir     catch( uno::RuntimeException& )
785cdf0e10cSrcweir     {}
786cdf0e10cSrcweir 
787cdf0e10cSrcweir     ClearAccessibleShapeList ();
788cdf0e10cSrcweir     SetShapeList (NULL);
789cdf0e10cSrcweir }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 
792cdf0e10cSrcweir 
793cdf0e10cSrcweir void SAL_CALL ChildrenManagerImpl::disposing (void)
794cdf0e10cSrcweir {
795cdf0e10cSrcweir     impl_dispose();
796cdf0e10cSrcweir }
797cdf0e10cSrcweir 
798cdf0e10cSrcweir 
799cdf0e10cSrcweir 
800cdf0e10cSrcweir 
801cdf0e10cSrcweir // This method is experimental.  Use with care.
802cdf0e10cSrcweir long int ChildrenManagerImpl::GetChildIndex (const ::com::sun::star::uno::Reference<
803cdf0e10cSrcweir     ::com::sun::star::accessibility::XAccessible>& xChild) const
804cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
805cdf0e10cSrcweir {
806cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
807cdf0e10cSrcweir 	sal_Int32 nCount = maVisibleChildren.size();
808cdf0e10cSrcweir     for (sal_Int32 i=0; i < nCount; ++i)
809cdf0e10cSrcweir     {
810cdf0e10cSrcweir         // Is this equality comparison valid?
811cdf0e10cSrcweir         if (maVisibleChildren[i].mxAccessibleShape == xChild)
812cdf0e10cSrcweir             return i;
813cdf0e10cSrcweir     }
814cdf0e10cSrcweir 
815cdf0e10cSrcweir     return -1;
816cdf0e10cSrcweir }
817cdf0e10cSrcweir 
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 
820cdf0e10cSrcweir 
821cdf0e10cSrcweir //=====  IAccessibleViewForwarderListener  ====================================
822cdf0e10cSrcweir 
823cdf0e10cSrcweir void ChildrenManagerImpl::ViewForwarderChanged (ChangeType aChangeType,
824cdf0e10cSrcweir         const IAccessibleViewForwarder* pViewForwarder)
825cdf0e10cSrcweir {
826cdf0e10cSrcweir     if (aChangeType == IAccessibleViewForwarderListener::VISIBLE_AREA)
827cdf0e10cSrcweir         Update (false);
828cdf0e10cSrcweir     else
829cdf0e10cSrcweir     {
830cdf0e10cSrcweir         ::osl::MutexGuard aGuard (maMutex);
831cdf0e10cSrcweir 		ChildDescriptorListType::iterator I, aEnd = maVisibleChildren.end();
832cdf0e10cSrcweir 		for (I=maVisibleChildren.begin(); I != aEnd; ++I)
833cdf0e10cSrcweir         {
834cdf0e10cSrcweir             AccessibleShape* pShape = I->GetAccessibleShape();
835cdf0e10cSrcweir             if (pShape != NULL)
836cdf0e10cSrcweir                 pShape->ViewForwarderChanged (aChangeType, pViewForwarder);
837cdf0e10cSrcweir         }
838cdf0e10cSrcweir     }
839cdf0e10cSrcweir }
840cdf0e10cSrcweir 
841cdf0e10cSrcweir 
842cdf0e10cSrcweir 
843cdf0e10cSrcweir 
844cdf0e10cSrcweir //=====  IAccessibleParent  ===================================================
845cdf0e10cSrcweir 
846cdf0e10cSrcweir sal_Bool ChildrenManagerImpl::ReplaceChild (
847cdf0e10cSrcweir     AccessibleShape* pCurrentChild,
848cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& _rxShape,
849cdf0e10cSrcweir 	const long _nIndex,
850cdf0e10cSrcweir 	const AccessibleShapeTreeInfo& _rShapeTreeInfo)
851cdf0e10cSrcweir     throw (uno::RuntimeException)
852cdf0e10cSrcweir {
853cdf0e10cSrcweir     AccessibleShapeInfo aShapeInfo( _rxShape, pCurrentChild->getAccessibleParent(), this, _nIndex );
854cdf0e10cSrcweir 	// create the new child
855cdf0e10cSrcweir 	AccessibleShape* pNewChild = ShapeTypeHandler::Instance().CreateAccessibleObject (
856cdf0e10cSrcweir         aShapeInfo,
857cdf0e10cSrcweir 		_rShapeTreeInfo
858cdf0e10cSrcweir 	);
859cdf0e10cSrcweir 	Reference< XAccessible > xNewChild( pNewChild );	// keep this alive (do this before calling Init!)
860cdf0e10cSrcweir 	if ( pNewChild )
861cdf0e10cSrcweir 		pNewChild->Init();
862cdf0e10cSrcweir 
863cdf0e10cSrcweir     sal_Bool bResult = sal_False;
864cdf0e10cSrcweir 
865cdf0e10cSrcweir     // Iterate over the visible children.  If one of them has an already
866cdf0e10cSrcweir     // created accessible object that matches pCurrentChild then replace
867cdf0e10cSrcweir     // it.  Otherwise the child to replace is either not in the list or has
868cdf0e10cSrcweir     // not ye been created (and is therefore not in the list, too) and a
869cdf0e10cSrcweir     // replacement is not necessary.
870cdf0e10cSrcweir     ChildDescriptorListType::iterator I,aEnd = maVisibleChildren.end();
871cdf0e10cSrcweir     for (I=maVisibleChildren.begin(); I != aEnd; ++I)
872cdf0e10cSrcweir     {
873cdf0e10cSrcweir         if (I->GetAccessibleShape() == pCurrentChild)
874cdf0e10cSrcweir         {
875cdf0e10cSrcweir             // Dispose the current child and send an event about its deletion.
876cdf0e10cSrcweir             pCurrentChild->dispose();
877cdf0e10cSrcweir             mrContext.CommitChange (
878cdf0e10cSrcweir                 AccessibleEventId::CHILD,
879cdf0e10cSrcweir                 uno::Any(),
880cdf0e10cSrcweir                 uno::makeAny (I->mxAccessibleShape));
881cdf0e10cSrcweir 
882cdf0e10cSrcweir             // Replace with replacement and send an event about existance
883cdf0e10cSrcweir             // of the new child.
884cdf0e10cSrcweir             I->mxAccessibleShape = pNewChild;
885cdf0e10cSrcweir             mrContext.CommitChange (
886cdf0e10cSrcweir                 AccessibleEventId::CHILD,
887cdf0e10cSrcweir                 uno::makeAny (I->mxAccessibleShape),
888cdf0e10cSrcweir                 uno::Any());
889cdf0e10cSrcweir             bResult = sal_True;
890cdf0e10cSrcweir             break;
891cdf0e10cSrcweir         }
892cdf0e10cSrcweir     }
893cdf0e10cSrcweir 
894cdf0e10cSrcweir     // When not found among the visible children we have to search the list
895cdf0e10cSrcweir     // of accessible shapes.  This is not yet implemented.
896cdf0e10cSrcweir 
897cdf0e10cSrcweir     return bResult;
898cdf0e10cSrcweir }
899*9b8096d0SSteve Yin //IAccessibility2 Implementation 2009-----
900*9b8096d0SSteve Yin // Add the impl method for IAccessibleParent interface
901*9b8096d0SSteve Yin AccessibleControlShape * ChildrenManagerImpl::GetAccControlShapeFromModel(::com::sun::star::beans::XPropertySet* pSet) throw (::com::sun::star::uno::RuntimeException)
902*9b8096d0SSteve Yin {
903*9b8096d0SSteve Yin 	sal_Int32 count = GetChildCount();
904*9b8096d0SSteve Yin 	for (sal_Int32 index=0;index<count;index++)
905*9b8096d0SSteve Yin 	{
906*9b8096d0SSteve Yin 		AccessibleShape* pAccShape = maVisibleChildren[index].GetAccessibleShape();
907*9b8096d0SSteve Yin       	 	if (pAccShape  && ::accessibility::ShapeTypeHandler::Instance().GetTypeId (pAccShape->GetXShape()) == DRAWING_CONTROL)
908*9b8096d0SSteve Yin       	  	{
909*9b8096d0SSteve Yin 			::accessibility::AccessibleControlShape *pCtlAccShape = static_cast < ::accessibility::AccessibleControlShape* >(pAccShape);
910*9b8096d0SSteve Yin 			if (pCtlAccShape && pCtlAccShape->GetControlModel() == pSet)
911*9b8096d0SSteve Yin 				return pCtlAccShape;
912*9b8096d0SSteve Yin             	}
913*9b8096d0SSteve Yin 	}
914*9b8096d0SSteve Yin 	return NULL;
915*9b8096d0SSteve Yin }
916*9b8096d0SSteve Yin uno::Reference<XAccessible>
917*9b8096d0SSteve Yin     ChildrenManagerImpl::GetAccessibleCaption (const uno::Reference<drawing::XShape>& xShape)
918*9b8096d0SSteve Yin     throw (uno::RuntimeException)
919*9b8096d0SSteve Yin {
920*9b8096d0SSteve Yin     ChildDescriptorListType::iterator I, aEnd = maVisibleChildren.end();
921*9b8096d0SSteve Yin     for (I = maVisibleChildren.begin(); I != aEnd; ++I)
922*9b8096d0SSteve Yin     {
923*9b8096d0SSteve Yin         if ( I->mxShape.get() == xShape.get() )
924*9b8096d0SSteve Yin             return I->mxAccessibleShape;
925*9b8096d0SSteve Yin     }
926*9b8096d0SSteve Yin     return uno::Reference<XAccessible> ();
927*9b8096d0SSteve Yin }
928*9b8096d0SSteve Yin //-----IAccessibility2 Implementation 2009
929cdf0e10cSrcweir 
930cdf0e10cSrcweir /** Update the <const>SELECTED</const> and the <const>FOCUSED</const> state
931cdf0e10cSrcweir     of all visible children.  Maybe this should be changed to all children.
932cdf0e10cSrcweir 
933cdf0e10cSrcweir     Iterate over all descriptors of visible accessible shapes and look them
934cdf0e10cSrcweir     up in the selection.
935cdf0e10cSrcweir 
936cdf0e10cSrcweir     If there is no valid controller then all shapes are deselected and
937cdf0e10cSrcweir     unfocused.  If the controller's frame is not active then all shapes are
938cdf0e10cSrcweir     unfocused.
939cdf0e10cSrcweir */
940cdf0e10cSrcweir void ChildrenManagerImpl::UpdateSelection (void)
941cdf0e10cSrcweir {
942cdf0e10cSrcweir     Reference<frame::XController> xController(maShapeTreeInfo.GetController());
943cdf0e10cSrcweir     Reference<view::XSelectionSupplier> xSelectionSupplier (
944cdf0e10cSrcweir         xController, uno::UNO_QUERY);
945cdf0e10cSrcweir 
946cdf0e10cSrcweir     // Try to cast the selection both to a multi selection and to a single
947cdf0e10cSrcweir     // selection.
948cdf0e10cSrcweir     Reference<container::XIndexAccess> xSelectedShapeAccess;
949cdf0e10cSrcweir     Reference<drawing::XShape> xSelectedShape;
950cdf0e10cSrcweir     if (xSelectionSupplier.is())
951cdf0e10cSrcweir     {
952cdf0e10cSrcweir         xSelectedShapeAccess = Reference<container::XIndexAccess> (
953cdf0e10cSrcweir             xSelectionSupplier->getSelection(), uno::UNO_QUERY);
954cdf0e10cSrcweir         xSelectedShape = Reference<drawing::XShape> (
955cdf0e10cSrcweir             xSelectionSupplier->getSelection(), uno::UNO_QUERY);
956cdf0e10cSrcweir     }
957cdf0e10cSrcweir 
958cdf0e10cSrcweir     // Remember the current and new focused shape.
959cdf0e10cSrcweir     AccessibleShape* pCurrentlyFocusedShape = NULL;
960cdf0e10cSrcweir     AccessibleShape* pNewFocusedShape = NULL;
961*9b8096d0SSteve Yin //IAccessibility2 Implementation 2009-----
962*9b8096d0SSteve Yin 	typedef std::pair< AccessibleShape* , sal_Bool > PAIR_SHAPE;//sal_Bool Selected,UnSelected.
963*9b8096d0SSteve Yin 	typedef std::vector< PAIR_SHAPE > VEC_SHAPE;
964*9b8096d0SSteve Yin 	VEC_SHAPE vecSelect;
965*9b8096d0SSteve Yin 	int nAddSelect=0;
966*9b8096d0SSteve Yin 	int nRemoveSelect=0;
967*9b8096d0SSteve Yin 	sal_Bool bHasSelectedShape=sal_False;
968*9b8096d0SSteve Yin //-----IAccessibility2 Implementation 2009
969cdf0e10cSrcweir     ChildDescriptorListType::iterator I, aEnd = maVisibleChildren.end();
970cdf0e10cSrcweir     for (I=maVisibleChildren.begin(); I != aEnd; ++I)
971cdf0e10cSrcweir     {
972cdf0e10cSrcweir         AccessibleShape* pAccessibleShape = I->GetAccessibleShape();
973cdf0e10cSrcweir         if (I->mxAccessibleShape.is() && I->mxShape.is() && pAccessibleShape!=NULL)
974cdf0e10cSrcweir         {
975*9b8096d0SSteve Yin 	//IAccessibility2 Implementation 2009-----
976*9b8096d0SSteve Yin 			short nRole = pAccessibleShape->getAccessibleRole();
977*9b8096d0SSteve Yin 			bool bDrawShape = (
978*9b8096d0SSteve Yin 				nRole == AccessibleRole::GRAPHIC ||
979*9b8096d0SSteve Yin 				nRole == AccessibleRole::EMBEDDED_OBJECT ||
980*9b8096d0SSteve Yin 				nRole == AccessibleRole::SHAPE ||
981*9b8096d0SSteve Yin 				nRole == AccessibleRole::IMAGE_MAP ||
982*9b8096d0SSteve Yin 				nRole == AccessibleRole::TABLE_CELL ||
983*9b8096d0SSteve Yin 				nRole == AccessibleRole::TABLE );
984*9b8096d0SSteve Yin //-----IAccessibility2 Implementation 2009
985cdf0e10cSrcweir             bool bShapeIsSelected = false;
986cdf0e10cSrcweir 
987cdf0e10cSrcweir             // Look up the shape in the (single or multi-) selection.
988cdf0e10cSrcweir             if (xSelectedShape.is())
989cdf0e10cSrcweir             {
990cdf0e10cSrcweir                 if  (I->mxShape == xSelectedShape)
991cdf0e10cSrcweir                 {
992cdf0e10cSrcweir                     bShapeIsSelected = true;
993cdf0e10cSrcweir                     pNewFocusedShape = pAccessibleShape;
994cdf0e10cSrcweir                 }
995cdf0e10cSrcweir             }
996cdf0e10cSrcweir             else if (xSelectedShapeAccess.is())
997cdf0e10cSrcweir             {
998cdf0e10cSrcweir                 sal_Int32 nCount=xSelectedShapeAccess->getCount();
999cdf0e10cSrcweir                 for (sal_Int32 i=0; i<nCount&&!bShapeIsSelected; i++)
1000cdf0e10cSrcweir                     if (xSelectedShapeAccess->getByIndex(i) == I->mxShape)
1001cdf0e10cSrcweir                     {
1002cdf0e10cSrcweir                         bShapeIsSelected = true;
1003cdf0e10cSrcweir                         // In a multi-selection no shape has the focus.
1004cdf0e10cSrcweir                         if (nCount == 1)
1005cdf0e10cSrcweir                             pNewFocusedShape = pAccessibleShape;
1006cdf0e10cSrcweir                     }
1007cdf0e10cSrcweir             }
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir             // Set or reset the SELECTED state.
1010cdf0e10cSrcweir             if (bShapeIsSelected)
1011*9b8096d0SSteve Yin 	    //IAccessibility2 Implementation 2009-----
1012*9b8096d0SSteve Yin                 //pAccessibleShape->SetState (AccessibleStateType::SELECTED);
1013*9b8096d0SSteve Yin 			{
1014*9b8096d0SSteve Yin 				if (pAccessibleShape->SetState (AccessibleStateType::SELECTED))
1015*9b8096d0SSteve Yin 				{
1016*9b8096d0SSteve Yin 					if (bDrawShape)
1017*9b8096d0SSteve Yin 					{
1018*9b8096d0SSteve Yin 						vecSelect.push_back(std::make_pair(pAccessibleShape,sal_True));
1019*9b8096d0SSteve Yin 						++nAddSelect;
1020*9b8096d0SSteve Yin 					}
1021*9b8096d0SSteve Yin 				}
1022*9b8096d0SSteve Yin 				else
1023*9b8096d0SSteve Yin 				{//Selected not change,has selected shape before
1024*9b8096d0SSteve Yin 					bHasSelectedShape=sal_True;
1025*9b8096d0SSteve Yin 				}
1026*9b8096d0SSteve Yin 			}
1027cdf0e10cSrcweir             else
1028*9b8096d0SSteve Yin                 //pAccessibleShape->ResetState (AccessibleStateType::SELECTED);
1029*9b8096d0SSteve Yin 			{
1030*9b8096d0SSteve Yin                 if(pAccessibleShape->ResetState (AccessibleStateType::SELECTED))
1031*9b8096d0SSteve Yin 				{
1032*9b8096d0SSteve Yin 					if(bDrawShape)
1033*9b8096d0SSteve Yin 					{
1034*9b8096d0SSteve Yin 						vecSelect.push_back(std::make_pair(pAccessibleShape,sal_False));
1035*9b8096d0SSteve Yin 						++nRemoveSelect;
1036*9b8096d0SSteve Yin 					}
1037*9b8096d0SSteve Yin 				}
1038*9b8096d0SSteve Yin 			}
1039*9b8096d0SSteve Yin //-----IAccessibility2 Implementation 2009
1040cdf0e10cSrcweir             // Does the shape have the current selection?
1041cdf0e10cSrcweir             if (pAccessibleShape->GetState (AccessibleStateType::FOCUSED))
1042cdf0e10cSrcweir                 pCurrentlyFocusedShape = pAccessibleShape;
1043cdf0e10cSrcweir         }
1044cdf0e10cSrcweir     }
1045*9b8096d0SSteve Yin //IAccessibility2 Implementation 2009-----
1046*9b8096d0SSteve Yin     /*
1047cdf0e10cSrcweir     // Check if the frame we are in is currently active.  If not then make
1048cdf0e10cSrcweir     // sure to not send a FOCUSED state change.
1049cdf0e10cSrcweir     if (xController.is())
1050cdf0e10cSrcweir     {
1051cdf0e10cSrcweir         Reference<frame::XFrame> xFrame (xController->getFrame());
1052cdf0e10cSrcweir         if (xFrame.is())
1053cdf0e10cSrcweir             if ( ! xFrame->isActive())
1054cdf0e10cSrcweir                 pNewFocusedShape = NULL;
1055cdf0e10cSrcweir     }
1056*9b8096d0SSteve Yin     */
1057*9b8096d0SSteve Yin 	Window *pParentWidow = maShapeTreeInfo.GetWindow();
1058*9b8096d0SSteve Yin 	bool bShapeActive= false;
1059*9b8096d0SSteve Yin 	// Sym2_6146, For table cell, the table's parent must be checked to make sure it has focus.
1060*9b8096d0SSteve Yin 	Window *pPWindow = pParentWidow->GetParent();
1061*9b8096d0SSteve Yin 	if (pParentWidow && ( pParentWidow->HasFocus() || (pPWindow && pPWindow->HasFocus())))
1062*9b8096d0SSteve Yin 	{
1063*9b8096d0SSteve Yin 		bShapeActive =true;
1064*9b8096d0SSteve Yin 	}
1065*9b8096d0SSteve Yin //-----IAccessibility2 Implementation 2009
1066cdf0e10cSrcweir     // Move focus from current to newly focused shape.
1067cdf0e10cSrcweir     if (pCurrentlyFocusedShape != pNewFocusedShape)
1068cdf0e10cSrcweir     {
1069cdf0e10cSrcweir         if (pCurrentlyFocusedShape != NULL)
1070cdf0e10cSrcweir             pCurrentlyFocusedShape->ResetState (AccessibleStateType::FOCUSED);
1071*9b8096d0SSteve Yin 	    //IAccessibility2 Implementation 2009-----
1072*9b8096d0SSteve Yin         //if (pNewFocusedShape != NULL)
1073*9b8096d0SSteve Yin 	//-----IAccessibility2 Implementation 2009
1074*9b8096d0SSteve Yin 	if (pNewFocusedShape != NULL && bShapeActive)
1075cdf0e10cSrcweir             pNewFocusedShape->SetState (AccessibleStateType::FOCUSED);
1076*9b8096d0SSteve Yin 	}
1077*9b8096d0SSteve Yin //IAccessibility2 Implementation 2009-----
1078*9b8096d0SSteve Yin 
1079*9b8096d0SSteve Yin 	if (nAddSelect >= 10 )//fire selection  within
1080*9b8096d0SSteve Yin 	{
1081*9b8096d0SSteve Yin 		mrContext.CommitChange(AccessibleEventId::SELECTION_CHANGED_WITHIN,uno::Any(),uno::Any());
1082*9b8096d0SSteve Yin 		nAddSelect =0 ;//not fire selection event
1083*9b8096d0SSteve Yin 	}
1084*9b8096d0SSteve Yin 	//VEC_SHAPE::iterator vi = vecSelect.begin();
1085*9b8096d0SSteve Yin 	//for (; vi != vecSelect.end() ;++vi)
1086*9b8096d0SSteve Yin 	VEC_SHAPE::reverse_iterator vi = vecSelect.rbegin();
1087*9b8096d0SSteve Yin 	for (; vi != vecSelect.rend() ;++vi)
1088*9b8096d0SSteve Yin 
1089*9b8096d0SSteve Yin 	{
1090*9b8096d0SSteve Yin 		PAIR_SHAPE &pairShape= *vi;
1091*9b8096d0SSteve Yin 		Reference< XAccessible > xShape(pairShape.first);
1092*9b8096d0SSteve Yin 		uno::Any anyShape;
1093*9b8096d0SSteve Yin 		anyShape <<= xShape;
1094*9b8096d0SSteve Yin 
1095*9b8096d0SSteve Yin 		if (pairShape.second)//Selection add
1096*9b8096d0SSteve Yin 		{
1097*9b8096d0SSteve Yin 			if (bHasSelectedShape)
1098*9b8096d0SSteve Yin 			{
1099*9b8096d0SSteve Yin 				if (  nAddSelect > 0 )
1100*9b8096d0SSteve Yin 				{
1101*9b8096d0SSteve Yin 					mrContext.CommitChange(AccessibleEventId::SELECTION_CHANGED_ADD,anyShape,uno::Any());
1102*9b8096d0SSteve Yin 				}
1103*9b8096d0SSteve Yin 			}
1104*9b8096d0SSteve Yin 			else
1105*9b8096d0SSteve Yin 			{
1106*9b8096d0SSteve Yin 				//if has not selected shape ,first selected shape is fire selection event;
1107*9b8096d0SSteve Yin 				if (nAddSelect > 0 )
1108*9b8096d0SSteve Yin 				{
1109*9b8096d0SSteve Yin 					mrContext.CommitChange(AccessibleEventId::SELECTION_CHANGED,anyShape,uno::Any());
1110*9b8096d0SSteve Yin 				}
1111*9b8096d0SSteve Yin 				if (nAddSelect > 1 )//check other selected shape fire selection add event
1112*9b8096d0SSteve Yin 				{
1113*9b8096d0SSteve Yin 					bHasSelectedShape=sal_True;
1114*9b8096d0SSteve Yin 				}
1115*9b8096d0SSteve Yin 			}
1116*9b8096d0SSteve Yin 		}
1117*9b8096d0SSteve Yin 		else //selection remove
1118*9b8096d0SSteve Yin 		{
1119*9b8096d0SSteve Yin 			mrContext.CommitChange(AccessibleEventId::SELECTION_CHANGED_REMOVE,anyShape,uno::Any());
1120*9b8096d0SSteve Yin 		}
1121*9b8096d0SSteve Yin 	}
1122*9b8096d0SSteve Yin //-----IAccessibility2 Implementation 2009
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir     // Remember whether there is a shape that now has the focus.
1125cdf0e10cSrcweir     mpFocusedShape = pNewFocusedShape;
1126cdf0e10cSrcweir }
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir bool ChildrenManagerImpl::HasFocus (void)
1132cdf0e10cSrcweir {
1133cdf0e10cSrcweir     return mpFocusedShape != NULL;
1134cdf0e10cSrcweir }
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir 
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir void ChildrenManagerImpl::RemoveFocus (void)
1140cdf0e10cSrcweir {
1141cdf0e10cSrcweir     if (mpFocusedShape != NULL)
1142cdf0e10cSrcweir     {
1143cdf0e10cSrcweir         mpFocusedShape->ResetState (AccessibleStateType::FOCUSED);
1144cdf0e10cSrcweir         mpFocusedShape = NULL;
1145cdf0e10cSrcweir     }
1146cdf0e10cSrcweir }
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir void ChildrenManagerImpl::RegisterAsDisposeListener (
1151cdf0e10cSrcweir     const Reference<drawing::XShape>& xShape)
1152cdf0e10cSrcweir {
1153cdf0e10cSrcweir     Reference<lang::XComponent> xComponent (xShape, uno::UNO_QUERY);
1154cdf0e10cSrcweir     if (xComponent.is())
1155cdf0e10cSrcweir         xComponent->addEventListener (
1156cdf0e10cSrcweir             static_cast<document::XEventListener*>(this));
1157cdf0e10cSrcweir }
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir void ChildrenManagerImpl::UnregisterAsDisposeListener (
1163cdf0e10cSrcweir     const Reference<drawing::XShape>& xShape)
1164cdf0e10cSrcweir {
1165cdf0e10cSrcweir     Reference<lang::XComponent> xComponent (xShape, uno::UNO_QUERY);
1166cdf0e10cSrcweir     if (xComponent.is())
1167cdf0e10cSrcweir         xComponent->removeEventListener (
1168cdf0e10cSrcweir             static_cast<document::XEventListener*>(this));
1169cdf0e10cSrcweir }
1170cdf0e10cSrcweir 
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir //=====  AccessibleChildDescriptor  ===========================================
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir ChildDescriptor::ChildDescriptor (const Reference<drawing::XShape>& xShape)
1177cdf0e10cSrcweir     : mxShape (xShape),
1178cdf0e10cSrcweir       mxAccessibleShape (NULL),
1179cdf0e10cSrcweir       mbCreateEventPending (true)
1180cdf0e10cSrcweir {
1181cdf0e10cSrcweir     // Empty.
1182cdf0e10cSrcweir }
1183cdf0e10cSrcweir 
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir 
1186cdf0e10cSrcweir 
1187cdf0e10cSrcweir ChildDescriptor::ChildDescriptor (const Reference<XAccessible>& rxAccessibleShape)
1188cdf0e10cSrcweir     : mxShape (NULL),
1189cdf0e10cSrcweir       mxAccessibleShape (rxAccessibleShape),
1190cdf0e10cSrcweir       mbCreateEventPending (true)
1191cdf0e10cSrcweir {
1192cdf0e10cSrcweir     // Make sure that the accessible object has the <const>VISIBLE</const>
1193cdf0e10cSrcweir     // state set.
1194cdf0e10cSrcweir     AccessibleShape* pAccessibleShape = GetAccessibleShape();
1195cdf0e10cSrcweir     pAccessibleShape->SetState (AccessibleStateType::VISIBLE);
1196cdf0e10cSrcweir }
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir 
1199cdf0e10cSrcweir 
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir ChildDescriptor::~ChildDescriptor (void)
1202cdf0e10cSrcweir {
1203cdf0e10cSrcweir }
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir 
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir AccessibleShape* ChildDescriptor::GetAccessibleShape (void) const
1209cdf0e10cSrcweir {
1210cdf0e10cSrcweir     return static_cast<AccessibleShape*> (mxAccessibleShape.get());
1211cdf0e10cSrcweir }
1212cdf0e10cSrcweir // -----------------------------------------------------------------------------
1213cdf0e10cSrcweir void ChildDescriptor::setIndexAtAccessibleShape(sal_Int32 _nIndex)
1214cdf0e10cSrcweir {
1215cdf0e10cSrcweir 	AccessibleShape* pShape = GetAccessibleShape();
1216cdf0e10cSrcweir 	if ( pShape )
1217cdf0e10cSrcweir 		pShape->setIndexInParent(_nIndex);
1218cdf0e10cSrcweir }
1219cdf0e10cSrcweir // -----------------------------------------------------------------------------
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir 
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir void ChildDescriptor::disposeAccessibleObject (AccessibleContextBase& rParent)
1225cdf0e10cSrcweir {
1226cdf0e10cSrcweir     if (mxAccessibleShape.is())
1227cdf0e10cSrcweir     {
1228cdf0e10cSrcweir         // Send event that the shape has been removed.
1229cdf0e10cSrcweir         uno::Any aOldValue;
1230cdf0e10cSrcweir         aOldValue <<= mxAccessibleShape;
1231cdf0e10cSrcweir         rParent.CommitChange (
1232cdf0e10cSrcweir             AccessibleEventId::CHILD,
1233cdf0e10cSrcweir             uno::Any(),
1234cdf0e10cSrcweir             aOldValue);
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir         // Dispose and remove the object.
1237cdf0e10cSrcweir         Reference<lang::XComponent> xComponent (mxAccessibleShape, uno::UNO_QUERY);
1238cdf0e10cSrcweir         if (xComponent.is())
1239cdf0e10cSrcweir             xComponent->dispose ();
1240cdf0e10cSrcweir 
1241cdf0e10cSrcweir         mxAccessibleShape = NULL;
1242cdf0e10cSrcweir     }
1243cdf0e10cSrcweir }
1244cdf0e10cSrcweir 
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir } // end of namespace accessibility
1247cdf0e10cSrcweir 
1248