xref: /AOO41X/main/sc/source/ui/Accessibility/AccessibleDocument.cxx (revision 4483d2e8c50e6ab05bc9c49c7af9c6b38e11e72f)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "AccessibleDocument.hxx"
29cdf0e10cSrcweir #include "AccessibleSpreadsheet.hxx"
30cdf0e10cSrcweir #include "tabvwsh.hxx"
31cdf0e10cSrcweir #include "AccessibilityHints.hxx"
32cdf0e10cSrcweir #include "document.hxx"
33cdf0e10cSrcweir #include "drwlayer.hxx"
34cdf0e10cSrcweir #include "unoguard.hxx"
35cdf0e10cSrcweir #include "shapeuno.hxx"
36cdf0e10cSrcweir #include "DrawModelBroadcaster.hxx"
37cdf0e10cSrcweir #include "drawview.hxx"
38cdf0e10cSrcweir #include "gridwin.hxx"
39cdf0e10cSrcweir #include "AccessibleEditObject.hxx"
40cdf0e10cSrcweir #include "scresid.hxx"
41cdf0e10cSrcweir #ifndef SC_SC_HRC
42cdf0e10cSrcweir #include "sc.hrc"
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
45cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLESTATETYPE_HPP_
46cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLERELATIONTYPE_HPP_
49cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #include <com/sun/star/view/XSelectionSupplier.hpp>
52cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp>
53cdf0e10cSrcweir #include <com/sun/star/drawing/XShapes.hpp>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX
56cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
57cdf0e10cSrcweir #endif
58cdf0e10cSrcweir #include <tools/debug.hxx>
59cdf0e10cSrcweir #include <tools/gen.hxx>
60cdf0e10cSrcweir #include <svx/svdpage.hxx>
61cdf0e10cSrcweir #include <svx/svdobj.hxx>
62cdf0e10cSrcweir #include <svx/ShapeTypeHandler.hxx>
63cdf0e10cSrcweir #include <svx/AccessibleShape.hxx>
64cdf0e10cSrcweir #include <svx/AccessibleShapeTreeInfo.hxx>
65cdf0e10cSrcweir #include <svx/AccessibleShapeInfo.hxx>
66cdf0e10cSrcweir #include <comphelper/sequence.hxx>
67cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
68cdf0e10cSrcweir #include <svx/unoshcol.hxx>
69cdf0e10cSrcweir #include <svx/unoshape.hxx>
70cdf0e10cSrcweir #include <unotools/accessiblerelationsethelper.hxx>
71cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
72cdf0e10cSrcweir 
730deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
740deba7fbSSteve Yin #include <svx/AccessibleControlShape.hxx>
750deba7fbSSteve Yin #include <svx/AccessibleShape.hxx>
760deba7fbSSteve Yin #include <svx/ShapeTypeHandler.hxx>
770deba7fbSSteve Yin #include <svx/SvxShapeTypes.hxx>
780deba7fbSSteve Yin #include <sfx2/objsh.hxx>
790deba7fbSSteve Yin #include <editeng/editview.hxx>
800deba7fbSSteve Yin #include <editeng/editeng.hxx>
810deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
82cdf0e10cSrcweir #include <list>
83cdf0e10cSrcweir #include <algorithm>
840deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
850deba7fbSSteve Yin #include "AccessibleCell.hxx"
86cdf0e10cSrcweir 
870deba7fbSSteve Yin #include "svx/unoapi.hxx"
880deba7fbSSteve Yin #include "scmod.hxx"
890deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
90cdf0e10cSrcweir using namespace	::com::sun::star;
91cdf0e10cSrcweir using namespace	::com::sun::star::accessibility;
92cdf0e10cSrcweir using ::std::for_each;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	//=====  internal  ========================================================
95cdf0e10cSrcweir 
96cdf0e10cSrcweir struct ScAccessibleShapeData
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	ScAccessibleShapeData() : pAccShape(NULL), pRelationCell(NULL), bSelected(sal_False), bSelectable(sal_True) {}
99cdf0e10cSrcweir 	~ScAccessibleShapeData();
100cdf0e10cSrcweir 	mutable ::accessibility::AccessibleShape* pAccShape;
101cdf0e10cSrcweir     mutable ScAddress*          pRelationCell; // if it is NULL this shape is anchored on the table
102cdf0e10cSrcweir //    SdrObject*                  pShape;
103cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape;
104cdf0e10cSrcweir 	mutable sal_Bool			bSelected;
105cdf0e10cSrcweir     sal_Bool                    bSelectable;
106cdf0e10cSrcweir };
107cdf0e10cSrcweir 
108cdf0e10cSrcweir ScAccessibleShapeData::~ScAccessibleShapeData()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     if (pAccShape)
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         pAccShape->dispose();
113cdf0e10cSrcweir         pAccShape->release();
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir struct ScShapeDataLess
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     rtl::OUString msLayerId;
120cdf0e10cSrcweir     rtl::OUString msZOrder;
121cdf0e10cSrcweir     ScShapeDataLess()
122cdf0e10cSrcweir         : msLayerId(RTL_CONSTASCII_USTRINGPARAM( "LayerID" )),
123cdf0e10cSrcweir         msZOrder(RTL_CONSTASCII_USTRINGPARAM( "ZOrder" ))
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir     void ConvertLayerId(sal_Int16& rLayerID) const // changes the number of the LayerId so it the accessibility order
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         switch (rLayerID)
129cdf0e10cSrcweir         {
130cdf0e10cSrcweir         case SC_LAYER_FRONT:
131cdf0e10cSrcweir             rLayerID = 1;
132cdf0e10cSrcweir             break;
133cdf0e10cSrcweir         case SC_LAYER_BACK:
134cdf0e10cSrcweir             rLayerID = 0;
135cdf0e10cSrcweir             break;
136cdf0e10cSrcweir         case SC_LAYER_INTERN:
137cdf0e10cSrcweir             rLayerID = 2;
138cdf0e10cSrcweir             break;
139cdf0e10cSrcweir         case SC_LAYER_CONTROLS:
140cdf0e10cSrcweir             rLayerID = 3;
141cdf0e10cSrcweir             break;
142cdf0e10cSrcweir         }
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir     sal_Bool LessThanSheet(const ScAccessibleShapeData* pData) const
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir         sal_Bool bResult(sal_False);
147cdf0e10cSrcweir         uno::Reference< beans::XPropertySet> xProps(pData->xShape, uno::UNO_QUERY);
148cdf0e10cSrcweir         if (xProps.is())
149cdf0e10cSrcweir         {
150cdf0e10cSrcweir 			uno::Any aPropAny = xProps->getPropertyValue(msLayerId);
151cdf0e10cSrcweir 			sal_Int16 nLayerID = 0;
152cdf0e10cSrcweir 			if( (aPropAny >>= nLayerID) )
153cdf0e10cSrcweir             {
154cdf0e10cSrcweir                 if (nLayerID == SC_LAYER_BACK)
155cdf0e10cSrcweir                     bResult = sal_True;
156cdf0e10cSrcweir             }
157cdf0e10cSrcweir         }
158cdf0e10cSrcweir         return bResult;
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir     sal_Bool operator()(const ScAccessibleShapeData* pData1, const ScAccessibleShapeData* pData2) const
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir         sal_Bool bResult(sal_False);
163cdf0e10cSrcweir         if (pData1 && pData2)
164cdf0e10cSrcweir         {
165cdf0e10cSrcweir             uno::Reference< beans::XPropertySet> xProps1(pData1->xShape, uno::UNO_QUERY);
166cdf0e10cSrcweir             uno::Reference< beans::XPropertySet> xProps2(pData2->xShape, uno::UNO_QUERY);
167cdf0e10cSrcweir             if (xProps1.is() && xProps2.is())
168cdf0e10cSrcweir             {
169cdf0e10cSrcweir 				uno::Any aPropAny1 = xProps1->getPropertyValue(msLayerId);
170cdf0e10cSrcweir                 uno::Any aPropAny2 = xProps2->getPropertyValue(msLayerId);
171cdf0e10cSrcweir 				sal_Int16 nLayerID1(0);
172cdf0e10cSrcweir                 sal_Int16 nLayerID2(0);
173cdf0e10cSrcweir 				if( (aPropAny1 >>= nLayerID1) && (aPropAny2 >>= nLayerID2) )
174cdf0e10cSrcweir                 {
175cdf0e10cSrcweir                     if (nLayerID1 == nLayerID2)
176cdf0e10cSrcweir                     {
177cdf0e10cSrcweir 		                uno::Any aAny1 = xProps1->getPropertyValue(msZOrder);
178cdf0e10cSrcweir 		                sal_Int32 nZOrder1 = 0;
179cdf0e10cSrcweir 		                uno::Any aAny2 = xProps2->getPropertyValue(msZOrder);
180cdf0e10cSrcweir 		                sal_Int32 nZOrder2 = 0;
181cdf0e10cSrcweir 		                if ( (aAny1 >>= nZOrder1) && (aAny2 >>= nZOrder2) )
182cdf0e10cSrcweir                             bResult = (nZOrder1 < nZOrder2);
183cdf0e10cSrcweir                     }
184cdf0e10cSrcweir                     else
185cdf0e10cSrcweir                     {
186cdf0e10cSrcweir                         ConvertLayerId(nLayerID1);
187cdf0e10cSrcweir                         ConvertLayerId(nLayerID2);
188cdf0e10cSrcweir                         bResult = (nLayerID1 < nLayerID2);
189cdf0e10cSrcweir                     }
190cdf0e10cSrcweir                 }
191cdf0e10cSrcweir             }
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir         else if (pData1 && !pData2)
194cdf0e10cSrcweir             bResult = LessThanSheet(pData1);
195cdf0e10cSrcweir         else if (!pData1 && pData2)
196cdf0e10cSrcweir             bResult = !LessThanSheet(pData2);
197cdf0e10cSrcweir         else
198cdf0e10cSrcweir             bResult = sal_False;
199cdf0e10cSrcweir         return bResult;
200cdf0e10cSrcweir     }
201cdf0e10cSrcweir };
202cdf0e10cSrcweir 
203cdf0e10cSrcweir struct DeselectShape
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	void operator() (const ScAccessibleShapeData* pAccShapeData) const
206cdf0e10cSrcweir 	{
207cdf0e10cSrcweir         if (pAccShapeData)
208cdf0e10cSrcweir         {
209cdf0e10cSrcweir 		    pAccShapeData->bSelected = sal_False;
210cdf0e10cSrcweir 		    if (pAccShapeData->pAccShape)
211cdf0e10cSrcweir 			    pAccShapeData->pAccShape->ResetState(AccessibleStateType::SELECTED);
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir 	}
214cdf0e10cSrcweir };
215cdf0e10cSrcweir 
216cdf0e10cSrcweir struct SelectShape
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     uno::Reference < drawing::XShapes > xShapes;
219cdf0e10cSrcweir     SelectShape(uno::Reference<drawing::XShapes>& xTemp) : xShapes(xTemp) {}
220cdf0e10cSrcweir 	void operator() (const ScAccessibleShapeData* pAccShapeData) const
221cdf0e10cSrcweir     {
222cdf0e10cSrcweir         if (pAccShapeData && pAccShapeData->bSelectable)
223cdf0e10cSrcweir         {
224cdf0e10cSrcweir 	        pAccShapeData->bSelected = sal_True;
225cdf0e10cSrcweir 	        if (pAccShapeData->pAccShape)
226cdf0e10cSrcweir 		        pAccShapeData->pAccShape->SetState(AccessibleStateType::SELECTED);
227cdf0e10cSrcweir             if (xShapes.is())
228cdf0e10cSrcweir                 xShapes->add(pAccShapeData->xShape);
229cdf0e10cSrcweir         }
230cdf0e10cSrcweir     }
231cdf0e10cSrcweir };
232cdf0e10cSrcweir 
233cdf0e10cSrcweir struct Destroy
234cdf0e10cSrcweir {
235cdf0e10cSrcweir     void operator() (ScAccessibleShapeData* pData)
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         if (pData)
238cdf0e10cSrcweir             DELETEZ(pData);
239cdf0e10cSrcweir     }
240cdf0e10cSrcweir };
241cdf0e10cSrcweir 
242cdf0e10cSrcweir class ScChildrenShapes : public SfxListener,
243cdf0e10cSrcweir 	public ::accessibility::IAccessibleParent
244cdf0e10cSrcweir {
245cdf0e10cSrcweir public:
246cdf0e10cSrcweir     ScChildrenShapes(ScAccessibleDocument* pAccessibleDocument, ScTabViewShell* pViewShell, ScSplitPos eSplitPos);
247cdf0e10cSrcweir     ~ScChildrenShapes();
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     ///=====  SfxListener  =====================================================
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir     ///=====  IAccessibleParent  ===============================================
254cdf0e10cSrcweir 
255cdf0e10cSrcweir     virtual sal_Bool ReplaceChild (
256cdf0e10cSrcweir         ::accessibility::AccessibleShape* pCurrentChild,
257cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& _rxShape,
258cdf0e10cSrcweir 		const long _nIndex,
259cdf0e10cSrcweir 		const ::accessibility::AccessibleShapeTreeInfo& _rShapeTreeInfo
260cdf0e10cSrcweir 	)	throw (::com::sun::star::uno::RuntimeException);
261cdf0e10cSrcweir 
2620deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
2630deba7fbSSteve Yin 	virtual ::accessibility::AccessibleControlShape* GetAccControlShapeFromModel
2640deba7fbSSteve Yin 		(::com::sun::star::beans::XPropertySet* pSet)
2650deba7fbSSteve Yin 		throw (::com::sun::star::uno::RuntimeException);
2660deba7fbSSteve Yin 	virtual  ::com::sun::star::uno::Reference<
2670deba7fbSSteve Yin             ::com::sun::star::accessibility::XAccessible>
2680deba7fbSSteve Yin         GetAccessibleCaption (const ::com::sun::star::uno::Reference<
2690deba7fbSSteve Yin             ::com::sun::star::drawing::XShape>& xShape)
2700deba7fbSSteve Yin 			throw (::com::sun::star::uno::RuntimeException);
2710deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
272cdf0e10cSrcweir     ///=====  Internal  ========================================================
273cdf0e10cSrcweir     void SetDrawBroadcaster();
274cdf0e10cSrcweir 
275cdf0e10cSrcweir     sal_Int32 GetCount() const;
276cdf0e10cSrcweir     uno::Reference< XAccessible > Get(const ScAccessibleShapeData* pData) const;
277cdf0e10cSrcweir     uno::Reference< XAccessible > Get(sal_Int32 nIndex) const;
278cdf0e10cSrcweir 	uno::Reference< XAccessible > GetAt(const awt::Point& rPoint) const;
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 	// gets the index of the shape starting on 0 (without the index of the table)
281cdf0e10cSrcweir 	// returns the selected shape
282cdf0e10cSrcweir 	sal_Bool IsSelected(sal_Int32 nIndex,
283cdf0e10cSrcweir 		com::sun::star::uno::Reference<com::sun::star::drawing::XShape>& rShape) const;
284cdf0e10cSrcweir 
285cdf0e10cSrcweir     sal_Bool SelectionChanged();
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     void Select(sal_Int32 nIndex);
288cdf0e10cSrcweir     void DeselectAll(); // deselect also the table
289cdf0e10cSrcweir     void SelectAll();
290cdf0e10cSrcweir     sal_Int32 GetSelectedCount() const;
291cdf0e10cSrcweir     uno::Reference< XAccessible > GetSelected(sal_Int32 nSelectedChildIndex, sal_Bool bTabSelected) const;
292cdf0e10cSrcweir     void Deselect(sal_Int32 nChildIndex);
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     SdrPage* GetDrawPage() const;
295cdf0e10cSrcweir 
296cdf0e10cSrcweir     utl::AccessibleRelationSetHelper* GetRelationSet(const ScAddress* pAddress) const;
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     void VisAreaChanged() const;
299cdf0e10cSrcweir private:
300cdf0e10cSrcweir     typedef std::vector<ScAccessibleShapeData*> SortedShapes;
301cdf0e10cSrcweir 
302cdf0e10cSrcweir     mutable SortedShapes maZOrderedShapes; // a null pointer represents the sheet in the correct order
303cdf0e10cSrcweir 
304cdf0e10cSrcweir     mutable ::accessibility::AccessibleShapeTreeInfo maShapeTreeInfo;
305cdf0e10cSrcweir 	mutable com::sun::star::uno::Reference<com::sun::star::view::XSelectionSupplier> xSelectionSupplier;
306cdf0e10cSrcweir 	mutable sal_uInt32 mnSdrObjCount;
307cdf0e10cSrcweir 	mutable sal_uInt32 mnShapesSelected;
308cdf0e10cSrcweir     ScTabViewShell* mpViewShell;
309cdf0e10cSrcweir     ScAccessibleDocument* mpAccessibleDocument;
310cdf0e10cSrcweir     ScSplitPos meSplitPos;
311cdf0e10cSrcweir 
312cdf0e10cSrcweir     void FillShapes(std::vector < uno::Reference < drawing::XShape > >& rShapes) const;
313cdf0e10cSrcweir     sal_Bool FindSelectedShapesChanges(const com::sun::star::uno::Reference<com::sun::star::drawing::XShapes>& xShapes, sal_Bool bCommitChange) const;
314cdf0e10cSrcweir 	void FillSelectionSupplier() const;
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     ScAddress* GetAnchor(const uno::Reference<drawing::XShape>& xShape) const;
317cdf0e10cSrcweir     uno::Reference<XAccessibleRelationSet> GetRelationSet(const ScAccessibleShapeData* pData) const;
318cdf0e10cSrcweir     void CheckWhetherAnchorChanged(const uno::Reference<drawing::XShape>& xShape) const;
319cdf0e10cSrcweir     void SetAnchor(const uno::Reference<drawing::XShape>& xShape, ScAccessibleShapeData* pData) const;
320cdf0e10cSrcweir     void AddShape(const uno::Reference<drawing::XShape>& xShape, sal_Bool bCommitChange) const;
321cdf0e10cSrcweir     void RemoveShape(const uno::Reference<drawing::XShape>& xShape) const;
322cdf0e10cSrcweir 
323cdf0e10cSrcweir     sal_Bool FindShape(const uno::Reference<drawing::XShape>& xShape, SortedShapes::iterator& rItr) const;
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 	sal_Int8 Compare(const ScAccessibleShapeData* pData1,
326cdf0e10cSrcweir 		const ScAccessibleShapeData* pData2) const;
327cdf0e10cSrcweir };
328cdf0e10cSrcweir 
329cdf0e10cSrcweir ScChildrenShapes::ScChildrenShapes(ScAccessibleDocument* pAccessibleDocument, ScTabViewShell* pViewShell, ScSplitPos eSplitPos)
330cdf0e10cSrcweir     :
331cdf0e10cSrcweir     mnShapesSelected(0),
332cdf0e10cSrcweir     mpViewShell(pViewShell),
333cdf0e10cSrcweir     mpAccessibleDocument(pAccessibleDocument),
334cdf0e10cSrcweir     meSplitPos(eSplitPos)
335cdf0e10cSrcweir {
336cdf0e10cSrcweir 	FillSelectionSupplier();
337cdf0e10cSrcweir     maZOrderedShapes.push_back(NULL); // add an element which represents the table
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 	GetCount(); // fill list with filtered shapes (no internal shapes)
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 	if (mnShapesSelected)
342cdf0e10cSrcweir 	{
343cdf0e10cSrcweir 		//set flag on every selected shape
344cdf0e10cSrcweir 		if (!xSelectionSupplier.is())
345cdf0e10cSrcweir 			throw uno::RuntimeException();
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 		uno::Reference<drawing::XShapes> xShapes(xSelectionSupplier->getSelection(), uno::UNO_QUERY);
348cdf0e10cSrcweir 		if (xShapes.is())
349cdf0e10cSrcweir 			FindSelectedShapesChanges(xShapes, sal_False);
350cdf0e10cSrcweir 	}
351cdf0e10cSrcweir     if (pViewShell)
352cdf0e10cSrcweir     {
353cdf0e10cSrcweir 	    SfxBroadcaster* pDrawBC = pViewShell->GetViewData()->GetDocument()->GetDrawBroadcaster();
354cdf0e10cSrcweir 	    if (pDrawBC)
355cdf0e10cSrcweir         {
356cdf0e10cSrcweir 		    StartListening(*pDrawBC);
357cdf0e10cSrcweir 
358cdf0e10cSrcweir             maShapeTreeInfo.SetModelBroadcaster( new ScDrawModelBroadcaster(pViewShell->GetViewData()->GetDocument()->GetDrawLayer()) );
359cdf0e10cSrcweir             maShapeTreeInfo.SetSdrView(pViewShell->GetViewData()->GetScDrawView());
360cdf0e10cSrcweir             maShapeTreeInfo.SetController(NULL);
361cdf0e10cSrcweir             maShapeTreeInfo.SetWindow(pViewShell->GetWindowByPos(meSplitPos));
362cdf0e10cSrcweir             maShapeTreeInfo.SetViewForwarder(mpAccessibleDocument);
363cdf0e10cSrcweir         }
364cdf0e10cSrcweir     }
365cdf0e10cSrcweir }
366cdf0e10cSrcweir 
367cdf0e10cSrcweir ScChildrenShapes::~ScChildrenShapes()
368cdf0e10cSrcweir {
369cdf0e10cSrcweir     std::for_each(maZOrderedShapes.begin(), maZOrderedShapes.end(), Destroy());
370cdf0e10cSrcweir     if (mpViewShell)
371cdf0e10cSrcweir     {
372cdf0e10cSrcweir 	    SfxBroadcaster* pDrawBC = mpViewShell->GetViewData()->GetDocument()->GetDrawBroadcaster();
373cdf0e10cSrcweir 	    if (pDrawBC)
374cdf0e10cSrcweir 		    EndListening(*pDrawBC);
375cdf0e10cSrcweir     }
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir void ScChildrenShapes::SetDrawBroadcaster()
379cdf0e10cSrcweir {
380cdf0e10cSrcweir     if (mpViewShell)
381cdf0e10cSrcweir     {
382cdf0e10cSrcweir 	    SfxBroadcaster* pDrawBC = mpViewShell->GetViewData()->GetDocument()->GetDrawBroadcaster();
383cdf0e10cSrcweir 	    if (pDrawBC)
384cdf0e10cSrcweir         {
385cdf0e10cSrcweir 		    StartListening(*pDrawBC, sal_True);
386cdf0e10cSrcweir 
387cdf0e10cSrcweir             maShapeTreeInfo.SetModelBroadcaster( new ScDrawModelBroadcaster(mpViewShell->GetViewData()->GetDocument()->GetDrawLayer()) );
388cdf0e10cSrcweir             maShapeTreeInfo.SetSdrView(mpViewShell->GetViewData()->GetScDrawView());
389cdf0e10cSrcweir             maShapeTreeInfo.SetController(NULL);
390cdf0e10cSrcweir             maShapeTreeInfo.SetWindow(mpViewShell->GetWindowByPos(meSplitPos));
391cdf0e10cSrcweir             maShapeTreeInfo.SetViewForwarder(mpAccessibleDocument);
392cdf0e10cSrcweir         }
393cdf0e10cSrcweir     }
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir void ScChildrenShapes::Notify(SfxBroadcaster&, const SfxHint& rHint)
397cdf0e10cSrcweir {
398cdf0e10cSrcweir 	if ( rHint.ISA( SdrHint ) )
399cdf0e10cSrcweir 	{
400cdf0e10cSrcweir 		const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
401cdf0e10cSrcweir         if (pSdrHint)
402cdf0e10cSrcweir         {
403cdf0e10cSrcweir             SdrObject* pObj = const_cast<SdrObject*>(pSdrHint->GetObject());
404cdf0e10cSrcweir             if (pObj && /*(pObj->GetLayer() != SC_LAYER_INTERN) && */(pObj->GetPage() == GetDrawPage()) &&
405cdf0e10cSrcweir                 (pObj->GetPage() == pObj->GetObjList()) ) //#108480# only do something if the object lies direct on the page
406cdf0e10cSrcweir             {
407cdf0e10cSrcweir                 switch (pSdrHint->GetKind())
408cdf0e10cSrcweir                 {
409cdf0e10cSrcweir                     case HINT_OBJCHG :         // Objekt geaendert
410cdf0e10cSrcweir                     {
411cdf0e10cSrcweir                         uno::Reference<drawing::XShape> xShape (pObj->getUnoShape(), uno::UNO_QUERY);
412cdf0e10cSrcweir                         if (xShape.is())
413cdf0e10cSrcweir                         {
414cdf0e10cSrcweir                             ScShapeDataLess aLess;
415cdf0e10cSrcweir                             std::sort(maZOrderedShapes.begin(), maZOrderedShapes.end(), aLess); // sort, because the z index or layer could be changed
416cdf0e10cSrcweir                             CheckWhetherAnchorChanged(xShape);
417cdf0e10cSrcweir                         }
418cdf0e10cSrcweir                     }
419cdf0e10cSrcweir                     break;
420cdf0e10cSrcweir                     case HINT_OBJINSERTED :    // Neues Zeichenobjekt eingefuegt
421cdf0e10cSrcweir                     {
422cdf0e10cSrcweir                         uno::Reference<drawing::XShape> xShape (pObj->getUnoShape(), uno::UNO_QUERY);
423cdf0e10cSrcweir                         if (xShape.is())
424cdf0e10cSrcweir                             AddShape(xShape, sal_True);
425cdf0e10cSrcweir                     }
426cdf0e10cSrcweir                     break;
427cdf0e10cSrcweir                     case HINT_OBJREMOVED :     // Zeichenobjekt aus Liste entfernt
428cdf0e10cSrcweir                     {
429cdf0e10cSrcweir                         uno::Reference<drawing::XShape> xShape (pObj->getUnoShape(), uno::UNO_QUERY);
430cdf0e10cSrcweir                         if (xShape.is())
431cdf0e10cSrcweir                             RemoveShape(xShape);
432cdf0e10cSrcweir                     }
433cdf0e10cSrcweir                     break;
434cdf0e10cSrcweir                     default :
435cdf0e10cSrcweir                     {
436cdf0e10cSrcweir                         // other events are not interesting
437cdf0e10cSrcweir                     }
438cdf0e10cSrcweir                     break;
439cdf0e10cSrcweir                 }
440cdf0e10cSrcweir             }
441cdf0e10cSrcweir         }
442cdf0e10cSrcweir     }
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir sal_Bool ScChildrenShapes::ReplaceChild (::accessibility::AccessibleShape* pCurrentChild,
446cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& _rxShape,
447cdf0e10cSrcweir 		const long _nIndex, const ::accessibility::AccessibleShapeTreeInfo& _rShapeTreeInfo)
448cdf0e10cSrcweir     throw (uno::RuntimeException)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir 	// create the new child
451cdf0e10cSrcweir 	::accessibility::AccessibleShape* pReplacement = ::accessibility::ShapeTypeHandler::Instance().CreateAccessibleObject (
452cdf0e10cSrcweir 		::accessibility::AccessibleShapeInfo ( _rxShape, pCurrentChild->getAccessibleParent(), this, _nIndex ),
453cdf0e10cSrcweir 		_rShapeTreeInfo
454cdf0e10cSrcweir 	);
455cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xNewChild( pReplacement );	// keep this alive (do this before calling Init!)
456cdf0e10cSrcweir 	if ( pReplacement )
457cdf0e10cSrcweir 		pReplacement->Init();
458cdf0e10cSrcweir 
459cdf0e10cSrcweir     sal_Bool bResult(sal_False);
460cdf0e10cSrcweir     if (pCurrentChild && pReplacement)
461cdf0e10cSrcweir     {
462cdf0e10cSrcweir         DBG_ASSERT(pCurrentChild->GetXShape().get() == pReplacement->GetXShape().get(), "XShape changes and should be inserted sorted");
463cdf0e10cSrcweir         SortedShapes::iterator aItr;
464cdf0e10cSrcweir         FindShape(pCurrentChild->GetXShape(), aItr);
465cdf0e10cSrcweir         if (aItr != maZOrderedShapes.end() && (*aItr))
466cdf0e10cSrcweir         {
467cdf0e10cSrcweir             if ((*aItr)->pAccShape)
468cdf0e10cSrcweir             {
469cdf0e10cSrcweir                 DBG_ASSERT((*aItr)->pAccShape == pCurrentChild, "wrong child found");
470cdf0e10cSrcweir                 AccessibleEventObject aEvent;
471cdf0e10cSrcweir 			    aEvent.EventId = AccessibleEventId::CHILD;
472cdf0e10cSrcweir 			    aEvent.Source = uno::Reference< XAccessibleContext >(mpAccessibleDocument);
473cdf0e10cSrcweir                 aEvent.OldValue <<= uno::makeAny(uno::Reference<XAccessible>(pCurrentChild));
474cdf0e10cSrcweir 
475cdf0e10cSrcweir 			    mpAccessibleDocument->CommitChange(aEvent); // child is gone - event
476cdf0e10cSrcweir 
477cdf0e10cSrcweir                 pCurrentChild->dispose();
478cdf0e10cSrcweir             }
479cdf0e10cSrcweir             (*aItr)->pAccShape = pReplacement;
480cdf0e10cSrcweir             AccessibleEventObject aEvent;
481cdf0e10cSrcweir 			aEvent.EventId = AccessibleEventId::CHILD;
482cdf0e10cSrcweir 			aEvent.Source = uno::Reference< XAccessibleContext >(mpAccessibleDocument);
483cdf0e10cSrcweir             aEvent.NewValue <<= uno::makeAny(uno::Reference<XAccessible>(pReplacement));
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 			mpAccessibleDocument->CommitChange(aEvent); // child is new - event
486cdf0e10cSrcweir             bResult = sal_True;
487cdf0e10cSrcweir         }
488cdf0e10cSrcweir     }
489cdf0e10cSrcweir     return bResult;
490cdf0e10cSrcweir }
491cdf0e10cSrcweir 
4920deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
4930deba7fbSSteve Yin ::accessibility::AccessibleControlShape * ScChildrenShapes::GetAccControlShapeFromModel(::com::sun::star::beans::XPropertySet* pSet) throw (::com::sun::star::uno::RuntimeException)
4940deba7fbSSteve Yin {
4950deba7fbSSteve Yin 	sal_Int32 count = GetCount();
4960deba7fbSSteve Yin 	for (sal_Int32 index=0;index<count;index++)
4970deba7fbSSteve Yin 	{
4980deba7fbSSteve Yin 		ScAccessibleShapeData* pShape = maZOrderedShapes[index];
4990deba7fbSSteve Yin             	if (pShape)
5000deba7fbSSteve Yin    	     	{
5010deba7fbSSteve Yin    	     		::accessibility::AccessibleShape* pAccShape = pShape->pAccShape;
5020deba7fbSSteve Yin           	 	if (pAccShape  && ::accessibility::ShapeTypeHandler::Instance().GetTypeId (pAccShape->GetXShape()) == ::accessibility::DRAWING_CONTROL)
5030deba7fbSSteve Yin           	  	{
5040deba7fbSSteve Yin 				::accessibility::AccessibleControlShape *pCtlAccShape = static_cast < ::accessibility::AccessibleControlShape* >(pAccShape);
5050deba7fbSSteve Yin 				if (pCtlAccShape && pCtlAccShape->GetControlModel() == pSet)
5060deba7fbSSteve Yin 					return pCtlAccShape;
5070deba7fbSSteve Yin 			  }
5080deba7fbSSteve Yin             	}
5090deba7fbSSteve Yin 	}
5100deba7fbSSteve Yin 	return NULL;
5110deba7fbSSteve Yin }
5120deba7fbSSteve Yin ::com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessible >
5130deba7fbSSteve Yin ScChildrenShapes::GetAccessibleCaption (const ::com::sun::star::uno::Reference < ::com::sun::star::drawing::XShape>& xShape)
5140deba7fbSSteve Yin 			throw (::com::sun::star::uno::RuntimeException)
5150deba7fbSSteve Yin {
5160deba7fbSSteve Yin 	sal_Int32 count = GetCount();
5170deba7fbSSteve Yin 	for (sal_Int32 index=0;index<count;index++)
5180deba7fbSSteve Yin 	{
5190deba7fbSSteve Yin 		ScAccessibleShapeData* pShape = maZOrderedShapes[index];
5200deba7fbSSteve Yin 			if (pShape && pShape->xShape == xShape )
5210deba7fbSSteve Yin    	     	{
5220deba7fbSSteve Yin 				::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xNewChild(  pShape->pAccShape );
5230deba7fbSSteve Yin //				uno::Reference<XAccessible> xNewChild( pShape->pAccShape , uno::UNO_QUERY );
5240deba7fbSSteve Yin 				if(xNewChild.get())
5250deba7fbSSteve Yin 				return xNewChild;
5260deba7fbSSteve Yin 			}
5270deba7fbSSteve Yin 	}
5280deba7fbSSteve Yin 	return NULL;
5290deba7fbSSteve Yin }
5300deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
531cdf0e10cSrcweir sal_Int32 ScChildrenShapes::GetCount() const
532cdf0e10cSrcweir {
533cdf0e10cSrcweir 	SdrPage* pDrawPage = GetDrawPage();
534cdf0e10cSrcweir 	if (pDrawPage && (maZOrderedShapes.size() == 1)) // the table is always in
535cdf0e10cSrcweir 	{
536cdf0e10cSrcweir 		mnSdrObjCount = pDrawPage->GetObjCount();
537cdf0e10cSrcweir 		maZOrderedShapes.reserve(mnSdrObjCount + 1); // the table is always in
538cdf0e10cSrcweir 		for (sal_uInt32 i = 0; i < mnSdrObjCount; ++i)
539cdf0e10cSrcweir 		{
540cdf0e10cSrcweir 			SdrObject* pObj = pDrawPage->GetObj(i);
541cdf0e10cSrcweir 			if (pObj/* && (pObj->GetLayer() != SC_LAYER_INTERN)*/)
542cdf0e10cSrcweir 			{
543cdf0e10cSrcweir 				uno::Reference< drawing::XShape > xShape (pObj->getUnoShape(), uno::UNO_QUERY);
544cdf0e10cSrcweir                 AddShape(xShape, sal_False); //inserts in the correct order
545cdf0e10cSrcweir 			}
546cdf0e10cSrcweir 		}
547cdf0e10cSrcweir 	}
548cdf0e10cSrcweir 	return maZOrderedShapes.size();
549cdf0e10cSrcweir }
550cdf0e10cSrcweir 
551cdf0e10cSrcweir uno::Reference< XAccessible > ScChildrenShapes::Get(const ScAccessibleShapeData* pData) const
552cdf0e10cSrcweir {
553cdf0e10cSrcweir     if (!pData)
554cdf0e10cSrcweir         return NULL;
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 	if (!pData->pAccShape)
557cdf0e10cSrcweir 	{
558cdf0e10cSrcweir 		::accessibility::ShapeTypeHandler& rShapeHandler = ::accessibility::ShapeTypeHandler::Instance();
559cdf0e10cSrcweir         ::accessibility::AccessibleShapeInfo aShapeInfo(pData->xShape, mpAccessibleDocument, const_cast<ScChildrenShapes*>(this));
560cdf0e10cSrcweir 		pData->pAccShape = rShapeHandler.CreateAccessibleObject(
561cdf0e10cSrcweir 			aShapeInfo, maShapeTreeInfo);
562cdf0e10cSrcweir 		if (pData->pAccShape)
563cdf0e10cSrcweir         {
564cdf0e10cSrcweir 			pData->pAccShape->acquire();
565cdf0e10cSrcweir 			pData->pAccShape->Init();
566cdf0e10cSrcweir             if (pData->bSelected)
567cdf0e10cSrcweir                 pData->pAccShape->SetState(AccessibleStateType::SELECTED);
568cdf0e10cSrcweir             if (!pData->bSelectable)
569cdf0e10cSrcweir                 pData->pAccShape->ResetState(AccessibleStateType::SELECTABLE);
570cdf0e10cSrcweir             pData->pAccShape->SetRelationSet(GetRelationSet(pData));
571cdf0e10cSrcweir         }
572cdf0e10cSrcweir 	}
573cdf0e10cSrcweir     return pData->pAccShape;
574cdf0e10cSrcweir  }
575cdf0e10cSrcweir 
576cdf0e10cSrcweir uno::Reference< XAccessible > ScChildrenShapes::Get(sal_Int32 nIndex) const
577cdf0e10cSrcweir {
578cdf0e10cSrcweir 	if (maZOrderedShapes.size() <= 1)
579cdf0e10cSrcweir 		GetCount(); // fill list with filtered shapes (no internal shapes)
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 	if (static_cast<sal_uInt32>(nIndex) >= maZOrderedShapes.size())
582cdf0e10cSrcweir 		return NULL;
583cdf0e10cSrcweir 
584cdf0e10cSrcweir     return Get(maZOrderedShapes[nIndex]);
585cdf0e10cSrcweir }
586cdf0e10cSrcweir 
587cdf0e10cSrcweir uno::Reference< XAccessible > ScChildrenShapes::GetAt(const awt::Point& rPoint) const
588cdf0e10cSrcweir {
589cdf0e10cSrcweir     uno::Reference<XAccessible> xAccessible;
590cdf0e10cSrcweir     if(mpViewShell)
591cdf0e10cSrcweir     {
592cdf0e10cSrcweir         sal_Int32 i(maZOrderedShapes.size() - 1);
593cdf0e10cSrcweir         sal_Bool bFound(sal_False);
594cdf0e10cSrcweir         while (!bFound && i >= 0)
595cdf0e10cSrcweir         {
596cdf0e10cSrcweir             ScAccessibleShapeData* pShape = maZOrderedShapes[i];
597cdf0e10cSrcweir             if (pShape)
598cdf0e10cSrcweir             {
599cdf0e10cSrcweir                 if (!pShape->pAccShape)
600cdf0e10cSrcweir                     Get(pShape);
601cdf0e10cSrcweir 
602cdf0e10cSrcweir                 if (pShape->pAccShape)
603cdf0e10cSrcweir                 {
604cdf0e10cSrcweir                     Point aPoint(VCLPoint(rPoint));
605cdf0e10cSrcweir                     aPoint -= VCLRectangle(pShape->pAccShape->getBounds()).TopLeft();
606cdf0e10cSrcweir                     if (pShape->pAccShape->containsPoint(AWTPoint(aPoint)))
607cdf0e10cSrcweir                     {
608cdf0e10cSrcweir                         xAccessible = pShape->pAccShape;
609cdf0e10cSrcweir                         bFound = sal_True;
610cdf0e10cSrcweir                     }
611cdf0e10cSrcweir                 }
612cdf0e10cSrcweir                 else
613cdf0e10cSrcweir                 {
614cdf0e10cSrcweir                     DBG_ERRORFILE("I should have an accessible shape now!");
615cdf0e10cSrcweir                 }
616cdf0e10cSrcweir             }
617cdf0e10cSrcweir             else
618cdf0e10cSrcweir                 bFound = sal_True; // this is the sheet and it lies before the rest of the shapes which are background shapes
619cdf0e10cSrcweir 
620cdf0e10cSrcweir             --i;
621cdf0e10cSrcweir         }
622cdf0e10cSrcweir     }
623cdf0e10cSrcweir     return xAccessible;
624cdf0e10cSrcweir }
625cdf0e10cSrcweir 
626cdf0e10cSrcweir sal_Bool ScChildrenShapes::IsSelected(sal_Int32 nIndex,
627cdf0e10cSrcweir 						uno::Reference<drawing::XShape>& rShape) const
628cdf0e10cSrcweir {
629cdf0e10cSrcweir 	sal_Bool bResult (sal_False);
630cdf0e10cSrcweir 	if (maZOrderedShapes.size() <= 1)
631cdf0e10cSrcweir 		GetCount(); // fill list with filtered shapes (no internal shapes)
632cdf0e10cSrcweir 
633cdf0e10cSrcweir 	if (!xSelectionSupplier.is())
634cdf0e10cSrcweir 		throw uno::RuntimeException();
635cdf0e10cSrcweir 
636cdf0e10cSrcweir     if (!maZOrderedShapes[nIndex])
637cdf0e10cSrcweir         return sal_False;
638cdf0e10cSrcweir 
639cdf0e10cSrcweir     bResult = maZOrderedShapes[nIndex]->bSelected;
640cdf0e10cSrcweir     rShape = maZOrderedShapes[nIndex]->xShape;
641cdf0e10cSrcweir 
642cdf0e10cSrcweir #ifdef DBG_UTIL // test whether it is truly selected by a slower method
643cdf0e10cSrcweir     uno::Reference< drawing::XShape > xReturnShape;
644cdf0e10cSrcweir     sal_Bool bDebugResult(sal_False);
645cdf0e10cSrcweir 	uno::Reference<container::XIndexAccess> xIndexAccess;
646cdf0e10cSrcweir 	xSelectionSupplier->getSelection() >>= xIndexAccess;
647cdf0e10cSrcweir 
648cdf0e10cSrcweir 	if (xIndexAccess.is())
649cdf0e10cSrcweir 	{
650cdf0e10cSrcweir 		sal_Int32 nCount(xIndexAccess->getCount());
651cdf0e10cSrcweir 		if (nCount)
652cdf0e10cSrcweir 		{
653cdf0e10cSrcweir 			uno::Reference< drawing::XShape > xShape;
654cdf0e10cSrcweir             uno::Reference< drawing::XShape > xIndexShape = maZOrderedShapes[nIndex]->xShape;
655cdf0e10cSrcweir 			sal_Int32 i(0);
656cdf0e10cSrcweir 			while (!bDebugResult && (i < nCount))
657cdf0e10cSrcweir 			{
658cdf0e10cSrcweir 				xIndexAccess->getByIndex(i) >>= xShape;
659cdf0e10cSrcweir 				if (xShape.is() && (xIndexShape.get() == xShape.get()))
660cdf0e10cSrcweir 				{
661cdf0e10cSrcweir 					bDebugResult = sal_True;
662cdf0e10cSrcweir 					xReturnShape = xShape;
663cdf0e10cSrcweir 				}
664cdf0e10cSrcweir 				else
665cdf0e10cSrcweir 					++i;
666cdf0e10cSrcweir 			}
667cdf0e10cSrcweir 		}
668cdf0e10cSrcweir 	}
669cdf0e10cSrcweir     DBG_ASSERT((bResult == bDebugResult) && ((bResult && (rShape.get() == xReturnShape.get())) || !bResult), "found the wrong shape or result");
670cdf0e10cSrcweir #endif
671cdf0e10cSrcweir 
672cdf0e10cSrcweir     return bResult;
673cdf0e10cSrcweir }
674cdf0e10cSrcweir 
675cdf0e10cSrcweir sal_Bool ScChildrenShapes::SelectionChanged()
676cdf0e10cSrcweir {
677cdf0e10cSrcweir     sal_Bool bResult(sal_False);
678cdf0e10cSrcweir 	if (!xSelectionSupplier.is())
679cdf0e10cSrcweir 		throw uno::RuntimeException();
680cdf0e10cSrcweir 
681cdf0e10cSrcweir 	uno::Reference<drawing::XShapes> xShapes(xSelectionSupplier->getSelection(), uno::UNO_QUERY);
682cdf0e10cSrcweir 
683cdf0e10cSrcweir 	bResult = FindSelectedShapesChanges(xShapes, sal_True);
684cdf0e10cSrcweir 
685cdf0e10cSrcweir     return bResult;
686cdf0e10cSrcweir }
687cdf0e10cSrcweir 
688cdf0e10cSrcweir void ScChildrenShapes::Select(sal_Int32 nIndex)
689cdf0e10cSrcweir {
690cdf0e10cSrcweir 	if (maZOrderedShapes.size() <= 1)
691cdf0e10cSrcweir 		GetCount(); // fill list with filtered shapes (no internal shapes)
692cdf0e10cSrcweir 
693cdf0e10cSrcweir 	if (!xSelectionSupplier.is())
694cdf0e10cSrcweir 		throw uno::RuntimeException();
695cdf0e10cSrcweir 
696cdf0e10cSrcweir     if (!maZOrderedShapes[nIndex])
697cdf0e10cSrcweir         return;
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 	uno::Reference<drawing::XShape> xShape;
700cdf0e10cSrcweir 	if (!IsSelected(nIndex, xShape) && maZOrderedShapes[nIndex]->bSelectable)
701cdf0e10cSrcweir 	{
702cdf0e10cSrcweir 		uno::Reference<drawing::XShapes> xShapes;
703cdf0e10cSrcweir 		xSelectionSupplier->getSelection() >>= xShapes;
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 		if (!xShapes.is())
706cdf0e10cSrcweir 			xShapes = new SvxShapeCollection();
707cdf0e10cSrcweir 
708cdf0e10cSrcweir 		xShapes->add(maZOrderedShapes[nIndex]->xShape);
709cdf0e10cSrcweir 
710cdf0e10cSrcweir         try
711cdf0e10cSrcweir         {
712cdf0e10cSrcweir             xSelectionSupplier->select(uno::makeAny(xShapes));
713cdf0e10cSrcweir 		    maZOrderedShapes[nIndex]->bSelected = sal_True;
714cdf0e10cSrcweir 		    if (maZOrderedShapes[nIndex]->pAccShape)
715cdf0e10cSrcweir 			    maZOrderedShapes[nIndex]->pAccShape->SetState(AccessibleStateType::SELECTED);
716cdf0e10cSrcweir         }
717cdf0e10cSrcweir         catch (lang::IllegalArgumentException&)
718cdf0e10cSrcweir         {
719cdf0e10cSrcweir         }
720cdf0e10cSrcweir 	}
721cdf0e10cSrcweir }
722cdf0e10cSrcweir 
723cdf0e10cSrcweir void ScChildrenShapes::DeselectAll()
724cdf0e10cSrcweir {
725cdf0e10cSrcweir 	if (!xSelectionSupplier.is())
726cdf0e10cSrcweir 		throw uno::RuntimeException();
727cdf0e10cSrcweir 
728cdf0e10cSrcweir     sal_Bool bSomethingSelected(sal_True);
729cdf0e10cSrcweir     try
730cdf0e10cSrcweir     {
731cdf0e10cSrcweir         xSelectionSupplier->select(uno::Any()); //deselects all
732cdf0e10cSrcweir     }
733cdf0e10cSrcweir     catch (lang::IllegalArgumentException&)
734cdf0e10cSrcweir     {
735cdf0e10cSrcweir         DBG_ERRORFILE("nothing selected before");
736cdf0e10cSrcweir         bSomethingSelected = sal_False;
737cdf0e10cSrcweir     }
738cdf0e10cSrcweir 
739cdf0e10cSrcweir     if (bSomethingSelected)
740cdf0e10cSrcweir         std::for_each(maZOrderedShapes.begin(), maZOrderedShapes.end(), DeselectShape());
741cdf0e10cSrcweir }
742cdf0e10cSrcweir 
743cdf0e10cSrcweir void ScChildrenShapes::SelectAll()
744cdf0e10cSrcweir {
745cdf0e10cSrcweir 	if (!xSelectionSupplier.is())
746cdf0e10cSrcweir 		throw uno::RuntimeException();
747cdf0e10cSrcweir 
748cdf0e10cSrcweir 	if (maZOrderedShapes.size() <= 1)
749cdf0e10cSrcweir 		GetCount(); // fill list with filtered shapes (no internal shapes)
750cdf0e10cSrcweir 
751cdf0e10cSrcweir     if (maZOrderedShapes.size() > 1)
752cdf0e10cSrcweir     {
753cdf0e10cSrcweir 	    uno::Reference<drawing::XShapes> xShapes;
754cdf0e10cSrcweir 	    xShapes = new SvxShapeCollection();
755cdf0e10cSrcweir 
756cdf0e10cSrcweir         try
757cdf0e10cSrcweir         {
758cdf0e10cSrcweir             std::for_each(maZOrderedShapes.begin(), maZOrderedShapes.end(), SelectShape(xShapes));
759cdf0e10cSrcweir     	    xSelectionSupplier->select(uno::makeAny(xShapes));
760cdf0e10cSrcweir         }
761cdf0e10cSrcweir         catch (lang::IllegalArgumentException&)
762cdf0e10cSrcweir         {
763cdf0e10cSrcweir             SelectionChanged(); // find all selected shapes and set the flags
764cdf0e10cSrcweir         }
765cdf0e10cSrcweir     }
766cdf0e10cSrcweir }
767cdf0e10cSrcweir 
768cdf0e10cSrcweir void ScChildrenShapes::FillShapes(std::vector < uno::Reference < drawing::XShape > >& rShapes) const
769cdf0e10cSrcweir {
770cdf0e10cSrcweir 	uno::Reference<container::XIndexAccess> xIndexAccess;
771cdf0e10cSrcweir 	xSelectionSupplier->getSelection() >>= xIndexAccess;
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 	if (xIndexAccess.is())
774cdf0e10cSrcweir     {
775cdf0e10cSrcweir         sal_uInt32 nCount(xIndexAccess->getCount());
776cdf0e10cSrcweir         for (sal_uInt32 i = 0; i < nCount; ++i)
777cdf0e10cSrcweir         {
778cdf0e10cSrcweir     		uno::Reference<drawing::XShape> xShape;
779cdf0e10cSrcweir             xIndexAccess->getByIndex(i) >>= xShape;
780cdf0e10cSrcweir             if (xShape.is())
781cdf0e10cSrcweir                 rShapes.push_back(xShape);
782cdf0e10cSrcweir         }
783cdf0e10cSrcweir     }
784cdf0e10cSrcweir }
785cdf0e10cSrcweir 
786cdf0e10cSrcweir sal_Int32 ScChildrenShapes::GetSelectedCount() const
787cdf0e10cSrcweir {
788cdf0e10cSrcweir 	if (!xSelectionSupplier.is())
789cdf0e10cSrcweir 		throw uno::RuntimeException();
790cdf0e10cSrcweir 
791cdf0e10cSrcweir     std::vector < uno::Reference < drawing::XShape > > aShapes;
792cdf0e10cSrcweir     FillShapes(aShapes);
793cdf0e10cSrcweir 
794cdf0e10cSrcweir     return aShapes.size();
795cdf0e10cSrcweir }
796cdf0e10cSrcweir 
797cdf0e10cSrcweir uno::Reference< XAccessible > ScChildrenShapes::GetSelected(sal_Int32 nSelectedChildIndex, sal_Bool bTabSelected) const
798cdf0e10cSrcweir {
799cdf0e10cSrcweir     uno::Reference< XAccessible > xAccessible;
800cdf0e10cSrcweir 
801cdf0e10cSrcweir 	if (maZOrderedShapes.size() <= 1)
802cdf0e10cSrcweir 		GetCount(); // fill list with shapes
803cdf0e10cSrcweir 
804cdf0e10cSrcweir     if (!bTabSelected)
805cdf0e10cSrcweir     {
806cdf0e10cSrcweir         std::vector < uno::Reference < drawing::XShape > > aShapes;
807cdf0e10cSrcweir         FillShapes(aShapes);
808cdf0e10cSrcweir 
8090deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
8100deba7fbSSteve Yin 		if(aShapes.size()<=0) return xAccessible;
8110deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
812cdf0e10cSrcweir         SortedShapes::iterator aItr;
813cdf0e10cSrcweir         if (FindShape(aShapes[nSelectedChildIndex], aItr))
814cdf0e10cSrcweir             xAccessible = Get(aItr - maZOrderedShapes.begin());
815cdf0e10cSrcweir     }
816cdf0e10cSrcweir     else
817cdf0e10cSrcweir     {
818cdf0e10cSrcweir         SortedShapes::iterator aItr = maZOrderedShapes.begin();
819cdf0e10cSrcweir         SortedShapes::iterator aEndItr = maZOrderedShapes.end();
820cdf0e10cSrcweir         sal_Bool bFound(sal_False);
821cdf0e10cSrcweir         while(!bFound && aItr != aEndItr)
822cdf0e10cSrcweir         {
823cdf0e10cSrcweir             if (*aItr)
824cdf0e10cSrcweir             {
825cdf0e10cSrcweir                 if ((*aItr)->bSelected)
826cdf0e10cSrcweir                 {
827cdf0e10cSrcweir                     if (nSelectedChildIndex == 0)
828cdf0e10cSrcweir                         bFound = sal_True;
829cdf0e10cSrcweir                     else
830cdf0e10cSrcweir                         --nSelectedChildIndex;
831cdf0e10cSrcweir                 }
832cdf0e10cSrcweir             }
833cdf0e10cSrcweir             else
834cdf0e10cSrcweir             {
835cdf0e10cSrcweir                 if (nSelectedChildIndex == 0)
836cdf0e10cSrcweir                     bFound = sal_True;
837cdf0e10cSrcweir                 else
838cdf0e10cSrcweir                     --nSelectedChildIndex;
839cdf0e10cSrcweir             }
840cdf0e10cSrcweir             if (!bFound)
841cdf0e10cSrcweir                 ++aItr;
842cdf0e10cSrcweir         }
843cdf0e10cSrcweir         if (bFound && *aItr)
844cdf0e10cSrcweir             xAccessible = (*aItr)->pAccShape;
845cdf0e10cSrcweir     }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir     return xAccessible;
848cdf0e10cSrcweir }
849cdf0e10cSrcweir 
850cdf0e10cSrcweir void ScChildrenShapes::Deselect(sal_Int32 nChildIndex)
851cdf0e10cSrcweir {
852cdf0e10cSrcweir 	uno::Reference<drawing::XShape> xShape;
853cdf0e10cSrcweir 	if (IsSelected(nChildIndex, xShape)) // returns false if it is the sheet
854cdf0e10cSrcweir 	{
855cdf0e10cSrcweir 		if (xShape.is())
856cdf0e10cSrcweir 		{
857cdf0e10cSrcweir 			uno::Reference<drawing::XShapes> xShapes;
858cdf0e10cSrcweir 			xSelectionSupplier->getSelection() >>= xShapes;
859cdf0e10cSrcweir 			if (xShapes.is())
860cdf0e10cSrcweir 				xShapes->remove(xShape);
861cdf0e10cSrcweir 
862cdf0e10cSrcweir             try
863cdf0e10cSrcweir             {
864cdf0e10cSrcweir 			    xSelectionSupplier->select(uno::makeAny(xShapes));
865cdf0e10cSrcweir             }
866cdf0e10cSrcweir             catch (lang::IllegalArgumentException&)
867cdf0e10cSrcweir             {
868cdf0e10cSrcweir                 DBG_ERRORFILE("something not selectable");
869cdf0e10cSrcweir             }
870cdf0e10cSrcweir 
871cdf0e10cSrcweir 			maZOrderedShapes[nChildIndex]->bSelected = sal_False;
872cdf0e10cSrcweir 			if (maZOrderedShapes[nChildIndex]->pAccShape)
873cdf0e10cSrcweir 				maZOrderedShapes[nChildIndex]->pAccShape->ResetState(AccessibleStateType::SELECTED);
874cdf0e10cSrcweir 		}
875cdf0e10cSrcweir 	}
876cdf0e10cSrcweir }
877cdf0e10cSrcweir 
878cdf0e10cSrcweir 
879cdf0e10cSrcweir SdrPage* ScChildrenShapes::GetDrawPage() const
880cdf0e10cSrcweir {
881cdf0e10cSrcweir 	SCTAB nTab(mpAccessibleDocument->getVisibleTable());
882cdf0e10cSrcweir 	SdrPage* pDrawPage = NULL;
883cdf0e10cSrcweir 	if (mpViewShell)
884cdf0e10cSrcweir 	{
885cdf0e10cSrcweir 		ScDocument* pDoc = mpViewShell->GetViewData()->GetDocument();
886cdf0e10cSrcweir 		if (pDoc && pDoc->GetDrawLayer())
887cdf0e10cSrcweir 		{
888cdf0e10cSrcweir 			ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
889cdf0e10cSrcweir 			if (pDrawLayer->HasObjects() && (pDrawLayer->GetPageCount() > nTab))
890cdf0e10cSrcweir 				pDrawPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(static_cast<sal_Int16>(nTab)));
891cdf0e10cSrcweir 		}
892cdf0e10cSrcweir 	}
893cdf0e10cSrcweir 	return pDrawPage;
894cdf0e10cSrcweir }
895cdf0e10cSrcweir 
896cdf0e10cSrcweir struct SetRelation
897cdf0e10cSrcweir {
898cdf0e10cSrcweir     const ScChildrenShapes* mpChildrenShapes;
899cdf0e10cSrcweir     mutable utl::AccessibleRelationSetHelper* mpRelationSet;
900cdf0e10cSrcweir     const ScAddress* mpAddress;
901cdf0e10cSrcweir     SetRelation(const ScChildrenShapes* pChildrenShapes, const ScAddress* pAddress)
902cdf0e10cSrcweir         :
903cdf0e10cSrcweir         mpChildrenShapes(pChildrenShapes),
904cdf0e10cSrcweir         mpRelationSet(NULL),
905cdf0e10cSrcweir         mpAddress(pAddress)
906cdf0e10cSrcweir     {
907cdf0e10cSrcweir     }
908cdf0e10cSrcweir 	void operator() (const ScAccessibleShapeData* pAccShapeData) const
909cdf0e10cSrcweir     {
910cdf0e10cSrcweir 	    if (pAccShapeData &&
911cdf0e10cSrcweir             ((!pAccShapeData->pRelationCell && !mpAddress) ||
912cdf0e10cSrcweir             (pAccShapeData->pRelationCell && mpAddress && (*(pAccShapeData->pRelationCell) == *mpAddress))))
913cdf0e10cSrcweir         {
914cdf0e10cSrcweir             if (!mpRelationSet)
915cdf0e10cSrcweir                 mpRelationSet = new utl::AccessibleRelationSetHelper();
916cdf0e10cSrcweir 
917cdf0e10cSrcweir             AccessibleRelation aRelation;
918cdf0e10cSrcweir             aRelation.TargetSet.realloc(1);
919cdf0e10cSrcweir             aRelation.TargetSet[0] = mpChildrenShapes->Get(pAccShapeData);
920cdf0e10cSrcweir             aRelation.RelationType = AccessibleRelationType::CONTROLLER_FOR;
921cdf0e10cSrcweir 
922cdf0e10cSrcweir             mpRelationSet->AddRelation(aRelation);
923cdf0e10cSrcweir         }
924cdf0e10cSrcweir     }
925cdf0e10cSrcweir };
926cdf0e10cSrcweir 
927cdf0e10cSrcweir utl::AccessibleRelationSetHelper* ScChildrenShapes::GetRelationSet(const ScAddress* pAddress) const
928cdf0e10cSrcweir {
929cdf0e10cSrcweir     SetRelation aSetRelation(this, pAddress);
930cdf0e10cSrcweir     ::std::for_each(maZOrderedShapes.begin(), maZOrderedShapes.end(), aSetRelation);
931cdf0e10cSrcweir     return aSetRelation.mpRelationSet;
932cdf0e10cSrcweir }
933cdf0e10cSrcweir 
934cdf0e10cSrcweir sal_Bool ScChildrenShapes::FindSelectedShapesChanges(const uno::Reference<drawing::XShapes>& xShapes, sal_Bool /* bCommitChange */) const
935cdf0e10cSrcweir {
936cdf0e10cSrcweir     sal_Bool bResult(sal_False);
937cdf0e10cSrcweir     SortedShapes aShapesList;
938cdf0e10cSrcweir     uno::Reference<container::XIndexAccess> xIndexAcc(xShapes, uno::UNO_QUERY);
939cdf0e10cSrcweir     if (xIndexAcc.is())
940cdf0e10cSrcweir     {
941cdf0e10cSrcweir         mnShapesSelected = xIndexAcc->getCount();
942cdf0e10cSrcweir         for (sal_uInt32 i = 0; i < mnShapesSelected; ++i)
943cdf0e10cSrcweir         {
944cdf0e10cSrcweir 			uno::Reference< drawing::XShape > xShape;
945cdf0e10cSrcweir             xIndexAcc->getByIndex(i) >>= xShape;
946cdf0e10cSrcweir             if (xShape.is())
947cdf0e10cSrcweir             {
948cdf0e10cSrcweir                 ScAccessibleShapeData* pShapeData = new ScAccessibleShapeData();
949cdf0e10cSrcweir                 pShapeData->xShape = xShape;
950cdf0e10cSrcweir                 aShapesList.push_back(pShapeData);
951cdf0e10cSrcweir             }
952cdf0e10cSrcweir         }
953cdf0e10cSrcweir     }
954cdf0e10cSrcweir     else
955cdf0e10cSrcweir         mnShapesSelected = 0;
9560deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
9570deba7fbSSteve Yin 	SdrObject *pFocusedObj = NULL;
9580deba7fbSSteve Yin 	if( mnShapesSelected == 1 && aShapesList.size() == 1)
9590deba7fbSSteve Yin 	{
9600deba7fbSSteve Yin 		pFocusedObj = GetSdrObjectFromXShape(aShapesList[0]->xShape);
9610deba7fbSSteve Yin 	}
9620deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
963cdf0e10cSrcweir     ScShapeDataLess aLess;
964cdf0e10cSrcweir     std::sort(aShapesList.begin(), aShapesList.end(), aLess);
9650deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
9660deba7fbSSteve Yin 	SortedShapes vecSelectedShapeAdd;
9670deba7fbSSteve Yin 	SortedShapes vecSelectedShapeRemove;
9680deba7fbSSteve Yin 	sal_Bool bHasSelect=sal_False;
9690deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
970cdf0e10cSrcweir     SortedShapes::iterator aXShapesItr(aShapesList.begin());
971cdf0e10cSrcweir     SortedShapes::const_iterator aXShapesEndItr(aShapesList.end());
972cdf0e10cSrcweir     SortedShapes::iterator aDataItr(maZOrderedShapes.begin());
973cdf0e10cSrcweir     SortedShapes::const_iterator aDataEndItr(maZOrderedShapes.end());
974cdf0e10cSrcweir     SortedShapes::const_iterator aFocusedItr = aDataEndItr;
975cdf0e10cSrcweir     while((aDataItr != aDataEndItr))
976cdf0e10cSrcweir     {
977cdf0e10cSrcweir         if (*aDataItr) // is it realy a shape or only the sheet
978cdf0e10cSrcweir         {
979cdf0e10cSrcweir             sal_Int8 nComp(0);
980cdf0e10cSrcweir             if (aXShapesItr == aXShapesEndItr)
981cdf0e10cSrcweir                 nComp = -1; // simulate that the Shape is lower, so the selction state will be removed
982cdf0e10cSrcweir             else
983cdf0e10cSrcweir                 nComp = Compare(*aDataItr, *aXShapesItr);
984cdf0e10cSrcweir             if (nComp == 0)
985cdf0e10cSrcweir             {
986cdf0e10cSrcweir                 if (!(*aDataItr)->bSelected)
987cdf0e10cSrcweir                 {
988cdf0e10cSrcweir                     (*aDataItr)->bSelected = sal_True;
989cdf0e10cSrcweir                     if ((*aDataItr)->pAccShape)
990cdf0e10cSrcweir                     {
991cdf0e10cSrcweir                         (*aDataItr)->pAccShape->SetState(AccessibleStateType::SELECTED);
992cdf0e10cSrcweir                         (*aDataItr)->pAccShape->ResetState(AccessibleStateType::FOCUSED);
993cdf0e10cSrcweir                         bResult = sal_True;
9940deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
9950deba7fbSSteve Yin 						vecSelectedShapeAdd.push_back((*aDataItr));
9960deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
997cdf0e10cSrcweir                     }
998cdf0e10cSrcweir                     aFocusedItr = aDataItr;
999cdf0e10cSrcweir                 }
10000deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
10010deba7fbSSteve Yin 				else
10020deba7fbSSteve Yin 				{
10030deba7fbSSteve Yin 					 bHasSelect = sal_True;
10040deba7fbSSteve Yin 				}
10050deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
1006cdf0e10cSrcweir                 ++aDataItr;
1007cdf0e10cSrcweir                 ++aXShapesItr;
1008cdf0e10cSrcweir             }
1009cdf0e10cSrcweir             else if (nComp < 0)
1010cdf0e10cSrcweir             {
1011cdf0e10cSrcweir                 if ((*aDataItr)->bSelected)
1012cdf0e10cSrcweir                 {
1013cdf0e10cSrcweir                     (*aDataItr)->bSelected = sal_False;
1014cdf0e10cSrcweir                     if ((*aDataItr)->pAccShape)
1015cdf0e10cSrcweir                     {
1016cdf0e10cSrcweir                         (*aDataItr)->pAccShape->ResetState(AccessibleStateType::SELECTED);
1017cdf0e10cSrcweir                         (*aDataItr)->pAccShape->ResetState(AccessibleStateType::FOCUSED);
1018cdf0e10cSrcweir                         bResult = sal_True;
10190deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
10200deba7fbSSteve Yin 						vecSelectedShapeRemove.push_back(*aDataItr);
10210deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
1022cdf0e10cSrcweir                     }
1023cdf0e10cSrcweir                 }
1024cdf0e10cSrcweir                 ++aDataItr;
1025cdf0e10cSrcweir             }
1026cdf0e10cSrcweir             else
1027cdf0e10cSrcweir             {
1028cdf0e10cSrcweir                 DBG_ERRORFILE("here is a selected shape which is not in the childlist");
1029cdf0e10cSrcweir                 ++aXShapesItr;
1030cdf0e10cSrcweir                 --mnShapesSelected;
1031cdf0e10cSrcweir             }
1032cdf0e10cSrcweir         }
1033cdf0e10cSrcweir         else
1034cdf0e10cSrcweir             ++aDataItr;
1035cdf0e10cSrcweir     }
10360deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
10370deba7fbSSteve Yin 	bool bWinFocus=false;
10380deba7fbSSteve Yin 	ScGridWindow* pWin = static_cast<ScGridWindow*>(mpViewShell->GetWindowByPos(meSplitPos));
10390deba7fbSSteve Yin 	if (pWin)
10400deba7fbSSteve Yin 	{
10410deba7fbSSteve Yin 		bWinFocus = pWin->HasFocus();
10420deba7fbSSteve Yin 	}
10430deba7fbSSteve Yin 	const SdrMarkList* pMarkList = NULL;
10440deba7fbSSteve Yin 	SdrObject* pMarkedObj = NULL;
10450deba7fbSSteve Yin 	SdrObject* pUpObj = NULL;
10460deba7fbSSteve Yin 	sal_Bool bIsFocuseMarked = sal_True;
10470deba7fbSSteve Yin 	if( mpViewShell && mnShapesSelected == 1 && bWinFocus)
10480deba7fbSSteve Yin 	{
10490deba7fbSSteve Yin 		ScDrawView* pScDrawView = mpViewShell->GetViewData()->GetScDrawView();
10500deba7fbSSteve Yin 		if( pScDrawView )
10510deba7fbSSteve Yin 		{
10520deba7fbSSteve Yin 			if( pScDrawView->GetMarkedObjectList().GetMarkCount() == 1 )
10530deba7fbSSteve Yin 			{
10540deba7fbSSteve Yin 				pMarkList = &(pScDrawView->GetMarkedObjectList());
10550deba7fbSSteve Yin 				pMarkedObj = pMarkList->GetMark(0)->GetMarkedSdrObj();
10560deba7fbSSteve Yin 				uno::Reference< drawing::XShape > xMarkedXShape (pMarkedObj->getUnoShape(), uno::UNO_QUERY);
10570deba7fbSSteve Yin 				if( aFocusedItr != aDataEndItr &&
10580deba7fbSSteve Yin 					(*aFocusedItr)->xShape.is() &&
10590deba7fbSSteve Yin 					xMarkedXShape.is() &&
10600deba7fbSSteve Yin 					(*aFocusedItr)->xShape != xMarkedXShape )
10610deba7fbSSteve Yin 					bIsFocuseMarked = sal_False;
10620deba7fbSSteve Yin 			}
10630deba7fbSSteve Yin 		}
10640deba7fbSSteve Yin 	}
10650deba7fbSSteve Yin     //if ((aFocusedItr != aDataEndItr) && (*aFocusedItr)->pAccShape && (mnShapesSelected == 1))
10660deba7fbSSteve Yin     if ( bIsFocuseMarked && (aFocusedItr != aDataEndItr) && (*aFocusedItr)->pAccShape && (mnShapesSelected == 1) && bWinFocus)
10670deba7fbSSteve Yin 	{
1068cdf0e10cSrcweir         (*aFocusedItr)->pAccShape->SetState(AccessibleStateType::FOCUSED);
10690deba7fbSSteve Yin 	}
10700deba7fbSSteve Yin 	else if( pFocusedObj && bWinFocus && pMarkList && pMarkList->GetMarkCount() == 1 && mnShapesSelected == 1 )
10710deba7fbSSteve Yin 	{
10720deba7fbSSteve Yin 		if( pMarkedObj )
10730deba7fbSSteve Yin 		{
10740deba7fbSSteve Yin 			uno::Reference< drawing::XShape > xMarkedXShape (pMarkedObj->getUnoShape(), uno::UNO_QUERY);
10750deba7fbSSteve Yin 			pUpObj = pMarkedObj->GetUpGroup();
1076cdf0e10cSrcweir 
10770deba7fbSSteve Yin 			if( pMarkedObj == pFocusedObj )
10780deba7fbSSteve Yin 			{
10790deba7fbSSteve Yin 				if( pUpObj )
10800deba7fbSSteve Yin 				{
10810deba7fbSSteve Yin 					uno::Reference< drawing::XShape > xUpGroupXShape (pUpObj->getUnoShape(), uno::UNO_QUERY);
10820deba7fbSSteve Yin 					uno::Reference < XAccessible > xAccGroupShape =
10830deba7fbSSteve Yin 						const_cast<ScChildrenShapes*>(this)->GetAccessibleCaption( xUpGroupXShape );
10840deba7fbSSteve Yin 					if( xAccGroupShape.is() )
10850deba7fbSSteve Yin 					{
10860deba7fbSSteve Yin 						::accessibility::AccessibleShape* pAccGroupShape =
10870deba7fbSSteve Yin 							static_cast< ::accessibility::AccessibleShape* >(xAccGroupShape.get());
10880deba7fbSSteve Yin 						if( pAccGroupShape )
10890deba7fbSSteve Yin 						{
10900deba7fbSSteve Yin 							sal_Int32 nCount =  pAccGroupShape->getAccessibleChildCount();
10910deba7fbSSteve Yin 							for( sal_Int32 i = 0; i < nCount; i++ )
10920deba7fbSSteve Yin 							{
10930deba7fbSSteve Yin 								uno::Reference<XAccessible> xAccShape = pAccGroupShape->getAccessibleChild(i);
10940deba7fbSSteve Yin 								if (xAccShape.is())
10950deba7fbSSteve Yin 								{
10960deba7fbSSteve Yin 									::accessibility::AccessibleShape* pChildAccShape =  static_cast< ::accessibility::AccessibleShape* >(xAccShape.get());
10970deba7fbSSteve Yin 									uno::Reference< drawing::XShape > xChildShape = pChildAccShape->GetXShape();
10980deba7fbSSteve Yin 									if (xChildShape == xMarkedXShape)
10990deba7fbSSteve Yin 									{
11000deba7fbSSteve Yin 			                			pChildAccShape->SetState(AccessibleStateType::FOCUSED);
11010deba7fbSSteve Yin 									}
11020deba7fbSSteve Yin 									else
11030deba7fbSSteve Yin 									{
11040deba7fbSSteve Yin 										pChildAccShape->ResetState(AccessibleStateType::FOCUSED);
11050deba7fbSSteve Yin 									}
11060deba7fbSSteve Yin 								}
11070deba7fbSSteve Yin 							}
11080deba7fbSSteve Yin 						}
11090deba7fbSSteve Yin 					}
11100deba7fbSSteve Yin 				}
11110deba7fbSSteve Yin 			}
11120deba7fbSSteve Yin 		}
11130deba7fbSSteve Yin 	}
11140deba7fbSSteve Yin 	if (vecSelectedShapeAdd.size() >= 10 )
11150deba7fbSSteve Yin 	{
11160deba7fbSSteve Yin 		AccessibleEventObject aEvent;
11170deba7fbSSteve Yin 		aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_WITHIN;
11180deba7fbSSteve Yin 		aEvent.Source = uno::Reference< XAccessible >(mpAccessibleDocument);
11190deba7fbSSteve Yin 		mpAccessibleDocument->CommitChange(aEvent);
11200deba7fbSSteve Yin 	}
11210deba7fbSSteve Yin 	else
11220deba7fbSSteve Yin 	{
11230deba7fbSSteve Yin 		SortedShapes::iterator vi = vecSelectedShapeAdd.begin();
11240deba7fbSSteve Yin 		for (; vi != vecSelectedShapeAdd.end() ; ++vi )
11250deba7fbSSteve Yin 		{
11260deba7fbSSteve Yin 			AccessibleEventObject aEvent;
11270deba7fbSSteve Yin 			if (bHasSelect)
11280deba7fbSSteve Yin 			{
11290deba7fbSSteve Yin 				aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_ADD;
11300deba7fbSSteve Yin 			}
11310deba7fbSSteve Yin 			else
11320deba7fbSSteve Yin 			{
11330deba7fbSSteve Yin 				aEvent.EventId = AccessibleEventId::SELECTION_CHANGED;
11340deba7fbSSteve Yin 			}
11350deba7fbSSteve Yin 			aEvent.Source = uno::Reference< XAccessible >(mpAccessibleDocument);
11360deba7fbSSteve Yin 			uno::Reference< XAccessible > xChild( (*vi)->pAccShape);
11370deba7fbSSteve Yin 			aEvent.NewValue <<= xChild;
11380deba7fbSSteve Yin 			mpAccessibleDocument->CommitChange(aEvent);
11390deba7fbSSteve Yin 		}
11400deba7fbSSteve Yin 	}
11410deba7fbSSteve Yin 	SortedShapes::iterator vi = vecSelectedShapeRemove.begin();
11420deba7fbSSteve Yin 	for (; vi != vecSelectedShapeRemove.end() ; ++vi )
11430deba7fbSSteve Yin 	{
11440deba7fbSSteve Yin 		AccessibleEventObject aEvent;
11450deba7fbSSteve Yin 		aEvent.EventId =  AccessibleEventId::SELECTION_CHANGED_REMOVE;
11460deba7fbSSteve Yin 		aEvent.Source = uno::Reference< XAccessible >(mpAccessibleDocument);
11470deba7fbSSteve Yin 		uno::Reference< XAccessible > xChild( (*vi)->pAccShape);
11480deba7fbSSteve Yin 		aEvent.NewValue <<= xChild;
11490deba7fbSSteve Yin 		mpAccessibleDocument->CommitChange(aEvent);
11500deba7fbSSteve Yin 	}
11510deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
1152cdf0e10cSrcweir     std::for_each(aShapesList.begin(), aShapesList.end(), Destroy());
1153cdf0e10cSrcweir 
1154cdf0e10cSrcweir     return bResult;
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir 
1157cdf0e10cSrcweir void ScChildrenShapes::FillSelectionSupplier() const
1158cdf0e10cSrcweir {
1159cdf0e10cSrcweir 	if (!xSelectionSupplier.is() && mpViewShell)
1160cdf0e10cSrcweir 	{
1161cdf0e10cSrcweir 		SfxViewFrame* pViewFrame = mpViewShell->GetViewFrame();
1162cdf0e10cSrcweir 		if (pViewFrame)
1163cdf0e10cSrcweir 		{
1164cdf0e10cSrcweir 			xSelectionSupplier = uno::Reference<view::XSelectionSupplier>(pViewFrame->GetFrame().GetController(), uno::UNO_QUERY);
1165cdf0e10cSrcweir 			if (xSelectionSupplier.is())
1166cdf0e10cSrcweir 			{
1167cdf0e10cSrcweir                 if (mpAccessibleDocument)
1168cdf0e10cSrcweir                     xSelectionSupplier->addSelectionChangeListener(mpAccessibleDocument);
1169cdf0e10cSrcweir 				uno::Reference<drawing::XShapes> xShapes (xSelectionSupplier->getSelection(), uno::UNO_QUERY);
1170cdf0e10cSrcweir 				if (xShapes.is())
1171cdf0e10cSrcweir 					mnShapesSelected = xShapes->getCount();
1172cdf0e10cSrcweir 			}
1173cdf0e10cSrcweir 		}
1174cdf0e10cSrcweir 	}
1175cdf0e10cSrcweir }
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir ScAddress* ScChildrenShapes::GetAnchor(const uno::Reference<drawing::XShape>& xShape) const
1178cdf0e10cSrcweir {
1179cdf0e10cSrcweir     ScAddress* pAddress = NULL;
1180cdf0e10cSrcweir     if (mpViewShell)
1181cdf0e10cSrcweir     {
1182cdf0e10cSrcweir 	    SvxShape* pShapeImp = SvxShape::getImplementation(xShape);
1183cdf0e10cSrcweir         uno::Reference<beans::XPropertySet> xShapeProp(xShape, uno::UNO_QUERY);
1184cdf0e10cSrcweir 	    if (pShapeImp && xShapeProp.is())
1185cdf0e10cSrcweir 	    {
1186cdf0e10cSrcweir 		    SdrObject *pSdrObj = pShapeImp->GetSdrObject();
1187cdf0e10cSrcweir 		    if (pSdrObj)
1188cdf0e10cSrcweir 		    {
1189cdf0e10cSrcweir 			    if (ScDrawLayer::GetAnchor(pSdrObj) == SCA_CELL)
1190cdf0e10cSrcweir 			    {
1191cdf0e10cSrcweir                     ScDocument* pDoc = mpViewShell->GetViewData()->GetDocument();
1192cdf0e10cSrcweir 				    if (pDoc)
1193cdf0e10cSrcweir 				    {
1194cdf0e10cSrcweir                         rtl::OUString sCaptionShape(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.CaptionShape"));
1195cdf0e10cSrcweir 					    awt::Point aPoint(xShape->getPosition());
1196cdf0e10cSrcweir 					    awt::Size aSize(xShape->getSize());
1197cdf0e10cSrcweir 					    rtl::OUString sType(xShape->getShapeType());
1198cdf0e10cSrcweir 					    Rectangle aRectangle(aPoint.X, aPoint.Y, aPoint.X + aSize.Width, aPoint.Y + aSize.Height);
1199cdf0e10cSrcweir 					    if ( sType.equals(sCaptionShape) )
1200cdf0e10cSrcweir 					    {
1201cdf0e10cSrcweir 						    awt::Point aRelativeCaptionPoint;
1202cdf0e10cSrcweir                             rtl::OUString sCaptionPoint( RTL_CONSTASCII_USTRINGPARAM( "CaptionPoint" ));
1203cdf0e10cSrcweir 						    xShapeProp->getPropertyValue( sCaptionPoint ) >>= aRelativeCaptionPoint;
1204cdf0e10cSrcweir 						    Point aCoreRelativeCaptionPoint(aRelativeCaptionPoint.X, aRelativeCaptionPoint.Y);
1205cdf0e10cSrcweir 						    Point aCoreAbsoluteCaptionPoint(aPoint.X, aPoint.Y);
1206cdf0e10cSrcweir 						    aCoreAbsoluteCaptionPoint += aCoreRelativeCaptionPoint;
1207cdf0e10cSrcweir 						    aRectangle.Union(Rectangle(aCoreAbsoluteCaptionPoint, aCoreAbsoluteCaptionPoint));
1208cdf0e10cSrcweir 					    }
1209cdf0e10cSrcweir 					    ScRange aRange = pDoc->GetRange(mpAccessibleDocument->getVisibleTable(), aRectangle);
1210cdf0e10cSrcweir                         pAddress = new ScAddress(aRange.aStart);
1211cdf0e10cSrcweir 				    }
1212cdf0e10cSrcweir 			    }
1213cdf0e10cSrcweir //			    else
1214cdf0e10cSrcweir //				    do nothing, because it is always a NULL Pointer
1215cdf0e10cSrcweir 		    }
1216cdf0e10cSrcweir 	    }
1217cdf0e10cSrcweir     }
1218cdf0e10cSrcweir 
1219cdf0e10cSrcweir     return pAddress;
1220cdf0e10cSrcweir }
1221cdf0e10cSrcweir 
1222cdf0e10cSrcweir uno::Reference<XAccessibleRelationSet> ScChildrenShapes::GetRelationSet(const ScAccessibleShapeData* pData) const
1223cdf0e10cSrcweir {
1224cdf0e10cSrcweir     utl::AccessibleRelationSetHelper* pRelationSet = new utl::AccessibleRelationSetHelper();
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir     if(pData && pRelationSet && mpAccessibleDocument)
1227cdf0e10cSrcweir     {
1228cdf0e10cSrcweir         uno::Reference<XAccessible> xAccessible = mpAccessibleDocument->GetAccessibleSpreadsheet(); // should be the current table
1229cdf0e10cSrcweir         if (pData->pRelationCell && xAccessible.is())
1230cdf0e10cSrcweir         {
1231cdf0e10cSrcweir             uno::Reference<XAccessibleTable> xAccTable (xAccessible->getAccessibleContext(), uno::UNO_QUERY);
1232cdf0e10cSrcweir             if (xAccTable.is())
1233cdf0e10cSrcweir                 xAccessible = xAccTable->getAccessibleCellAt(pData->pRelationCell->Row(), pData->pRelationCell->Col());
1234cdf0e10cSrcweir         }
1235cdf0e10cSrcweir         AccessibleRelation aRelation;
1236cdf0e10cSrcweir         aRelation.TargetSet.realloc(1);
1237cdf0e10cSrcweir         aRelation.TargetSet[0] = xAccessible;
1238cdf0e10cSrcweir         aRelation.RelationType = AccessibleRelationType::CONTROLLED_BY;
1239cdf0e10cSrcweir         pRelationSet->AddRelation(aRelation);
1240cdf0e10cSrcweir     }
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir     return pRelationSet;
1243cdf0e10cSrcweir }
1244cdf0e10cSrcweir 
1245cdf0e10cSrcweir void ScChildrenShapes::CheckWhetherAnchorChanged(const uno::Reference<drawing::XShape>& xShape) const
1246cdf0e10cSrcweir {
1247cdf0e10cSrcweir     SortedShapes::iterator aItr;
1248cdf0e10cSrcweir     if (FindShape(xShape, aItr))
1249cdf0e10cSrcweir         SetAnchor(xShape, *aItr);
1250cdf0e10cSrcweir }
1251cdf0e10cSrcweir 
1252cdf0e10cSrcweir void ScChildrenShapes::SetAnchor(const uno::Reference<drawing::XShape>& xShape, ScAccessibleShapeData* pData) const
1253cdf0e10cSrcweir {
1254cdf0e10cSrcweir     if (pData)
1255cdf0e10cSrcweir     {
1256cdf0e10cSrcweir         ScAddress* pAddress = GetAnchor(xShape);
1257cdf0e10cSrcweir         if ((pAddress && pData->pRelationCell && (*pAddress != *(pData->pRelationCell))) ||
1258cdf0e10cSrcweir             (!pAddress && pData->pRelationCell) || (pAddress && !pData->pRelationCell))
1259cdf0e10cSrcweir         {
1260cdf0e10cSrcweir             if (pData->pRelationCell)
1261cdf0e10cSrcweir                 delete pData->pRelationCell;
1262cdf0e10cSrcweir             pData->pRelationCell = pAddress;
1263cdf0e10cSrcweir             if (pData->pAccShape)
1264cdf0e10cSrcweir                 pData->pAccShape->SetRelationSet(GetRelationSet(pData));
1265cdf0e10cSrcweir         }
1266cdf0e10cSrcweir     }
1267cdf0e10cSrcweir }
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir void ScChildrenShapes::AddShape(const uno::Reference<drawing::XShape>& xShape, sal_Bool bCommitChange) const
1270cdf0e10cSrcweir {
1271cdf0e10cSrcweir     SortedShapes::iterator aFindItr;
1272cdf0e10cSrcweir     if (!FindShape(xShape, aFindItr))
1273cdf0e10cSrcweir     {
1274cdf0e10cSrcweir         ScAccessibleShapeData* pShape = new ScAccessibleShapeData();
1275cdf0e10cSrcweir         pShape->xShape = xShape;
1276cdf0e10cSrcweir         SortedShapes::iterator aNewItr = maZOrderedShapes.insert(aFindItr, pShape);
1277cdf0e10cSrcweir         SetAnchor(xShape, pShape);
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xShapeProp(xShape, uno::UNO_QUERY);
1280cdf0e10cSrcweir         if (xShapeProp.is())
1281cdf0e10cSrcweir         {
1282cdf0e10cSrcweir             uno::Any aPropAny = xShapeProp->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(  "LayerID" )));
1283cdf0e10cSrcweir 		    sal_Int16 nLayerID = 0;
1284cdf0e10cSrcweir 		    if( aPropAny >>= nLayerID )
1285cdf0e10cSrcweir 		    {
1286cdf0e10cSrcweir                 if( (nLayerID == SC_LAYER_INTERN) || (nLayerID == SC_LAYER_HIDDEN) )
1287cdf0e10cSrcweir                     pShape->bSelectable = sal_False;
1288cdf0e10cSrcweir                 else
1289cdf0e10cSrcweir                     pShape->bSelectable = sal_True;
1290cdf0e10cSrcweir             }
1291cdf0e10cSrcweir         }
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir         if (!xSelectionSupplier.is())
1295cdf0e10cSrcweir 		    throw uno::RuntimeException();
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir         uno::Reference<container::XEnumerationAccess> xEnumAcc(xSelectionSupplier->getSelection(), uno::UNO_QUERY);
1298cdf0e10cSrcweir 	    if (xEnumAcc.is())
1299cdf0e10cSrcweir 	    {
1300cdf0e10cSrcweir             uno::Reference<container::XEnumeration> xEnum = xEnumAcc->createEnumeration();
1301cdf0e10cSrcweir             if (xEnum.is())
1302cdf0e10cSrcweir             {
1303cdf0e10cSrcweir                 uno::Reference<drawing::XShape> xSelectedShape;
1304cdf0e10cSrcweir                 sal_Bool bFound(sal_False);
1305cdf0e10cSrcweir                 while (!bFound && xEnum->hasMoreElements())
1306cdf0e10cSrcweir                 {
1307cdf0e10cSrcweir                     xEnum->nextElement() >>= xSelectedShape;
1308cdf0e10cSrcweir                     if (xShape.is() && (xShape.get() == xSelectedShape.get()))
1309cdf0e10cSrcweir                     {
1310cdf0e10cSrcweir                         pShape->bSelected = sal_True;
1311cdf0e10cSrcweir                         bFound = sal_True;
1312cdf0e10cSrcweir                     }
1313cdf0e10cSrcweir                 }
1314cdf0e10cSrcweir             }
1315cdf0e10cSrcweir         }
1316cdf0e10cSrcweir         if (mpAccessibleDocument && bCommitChange)
1317cdf0e10cSrcweir         {
1318cdf0e10cSrcweir 			AccessibleEventObject aEvent;
1319cdf0e10cSrcweir 			aEvent.EventId = AccessibleEventId::CHILD;
1320cdf0e10cSrcweir 			aEvent.Source = uno::Reference< XAccessibleContext >(mpAccessibleDocument);
1321cdf0e10cSrcweir 			aEvent.NewValue <<= Get(aNewItr - maZOrderedShapes.begin());
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir 			mpAccessibleDocument->CommitChange(aEvent); // new child - event
1324cdf0e10cSrcweir         }
1325cdf0e10cSrcweir     }
1326cdf0e10cSrcweir     else
1327cdf0e10cSrcweir     {
1328cdf0e10cSrcweir         DBG_ERRORFILE("shape is always in the list");
1329cdf0e10cSrcweir     }
1330cdf0e10cSrcweir }
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir void ScChildrenShapes::RemoveShape(const uno::Reference<drawing::XShape>& xShape) const
1333cdf0e10cSrcweir {
1334cdf0e10cSrcweir     SortedShapes::iterator aItr;
1335cdf0e10cSrcweir     if (FindShape(xShape, aItr))
1336cdf0e10cSrcweir     {
1337cdf0e10cSrcweir         if (mpAccessibleDocument)
1338cdf0e10cSrcweir         {
1339cdf0e10cSrcweir             uno::Reference<XAccessible> xOldAccessible (Get(aItr - maZOrderedShapes.begin()));
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir             delete *aItr;
1342cdf0e10cSrcweir             maZOrderedShapes.erase(aItr);
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir             AccessibleEventObject aEvent;
1345cdf0e10cSrcweir 			aEvent.EventId = AccessibleEventId::CHILD;
1346cdf0e10cSrcweir 			aEvent.Source = uno::Reference< XAccessibleContext >(mpAccessibleDocument);
1347cdf0e10cSrcweir             aEvent.OldValue <<= uno::makeAny(xOldAccessible);
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir 			mpAccessibleDocument->CommitChange(aEvent); // child is gone - event
1350cdf0e10cSrcweir         }
1351cdf0e10cSrcweir         else
1352cdf0e10cSrcweir         {
1353cdf0e10cSrcweir             delete *aItr;
1354cdf0e10cSrcweir             maZOrderedShapes.erase(aItr);
1355cdf0e10cSrcweir         }
1356cdf0e10cSrcweir     }
1357cdf0e10cSrcweir     else
1358cdf0e10cSrcweir     {
1359cdf0e10cSrcweir         DBG_ERRORFILE("shape was not in internal list");
1360cdf0e10cSrcweir     }
1361cdf0e10cSrcweir }
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir sal_Bool ScChildrenShapes::FindShape(const uno::Reference<drawing::XShape>& xShape, ScChildrenShapes::SortedShapes::iterator& rItr) const
1364cdf0e10cSrcweir {
1365cdf0e10cSrcweir     sal_Bool bResult(sal_False);
1366cdf0e10cSrcweir     ScAccessibleShapeData aShape;
1367cdf0e10cSrcweir     aShape.xShape = xShape;
1368cdf0e10cSrcweir     ScShapeDataLess aLess;
1369cdf0e10cSrcweir     rItr = std::lower_bound(maZOrderedShapes.begin(), maZOrderedShapes.end(), &aShape, aLess);
1370cdf0e10cSrcweir     if ((rItr != maZOrderedShapes.end()) && (*rItr != NULL) && ((*rItr)->xShape.get() == xShape.get()))
1371cdf0e10cSrcweir         bResult = sal_True; // if the shape is found
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir #ifdef DBG_UTIL // test whether it finds truly the correct shape (perhaps it is not really sorted)
1374cdf0e10cSrcweir     SortedShapes::iterator aDebugItr = maZOrderedShapes.begin();
1375cdf0e10cSrcweir     SortedShapes::iterator aEndItr = maZOrderedShapes.end();
1376cdf0e10cSrcweir     sal_Bool bFound(sal_False);
1377cdf0e10cSrcweir     while (!bFound && aDebugItr != aEndItr)
1378cdf0e10cSrcweir     {
1379cdf0e10cSrcweir         if (*aDebugItr && ((*aDebugItr)->xShape.get() == xShape.get()))
1380cdf0e10cSrcweir             bFound = sal_True;
1381cdf0e10cSrcweir         else
1382cdf0e10cSrcweir             ++aDebugItr;
1383cdf0e10cSrcweir     }
1384cdf0e10cSrcweir     sal_Bool bResult2 = (aDebugItr != maZOrderedShapes.end());
1385cdf0e10cSrcweir     DBG_ASSERT((bResult == bResult2) && ((bResult && (rItr == aDebugItr)) || !bResult), "wrong Shape found");
1386cdf0e10cSrcweir #endif
1387cdf0e10cSrcweir     return bResult;
1388cdf0e10cSrcweir }
1389cdf0e10cSrcweir 
1390cdf0e10cSrcweir sal_Int8 ScChildrenShapes::Compare(const ScAccessibleShapeData* pData1,
1391cdf0e10cSrcweir 		const ScAccessibleShapeData* pData2) const
1392cdf0e10cSrcweir {
1393cdf0e10cSrcweir     ScShapeDataLess aLess;
1394cdf0e10cSrcweir 
1395cdf0e10cSrcweir     sal_Bool bResult1(aLess(pData1, pData2));
1396cdf0e10cSrcweir     sal_Bool bResult2(aLess(pData2, pData1));
1397cdf0e10cSrcweir 
1398cdf0e10cSrcweir 	sal_Int8 nResult(0);
1399cdf0e10cSrcweir     if (!bResult1 && bResult2)
1400cdf0e10cSrcweir         nResult = 1;
1401cdf0e10cSrcweir     else if (bResult1 && !bResult2)
1402cdf0e10cSrcweir         nResult = -1;
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir 	return nResult;
1405cdf0e10cSrcweir }
1406cdf0e10cSrcweir 
1407cdf0e10cSrcweir struct ScVisAreaChanged
1408cdf0e10cSrcweir {
1409cdf0e10cSrcweir     ScAccessibleDocument* mpAccDoc;
1410cdf0e10cSrcweir     ScVisAreaChanged(ScAccessibleDocument* pAccDoc) : mpAccDoc(pAccDoc) {}
1411cdf0e10cSrcweir 	void operator() (const ScAccessibleShapeData* pAccShapeData) const
1412cdf0e10cSrcweir     {
1413cdf0e10cSrcweir 	    if (pAccShapeData && pAccShapeData->pAccShape)
1414cdf0e10cSrcweir         {
1415cdf0e10cSrcweir             pAccShapeData->pAccShape->ViewForwarderChanged(::accessibility::IAccessibleViewForwarderListener::VISIBLE_AREA, mpAccDoc);
1416cdf0e10cSrcweir         }
1417cdf0e10cSrcweir     }
1418cdf0e10cSrcweir };
1419cdf0e10cSrcweir 
1420cdf0e10cSrcweir void ScChildrenShapes::VisAreaChanged() const
1421cdf0e10cSrcweir {
1422cdf0e10cSrcweir     ScVisAreaChanged aVisAreaChanged(mpAccessibleDocument);
1423cdf0e10cSrcweir     std::for_each(maZOrderedShapes.begin(), maZOrderedShapes.end(), aVisAreaChanged);
1424cdf0e10cSrcweir }
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir // ============================================================================
1427cdf0e10cSrcweir 
1428cdf0e10cSrcweir ScAccessibleDocument::ScAccessibleDocument(
1429cdf0e10cSrcweir         const uno::Reference<XAccessible>& rxParent,
1430cdf0e10cSrcweir 		ScTabViewShell* pViewShell,
1431cdf0e10cSrcweir 		ScSplitPos eSplitPos)
1432cdf0e10cSrcweir 	: ScAccessibleDocumentBase(rxParent),
1433cdf0e10cSrcweir 	mpViewShell(pViewShell),
1434cdf0e10cSrcweir 	meSplitPos(eSplitPos),
1435cdf0e10cSrcweir 	mpAccessibleSpreadsheet(NULL),
1436cdf0e10cSrcweir     mpChildrenShapes(NULL),
1437cdf0e10cSrcweir     mpTempAccEdit(NULL),
1438cdf0e10cSrcweir 	mbCompleteSheetSelected(sal_False)
1439cdf0e10cSrcweir {
1440cdf0e10cSrcweir 	if (pViewShell)
1441cdf0e10cSrcweir     {
1442cdf0e10cSrcweir 		pViewShell->AddAccessibilityObject(*this);
1443cdf0e10cSrcweir 	    Window *pWin = pViewShell->GetWindowByPos(eSplitPos);
1444cdf0e10cSrcweir 	    if( pWin )
1445cdf0e10cSrcweir 	    {
1446cdf0e10cSrcweir 		    pWin->AddChildEventListener( LINK( this, ScAccessibleDocument, WindowChildEventListener ));
1447cdf0e10cSrcweir 		    sal_uInt16 nCount =   pWin->GetChildCount();
1448cdf0e10cSrcweir 		    for( sal_uInt16 i=0; i < nCount; ++i )
1449cdf0e10cSrcweir 		    {
1450cdf0e10cSrcweir 			    Window *pChildWin = pWin->GetChild( i );
1451cdf0e10cSrcweir 			    if( pChildWin &&
1452cdf0e10cSrcweir 				    AccessibleRole::EMBEDDED_OBJECT == pChildWin->GetAccessibleRole() )
1453cdf0e10cSrcweir 				    AddChild( pChildWin->GetAccessible(), sal_False );
1454cdf0e10cSrcweir 		    }
1455cdf0e10cSrcweir 	    }
1456cdf0e10cSrcweir         if (pViewShell->GetViewData()->HasEditView( eSplitPos ))
1457cdf0e10cSrcweir         {
1458cdf0e10cSrcweir             uno::Reference<XAccessible> xAcc = new ScAccessibleEditObject(this, pViewShell->GetViewData()->GetEditView(eSplitPos),
1459cdf0e10cSrcweir                 pViewShell->GetWindowByPos(eSplitPos), GetCurrentCellName(), GetCurrentCellDescription(),
1460cdf0e10cSrcweir                 CellInEditMode);
1461cdf0e10cSrcweir             AddChild(xAcc, sal_False);
1462cdf0e10cSrcweir         }
1463cdf0e10cSrcweir     }
1464cdf0e10cSrcweir     maVisArea = GetVisibleArea_Impl();
1465cdf0e10cSrcweir }
1466cdf0e10cSrcweir 
1467cdf0e10cSrcweir void ScAccessibleDocument::Init()
1468cdf0e10cSrcweir {
1469cdf0e10cSrcweir     if(!mpChildrenShapes)
1470cdf0e10cSrcweir         mpChildrenShapes = new ScChildrenShapes(this, mpViewShell, meSplitPos);
1471cdf0e10cSrcweir }
1472cdf0e10cSrcweir 
1473cdf0e10cSrcweir ScAccessibleDocument::~ScAccessibleDocument(void)
1474cdf0e10cSrcweir {
1475cdf0e10cSrcweir 	if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
1476cdf0e10cSrcweir 	{
1477cdf0e10cSrcweir 		// increment refcount to prevent double call off dtor
1478cdf0e10cSrcweir 		osl_incrementInterlockedCount( &m_refCount );
1479cdf0e10cSrcweir 		dispose();
1480cdf0e10cSrcweir 	}
1481cdf0e10cSrcweir }
1482cdf0e10cSrcweir 
1483cdf0e10cSrcweir void SAL_CALL ScAccessibleDocument::disposing()
1484cdf0e10cSrcweir {
1485cdf0e10cSrcweir     ScUnoGuard aGuard;
1486cdf0e10cSrcweir 	FreeAccessibleSpreadsheet();
1487cdf0e10cSrcweir 	if (mpViewShell)
1488cdf0e10cSrcweir 	{
1489cdf0e10cSrcweir         Window *pWin = mpViewShell->GetWindowByPos(meSplitPos);
1490cdf0e10cSrcweir 	    if( pWin )
1491cdf0e10cSrcweir 		    pWin->RemoveChildEventListener( LINK( this, ScAccessibleDocument, WindowChildEventListener ));
1492cdf0e10cSrcweir 
1493cdf0e10cSrcweir         mpViewShell->RemoveAccessibilityObject(*this);
1494cdf0e10cSrcweir 		mpViewShell = NULL;
1495cdf0e10cSrcweir 	}
1496cdf0e10cSrcweir     if (mpChildrenShapes)
1497cdf0e10cSrcweir         DELETEZ(mpChildrenShapes);
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir 	ScAccessibleDocumentBase::disposing();
1500cdf0e10cSrcweir }
1501cdf0e10cSrcweir 
1502cdf0e10cSrcweir void SAL_CALL ScAccessibleDocument::disposing( const lang::EventObject& /* Source */ )
1503cdf0e10cSrcweir 		throw (uno::RuntimeException)
1504cdf0e10cSrcweir {
1505cdf0e10cSrcweir 	disposing();
1506cdf0e10cSrcweir }
1507cdf0e10cSrcweir 
1508cdf0e10cSrcweir 	//=====  SfxListener  =====================================================
1509cdf0e10cSrcweir 
1510cdf0e10cSrcweir IMPL_LINK( ScAccessibleDocument, WindowChildEventListener, VclSimpleEvent*, pEvent )
1511cdf0e10cSrcweir {
1512cdf0e10cSrcweir 	DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
1513cdf0e10cSrcweir 	if ( pEvent && pEvent->ISA( VclWindowEvent ) )
1514cdf0e10cSrcweir 	{
1515cdf0e10cSrcweir 		VclWindowEvent *pVclEvent = static_cast< VclWindowEvent * >( pEvent );
1516cdf0e10cSrcweir 		DBG_ASSERT( pVclEvent->GetWindow(), "Window???" );
1517cdf0e10cSrcweir 		switch ( pVclEvent->GetId() )
1518cdf0e10cSrcweir 		{
1519cdf0e10cSrcweir         case VCLEVENT_WINDOW_SHOW:  // send create on show for direct accessible children
1520cdf0e10cSrcweir 			{
1521cdf0e10cSrcweir 				Window* pChildWin = static_cast < Window * >( pVclEvent->GetData() );
1522cdf0e10cSrcweir 				if( pChildWin && AccessibleRole::EMBEDDED_OBJECT == pChildWin->GetAccessibleRole() )
1523cdf0e10cSrcweir 				{
1524cdf0e10cSrcweir 					AddChild( pChildWin->GetAccessible(), sal_True );
1525cdf0e10cSrcweir 				}
1526cdf0e10cSrcweir 			}
1527cdf0e10cSrcweir 			break;
1528cdf0e10cSrcweir         case VCLEVENT_WINDOW_HIDE:  // send destroy on hide for direct accessible children
1529cdf0e10cSrcweir 			{
1530cdf0e10cSrcweir 				Window* pChildWin = static_cast < Window * >( pVclEvent->GetData() );
1531cdf0e10cSrcweir 				if( pChildWin && AccessibleRole::EMBEDDED_OBJECT == pChildWin->GetAccessibleRole() )
1532cdf0e10cSrcweir 				{
1533cdf0e10cSrcweir 					RemoveChild( pChildWin->GetAccessible(), sal_True );
1534cdf0e10cSrcweir 				}
1535cdf0e10cSrcweir 			}
1536cdf0e10cSrcweir 			break;
1537cdf0e10cSrcweir 		}
1538cdf0e10cSrcweir 	}
1539cdf0e10cSrcweir 	return 0;
1540cdf0e10cSrcweir }
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir void ScAccessibleDocument::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1543cdf0e10cSrcweir {
1544cdf0e10cSrcweir 	if (rHint.ISA( ScAccGridWinFocusLostHint ) )
1545cdf0e10cSrcweir 	{
1546cdf0e10cSrcweir 		const ScAccGridWinFocusLostHint& rRef = (const ScAccGridWinFocusLostHint&)rHint;
1547cdf0e10cSrcweir 		if (rRef.GetOldGridWin() == meSplitPos)
1548cdf0e10cSrcweir         {
1549cdf0e10cSrcweir             if (mxTempAcc.is() && mpTempAccEdit)
1550cdf0e10cSrcweir                 mpTempAccEdit->LostFocus();
1551cdf0e10cSrcweir             else if (mpAccessibleSpreadsheet)
1552cdf0e10cSrcweir                 mpAccessibleSpreadsheet->LostFocus();
1553cdf0e10cSrcweir             else
1554cdf0e10cSrcweir                 CommitFocusLost();
1555cdf0e10cSrcweir         }
1556cdf0e10cSrcweir 	}
1557cdf0e10cSrcweir     else if (rHint.ISA( ScAccGridWinFocusGotHint ) )
1558cdf0e10cSrcweir 	{
1559cdf0e10cSrcweir 		const ScAccGridWinFocusGotHint& rRef = (const ScAccGridWinFocusGotHint&)rHint;
1560cdf0e10cSrcweir 		if (rRef.GetNewGridWin() == meSplitPos)
1561cdf0e10cSrcweir         {
15620deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
15630deba7fbSSteve Yin 			uno::Reference<XAccessible> xAccessible;
15640deba7fbSSteve Yin 			if (mpChildrenShapes)
15650deba7fbSSteve Yin 			{
15660deba7fbSSteve Yin 				sal_Bool bTabMarked(IsTableSelected());
15670deba7fbSSteve Yin 				xAccessible = mpChildrenShapes->GetSelected(0, bTabMarked);
15680deba7fbSSteve Yin 			}
15690deba7fbSSteve Yin 			if( xAccessible.is() )
15700deba7fbSSteve Yin 			{
15710deba7fbSSteve Yin 				uno::Any aNewValue;
15720deba7fbSSteve Yin 				aNewValue<<=AccessibleStateType::FOCUSED;
15730deba7fbSSteve Yin 				static_cast< ::accessibility::AccessibleShape* >(xAccessible.get())->
15740deba7fbSSteve Yin 					CommitChange(AccessibleEventId::STATE_CHANGED,
15750deba7fbSSteve Yin 								aNewValue,
15760deba7fbSSteve Yin 								uno::Any() );
15770deba7fbSSteve Yin 			}
15780deba7fbSSteve Yin 			else
15790deba7fbSSteve Yin 			{
1580cdf0e10cSrcweir             if (mxTempAcc.is() && mpTempAccEdit)
1581cdf0e10cSrcweir                 mpTempAccEdit->GotFocus();
1582cdf0e10cSrcweir             else if (mpAccessibleSpreadsheet)
1583cdf0e10cSrcweir                 mpAccessibleSpreadsheet->GotFocus();
1584cdf0e10cSrcweir             else
1585cdf0e10cSrcweir                 CommitFocusGained();
1586cdf0e10cSrcweir 			}
15870deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
15880deba7fbSSteve Yin         }
1589cdf0e10cSrcweir 	}
1590cdf0e10cSrcweir 	else if (rHint.ISA( SfxSimpleHint ))
1591cdf0e10cSrcweir 	{
1592cdf0e10cSrcweir 		const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
1593cdf0e10cSrcweir 		// only notify if child exist, otherwise it is not necessary
1594cdf0e10cSrcweir 		if ((rRef.GetId() == SC_HINT_ACC_TABLECHANGED) &&
1595cdf0e10cSrcweir 			mpAccessibleSpreadsheet)
1596cdf0e10cSrcweir 		{
1597cdf0e10cSrcweir 			FreeAccessibleSpreadsheet();
1598cdf0e10cSrcweir             if (mpChildrenShapes)
1599cdf0e10cSrcweir                 DELETEZ(mpChildrenShapes);
1600cdf0e10cSrcweir 
1601cdf0e10cSrcweir             // #124567# Accessibility: Shapes / form controls after reload not accessible
1602cdf0e10cSrcweir             if ( !mpChildrenShapes )
1603cdf0e10cSrcweir             {
1604cdf0e10cSrcweir                 mpChildrenShapes = new ScChildrenShapes( this, mpViewShell, meSplitPos );
1605cdf0e10cSrcweir             }
16060deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
16070deba7fbSSteve Yin 			//Invoke Init() to rebuild the mpChildrenShapes variable
16080deba7fbSSteve Yin 			this->Init();
16090deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
1610cdf0e10cSrcweir 			AccessibleEventObject aEvent;
1611cdf0e10cSrcweir 			aEvent.EventId = AccessibleEventId::INVALIDATE_ALL_CHILDREN;
1612cdf0e10cSrcweir 			aEvent.Source = uno::Reference< XAccessibleContext >(this);
1613cdf0e10cSrcweir 			CommitChange(aEvent); // all childs changed
16140deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
16150deba7fbSSteve Yin 			if (mpAccessibleSpreadsheet)
16160deba7fbSSteve Yin 				mpAccessibleSpreadsheet->FireFirstCellFocus();
16170deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
1618cdf0e10cSrcweir 		}
1619cdf0e10cSrcweir         else if (rRef.GetId() == SC_HINT_ACC_MAKEDRAWLAYER)
1620cdf0e10cSrcweir         {
1621cdf0e10cSrcweir             if (mpChildrenShapes)
1622cdf0e10cSrcweir                 mpChildrenShapes->SetDrawBroadcaster();
1623cdf0e10cSrcweir         }
1624cdf0e10cSrcweir         else if ((rRef.GetId() == SC_HINT_ACC_ENTEREDITMODE)) // this event comes only on creating edit field of a cell
1625cdf0e10cSrcweir         {
1626cdf0e10cSrcweir             if (mpViewShell && mpViewShell->GetViewData()->HasEditView(meSplitPos))
1627cdf0e10cSrcweir             {
16280deba7fbSSteve Yin 				//IAccessibility2 Implementation 2009------
16290deba7fbSSteve Yin 				EditEngine* pEditEng = mpViewShell->GetViewData()->GetEditView(meSplitPos)->GetEditEngine();
16300deba7fbSSteve Yin 				if (pEditEng && pEditEng->GetUpdateMode())
16310deba7fbSSteve Yin 				{
1632cdf0e10cSrcweir 					mpTempAccEdit = new ScAccessibleEditObject(this, mpViewShell->GetViewData()->GetEditView(meSplitPos),
1633cdf0e10cSrcweir 						mpViewShell->GetWindowByPos(meSplitPos), GetCurrentCellName(),
1634cdf0e10cSrcweir 						rtl::OUString(String(ScResId(STR_ACC_EDITLINE_DESCR))), CellInEditMode);
1635cdf0e10cSrcweir 					uno::Reference<XAccessible> xAcc = mpTempAccEdit;
1636cdf0e10cSrcweir 
1637cdf0e10cSrcweir 					AddChild(xAcc, sal_True);
1638cdf0e10cSrcweir 
1639cdf0e10cSrcweir 					if (mpAccessibleSpreadsheet)
1640cdf0e10cSrcweir 						mpAccessibleSpreadsheet->LostFocus();
1641cdf0e10cSrcweir 					else
1642cdf0e10cSrcweir 						CommitFocusLost();
1643cdf0e10cSrcweir 
1644cdf0e10cSrcweir 					mpTempAccEdit->GotFocus();
1645cdf0e10cSrcweir 				}
16460deba7fbSSteve Yin 				//------IAccessibility2 Implementation 2009
16470deba7fbSSteve Yin             }
1648cdf0e10cSrcweir         }
1649cdf0e10cSrcweir         else if (rRef.GetId() == SC_HINT_ACC_LEAVEEDITMODE)
1650cdf0e10cSrcweir         {
1651cdf0e10cSrcweir             if (mxTempAcc.is())
1652cdf0e10cSrcweir             {
1653cdf0e10cSrcweir                 if (mpTempAccEdit)
1654cdf0e10cSrcweir                     mpTempAccEdit->LostFocus();
1655cdf0e10cSrcweir 
1656cdf0e10cSrcweir                 mpTempAccEdit = NULL;
1657cdf0e10cSrcweir                 RemoveChild(mxTempAcc, sal_True);
16580deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
16590deba7fbSSteve Yin                 //if (mpAccessibleSpreadsheet)
16600deba7fbSSteve Yin                 if (mpAccessibleSpreadsheet && mpViewShell->IsActive())
16610deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
1662cdf0e10cSrcweir                     mpAccessibleSpreadsheet->GotFocus();
16630deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
16640deba7fbSSteve Yin                 //else
16650deba7fbSSteve Yin                 else if( mpViewShell->IsActive())
16660deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
1667cdf0e10cSrcweir                     CommitFocusGained();
1668cdf0e10cSrcweir             }
1669cdf0e10cSrcweir         }
1670cdf0e10cSrcweir         else if ((rRef.GetId() == SC_HINT_ACC_VISAREACHANGED) || (rRef.GetId() == SC_HINT_ACC_WINDOWRESIZED))
1671cdf0e10cSrcweir         {
1672cdf0e10cSrcweir             Rectangle aOldVisArea(maVisArea);
1673cdf0e10cSrcweir             maVisArea = GetVisibleArea_Impl();
1674cdf0e10cSrcweir 
1675cdf0e10cSrcweir             if (maVisArea != aOldVisArea)
1676cdf0e10cSrcweir             {
1677cdf0e10cSrcweir                 if (maVisArea.GetSize() != aOldVisArea.GetSize())
1678cdf0e10cSrcweir                 {
1679cdf0e10cSrcweir 			        AccessibleEventObject aEvent;
1680cdf0e10cSrcweir 			        aEvent.EventId = AccessibleEventId::BOUNDRECT_CHANGED;
1681cdf0e10cSrcweir 			        aEvent.Source = uno::Reference< XAccessibleContext >(this);
1682cdf0e10cSrcweir 
1683cdf0e10cSrcweir 			        CommitChange(aEvent);
1684cdf0e10cSrcweir 
1685cdf0e10cSrcweir                     if (mpAccessibleSpreadsheet)
1686cdf0e10cSrcweir                         mpAccessibleSpreadsheet->BoundingBoxChanged();
1687cdf0e10cSrcweir                 }
1688cdf0e10cSrcweir                 else if (mpAccessibleSpreadsheet)
1689cdf0e10cSrcweir                 {
1690cdf0e10cSrcweir                     mpAccessibleSpreadsheet->VisAreaChanged();
1691cdf0e10cSrcweir                 }
1692cdf0e10cSrcweir                 if (mpChildrenShapes)
1693cdf0e10cSrcweir                     mpChildrenShapes->VisAreaChanged();
1694cdf0e10cSrcweir             }
1695cdf0e10cSrcweir         }
1696cdf0e10cSrcweir 	}
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir 	ScAccessibleDocumentBase::Notify(rBC, rHint);
1699cdf0e10cSrcweir }
1700cdf0e10cSrcweir 
1701cdf0e10cSrcweir void SAL_CALL ScAccessibleDocument::selectionChanged( const lang::EventObject& /* aEvent */ )
1702cdf0e10cSrcweir 		throw (uno::RuntimeException)
1703cdf0e10cSrcweir {
1704cdf0e10cSrcweir 	sal_Bool bSelectionChanged(sal_False);
1705cdf0e10cSrcweir 	if (mpAccessibleSpreadsheet)
1706cdf0e10cSrcweir 	{
1707cdf0e10cSrcweir 		sal_Bool bOldSelected(mbCompleteSheetSelected);
1708cdf0e10cSrcweir 		mbCompleteSheetSelected = IsTableSelected();
1709cdf0e10cSrcweir 		if (bOldSelected != mbCompleteSheetSelected)
1710cdf0e10cSrcweir 		{
1711cdf0e10cSrcweir 			mpAccessibleSpreadsheet->CompleteSelectionChanged(mbCompleteSheetSelected);
1712cdf0e10cSrcweir 			bSelectionChanged = sal_True;
1713cdf0e10cSrcweir 		}
1714cdf0e10cSrcweir 	}
1715cdf0e10cSrcweir 
1716cdf0e10cSrcweir     if (mpChildrenShapes && mpChildrenShapes->SelectionChanged())
1717cdf0e10cSrcweir         bSelectionChanged = sal_True;
1718cdf0e10cSrcweir 
1719cdf0e10cSrcweir 	if (bSelectionChanged)
1720cdf0e10cSrcweir 	{
1721cdf0e10cSrcweir 		AccessibleEventObject aEvent;
1722cdf0e10cSrcweir 		aEvent.EventId = AccessibleEventId::SELECTION_CHANGED;
1723cdf0e10cSrcweir 		aEvent.Source = uno::Reference< XAccessibleContext >(this);
1724cdf0e10cSrcweir 
1725cdf0e10cSrcweir 		CommitChange(aEvent);
1726cdf0e10cSrcweir 	}
17270deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
17280deba7fbSSteve Yin     if(mpChildrenShapes )
17290deba7fbSSteve Yin 	{
17300deba7fbSSteve Yin 		mpChildrenShapes->SelectionChanged();
17310deba7fbSSteve Yin 	}
17320deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
1733cdf0e10cSrcweir }
1734cdf0e10cSrcweir 
1735cdf0e10cSrcweir 	//=====  XInterface  =====================================================
1736cdf0e10cSrcweir 
1737cdf0e10cSrcweir uno::Any SAL_CALL ScAccessibleDocument::queryInterface( uno::Type const & rType )
1738cdf0e10cSrcweir 	throw (uno::RuntimeException)
1739cdf0e10cSrcweir {
17400deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
17410deba7fbSSteve Yin 	uno::Any aAnyTmp;
17420deba7fbSSteve Yin 	if(rType == ::getCppuType((com::sun::star::uno::Reference<XAccessibleGetAccFlowTo> *)NULL) )
17430deba7fbSSteve Yin        {
17440deba7fbSSteve Yin 	     com::sun::star::uno::Reference<XAccessibleGetAccFlowTo> AccFromXShape = this;
17450deba7fbSSteve Yin             aAnyTmp <<= AccFromXShape;
17460deba7fbSSteve Yin 	     return aAnyTmp;
17470deba7fbSSteve Yin        }
17480deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
1749cdf0e10cSrcweir 	uno::Any aAny (ScAccessibleDocumentImpl::queryInterface(rType));
1750cdf0e10cSrcweir 	return aAny.hasValue() ? aAny : ScAccessibleContextBase::queryInterface(rType);
1751cdf0e10cSrcweir }
1752cdf0e10cSrcweir 
1753cdf0e10cSrcweir void SAL_CALL ScAccessibleDocument::acquire()
1754cdf0e10cSrcweir 	throw ()
1755cdf0e10cSrcweir {
1756cdf0e10cSrcweir 	ScAccessibleContextBase::acquire();
1757cdf0e10cSrcweir }
1758cdf0e10cSrcweir 
1759cdf0e10cSrcweir void SAL_CALL ScAccessibleDocument::release()
1760cdf0e10cSrcweir 	throw ()
1761cdf0e10cSrcweir {
1762cdf0e10cSrcweir 	ScAccessibleContextBase::release();
1763cdf0e10cSrcweir }
1764cdf0e10cSrcweir 
1765cdf0e10cSrcweir 	//=====  XAccessibleComponent  ============================================
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL ScAccessibleDocument::getAccessibleAtPoint(
1768cdf0e10cSrcweir 		const awt::Point& rPoint )
1769cdf0e10cSrcweir 		throw (uno::RuntimeException)
1770cdf0e10cSrcweir {
1771cdf0e10cSrcweir 	uno::Reference<XAccessible> xAccessible = NULL;
1772cdf0e10cSrcweir     if (containsPoint(rPoint))
1773cdf0e10cSrcweir     {
1774cdf0e10cSrcweir     	ScUnoGuard aGuard;
1775cdf0e10cSrcweir         IsObjectValid();
1776cdf0e10cSrcweir         if (mpChildrenShapes)
1777cdf0e10cSrcweir             xAccessible = mpChildrenShapes->GetAt(rPoint);
1778cdf0e10cSrcweir 	    if(!xAccessible.is())
1779cdf0e10cSrcweir         {
1780cdf0e10cSrcweir             if (mxTempAcc.is())
1781cdf0e10cSrcweir             {
1782cdf0e10cSrcweir                 uno::Reference< XAccessibleContext > xCont(mxTempAcc->getAccessibleContext());
1783cdf0e10cSrcweir                 uno::Reference< XAccessibleComponent > xComp(xCont, uno::UNO_QUERY);
1784cdf0e10cSrcweir                 if (xComp.is())
1785cdf0e10cSrcweir                 {
1786cdf0e10cSrcweir                     Rectangle aBound(VCLRectangle(xComp->getBounds()));
1787cdf0e10cSrcweir                     if (aBound.IsInside(VCLPoint(rPoint)))
1788cdf0e10cSrcweir                         xAccessible = mxTempAcc;
1789cdf0e10cSrcweir                 }
1790cdf0e10cSrcweir             }
1791cdf0e10cSrcweir             if (!xAccessible.is())
1792cdf0e10cSrcweir 		        xAccessible = GetAccessibleSpreadsheet();
1793cdf0e10cSrcweir         }
1794cdf0e10cSrcweir     }
1795cdf0e10cSrcweir 	return xAccessible;
1796cdf0e10cSrcweir }
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir void SAL_CALL ScAccessibleDocument::grabFocus(  )
1799cdf0e10cSrcweir 		throw (uno::RuntimeException)
1800cdf0e10cSrcweir {
1801cdf0e10cSrcweir 	ScUnoGuard aGuard;
1802cdf0e10cSrcweir     IsObjectValid();
1803cdf0e10cSrcweir 	if (getAccessibleParent().is())
1804cdf0e10cSrcweir 	{
1805cdf0e10cSrcweir 		uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
1806cdf0e10cSrcweir 		if (xAccessibleComponent.is())
1807cdf0e10cSrcweir 		{
1808cdf0e10cSrcweir 			xAccessibleComponent->grabFocus();
1809cdf0e10cSrcweir 			// grab only focus if it does not have the focus and it is not hidden
1810cdf0e10cSrcweir 			if (mpViewShell && mpViewShell->GetViewData() &&
1811cdf0e10cSrcweir 				(mpViewShell->GetViewData()->GetActivePart() != meSplitPos) &&
1812cdf0e10cSrcweir 				mpViewShell->GetWindowByPos(meSplitPos)->IsVisible())
1813cdf0e10cSrcweir 			{
1814cdf0e10cSrcweir 				mpViewShell->ActivatePart(meSplitPos);
1815cdf0e10cSrcweir 			}
1816cdf0e10cSrcweir 		}
1817cdf0e10cSrcweir 	}
1818cdf0e10cSrcweir }
1819cdf0e10cSrcweir 
1820cdf0e10cSrcweir 	//=====  XAccessibleContext  ==============================================
1821cdf0e10cSrcweir 
1822cdf0e10cSrcweir     ///	Return the number of currently visible children.
1823cdf0e10cSrcweir sal_Int32 SAL_CALL
1824cdf0e10cSrcweir     ScAccessibleDocument::getAccessibleChildCount(void)
1825cdf0e10cSrcweir     throw (uno::RuntimeException)
1826cdf0e10cSrcweir {
1827cdf0e10cSrcweir 	ScUnoGuard aGuard;
1828cdf0e10cSrcweir     IsObjectValid();
1829cdf0e10cSrcweir     sal_Int32 nCount(1);
1830cdf0e10cSrcweir     if (mpChildrenShapes)
1831cdf0e10cSrcweir         nCount = mpChildrenShapes->GetCount(); // returns the count of the shapes inclusive the table
1832cdf0e10cSrcweir 
1833cdf0e10cSrcweir     if (mxTempAcc.is())
1834cdf0e10cSrcweir         ++nCount;
1835cdf0e10cSrcweir 
1836cdf0e10cSrcweir 	return nCount;
1837cdf0e10cSrcweir }
1838cdf0e10cSrcweir 
1839cdf0e10cSrcweir     ///	Return the specified child or NULL if index is invalid.
1840cdf0e10cSrcweir uno::Reference<XAccessible> SAL_CALL
1841cdf0e10cSrcweir     ScAccessibleDocument::getAccessibleChild(sal_Int32 nIndex)
1842cdf0e10cSrcweir     throw (uno::RuntimeException,
1843cdf0e10cSrcweir 		lang::IndexOutOfBoundsException)
1844cdf0e10cSrcweir {
1845cdf0e10cSrcweir 	ScUnoGuard aGuard;
1846cdf0e10cSrcweir     IsObjectValid();
1847cdf0e10cSrcweir 	uno::Reference<XAccessible> xAccessible;
1848cdf0e10cSrcweir 	if (nIndex >= 0)
1849cdf0e10cSrcweir 	{
1850cdf0e10cSrcweir         sal_Int32 nCount(1);
1851cdf0e10cSrcweir         if (mpChildrenShapes)
1852cdf0e10cSrcweir         {
1853cdf0e10cSrcweir             xAccessible = mpChildrenShapes->Get(nIndex); // returns NULL if it is the table or out of range
1854cdf0e10cSrcweir             nCount = mpChildrenShapes->GetCount(); //there is always a table
1855cdf0e10cSrcweir         }
1856cdf0e10cSrcweir         if (!xAccessible.is())
1857cdf0e10cSrcweir         {
1858cdf0e10cSrcweir             if (nIndex < nCount)
1859cdf0e10cSrcweir                 xAccessible = GetAccessibleSpreadsheet();
1860cdf0e10cSrcweir             else if (nIndex == nCount && mxTempAcc.is())
1861cdf0e10cSrcweir                 xAccessible = mxTempAcc;
1862cdf0e10cSrcweir         }
1863cdf0e10cSrcweir 	}
1864cdf0e10cSrcweir 
1865cdf0e10cSrcweir     if (!xAccessible.is())
1866cdf0e10cSrcweir         throw lang::IndexOutOfBoundsException();
1867cdf0e10cSrcweir 
1868cdf0e10cSrcweir 	return xAccessible;
1869cdf0e10cSrcweir }
1870cdf0e10cSrcweir 
1871cdf0e10cSrcweir     ///	Return the set of current states.
1872cdf0e10cSrcweir uno::Reference<XAccessibleStateSet> SAL_CALL
1873cdf0e10cSrcweir     ScAccessibleDocument::getAccessibleStateSet(void)
1874cdf0e10cSrcweir     throw (uno::RuntimeException)
1875cdf0e10cSrcweir {
1876cdf0e10cSrcweir 	ScUnoGuard aGuard;
1877cdf0e10cSrcweir 	uno::Reference<XAccessibleStateSet> xParentStates;
1878cdf0e10cSrcweir 	if (getAccessibleParent().is())
1879cdf0e10cSrcweir 	{
1880cdf0e10cSrcweir 		uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
1881cdf0e10cSrcweir 		xParentStates = xParentContext->getAccessibleStateSet();
1882cdf0e10cSrcweir 	}
1883cdf0e10cSrcweir 	utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
1884cdf0e10cSrcweir 	if (IsDefunc(xParentStates))
1885cdf0e10cSrcweir 		pStateSet->AddState(AccessibleStateType::DEFUNC);
1886cdf0e10cSrcweir     else
1887cdf0e10cSrcweir     {
1888cdf0e10cSrcweir 	    if (IsEditable(xParentStates))
1889cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::EDITABLE);
1890cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::ENABLED);
1891cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::OPAQUE);
1892cdf0e10cSrcweir 	    if (isShowing())
1893cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::SHOWING);
1894cdf0e10cSrcweir 	    if (isVisible())
1895cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::VISIBLE);
1896cdf0e10cSrcweir     }
1897cdf0e10cSrcweir 	return pStateSet;
1898cdf0e10cSrcweir }
1899cdf0e10cSrcweir 
19000deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
19010deba7fbSSteve Yin ::rtl::OUString SAL_CALL
19020deba7fbSSteve Yin     ScAccessibleDocument::getAccessibleName(void)
19030deba7fbSSteve Yin     throw (::com::sun::star::uno::RuntimeException)
19040deba7fbSSteve Yin {
19050deba7fbSSteve Yin 	rtl::OUString sName = String(ScResId(STR_ACC_DOC_SPREADSHEET));
19060deba7fbSSteve Yin 	ScDocument* pScDoc = GetDocument();
19070deba7fbSSteve Yin 	if ( pScDoc )
19080deba7fbSSteve Yin 	{
19090deba7fbSSteve Yin 		rtl::OUString sFileName = pScDoc->getDocAccTitle();
19100deba7fbSSteve Yin 		if ( !sFileName.getLength() )
19110deba7fbSSteve Yin 		{
19120deba7fbSSteve Yin 			SfxObjectShell* pObjSh = pScDoc->GetDocumentShell();
19130deba7fbSSteve Yin 			if ( pObjSh )
19140deba7fbSSteve Yin 			{
19150deba7fbSSteve Yin 				sFileName = pObjSh->GetTitle( SFX_TITLE_APINAME );
19160deba7fbSSteve Yin 			}
19170deba7fbSSteve Yin 		}
19180deba7fbSSteve Yin 		rtl::OUString sReadOnly;
19190deba7fbSSteve Yin 		if (pScDoc->getDocReadOnly())
19200deba7fbSSteve Yin 		{
19210deba7fbSSteve Yin 			sReadOnly = String(ScResId(STR_ACC_DOC_SPREADSHEET_READONLY));
19220deba7fbSSteve Yin 		}
19230deba7fbSSteve Yin 		if ( sFileName.getLength() )
19240deba7fbSSteve Yin 		{
19250deba7fbSSteve Yin 			sName = sFileName + sReadOnly + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - ")) + sName;
19260deba7fbSSteve Yin 		}
19270deba7fbSSteve Yin 	}
19280deba7fbSSteve Yin 	return sName;
19290deba7fbSSteve Yin }
19300deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
1931cdf0e10cSrcweir 	///=====  XAccessibleSelection  ===========================================
1932cdf0e10cSrcweir 
1933cdf0e10cSrcweir void SAL_CALL
1934cdf0e10cSrcweir 	ScAccessibleDocument::selectAccessibleChild( sal_Int32 nChildIndex )
1935cdf0e10cSrcweir 		throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1936cdf0e10cSrcweir {
1937cdf0e10cSrcweir 	ScUnoGuard aGuard;
1938cdf0e10cSrcweir     IsObjectValid();
1939cdf0e10cSrcweir 
1940cdf0e10cSrcweir     if (mpChildrenShapes)
1941cdf0e10cSrcweir     {
1942cdf0e10cSrcweir         sal_Int32 nCount(mpChildrenShapes->GetCount()); //all shapes and the table
1943cdf0e10cSrcweir         if (mxTempAcc.is())
1944cdf0e10cSrcweir             ++nCount;
1945cdf0e10cSrcweir         if (nChildIndex < 0 || nChildIndex >= nCount)
1946cdf0e10cSrcweir             throw lang::IndexOutOfBoundsException();
1947cdf0e10cSrcweir 
1948cdf0e10cSrcweir         uno::Reference < XAccessible > xAccessible = mpChildrenShapes->Get(nChildIndex);
1949cdf0e10cSrcweir         if (xAccessible.is())
1950cdf0e10cSrcweir         {
1951cdf0e10cSrcweir 		    sal_Bool bWasTableSelected(IsTableSelected());
1952cdf0e10cSrcweir 
1953cdf0e10cSrcweir             if (mpChildrenShapes)
1954cdf0e10cSrcweir                 mpChildrenShapes->Select(nChildIndex); // throws no lang::IndexOutOfBoundsException if Index is to high
1955cdf0e10cSrcweir 
1956cdf0e10cSrcweir 		    if (bWasTableSelected)
1957cdf0e10cSrcweir 			    mpViewShell->SelectAll();
1958cdf0e10cSrcweir         }
1959cdf0e10cSrcweir         else
1960cdf0e10cSrcweir         {
1961cdf0e10cSrcweir 		    if (mpViewShell)
1962cdf0e10cSrcweir 			    mpViewShell->SelectAll();
1963cdf0e10cSrcweir         }
1964cdf0e10cSrcweir     }
1965cdf0e10cSrcweir }
1966cdf0e10cSrcweir 
1967cdf0e10cSrcweir sal_Bool SAL_CALL
1968cdf0e10cSrcweir 	ScAccessibleDocument::isAccessibleChildSelected( sal_Int32 nChildIndex )
1969cdf0e10cSrcweir 		throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
1970cdf0e10cSrcweir {
1971cdf0e10cSrcweir 	ScUnoGuard aGuard;
1972cdf0e10cSrcweir     IsObjectValid();
1973cdf0e10cSrcweir 	sal_Bool bResult(sal_False);
1974cdf0e10cSrcweir 
1975cdf0e10cSrcweir     if (mpChildrenShapes)
1976cdf0e10cSrcweir     {
1977cdf0e10cSrcweir         sal_Int32 nCount(mpChildrenShapes->GetCount()); //all shapes and the table
1978cdf0e10cSrcweir         if (mxTempAcc.is())
1979cdf0e10cSrcweir             ++nCount;
1980cdf0e10cSrcweir         if (nChildIndex < 0 || nChildIndex >= nCount)
1981cdf0e10cSrcweir             throw lang::IndexOutOfBoundsException();
1982cdf0e10cSrcweir 
1983cdf0e10cSrcweir         uno::Reference < XAccessible > xAccessible = mpChildrenShapes->Get(nChildIndex);
1984cdf0e10cSrcweir         if (xAccessible.is())
1985cdf0e10cSrcweir         {
1986cdf0e10cSrcweir 		    uno::Reference<drawing::XShape> xShape;
1987cdf0e10cSrcweir 		    bResult = mpChildrenShapes->IsSelected(nChildIndex, xShape); // throws no lang::IndexOutOfBoundsException if Index is to high
1988cdf0e10cSrcweir         }
1989cdf0e10cSrcweir         else
1990cdf0e10cSrcweir         {
1991cdf0e10cSrcweir             if (mxTempAcc.is() && nChildIndex == nCount)
1992cdf0e10cSrcweir                 bResult = sal_True;
1993cdf0e10cSrcweir             else
1994cdf0e10cSrcweir     		    bResult = IsTableSelected();
1995cdf0e10cSrcweir         }
1996cdf0e10cSrcweir     }
1997cdf0e10cSrcweir 	return bResult;
1998cdf0e10cSrcweir }
1999cdf0e10cSrcweir 
2000cdf0e10cSrcweir void SAL_CALL
2001cdf0e10cSrcweir 	ScAccessibleDocument::clearAccessibleSelection(  )
2002cdf0e10cSrcweir 		throw (uno::RuntimeException)
2003cdf0e10cSrcweir {
2004cdf0e10cSrcweir 	ScUnoGuard aGuard;
2005cdf0e10cSrcweir     IsObjectValid();
2006cdf0e10cSrcweir 
2007cdf0e10cSrcweir     if (mpChildrenShapes)
2008cdf0e10cSrcweir         mpChildrenShapes->DeselectAll(); //deselects all (also the table)
2009cdf0e10cSrcweir }
2010cdf0e10cSrcweir 
2011cdf0e10cSrcweir void SAL_CALL
2012cdf0e10cSrcweir 	ScAccessibleDocument::selectAllAccessibleChildren(  )
2013cdf0e10cSrcweir 		throw (uno::RuntimeException)
2014cdf0e10cSrcweir {
2015cdf0e10cSrcweir 	ScUnoGuard aGuard;
2016cdf0e10cSrcweir     IsObjectValid();
2017cdf0e10cSrcweir 
2018cdf0e10cSrcweir     if (mpChildrenShapes)
2019cdf0e10cSrcweir         mpChildrenShapes->SelectAll();
2020cdf0e10cSrcweir 
2021cdf0e10cSrcweir 	// select table after shapes, because while selecting shapes the table will be deselected
2022cdf0e10cSrcweir 	if (mpViewShell)
2023cdf0e10cSrcweir 	{
2024cdf0e10cSrcweir 		mpViewShell->SelectAll();
2025cdf0e10cSrcweir 	}
2026cdf0e10cSrcweir }
2027cdf0e10cSrcweir 
2028cdf0e10cSrcweir sal_Int32 SAL_CALL
2029cdf0e10cSrcweir 	ScAccessibleDocument::getSelectedAccessibleChildCount(  )
2030cdf0e10cSrcweir 		throw (uno::RuntimeException)
2031cdf0e10cSrcweir {
2032cdf0e10cSrcweir 	ScUnoGuard aGuard;
2033cdf0e10cSrcweir     IsObjectValid();
2034cdf0e10cSrcweir 	sal_Int32 nCount(0);
2035cdf0e10cSrcweir 
2036cdf0e10cSrcweir     if (mpChildrenShapes)
2037cdf0e10cSrcweir         nCount = mpChildrenShapes->GetSelectedCount();
2038cdf0e10cSrcweir 
2039cdf0e10cSrcweir 	if (IsTableSelected())
2040cdf0e10cSrcweir 		++nCount;
2041cdf0e10cSrcweir 
2042cdf0e10cSrcweir     if (mxTempAcc.is())
2043cdf0e10cSrcweir         ++nCount;
2044cdf0e10cSrcweir 
2045cdf0e10cSrcweir 	return nCount;
2046cdf0e10cSrcweir }
2047cdf0e10cSrcweir 
2048cdf0e10cSrcweir uno::Reference<XAccessible > SAL_CALL
2049cdf0e10cSrcweir 	ScAccessibleDocument::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
2050cdf0e10cSrcweir 		throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2051cdf0e10cSrcweir {
2052cdf0e10cSrcweir 	ScUnoGuard aGuard;
2053cdf0e10cSrcweir     IsObjectValid();
2054cdf0e10cSrcweir 	uno::Reference<XAccessible> xAccessible;
2055cdf0e10cSrcweir     if (mpChildrenShapes)
2056cdf0e10cSrcweir     {
2057cdf0e10cSrcweir         sal_Int32 nCount(getSelectedAccessibleChildCount()); //all shapes and the table
2058cdf0e10cSrcweir         if (nSelectedChildIndex < 0 || nSelectedChildIndex >= nCount)
2059cdf0e10cSrcweir             throw lang::IndexOutOfBoundsException();
2060cdf0e10cSrcweir 
2061cdf0e10cSrcweir         sal_Bool bTabMarked(IsTableSelected());
2062cdf0e10cSrcweir 
2063cdf0e10cSrcweir         if (mpChildrenShapes)
2064cdf0e10cSrcweir             xAccessible = mpChildrenShapes->GetSelected(nSelectedChildIndex, bTabMarked); // throws no lang::IndexOutOfBoundsException if Index is to high
2065cdf0e10cSrcweir         if (mxTempAcc.is() && nSelectedChildIndex == nCount - 1)
2066cdf0e10cSrcweir             xAccessible = mxTempAcc;
2067cdf0e10cSrcweir         else if (bTabMarked)
2068cdf0e10cSrcweir             xAccessible = GetAccessibleSpreadsheet();
2069cdf0e10cSrcweir     }
2070cdf0e10cSrcweir 
2071cdf0e10cSrcweir     DBG_ASSERT(xAccessible.is(), "here should always be an accessible object or a exception throwed");
2072cdf0e10cSrcweir 
2073cdf0e10cSrcweir 	return xAccessible;
2074cdf0e10cSrcweir }
2075cdf0e10cSrcweir 
2076cdf0e10cSrcweir void SAL_CALL
2077cdf0e10cSrcweir 	ScAccessibleDocument::deselectAccessibleChild( sal_Int32 nChildIndex )
2078cdf0e10cSrcweir 		throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
2079cdf0e10cSrcweir {
2080cdf0e10cSrcweir 	ScUnoGuard aGuard;
2081cdf0e10cSrcweir     IsObjectValid();
2082cdf0e10cSrcweir 
2083cdf0e10cSrcweir     if (mpChildrenShapes)
2084cdf0e10cSrcweir     {
2085cdf0e10cSrcweir         sal_Int32 nCount(mpChildrenShapes->GetCount()); //all shapes and the table
2086cdf0e10cSrcweir         if (mxTempAcc.is())
2087cdf0e10cSrcweir             ++nCount;
2088cdf0e10cSrcweir         if (nChildIndex < 0 || nChildIndex >= nCount)
2089cdf0e10cSrcweir             throw lang::IndexOutOfBoundsException();
2090cdf0e10cSrcweir 
2091cdf0e10cSrcweir         sal_Bool bTabMarked(IsTableSelected());
2092cdf0e10cSrcweir 
2093cdf0e10cSrcweir         uno::Reference < XAccessible > xAccessible = mpChildrenShapes->Get(nChildIndex);
2094cdf0e10cSrcweir         if (xAccessible.is())
2095cdf0e10cSrcweir         {
2096cdf0e10cSrcweir             if (mpChildrenShapes)
2097cdf0e10cSrcweir                 mpChildrenShapes->Deselect(nChildIndex); // throws no lang::IndexOutOfBoundsException if Index is to high
2098cdf0e10cSrcweir 
2099cdf0e10cSrcweir 		    if (bTabMarked)
2100cdf0e10cSrcweir 			    mpViewShell->SelectAll(); // select the table again
2101cdf0e10cSrcweir         }
2102cdf0e10cSrcweir         else if (bTabMarked)
2103cdf0e10cSrcweir             mpViewShell->Unmark();
2104cdf0e10cSrcweir     }
2105cdf0e10cSrcweir }
2106cdf0e10cSrcweir 
2107cdf0e10cSrcweir 	//=====  XServiceInfo  ====================================================
2108cdf0e10cSrcweir 
2109cdf0e10cSrcweir ::rtl::OUString SAL_CALL
2110cdf0e10cSrcweir     ScAccessibleDocument::getImplementationName(void)
2111cdf0e10cSrcweir     throw (uno::RuntimeException)
2112cdf0e10cSrcweir {
2113cdf0e10cSrcweir 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ("ScAccessibleDocument"));
2114cdf0e10cSrcweir }
2115cdf0e10cSrcweir 
2116cdf0e10cSrcweir uno::Sequence< ::rtl::OUString> SAL_CALL
2117cdf0e10cSrcweir 	ScAccessibleDocument::getSupportedServiceNames(void)
2118cdf0e10cSrcweir         throw (uno::RuntimeException)
2119cdf0e10cSrcweir {
2120cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
2121cdf0e10cSrcweir     sal_Int32 nOldSize(aSequence.getLength());
2122cdf0e10cSrcweir     aSequence.realloc(nOldSize + 1);
2123cdf0e10cSrcweir     ::rtl::OUString* pNames = aSequence.getArray();
2124cdf0e10cSrcweir 
2125cdf0e10cSrcweir 	pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.AccessibleSpreadsheetDocumentView"));
2126cdf0e10cSrcweir 
2127cdf0e10cSrcweir 	return aSequence;
2128cdf0e10cSrcweir }
2129cdf0e10cSrcweir 
2130cdf0e10cSrcweir //=====  XTypeProvider  =======================================================
2131cdf0e10cSrcweir 
2132cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL ScAccessibleDocument::getTypes()
2133cdf0e10cSrcweir 		throw (uno::RuntimeException)
2134cdf0e10cSrcweir {
2135cdf0e10cSrcweir 	return comphelper::concatSequences(ScAccessibleDocumentImpl::getTypes(), ScAccessibleContextBase::getTypes());
2136cdf0e10cSrcweir }
2137cdf0e10cSrcweir 
2138cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL
2139cdf0e10cSrcweir 	ScAccessibleDocument::getImplementationId(void)
2140cdf0e10cSrcweir     throw (uno::RuntimeException)
2141cdf0e10cSrcweir {
2142cdf0e10cSrcweir     ScUnoGuard aGuard;
2143cdf0e10cSrcweir     IsObjectValid();
2144cdf0e10cSrcweir 	static uno::Sequence<sal_Int8> aId;
2145cdf0e10cSrcweir 	if (aId.getLength() == 0)
2146cdf0e10cSrcweir 	{
2147cdf0e10cSrcweir 		aId.realloc (16);
2148cdf0e10cSrcweir 		rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True);
2149cdf0e10cSrcweir 	}
2150cdf0e10cSrcweir 	return aId;
2151cdf0e10cSrcweir }
2152cdf0e10cSrcweir 
2153cdf0e10cSrcweir ///=====  IAccessibleViewForwarder  ========================================
2154cdf0e10cSrcweir 
2155cdf0e10cSrcweir sal_Bool ScAccessibleDocument::IsValid (void) const
2156cdf0e10cSrcweir {
2157cdf0e10cSrcweir     ScUnoGuard aGuard;
2158cdf0e10cSrcweir     IsObjectValid();
2159cdf0e10cSrcweir     return (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose);
2160cdf0e10cSrcweir }
2161cdf0e10cSrcweir 
2162cdf0e10cSrcweir Rectangle ScAccessibleDocument::GetVisibleArea_Impl() const
2163cdf0e10cSrcweir {
2164cdf0e10cSrcweir     Rectangle aVisRect(GetBoundingBox());
2165cdf0e10cSrcweir 
2166cdf0e10cSrcweir     Point aPoint(mpViewShell->GetViewData()->GetPixPos(meSplitPos)); // returns a negative Point
2167cdf0e10cSrcweir     aPoint.setX(-aPoint.getX());
2168cdf0e10cSrcweir     aPoint.setY(-aPoint.getY());
2169cdf0e10cSrcweir     aVisRect.SetPos(aPoint);
2170cdf0e10cSrcweir 
2171cdf0e10cSrcweir     ScGridWindow* pWin = static_cast<ScGridWindow*>(mpViewShell->GetWindowByPos(meSplitPos));
2172cdf0e10cSrcweir     if (pWin)
2173cdf0e10cSrcweir         aVisRect = pWin->PixelToLogic(aVisRect, pWin->GetDrawMapMode());
2174cdf0e10cSrcweir 
2175cdf0e10cSrcweir     return aVisRect;
2176cdf0e10cSrcweir }
2177cdf0e10cSrcweir 
2178cdf0e10cSrcweir Rectangle ScAccessibleDocument::GetVisibleArea() const
2179cdf0e10cSrcweir {
2180cdf0e10cSrcweir     ScUnoGuard aGuard;
2181cdf0e10cSrcweir     IsObjectValid();
2182cdf0e10cSrcweir     return maVisArea;
2183cdf0e10cSrcweir }
2184cdf0e10cSrcweir 
2185cdf0e10cSrcweir Point ScAccessibleDocument::LogicToPixel (const Point& rPoint) const
2186cdf0e10cSrcweir {
2187cdf0e10cSrcweir     ScUnoGuard aGuard;
2188cdf0e10cSrcweir     IsObjectValid();
2189cdf0e10cSrcweir     Point aPoint;
2190cdf0e10cSrcweir     ScGridWindow* pWin = static_cast<ScGridWindow*>(mpViewShell->GetWindowByPos(meSplitPos));
2191cdf0e10cSrcweir     if (pWin)
2192cdf0e10cSrcweir     {
2193cdf0e10cSrcweir         aPoint = pWin->LogicToPixel(rPoint, pWin->GetDrawMapMode());
2194cdf0e10cSrcweir         aPoint += pWin->GetWindowExtentsRelative(NULL).TopLeft();
2195cdf0e10cSrcweir     }
2196cdf0e10cSrcweir     return aPoint;
2197cdf0e10cSrcweir }
2198cdf0e10cSrcweir 
2199cdf0e10cSrcweir Size ScAccessibleDocument::LogicToPixel (const Size& rSize) const
2200cdf0e10cSrcweir {
2201cdf0e10cSrcweir     ScUnoGuard aGuard;
2202cdf0e10cSrcweir     IsObjectValid();
2203cdf0e10cSrcweir     Size aSize;
2204cdf0e10cSrcweir     ScGridWindow* pWin = static_cast<ScGridWindow*>(mpViewShell->GetWindowByPos(meSplitPos));
2205cdf0e10cSrcweir     if (pWin)
2206cdf0e10cSrcweir         aSize = pWin->LogicToPixel(rSize, pWin->GetDrawMapMode());
2207cdf0e10cSrcweir     return aSize;
2208cdf0e10cSrcweir }
2209cdf0e10cSrcweir 
2210cdf0e10cSrcweir Point ScAccessibleDocument::PixelToLogic (const Point& rPoint) const
2211cdf0e10cSrcweir {
2212cdf0e10cSrcweir     ScUnoGuard aGuard;
2213cdf0e10cSrcweir     IsObjectValid();
2214cdf0e10cSrcweir     Point aPoint;
2215cdf0e10cSrcweir     ScGridWindow* pWin = static_cast<ScGridWindow*>(mpViewShell->GetWindowByPos(meSplitPos));
2216cdf0e10cSrcweir     if (pWin)
2217cdf0e10cSrcweir     {
2218cdf0e10cSrcweir         aPoint -= pWin->GetWindowExtentsRelative(NULL).TopLeft();
2219cdf0e10cSrcweir         aPoint = pWin->PixelToLogic(rPoint, pWin->GetDrawMapMode());
2220cdf0e10cSrcweir     }
2221cdf0e10cSrcweir     return aPoint;
2222cdf0e10cSrcweir }
2223cdf0e10cSrcweir 
2224cdf0e10cSrcweir Size ScAccessibleDocument::PixelToLogic (const Size& rSize) const
2225cdf0e10cSrcweir {
2226cdf0e10cSrcweir     ScUnoGuard aGuard;
2227cdf0e10cSrcweir     IsObjectValid();
2228cdf0e10cSrcweir     Size aSize;
2229cdf0e10cSrcweir     ScGridWindow* pWin = static_cast<ScGridWindow*>(mpViewShell->GetWindowByPos(meSplitPos));
2230cdf0e10cSrcweir     if (pWin)
2231cdf0e10cSrcweir         aSize = pWin->PixelToLogic(rSize, pWin->GetDrawMapMode());
2232cdf0e10cSrcweir     return aSize;
2233cdf0e10cSrcweir }
2234cdf0e10cSrcweir 
2235cdf0e10cSrcweir     //=====  internal  ========================================================
2236cdf0e10cSrcweir 
2237cdf0e10cSrcweir utl::AccessibleRelationSetHelper* ScAccessibleDocument::GetRelationSet(const ScAddress* pAddress) const
2238cdf0e10cSrcweir {
2239cdf0e10cSrcweir     utl::AccessibleRelationSetHelper* pRelationSet = NULL;
2240cdf0e10cSrcweir     if (mpChildrenShapes)
2241cdf0e10cSrcweir         pRelationSet = mpChildrenShapes->GetRelationSet(pAddress);
2242cdf0e10cSrcweir     return pRelationSet;
2243cdf0e10cSrcweir }
2244cdf0e10cSrcweir 
2245cdf0e10cSrcweir ::rtl::OUString SAL_CALL
2246cdf0e10cSrcweir     ScAccessibleDocument::createAccessibleDescription(void)
2247cdf0e10cSrcweir     throw (uno::RuntimeException)
2248cdf0e10cSrcweir {
2249cdf0e10cSrcweir     rtl::OUString sDescription = String(ScResId(STR_ACC_DOC_DESCR));
2250cdf0e10cSrcweir 	return sDescription;
2251cdf0e10cSrcweir }
2252cdf0e10cSrcweir 
2253cdf0e10cSrcweir ::rtl::OUString SAL_CALL
2254cdf0e10cSrcweir     ScAccessibleDocument::createAccessibleName(void)
2255cdf0e10cSrcweir     throw (uno::RuntimeException)
2256cdf0e10cSrcweir {
2257cdf0e10cSrcweir 	ScUnoGuard aGuard;
2258cdf0e10cSrcweir     IsObjectValid();
2259cdf0e10cSrcweir 	rtl::OUString sName = String(ScResId(STR_ACC_DOC_NAME));
2260cdf0e10cSrcweir 	sal_Int32 nNumber(sal_Int32(meSplitPos) + 1);
2261cdf0e10cSrcweir 	sName += rtl::OUString::valueOf(nNumber);
2262cdf0e10cSrcweir 	return sName;
2263cdf0e10cSrcweir }
2264cdf0e10cSrcweir 
2265cdf0e10cSrcweir Rectangle ScAccessibleDocument::GetBoundingBoxOnScreen() const
2266cdf0e10cSrcweir 	throw (uno::RuntimeException)
2267cdf0e10cSrcweir {
2268cdf0e10cSrcweir 	Rectangle aRect;
2269cdf0e10cSrcweir 	if (mpViewShell)
2270cdf0e10cSrcweir 	{
2271cdf0e10cSrcweir 		Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
2272cdf0e10cSrcweir 		if (pWindow)
2273cdf0e10cSrcweir 			aRect = pWindow->GetWindowExtentsRelative(NULL);
2274cdf0e10cSrcweir 	}
2275cdf0e10cSrcweir 	return aRect;
2276cdf0e10cSrcweir }
2277cdf0e10cSrcweir 
2278cdf0e10cSrcweir Rectangle ScAccessibleDocument::GetBoundingBox() const
2279cdf0e10cSrcweir 	throw (uno::RuntimeException)
2280cdf0e10cSrcweir {
2281cdf0e10cSrcweir 	Rectangle aRect;
2282cdf0e10cSrcweir 	if (mpViewShell)
2283cdf0e10cSrcweir 	{
2284cdf0e10cSrcweir 		Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
2285cdf0e10cSrcweir 		if (pWindow)
2286cdf0e10cSrcweir 			aRect = pWindow->GetWindowExtentsRelative(pWindow->GetAccessibleParentWindow());
2287cdf0e10cSrcweir 	}
2288cdf0e10cSrcweir 	return aRect;
2289cdf0e10cSrcweir }
2290cdf0e10cSrcweir 
2291cdf0e10cSrcweir SCTAB ScAccessibleDocument::getVisibleTable() const
2292cdf0e10cSrcweir {
2293cdf0e10cSrcweir 	SCTAB nVisibleTable(0);
2294cdf0e10cSrcweir 	if (mpViewShell && mpViewShell->GetViewData())
2295cdf0e10cSrcweir 		nVisibleTable = mpViewShell->GetViewData()->GetTabNo();
2296cdf0e10cSrcweir 	return nVisibleTable;
2297cdf0e10cSrcweir }
2298cdf0e10cSrcweir 
2299cdf0e10cSrcweir uno::Reference < XAccessible >
2300cdf0e10cSrcweir 	ScAccessibleDocument::GetAccessibleSpreadsheet()
2301cdf0e10cSrcweir {
2302cdf0e10cSrcweir 	if (!mpAccessibleSpreadsheet && mpViewShell)
2303cdf0e10cSrcweir 	{
2304cdf0e10cSrcweir 		mpAccessibleSpreadsheet = new ScAccessibleSpreadsheet(this, mpViewShell, getVisibleTable(), meSplitPos);
2305cdf0e10cSrcweir 		mpAccessibleSpreadsheet->acquire();
2306cdf0e10cSrcweir 		mpAccessibleSpreadsheet->Init();
2307cdf0e10cSrcweir 		mbCompleteSheetSelected = IsTableSelected();
2308cdf0e10cSrcweir 	}
2309cdf0e10cSrcweir 	return mpAccessibleSpreadsheet;
2310cdf0e10cSrcweir }
2311cdf0e10cSrcweir 
2312cdf0e10cSrcweir void ScAccessibleDocument::FreeAccessibleSpreadsheet()
2313cdf0e10cSrcweir {
2314cdf0e10cSrcweir 	if (mpAccessibleSpreadsheet)
2315cdf0e10cSrcweir 	{
2316cdf0e10cSrcweir 		mpAccessibleSpreadsheet->dispose();
2317cdf0e10cSrcweir 		mpAccessibleSpreadsheet->release();
2318cdf0e10cSrcweir 		mpAccessibleSpreadsheet = NULL;
2319cdf0e10cSrcweir 	}
2320cdf0e10cSrcweir }
2321cdf0e10cSrcweir 
2322cdf0e10cSrcweir sal_Bool ScAccessibleDocument::IsTableSelected() const
2323cdf0e10cSrcweir {
2324cdf0e10cSrcweir 	sal_Bool bResult (sal_False);
2325cdf0e10cSrcweir 	if(mpViewShell)
2326cdf0e10cSrcweir 	{
2327cdf0e10cSrcweir 		SCTAB nTab(getVisibleTable());
2328cdf0e10cSrcweir         //#103800#; use a copy of MarkData
2329cdf0e10cSrcweir         ScMarkData aMarkData(mpViewShell->GetViewData()->GetMarkData());
2330cdf0e10cSrcweir 		aMarkData.MarkToMulti();
2331cdf0e10cSrcweir 		if (aMarkData.IsAllMarked(ScRange(ScAddress(0, 0, nTab),ScAddress(MAXCOL, MAXROW, nTab))))
2332cdf0e10cSrcweir 			bResult = sal_True;
2333cdf0e10cSrcweir 	}
2334cdf0e10cSrcweir 	return bResult;
2335cdf0e10cSrcweir }
2336cdf0e10cSrcweir 
2337cdf0e10cSrcweir sal_Bool ScAccessibleDocument::IsDefunc(
2338cdf0e10cSrcweir 	const uno::Reference<XAccessibleStateSet>& rxParentStates)
2339cdf0e10cSrcweir {
2340cdf0e10cSrcweir 	return ScAccessibleContextBase::IsDefunc() || (mpViewShell == NULL) || !getAccessibleParent().is() ||
2341cdf0e10cSrcweir 		(rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
2342cdf0e10cSrcweir }
2343cdf0e10cSrcweir 
2344cdf0e10cSrcweir sal_Bool ScAccessibleDocument::IsEditable(
2345cdf0e10cSrcweir     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
2346cdf0e10cSrcweir {
2347cdf0e10cSrcweir 	// what is with document protection or readonly documents?
2348cdf0e10cSrcweir 	return sal_True;
2349cdf0e10cSrcweir }
2350cdf0e10cSrcweir 
2351cdf0e10cSrcweir void ScAccessibleDocument::AddChild(const uno::Reference<XAccessible>& xAcc, sal_Bool bFireEvent)
2352cdf0e10cSrcweir {
2353cdf0e10cSrcweir     DBG_ASSERT(!mxTempAcc.is(), "this object should be removed before");
2354cdf0e10cSrcweir     if (xAcc.is())
2355cdf0e10cSrcweir     {
2356cdf0e10cSrcweir         mxTempAcc = xAcc;
2357cdf0e10cSrcweir 		if( bFireEvent )
2358cdf0e10cSrcweir 		{
2359cdf0e10cSrcweir 			AccessibleEventObject aEvent;
2360cdf0e10cSrcweir                         aEvent.Source = uno::Reference<XAccessibleContext>(this);
2361cdf0e10cSrcweir 			aEvent.EventId = AccessibleEventId::CHILD;
2362cdf0e10cSrcweir 			aEvent.NewValue <<= mxTempAcc;
2363cdf0e10cSrcweir 			CommitChange( aEvent );
2364cdf0e10cSrcweir 		}
2365cdf0e10cSrcweir     }
2366cdf0e10cSrcweir }
2367cdf0e10cSrcweir 
2368cdf0e10cSrcweir void ScAccessibleDocument::RemoveChild(const uno::Reference<XAccessible>& xAcc, sal_Bool bFireEvent)
2369cdf0e10cSrcweir {
2370cdf0e10cSrcweir     DBG_ASSERT(mxTempAcc.is(), "this object should be added before");
2371cdf0e10cSrcweir     if (xAcc.is())
2372cdf0e10cSrcweir     {
2373cdf0e10cSrcweir         DBG_ASSERT(xAcc.get() == mxTempAcc.get(), "only the same object should be removed");
2374cdf0e10cSrcweir 		if( bFireEvent )
2375cdf0e10cSrcweir 		{
2376cdf0e10cSrcweir 			AccessibleEventObject aEvent;
2377cdf0e10cSrcweir                         aEvent.Source = uno::Reference<XAccessibleContext>(this);
2378cdf0e10cSrcweir 			aEvent.EventId = AccessibleEventId::CHILD;
2379cdf0e10cSrcweir 			aEvent.OldValue <<= mxTempAcc;
2380cdf0e10cSrcweir 			CommitChange( aEvent );
2381cdf0e10cSrcweir 		}
2382cdf0e10cSrcweir         mxTempAcc = NULL;
2383cdf0e10cSrcweir     }
2384cdf0e10cSrcweir }
2385cdf0e10cSrcweir 
2386cdf0e10cSrcweir rtl::OUString ScAccessibleDocument::GetCurrentCellName() const
2387cdf0e10cSrcweir {
2388cdf0e10cSrcweir 	String sName( ScResId(STR_ACC_CELL_NAME) );
2389cdf0e10cSrcweir     if (mpViewShell)
2390cdf0e10cSrcweir     {
2391cdf0e10cSrcweir 	    String sAddress;
2392cdf0e10cSrcweir 	    // Document not needed, because only the cell address, but not the tablename is needed
2393cdf0e10cSrcweir 	    mpViewShell->GetViewData()->GetCurPos().Format( sAddress, SCA_VALID, NULL );
2394cdf0e10cSrcweir 	    sName.SearchAndReplaceAscii("%1", sAddress);
2395cdf0e10cSrcweir     }
2396cdf0e10cSrcweir     return rtl::OUString(sName);
2397cdf0e10cSrcweir }
2398cdf0e10cSrcweir 
2399cdf0e10cSrcweir rtl::OUString ScAccessibleDocument::GetCurrentCellDescription() const
2400cdf0e10cSrcweir {
2401cdf0e10cSrcweir     return rtl::OUString();
2402cdf0e10cSrcweir }
24030deba7fbSSteve Yin //IAccessibility2 Implementation 2009-----
24040deba7fbSSteve Yin ScDocument *ScAccessibleDocument::GetDocument() const
24050deba7fbSSteve Yin {
24060deba7fbSSteve Yin 	return mpViewShell ? mpViewShell->GetViewData()->GetDocument() : NULL;
24070deba7fbSSteve Yin }
24080deba7fbSSteve Yin ScAddress   ScAccessibleDocument::GetCurCellAddress() const
24090deba7fbSSteve Yin {
24100deba7fbSSteve Yin 	return mpViewShell ? mpViewShell->GetViewData()->GetCurPos() :ScAddress();
24110deba7fbSSteve Yin }
24120deba7fbSSteve Yin uno::Any SAL_CALL ScAccessibleDocument::getExtendedAttributes()
24130deba7fbSSteve Yin 		throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
24140deba7fbSSteve Yin {
24150deba7fbSSteve Yin 
24160deba7fbSSteve Yin 	uno::Any anyAtrribute;
24170deba7fbSSteve Yin 
24180deba7fbSSteve Yin 	rtl::OUString sName;
24190deba7fbSSteve Yin 	rtl::OUString sValue;
24200deba7fbSSteve Yin 	sal_uInt16 sheetIndex;
24210deba7fbSSteve Yin 	String sSheetName;
24220deba7fbSSteve Yin 	sheetIndex = getVisibleTable();
24230deba7fbSSteve Yin 	if(GetDocument()==NULL)
24240deba7fbSSteve Yin 		return anyAtrribute;
24250deba7fbSSteve Yin 	GetDocument()->GetName(sheetIndex,sSheetName);
24260deba7fbSSteve Yin 	sName = rtl::OUString::createFromAscii("page-name:");
24270deba7fbSSteve Yin 	sValue = sName + sSheetName ;
24280deba7fbSSteve Yin 	sName = rtl::OUString::createFromAscii(";page-number:");
24290deba7fbSSteve Yin 	sValue += sName;
24300deba7fbSSteve Yin 	sValue += String::CreateFromInt32(sheetIndex+1) ;
24310deba7fbSSteve Yin 	sName = rtl::OUString::createFromAscii(";total-pages:");
24320deba7fbSSteve Yin 	sValue += sName;
24330deba7fbSSteve Yin 	sValue += String::CreateFromInt32(GetDocument()->GetTableCount());
24340deba7fbSSteve Yin 	sValue +=  rtl::OUString::createFromAscii(";");
24350deba7fbSSteve Yin 	anyAtrribute <<= sValue;
24360deba7fbSSteve Yin 	return anyAtrribute;
24370deba7fbSSteve Yin }
24380deba7fbSSteve Yin com::sun::star::uno::Sequence< com::sun::star::uno::Any > ScAccessibleDocument::GetScAccFlowToSequence()
24390deba7fbSSteve Yin {
24400deba7fbSSteve Yin 	if ( getAccessibleChildCount() )
24410deba7fbSSteve Yin 	{
24420deba7fbSSteve Yin 		uno::Reference < XAccessible > xSCTableAcc = getAccessibleChild( 0 ); // table
24430deba7fbSSteve Yin 		if ( xSCTableAcc.is() )
24440deba7fbSSteve Yin 		{
24450deba7fbSSteve Yin 			uno::Reference < XAccessibleSelection > xAccSelection( xSCTableAcc, uno::UNO_QUERY );
24460deba7fbSSteve Yin 			sal_Int32 nSelCount = xAccSelection->getSelectedAccessibleChildCount();
24470deba7fbSSteve Yin 			if( nSelCount )
24480deba7fbSSteve Yin 			{
24490deba7fbSSteve Yin 				uno::Reference < XAccessible > xSel = xAccSelection->getSelectedAccessibleChild( 0 ); // selected cell
24500deba7fbSSteve Yin 				if ( xSel.is() )
24510deba7fbSSteve Yin 				{
24520deba7fbSSteve Yin 					uno::Reference < XAccessibleContext > xSelContext( xSel->getAccessibleContext() );
24530deba7fbSSteve Yin 					if ( xSelContext.is() )
24540deba7fbSSteve Yin 					{
24550deba7fbSSteve Yin 						if ( xSelContext->getAccessibleRole() == AccessibleRole::TABLE_CELL )
24560deba7fbSSteve Yin 						{
24570deba7fbSSteve Yin 							sal_Int32 nParaCount = 0;
24580deba7fbSSteve Yin 							uno::Sequence <uno::Any> aSequence(nSelCount);
24590deba7fbSSteve Yin 							for ( sal_Int32 i = 0; i < nSelCount; i++ )
24600deba7fbSSteve Yin 							{
24610deba7fbSSteve Yin 								xSel = xAccSelection->getSelectedAccessibleChild( i )	;
24620deba7fbSSteve Yin 								if ( xSel.is() )
24630deba7fbSSteve Yin 								{
24640deba7fbSSteve Yin 									xSelContext = xSel->getAccessibleContext();
24650deba7fbSSteve Yin 									if ( xSelContext.is() )
24660deba7fbSSteve Yin 									{
24670deba7fbSSteve Yin 										if ( xSelContext->getAccessibleRole() == AccessibleRole::TABLE_CELL )
24680deba7fbSSteve Yin 										{
24690deba7fbSSteve Yin 											aSequence[nParaCount] = uno::makeAny( xSel );
24700deba7fbSSteve Yin 											nParaCount++;
24710deba7fbSSteve Yin 										}
24720deba7fbSSteve Yin 									}
24730deba7fbSSteve Yin 								}
24740deba7fbSSteve Yin 							}
24750deba7fbSSteve Yin 							return aSequence;
24760deba7fbSSteve Yin 						}
24770deba7fbSSteve Yin 					}
24780deba7fbSSteve Yin 				}
24790deba7fbSSteve Yin 			}
24800deba7fbSSteve Yin 		}
24810deba7fbSSteve Yin 	}
24820deba7fbSSteve Yin 	uno::Sequence <uno::Any> aEmpty;
24830deba7fbSSteve Yin 	return aEmpty;
24840deba7fbSSteve Yin }
24850deba7fbSSteve Yin ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
24860deba7fbSSteve Yin 		SAL_CALL ScAccessibleDocument::get_AccFlowTo(const ::com::sun::star::uno::Any& rAny, sal_Int32 nType)
24870deba7fbSSteve Yin 		throw ( ::com::sun::star::uno::RuntimeException )
24880deba7fbSSteve Yin {
24890deba7fbSSteve Yin 	const sal_Int32 SPELLCHECKFLOWTO = 1;
24900deba7fbSSteve Yin 	const sal_Int32 FINDREPLACEFLOWTO = 2;
24910deba7fbSSteve Yin 	if ( nType == SPELLCHECKFLOWTO )
24920deba7fbSSteve Yin 	{
24930deba7fbSSteve Yin 		uno::Reference< ::com::sun::star::drawing::XShape > xShape;
24940deba7fbSSteve Yin 		rAny >>= xShape;
24950deba7fbSSteve Yin 		if ( xShape.is() )
24960deba7fbSSteve Yin 		{
24970deba7fbSSteve Yin 			uno::Reference < XAccessible > xAcc = mpChildrenShapes->GetAccessibleCaption(xShape);
24980deba7fbSSteve Yin 			uno::Reference < XAccessibleSelection > xAccSelection( xAcc, uno::UNO_QUERY );
24990deba7fbSSteve Yin 			if ( xAccSelection.is() )
25000deba7fbSSteve Yin 			{
25010deba7fbSSteve Yin 				if ( xAccSelection->getSelectedAccessibleChildCount() )
25020deba7fbSSteve Yin 				{
25030deba7fbSSteve Yin 					uno::Reference < XAccessible > xSel = xAccSelection->getSelectedAccessibleChild( 0 );
25040deba7fbSSteve Yin 					if ( xSel.is() )
25050deba7fbSSteve Yin 					{
25060deba7fbSSteve Yin 						uno::Reference < XAccessibleContext > xSelContext( xSel->getAccessibleContext() );
25070deba7fbSSteve Yin 						if ( xSelContext.is() )
25080deba7fbSSteve Yin 						{
25090deba7fbSSteve Yin 							//if in sw we find the selected paragraph here
25100deba7fbSSteve Yin 							if ( xSelContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
25110deba7fbSSteve Yin 							{
25120deba7fbSSteve Yin 								uno::Sequence<uno::Any> aRet( 1 );
25130deba7fbSSteve Yin 								aRet[0] = uno::makeAny( xSel );
25140deba7fbSSteve Yin 								return aRet;
25150deba7fbSSteve Yin 							}
25160deba7fbSSteve Yin 						}
25170deba7fbSSteve Yin 					}
25180deba7fbSSteve Yin 				}
25190deba7fbSSteve Yin 			}
25200deba7fbSSteve Yin 		}
25210deba7fbSSteve Yin 		else
25220deba7fbSSteve Yin 		{
25230deba7fbSSteve Yin 			if ( getSelectedAccessibleChildCount() )
25240deba7fbSSteve Yin 			{
25250deba7fbSSteve Yin 				uno::Reference < XAccessible > xSel = getSelectedAccessibleChild( 0 );
25260deba7fbSSteve Yin 				if ( xSel.is() )
25270deba7fbSSteve Yin 				{
25280deba7fbSSteve Yin 					uno::Reference < XAccessibleContext > xSelContext( xSel->getAccessibleContext() );
25290deba7fbSSteve Yin 					if ( xSelContext.is() )
25300deba7fbSSteve Yin 					{
25310deba7fbSSteve Yin 						uno::Reference < XAccessibleSelection > xAccChildSelection( xSel, uno::UNO_QUERY );
25320deba7fbSSteve Yin 						if ( xAccChildSelection.is() )
25330deba7fbSSteve Yin 						{
25340deba7fbSSteve Yin 							if ( xAccChildSelection->getSelectedAccessibleChildCount() )
25350deba7fbSSteve Yin 							{
25360deba7fbSSteve Yin 								uno::Reference < XAccessible > xChildSel = xAccChildSelection->getSelectedAccessibleChild( 0 );
25370deba7fbSSteve Yin 								if ( xChildSel.is() )
25380deba7fbSSteve Yin 								{
25390deba7fbSSteve Yin 									uno::Reference < ::com::sun::star::accessibility::XAccessibleContext > xChildSelContext( xChildSel->getAccessibleContext() );
25400deba7fbSSteve Yin 									if ( xChildSelContext.is() &&
25410deba7fbSSteve Yin 										xChildSelContext->getAccessibleRole() == ::com::sun::star::accessibility::AccessibleRole::PARAGRAPH )
25420deba7fbSSteve Yin 									{
25430deba7fbSSteve Yin 										uno::Sequence<uno::Any> aRet( 1 );
25440deba7fbSSteve Yin 										aRet[0] = uno::makeAny( xChildSel );
25450deba7fbSSteve Yin 										return aRet;
25460deba7fbSSteve Yin 									}
25470deba7fbSSteve Yin 								}
25480deba7fbSSteve Yin 							}
25490deba7fbSSteve Yin 						}
25500deba7fbSSteve Yin 					}
25510deba7fbSSteve Yin 				}
25520deba7fbSSteve Yin 			}
25530deba7fbSSteve Yin 		}
25540deba7fbSSteve Yin 	}
25550deba7fbSSteve Yin 	else if ( nType == FINDREPLACEFLOWTO )
25560deba7fbSSteve Yin 	{
2557*4483d2e8SPavel Janík 		sal_Bool bSuccess(sal_False);
25580deba7fbSSteve Yin 		rAny >>= bSuccess;
25590deba7fbSSteve Yin 		if ( bSuccess )
25600deba7fbSSteve Yin 		{
25610deba7fbSSteve Yin 			uno::Sequence< uno::Any> aSeq = GetScAccFlowToSequence();
25620deba7fbSSteve Yin 			if ( aSeq.getLength() )
25630deba7fbSSteve Yin 			{
25640deba7fbSSteve Yin 				return aSeq;
25650deba7fbSSteve Yin 			}
25660deba7fbSSteve Yin 			else if( mpAccessibleSpreadsheet )
25670deba7fbSSteve Yin 			{
25680deba7fbSSteve Yin 				uno::Reference < XAccessible > xFindCellAcc = mpAccessibleSpreadsheet->GetActiveCell();
25690deba7fbSSteve Yin 				// add xFindCellAcc to the return the Sequence
25700deba7fbSSteve Yin 				uno::Sequence< uno::Any> aSeq2(1);
25710deba7fbSSteve Yin 				aSeq2[0] = uno::makeAny( xFindCellAcc );
25720deba7fbSSteve Yin 				return aSeq2;
25730deba7fbSSteve Yin 			}
25740deba7fbSSteve Yin 		}
25750deba7fbSSteve Yin 	}
25760deba7fbSSteve Yin 	uno::Sequence< uno::Any> aEmpty;
25770deba7fbSSteve Yin 	return aEmpty;
25780deba7fbSSteve Yin }
25790deba7fbSSteve Yin void ScAccessibleDocument::SwitchViewFireFocus()
25800deba7fbSSteve Yin {
25810deba7fbSSteve Yin 	if (mpAccessibleSpreadsheet)
25820deba7fbSSteve Yin 	{
25830deba7fbSSteve Yin 		mpAccessibleSpreadsheet->FireFirstCellFocus();
25840deba7fbSSteve Yin 	}
25850deba7fbSSteve Yin }
25860deba7fbSSteve Yin 
25870deba7fbSSteve Yin sal_Int32 SAL_CALL ScAccessibleDocument::getForeground(  )
25880deba7fbSSteve Yin         throw (uno::RuntimeException)
25890deba7fbSSteve Yin {
25900deba7fbSSteve Yin     return COL_BLACK;
25910deba7fbSSteve Yin }
25920deba7fbSSteve Yin 
25930deba7fbSSteve Yin sal_Int32 SAL_CALL ScAccessibleDocument::getBackground(  )
25940deba7fbSSteve Yin         throw (uno::RuntimeException)
25950deba7fbSSteve Yin {
25960deba7fbSSteve Yin 	ScUnoGuard aGuard;
25970deba7fbSSteve Yin     IsObjectValid();
25980deba7fbSSteve Yin     return SC_MOD()->GetColorConfig().GetColorValue( ::svtools::DOCCOLOR ).nColor;
25990deba7fbSSteve Yin }
26000deba7fbSSteve Yin //-----IAccessibility2 Implementation 2009
26010deba7fbSSteve Yin 
2602