xref: /AOO41X/main/sc/source/ui/Accessibility/AccessibleDocumentPagePreview.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "AccessibleDocumentPagePreview.hxx"
32*cdf0e10cSrcweir #include "AccessiblePreviewTable.hxx"
33*cdf0e10cSrcweir #include "AccessiblePageHeader.hxx"
34*cdf0e10cSrcweir #include "AccessibilityHints.hxx"
35*cdf0e10cSrcweir #include "AccessibleText.hxx"
36*cdf0e10cSrcweir #include "document.hxx"
37*cdf0e10cSrcweir #include "prevwsh.hxx"
38*cdf0e10cSrcweir #include "prevloc.hxx"
39*cdf0e10cSrcweir #include "unoguard.hxx"
40*cdf0e10cSrcweir #include "drwlayer.hxx"
41*cdf0e10cSrcweir #include "editsrc.hxx"
42*cdf0e10cSrcweir #include "scresid.hxx"
43*cdf0e10cSrcweir #include "sc.hrc"
44*cdf0e10cSrcweir #include "DrawModelBroadcaster.hxx"
45*cdf0e10cSrcweir #include "docsh.hxx"
46*cdf0e10cSrcweir #include "drawview.hxx"
47*cdf0e10cSrcweir #include "preview.hxx"
48*cdf0e10cSrcweir #include "postit.hxx"
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
55*cdf0e10cSrcweir #include <tools/debug.hxx>
56*cdf0e10cSrcweir #include <tools/gen.hxx>
57*cdf0e10cSrcweir #include <svx/svdpage.hxx>
58*cdf0e10cSrcweir #include <svx/svdobj.hxx>
59*cdf0e10cSrcweir #include <svx/AccessibleTextHelper.hxx>
60*cdf0e10cSrcweir #include <svx/AccessibleShape.hxx>
61*cdf0e10cSrcweir #include <svx/ShapeTypeHandler.hxx>
62*cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
63*cdf0e10cSrcweir #include <svx/unoshape.hxx>
64*cdf0e10cSrcweir #include <unotools/accessiblerelationsethelper.hxx>
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir #include <vector>
67*cdf0e10cSrcweir #include <list>
68*cdf0e10cSrcweir #include <algorithm>
69*cdf0e10cSrcweir #include <memory>
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir using namespace	::com::sun::star;
72*cdf0e10cSrcweir using namespace	::com::sun::star::accessibility;
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir //=========================================================================
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir typedef std::list< uno::Reference< XAccessible > > ScXAccList;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir struct ScAccNote
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir     String      maNoteText;
82*cdf0e10cSrcweir     Rectangle   maRect;
83*cdf0e10cSrcweir     ScAddress   maNoteCell;
84*cdf0e10cSrcweir     ::accessibility::AccessibleTextHelper* mpTextHelper;
85*cdf0e10cSrcweir     sal_Int32   mnParaCount;
86*cdf0e10cSrcweir     sal_Bool    mbMarkNote;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir                 ScAccNote() : mpTextHelper(NULL), mnParaCount(0) {}
89*cdf0e10cSrcweir };
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir class ScNotesChilds
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir public:
94*cdf0e10cSrcweir     ScNotesChilds(ScPreviewShell* pViewShell, ScAccessibleDocumentPagePreview* pAccDoc);
95*cdf0e10cSrcweir     ~ScNotesChilds();
96*cdf0e10cSrcweir     void Init(const Rectangle& rVisRect, sal_Int32 nOffset);
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir     sal_Int32 GetChildsCount() const;
99*cdf0e10cSrcweir     uno::Reference<XAccessible> GetChild(sal_Int32 nIndex) const;
100*cdf0e10cSrcweir     uno::Reference<XAccessible> GetAt(const awt::Point& rPoint) const;
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     void DataChanged(const Rectangle& rVisRect);
103*cdf0e10cSrcweir     void SetOffset(sal_Int32 nNewOffset);
104*cdf0e10cSrcweir private:
105*cdf0e10cSrcweir     ScPreviewShell*         mpViewShell;
106*cdf0e10cSrcweir     ScAccessibleDocumentPagePreview* mpAccDoc;
107*cdf0e10cSrcweir     typedef std::vector<ScAccNote> ScAccNotes;
108*cdf0e10cSrcweir     mutable ScAccNotes      maNotes;
109*cdf0e10cSrcweir     mutable ScAccNotes      maMarks;
110*cdf0e10cSrcweir     sal_Int32               mnParagraphs;
111*cdf0e10cSrcweir     sal_Int32               mnOffset;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     ::accessibility::AccessibleTextHelper* CreateTextHelper(const String& rString, const Rectangle& rVisRect, const ScAddress& aCellPos, sal_Bool bMarkNote, sal_Int32 nChildOffset) const;
114*cdf0e10cSrcweir     sal_Int32 AddNotes(const ScPreviewLocationData& rData, const Rectangle& rVisRect, sal_Bool bMark, ScAccNotes& rNotes);
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     sal_Int8 CompareCell(const ScAddress& aCell1, const ScAddress& aCell2);
117*cdf0e10cSrcweir     void CollectChilds(const ScAccNote& rNote, ScXAccList& rList);
118*cdf0e10cSrcweir     sal_Int32 CheckChanges(const ScPreviewLocationData& rData, const Rectangle& rVisRect,
119*cdf0e10cSrcweir         sal_Bool bMark, ScAccNotes& rOldNotes, ScAccNotes& rNewNotes,
120*cdf0e10cSrcweir         ScXAccList& rOldParas, ScXAccList& rNewParas);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     inline ScDocument* GetDocument() const;
123*cdf0e10cSrcweir };
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir ScNotesChilds::ScNotesChilds(ScPreviewShell* pViewShell, ScAccessibleDocumentPagePreview* pAccDoc)
126*cdf0e10cSrcweir     : mpViewShell(pViewShell),
127*cdf0e10cSrcweir     mpAccDoc(pAccDoc),
128*cdf0e10cSrcweir     mnParagraphs(0),
129*cdf0e10cSrcweir     mnOffset(0)
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir struct DeleteAccNote
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir     void operator()(ScAccNote& rNote)
136*cdf0e10cSrcweir     {
137*cdf0e10cSrcweir         if (rNote.mpTextHelper)
138*cdf0e10cSrcweir             DELETEZ( rNote.mpTextHelper);
139*cdf0e10cSrcweir     }
140*cdf0e10cSrcweir };
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir ScNotesChilds::~ScNotesChilds()
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir     std::for_each(maNotes.begin(), maNotes.end(), DeleteAccNote());
145*cdf0e10cSrcweir     std::for_each(maMarks.begin(), maMarks.end(), DeleteAccNote());
146*cdf0e10cSrcweir }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir ::accessibility::AccessibleTextHelper* ScNotesChilds::CreateTextHelper(const String& rString, const Rectangle& rVisRect, const ScAddress& aCellPos, sal_Bool bMarkNote, sal_Int32 nChildOffset) const
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir     ::accessibility::AccessibleTextHelper* pTextHelper = NULL;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewHeaderCellTextData
153*cdf0e10cSrcweir 		(new ScAccessibleNoteTextData(mpViewShell, rString, aCellPos, bMarkNote));
154*cdf0e10cSrcweir 	::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewHeaderCellTextData));
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	pTextHelper = new ::accessibility::AccessibleTextHelper(pEditSource);
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     if (pTextHelper)
159*cdf0e10cSrcweir     {
160*cdf0e10cSrcweir         pTextHelper->SetEventSource(mpAccDoc);
161*cdf0e10cSrcweir         pTextHelper->SetStartIndex(nChildOffset);
162*cdf0e10cSrcweir         pTextHelper->SetOffset(rVisRect.TopLeft());
163*cdf0e10cSrcweir     }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     return pTextHelper;
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir sal_Int32 ScNotesChilds::AddNotes(const ScPreviewLocationData& rData, const Rectangle& rVisRect, sal_Bool bMark, ScAccNotes& rNotes)
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir     sal_Int32 nCount = rData.GetNoteCountInRange(rVisRect, bMark);
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     rNotes.reserve(nCount);
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir     sal_Int32 nParagraphs(0);
175*cdf0e10cSrcweir     ScDocument* pDoc = GetDocument();
176*cdf0e10cSrcweir     if (pDoc)
177*cdf0e10cSrcweir     {
178*cdf0e10cSrcweir         ScAccNote aNote;
179*cdf0e10cSrcweir         aNote.mbMarkNote = bMark;
180*cdf0e10cSrcweir         if (bMark)
181*cdf0e10cSrcweir             aNote.mnParaCount = 1;
182*cdf0e10cSrcweir         for (sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex)
183*cdf0e10cSrcweir         {
184*cdf0e10cSrcweir             if (rData.GetNoteInRange(rVisRect, nIndex, bMark, aNote.maNoteCell, aNote.maRect))
185*cdf0e10cSrcweir             {
186*cdf0e10cSrcweir                 if (bMark)
187*cdf0e10cSrcweir                 {
188*cdf0e10cSrcweir 	                // Document not needed, because only the cell address, but not the tablename is needed
189*cdf0e10cSrcweir 	                aNote.maNoteCell.Format( aNote.maNoteText, SCA_VALID, NULL );
190*cdf0e10cSrcweir                 }
191*cdf0e10cSrcweir                 else
192*cdf0e10cSrcweir                 {
193*cdf0e10cSrcweir                     if( ScPostIt* pNote = pDoc->GetNote( aNote.maNoteCell ) )
194*cdf0e10cSrcweir                         aNote.maNoteText = pNote->GetText();
195*cdf0e10cSrcweir                     aNote.mpTextHelper = CreateTextHelper(aNote.maNoteText, aNote.maRect, aNote.maNoteCell, aNote.mbMarkNote, nParagraphs + mnOffset);
196*cdf0e10cSrcweir                     if (aNote.mpTextHelper)
197*cdf0e10cSrcweir                         aNote.mnParaCount = aNote.mpTextHelper->GetChildCount();
198*cdf0e10cSrcweir                 }
199*cdf0e10cSrcweir                 nParagraphs += aNote.mnParaCount;
200*cdf0e10cSrcweir                 rNotes.push_back(aNote);
201*cdf0e10cSrcweir             }
202*cdf0e10cSrcweir         }
203*cdf0e10cSrcweir     }
204*cdf0e10cSrcweir     return nParagraphs;
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir void ScNotesChilds::Init(const Rectangle& rVisRect, sal_Int32 nOffset)
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir     if (mpViewShell && !mnParagraphs)
210*cdf0e10cSrcweir     {
211*cdf0e10cSrcweir         mnOffset = nOffset;
212*cdf0e10cSrcweir         const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir         mnParagraphs = AddNotes(rData, rVisRect, sal_False, maMarks);
215*cdf0e10cSrcweir         mnParagraphs += AddNotes(rData, rVisRect, sal_True, maNotes);
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir sal_Int32 ScNotesChilds::GetChildsCount() const
220*cdf0e10cSrcweir {
221*cdf0e10cSrcweir     return mnParagraphs;
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir struct ScParaFound
225*cdf0e10cSrcweir {
226*cdf0e10cSrcweir     sal_Int32 mnIndex;
227*cdf0e10cSrcweir     ScParaFound(sal_Int32 nIndex) : mnIndex(nIndex) {}
228*cdf0e10cSrcweir     sal_Bool operator() (const ScAccNote& rNote)
229*cdf0e10cSrcweir     {
230*cdf0e10cSrcweir         sal_Bool bResult(sal_False);
231*cdf0e10cSrcweir         if (rNote.mnParaCount > mnIndex)
232*cdf0e10cSrcweir             bResult = sal_True;
233*cdf0e10cSrcweir         else
234*cdf0e10cSrcweir             mnIndex -= rNote.mnParaCount;
235*cdf0e10cSrcweir         return bResult;
236*cdf0e10cSrcweir     }
237*cdf0e10cSrcweir };
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir uno::Reference<XAccessible> ScNotesChilds::GetChild(sal_Int32 nIndex) const
240*cdf0e10cSrcweir {
241*cdf0e10cSrcweir     uno::Reference<XAccessible> xAccessible;
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     if (nIndex < mnParagraphs)
244*cdf0e10cSrcweir     {
245*cdf0e10cSrcweir         if (nIndex < static_cast<sal_Int32>(maMarks.size()))
246*cdf0e10cSrcweir         {
247*cdf0e10cSrcweir             ScAccNotes::iterator aEndItr = maMarks.end();
248*cdf0e10cSrcweir             ScParaFound aParaFound(nIndex);
249*cdf0e10cSrcweir             ScAccNotes::iterator aItr = std::find_if(maMarks.begin(), aEndItr, aParaFound);
250*cdf0e10cSrcweir             if (aItr != aEndItr)
251*cdf0e10cSrcweir             {
252*cdf0e10cSrcweir                 DBG_ASSERT((aItr->maNoteCell == maMarks[nIndex].maNoteCell) && (aItr->mbMarkNote == maMarks[nIndex].mbMarkNote), "wrong note found");
253*cdf0e10cSrcweir             }
254*cdf0e10cSrcweir             else
255*cdf0e10cSrcweir             {
256*cdf0e10cSrcweir                 DBG_ERRORFILE("wrong note found");
257*cdf0e10cSrcweir             }
258*cdf0e10cSrcweir             if (!aItr->mpTextHelper)
259*cdf0e10cSrcweir                 aItr->mpTextHelper = CreateTextHelper(maMarks[nIndex].maNoteText, maMarks[nIndex].maRect, maMarks[nIndex].maNoteCell, maMarks[nIndex].mbMarkNote, nIndex + mnOffset); // the marks are the first and every mark has only one paragraph
260*cdf0e10cSrcweir             xAccessible = aItr->mpTextHelper->GetChild(aParaFound.mnIndex + aItr->mpTextHelper->GetStartIndex());
261*cdf0e10cSrcweir         }
262*cdf0e10cSrcweir         else
263*cdf0e10cSrcweir         {
264*cdf0e10cSrcweir             nIndex -= maMarks.size();
265*cdf0e10cSrcweir             ScAccNotes::iterator aEndItr = maNotes.end();
266*cdf0e10cSrcweir             ScParaFound aParaFound(nIndex);
267*cdf0e10cSrcweir             ScAccNotes::iterator aItr = std::find_if(maNotes.begin(), aEndItr, aParaFound);
268*cdf0e10cSrcweir             if (aEndItr != aItr)
269*cdf0e10cSrcweir             {
270*cdf0e10cSrcweir                 if (!aItr->mpTextHelper)
271*cdf0e10cSrcweir                     aItr->mpTextHelper = CreateTextHelper(aItr->maNoteText, aItr->maRect, aItr->maNoteCell, aItr->mbMarkNote, (nIndex - aParaFound.mnIndex) + mnOffset + maMarks.size());
272*cdf0e10cSrcweir                 xAccessible = aItr->mpTextHelper->GetChild(aParaFound.mnIndex + aItr->mpTextHelper->GetStartIndex());
273*cdf0e10cSrcweir             }
274*cdf0e10cSrcweir         }
275*cdf0e10cSrcweir     }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir     return xAccessible;
278*cdf0e10cSrcweir }
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir struct ScPointFound
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir     Rectangle maPoint;
283*cdf0e10cSrcweir     sal_Int32 mnParagraphs;
284*cdf0e10cSrcweir     ScPointFound(const Point& rPoint) : maPoint(rPoint, Size(0, 0)), mnParagraphs(0) {}
285*cdf0e10cSrcweir     sal_Bool operator() (const ScAccNote& rNote)
286*cdf0e10cSrcweir     {
287*cdf0e10cSrcweir         sal_Bool bResult(sal_False);
288*cdf0e10cSrcweir         if (maPoint.IsInside(rNote.maRect))
289*cdf0e10cSrcweir             bResult = sal_True;
290*cdf0e10cSrcweir         else
291*cdf0e10cSrcweir             mnParagraphs += rNote.mnParaCount;
292*cdf0e10cSrcweir         return bResult;
293*cdf0e10cSrcweir     }
294*cdf0e10cSrcweir };
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir uno::Reference<XAccessible> ScNotesChilds::GetAt(const awt::Point& rPoint) const
297*cdf0e10cSrcweir {
298*cdf0e10cSrcweir     uno::Reference<XAccessible> xAccessible;
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     ScPointFound aPointFound(Point(rPoint.X, rPoint.Y));
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir     ScAccNotes::iterator aEndItr = maMarks.end();
303*cdf0e10cSrcweir     ScAccNotes::iterator aItr = std::find_if(maMarks.begin(), aEndItr, aPointFound);
304*cdf0e10cSrcweir     if (aEndItr == aItr)
305*cdf0e10cSrcweir     {
306*cdf0e10cSrcweir         aEndItr = maNotes.end();
307*cdf0e10cSrcweir         aItr = std::find_if(maNotes.begin(), aEndItr, aPointFound);
308*cdf0e10cSrcweir     }
309*cdf0e10cSrcweir     if (aEndItr != aItr)
310*cdf0e10cSrcweir     {
311*cdf0e10cSrcweir         if (!aItr->mpTextHelper)
312*cdf0e10cSrcweir             aItr->mpTextHelper = CreateTextHelper(aItr->maNoteText, aItr->maRect, aItr->maNoteCell, aItr->mbMarkNote, aPointFound.mnParagraphs + mnOffset);
313*cdf0e10cSrcweir         xAccessible = aItr->mpTextHelper->GetAt(rPoint);
314*cdf0e10cSrcweir     }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir     return xAccessible;
317*cdf0e10cSrcweir }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir sal_Int8 ScNotesChilds::CompareCell(const ScAddress& aCell1, const ScAddress& aCell2)
320*cdf0e10cSrcweir {
321*cdf0e10cSrcweir     DBG_ASSERT(aCell1.Tab() == aCell2.Tab(), "the notes should be on the same table");
322*cdf0e10cSrcweir     sal_Int8 nResult(0);
323*cdf0e10cSrcweir     if (aCell1 != aCell2)
324*cdf0e10cSrcweir     {
325*cdf0e10cSrcweir         if (aCell1.Row() == aCell2.Row())
326*cdf0e10cSrcweir             nResult = (aCell1.Col() < aCell2.Col()) ? -1 : 1;
327*cdf0e10cSrcweir         else
328*cdf0e10cSrcweir             nResult = (aCell1.Row() < aCell2.Row()) ? -1 : 1;
329*cdf0e10cSrcweir     }
330*cdf0e10cSrcweir     return nResult;
331*cdf0e10cSrcweir }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir void ScNotesChilds::CollectChilds(const ScAccNote& rNote, ScXAccList& rList)
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir     if (rNote.mpTextHelper)
336*cdf0e10cSrcweir         for (sal_Int32 i = 0; i < rNote.mnParaCount; ++i)
337*cdf0e10cSrcweir             rList.push_back(rNote.mpTextHelper->GetChild(i + rNote.mpTextHelper->GetStartIndex()));
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir sal_Int32 ScNotesChilds::CheckChanges(const ScPreviewLocationData& rData,
341*cdf0e10cSrcweir             const Rectangle& rVisRect, sal_Bool bMark, ScAccNotes& rOldNotes,
342*cdf0e10cSrcweir             ScAccNotes& rNewNotes, ScXAccList& rOldParas, ScXAccList& rNewParas)
343*cdf0e10cSrcweir {
344*cdf0e10cSrcweir     sal_Int32 nCount = rData.GetNoteCountInRange(rVisRect, bMark);
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     rNewNotes.reserve(nCount);
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir     sal_Int32 nParagraphs(0);
349*cdf0e10cSrcweir     ScDocument* pDoc = GetDocument();
350*cdf0e10cSrcweir     if (pDoc)
351*cdf0e10cSrcweir     {
352*cdf0e10cSrcweir         ScAccNote aNote;
353*cdf0e10cSrcweir         aNote.mbMarkNote = bMark;
354*cdf0e10cSrcweir         if (bMark)
355*cdf0e10cSrcweir             aNote.mnParaCount = 1;
356*cdf0e10cSrcweir         ScAccNotes::iterator aItr = rOldNotes.begin();
357*cdf0e10cSrcweir         ScAccNotes::iterator aEndItr = rOldNotes.end();
358*cdf0e10cSrcweir         sal_Bool bAddNote(sal_False);
359*cdf0e10cSrcweir         for (sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex)
360*cdf0e10cSrcweir         {
361*cdf0e10cSrcweir             if (rData.GetNoteInRange(rVisRect, nIndex, bMark, aNote.maNoteCell, aNote.maRect))
362*cdf0e10cSrcweir             {
363*cdf0e10cSrcweir                 if (bMark)
364*cdf0e10cSrcweir                 {
365*cdf0e10cSrcweir 	                // Document not needed, because only the cell address, but not the tablename is needed
366*cdf0e10cSrcweir 	                aNote.maNoteCell.Format( aNote.maNoteText, SCA_VALID, NULL );
367*cdf0e10cSrcweir                 }
368*cdf0e10cSrcweir                 else
369*cdf0e10cSrcweir                 {
370*cdf0e10cSrcweir                     if( ScPostIt* pNote = pDoc->GetNote( aNote.maNoteCell ) )
371*cdf0e10cSrcweir                         aNote.maNoteText = pNote->GetText();
372*cdf0e10cSrcweir                 }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir                 sal_Int8 nCompare(-1); // if there are no more old childs it is always a new one
375*cdf0e10cSrcweir                 if (aItr != aEndItr)
376*cdf0e10cSrcweir                     nCompare = CompareCell(aNote.maNoteCell, aItr->maNoteCell);
377*cdf0e10cSrcweir                 if (nCompare == 0)
378*cdf0e10cSrcweir                 {
379*cdf0e10cSrcweir                     if (aNote.maNoteText == aItr->maNoteText)
380*cdf0e10cSrcweir                     {
381*cdf0e10cSrcweir                         aNote.mpTextHelper = aItr->mpTextHelper;
382*cdf0e10cSrcweir                         if (aNote.maRect != aItr->maRect)  //neue VisArea setzen
383*cdf0e10cSrcweir                         {
384*cdf0e10cSrcweir                             aNote.mpTextHelper->SetOffset(aNote.maRect.TopLeft());
385*cdf0e10cSrcweir                             aNote.mpTextHelper->UpdateChildren();
386*cdf0e10cSrcweir                             //DBG_ASSERT(aItr->maRect.GetSize() == aNote.maRect.GetSize(), "size should be the same, because the text is not changed");
387*cdf0e10cSrcweir                             // could be changed, because only a part of the note is visible
388*cdf0e10cSrcweir                         }
389*cdf0e10cSrcweir                     }
390*cdf0e10cSrcweir                     else
391*cdf0e10cSrcweir                     {
392*cdf0e10cSrcweir                         aNote.mpTextHelper = CreateTextHelper(aNote.maNoteText, aNote.maRect, aNote.maNoteCell, aNote.mbMarkNote, nParagraphs + mnOffset);
393*cdf0e10cSrcweir                         if (aNote.mpTextHelper)
394*cdf0e10cSrcweir                             aNote.mnParaCount = aNote.mpTextHelper->GetChildCount();
395*cdf0e10cSrcweir                         // collect removed childs
396*cdf0e10cSrcweir                         CollectChilds(*aItr, rOldParas);
397*cdf0e10cSrcweir                         DELETEZ(aItr->mpTextHelper);
398*cdf0e10cSrcweir                         // collect new childs
399*cdf0e10cSrcweir                         CollectChilds(aNote, rNewParas);
400*cdf0e10cSrcweir                     }
401*cdf0e10cSrcweir                     bAddNote = sal_True;
402*cdf0e10cSrcweir                     // not necessary, because this branch should not be reached if it is the end
403*cdf0e10cSrcweir                     //if (aItr != aEndItr)
404*cdf0e10cSrcweir                     ++aItr;
405*cdf0e10cSrcweir                 }
406*cdf0e10cSrcweir                 else if (nCompare < 0)
407*cdf0e10cSrcweir                 {
408*cdf0e10cSrcweir                     aNote.mpTextHelper = CreateTextHelper(aNote.maNoteText, aNote.maRect, aNote.maNoteCell, aNote.mbMarkNote, nParagraphs + mnOffset);
409*cdf0e10cSrcweir                     if (aNote.mpTextHelper)
410*cdf0e10cSrcweir                         aNote.mnParaCount = aNote.mpTextHelper->GetChildCount();
411*cdf0e10cSrcweir                     // collect new childs
412*cdf0e10cSrcweir                     CollectChilds(aNote, rNewParas);
413*cdf0e10cSrcweir                     bAddNote = sal_True;
414*cdf0e10cSrcweir                 }
415*cdf0e10cSrcweir                 else
416*cdf0e10cSrcweir                 {
417*cdf0e10cSrcweir                     // collect removed childs
418*cdf0e10cSrcweir                     CollectChilds(*aItr, rOldParas);
419*cdf0e10cSrcweir                     DELETEZ(aItr->mpTextHelper);
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir                     // no note to add
422*cdf0e10cSrcweir                     // not necessary, because this branch should not be reached if it is the end
423*cdf0e10cSrcweir                     //if (aItr != aEndItr)
424*cdf0e10cSrcweir                     ++aItr;
425*cdf0e10cSrcweir                 }
426*cdf0e10cSrcweir                 if (bAddNote)
427*cdf0e10cSrcweir                 {
428*cdf0e10cSrcweir                     nParagraphs += aNote.mnParaCount;
429*cdf0e10cSrcweir                     rNewNotes.push_back(aNote);
430*cdf0e10cSrcweir                     bAddNote = sal_False;
431*cdf0e10cSrcweir                 }
432*cdf0e10cSrcweir             }
433*cdf0e10cSrcweir         }
434*cdf0e10cSrcweir     }
435*cdf0e10cSrcweir     return nParagraphs;
436*cdf0e10cSrcweir }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir struct ScChildGone
439*cdf0e10cSrcweir {
440*cdf0e10cSrcweir     ScAccessibleDocumentPagePreview* mpAccDoc;
441*cdf0e10cSrcweir     ScChildGone(ScAccessibleDocumentPagePreview* pAccDoc) : mpAccDoc(pAccDoc) {}
442*cdf0e10cSrcweir     void operator() (const uno::Reference<XAccessible>& xAccessible) const
443*cdf0e10cSrcweir     {
444*cdf0e10cSrcweir         if (mpAccDoc)
445*cdf0e10cSrcweir         {
446*cdf0e10cSrcweir 			AccessibleEventObject aEvent;
447*cdf0e10cSrcweir 			aEvent.EventId = AccessibleEventId::CHILD;
448*cdf0e10cSrcweir 			aEvent.Source = uno::Reference< XAccessibleContext >(mpAccDoc);
449*cdf0e10cSrcweir 			aEvent.OldValue <<= xAccessible;
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 			mpAccDoc->CommitChange(aEvent); // gone child - event
452*cdf0e10cSrcweir         }
453*cdf0e10cSrcweir     }
454*cdf0e10cSrcweir };
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir struct ScChildNew
457*cdf0e10cSrcweir {
458*cdf0e10cSrcweir     ScAccessibleDocumentPagePreview* mpAccDoc;
459*cdf0e10cSrcweir     ScChildNew(ScAccessibleDocumentPagePreview* pAccDoc) : mpAccDoc(pAccDoc) {}
460*cdf0e10cSrcweir     void operator() (const uno::Reference<XAccessible>& xAccessible) const
461*cdf0e10cSrcweir     {
462*cdf0e10cSrcweir         if (mpAccDoc)
463*cdf0e10cSrcweir         {
464*cdf0e10cSrcweir 			AccessibleEventObject aEvent;
465*cdf0e10cSrcweir 			aEvent.EventId = AccessibleEventId::CHILD;
466*cdf0e10cSrcweir 			aEvent.Source = uno::Reference< XAccessibleContext >(mpAccDoc);
467*cdf0e10cSrcweir 			aEvent.NewValue <<= xAccessible;
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir 			mpAccDoc->CommitChange(aEvent); // new child - event
470*cdf0e10cSrcweir         }
471*cdf0e10cSrcweir     }
472*cdf0e10cSrcweir };
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir void ScNotesChilds::DataChanged(const Rectangle& rVisRect)
475*cdf0e10cSrcweir {
476*cdf0e10cSrcweir     if (mpViewShell && mpAccDoc)
477*cdf0e10cSrcweir     {
478*cdf0e10cSrcweir         ScXAccList aNewParas;
479*cdf0e10cSrcweir         ScXAccList aOldParas;
480*cdf0e10cSrcweir         ScAccNotes aNewMarks;
481*cdf0e10cSrcweir         mnParagraphs = CheckChanges(mpViewShell->GetLocationData(), rVisRect, sal_True, maMarks, aNewMarks, aOldParas, aNewParas);
482*cdf0e10cSrcweir         maMarks = aNewMarks;
483*cdf0e10cSrcweir         ScAccNotes aNewNotes;
484*cdf0e10cSrcweir         mnParagraphs += CheckChanges(mpViewShell->GetLocationData(), rVisRect, sal_False, maNotes, aNewNotes, aOldParas, aNewParas);
485*cdf0e10cSrcweir         maNotes = aNewNotes;
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir         std::for_each(aOldParas.begin(), aOldParas.end(), ScChildGone(mpAccDoc));
488*cdf0e10cSrcweir         std::for_each(aNewParas.begin(), aNewParas.end(), ScChildNew(mpAccDoc));
489*cdf0e10cSrcweir     }
490*cdf0e10cSrcweir }
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir struct ScChangeOffset
493*cdf0e10cSrcweir {
494*cdf0e10cSrcweir     sal_Int32 mnDiff;
495*cdf0e10cSrcweir     ScChangeOffset(sal_Int32 nDiff) : mnDiff(nDiff) {}
496*cdf0e10cSrcweir     void operator() (const ScAccNote& rNote)
497*cdf0e10cSrcweir     {
498*cdf0e10cSrcweir         if (rNote.mpTextHelper)
499*cdf0e10cSrcweir             rNote.mpTextHelper->SetStartIndex(rNote.mpTextHelper->GetStartIndex() + mnDiff);
500*cdf0e10cSrcweir     }
501*cdf0e10cSrcweir };
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir void ScNotesChilds::SetOffset(sal_Int32 nNewOffset)
504*cdf0e10cSrcweir {
505*cdf0e10cSrcweir     sal_Int32 nDiff(nNewOffset - mnOffset);
506*cdf0e10cSrcweir     if (nDiff != 0)
507*cdf0e10cSrcweir     {
508*cdf0e10cSrcweir         std::for_each(maMarks.begin(), maMarks.end(), ScChangeOffset(nDiff));
509*cdf0e10cSrcweir         std::for_each(maNotes.begin(), maNotes.end(), ScChangeOffset(nDiff));
510*cdf0e10cSrcweir         mnOffset = nNewOffset;
511*cdf0e10cSrcweir     }
512*cdf0e10cSrcweir }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir inline ScDocument* ScNotesChilds::GetDocument() const
515*cdf0e10cSrcweir {
516*cdf0e10cSrcweir     ScDocument* pDoc = NULL;
517*cdf0e10cSrcweir     if (mpViewShell)
518*cdf0e10cSrcweir         pDoc = mpViewShell->GetDocument();
519*cdf0e10cSrcweir     return pDoc;
520*cdf0e10cSrcweir }
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir class ScIAccessibleViewForwarder : public ::accessibility::IAccessibleViewForwarder
523*cdf0e10cSrcweir {
524*cdf0e10cSrcweir public:
525*cdf0e10cSrcweir     ScIAccessibleViewForwarder();
526*cdf0e10cSrcweir     ScIAccessibleViewForwarder(ScPreviewShell* pViewShell,
527*cdf0e10cSrcweir                                 ScAccessibleDocumentPagePreview* pAccDoc,
528*cdf0e10cSrcweir                                 const MapMode& aMapMode);
529*cdf0e10cSrcweir     ~ScIAccessibleViewForwarder();
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir 	///=====  IAccessibleViewForwarder  ========================================
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir 	virtual sal_Bool IsValid (void) const;
534*cdf0e10cSrcweir     virtual Rectangle GetVisibleArea() const;
535*cdf0e10cSrcweir     virtual Point LogicToPixel (const Point& rPoint) const;
536*cdf0e10cSrcweir     virtual Size LogicToPixel (const Size& rSize) const;
537*cdf0e10cSrcweir     virtual Point PixelToLogic (const Point& rPoint) const;
538*cdf0e10cSrcweir     virtual Size PixelToLogic (const Size& rSize) const;
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir private:
541*cdf0e10cSrcweir     ScPreviewShell*                     mpViewShell;
542*cdf0e10cSrcweir     ScAccessibleDocumentPagePreview*    mpAccDoc;
543*cdf0e10cSrcweir     MapMode                             maMapMode;
544*cdf0e10cSrcweir     sal_Bool                            mbValid;
545*cdf0e10cSrcweir };
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir ScIAccessibleViewForwarder::ScIAccessibleViewForwarder()
548*cdf0e10cSrcweir     : mbValid(sal_False)
549*cdf0e10cSrcweir {
550*cdf0e10cSrcweir }
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir ScIAccessibleViewForwarder::ScIAccessibleViewForwarder(ScPreviewShell* pViewShell,
553*cdf0e10cSrcweir                                 ScAccessibleDocumentPagePreview* pAccDoc,
554*cdf0e10cSrcweir                                 const MapMode& aMapMode)
555*cdf0e10cSrcweir     : mpViewShell(pViewShell),
556*cdf0e10cSrcweir     mpAccDoc(pAccDoc),
557*cdf0e10cSrcweir     maMapMode(aMapMode),
558*cdf0e10cSrcweir     mbValid(sal_True)
559*cdf0e10cSrcweir {
560*cdf0e10cSrcweir }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir ScIAccessibleViewForwarder::~ScIAccessibleViewForwarder()
563*cdf0e10cSrcweir {
564*cdf0e10cSrcweir }
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir ///=====  IAccessibleViewForwarder  ========================================
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir sal_Bool ScIAccessibleViewForwarder::IsValid (void) const
569*cdf0e10cSrcweir {
570*cdf0e10cSrcweir     ScUnoGuard aGuard;
571*cdf0e10cSrcweir     return mbValid;
572*cdf0e10cSrcweir }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir Rectangle ScIAccessibleViewForwarder::GetVisibleArea() const
575*cdf0e10cSrcweir {
576*cdf0e10cSrcweir     ScUnoGuard aGuard;
577*cdf0e10cSrcweir     Rectangle aVisRect;
578*cdf0e10cSrcweir     Window* pWin = mpViewShell->GetWindow();
579*cdf0e10cSrcweir     if (pWin)
580*cdf0e10cSrcweir     {
581*cdf0e10cSrcweir         aVisRect.SetSize(pWin->GetOutputSizePixel());
582*cdf0e10cSrcweir         aVisRect.SetPos(Point(0, 0));
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir         aVisRect = pWin->PixelToLogic(aVisRect, maMapMode);
585*cdf0e10cSrcweir     }
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir     return aVisRect;
588*cdf0e10cSrcweir }
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir Point ScIAccessibleViewForwarder::LogicToPixel (const Point& rPoint) const
591*cdf0e10cSrcweir {
592*cdf0e10cSrcweir     ScUnoGuard aGuard;
593*cdf0e10cSrcweir     Point aPoint;
594*cdf0e10cSrcweir     Window* pWin = mpViewShell->GetWindow();
595*cdf0e10cSrcweir     if (pWin && mpAccDoc)
596*cdf0e10cSrcweir     {
597*cdf0e10cSrcweir     	Rectangle aRect(mpAccDoc->GetBoundingBoxOnScreen());
598*cdf0e10cSrcweir         aPoint = pWin->LogicToPixel(rPoint, maMapMode) + aRect.TopLeft();
599*cdf0e10cSrcweir     }
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir     return aPoint;
602*cdf0e10cSrcweir }
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir Size ScIAccessibleViewForwarder::LogicToPixel (const Size& rSize) const
605*cdf0e10cSrcweir {
606*cdf0e10cSrcweir     ScUnoGuard aGuard;
607*cdf0e10cSrcweir     Size aSize;
608*cdf0e10cSrcweir     Window* pWin = mpViewShell->GetWindow();
609*cdf0e10cSrcweir     if (pWin)
610*cdf0e10cSrcweir         aSize = pWin->LogicToPixel(rSize, maMapMode);
611*cdf0e10cSrcweir     return aSize;
612*cdf0e10cSrcweir }
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir Point ScIAccessibleViewForwarder::PixelToLogic (const Point& rPoint) const
615*cdf0e10cSrcweir {
616*cdf0e10cSrcweir     ScUnoGuard aGuard;
617*cdf0e10cSrcweir     Point aPoint;
618*cdf0e10cSrcweir     Window* pWin = mpViewShell->GetWindow();
619*cdf0e10cSrcweir     if (pWin && mpAccDoc)
620*cdf0e10cSrcweir     {
621*cdf0e10cSrcweir     	Rectangle aRect(mpAccDoc->GetBoundingBoxOnScreen());
622*cdf0e10cSrcweir         aPoint = pWin->PixelToLogic(rPoint - aRect.TopLeft(), maMapMode);
623*cdf0e10cSrcweir     }
624*cdf0e10cSrcweir     return aPoint;
625*cdf0e10cSrcweir }
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir Size ScIAccessibleViewForwarder::PixelToLogic (const Size& rSize) const
628*cdf0e10cSrcweir {
629*cdf0e10cSrcweir     ScUnoGuard aGuard;
630*cdf0e10cSrcweir     Size aSize;
631*cdf0e10cSrcweir     Window* pWin = mpViewShell->GetWindow();
632*cdf0e10cSrcweir     if (pWin)
633*cdf0e10cSrcweir         aSize = pWin->PixelToLogic(rSize, maMapMode);
634*cdf0e10cSrcweir     return aSize;
635*cdf0e10cSrcweir }
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir struct ScShapeChild
638*cdf0e10cSrcweir {
639*cdf0e10cSrcweir     ScShapeChild() : mpAccShape(NULL) {}
640*cdf0e10cSrcweir     ScShapeChild(const ScShapeChild& rOld);
641*cdf0e10cSrcweir     ~ScShapeChild();
642*cdf0e10cSrcweir 	mutable ::accessibility::AccessibleShape* mpAccShape;
643*cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::drawing::XShape > mxShape;
644*cdf0e10cSrcweir     sal_Int32 mnRangeId;
645*cdf0e10cSrcweir };
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir ScShapeChild::ScShapeChild(const ScShapeChild& rOld)
648*cdf0e10cSrcweir :
649*cdf0e10cSrcweir mpAccShape(rOld.mpAccShape),
650*cdf0e10cSrcweir mxShape(rOld.mxShape),
651*cdf0e10cSrcweir mnRangeId(rOld.mnRangeId)
652*cdf0e10cSrcweir {
653*cdf0e10cSrcweir     if (mpAccShape)
654*cdf0e10cSrcweir         mpAccShape->acquire();
655*cdf0e10cSrcweir }
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir ScShapeChild::~ScShapeChild()
658*cdf0e10cSrcweir {
659*cdf0e10cSrcweir     if (mpAccShape)
660*cdf0e10cSrcweir     {
661*cdf0e10cSrcweir         mpAccShape->dispose();
662*cdf0e10cSrcweir         mpAccShape->release();
663*cdf0e10cSrcweir     }
664*cdf0e10cSrcweir }
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir struct ScShapeChildLess
667*cdf0e10cSrcweir {
668*cdf0e10cSrcweir     sal_Bool operator()(const ScShapeChild& rChild1, const ScShapeChild& rChild2) const
669*cdf0e10cSrcweir     {
670*cdf0e10cSrcweir       sal_Bool bResult(sal_False);
671*cdf0e10cSrcweir       if (rChild1.mxShape.is() && rChild2.mxShape.is())
672*cdf0e10cSrcweir 	      bResult = (rChild1.mxShape.get() < rChild2.mxShape.get());
673*cdf0e10cSrcweir       return bResult;
674*cdf0e10cSrcweir     }
675*cdf0e10cSrcweir };
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir typedef std::vector<ScShapeChild> ScShapeChildVec;
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir struct ScShapeRange
680*cdf0e10cSrcweir {
681*cdf0e10cSrcweir     ScShapeChildVec maBackShapes;
682*cdf0e10cSrcweir     ScShapeChildVec maForeShapes; // inclusive internal shapes
683*cdf0e10cSrcweir     ScShapeChildVec maControls;
684*cdf0e10cSrcweir     Rectangle       maPixelRect;
685*cdf0e10cSrcweir     MapMode         maMapMode;
686*cdf0e10cSrcweir     ScIAccessibleViewForwarder maViewForwarder;
687*cdf0e10cSrcweir };
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir typedef std::vector<ScShapeRange> ScShapeRangeVec;
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir class ScShapeChilds : public SfxListener,
692*cdf0e10cSrcweir         public ::accessibility::IAccessibleParent
693*cdf0e10cSrcweir {
694*cdf0e10cSrcweir public:
695*cdf0e10cSrcweir     ScShapeChilds(ScPreviewShell* pViewShell, ScAccessibleDocumentPagePreview* pAccDoc);
696*cdf0e10cSrcweir     ~ScShapeChilds();
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir     ///=====  SfxListener  =====================================================
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir 	virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir     ///=====  IAccessibleParent  ==============================================
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir     virtual sal_Bool ReplaceChild (
705*cdf0e10cSrcweir         ::accessibility::AccessibleShape* pCurrentChild,
706*cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& _rxShape,
707*cdf0e10cSrcweir 		const long _nIndex,
708*cdf0e10cSrcweir 		const ::accessibility::AccessibleShapeTreeInfo& _rShapeTreeInfo
709*cdf0e10cSrcweir 	)	throw (::com::sun::star::uno::RuntimeException);
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir     ///=====  Internal  ========================================================
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir     void Init();
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir     sal_Int32 GetBackShapeCount() const;
716*cdf0e10cSrcweir     uno::Reference<XAccessible> GetBackShape(sal_Int32 nIndex) const;
717*cdf0e10cSrcweir     sal_Int32 GetForeShapeCount() const;
718*cdf0e10cSrcweir     uno::Reference<XAccessible> GetForeShape(sal_Int32 nIndex) const;
719*cdf0e10cSrcweir     sal_Int32 GetControlCount() const;
720*cdf0e10cSrcweir     uno::Reference<XAccessible> GetControl(sal_Int32 nIndex) const;
721*cdf0e10cSrcweir     uno::Reference<XAccessible> GetForegroundShapeAt(const awt::Point& rPoint) const; // inclusive controls
722*cdf0e10cSrcweir     uno::Reference<XAccessible> GetBackgroundShapeAt(const awt::Point& rPoint) const;
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir     void DataChanged();
725*cdf0e10cSrcweir     void VisAreaChanged() const;
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir     void SetDrawBroadcaster();
728*cdf0e10cSrcweir private:
729*cdf0e10cSrcweir     ScAccessibleDocumentPagePreview* mpAccDoc;
730*cdf0e10cSrcweir     ScPreviewShell* mpViewShell;
731*cdf0e10cSrcweir     ScShapeRangeVec maShapeRanges;
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir     void FindChanged(ScShapeChildVec& aOld, ScShapeChildVec& aNew) const;
734*cdf0e10cSrcweir     void FindChanged(ScShapeRange& aOld, ScShapeRange& aNew) const;
735*cdf0e10cSrcweir     ::accessibility::AccessibleShape* GetAccShape(const ScShapeChild& rShape) const;
736*cdf0e10cSrcweir     ::accessibility::AccessibleShape* GetAccShape(const ScShapeChildVec& rShapes, sal_Int32 nIndex) const;
737*cdf0e10cSrcweir     void FillShapes(const Rectangle& aPixelPaintRect, const MapMode& aMapMode, sal_uInt8 nRangeId);
738*cdf0e10cSrcweir //UNUSED2008-05  sal_Bool FindShape(ScShapeChildVec& rShapes, const uno::Reference <drawing::XShape>& xShape, ScShapeChildVec::iterator& rItr) const;
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir //    void AddShape(const uno::Reference<drawing::XShape>& xShape, SdrLayerID aLayerID);
741*cdf0e10cSrcweir //    void RemoveShape(const uno::Reference<drawing::XShape>& xShape, SdrLayerID aLayerID);
742*cdf0e10cSrcweir     SdrPage* GetDrawPage() const;
743*cdf0e10cSrcweir };
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir ScShapeChilds::ScShapeChilds(ScPreviewShell* pViewShell, ScAccessibleDocumentPagePreview* pAccDoc)
746*cdf0e10cSrcweir     :
747*cdf0e10cSrcweir     mpAccDoc(pAccDoc),
748*cdf0e10cSrcweir     mpViewShell(pViewShell),
749*cdf0e10cSrcweir     maShapeRanges(SC_PREVIEW_MAXRANGES)
750*cdf0e10cSrcweir {
751*cdf0e10cSrcweir     if (pViewShell)
752*cdf0e10cSrcweir     {
753*cdf0e10cSrcweir 	    SfxBroadcaster* pDrawBC = pViewShell->GetDocument()->GetDrawBroadcaster();
754*cdf0e10cSrcweir 	    if (pDrawBC)
755*cdf0e10cSrcweir 		    StartListening(*pDrawBC);
756*cdf0e10cSrcweir     }
757*cdf0e10cSrcweir }
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir ScShapeChilds::~ScShapeChilds()
760*cdf0e10cSrcweir {
761*cdf0e10cSrcweir     if (mpViewShell)
762*cdf0e10cSrcweir     {
763*cdf0e10cSrcweir 	    SfxBroadcaster* pDrawBC = mpViewShell->GetDocument()->GetDrawBroadcaster();
764*cdf0e10cSrcweir 	    if (pDrawBC)
765*cdf0e10cSrcweir 		    EndListening(*pDrawBC);
766*cdf0e10cSrcweir     }
767*cdf0e10cSrcweir }
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir void ScShapeChilds::SetDrawBroadcaster()
770*cdf0e10cSrcweir {
771*cdf0e10cSrcweir     if (mpViewShell)
772*cdf0e10cSrcweir     {
773*cdf0e10cSrcweir 	    SfxBroadcaster* pDrawBC = mpViewShell->GetDocument()->GetDrawBroadcaster();
774*cdf0e10cSrcweir 	    if (pDrawBC)
775*cdf0e10cSrcweir 		    StartListening(*pDrawBC, sal_True);
776*cdf0e10cSrcweir     }
777*cdf0e10cSrcweir }
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir void ScShapeChilds::Notify(SfxBroadcaster&, const SfxHint& rHint)
780*cdf0e10cSrcweir {
781*cdf0e10cSrcweir 	if ( rHint.ISA( SdrHint ) )
782*cdf0e10cSrcweir 	{
783*cdf0e10cSrcweir 		const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
784*cdf0e10cSrcweir         if (pSdrHint)
785*cdf0e10cSrcweir         {
786*cdf0e10cSrcweir             SdrObject* pObj = const_cast<SdrObject*>(pSdrHint->GetObject());
787*cdf0e10cSrcweir             if (pObj && (pObj->GetPage() == GetDrawPage()))
788*cdf0e10cSrcweir             {
789*cdf0e10cSrcweir                 switch (pSdrHint->GetKind())
790*cdf0e10cSrcweir                 {
791*cdf0e10cSrcweir                     case HINT_OBJCHG :         // Objekt geaendert
792*cdf0e10cSrcweir                     {
793*cdf0e10cSrcweir                     }
794*cdf0e10cSrcweir                     break;
795*cdf0e10cSrcweir                     // no longer necessary
796*cdf0e10cSrcweir /*                    case HINT_OBJINSERTED :    // Neues Zeichenobjekt eingefuegt
797*cdf0e10cSrcweir                     {
798*cdf0e10cSrcweir                         uno::Reference<drawing::XShape> xShape (pObj->getUnoShape(), uno::UNO_QUERY);
799*cdf0e10cSrcweir                         if (xShape.is())
800*cdf0e10cSrcweir                             AddShape(xShape, pObj->GetLayer());
801*cdf0e10cSrcweir                     }
802*cdf0e10cSrcweir                     break;
803*cdf0e10cSrcweir                     case HINT_OBJREMOVED :     // Zeichenobjekt aus Liste entfernt
804*cdf0e10cSrcweir                     {
805*cdf0e10cSrcweir                         uno::Reference<drawing::XShape> xShape (pObj->getUnoShape(), uno::UNO_QUERY);
806*cdf0e10cSrcweir                         if (xShape.is())
807*cdf0e10cSrcweir                             RemoveShape(xShape, pObj->GetLayer());
808*cdf0e10cSrcweir                     }
809*cdf0e10cSrcweir                     break;*/
810*cdf0e10cSrcweir                     default :
811*cdf0e10cSrcweir                     {
812*cdf0e10cSrcweir                         // other events are not interesting
813*cdf0e10cSrcweir                     }
814*cdf0e10cSrcweir                     break;
815*cdf0e10cSrcweir                 }
816*cdf0e10cSrcweir             }
817*cdf0e10cSrcweir         }
818*cdf0e10cSrcweir     }
819*cdf0e10cSrcweir }
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir void ScShapeChilds::FindChanged(ScShapeChildVec& rOld, ScShapeChildVec& rNew) const
822*cdf0e10cSrcweir {
823*cdf0e10cSrcweir     ScShapeChildVec::iterator aOldItr = rOld.begin();
824*cdf0e10cSrcweir     ScShapeChildVec::iterator aOldEnd = rOld.end();
825*cdf0e10cSrcweir     ScShapeChildVec::const_iterator aNewItr = rNew.begin();
826*cdf0e10cSrcweir     ScShapeChildVec::const_iterator aNewEnd = rNew.begin();
827*cdf0e10cSrcweir     uno::Reference<XAccessible> xAcc;
828*cdf0e10cSrcweir     while ((aNewItr != aNewEnd) && (aOldItr != aOldEnd))
829*cdf0e10cSrcweir     {
830*cdf0e10cSrcweir         if (aNewItr->mxShape.get() == aOldItr->mxShape.get())
831*cdf0e10cSrcweir         {
832*cdf0e10cSrcweir             ++aOldItr;
833*cdf0e10cSrcweir             ++aNewItr;
834*cdf0e10cSrcweir         }
835*cdf0e10cSrcweir         else if (aNewItr->mxShape.get() < aOldItr->mxShape.get())
836*cdf0e10cSrcweir         {
837*cdf0e10cSrcweir             xAcc = GetAccShape(*aNewItr);
838*cdf0e10cSrcweir             AccessibleEventObject aEvent;
839*cdf0e10cSrcweir             aEvent.Source = uno::Reference<XAccessibleContext> (mpAccDoc);
840*cdf0e10cSrcweir             aEvent.EventId = AccessibleEventId::CHILD;
841*cdf0e10cSrcweir             aEvent.NewValue <<= xAcc;
842*cdf0e10cSrcweir             mpAccDoc->CommitChange(aEvent);
843*cdf0e10cSrcweir             ++aNewItr;
844*cdf0e10cSrcweir         }
845*cdf0e10cSrcweir         else
846*cdf0e10cSrcweir         {
847*cdf0e10cSrcweir             xAcc = GetAccShape(*aOldItr);
848*cdf0e10cSrcweir             AccessibleEventObject aEvent;
849*cdf0e10cSrcweir             aEvent.Source = uno::Reference<XAccessibleContext> (mpAccDoc);
850*cdf0e10cSrcweir             aEvent.EventId = AccessibleEventId::CHILD;
851*cdf0e10cSrcweir             aEvent.OldValue <<= xAcc;
852*cdf0e10cSrcweir             mpAccDoc->CommitChange(aEvent);
853*cdf0e10cSrcweir             ++aOldItr;
854*cdf0e10cSrcweir         }
855*cdf0e10cSrcweir     }
856*cdf0e10cSrcweir     while (aOldItr != aOldEnd)
857*cdf0e10cSrcweir     {
858*cdf0e10cSrcweir         xAcc = GetAccShape(*aOldItr);
859*cdf0e10cSrcweir         AccessibleEventObject aEvent;
860*cdf0e10cSrcweir         aEvent.Source = uno::Reference<XAccessibleContext> (mpAccDoc);
861*cdf0e10cSrcweir         aEvent.EventId = AccessibleEventId::CHILD;
862*cdf0e10cSrcweir         aEvent.OldValue <<= xAcc;
863*cdf0e10cSrcweir         mpAccDoc->CommitChange(aEvent);
864*cdf0e10cSrcweir         ++aOldItr;
865*cdf0e10cSrcweir     }
866*cdf0e10cSrcweir     while (aNewItr != aNewEnd)
867*cdf0e10cSrcweir     {
868*cdf0e10cSrcweir         xAcc = GetAccShape(*aNewItr);
869*cdf0e10cSrcweir         AccessibleEventObject aEvent;
870*cdf0e10cSrcweir         aEvent.Source = uno::Reference<XAccessibleContext> (mpAccDoc);
871*cdf0e10cSrcweir         aEvent.EventId = AccessibleEventId::CHILD;
872*cdf0e10cSrcweir         aEvent.NewValue <<= xAcc;
873*cdf0e10cSrcweir         mpAccDoc->CommitChange(aEvent);
874*cdf0e10cSrcweir         ++aNewItr;
875*cdf0e10cSrcweir     }
876*cdf0e10cSrcweir }
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir void ScShapeChilds::FindChanged(ScShapeRange& rOld, ScShapeRange& rNew) const
879*cdf0e10cSrcweir {
880*cdf0e10cSrcweir     FindChanged(rOld.maBackShapes, rNew.maBackShapes);
881*cdf0e10cSrcweir     FindChanged(rOld.maForeShapes, rNew.maForeShapes);
882*cdf0e10cSrcweir     FindChanged(rOld.maControls, rNew.maControls);
883*cdf0e10cSrcweir }
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir void ScShapeChilds::DataChanged()
886*cdf0e10cSrcweir {
887*cdf0e10cSrcweir     ScShapeRangeVec aOldShapeRanges(maShapeRanges);
888*cdf0e10cSrcweir     maShapeRanges.clear();
889*cdf0e10cSrcweir     maShapeRanges.resize(SC_PREVIEW_MAXRANGES);
890*cdf0e10cSrcweir     Init();
891*cdf0e10cSrcweir     for (sal_Int32 i = 0; i < SC_PREVIEW_MAXRANGES; ++i)
892*cdf0e10cSrcweir     {
893*cdf0e10cSrcweir         FindChanged(aOldShapeRanges[i], maShapeRanges[i]);
894*cdf0e10cSrcweir     }
895*cdf0e10cSrcweir }
896*cdf0e10cSrcweir 
897*cdf0e10cSrcweir struct ScVisAreaChanged
898*cdf0e10cSrcweir {
899*cdf0e10cSrcweir     const ScIAccessibleViewForwarder* mpViewForwarder;
900*cdf0e10cSrcweir     ScVisAreaChanged(const ScIAccessibleViewForwarder* pViewForwarder) : mpViewForwarder(pViewForwarder) {}
901*cdf0e10cSrcweir 	void operator() (const ScShapeChild& rAccShapeData) const
902*cdf0e10cSrcweir     {
903*cdf0e10cSrcweir 	    if (rAccShapeData.mpAccShape)
904*cdf0e10cSrcweir         {
905*cdf0e10cSrcweir             rAccShapeData.mpAccShape->ViewForwarderChanged(::accessibility::IAccessibleViewForwarderListener::VISIBLE_AREA, mpViewForwarder);
906*cdf0e10cSrcweir         }
907*cdf0e10cSrcweir     }
908*cdf0e10cSrcweir };
909*cdf0e10cSrcweir 
910*cdf0e10cSrcweir void ScShapeChilds::VisAreaChanged() const
911*cdf0e10cSrcweir {
912*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aEndItr = maShapeRanges.end();
913*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aItr = maShapeRanges.begin();
914*cdf0e10cSrcweir     while (aItr != aEndItr)
915*cdf0e10cSrcweir     {
916*cdf0e10cSrcweir         ScVisAreaChanged aVisAreaChanged(&(aItr->maViewForwarder));
917*cdf0e10cSrcweir         std::for_each(aItr->maBackShapes.begin(), aItr->maBackShapes.end(), aVisAreaChanged);
918*cdf0e10cSrcweir         std::for_each(aItr->maControls.begin(), aItr->maControls.end(), aVisAreaChanged);
919*cdf0e10cSrcweir         std::for_each(aItr->maForeShapes.begin(), aItr->maForeShapes.end(), aVisAreaChanged);
920*cdf0e10cSrcweir         ++aItr;
921*cdf0e10cSrcweir     }
922*cdf0e10cSrcweir }
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir     ///=====  IAccessibleParent  ==============================================
925*cdf0e10cSrcweir 
926*cdf0e10cSrcweir sal_Bool ScShapeChilds::ReplaceChild (::accessibility::AccessibleShape* /* pCurrentChild */,
927*cdf0e10cSrcweir     const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& /* _rxShape */,
928*cdf0e10cSrcweir         const long /* _nIndex */, const ::accessibility::AccessibleShapeTreeInfo& /* _rShapeTreeInfo */)
929*cdf0e10cSrcweir         throw (uno::RuntimeException)
930*cdf0e10cSrcweir {
931*cdf0e10cSrcweir     DBG_ERRORFILE("should not be called in the page preview");
932*cdf0e10cSrcweir     return sal_False;
933*cdf0e10cSrcweir }
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir     ///=====  Internal  ========================================================
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir void ScShapeChilds::Init()
938*cdf0e10cSrcweir {
939*cdf0e10cSrcweir     if(mpViewShell)
940*cdf0e10cSrcweir     {
941*cdf0e10cSrcweir         const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
942*cdf0e10cSrcweir         MapMode aMapMode;
943*cdf0e10cSrcweir         Rectangle aPixelPaintRect;
944*cdf0e10cSrcweir         sal_uInt8 nRangeId;
945*cdf0e10cSrcweir         sal_uInt16 nCount(rData.GetDrawRanges());
946*cdf0e10cSrcweir         for (sal_uInt16 i = 0; i < nCount; ++i)
947*cdf0e10cSrcweir         {
948*cdf0e10cSrcweir             rData.GetDrawRange(i, aPixelPaintRect, aMapMode, nRangeId);
949*cdf0e10cSrcweir             FillShapes(aPixelPaintRect, aMapMode, nRangeId);
950*cdf0e10cSrcweir         }
951*cdf0e10cSrcweir     }
952*cdf0e10cSrcweir }
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir sal_Int32 ScShapeChilds::GetBackShapeCount() const
955*cdf0e10cSrcweir {
956*cdf0e10cSrcweir     sal_Int32 nCount(0);
957*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aEndItr = maShapeRanges.end();
958*cdf0e10cSrcweir     for ( ScShapeRangeVec::const_iterator aItr = maShapeRanges.begin(); aItr != aEndItr; ++aItr )
959*cdf0e10cSrcweir         nCount += aItr->maBackShapes.size();
960*cdf0e10cSrcweir     return nCount;
961*cdf0e10cSrcweir }
962*cdf0e10cSrcweir 
963*cdf0e10cSrcweir uno::Reference<XAccessible> ScShapeChilds::GetBackShape(sal_Int32 nIndex) const
964*cdf0e10cSrcweir {
965*cdf0e10cSrcweir     uno::Reference<XAccessible> xAccessible;
966*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aEndItr = maShapeRanges.end();
967*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aItr = maShapeRanges.begin();
968*cdf0e10cSrcweir     while ((aItr != aEndItr) && !xAccessible.is())
969*cdf0e10cSrcweir     {
970*cdf0e10cSrcweir         sal_Int32 nCount(aItr->maBackShapes.size());
971*cdf0e10cSrcweir         if(nIndex < nCount)
972*cdf0e10cSrcweir             xAccessible = GetAccShape(aItr->maBackShapes, nIndex);
973*cdf0e10cSrcweir         else
974*cdf0e10cSrcweir             ++aItr;
975*cdf0e10cSrcweir         nIndex -= nCount;
976*cdf0e10cSrcweir     }
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir     if (nIndex >= 0)
979*cdf0e10cSrcweir         throw lang::IndexOutOfBoundsException();
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir    return xAccessible;
982*cdf0e10cSrcweir }
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir sal_Int32 ScShapeChilds::GetForeShapeCount() const
985*cdf0e10cSrcweir {
986*cdf0e10cSrcweir     sal_Int32 nCount(0);
987*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aEndItr = maShapeRanges.end();
988*cdf0e10cSrcweir     for ( ScShapeRangeVec::const_iterator aItr = maShapeRanges.begin(); aItr != aEndItr; ++aItr )
989*cdf0e10cSrcweir         nCount += aItr->maForeShapes.size();
990*cdf0e10cSrcweir     return nCount;
991*cdf0e10cSrcweir }
992*cdf0e10cSrcweir 
993*cdf0e10cSrcweir uno::Reference<XAccessible> ScShapeChilds::GetForeShape(sal_Int32 nIndex) const
994*cdf0e10cSrcweir {
995*cdf0e10cSrcweir     uno::Reference<XAccessible> xAccessible;
996*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aEndItr = maShapeRanges.end();
997*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aItr = maShapeRanges.begin();
998*cdf0e10cSrcweir     while ((aItr != aEndItr) && !xAccessible.is())
999*cdf0e10cSrcweir     {
1000*cdf0e10cSrcweir         sal_Int32 nCount(aItr->maForeShapes.size());
1001*cdf0e10cSrcweir         if(nIndex < nCount)
1002*cdf0e10cSrcweir             xAccessible = GetAccShape(aItr->maForeShapes, nIndex);
1003*cdf0e10cSrcweir         else
1004*cdf0e10cSrcweir             ++aItr;
1005*cdf0e10cSrcweir         nIndex -= nCount;
1006*cdf0e10cSrcweir     }
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir     if (nIndex >= 0)
1009*cdf0e10cSrcweir         throw lang::IndexOutOfBoundsException();
1010*cdf0e10cSrcweir 
1011*cdf0e10cSrcweir    return xAccessible;
1012*cdf0e10cSrcweir }
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir sal_Int32 ScShapeChilds::GetControlCount() const
1015*cdf0e10cSrcweir {
1016*cdf0e10cSrcweir     sal_Int32 nCount(0);
1017*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aEndItr = maShapeRanges.end();
1018*cdf0e10cSrcweir     for ( ScShapeRangeVec::const_iterator aItr = maShapeRanges.begin(); aItr != aEndItr; ++aItr )
1019*cdf0e10cSrcweir         nCount += aItr->maControls.size();
1020*cdf0e10cSrcweir     return nCount;
1021*cdf0e10cSrcweir }
1022*cdf0e10cSrcweir 
1023*cdf0e10cSrcweir uno::Reference<XAccessible> ScShapeChilds::GetControl(sal_Int32 nIndex) const
1024*cdf0e10cSrcweir {
1025*cdf0e10cSrcweir     uno::Reference<XAccessible> xAccessible;
1026*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aEndItr = maShapeRanges.end();
1027*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aItr = maShapeRanges.begin();
1028*cdf0e10cSrcweir     while ((aItr != aEndItr) && !xAccessible.is())
1029*cdf0e10cSrcweir     {
1030*cdf0e10cSrcweir         sal_Int32 nCount(aItr->maControls.size());
1031*cdf0e10cSrcweir         if(nIndex < nCount)
1032*cdf0e10cSrcweir             xAccessible = GetAccShape(aItr->maControls, nIndex);
1033*cdf0e10cSrcweir         else
1034*cdf0e10cSrcweir             ++aItr;
1035*cdf0e10cSrcweir         nIndex -= nCount;
1036*cdf0e10cSrcweir     }
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir     if (nIndex >= 0)
1039*cdf0e10cSrcweir         throw lang::IndexOutOfBoundsException();
1040*cdf0e10cSrcweir 
1041*cdf0e10cSrcweir    return xAccessible;
1042*cdf0e10cSrcweir }
1043*cdf0e10cSrcweir 
1044*cdf0e10cSrcweir struct ScShapePointFound
1045*cdf0e10cSrcweir {
1046*cdf0e10cSrcweir     Point maPoint;
1047*cdf0e10cSrcweir     ScShapePointFound(const awt::Point& rPoint) : maPoint(VCLPoint(rPoint)) {}
1048*cdf0e10cSrcweir     sal_Bool operator() (const ScShapeChild& rShape)
1049*cdf0e10cSrcweir     {
1050*cdf0e10cSrcweir         sal_Bool bResult(sal_False);
1051*cdf0e10cSrcweir         if ((VCLRectangle(rShape.mpAccShape->getBounds())).IsInside(maPoint))
1052*cdf0e10cSrcweir             bResult = sal_True;
1053*cdf0e10cSrcweir         return bResult;
1054*cdf0e10cSrcweir     }
1055*cdf0e10cSrcweir };
1056*cdf0e10cSrcweir 
1057*cdf0e10cSrcweir uno::Reference<XAccessible> ScShapeChilds::GetForegroundShapeAt(const awt::Point& rPoint) const //inclusive Controls
1058*cdf0e10cSrcweir {
1059*cdf0e10cSrcweir     uno::Reference<XAccessible> xAcc;
1060*cdf0e10cSrcweir 
1061*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aItr = maShapeRanges.begin();
1062*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aEndItr = maShapeRanges.end();
1063*cdf0e10cSrcweir     while((aItr != aEndItr) && !xAcc.is())
1064*cdf0e10cSrcweir     {
1065*cdf0e10cSrcweir         ScShapeChildVec::const_iterator aFindItr = std::find_if(aItr->maForeShapes.begin(), aItr->maForeShapes.end(), ScShapePointFound(rPoint));
1066*cdf0e10cSrcweir         if (aFindItr != aItr->maForeShapes.end())
1067*cdf0e10cSrcweir             xAcc = GetAccShape(*aFindItr);
1068*cdf0e10cSrcweir         else
1069*cdf0e10cSrcweir         {
1070*cdf0e10cSrcweir             ScShapeChildVec::const_iterator aCtrlItr = std::find_if(aItr->maControls.begin(), aItr->maControls.end(), ScShapePointFound(rPoint));
1071*cdf0e10cSrcweir             if (aCtrlItr != aItr->maControls.end())
1072*cdf0e10cSrcweir                 xAcc = GetAccShape(*aCtrlItr);
1073*cdf0e10cSrcweir             else
1074*cdf0e10cSrcweir                 ++aItr;
1075*cdf0e10cSrcweir         }
1076*cdf0e10cSrcweir     }
1077*cdf0e10cSrcweir 
1078*cdf0e10cSrcweir     return xAcc;
1079*cdf0e10cSrcweir }
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir uno::Reference<XAccessible> ScShapeChilds::GetBackgroundShapeAt(const awt::Point& rPoint) const
1082*cdf0e10cSrcweir {
1083*cdf0e10cSrcweir     uno::Reference<XAccessible> xAcc;
1084*cdf0e10cSrcweir 
1085*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aItr = maShapeRanges.begin();
1086*cdf0e10cSrcweir     ScShapeRangeVec::const_iterator aEndItr = maShapeRanges.end();
1087*cdf0e10cSrcweir     while((aItr != aEndItr) && !xAcc.is())
1088*cdf0e10cSrcweir     {
1089*cdf0e10cSrcweir         ScShapeChildVec::const_iterator aFindItr = std::find_if(aItr->maBackShapes.begin(), aItr->maBackShapes.end(), ScShapePointFound(rPoint));
1090*cdf0e10cSrcweir         if (aFindItr != aItr->maBackShapes.end())
1091*cdf0e10cSrcweir             xAcc = GetAccShape(*aFindItr);
1092*cdf0e10cSrcweir         else
1093*cdf0e10cSrcweir             ++aItr;
1094*cdf0e10cSrcweir     }
1095*cdf0e10cSrcweir 
1096*cdf0e10cSrcweir     return xAcc;
1097*cdf0e10cSrcweir }
1098*cdf0e10cSrcweir 
1099*cdf0e10cSrcweir ::accessibility::AccessibleShape* ScShapeChilds::GetAccShape(const ScShapeChild& rShape) const
1100*cdf0e10cSrcweir {
1101*cdf0e10cSrcweir 	if (!rShape.mpAccShape)
1102*cdf0e10cSrcweir 	{
1103*cdf0e10cSrcweir 		::accessibility::ShapeTypeHandler& rShapeHandler = ::accessibility::ShapeTypeHandler::Instance();
1104*cdf0e10cSrcweir         ::accessibility::AccessibleShapeInfo aShapeInfo(rShape.mxShape, mpAccDoc, const_cast<ScShapeChilds*>(this));
1105*cdf0e10cSrcweir 
1106*cdf0e10cSrcweir         if (mpViewShell)
1107*cdf0e10cSrcweir         {
1108*cdf0e10cSrcweir             ::accessibility::AccessibleShapeTreeInfo aShapeTreeInfo;
1109*cdf0e10cSrcweir             aShapeTreeInfo.SetSdrView(mpViewShell->GetPreview()->GetDrawView());
1110*cdf0e10cSrcweir             aShapeTreeInfo.SetController(NULL);
1111*cdf0e10cSrcweir             aShapeTreeInfo.SetWindow(mpViewShell->GetWindow());
1112*cdf0e10cSrcweir             aShapeTreeInfo.SetViewForwarder(&(maShapeRanges[rShape.mnRangeId].maViewForwarder));
1113*cdf0e10cSrcweir 		    rShape.mpAccShape = rShapeHandler.CreateAccessibleObject(aShapeInfo, aShapeTreeInfo);
1114*cdf0e10cSrcweir 		    if (rShape.mpAccShape)
1115*cdf0e10cSrcweir             {
1116*cdf0e10cSrcweir 			    rShape.mpAccShape->acquire();
1117*cdf0e10cSrcweir                 rShape.mpAccShape->Init();
1118*cdf0e10cSrcweir             }
1119*cdf0e10cSrcweir         }
1120*cdf0e10cSrcweir 	}
1121*cdf0e10cSrcweir     return rShape.mpAccShape;
1122*cdf0e10cSrcweir }
1123*cdf0e10cSrcweir 
1124*cdf0e10cSrcweir ::accessibility::AccessibleShape* ScShapeChilds::GetAccShape(const ScShapeChildVec& rShapes, sal_Int32 nIndex) const
1125*cdf0e10cSrcweir {
1126*cdf0e10cSrcweir 	return (GetAccShape(rShapes[nIndex]));
1127*cdf0e10cSrcweir }
1128*cdf0e10cSrcweir 
1129*cdf0e10cSrcweir void ScShapeChilds::FillShapes(const Rectangle& aPixelPaintRect, const MapMode& aMapMode, sal_uInt8 nRangeId)
1130*cdf0e10cSrcweir {
1131*cdf0e10cSrcweir     DBG_ASSERT(nRangeId < maShapeRanges.size(), "this is not a valid range for draw objects");
1132*cdf0e10cSrcweir     SdrPage* pPage = GetDrawPage();
1133*cdf0e10cSrcweir     Window* pWin = mpViewShell->GetWindow();
1134*cdf0e10cSrcweir     if (pPage && pWin)
1135*cdf0e10cSrcweir     {
1136*cdf0e10cSrcweir         sal_Bool bForeAdded(sal_False);
1137*cdf0e10cSrcweir         sal_Bool bBackAdded(sal_False);
1138*cdf0e10cSrcweir         sal_Bool bControlAdded(sal_False);
1139*cdf0e10cSrcweir         Rectangle aClippedPixelPaintRect(aPixelPaintRect);
1140*cdf0e10cSrcweir         if (mpAccDoc)
1141*cdf0e10cSrcweir         {
1142*cdf0e10cSrcweir             Rectangle aRect2(Point(0,0), mpAccDoc->GetBoundingBoxOnScreen().GetSize());
1143*cdf0e10cSrcweir             aClippedPixelPaintRect = aPixelPaintRect.GetIntersection(aRect2);
1144*cdf0e10cSrcweir         }
1145*cdf0e10cSrcweir         maShapeRanges[nRangeId].maPixelRect = aClippedPixelPaintRect;
1146*cdf0e10cSrcweir         maShapeRanges[nRangeId].maMapMode = aMapMode;
1147*cdf0e10cSrcweir         ScIAccessibleViewForwarder aViewForwarder(mpViewShell, mpAccDoc, aMapMode);
1148*cdf0e10cSrcweir         maShapeRanges[nRangeId].maViewForwarder = aViewForwarder;
1149*cdf0e10cSrcweir         sal_uInt32 nCount(pPage->GetObjCount());
1150*cdf0e10cSrcweir         for (sal_uInt32 i = 0; i < nCount; ++i)
1151*cdf0e10cSrcweir         {
1152*cdf0e10cSrcweir             SdrObject* pObj = pPage->GetObj(i);
1153*cdf0e10cSrcweir             if (pObj)
1154*cdf0e10cSrcweir             {
1155*cdf0e10cSrcweir                 uno::Reference< drawing::XShape > xShape(pObj->getUnoShape(), uno::UNO_QUERY);
1156*cdf0e10cSrcweir                 if (xShape.is())
1157*cdf0e10cSrcweir                 {
1158*cdf0e10cSrcweir                     Rectangle aRect(pWin->LogicToPixel(VCLPoint(xShape->getPosition()), aMapMode), pWin->LogicToPixel(VCLSize(xShape->getSize()), aMapMode));
1159*cdf0e10cSrcweir                     if(!aClippedPixelPaintRect.GetIntersection(aRect).IsEmpty())
1160*cdf0e10cSrcweir                     {
1161*cdf0e10cSrcweir                         ScShapeChild aShape;
1162*cdf0e10cSrcweir                         aShape.mxShape = xShape;
1163*cdf0e10cSrcweir                         aShape.mnRangeId = nRangeId;
1164*cdf0e10cSrcweir                         switch (pObj->GetLayer())
1165*cdf0e10cSrcweir                         {
1166*cdf0e10cSrcweir                             case SC_LAYER_INTERN:
1167*cdf0e10cSrcweir                             case SC_LAYER_FRONT:
1168*cdf0e10cSrcweir                             {
1169*cdf0e10cSrcweir                                 maShapeRanges[nRangeId].maForeShapes.push_back(aShape);
1170*cdf0e10cSrcweir                                 bForeAdded = sal_True;
1171*cdf0e10cSrcweir                             }
1172*cdf0e10cSrcweir                             break;
1173*cdf0e10cSrcweir                             case SC_LAYER_BACK:
1174*cdf0e10cSrcweir                             {
1175*cdf0e10cSrcweir                                 maShapeRanges[nRangeId].maBackShapes.push_back(aShape);
1176*cdf0e10cSrcweir                                 bBackAdded = sal_True;
1177*cdf0e10cSrcweir                             }
1178*cdf0e10cSrcweir                             break;
1179*cdf0e10cSrcweir                             case SC_LAYER_CONTROLS:
1180*cdf0e10cSrcweir                             {
1181*cdf0e10cSrcweir                                 maShapeRanges[nRangeId].maControls.push_back(aShape);
1182*cdf0e10cSrcweir                                 bControlAdded = sal_True;
1183*cdf0e10cSrcweir                             }
1184*cdf0e10cSrcweir                             break;
1185*cdf0e10cSrcweir                             default:
1186*cdf0e10cSrcweir                             {
1187*cdf0e10cSrcweir                                 DBG_ERRORFILE("I don't know this layer.");
1188*cdf0e10cSrcweir                             }
1189*cdf0e10cSrcweir                             break;
1190*cdf0e10cSrcweir                         }
1191*cdf0e10cSrcweir                     }
1192*cdf0e10cSrcweir                 }
1193*cdf0e10cSrcweir             }
1194*cdf0e10cSrcweir         }
1195*cdf0e10cSrcweir         if (bForeAdded)
1196*cdf0e10cSrcweir             std::sort(maShapeRanges[nRangeId].maForeShapes.begin(), maShapeRanges[nRangeId].maForeShapes.end(),ScShapeChildLess());
1197*cdf0e10cSrcweir         if (bBackAdded)
1198*cdf0e10cSrcweir             std::sort(maShapeRanges[nRangeId].maBackShapes.begin(), maShapeRanges[nRangeId].maBackShapes.end(),ScShapeChildLess());
1199*cdf0e10cSrcweir         if (bControlAdded)
1200*cdf0e10cSrcweir             std::sort(maShapeRanges[nRangeId].maControls.begin(), maShapeRanges[nRangeId].maControls.end(),ScShapeChildLess());
1201*cdf0e10cSrcweir     }
1202*cdf0e10cSrcweir }
1203*cdf0e10cSrcweir 
1204*cdf0e10cSrcweir //UNUSED2008-05  sal_Bool ScShapeChilds::FindShape(ScShapeChildVec& rShapes, const uno::Reference <drawing::XShape>& xShape, ScShapeChildVec::iterator& rItr) const
1205*cdf0e10cSrcweir //UNUSED2008-05  {
1206*cdf0e10cSrcweir //UNUSED2008-05      sal_Bool bResult(sal_False);
1207*cdf0e10cSrcweir //UNUSED2008-05      ScShapeChild aShape;
1208*cdf0e10cSrcweir //UNUSED2008-05      aShape.mxShape = xShape;
1209*cdf0e10cSrcweir //UNUSED2008-05      rItr = std::lower_bound(rShapes.begin(), rShapes.end(), aShape, ScShapeChildLess());
1210*cdf0e10cSrcweir //UNUSED2008-05      if (rItr->mxShape.get() == xShape.get())
1211*cdf0e10cSrcweir //UNUSED2008-05          bResult = sal_True; // if the shape is found
1212*cdf0e10cSrcweir //UNUSED2008-05
1213*cdf0e10cSrcweir //UNUSED2008-05  /*#ifdef DBG_UTIL // test whether it finds truly the correct shape (perhaps it is not really sorted)
1214*cdf0e10cSrcweir //UNUSED2008-05      ScShapeChildVec::iterator aDebugItr = std::find(rShapes.begin(), rShapes.end(), aShape);
1215*cdf0e10cSrcweir //UNUSED2008-05      DBG_ASSERT(rItr == aDebugItr, "wrong Shape found");
1216*cdf0e10cSrcweir //UNUSED2008-05  #endif*/
1217*cdf0e10cSrcweir //UNUSED2008-05      return bResult;
1218*cdf0e10cSrcweir //UNUSED2008-05  }
1219*cdf0e10cSrcweir 
1220*cdf0e10cSrcweir /*void ScShapeChilds::AddShape(const uno::Reference<drawing::XShape>& xShape, SdrLayerID aLayerID)
1221*cdf0e10cSrcweir {
1222*cdf0e10cSrcweir     uno::Reference < XAccessible > xNew;
1223*cdf0e10cSrcweir     Window* pWin = mpViewShell->GetWindow();
1224*cdf0e10cSrcweir     if (pWin)
1225*cdf0e10cSrcweir     {
1226*cdf0e10cSrcweir         ScShapeRangeVec::iterator aEndItr = maShapeRanges.end();
1227*cdf0e10cSrcweir         ScShapeRangeVec::iterator aItr = maShapeRanges.begin();
1228*cdf0e10cSrcweir         sal_Bool bNotify(sal_False);
1229*cdf0e10cSrcweir         uno::Reference <XAccessible> xAcc;
1230*cdf0e10cSrcweir         while (aItr != aEndItr)
1231*cdf0e10cSrcweir         {
1232*cdf0e10cSrcweir             Rectangle aLogicPaintRect(pWin->PixelToLogic(aItr->maPixelRect, aItr->maMapMode));
1233*cdf0e10cSrcweir             Rectangle aRect(VCLPoint(xShape->getPosition()), VCLSize(xShape->getSize()));
1234*cdf0e10cSrcweir             if(!aRect.GetIntersection(aLogicPaintRect).IsEmpty())
1235*cdf0e10cSrcweir             {
1236*cdf0e10cSrcweir                 ScShapeChild aShape;
1237*cdf0e10cSrcweir                 aShape.mxShape = xShape;
1238*cdf0e10cSrcweir                 switch (aLayerID)
1239*cdf0e10cSrcweir                 {
1240*cdf0e10cSrcweir                     case SC_LAYER_INTERN:
1241*cdf0e10cSrcweir                     case SC_LAYER_FRONT:
1242*cdf0e10cSrcweir                     {
1243*cdf0e10cSrcweir                         SetAnchor(aShape);
1244*cdf0e10cSrcweir                         aItr->maForeShapes.push_back(aShape);
1245*cdf0e10cSrcweir                         std::sort(aItr->maForeShapes.begin(), aItr->maForeShapes.end(),ScShapeChildLess());
1246*cdf0e10cSrcweir 
1247*cdf0e10cSrcweir                     }
1248*cdf0e10cSrcweir                     break;
1249*cdf0e10cSrcweir                     case SC_LAYER_BACK:
1250*cdf0e10cSrcweir                     {
1251*cdf0e10cSrcweir                         aItr->maBackShapes.push_back(aShape);
1252*cdf0e10cSrcweir                         std::sort(aItr->maBackShapes.begin(), aItr->maBackShapes.end(),ScShapeChildLess());
1253*cdf0e10cSrcweir                     }
1254*cdf0e10cSrcweir                     break;
1255*cdf0e10cSrcweir                     case SC_LAYER_CONTROLS:
1256*cdf0e10cSrcweir                     {
1257*cdf0e10cSrcweir                         SetAnchor(aShape);
1258*cdf0e10cSrcweir                         aItr->maControls.push_back(aShape);
1259*cdf0e10cSrcweir                         std::sort(aItr->maControls.begin(), aItr->maControls.end(),ScShapeChildLess());
1260*cdf0e10cSrcweir                     }
1261*cdf0e10cSrcweir                     break;
1262*cdf0e10cSrcweir                     default:
1263*cdf0e10cSrcweir                     {
1264*cdf0e10cSrcweir                         DBG_ERRORFILE("I don't know this layer.");
1265*cdf0e10cSrcweir                     }
1266*cdf0e10cSrcweir                     break;
1267*cdf0e10cSrcweir                 }
1268*cdf0e10cSrcweir                 if (bNotify)
1269*cdf0e10cSrcweir                 {
1270*cdf0e10cSrcweir                     xAcc = GetAccShape(aShape);
1271*cdf0e10cSrcweir                     AccessibleEventObject aEvent;
1272*cdf0e10cSrcweir                     aEvent.Source = uno::Reference<XAccessibleContext> (mpAccDoc);
1273*cdf0e10cSrcweir                     aEvent.EventId = AccessibleEventId::CHILD;
1274*cdf0e10cSrcweir                     aEvent.NewValue <<= xAcc;
1275*cdf0e10cSrcweir                     mpAccDoc->CommitChange(aEvent);
1276*cdf0e10cSrcweir                     bNotify = sal_False;
1277*cdf0e10cSrcweir                 }
1278*cdf0e10cSrcweir                 xAcc = NULL;
1279*cdf0e10cSrcweir             }
1280*cdf0e10cSrcweir             ++aItr;
1281*cdf0e10cSrcweir         }
1282*cdf0e10cSrcweir     }
1283*cdf0e10cSrcweir }*/
1284*cdf0e10cSrcweir 
1285*cdf0e10cSrcweir /*sal_Bool HaveToNotify(uno::Reference<XAccessible>& xAcc, ScShapeChildVec::iterator aItr)
1286*cdf0e10cSrcweir {
1287*cdf0e10cSrcweir     sal_Bool bResult(sal_False);
1288*cdf0e10cSrcweir     if (aItr->mpAccShape)
1289*cdf0e10cSrcweir     {
1290*cdf0e10cSrcweir         bResult = sal_True;
1291*cdf0e10cSrcweir         xAcc = aItr->mpAccShape;
1292*cdf0e10cSrcweir     }
1293*cdf0e10cSrcweir     else
1294*cdf0e10cSrcweir         DBG_ERRORFILE("No Accessible object found. Don't know how to notify.");
1295*cdf0e10cSrcweir     return bResult;
1296*cdf0e10cSrcweir }*/
1297*cdf0e10cSrcweir 
1298*cdf0e10cSrcweir /*void ScShapeChilds::RemoveShape(const uno::Reference<drawing::XShape>& xShape, SdrLayerID aLayerID)
1299*cdf0e10cSrcweir {
1300*cdf0e10cSrcweir     ScShapeRangeVec::iterator aEndItr = maShapeRanges.end();
1301*cdf0e10cSrcweir     ScShapeRangeVec::iterator aItr = maShapeRanges.begin();
1302*cdf0e10cSrcweir     ScShapeChildVec::iterator aEraseItr;
1303*cdf0e10cSrcweir     sal_Bool bNotify(sal_False);
1304*cdf0e10cSrcweir     uno::Reference <XAccessible> xAcc;
1305*cdf0e10cSrcweir     while (aItr != aEndItr)
1306*cdf0e10cSrcweir     {
1307*cdf0e10cSrcweir         switch (aLayerID)
1308*cdf0e10cSrcweir         {
1309*cdf0e10cSrcweir             case SC_LAYER_INTERN:
1310*cdf0e10cSrcweir             case SC_LAYER_FRONT:
1311*cdf0e10cSrcweir             {
1312*cdf0e10cSrcweir                 if (FindShape(aItr->maForeShapes, xShape, aEraseItr))
1313*cdf0e10cSrcweir                 {
1314*cdf0e10cSrcweir                     bNotify = HaveToNotify(xAcc, aEraseItr);
1315*cdf0e10cSrcweir                     aItr->maForeShapes.erase(aEraseItr);
1316*cdf0e10cSrcweir                 }
1317*cdf0e10cSrcweir             }
1318*cdf0e10cSrcweir             break;
1319*cdf0e10cSrcweir             case SC_LAYER_BACK:
1320*cdf0e10cSrcweir             {
1321*cdf0e10cSrcweir                 if (FindShape(aItr->maBackShapes, xShape, aEraseItr))
1322*cdf0e10cSrcweir                 {
1323*cdf0e10cSrcweir                     bNotify = HaveToNotify(xAcc, aEraseItr);
1324*cdf0e10cSrcweir                     aItr->maBackShapes.erase(aEraseItr);
1325*cdf0e10cSrcweir                 }
1326*cdf0e10cSrcweir             }
1327*cdf0e10cSrcweir             break;
1328*cdf0e10cSrcweir             case SC_LAYER_CONTROLS:
1329*cdf0e10cSrcweir             {
1330*cdf0e10cSrcweir                 if (FindShape(aItr->maControls, xShape, aEraseItr))
1331*cdf0e10cSrcweir                 {
1332*cdf0e10cSrcweir                     bNotify = HaveToNotify(xAcc, aEraseItr);
1333*cdf0e10cSrcweir                     aItr->maControls.erase(aEraseItr);
1334*cdf0e10cSrcweir                 }
1335*cdf0e10cSrcweir             }
1336*cdf0e10cSrcweir             break;
1337*cdf0e10cSrcweir             default:
1338*cdf0e10cSrcweir             {
1339*cdf0e10cSrcweir                 DBG_ERRORFILE("I don't know this layer.");
1340*cdf0e10cSrcweir             }
1341*cdf0e10cSrcweir             break;
1342*cdf0e10cSrcweir         }
1343*cdf0e10cSrcweir         if (bNotify)
1344*cdf0e10cSrcweir         {
1345*cdf0e10cSrcweir             AccessibleEventObject aEvent;
1346*cdf0e10cSrcweir             aEvent.Source = uno::Reference<XAccessibleContext> (mpAccDoc);
1347*cdf0e10cSrcweir             aEvent.EventId = AccessibleEventId::CHILD;
1348*cdf0e10cSrcweir             aEvent.OldValue <<= xAcc;
1349*cdf0e10cSrcweir             mpAccDoc->CommitChange(aEvent);
1350*cdf0e10cSrcweir             bNotify = sal_False;
1351*cdf0e10cSrcweir         }
1352*cdf0e10cSrcweir         xAcc = NULL;
1353*cdf0e10cSrcweir         ++aItr;
1354*cdf0e10cSrcweir     }
1355*cdf0e10cSrcweir }*/
1356*cdf0e10cSrcweir 
1357*cdf0e10cSrcweir SdrPage* ScShapeChilds::GetDrawPage() const
1358*cdf0e10cSrcweir {
1359*cdf0e10cSrcweir 	SCTAB nTab( mpViewShell->GetLocationData().GetPrintTab() );
1360*cdf0e10cSrcweir 	SdrPage* pDrawPage = NULL;
1361*cdf0e10cSrcweir 	if (mpViewShell)
1362*cdf0e10cSrcweir 	{
1363*cdf0e10cSrcweir 		ScDocument* pDoc = mpViewShell->GetDocument();
1364*cdf0e10cSrcweir 		if (pDoc && pDoc->GetDrawLayer())
1365*cdf0e10cSrcweir 		{
1366*cdf0e10cSrcweir 			ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1367*cdf0e10cSrcweir 			if (pDrawLayer->HasObjects() && (pDrawLayer->GetPageCount() > nTab))
1368*cdf0e10cSrcweir 				pDrawPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(static_cast<sal_Int16>(nTab)));
1369*cdf0e10cSrcweir 		}
1370*cdf0e10cSrcweir 	}
1371*cdf0e10cSrcweir 	return pDrawPage;
1372*cdf0e10cSrcweir }
1373*cdf0e10cSrcweir 
1374*cdf0e10cSrcweir struct ScPagePreviewCountData
1375*cdf0e10cSrcweir {
1376*cdf0e10cSrcweir 	//	order is background shapes, header, table or notes, footer, foreground shapes, controls
1377*cdf0e10cSrcweir 
1378*cdf0e10cSrcweir     Rectangle aVisRect;
1379*cdf0e10cSrcweir 	long nBackShapes;
1380*cdf0e10cSrcweir 	long nHeaders;
1381*cdf0e10cSrcweir 	long nTables;
1382*cdf0e10cSrcweir     long nNoteParagraphs;
1383*cdf0e10cSrcweir 	long nFooters;
1384*cdf0e10cSrcweir 	long nForeShapes;
1385*cdf0e10cSrcweir 	long nControls;
1386*cdf0e10cSrcweir 
1387*cdf0e10cSrcweir 	ScPagePreviewCountData( const ScPreviewLocationData& rData, Window* pSizeWindow,
1388*cdf0e10cSrcweir         ScNotesChilds* pNotesChilds, ScShapeChilds* pShapeChilds );
1389*cdf0e10cSrcweir 
1390*cdf0e10cSrcweir 	long GetTotal() const
1391*cdf0e10cSrcweir 	{
1392*cdf0e10cSrcweir 		return nBackShapes + nHeaders + nTables + nNoteParagraphs + nFooters + nForeShapes + nControls;
1393*cdf0e10cSrcweir 	}
1394*cdf0e10cSrcweir };
1395*cdf0e10cSrcweir 
1396*cdf0e10cSrcweir ScPagePreviewCountData::ScPagePreviewCountData( const ScPreviewLocationData& rData,
1397*cdf0e10cSrcweir                                 Window* pSizeWindow, ScNotesChilds* pNotesChilds,
1398*cdf0e10cSrcweir                                 ScShapeChilds* pShapeChilds) :
1399*cdf0e10cSrcweir 	nBackShapes( 0 ),
1400*cdf0e10cSrcweir 	nHeaders( 0 ),
1401*cdf0e10cSrcweir 	nTables( 0 ),
1402*cdf0e10cSrcweir     nNoteParagraphs( 0 ),
1403*cdf0e10cSrcweir 	nFooters( 0 ),
1404*cdf0e10cSrcweir 	nForeShapes( 0 ),
1405*cdf0e10cSrcweir 	nControls( 0 )
1406*cdf0e10cSrcweir {
1407*cdf0e10cSrcweir 	Size aOutputSize;
1408*cdf0e10cSrcweir 	if ( pSizeWindow )
1409*cdf0e10cSrcweir 		aOutputSize = pSizeWindow->GetOutputSizePixel();
1410*cdf0e10cSrcweir     Point aPoint;
1411*cdf0e10cSrcweir 	aVisRect = Rectangle( aPoint, aOutputSize );
1412*cdf0e10cSrcweir 
1413*cdf0e10cSrcweir 	Rectangle aObjRect;
1414*cdf0e10cSrcweir 
1415*cdf0e10cSrcweir 	if ( rData.GetHeaderPosition( aObjRect ) && aObjRect.IsOver( aVisRect ) )
1416*cdf0e10cSrcweir 		nHeaders = 1;
1417*cdf0e10cSrcweir 
1418*cdf0e10cSrcweir 	if ( rData.GetFooterPosition( aObjRect ) && aObjRect.IsOver( aVisRect ) )
1419*cdf0e10cSrcweir 		nFooters = 1;
1420*cdf0e10cSrcweir 
1421*cdf0e10cSrcweir 	if ( rData.HasCellsInRange( aVisRect ) )
1422*cdf0e10cSrcweir 		nTables = 1;
1423*cdf0e10cSrcweir 
1424*cdf0e10cSrcweir 	//!	shapes...
1425*cdf0e10cSrcweir     nBackShapes = pShapeChilds->GetBackShapeCount();
1426*cdf0e10cSrcweir     nForeShapes = pShapeChilds->GetForeShapeCount();
1427*cdf0e10cSrcweir     nControls = pShapeChilds->GetControlCount();
1428*cdf0e10cSrcweir 
1429*cdf0e10cSrcweir     // there are only notes if there is no table
1430*cdf0e10cSrcweir     if (nTables == 0)
1431*cdf0e10cSrcweir         nNoteParagraphs = pNotesChilds->GetChildsCount();
1432*cdf0e10cSrcweir }
1433*cdf0e10cSrcweir 
1434*cdf0e10cSrcweir //=====  internal  ========================================================
1435*cdf0e10cSrcweir 
1436*cdf0e10cSrcweir ScAccessibleDocumentPagePreview::ScAccessibleDocumentPagePreview(
1437*cdf0e10cSrcweir         const uno::Reference<XAccessible>& rxParent, ScPreviewShell* pViewShell ) :
1438*cdf0e10cSrcweir 	ScAccessibleDocumentBase(rxParent),
1439*cdf0e10cSrcweir 	mpViewShell(pViewShell),
1440*cdf0e10cSrcweir 	mpNotesChilds(NULL),
1441*cdf0e10cSrcweir     mpShapeChilds(NULL),
1442*cdf0e10cSrcweir     mpTable(NULL),
1443*cdf0e10cSrcweir     mpHeader(NULL),
1444*cdf0e10cSrcweir     mpFooter(NULL)
1445*cdf0e10cSrcweir {
1446*cdf0e10cSrcweir 	if (pViewShell)
1447*cdf0e10cSrcweir 		pViewShell->AddAccessibilityObject(*this);
1448*cdf0e10cSrcweir 
1449*cdf0e10cSrcweir //    GetNotesChilds(); not neccessary and reduces the creation performance
1450*cdf0e10cSrcweir //    GetShapeChilds();
1451*cdf0e10cSrcweir }
1452*cdf0e10cSrcweir 
1453*cdf0e10cSrcweir ScAccessibleDocumentPagePreview::~ScAccessibleDocumentPagePreview(void)
1454*cdf0e10cSrcweir {
1455*cdf0e10cSrcweir 	if (!ScAccessibleDocumentBase::IsDefunc() && !rBHelper.bInDispose)
1456*cdf0e10cSrcweir 	{
1457*cdf0e10cSrcweir 		// increment refcount to prevent double call off dtor
1458*cdf0e10cSrcweir 		osl_incrementInterlockedCount( &m_refCount );
1459*cdf0e10cSrcweir 		// call dispose to inform object wich have a weak reference to this object
1460*cdf0e10cSrcweir 		dispose();
1461*cdf0e10cSrcweir 	}
1462*cdf0e10cSrcweir }
1463*cdf0e10cSrcweir 
1464*cdf0e10cSrcweir void SAL_CALL ScAccessibleDocumentPagePreview::disposing()
1465*cdf0e10cSrcweir {
1466*cdf0e10cSrcweir     ScUnoGuard aGuard;
1467*cdf0e10cSrcweir     if (mpTable)
1468*cdf0e10cSrcweir     {
1469*cdf0e10cSrcweir 	    mpTable->release();
1470*cdf0e10cSrcweir         mpTable = NULL;
1471*cdf0e10cSrcweir     }
1472*cdf0e10cSrcweir     if (mpHeader)
1473*cdf0e10cSrcweir     {
1474*cdf0e10cSrcweir 	    mpHeader->release();
1475*cdf0e10cSrcweir         mpHeader = NULL;
1476*cdf0e10cSrcweir     }
1477*cdf0e10cSrcweir     if (mpFooter)
1478*cdf0e10cSrcweir     {
1479*cdf0e10cSrcweir 	    mpFooter->release();
1480*cdf0e10cSrcweir         mpFooter = NULL;
1481*cdf0e10cSrcweir     }
1482*cdf0e10cSrcweir 
1483*cdf0e10cSrcweir 	if (mpViewShell)
1484*cdf0e10cSrcweir 	{
1485*cdf0e10cSrcweir 		mpViewShell->RemoveAccessibilityObject(*this);
1486*cdf0e10cSrcweir 		mpViewShell = NULL;
1487*cdf0e10cSrcweir 	}
1488*cdf0e10cSrcweir 
1489*cdf0e10cSrcweir     // #100593# no need to Dispose the AccessibleTextHelper,
1490*cdf0e10cSrcweir     // as long as mpNotesChilds are destructed here
1491*cdf0e10cSrcweir 	if (mpNotesChilds)
1492*cdf0e10cSrcweir 	    DELETEZ(mpNotesChilds);
1493*cdf0e10cSrcweir 
1494*cdf0e10cSrcweir     if (mpShapeChilds)
1495*cdf0e10cSrcweir         DELETEZ(mpShapeChilds);
1496*cdf0e10cSrcweir 
1497*cdf0e10cSrcweir 	ScAccessibleDocumentBase::disposing();
1498*cdf0e10cSrcweir }
1499*cdf0e10cSrcweir 
1500*cdf0e10cSrcweir //=====  SfxListener  =====================================================
1501*cdf0e10cSrcweir 
1502*cdf0e10cSrcweir void ScAccessibleDocumentPagePreview::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1503*cdf0e10cSrcweir {
1504*cdf0e10cSrcweir 	if (rHint.ISA( SfxSimpleHint ) )
1505*cdf0e10cSrcweir 	{
1506*cdf0e10cSrcweir 		const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
1507*cdf0e10cSrcweir 		// only notify if child exist, otherwise it is not necessary
1508*cdf0e10cSrcweir 		if ((rRef.GetId() == SC_HINT_DATACHANGED))
1509*cdf0e10cSrcweir         {
1510*cdf0e10cSrcweir             if (mpTable) // if there is no table there is nothing to notify, because no one recongnizes the change
1511*cdf0e10cSrcweir             {
1512*cdf0e10cSrcweir                 {
1513*cdf0e10cSrcweir                     uno::Reference<XAccessible> xAcc = mpTable;
1514*cdf0e10cSrcweir                     AccessibleEventObject aEvent;
1515*cdf0e10cSrcweir                     aEvent.EventId = AccessibleEventId::CHILD;
1516*cdf0e10cSrcweir 					aEvent.Source = uno::Reference< XAccessibleContext >(this);
1517*cdf0e10cSrcweir                     aEvent.OldValue <<= xAcc;
1518*cdf0e10cSrcweir                     CommitChange(aEvent);
1519*cdf0e10cSrcweir                 }
1520*cdf0e10cSrcweir 
1521*cdf0e10cSrcweir                 mpTable->dispose();
1522*cdf0e10cSrcweir                 mpTable->release();
1523*cdf0e10cSrcweir                 mpTable = NULL;
1524*cdf0e10cSrcweir             }
1525*cdf0e10cSrcweir 
1526*cdf0e10cSrcweir 	        Size aOutputSize;
1527*cdf0e10cSrcweir             Window* pSizeWindow = mpViewShell->GetWindow();
1528*cdf0e10cSrcweir 	        if ( pSizeWindow )
1529*cdf0e10cSrcweir 		        aOutputSize = pSizeWindow->GetOutputSizePixel();
1530*cdf0e10cSrcweir             Point aPoint;
1531*cdf0e10cSrcweir 	        Rectangle aVisRect( aPoint, aOutputSize );
1532*cdf0e10cSrcweir             GetNotesChilds()->DataChanged(aVisRect);
1533*cdf0e10cSrcweir 
1534*cdf0e10cSrcweir             GetShapeChilds()->DataChanged();
1535*cdf0e10cSrcweir 
1536*cdf0e10cSrcweir             const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
1537*cdf0e10cSrcweir 		    ScPagePreviewCountData aCount( rData, mpViewShell->GetWindow(), GetNotesChilds(), GetShapeChilds() );
1538*cdf0e10cSrcweir 
1539*cdf0e10cSrcweir             if (aCount.nTables > 0)
1540*cdf0e10cSrcweir             {
1541*cdf0e10cSrcweir 				//!	order is background shapes, header, table or notes, footer, foreground shapes, controls
1542*cdf0e10cSrcweir 				sal_Int32 nIndex (aCount.nBackShapes + aCount.nHeaders);
1543*cdf0e10cSrcweir 
1544*cdf0e10cSrcweir 				mpTable = new ScAccessiblePreviewTable( this, mpViewShell, nIndex );
1545*cdf0e10cSrcweir                 mpTable->acquire();
1546*cdf0e10cSrcweir 				mpTable->Init();
1547*cdf0e10cSrcweir 
1548*cdf0e10cSrcweir                 {
1549*cdf0e10cSrcweir                     uno::Reference<XAccessible> xAcc = mpTable;
1550*cdf0e10cSrcweir                     AccessibleEventObject aEvent;
1551*cdf0e10cSrcweir                     aEvent.EventId = AccessibleEventId::CHILD;
1552*cdf0e10cSrcweir 					aEvent.Source = uno::Reference< XAccessibleContext >(this);
1553*cdf0e10cSrcweir                     aEvent.NewValue <<= xAcc;
1554*cdf0e10cSrcweir                     CommitChange(aEvent);
1555*cdf0e10cSrcweir                 }
1556*cdf0e10cSrcweir             }
1557*cdf0e10cSrcweir         }
1558*cdf0e10cSrcweir         else if (rRef.GetId() == SC_HINT_ACC_MAKEDRAWLAYER)
1559*cdf0e10cSrcweir         {
1560*cdf0e10cSrcweir             GetShapeChilds()->SetDrawBroadcaster();
1561*cdf0e10cSrcweir         }
1562*cdf0e10cSrcweir         else if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
1563*cdf0e10cSrcweir         {
1564*cdf0e10cSrcweir 	        Size aOutputSize;
1565*cdf0e10cSrcweir             Window* pSizeWindow = mpViewShell->GetWindow();
1566*cdf0e10cSrcweir 	        if ( pSizeWindow )
1567*cdf0e10cSrcweir 		        aOutputSize = pSizeWindow->GetOutputSizePixel();
1568*cdf0e10cSrcweir             Point aPoint;
1569*cdf0e10cSrcweir 	        Rectangle aVisRect( aPoint, aOutputSize );
1570*cdf0e10cSrcweir             GetNotesChilds()->DataChanged(aVisRect);
1571*cdf0e10cSrcweir 
1572*cdf0e10cSrcweir             GetShapeChilds()->VisAreaChanged();
1573*cdf0e10cSrcweir 
1574*cdf0e10cSrcweir             AccessibleEventObject aEvent;
1575*cdf0e10cSrcweir             aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
1576*cdf0e10cSrcweir 			aEvent.Source = uno::Reference< XAccessibleContext >(this);
1577*cdf0e10cSrcweir             CommitChange(aEvent);
1578*cdf0e10cSrcweir         }
1579*cdf0e10cSrcweir     }
1580*cdf0e10cSrcweir     else if ( rHint.ISA(ScAccWinFocusLostHint) )
1581*cdf0e10cSrcweir     {
1582*cdf0e10cSrcweir         CommitFocusLost();
1583*cdf0e10cSrcweir     }
1584*cdf0e10cSrcweir     else if ( rHint.ISA(ScAccWinFocusGotHint) )
1585*cdf0e10cSrcweir     {
1586*cdf0e10cSrcweir         CommitFocusGained();
1587*cdf0e10cSrcweir     }
1588*cdf0e10cSrcweir 	ScAccessibleDocumentBase::Notify(rBC, rHint);
1589*cdf0e10cSrcweir }
1590*cdf0e10cSrcweir 
1591*cdf0e10cSrcweir //=====  XAccessibleComponent  ============================================
1592*cdf0e10cSrcweir 
1593*cdf0e10cSrcweir uno::Reference< XAccessible > SAL_CALL ScAccessibleDocumentPagePreview::getAccessibleAtPoint( const awt::Point& rPoint )
1594*cdf0e10cSrcweir 								throw (uno::RuntimeException)
1595*cdf0e10cSrcweir {
1596*cdf0e10cSrcweir 	uno::Reference<XAccessible> xAccessible;
1597*cdf0e10cSrcweir     if (containsPoint(rPoint))
1598*cdf0e10cSrcweir     {
1599*cdf0e10cSrcweir 	    ScUnoGuard aGuard;
1600*cdf0e10cSrcweir         IsObjectValid();
1601*cdf0e10cSrcweir 
1602*cdf0e10cSrcweir 	    if ( mpViewShell )
1603*cdf0e10cSrcweir 	    {
1604*cdf0e10cSrcweir             xAccessible = GetShapeChilds()->GetForegroundShapeAt(rPoint);
1605*cdf0e10cSrcweir             if (!xAccessible.is())
1606*cdf0e10cSrcweir             {
1607*cdf0e10cSrcweir 		        const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
1608*cdf0e10cSrcweir 		        ScPagePreviewCountData aCount( rData, mpViewShell->GetWindow(), GetNotesChilds(), GetShapeChilds() );
1609*cdf0e10cSrcweir 
1610*cdf0e10cSrcweir /*		        if ( rData.HasCellsInRange( Rectangle( rPoint, rPoint ) ) )
1611*cdf0e10cSrcweir 		        {
1612*cdf0e10cSrcweir 			        if ( !mpTable && (aCount.nTables > 0) )
1613*cdf0e10cSrcweir 			        {
1614*cdf0e10cSrcweir 				        //!	order is background shapes, header, table or notes, footer, foreground shapes, controls
1615*cdf0e10cSrcweir 				        sal_Int32 nIndex (aCount.nBackShapes + aCount.nHeaders);
1616*cdf0e10cSrcweir 
1617*cdf0e10cSrcweir 				        mpTable = new ScAccessiblePreviewTable( this, mpViewShell, nIndex );
1618*cdf0e10cSrcweir                         mpTable->acquire();
1619*cdf0e10cSrcweir 				        mpTable->Init();
1620*cdf0e10cSrcweir 			        }
1621*cdf0e10cSrcweir 			        xAccessible = mpTable;
1622*cdf0e10cSrcweir 		        }*/
1623*cdf0e10cSrcweir 			    if ( !mpTable && (aCount.nTables > 0) )
1624*cdf0e10cSrcweir 			    {
1625*cdf0e10cSrcweir 				    //!	order is background shapes, header, table or notes, footer, foreground shapes, controls
1626*cdf0e10cSrcweir 				    sal_Int32 nIndex (aCount.nBackShapes + aCount.nHeaders);
1627*cdf0e10cSrcweir 
1628*cdf0e10cSrcweir 				    mpTable = new ScAccessiblePreviewTable( this, mpViewShell, nIndex );
1629*cdf0e10cSrcweir                     mpTable->acquire();
1630*cdf0e10cSrcweir 				    mpTable->Init();
1631*cdf0e10cSrcweir 			    }
1632*cdf0e10cSrcweir                 if (mpTable && VCLRectangle(mpTable->getBounds()).IsInside(VCLPoint(rPoint)))
1633*cdf0e10cSrcweir 			        xAccessible = mpTable;
1634*cdf0e10cSrcweir             }
1635*cdf0e10cSrcweir             if (!xAccessible.is())
1636*cdf0e10cSrcweir                 xAccessible = GetNotesChilds()->GetAt(rPoint);
1637*cdf0e10cSrcweir             if (!xAccessible.is())
1638*cdf0e10cSrcweir             {
1639*cdf0e10cSrcweir 	            if (!mpHeader || !mpFooter)
1640*cdf0e10cSrcweir                 {
1641*cdf0e10cSrcweir 		            const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
1642*cdf0e10cSrcweir 		            ScPagePreviewCountData aCount( rData, mpViewShell->GetWindow(), GetNotesChilds(), GetShapeChilds() );
1643*cdf0e10cSrcweir 
1644*cdf0e10cSrcweir                     if (!mpHeader)
1645*cdf0e10cSrcweir                     {
1646*cdf0e10cSrcweir                         mpHeader = new ScAccessiblePageHeader( this, mpViewShell, sal_True, aCount.nBackShapes + aCount.nHeaders - 1);
1647*cdf0e10cSrcweir                         mpHeader->acquire();
1648*cdf0e10cSrcweir                     }
1649*cdf0e10cSrcweir                     if (!mpFooter)
1650*cdf0e10cSrcweir                     {
1651*cdf0e10cSrcweir                         mpFooter = new ScAccessiblePageHeader( this, mpViewShell, sal_False, aCount.nBackShapes + aCount.nHeaders + aCount.nTables + aCount.nNoteParagraphs + aCount.nFooters - 1 );
1652*cdf0e10cSrcweir                         mpFooter->acquire();
1653*cdf0e10cSrcweir                     }
1654*cdf0e10cSrcweir                 }
1655*cdf0e10cSrcweir 
1656*cdf0e10cSrcweir                 Point aPoint(VCLPoint(rPoint));
1657*cdf0e10cSrcweir 
1658*cdf0e10cSrcweir                 if (VCLRectangle(mpHeader->getBounds()).IsInside(aPoint))
1659*cdf0e10cSrcweir                     xAccessible = mpHeader;
1660*cdf0e10cSrcweir                 else if (VCLRectangle(mpFooter->getBounds()).IsInside(aPoint))
1661*cdf0e10cSrcweir                     xAccessible = mpFooter;
1662*cdf0e10cSrcweir             }
1663*cdf0e10cSrcweir             if (!xAccessible.is())
1664*cdf0e10cSrcweir                 xAccessible = GetShapeChilds()->GetBackgroundShapeAt(rPoint);
1665*cdf0e10cSrcweir 	    }
1666*cdf0e10cSrcweir     }
1667*cdf0e10cSrcweir 
1668*cdf0e10cSrcweir 	return xAccessible;
1669*cdf0e10cSrcweir }
1670*cdf0e10cSrcweir 
1671*cdf0e10cSrcweir void SAL_CALL ScAccessibleDocumentPagePreview::grabFocus() throw (uno::RuntimeException)
1672*cdf0e10cSrcweir {
1673*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1674*cdf0e10cSrcweir     IsObjectValid();
1675*cdf0e10cSrcweir 	if (getAccessibleParent().is())
1676*cdf0e10cSrcweir 	{
1677*cdf0e10cSrcweir 		uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
1678*cdf0e10cSrcweir 		if (xAccessibleComponent.is())
1679*cdf0e10cSrcweir 		{
1680*cdf0e10cSrcweir 			// just grab the focus for the window
1681*cdf0e10cSrcweir 			xAccessibleComponent->grabFocus();
1682*cdf0e10cSrcweir 		}
1683*cdf0e10cSrcweir 	}
1684*cdf0e10cSrcweir }
1685*cdf0e10cSrcweir 
1686*cdf0e10cSrcweir //=====  XAccessibleContext  ==============================================
1687*cdf0e10cSrcweir 
1688*cdf0e10cSrcweir sal_Int32 SAL_CALL ScAccessibleDocumentPagePreview::getAccessibleChildCount(void) throw (uno::RuntimeException)
1689*cdf0e10cSrcweir {
1690*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1691*cdf0e10cSrcweir     IsObjectValid();
1692*cdf0e10cSrcweir 
1693*cdf0e10cSrcweir 	long nRet = 0;
1694*cdf0e10cSrcweir 	if ( mpViewShell )
1695*cdf0e10cSrcweir 	{
1696*cdf0e10cSrcweir 		ScPagePreviewCountData aCount( mpViewShell->GetLocationData(), mpViewShell->GetWindow(), GetNotesChilds(), GetShapeChilds() );
1697*cdf0e10cSrcweir 		nRet = aCount.GetTotal();
1698*cdf0e10cSrcweir 	}
1699*cdf0e10cSrcweir 
1700*cdf0e10cSrcweir 	return nRet;
1701*cdf0e10cSrcweir }
1702*cdf0e10cSrcweir 
1703*cdf0e10cSrcweir uno::Reference<XAccessible> SAL_CALL ScAccessibleDocumentPagePreview::getAccessibleChild(sal_Int32 nIndex)
1704*cdf0e10cSrcweir 			    throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
1705*cdf0e10cSrcweir {
1706*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1707*cdf0e10cSrcweir     IsObjectValid();
1708*cdf0e10cSrcweir 	uno::Reference<XAccessible> xAccessible;
1709*cdf0e10cSrcweir 
1710*cdf0e10cSrcweir 	if ( mpViewShell )
1711*cdf0e10cSrcweir 	{
1712*cdf0e10cSrcweir 		const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
1713*cdf0e10cSrcweir 		ScPagePreviewCountData aCount( rData, mpViewShell->GetWindow(), GetNotesChilds(), GetShapeChilds() );
1714*cdf0e10cSrcweir 
1715*cdf0e10cSrcweir 		if ( nIndex < aCount.nBackShapes )
1716*cdf0e10cSrcweir 		{
1717*cdf0e10cSrcweir 			xAccessible = GetShapeChilds()->GetBackShape(nIndex);
1718*cdf0e10cSrcweir 		}
1719*cdf0e10cSrcweir 		else if ( nIndex < aCount.nBackShapes + aCount.nHeaders )
1720*cdf0e10cSrcweir 		{
1721*cdf0e10cSrcweir 			if ( !mpHeader )
1722*cdf0e10cSrcweir             {
1723*cdf0e10cSrcweir                 mpHeader = new ScAccessiblePageHeader( this, mpViewShell, sal_True, nIndex );
1724*cdf0e10cSrcweir                 mpHeader->acquire();
1725*cdf0e10cSrcweir             }
1726*cdf0e10cSrcweir 
1727*cdf0e10cSrcweir 			xAccessible = mpHeader;
1728*cdf0e10cSrcweir 		}
1729*cdf0e10cSrcweir 		else if ( nIndex < aCount.nBackShapes + aCount.nHeaders + aCount.nTables )
1730*cdf0e10cSrcweir 		{
1731*cdf0e10cSrcweir 			if ( !mpTable )
1732*cdf0e10cSrcweir             {
1733*cdf0e10cSrcweir 				mpTable = new ScAccessiblePreviewTable( this, mpViewShell, nIndex );
1734*cdf0e10cSrcweir                 mpTable->acquire();
1735*cdf0e10cSrcweir 				mpTable->Init();
1736*cdf0e10cSrcweir             }
1737*cdf0e10cSrcweir 			xAccessible = mpTable;
1738*cdf0e10cSrcweir 		}
1739*cdf0e10cSrcweir         else if ( nIndex < aCount.nBackShapes + aCount.nHeaders + aCount.nNoteParagraphs )
1740*cdf0e10cSrcweir         {
1741*cdf0e10cSrcweir             xAccessible = GetNotesChilds()->GetChild(nIndex - aCount.nBackShapes - aCount.nHeaders);
1742*cdf0e10cSrcweir         }
1743*cdf0e10cSrcweir 		else if ( (nIndex < aCount.nBackShapes + aCount.nHeaders + aCount.nTables + aCount.nNoteParagraphs + aCount.nFooters) )
1744*cdf0e10cSrcweir 		{
1745*cdf0e10cSrcweir 			if ( !mpFooter )
1746*cdf0e10cSrcweir             {
1747*cdf0e10cSrcweir 				mpFooter = new ScAccessiblePageHeader( this, mpViewShell, sal_False, nIndex );
1748*cdf0e10cSrcweir                 mpFooter->acquire();
1749*cdf0e10cSrcweir             }
1750*cdf0e10cSrcweir 			xAccessible = mpFooter;
1751*cdf0e10cSrcweir 		}
1752*cdf0e10cSrcweir 		else
1753*cdf0e10cSrcweir         {
1754*cdf0e10cSrcweir             sal_Int32 nIdx(nIndex - (aCount.nBackShapes + aCount.nHeaders + aCount.nTables + aCount.nNoteParagraphs + aCount.nFooters));
1755*cdf0e10cSrcweir             if (nIdx < aCount.nForeShapes)
1756*cdf0e10cSrcweir                 xAccessible = GetShapeChilds()->GetForeShape(nIdx);
1757*cdf0e10cSrcweir             else
1758*cdf0e10cSrcweir                 xAccessible = GetShapeChilds()->GetControl(nIdx - aCount.nForeShapes);
1759*cdf0e10cSrcweir         }
1760*cdf0e10cSrcweir 	}
1761*cdf0e10cSrcweir 
1762*cdf0e10cSrcweir 	if ( !xAccessible.is() )
1763*cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
1764*cdf0e10cSrcweir 
1765*cdf0e10cSrcweir 	return xAccessible;
1766*cdf0e10cSrcweir }
1767*cdf0e10cSrcweir 
1768*cdf0e10cSrcweir     ///	Return the set of current states.
1769*cdf0e10cSrcweir uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessibleDocumentPagePreview::getAccessibleStateSet(void)
1770*cdf0e10cSrcweir 					    throw (uno::RuntimeException)
1771*cdf0e10cSrcweir {
1772*cdf0e10cSrcweir 	ScUnoGuard aGuard;
1773*cdf0e10cSrcweir 	uno::Reference<XAccessibleStateSet> xParentStates;
1774*cdf0e10cSrcweir 	if (getAccessibleParent().is())
1775*cdf0e10cSrcweir 	{
1776*cdf0e10cSrcweir 		uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
1777*cdf0e10cSrcweir 		xParentStates = xParentContext->getAccessibleStateSet();
1778*cdf0e10cSrcweir 	}
1779*cdf0e10cSrcweir 	utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
1780*cdf0e10cSrcweir 	if (IsDefunc(xParentStates))
1781*cdf0e10cSrcweir 		pStateSet->AddState(AccessibleStateType::DEFUNC);
1782*cdf0e10cSrcweir     else
1783*cdf0e10cSrcweir     {
1784*cdf0e10cSrcweir 	    // never editable
1785*cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::ENABLED);
1786*cdf0e10cSrcweir 	    pStateSet->AddState(AccessibleStateType::OPAQUE);
1787*cdf0e10cSrcweir 	    if (isShowing())
1788*cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::SHOWING);
1789*cdf0e10cSrcweir 	    if (isVisible())
1790*cdf0e10cSrcweir 		    pStateSet->AddState(AccessibleStateType::VISIBLE);
1791*cdf0e10cSrcweir     }
1792*cdf0e10cSrcweir 	return pStateSet;
1793*cdf0e10cSrcweir }
1794*cdf0e10cSrcweir 
1795*cdf0e10cSrcweir 	//=====  XServiceInfo  ====================================================
1796*cdf0e10cSrcweir 
1797*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScAccessibleDocumentPagePreview::getImplementationName(void)
1798*cdf0e10cSrcweir 				    throw (uno::RuntimeException)
1799*cdf0e10cSrcweir {
1800*cdf0e10cSrcweir 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScAccessibleDocumentPagePreview"));
1801*cdf0e10cSrcweir }
1802*cdf0e10cSrcweir 
1803*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString> SAL_CALL ScAccessibleDocumentPagePreview::getSupportedServiceNames(void)
1804*cdf0e10cSrcweir 			        throw (uno::RuntimeException)
1805*cdf0e10cSrcweir {
1806*cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
1807*cdf0e10cSrcweir     sal_Int32 nOldSize(aSequence.getLength());
1808*cdf0e10cSrcweir     aSequence.realloc(nOldSize + 1);
1809*cdf0e10cSrcweir     ::rtl::OUString* pNames = aSequence.getArray();
1810*cdf0e10cSrcweir 
1811*cdf0e10cSrcweir 	pNames[nOldSize] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.AccessibleSpreadsheetPageView"));
1812*cdf0e10cSrcweir 
1813*cdf0e10cSrcweir 	return aSequence;
1814*cdf0e10cSrcweir }
1815*cdf0e10cSrcweir 
1816*cdf0e10cSrcweir //=====  XTypeProvider  =======================================================
1817*cdf0e10cSrcweir 
1818*cdf0e10cSrcweir uno::Sequence<sal_Int8> SAL_CALL
1819*cdf0e10cSrcweir 	ScAccessibleDocumentPagePreview::getImplementationId(void)
1820*cdf0e10cSrcweir     throw (uno::RuntimeException)
1821*cdf0e10cSrcweir {
1822*cdf0e10cSrcweir     ScUnoGuard aGuard;
1823*cdf0e10cSrcweir     IsObjectValid();
1824*cdf0e10cSrcweir 	static uno::Sequence<sal_Int8> aId;
1825*cdf0e10cSrcweir 	if (aId.getLength() == 0)
1826*cdf0e10cSrcweir 	{
1827*cdf0e10cSrcweir 		aId.realloc (16);
1828*cdf0e10cSrcweir 		rtl_createUuid (reinterpret_cast<sal_uInt8 *>(aId.getArray()), 0, sal_True);
1829*cdf0e10cSrcweir 	}
1830*cdf0e10cSrcweir 	return aId;
1831*cdf0e10cSrcweir }
1832*cdf0e10cSrcweir 
1833*cdf0e10cSrcweir //=====  internal  ========================================================
1834*cdf0e10cSrcweir 
1835*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScAccessibleDocumentPagePreview::createAccessibleDescription(void)
1836*cdf0e10cSrcweir 				    throw (uno::RuntimeException)
1837*cdf0e10cSrcweir {
1838*cdf0e10cSrcweir     rtl::OUString sDescription = String(ScResId(STR_ACC_PREVIEWDOC_DESCR));
1839*cdf0e10cSrcweir 	return sDescription;
1840*cdf0e10cSrcweir }
1841*cdf0e10cSrcweir 
1842*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScAccessibleDocumentPagePreview::createAccessibleName(void)
1843*cdf0e10cSrcweir 				    throw (uno::RuntimeException)
1844*cdf0e10cSrcweir {
1845*cdf0e10cSrcweir     rtl::OUString sName = String(ScResId(STR_ACC_PREVIEWDOC_NAME));
1846*cdf0e10cSrcweir 	return sName;
1847*cdf0e10cSrcweir }
1848*cdf0e10cSrcweir 
1849*cdf0e10cSrcweir Rectangle ScAccessibleDocumentPagePreview::GetBoundingBoxOnScreen() const throw (uno::RuntimeException)
1850*cdf0e10cSrcweir {
1851*cdf0e10cSrcweir 	Rectangle aRect;
1852*cdf0e10cSrcweir 	if (mpViewShell)
1853*cdf0e10cSrcweir 	{
1854*cdf0e10cSrcweir 		Window* pWindow = mpViewShell->GetWindow();
1855*cdf0e10cSrcweir 		if (pWindow)
1856*cdf0e10cSrcweir 			aRect = pWindow->GetWindowExtentsRelative(NULL);
1857*cdf0e10cSrcweir 	}
1858*cdf0e10cSrcweir 	return aRect;
1859*cdf0e10cSrcweir }
1860*cdf0e10cSrcweir 
1861*cdf0e10cSrcweir Rectangle ScAccessibleDocumentPagePreview::GetBoundingBox() const throw (uno::RuntimeException)
1862*cdf0e10cSrcweir {
1863*cdf0e10cSrcweir 	Rectangle aRect;
1864*cdf0e10cSrcweir 	if (mpViewShell)
1865*cdf0e10cSrcweir 	{
1866*cdf0e10cSrcweir 		Window* pWindow = mpViewShell->GetWindow();
1867*cdf0e10cSrcweir 		if (pWindow)
1868*cdf0e10cSrcweir 			aRect = pWindow->GetWindowExtentsRelative(pWindow->GetAccessibleParentWindow());
1869*cdf0e10cSrcweir 	}
1870*cdf0e10cSrcweir 	return aRect;
1871*cdf0e10cSrcweir }
1872*cdf0e10cSrcweir 
1873*cdf0e10cSrcweir sal_Bool ScAccessibleDocumentPagePreview::IsDefunc(
1874*cdf0e10cSrcweir 	const uno::Reference<XAccessibleStateSet>& rxParentStates)
1875*cdf0e10cSrcweir {
1876*cdf0e10cSrcweir 	return ScAccessibleContextBase::IsDefunc() || !getAccessibleParent().is() ||
1877*cdf0e10cSrcweir 		(rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
1878*cdf0e10cSrcweir }
1879*cdf0e10cSrcweir 
1880*cdf0e10cSrcweir ScNotesChilds* ScAccessibleDocumentPagePreview::GetNotesChilds()
1881*cdf0e10cSrcweir {
1882*cdf0e10cSrcweir     if (!mpNotesChilds && mpViewShell)
1883*cdf0e10cSrcweir     {
1884*cdf0e10cSrcweir         mpNotesChilds = new ScNotesChilds(mpViewShell, this);
1885*cdf0e10cSrcweir 
1886*cdf0e10cSrcweir 		const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
1887*cdf0e10cSrcweir 		ScPagePreviewCountData aCount( rData, mpViewShell->GetWindow(), GetNotesChilds(), GetShapeChilds() );
1888*cdf0e10cSrcweir 
1889*cdf0e10cSrcweir         //!	order is background shapes, header, table or notes, footer, foreground shapes, controls
1890*cdf0e10cSrcweir         mpNotesChilds->Init(aCount.aVisRect, aCount.nBackShapes + aCount.nHeaders);
1891*cdf0e10cSrcweir     }
1892*cdf0e10cSrcweir     return mpNotesChilds;
1893*cdf0e10cSrcweir }
1894*cdf0e10cSrcweir 
1895*cdf0e10cSrcweir ScShapeChilds* ScAccessibleDocumentPagePreview::GetShapeChilds()
1896*cdf0e10cSrcweir {
1897*cdf0e10cSrcweir     if (!mpShapeChilds && mpViewShell)
1898*cdf0e10cSrcweir     {
1899*cdf0e10cSrcweir         mpShapeChilds = new ScShapeChilds(mpViewShell, this);
1900*cdf0e10cSrcweir         mpShapeChilds->Init();
1901*cdf0e10cSrcweir     }
1902*cdf0e10cSrcweir 
1903*cdf0e10cSrcweir     return mpShapeChilds;
1904*cdf0e10cSrcweir }
1905*cdf0e10cSrcweir 
1906*cdf0e10cSrcweir //UNUSED2009-05 uno::Reference < XAccessible > ScAccessibleDocumentPagePreview::GetCurrentAccessibleTable()
1907*cdf0e10cSrcweir //UNUSED2009-05 {
1908*cdf0e10cSrcweir //UNUSED2009-05     if (!mpTable)
1909*cdf0e10cSrcweir //UNUSED2009-05     {
1910*cdf0e10cSrcweir //UNUSED2009-05         if ( mpViewShell )
1911*cdf0e10cSrcweir //UNUSED2009-05         {
1912*cdf0e10cSrcweir //UNUSED2009-05             const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
1913*cdf0e10cSrcweir //UNUSED2009-05             ScPagePreviewCountData aCount( rData, mpViewShell->GetWindow(), GetNotesChilds(), GetShapeChilds() );
1914*cdf0e10cSrcweir //UNUSED2009-05             //! order is background shapes, header, table or notes, footer, foreground shapes, controls
1915*cdf0e10cSrcweir //UNUSED2009-05             sal_Int32 nIndex (aCount.nBackShapes + aCount.nHeaders);
1916*cdf0e10cSrcweir //UNUSED2009-05
1917*cdf0e10cSrcweir //UNUSED2009-05             mpTable = new ScAccessiblePreviewTable( this, mpViewShell, nIndex );
1918*cdf0e10cSrcweir //UNUSED2009-05             mpTable->acquire();
1919*cdf0e10cSrcweir //UNUSED2009-05             mpTable->Init();
1920*cdf0e10cSrcweir //UNUSED2009-05         }
1921*cdf0e10cSrcweir //UNUSED2009-05     }
1922*cdf0e10cSrcweir //UNUSED2009-05     return mpTable;
1923*cdf0e10cSrcweir //UNUSED2009-05 }
1924*cdf0e10cSrcweir 
1925*cdf0e10cSrcweir //UNUSED2009-05 void ScAccessibleDocumentPagePreview::ChildCountChanged()
1926*cdf0e10cSrcweir //UNUSED2009-05 {
1927*cdf0e10cSrcweir //UNUSED2009-05     if (mpViewShell)
1928*cdf0e10cSrcweir //UNUSED2009-05     {
1929*cdf0e10cSrcweir //UNUSED2009-05         const ScPreviewLocationData& rData = mpViewShell->GetLocationData();
1930*cdf0e10cSrcweir //UNUSED2009-05         ScPagePreviewCountData aCount( rData, mpViewShell->GetWindow(), GetNotesChilds(), GetShapeChilds() );
1931*cdf0e10cSrcweir //UNUSED2009-05         //! order is background shapes, header, table or notes, footer, foreground shapes, controls
1932*cdf0e10cSrcweir //UNUSED2009-05         if(mpHeader)
1933*cdf0e10cSrcweir //UNUSED2009-05             mpHeader->SetCurrentIndexInParent(aCount.nBackShapes);
1934*cdf0e10cSrcweir //UNUSED2009-05         if (mpTable)
1935*cdf0e10cSrcweir //UNUSED2009-05             mpTable->SetCurrentIndexInParent(aCount.nBackShapes + aCount.nHeaders);
1936*cdf0e10cSrcweir //UNUSED2009-05         if (mpFooter)
1937*cdf0e10cSrcweir //UNUSED2009-05             mpFooter->SetCurrentIndexInParent(aCount.nBackShapes + aCount.nHeaders + aCount.nTables + aCount.nNoteParagraphs);
1938*cdf0e10cSrcweir //UNUSED2009-05
1939*cdf0e10cSrcweir //UNUSED2009-05         if (mpNotesChilds)
1940*cdf0e10cSrcweir //UNUSED2009-05             mpNotesChilds->SetOffset(aCount.nBackShapes + aCount.nHeaders);
1941*cdf0e10cSrcweir //UNUSED2009-05     }
1942*cdf0e10cSrcweir //UNUSED2009-05 }
1943