LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/Accessibility - AccessibleDocumentPagePreview.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 807 0.1 %
Date: 2012-12-27 Functions: 2 97 2.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10