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

Generated by: LCOV version 1.10