LCOV - code coverage report
Current view: top level - sc/source/ui/Accessibility - AccessibleSpreadsheet.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 248 938 26.4 %
Date: 2014-04-11 Functions: 26 70 37.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             : #include "AccessibleSpreadsheet.hxx"
      21             : #include "AccessibilityHints.hxx"
      22             : #include "AccessibleCell.hxx"
      23             : #include "AccessibleDocument.hxx"
      24             : #include "tabvwsh.hxx"
      25             : #include "document.hxx"
      26             : #include "hints.hxx"
      27             : #include "scmod.hxx"
      28             : #include "markdata.hxx"
      29             : 
      30             : #include <unotools/accessiblestatesethelper.hxx>
      31             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      32             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      33             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      34             : #include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp>
      35             : #include <comphelper/servicehelper.hxx>
      36             : #include <tools/gen.hxx>
      37             : #include <svtools/colorcfg.hxx>
      38             : #include <vcl/svapp.hxx>
      39             : #include "scresid.hxx"
      40             : #include "sc.hrc"
      41             : 
      42             : #include <algorithm>
      43             : 
      44             : using namespace ::com::sun::star;
      45             : using namespace ::com::sun::star::accessibility;
      46             : 
      47           0 : bool CompMinCol(const std::pair<sal_uInt16,sal_uInt16> & pc1,const std::pair<sal_uInt16,sal_uInt16>  &pc2)
      48             : {
      49           0 :     return pc1.first < pc2.first;
      50             : }
      51             : 
      52           0 : ScMyAddress ScAccessibleSpreadsheet::CalcScAddressFromRangeList(ScRangeList *pMarkedRanges,sal_Int32 nSelectedChildIndex)
      53             : {
      54           0 :     if (pMarkedRanges->size() <= 1)
      55             :     {
      56           0 :         ScRange* pRange = pMarkedRanges->front();
      57           0 :         if (pRange)
      58             :         {
      59             :             // MT IA2: Not used.
      60             :             // const int nRowNum = pRange->aEnd.Row() - pRange->aStart.Row() + 1;
      61           0 :             const int nColNum = pRange->aEnd.Col() - pRange->aStart.Col() + 1;
      62           0 :             const int nCurCol = nSelectedChildIndex % nColNum;
      63           0 :             const int nCurRow = (nSelectedChildIndex - nCurCol)/nColNum;
      64           0 :             return ScMyAddress(static_cast<SCCOL>(pRange->aStart.Col() + nCurCol), pRange->aStart.Row() + nCurRow, maActiveCell.Tab());
      65             :         }
      66             :     }
      67             :     else
      68             :     {
      69           0 :         sal_Int32 nMinRow = MAXROW;
      70           0 :         sal_Int32 nMaxRow = 0;
      71           0 :         m_vecTempRange.clear();
      72           0 :         size_t nSize = pMarkedRanges->size();
      73           0 :         for (size_t i = 0; i < nSize; ++i)
      74             :         {
      75           0 :             ScRange* pRange = (*pMarkedRanges)[i];
      76           0 :             if (pRange->aStart.Tab() != pRange->aEnd.Tab())
      77             :             {
      78           0 :                 if ((maActiveCell.Tab() >= pRange->aStart.Tab()) ||
      79           0 :                     maActiveCell.Tab() <= pRange->aEnd.Tab())
      80             :                 {
      81           0 :                     m_vecTempRange.push_back(pRange);
      82           0 :                     nMinRow = std::min(pRange->aStart.Row(),nMinRow);
      83           0 :                     nMaxRow = std::max(pRange->aEnd.Row(),nMaxRow);
      84             :                 }
      85             :                 else
      86             :                     SAL_WARN("sc", "Range of wrong table");
      87             :             }
      88           0 :             else if(pRange->aStart.Tab() == maActiveCell.Tab())
      89             :             {
      90           0 :                 m_vecTempRange.push_back(pRange);
      91           0 :                 nMinRow = std::min(pRange->aStart.Row(),nMinRow);
      92           0 :                 nMaxRow = std::max(pRange->aEnd.Row(),nMaxRow);
      93             :             }
      94             :             else
      95             :                 SAL_WARN("sc", "Range of wrong table");
      96             :         }
      97           0 :         int nCurrentIndex = 0 ;
      98           0 :         for(sal_Int32 row = nMinRow ; row <= nMaxRow ; ++row)
      99             :         {
     100           0 :             m_vecTempCol.clear();
     101             :             {
     102           0 :                 VEC_RANGE::const_iterator vi = m_vecTempRange.begin();
     103           0 :                 for (; vi < m_vecTempRange.end(); ++vi)
     104             :                 {
     105           0 :                     ScRange *p = *vi;
     106           0 :                     if ( row >= p->aStart.Row() && row <= p->aEnd.Row())
     107             :                     {
     108           0 :                         m_vecTempCol.push_back(std::make_pair(p->aStart.Col(),p->aEnd.Col()));
     109             :                     }
     110             :                 }
     111             :             }
     112           0 :             std::sort(m_vecTempCol.begin(),m_vecTempCol.end(),CompMinCol);
     113             :             {
     114           0 :                 VEC_COL::const_iterator vic = m_vecTempCol.begin();
     115           0 :                 for(; vic != m_vecTempCol.end(); ++vic)
     116             :                 {
     117           0 :                     const PAIR_COL &pariCol = *vic;
     118           0 :                     sal_uInt16 nCol = pariCol.second - pariCol.first + 1;
     119           0 :                     if (nCol + nCurrentIndex > nSelectedChildIndex)
     120             :                     {
     121           0 :                         return ScMyAddress(static_cast<SCCOL>(pariCol.first + nSelectedChildIndex - nCurrentIndex), row, maActiveCell.Tab());
     122             :                     }
     123           0 :                     nCurrentIndex += nCol;
     124             :                 }
     125             :             }
     126             :         }
     127             :     }
     128           0 :     return ScMyAddress(0,0,maActiveCell.Tab());
     129             : }
     130             : 
     131           0 : bool ScAccessibleSpreadsheet::CalcScRangeDifferenceMax(ScRange *pSrc,ScRange *pDest,int nMax,VEC_MYADDR &vecRet,int &nSize)
     132             : {
     133             :     //Src Must be :Src > Dest
     134           0 :     if (pDest->In(*pSrc))
     135             :     {//Here is Src In Dest,Src <= Dest
     136           0 :         return false;
     137             :     }
     138           0 :     if (!pDest->Intersects(*pSrc))
     139             :     {
     140           0 :         int nCellCount = sal_uInt32(pDest->aEnd.Col() - pDest->aStart.Col() + 1)
     141           0 :             * sal_uInt32(pDest->aEnd.Row() - pDest->aStart.Row() + 1)
     142           0 :             * sal_uInt32(pDest->aEnd.Tab() - pDest->aStart.Tab() + 1);
     143           0 :         if (nCellCount + nSize > nMax)
     144             :         {
     145           0 :             return true;
     146             :         }
     147           0 :         else if(nCellCount > 0)
     148             :         {
     149           0 :             nCellCount +=nSize;
     150           0 :             for (sal_Int32 row = pDest->aStart.Row(); row <=  pDest->aEnd.Row();++row)
     151             :             {
     152           0 :                 for (sal_uInt16 col = pDest->aStart.Col(); col <=  pDest->aEnd.Col();++col)
     153             :                 {
     154           0 :                     vecRet.push_back(ScMyAddress(col,row,pDest->aStart.Tab()));
     155             :                 }
     156             :             }
     157             :         }
     158           0 :         return false;
     159             :     }
     160           0 :     sal_Int32 nMinRow = pSrc->aStart.Row();
     161           0 :     sal_Int32 nMaxRow = pSrc->aEnd.Row();
     162           0 :     for (; nMinRow <= nMaxRow ; ++nMinRow,--nMaxRow)
     163             :     {
     164           0 :         for (sal_uInt16 col = pSrc->aStart.Col(); col <=  pSrc->aEnd.Col();++col)
     165             :         {
     166           0 :             if (nSize > nMax)
     167             :             {
     168           0 :                 return true;
     169             :             }
     170           0 :             ScMyAddress cell(col,nMinRow,pSrc->aStart.Tab());
     171           0 :             if(!pDest->In(cell))
     172             :             {//In Src ,Not In Dest
     173           0 :                 vecRet.push_back(cell);
     174           0 :                 ++nSize;
     175             :             }
     176             :         }
     177           0 :         if (nMinRow != nMaxRow)
     178             :         {
     179           0 :             for (sal_uInt16 col = pSrc->aStart.Col(); col <=  pSrc->aEnd.Col();++col)
     180             :             {
     181           0 :                 if (nSize > nMax)
     182             :                 {
     183           0 :                     return true;
     184             :                 }
     185           0 :                 ScMyAddress cell(col,nMaxRow,pSrc->aStart.Tab());
     186           0 :                 if(!pDest->In(cell))
     187             :                 {//In Src ,Not In Dest
     188           0 :                     vecRet.push_back(cell);
     189           0 :                     ++nSize;
     190             :                 }
     191             :             }
     192             :         }
     193             :     }
     194           0 :     return false;
     195             : }
     196             : 
     197             : //In Src , Not in Dest
     198           0 : bool ScAccessibleSpreadsheet::CalcScRangeListDifferenceMax(ScRangeList *pSrc,ScRangeList *pDest,int nMax,VEC_MYADDR &vecRet)
     199             : {
     200           0 :     if (pSrc == NULL || pDest == NULL)
     201             :     {
     202           0 :         return false;
     203             :     }
     204           0 :     int nSize =0;
     205           0 :     if (pDest->GetCellCount() == 0)//if the Dest Rang List is empty
     206             :     {
     207           0 :         if (pSrc->GetCellCount() > sal_uInt32(nMax))//if the Src Cell count is greater then  nMax
     208             :         {
     209           0 :             return true;
     210             :         }
     211             :         //now the cell count is less then nMax
     212           0 :         vecRet.reserve(10);
     213           0 :         size_t nSrcSize = pSrc->size();
     214           0 :         for (size_t i = 0; i < nSrcSize; ++i)
     215             :         {
     216           0 :             ScRange* pRange = (*pSrc)[i];
     217           0 :             for (sal_Int32 row = pRange->aStart.Row(); row <=  pRange->aEnd.Row();++row)
     218             :             {
     219           0 :                 for (sal_uInt16 col = pRange->aStart.Col(); col <=  pRange->aEnd.Col();++col)
     220             :                 {
     221           0 :                     vecRet.push_back(ScMyAddress(col,row,pRange->aStart.Tab()));
     222             :                 }
     223             :             }
     224             :         }
     225           0 :         return false;
     226             :     }
     227             :     //the Dest Rang List is not empty
     228           0 :     vecRet.reserve(10);
     229           0 :     size_t nSizeSrc = pSrc->size();
     230           0 :     for (size_t i = 0; i < nSizeSrc; ++i)
     231             :     {
     232           0 :         ScRange* pRange = (*pSrc)[i];
     233           0 :         size_t nSizeDest = pDest->size();
     234           0 :         for (size_t j = 0; j < nSizeDest; ++j)
     235             :         {
     236           0 :             ScRange* pRangeDest = (*pDest)[j];
     237           0 :             if (CalcScRangeDifferenceMax(pRange,pRangeDest,nMax,vecRet,nSize))
     238             :             {
     239           0 :                 return true;
     240             :             }
     241             :         }
     242             :     }
     243           0 :     return false;
     244             : }
     245             : 
     246             : //=====  internal  ============================================================
     247             : 
     248             : // FIXME: really unclear why we have an ScAccessibleTableBase with
     249             : // only this single sub-class
     250           2 : ScAccessibleSpreadsheet::ScAccessibleSpreadsheet(
     251             :         ScAccessibleDocument* pAccDoc,
     252             :         ScTabViewShell* pViewShell,
     253             :         SCTAB nTab,
     254             :         ScSplitPos eSplitPos)
     255             :     :
     256             :     ScAccessibleTableBase (pAccDoc, GetDocument(pViewShell),
     257             :         ScRange(ScAddress(0, 0, nTab),ScAddress(MAXCOL, MAXROW, nTab))),
     258             :     mbIsSpreadsheet( true ),
     259             :     m_bFormulaMode( false ),
     260             :     m_bFormulaLastMode( false ),
     261           2 :     m_nMinX(0),m_nMaxX(0),m_nMinY(0),m_nMaxY(0)
     262             : {
     263           2 :     ConstructScAccessibleSpreadsheet( pAccDoc, pViewShell, nTab, eSplitPos );
     264           2 : }
     265             : 
     266           0 : ScAccessibleSpreadsheet::ScAccessibleSpreadsheet(
     267             :         ScAccessibleSpreadsheet& rParent, const ScRange& rRange ) :
     268             :     ScAccessibleTableBase( rParent.mpAccDoc, rParent.mpDoc, rRange),
     269           0 :     mbIsSpreadsheet( false )
     270             : {
     271           0 :     ConstructScAccessibleSpreadsheet( rParent.mpAccDoc, rParent.mpViewShell, rParent.mnTab, rParent.meSplitPos );
     272           0 : }
     273             : 
     274           6 : ScAccessibleSpreadsheet::~ScAccessibleSpreadsheet()
     275             : {
     276           2 :     delete mpMarkedRanges;
     277           2 :     if (mpViewShell)
     278           0 :         mpViewShell->RemoveAccessibilityObject(*this);
     279           4 : }
     280             : 
     281           2 : void ScAccessibleSpreadsheet::ConstructScAccessibleSpreadsheet(
     282             :     ScAccessibleDocument* pAccDoc,
     283             :     ScTabViewShell* pViewShell,
     284             :     SCTAB nTab,
     285             :     ScSplitPos eSplitPos)
     286             : {
     287           2 :     mpViewShell = pViewShell;
     288           2 :     mpMarkedRanges = 0;
     289           2 :     mpSortedMarkedCells = 0;
     290           2 :     mpAccDoc = pAccDoc;
     291           2 :     mpAccCell.clear();
     292           2 :     meSplitPos = eSplitPos;
     293           2 :     mnTab = nTab;
     294           2 :     mbHasSelection = false;
     295           2 :     mbDelIns = false;
     296           2 :     mbIsFocusSend = false;
     297           2 :     maVisCells = GetVisCells(GetVisArea(mpViewShell, meSplitPos));
     298           2 :     if (mpViewShell)
     299             :     {
     300           2 :         mpViewShell->AddAccessibilityObject(*this);
     301             : 
     302           2 :         const ScViewData& rViewData = *mpViewShell->GetViewData();
     303           2 :         const ScMarkData& rMarkData = rViewData.GetMarkData();
     304           2 :         maActiveCell = rViewData.GetCurPos();
     305           4 :         mbHasSelection = rMarkData.GetTableSelect(maActiveCell.Tab()) &&
     306           6 :                     (rMarkData.IsMarked() || rMarkData.IsMultiMarked());
     307           2 :         mpAccCell = GetAccessibleCellAt(maActiveCell.Row(), maActiveCell.Col());
     308           2 :         ScDocument* pScDoc= GetDocument(mpViewShell);
     309           2 :         if (pScDoc)
     310             :         {
     311           2 :             pScDoc->GetName( maActiveCell.Tab(), m_strOldTabName );
     312             :         }
     313             :     }
     314           2 : }
     315             : 
     316           2 : void SAL_CALL ScAccessibleSpreadsheet::disposing()
     317             : {
     318           2 :     SolarMutexGuard aGuard;
     319           2 :     if (mpViewShell)
     320             :     {
     321           2 :         mpViewShell->RemoveAccessibilityObject(*this);
     322           2 :         mpViewShell = NULL;
     323             :     }
     324           2 :     mpAccCell.clear();
     325             : 
     326           2 :     ScAccessibleTableBase::disposing();
     327           2 : }
     328             : 
     329           0 : void ScAccessibleSpreadsheet::CompleteSelectionChanged(bool bNewState)
     330             : {
     331           0 :     if (IsFormulaMode())
     332             :     {
     333           0 :         return ;
     334             :     }
     335           0 :     if (mpMarkedRanges)
     336           0 :         DELETEZ(mpMarkedRanges);
     337           0 :     mbHasSelection = bNewState;
     338             : 
     339           0 :     AccessibleEventObject aEvent;
     340           0 :     aEvent.EventId = AccessibleEventId::STATE_CHANGED;
     341           0 :     if (bNewState)
     342           0 :         aEvent.NewValue = uno::makeAny(AccessibleStateType::SELECTED);
     343             :     else
     344           0 :         aEvent.OldValue = uno::makeAny(AccessibleStateType::SELECTED);
     345           0 :     aEvent.Source = uno::Reference< XAccessibleContext >(this);
     346             : 
     347           0 :     CommitChange(aEvent);
     348             : }
     349             : 
     350           2 : void ScAccessibleSpreadsheet::LostFocus()
     351             : {
     352           2 :     AccessibleEventObject aEvent;
     353           2 :     aEvent.EventId = AccessibleEventId::ACTIVE_DESCENDANT_CHANGED;
     354           2 :     aEvent.Source = uno::Reference< XAccessibleContext >(this);
     355           2 :     aEvent.OldValue <<= uno::Reference<XAccessible>(mpAccCell.get());
     356             : 
     357           2 :     CommitChange(aEvent);
     358             : 
     359           2 :     CommitFocusLost();
     360           2 : }
     361             : 
     362           0 : void ScAccessibleSpreadsheet::GotFocus()
     363             : {
     364           0 :     AccessibleEventObject aEvent;
     365           0 :     aEvent.EventId = AccessibleEventId::ACTIVE_DESCENDANT_CHANGED;
     366           0 :     aEvent.Source = uno::Reference< XAccessibleContext >(this);
     367           0 :     uno::Reference< XAccessible > xNew;
     368           0 :     if (IsFormulaMode())
     369             :     {
     370           0 :         if (!m_pAccFormulaCell.is() || !m_bFormulaLastMode)
     371             :         {
     372           0 :             ScAddress aFormulaAddr;
     373           0 :             if(!GetFormulaCurrentFocusCell(aFormulaAddr))
     374             :             {
     375           0 :                 return;
     376             :             }
     377           0 :             m_pAccFormulaCell = GetAccessibleCellAt(aFormulaAddr.Row(),aFormulaAddr.Col());
     378             :         }
     379           0 :         xNew = m_pAccFormulaCell.get();
     380             :     }
     381             :     else
     382             :     {
     383           0 :         if(mpAccCell->GetCellAddress() == maActiveCell)
     384             :         {
     385           0 :             xNew = mpAccCell.get();
     386             :         }
     387             :         else
     388             :         {
     389           0 :             CommitFocusCell(maActiveCell);
     390           0 :             return ;
     391             :         }
     392             :     }
     393           0 :     aEvent.NewValue <<= xNew;
     394             : 
     395           0 :     CommitChange(aEvent);
     396             : }
     397             : 
     398           0 : void ScAccessibleSpreadsheet::BoundingBoxChanged()
     399             : {
     400           0 :     AccessibleEventObject aEvent;
     401           0 :     aEvent.EventId = AccessibleEventId::BOUNDRECT_CHANGED;
     402           0 :     aEvent.Source = uno::Reference< XAccessibleContext >(this);
     403             : 
     404           0 :     CommitChange(aEvent);
     405           0 : }
     406             : 
     407           0 : void ScAccessibleSpreadsheet::VisAreaChanged()
     408             : {
     409           0 :     AccessibleEventObject aEvent;
     410           0 :     aEvent.EventId = AccessibleEventId::VISIBLE_DATA_CHANGED;
     411           0 :     aEvent.Source = uno::Reference< XAccessibleContext >(this);
     412             : 
     413           0 :     CommitChange(aEvent);
     414           0 : }
     415             : 
     416             :     //=====  SfxListener  =====================================================
     417             : 
     418          14 : void ScAccessibleSpreadsheet::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
     419             : {
     420          14 :     if (rHint.ISA( SfxSimpleHint ) )
     421             :     {
     422          12 :         const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
     423          12 :         if ((rRef.GetId() == SC_HINT_ACC_CURSORCHANGED))
     424             :         {
     425           1 :             if (mpViewShell)
     426             :             {
     427           1 :                 ScViewData *pViewData = mpViewShell->GetViewData();
     428             : 
     429           1 :                 m_bFormulaMode = pViewData->IsRefMode() || SC_MOD()->IsFormulaMode();
     430           1 :                 if ( m_bFormulaMode )
     431             :                 {
     432           0 :                     NotifyRefMode();
     433           0 :                     m_bFormulaLastMode = true;
     434           0 :                     return ;
     435             :                 }
     436           1 :                 if (m_bFormulaLastMode)
     437             :                 {//Last Notify Mode  Is Formula Mode.
     438           0 :                     m_vecFormulaLastMyAddr.clear();
     439           0 :                     RemoveFormulaSelection(true);
     440           0 :                     m_pAccFormulaCell.clear();
     441             :                     //Remove All Selection
     442             :                 }
     443           1 :                 m_bFormulaLastMode = m_bFormulaMode;
     444             : 
     445           1 :                 AccessibleEventObject aEvent;
     446           1 :                 aEvent.Source = uno::Reference< XAccessible >(this);
     447           1 :                 ScAddress aNewCell = pViewData->GetCurPos();
     448           1 :                 if(aNewCell.Tab() != maActiveCell.Tab())
     449             :                 {
     450           0 :                     aEvent.EventId = AccessibleEventId::PAGE_CHANGED;
     451             :                     ScAccessibleDocument *pAccDoc =
     452           0 :                         static_cast<ScAccessibleDocument*>(getAccessibleParent().get());
     453           0 :                     if(pAccDoc)
     454             :                     {
     455           0 :                         pAccDoc->CommitChange(aEvent);
     456             :                     }
     457             :                 }
     458           1 :                 sal_Bool bNewPosCell = (aNewCell != maActiveCell) || mpViewShell->GetForceFocusOnCurCell(); // #i123629#
     459           1 :                 sal_Bool bNewPosCellFocus=sal_False;
     460           1 :                 if ( bNewPosCell && IsFocused() && aNewCell.Tab() == maActiveCell.Tab() )
     461             :                 {//single Focus
     462           1 :                     bNewPosCellFocus=sal_True;
     463             :                 }
     464           1 :                 ScMarkData &refScMarkData = pViewData->GetMarkData();
     465             :                 // MT IA2: Not used
     466             :                 // int nSelCount = refScMarkData.GetSelectCount();
     467           1 :                 sal_Bool bIsMark =refScMarkData.IsMarked();
     468           1 :                 sal_Bool bIsMultMark = refScMarkData.IsMultiMarked();
     469           1 :                 sal_Bool bNewMarked = refScMarkData.GetTableSelect(aNewCell.Tab()) && ( bIsMark || bIsMultMark );
     470             : //              sal_Bool bNewCellSelected = isAccessibleSelected(aNewCell.Row(), aNewCell.Col());
     471           1 :                 sal_uInt16 nTab = pViewData->GetTabNo();
     472           1 :                 ScRange aMarkRange;
     473           1 :                 refScMarkData.GetMarkArea(aMarkRange);
     474           1 :                 aEvent.OldValue <<= ::com::sun::star::uno::Any();
     475             :                 //Mark All
     476           3 :                 if ( !bNewPosCellFocus &&
     477           1 :                     (bNewMarked || bIsMark || bIsMultMark ) &&
     478           1 :                     aMarkRange == ScRange( 0,0,nTab, MAXCOL,MAXROW,nTab ) )
     479             :                 {
     480           0 :                     aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_WITHIN;
     481           0 :                     aEvent.NewValue <<= ::com::sun::star::uno::Any();
     482           0 :                     CommitChange(aEvent);
     483           0 :                     return ;
     484             :                 }
     485           1 :                 if (!mpMarkedRanges)
     486             :                 {
     487           1 :                     mpMarkedRanges = new ScRangeList();
     488             :                 }
     489           1 :                 refScMarkData.FillRangeListWithMarks(mpMarkedRanges, true);
     490             : 
     491             :                 //For Whole Col Row
     492           1 :                 sal_Bool bWholeRow = ::labs(aMarkRange.aStart.Row() - aMarkRange.aEnd.Row()) == MAXROW ;
     493           1 :                 sal_Bool bWholeCol = ::abs(aMarkRange.aStart.Col() - aMarkRange.aEnd.Col()) == MAXCOL ;
     494           1 :                 if ((bNewMarked || bIsMark || bIsMultMark ) && (bWholeCol || bWholeRow))
     495             :                 {
     496           0 :                     if ( aMarkRange != m_aLastWithInMarkRange )
     497             :                     {
     498           0 :                         RemoveSelection(refScMarkData);
     499           0 :                         if(bNewPosCell)
     500             :                         {
     501           0 :                             CommitFocusCell(aNewCell);
     502             :                         }
     503             :                         sal_Bool bLastIsWholeColRow =
     504           0 :                             (::labs(m_aLastWithInMarkRange.aStart.Row() - m_aLastWithInMarkRange.aEnd.Row()) == MAXROW && bWholeRow) ||
     505           0 :                             (::abs(m_aLastWithInMarkRange.aStart.Col() - m_aLastWithInMarkRange.aEnd.Col()) == MAXCOL && bWholeCol);
     506             :                         sal_Bool bSelSmaller=
     507           0 :                             bLastIsWholeColRow &&
     508           0 :                             !aMarkRange.In(m_aLastWithInMarkRange) &&
     509           0 :                             aMarkRange.Intersects(m_aLastWithInMarkRange);
     510           0 :                         if( !bSelSmaller )
     511             :                         {
     512           0 :                             aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_WITHIN;
     513           0 :                             aEvent.NewValue <<= ::com::sun::star::uno::Any();
     514           0 :                             CommitChange(aEvent);
     515             :                         }
     516           0 :                         m_aLastWithInMarkRange = aMarkRange;
     517             :                     }
     518           0 :                     return ;
     519             :                 }
     520           1 :                 m_aLastWithInMarkRange = aMarkRange;
     521           1 :                 int nNewMarkCount = mpMarkedRanges->GetCellCount();
     522           1 :                 sal_Bool bSendSingle= (0 == nNewMarkCount) && bNewPosCell;
     523           1 :                 if (bSendSingle)
     524             :                 {
     525           1 :                     RemoveSelection(refScMarkData);
     526           1 :                     if(bNewPosCellFocus)
     527             :                     {
     528           1 :                         CommitFocusCell(aNewCell);
     529             :                     }
     530           1 :                     uno::Reference< XAccessible > xChild ;
     531           1 :                     if (bNewPosCellFocus)
     532             :                     {
     533           1 :                         xChild = mpAccCell.get();
     534             :                     }
     535             :                     else
     536             :                     {
     537           0 :                         mpAccCell = GetAccessibleCellAt(aNewCell.Row(),aNewCell.Col());
     538           0 :                         xChild = mpAccCell.get();
     539             : 
     540           0 :                         maActiveCell = aNewCell;
     541           0 :                         aEvent.EventId = AccessibleEventId::ACTIVE_DESCENDANT_CHANGED_NOFOCUS;
     542           0 :                         aEvent.NewValue <<= xChild;
     543           0 :                         aEvent.OldValue <<= uno::Reference< XAccessible >();
     544           0 :                         CommitChange(aEvent);
     545             :                     }
     546           1 :                     aEvent.EventId = AccessibleEventId::SELECTION_CHANGED;
     547           1 :                     aEvent.NewValue <<= xChild;
     548           1 :                     CommitChange(aEvent);
     549             :                     OSL_ASSERT(m_mapSelectionSend.count(aNewCell) == 0 );
     550           1 :                     m_mapSelectionSend.insert(MAP_ADDR_XACC::value_type(aNewCell,xChild));
     551             : 
     552             :                 }
     553             :                 else
     554             :                 {
     555           0 :                     ScRange aDelRange;
     556           0 :                     sal_Bool bIsDel = pViewData->GetDelMark( aDelRange );
     557           0 :                     if ( (!bIsDel || (bIsDel && aMarkRange != aDelRange)) &&
     558           0 :                         bNewMarked &&
     559           0 :                         nNewMarkCount > 0 &&
     560           0 :                         !IsSameMarkCell() )
     561             :                     {
     562           0 :                         RemoveSelection(refScMarkData);
     563           0 :                         if(bNewPosCellFocus)
     564             :                         {
     565           0 :                             CommitFocusCell(aNewCell);
     566             :                         }
     567           0 :                         VEC_MYADDR vecNew;
     568           0 :                         if(CalcScRangeListDifferenceMax(mpMarkedRanges,&m_LastMarkedRanges,10,vecNew))
     569             :                         {
     570           0 :                             aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_WITHIN;
     571           0 :                             aEvent.NewValue <<= ::com::sun::star::uno::Any();
     572           0 :                             CommitChange(aEvent);
     573             :                         }
     574             :                         else
     575             :                         {
     576           0 :                             VEC_MYADDR::iterator viAddr = vecNew.begin();
     577           0 :                             for(; viAddr < vecNew.end() ; ++viAddr )
     578             :                             {
     579           0 :                                 uno::Reference< XAccessible > xChild = getAccessibleCellAt(viAddr->Row(),viAddr->Col());
     580           0 :                                 if (!(bNewPosCellFocus && *viAddr == aNewCell) )
     581             :                                 {
     582           0 :                                     aEvent.EventId = AccessibleEventId::ACTIVE_DESCENDANT_CHANGED_NOFOCUS;
     583           0 :                                     aEvent.NewValue <<= xChild;
     584           0 :                                     CommitChange(aEvent);
     585             :                                 }
     586           0 :                                 aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_ADD;
     587           0 :                                 aEvent.NewValue <<= xChild;
     588           0 :                                 CommitChange(aEvent);
     589           0 :                                 m_mapSelectionSend.insert(MAP_ADDR_XACC::value_type(*viAddr,xChild));
     590           0 :                             }
     591           0 :                         }
     592             :                     }
     593             :                 }
     594           1 :                 if (bNewPosCellFocus && maActiveCell != aNewCell)
     595             :                 {
     596           0 :                     CommitFocusCell(aNewCell);
     597             :                 }
     598           1 :                 m_LastMarkedRanges = *mpMarkedRanges;
     599             :             }
     600             :         }
     601          11 :         else if ((rRef.GetId() == SC_HINT_DATACHANGED))
     602             :         {
     603           9 :             if (!mbDelIns)
     604           9 :                 CommitTableModelChange(maRange.aStart.Row(), maRange.aStart.Col(), maRange.aEnd.Row(), maRange.aEnd.Col(), AccessibleTableModelChangeType::UPDATE);
     605             :             else
     606           0 :                 mbDelIns = false;
     607           9 :             ScViewData *pViewData = mpViewShell->GetViewData();
     608           9 :             ScAddress aNewCell = pViewData->GetCurPos();
     609           9 :             if( maActiveCell == aNewCell)
     610             :             {
     611           9 :                 ScDocument* pScDoc= GetDocument(mpViewShell);
     612           9 :                 if (pScDoc)
     613             :                 {
     614           9 :                     OUString valStr(pScDoc->GetString(aNewCell.Col(),aNewCell.Row(),aNewCell.Tab()));
     615           9 :                     if(m_strCurCellValue != valStr)
     616             :                     {
     617           0 :                         AccessibleEventObject aEvent;
     618           0 :                         aEvent.EventId = AccessibleEventId::VALUE_CHANGED;
     619           0 :                         mpAccCell->CommitChange(aEvent);
     620           0 :                         m_strCurCellValue=valStr;
     621             :                     }
     622          18 :                     OUString tabName;
     623           9 :                     pScDoc->GetName( maActiveCell.Tab(), tabName );
     624           9 :                     if( m_strOldTabName != tabName )
     625             :                     {
     626           0 :                         AccessibleEventObject aEvent;
     627           0 :                         aEvent.EventId = AccessibleEventId::NAME_CHANGED;
     628           0 :                         OUString sOldName(ScResId(STR_ACC_TABLE_NAME));
     629           0 :                         sOldName = sOldName.replaceFirst("%1", m_strOldTabName);
     630           0 :                         aEvent.OldValue <<= sOldName;
     631           0 :                         OUString sNewName(ScResId(STR_ACC_TABLE_NAME));
     632           0 :                         sOldName = sNewName.replaceFirst("%1", tabName);
     633           0 :                         aEvent.NewValue <<= sNewName;
     634           0 :                         CommitChange( aEvent );
     635           0 :                         m_strOldTabName = tabName;
     636           9 :                     }
     637             :                 }
     638             :             }
     639             :         }
     640             :         // commented out, because to use a ModelChangeEvent is not the right way
     641             :         // at the moment there is no way, but the Java/Gnome Api should be extended sometime
     642             : /*          if (mpViewShell)
     643             :             {
     644             :                 Rectangle aNewVisCells(GetVisCells(GetVisArea(mpViewShell, meSplitPos)));
     645             : 
     646             :                 Rectangle aNewPos(aNewVisCells);
     647             : 
     648             :                 if (aNewVisCells.IsOver(maVisCells))
     649             :                     aNewPos.Union(maVisCells);
     650             :                 else
     651             :                     CommitTableModelChange(maVisCells.Top(), maVisCells.Left(), maVisCells.Bottom(), maVisCells.Right(), AccessibleTableModelChangeType::UPDATE);
     652             : 
     653             :                 maVisCells = aNewVisCells;
     654             : 
     655             :                 CommitTableModelChange(aNewPos.Top(), aNewPos.Left(), aNewPos.Bottom(), aNewPos.Right(), AccessibleTableModelChangeType::UPDATE);
     656             :             }
     657             :         }*/
     658             :     }
     659           2 :     else if (rHint.ISA( ScUpdateRefHint ))
     660             :     {
     661           0 :         const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
     662           0 :         if (rRef.GetMode() == URM_INSDEL && rRef.GetDz() == 0) //test whether table is inserted or deleted
     663             :         {
     664           0 :             if (((rRef.GetRange().aStart.Col() == maRange.aStart.Col()) &&
     665           0 :                 (rRef.GetRange().aEnd.Col() == maRange.aEnd.Col())) ||
     666           0 :                 ((rRef.GetRange().aStart.Row() == maRange.aStart.Row()) &&
     667           0 :                 (rRef.GetRange().aEnd.Row() == maRange.aEnd.Row())))
     668             :             {
     669             :                 // ignore next SC_HINT_DATACHANGED notification
     670           0 :                 mbDelIns = true;
     671             : 
     672           0 :                 sal_Int16 nId(0);
     673           0 :                 SCsCOL nX(rRef.GetDx());
     674           0 :                 SCsROW nY(rRef.GetDy());
     675           0 :                 ScRange aRange(rRef.GetRange());
     676           0 :                 if ((nX < 0) || (nY < 0))
     677             :                 {
     678             :                     OSL_ENSURE(!((nX < 0) && (nY < 0)), "should not be possible to remove row and column at the same time");
     679           0 :                     nId = AccessibleTableModelChangeType::DELETE;
     680           0 :                     if (nX < 0)
     681             :                     {
     682           0 :                         nX = -nX;
     683           0 :                         nY = aRange.aEnd.Row() - aRange.aStart.Row();
     684             :                     }
     685             :                     else
     686             :                     {
     687           0 :                         nY = -nY;
     688           0 :                         nX = aRange.aEnd.Col() - aRange.aStart.Col();
     689             :                     }
     690             :                 }
     691           0 :                 else if ((nX > 0) || (nY > 0))
     692             :                 {
     693             :                     OSL_ENSURE(!((nX > 0) && (nY > 0)), "should not be possible to add row and column at the same time");
     694           0 :                     nId = AccessibleTableModelChangeType::INSERT;
     695           0 :                     if (nX < 0)
     696           0 :                         nY = aRange.aEnd.Row() - aRange.aStart.Row();
     697             :                     else
     698           0 :                         nX = aRange.aEnd.Col() - aRange.aStart.Col();
     699             :                 }
     700             :                 else
     701             :                 {
     702             :                     OSL_FAIL("is it a deletion or a insertion?");
     703             :                 }
     704             : 
     705           0 :                 CommitTableModelChange(rRef.GetRange().aStart.Row(),
     706           0 :                     rRef.GetRange().aStart.Col(),
     707           0 :                     rRef.GetRange().aStart.Row() + nY,
     708           0 :                     rRef.GetRange().aStart.Col() + nX, nId);
     709             : 
     710           0 :                 AccessibleEventObject aEvent;
     711           0 :                 aEvent.EventId = AccessibleEventId::ACTIVE_DESCENDANT_CHANGED;
     712           0 :                 aEvent.Source = uno::Reference< XAccessibleContext >(this);
     713           0 :                 aEvent.NewValue <<= uno::Reference<XAccessible>(mpAccCell.get());
     714             : 
     715           0 :                 CommitChange(aEvent);
     716             :             }
     717             :         }
     718             :     }
     719             : 
     720          14 :     ScAccessibleTableBase::Notify(rBC, rHint);
     721             : }
     722             : 
     723           1 : void ScAccessibleSpreadsheet::RemoveSelection(ScMarkData &refScMarkData)
     724             : {
     725           1 :     AccessibleEventObject aEvent;
     726           1 :     aEvent.Source = uno::Reference< XAccessible >(this);
     727           1 :     aEvent.OldValue <<= ::com::sun::star::uno::Any();
     728           1 :     MAP_ADDR_XACC::iterator miRemove = m_mapSelectionSend.begin();
     729           2 :     for(;  miRemove != m_mapSelectionSend.end() ;)
     730             :     {
     731           0 :         if (refScMarkData.IsCellMarked(miRemove->first.Col(),miRemove->first.Row(),true) ||
     732           0 :             refScMarkData.IsCellMarked(miRemove->first.Col(),miRemove->first.Row(),false) )
     733             :         {
     734           0 :             ++miRemove;
     735           0 :             continue;
     736             :         }
     737           0 :         aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_REMOVE;
     738           0 :         aEvent.NewValue <<= miRemove->second;
     739           0 :         CommitChange(aEvent);
     740           0 :         MAP_ADDR_XACC::iterator miNext = miRemove;
     741           0 :         ++miNext;
     742           0 :         m_mapSelectionSend.erase(miRemove);
     743           0 :         miRemove = miNext;
     744           1 :     }
     745           1 : }
     746           1 : void ScAccessibleSpreadsheet::CommitFocusCell(const ScAddress &aNewCell)
     747             : {
     748             :     OSL_ASSERT(!IsFormulaMode());
     749           1 :     if(IsFormulaMode())
     750             :     {
     751           1 :         return ;
     752             :     }
     753           1 :     AccessibleEventObject aEvent;
     754           1 :     aEvent.EventId = AccessibleEventId::ACTIVE_DESCENDANT_CHANGED;
     755           1 :     aEvent.Source = uno::Reference< XAccessible >(this);
     756           1 :     aEvent.OldValue <<= uno::Reference<XAccessible>(mpAccCell.get());
     757           1 :     mpAccCell.clear();
     758           1 :     mpAccCell = GetAccessibleCellAt(aNewCell.Row(), aNewCell.Col());
     759           1 :     aEvent.NewValue <<= uno::Reference<XAccessible>(mpAccCell.get());
     760           1 :     maActiveCell = aNewCell;
     761           1 :     ScDocument* pScDoc= GetDocument(mpViewShell);
     762           1 :     if (pScDoc)
     763             :     {
     764           1 :         m_strCurCellValue = pScDoc->GetString(maActiveCell.Col(),maActiveCell.Row(),maActiveCell.Tab());
     765             :     }
     766           1 :     CommitChange(aEvent);
     767             : }
     768             : 
     769           0 : bool ScAccessibleSpreadsheet::IsSameMarkCell()
     770             : {
     771           0 :     return m_LastMarkedRanges == *mpMarkedRanges;
     772             : }
     773             : 
     774             : //=====  XAccessibleTable  ================================================
     775             : 
     776           0 : uno::Reference< XAccessibleTable > SAL_CALL ScAccessibleSpreadsheet::getAccessibleRowHeaders(  )
     777             :                     throw (uno::RuntimeException, std::exception)
     778             : {
     779           0 :     SolarMutexGuard aGuard;
     780           0 :     IsObjectValid();
     781           0 :     uno::Reference< XAccessibleTable > xAccessibleTable;
     782           0 :     if( mpDoc && mbIsSpreadsheet )
     783             :     {
     784           0 :         if( const ScRange* pRowRange = mpDoc->GetRepeatRowRange( mnTab ) )
     785             :         {
     786           0 :             SCROW nStart = pRowRange->aStart.Row();
     787           0 :             SCROW nEnd = pRowRange->aEnd.Row();
     788           0 :             if( (0 <= nStart) && (nStart <= nEnd) && (nEnd <= MAXROW) )
     789           0 :                 xAccessibleTable.set( new ScAccessibleSpreadsheet( *this, ScRange( 0, nStart, mnTab, MAXCOL, nEnd, mnTab ) ) );
     790             :         }
     791             :     }
     792           0 :     return xAccessibleTable;
     793             : }
     794             : 
     795           0 : uno::Reference< XAccessibleTable > SAL_CALL ScAccessibleSpreadsheet::getAccessibleColumnHeaders(  )
     796             :                     throw (uno::RuntimeException, std::exception)
     797             : {
     798           0 :     SolarMutexGuard aGuard;
     799           0 :     IsObjectValid();
     800           0 :     uno::Reference< XAccessibleTable > xAccessibleTable;
     801           0 :     if( mpDoc && mbIsSpreadsheet )
     802             :     {
     803           0 :         if( const ScRange* pColRange = mpDoc->GetRepeatColRange( mnTab ) )
     804             :         {
     805           0 :             SCCOL nStart = pColRange->aStart.Col();
     806           0 :             SCCOL nEnd = pColRange->aEnd.Col();
     807           0 :             if( (0 <= nStart) && (nStart <= nEnd) && (nEnd <= MAXCOL) )
     808           0 :                 xAccessibleTable.set( new ScAccessibleSpreadsheet( *this, ScRange( nStart, 0, mnTab, nEnd, MAXROW, mnTab ) ) );
     809             :         }
     810             :     }
     811           0 :     return xAccessibleTable;
     812             : }
     813             : 
     814           0 : uno::Sequence< sal_Int32 > SAL_CALL ScAccessibleSpreadsheet::getSelectedAccessibleRows(  )
     815             :                     throw (uno::RuntimeException, std::exception)
     816             : {
     817           0 :     SolarMutexGuard aGuard;
     818           0 :     IsObjectValid();
     819           0 :     uno::Sequence<sal_Int32> aSequence;
     820           0 :     if (IsFormulaMode())
     821             :     {
     822           0 :         return aSequence;
     823             :     }
     824           0 :     if (mpViewShell && mpViewShell->GetViewData())
     825             :     {
     826           0 :         aSequence.realloc(maRange.aEnd.Row() - maRange.aStart.Row() + 1);
     827           0 :         const ScMarkData& rMarkdata = mpViewShell->GetViewData()->GetMarkData();
     828           0 :         sal_Int32* pSequence = aSequence.getArray();
     829           0 :         sal_Int32 nCount(0);
     830           0 :         for (SCROW i = maRange.aStart.Row(); i <= maRange.aEnd.Row(); ++i)
     831             :         {
     832           0 :             if (rMarkdata.IsRowMarked(i))
     833             :             {
     834           0 :                 pSequence[nCount] = i;
     835           0 :                 ++nCount;
     836             :             }
     837             :         }
     838           0 :         aSequence.realloc(nCount);
     839             :     }
     840             :     else
     841           0 :         aSequence.realloc(0);
     842           0 :     return aSequence;
     843             : }
     844             : 
     845           0 : uno::Sequence< sal_Int32 > SAL_CALL ScAccessibleSpreadsheet::getSelectedAccessibleColumns(  )
     846             :                     throw (uno::RuntimeException, std::exception)
     847             : {
     848           0 :     SolarMutexGuard aGuard;
     849           0 :     IsObjectValid();
     850           0 :     uno::Sequence<sal_Int32> aSequence;
     851           0 :     if (IsFormulaMode())
     852             :     {
     853           0 :         return aSequence;
     854             :     }
     855           0 :     if (mpViewShell && mpViewShell->GetViewData())
     856             :     {
     857           0 :         aSequence.realloc(maRange.aEnd.Col() - maRange.aStart.Col() + 1);
     858           0 :         const ScMarkData& rMarkdata = mpViewShell->GetViewData()->GetMarkData();
     859           0 :         sal_Int32* pSequence = aSequence.getArray();
     860           0 :         sal_Int32 nCount(0);
     861           0 :         for (SCCOL i = maRange.aStart.Col(); i <= maRange.aEnd.Col(); ++i)
     862             :         {
     863           0 :             if (rMarkdata.IsColumnMarked(i))
     864             :             {
     865           0 :                 pSequence[nCount] = i;
     866           0 :                 ++nCount;
     867             :             }
     868             :         }
     869           0 :         aSequence.realloc(nCount);
     870             :     }
     871             :     else
     872           0 :         aSequence.realloc(0);
     873           0 :     return aSequence;
     874             : }
     875             : 
     876           0 : sal_Bool SAL_CALL ScAccessibleSpreadsheet::isAccessibleRowSelected( sal_Int32 nRow )
     877             :     throw (uno::RuntimeException, lang::IndexOutOfBoundsException, std::exception)
     878             : {
     879           0 :     SolarMutexGuard aGuard;
     880           0 :     IsObjectValid();
     881           0 :     if (IsFormulaMode())
     882             :     {
     883           0 :         return sal_False;
     884             :     }
     885             : 
     886           0 :     if ((nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
     887           0 :         throw lang::IndexOutOfBoundsException();
     888             : 
     889           0 :     sal_Bool bResult(false);
     890           0 :     if (mpViewShell && mpViewShell->GetViewData())
     891             :     {
     892           0 :         const ScMarkData& rMarkdata = mpViewShell->GetViewData()->GetMarkData();
     893           0 :         bResult = rMarkdata.IsRowMarked((SCROW)nRow);
     894             :     }
     895           0 :     return bResult;
     896             : }
     897             : 
     898           0 : sal_Bool SAL_CALL ScAccessibleSpreadsheet::isAccessibleColumnSelected( sal_Int32 nColumn )
     899             :     throw (uno::RuntimeException, lang::IndexOutOfBoundsException, std::exception)
     900             : {
     901           0 :     SolarMutexGuard aGuard;
     902           0 :     IsObjectValid();
     903             : 
     904           0 :     if (IsFormulaMode())
     905             :     {
     906           0 :         return sal_False;
     907             :     }
     908           0 :     if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0))
     909           0 :         throw lang::IndexOutOfBoundsException();
     910             : 
     911           0 :     sal_Bool bResult(false);
     912           0 :     if (mpViewShell && mpViewShell->GetViewData())
     913             :     {
     914           0 :         const ScMarkData& rMarkdata = mpViewShell->GetViewData()->GetMarkData();
     915           0 :         bResult = rMarkdata.IsColumnMarked((SCCOL)nColumn);
     916             :     }
     917           0 :     return bResult;
     918             : }
     919             : 
     920           8 : rtl::Reference<ScAccessibleCell> ScAccessibleSpreadsheet::GetAccessibleCellAt(sal_Int32 nRow, sal_Int32 nColumn)
     921             : {
     922           8 :     if (IsFormulaMode())
     923             :     {
     924           0 :         ScAddress aCellAddress(static_cast<SCCOL>(nColumn), nRow, mpViewShell->GetViewData()->GetTabNo());
     925           0 :         if ((aCellAddress == m_aFormulaActiveCell) && m_pAccFormulaCell.is())
     926             :         {
     927           0 :             return m_pAccFormulaCell;
     928             :         }
     929             :         else
     930           0 :             return ScAccessibleCell::create(this, mpViewShell, aCellAddress, GetAccessibleIndexFormula(nRow, nColumn), meSplitPos, mpAccDoc);
     931             :     }
     932             :     else
     933             :     {
     934           8 :         ScAddress aCellAddress(static_cast<SCCOL>(maRange.aStart.Col() + nColumn),
     935          16 :             static_cast<SCROW>(maRange.aStart.Row() + nRow), maRange.aStart.Tab());
     936           8 :         if ((aCellAddress == maActiveCell) && mpAccCell.is())
     937             :         {
     938           3 :             return mpAccCell;
     939             :         }
     940             :         else
     941           5 :             return ScAccessibleCell::create(this, mpViewShell, aCellAddress, getAccessibleIndex(nRow, nColumn), meSplitPos, mpAccDoc);
     942             :     }
     943             : }
     944             : 
     945           5 : uno::Reference< XAccessible > SAL_CALL ScAccessibleSpreadsheet::getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn )
     946             :                     throw (uno::RuntimeException, lang::IndexOutOfBoundsException, std::exception)
     947             : {
     948           5 :     SolarMutexGuard aGuard;
     949           5 :     IsObjectValid();
     950           5 :     if (!IsFormulaMode())
     951             :     {
     952          15 :     if (nRow > (maRange.aEnd.Row() - maRange.aStart.Row()) ||
     953           5 :         nRow < 0 ||
     954          15 :         nColumn > (maRange.aEnd.Col() - maRange.aStart.Col()) ||
     955             :         nColumn < 0)
     956           0 :         throw lang::IndexOutOfBoundsException();
     957             :     }
     958          10 :     rtl::Reference<ScAccessibleCell> pAccessibleCell = GetAccessibleCellAt(nRow, nColumn);
     959          10 :     return pAccessibleCell.get();
     960             : }
     961             : 
     962           0 : sal_Bool SAL_CALL ScAccessibleSpreadsheet::isAccessibleSelected( sal_Int32 nRow, sal_Int32 nColumn )
     963             :     throw (uno::RuntimeException, lang::IndexOutOfBoundsException, std::exception)
     964             : {
     965           0 :     SolarMutexGuard aGuard;
     966           0 :     IsObjectValid();
     967             : 
     968           0 :     if (IsFormulaMode())
     969             :     {
     970           0 :         ScAddress addr(static_cast<SCCOL>(nColumn), nRow, 0);
     971           0 :         return IsScAddrFormulaSel(addr);
     972             :     }
     973           0 :     if ((nColumn > (maRange.aEnd.Col() - maRange.aStart.Col())) || (nColumn < 0) ||
     974           0 :         (nRow > (maRange.aEnd.Row() - maRange.aStart.Row())) || (nRow < 0))
     975           0 :         throw lang::IndexOutOfBoundsException();
     976             : 
     977           0 :     sal_Bool bResult(false);
     978           0 :     if (mpViewShell)
     979             :     {
     980           0 :         const ScMarkData& rMarkdata = mpViewShell->GetViewData()->GetMarkData();
     981           0 :         bResult = rMarkdata.IsCellMarked(static_cast<SCCOL>(nColumn), static_cast<SCROW>(nRow));
     982             :     }
     983           0 :     return bResult;
     984             : }
     985             : 
     986             :     //=====  XAccessibleComponent  ============================================
     987             : 
     988           0 : uno::Reference< XAccessible > SAL_CALL ScAccessibleSpreadsheet::getAccessibleAtPoint(const awt::Point& rPoint)
     989             :     throw (uno::RuntimeException, std::exception)
     990             : {
     991           0 :     uno::Reference< XAccessible > xAccessible;
     992           0 :     if (containsPoint(rPoint))
     993             :     {
     994           0 :         SolarMutexGuard aGuard;
     995           0 :         IsObjectValid();
     996           0 :         if (mpViewShell)
     997             :         {
     998             :             SCsCOL nX;
     999             :             SCsROW nY;
    1000           0 :             mpViewShell->GetViewData()->GetPosFromPixel( rPoint.X, rPoint.Y, meSplitPos, nX, nY);
    1001             :             try{
    1002           0 :             xAccessible = getAccessibleCellAt(nY, nX);
    1003             :             }
    1004           0 :             catch( ::com::sun::star::lang::IndexOutOfBoundsException e)
    1005             :             {
    1006           0 :                 return NULL;
    1007             :             }
    1008           0 :         }
    1009             :     }
    1010           0 :     return xAccessible;
    1011             : }
    1012             : 
    1013           1 : void SAL_CALL ScAccessibleSpreadsheet::grabFocus(  )
    1014             :         throw (uno::RuntimeException, std::exception)
    1015             : {
    1016           1 :     if (getAccessibleParent().is())
    1017             :     {
    1018           1 :         uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
    1019           1 :         if (xAccessibleComponent.is())
    1020           1 :             xAccessibleComponent->grabFocus();
    1021             :     }
    1022           1 : }
    1023             : 
    1024           0 : sal_Int32 SAL_CALL ScAccessibleSpreadsheet::getForeground(  )
    1025             :         throw (uno::RuntimeException, std::exception)
    1026             : {
    1027           0 :     return COL_BLACK;
    1028             : }
    1029             : 
    1030           0 : sal_Int32 SAL_CALL ScAccessibleSpreadsheet::getBackground(  )
    1031             :         throw (uno::RuntimeException, std::exception)
    1032             : {
    1033           0 :     SolarMutexGuard aGuard;
    1034           0 :     IsObjectValid();
    1035           0 :     return SC_MOD()->GetColorConfig().GetColorValue( ::svtools::DOCCOLOR ).nColor;
    1036             : }
    1037             : 
    1038             :     //=====  XAccessibleContext  ==============================================
    1039             : 
    1040           0 : uno::Reference<XAccessibleRelationSet> SAL_CALL ScAccessibleSpreadsheet::getAccessibleRelationSet(void)
    1041             :         throw (::com::sun::star::uno::RuntimeException, std::exception)
    1042             : {
    1043           0 :     utl::AccessibleRelationSetHelper* pRelationSet = NULL;
    1044           0 :     if(mpAccDoc)
    1045           0 :         pRelationSet = mpAccDoc->GetRelationSet(NULL);
    1046           0 :     if (!pRelationSet)
    1047           0 :         pRelationSet = new utl::AccessibleRelationSetHelper();
    1048           0 :     return pRelationSet;
    1049             : }
    1050             : 
    1051             : uno::Reference<XAccessibleStateSet> SAL_CALL
    1052          12 :     ScAccessibleSpreadsheet::getAccessibleStateSet(void)
    1053             :     throw (uno::RuntimeException, std::exception)
    1054             : {
    1055          12 :     SolarMutexGuard aGuard;
    1056          24 :     uno::Reference<XAccessibleStateSet> xParentStates;
    1057          12 :     if (getAccessibleParent().is())
    1058             :     {
    1059          12 :         uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
    1060          12 :         xParentStates = xParentContext->getAccessibleStateSet();
    1061             :     }
    1062          12 :     utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
    1063          12 :     if (IsDefunc(xParentStates))
    1064           0 :         pStateSet->AddState(AccessibleStateType::DEFUNC);
    1065             :     else
    1066             :     {
    1067          12 :         pStateSet->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
    1068          12 :         if (IsEditable(xParentStates))
    1069          12 :             pStateSet->AddState(AccessibleStateType::EDITABLE);
    1070          12 :         pStateSet->AddState(AccessibleStateType::ENABLED);
    1071          12 :         pStateSet->AddState(AccessibleStateType::FOCUSABLE);
    1072          12 :         if (IsFocused())
    1073          12 :             pStateSet->AddState(AccessibleStateType::FOCUSED);
    1074          12 :         pStateSet->AddState(AccessibleStateType::MULTI_SELECTABLE);
    1075          12 :         pStateSet->AddState(AccessibleStateType::OPAQUE);
    1076          12 :         pStateSet->AddState(AccessibleStateType::SELECTABLE);
    1077          12 :         if (IsCompleteSheetSelected())
    1078           0 :             pStateSet->AddState(AccessibleStateType::SELECTED);
    1079          12 :         if (isShowing())
    1080          12 :             pStateSet->AddState(AccessibleStateType::SHOWING);
    1081          12 :         if (isVisible())
    1082          12 :             pStateSet->AddState(AccessibleStateType::VISIBLE);
    1083             :     }
    1084          24 :     return pStateSet;
    1085             : }
    1086             : 
    1087             :     ///=====  XAccessibleSelection  ===========================================
    1088             : 
    1089           0 : void SAL_CALL ScAccessibleSpreadsheet::selectAccessibleChild( sal_Int32 nChildIndex )
    1090             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
    1091             : {
    1092           0 :     SolarMutexGuard aGuard;
    1093           0 :     IsObjectValid();
    1094           0 :     if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
    1095           0 :         throw lang::IndexOutOfBoundsException();
    1096             : 
    1097           0 :     if (mpViewShell)
    1098             :     {
    1099           0 :         sal_Int32 nCol(getAccessibleColumn(nChildIndex));
    1100           0 :         sal_Int32 nRow(getAccessibleRow(nChildIndex));
    1101             : 
    1102           0 :         SelectCell(nRow, nCol, false);
    1103           0 :     }
    1104           0 : }
    1105             : 
    1106             : void SAL_CALL
    1107           0 :         ScAccessibleSpreadsheet::clearAccessibleSelection(  )
    1108             :         throw (uno::RuntimeException, std::exception)
    1109             : {
    1110           0 :     SolarMutexGuard aGuard;
    1111           0 :     IsObjectValid();
    1112           0 :     if (mpViewShell)
    1113             :     {
    1114           0 :         if (!IsFormulaMode())
    1115           0 :             mpViewShell->Unmark();
    1116           0 :     }
    1117           0 : }
    1118             : 
    1119           0 : void SAL_CALL ScAccessibleSpreadsheet::selectAllAccessibleChildren(  )
    1120             :     throw (uno::RuntimeException, std::exception)
    1121             : {
    1122           0 :     SolarMutexGuard aGuard;
    1123           0 :     IsObjectValid();
    1124           0 :     if (mpViewShell)
    1125             :     {
    1126           0 :         if (IsFormulaMode())
    1127             :         {
    1128           0 :             ScViewData *pViewData = mpViewShell->GetViewData();
    1129           0 :             mpViewShell->InitRefMode( 0, 0, pViewData->GetTabNo(), SC_REFTYPE_REF );
    1130           0 :             pViewData->SetRefStart(0,0,pViewData->GetTabNo());
    1131           0 :             pViewData->SetRefEnd(MAXCOL,MAXROW,pViewData->GetTabNo());
    1132           0 :             mpViewShell->UpdateRef(MAXCOL, MAXROW, pViewData->GetTabNo());
    1133             :         }
    1134             :         else
    1135           0 :             mpViewShell->SelectAll();
    1136           0 :     }
    1137           0 : }
    1138             : 
    1139             : sal_Int32 SAL_CALL
    1140           0 :         ScAccessibleSpreadsheet::getSelectedAccessibleChildCount(  )
    1141             :         throw (uno::RuntimeException, std::exception)
    1142             : {
    1143           0 :     SolarMutexGuard aGuard;
    1144           0 :     IsObjectValid();
    1145           0 :     sal_Int32 nResult(0);
    1146           0 :     if (mpViewShell)
    1147             :     {
    1148           0 :         if (IsFormulaMode())
    1149             :         {
    1150           0 :             nResult =  GetRowAll() * GetColAll() ;
    1151             :         }
    1152             :         else
    1153             :         {
    1154           0 :             if (!mpMarkedRanges)
    1155             :             {
    1156           0 :                 mpMarkedRanges = new ScRangeList();
    1157           0 :                 ScMarkData aMarkData(mpViewShell->GetViewData()->GetMarkData());
    1158           0 :                 aMarkData.FillRangeListWithMarks(mpMarkedRanges, false);
    1159             :             }
    1160             :             // is possible, because there shouldn't be overlapped ranges in it
    1161           0 :             if (mpMarkedRanges)
    1162           0 :                 nResult = mpMarkedRanges->GetCellCount();
    1163             :         }
    1164             :     }
    1165           0 :     return nResult;
    1166             : }
    1167             : 
    1168             : uno::Reference<XAccessible > SAL_CALL
    1169           0 :         ScAccessibleSpreadsheet::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
    1170             :         throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
    1171             : {
    1172           0 :     SolarMutexGuard aGuard;
    1173           0 :     IsObjectValid();
    1174           0 :     uno::Reference < XAccessible > xAccessible;
    1175           0 :     if (IsFormulaMode())
    1176             :     {
    1177           0 :         if(CheckChildIndex(nSelectedChildIndex))
    1178             :         {
    1179           0 :             ScAddress addr = GetChildIndexAddress(nSelectedChildIndex);
    1180           0 :             xAccessible = getAccessibleCellAt(addr.Row(), addr.Col());
    1181             :         }
    1182           0 :         return xAccessible;
    1183             :     }
    1184           0 :     if (mpViewShell)
    1185             :     {
    1186           0 :         if (!mpMarkedRanges)
    1187             :         {
    1188           0 :             mpMarkedRanges = new ScRangeList();
    1189           0 :             mpViewShell->GetViewData()->GetMarkData().FillRangeListWithMarks(mpMarkedRanges, false);
    1190             :         }
    1191           0 :         if (mpMarkedRanges)
    1192             :         {
    1193           0 :             if ((nSelectedChildIndex < 0) ||
    1194           0 :                     (mpMarkedRanges->GetCellCount() <= static_cast<sal_uInt32>(nSelectedChildIndex)))
    1195             :             {
    1196           0 :                 throw lang::IndexOutOfBoundsException();
    1197             :             }
    1198           0 :             ScMyAddress addr = CalcScAddressFromRangeList(mpMarkedRanges,nSelectedChildIndex);
    1199           0 :             if( m_mapSelectionSend.find(addr) != m_mapSelectionSend.end() )
    1200           0 :                 xAccessible = m_mapSelectionSend[addr];
    1201             :             else
    1202           0 :                 xAccessible = getAccessibleCellAt(addr.Row(), addr.Col());
    1203             :         }
    1204             :     }
    1205           0 :     return xAccessible;
    1206             : }
    1207             : 
    1208           0 : void SAL_CALL ScAccessibleSpreadsheet::deselectAccessibleChild( sal_Int32 nChildIndex )
    1209             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
    1210             : {
    1211           0 :     SolarMutexGuard aGuard;
    1212           0 :     IsObjectValid();
    1213             : 
    1214           0 :     if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
    1215           0 :         throw lang::IndexOutOfBoundsException();
    1216             : 
    1217           0 :     if (mpViewShell)
    1218             :     {
    1219           0 :         sal_Int32 nCol(getAccessibleColumn(nChildIndex));
    1220           0 :         sal_Int32 nRow(getAccessibleRow(nChildIndex));
    1221             : 
    1222           0 :         if (IsFormulaMode())
    1223             :         {
    1224           0 :             if(IsScAddrFormulaSel(
    1225           0 :                 ScAddress(static_cast<SCCOL>(nCol), nRow,mpViewShell->GetViewData()->GetTabNo()))
    1226             :                 )
    1227             :             {
    1228           0 :                 SelectCell(nRow, nCol, true);
    1229             :             }
    1230           0 :             return ;
    1231             :         }
    1232           0 :         if (mpViewShell->GetViewData()->GetMarkData().IsCellMarked(static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow)))
    1233           0 :             SelectCell(nRow, nCol, true);
    1234           0 :     }
    1235             : }
    1236             : 
    1237           0 : void ScAccessibleSpreadsheet::SelectCell(sal_Int32 nRow, sal_Int32 nCol, bool bDeselect)
    1238             : {
    1239           0 :     if (IsFormulaMode())
    1240             :     {
    1241           0 :         if (bDeselect)
    1242             :         {//??
    1243           0 :                 return;
    1244             :         }
    1245             :         else
    1246             :         {
    1247           0 :             ScViewData *pViewData = mpViewShell->GetViewData();
    1248             : 
    1249           0 :             mpViewShell->InitRefMode( static_cast<SCCOL>(nCol), nRow, pViewData->GetTabNo(), SC_REFTYPE_REF );
    1250           0 :             mpViewShell->UpdateRef(static_cast<SCCOL>(nCol), nRow, pViewData->GetTabNo());
    1251             :         }
    1252           0 :         return ;
    1253             :     }
    1254           0 :     mpViewShell->SetTabNo( maRange.aStart.Tab() );
    1255             : 
    1256           0 :     mpViewShell->DoneBlockMode( true ); // continue selecting
    1257           0 :     mpViewShell->InitBlockMode( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), maRange.aStart.Tab(), bDeselect, false, false );
    1258             : 
    1259           0 :     mpViewShell->SelectionChanged();
    1260             : }
    1261             : 
    1262             : /*
    1263             : void ScAccessibleSpreadsheet::CreateSortedMarkedCells()
    1264             : {
    1265             :     mpSortedMarkedCells = new std::vector<ScMyAddress>();
    1266             :     mpSortedMarkedCells->reserve(mpMarkedRanges->GetCellCount());
    1267             :     for ( size_t i = 0, ListSize = mpMarkedRanges->size(); i < ListSize; ++i )
    1268             :     {
    1269             :         ScRange* pRange = (*mpMarkedRanges)[i];
    1270             :         if (pRange->aStart.Tab() != pRange->aEnd.Tab())
    1271             :         {
    1272             :             if ((maActiveCell.Tab() >= pRange->aStart.Tab()) ||
    1273             :                 maActiveCell.Tab() <= pRange->aEnd.Tab())
    1274             :             {
    1275             :                 ScRange aRange(*pRange);
    1276             :                 aRange.aStart.SetTab(maActiveCell.Tab());
    1277             :                 aRange.aEnd.SetTab(maActiveCell.Tab());
    1278             :                 AddMarkedRange(aRange);
    1279             :             }
    1280             :             else
    1281             :             {
    1282             :                 OSL_FAIL("Range of wrong table");
    1283             :             }
    1284             :         }
    1285             :         else if(pRange->aStart.Tab() == maActiveCell.Tab())
    1286             :             AddMarkedRange(*pRange);
    1287             :         else
    1288             :         {
    1289             :             OSL_FAIL("Range of wrong table");
    1290             :         }
    1291             :     }
    1292             :     std::sort(mpSortedMarkedCells->begin(), mpSortedMarkedCells->end());
    1293             : }
    1294             : 
    1295             : void ScAccessibleSpreadsheet::AddMarkedRange(const ScRange& rRange)
    1296             : {
    1297             :     for (SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow)
    1298             :     {
    1299             :         for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
    1300             :         {
    1301             :             ScMyAddress aCell(nCol, nRow, maActiveCell.Tab());
    1302             :             mpSortedMarkedCells->push_back(aCell);
    1303             :         }
    1304             :     }
    1305             : }*/
    1306             : 
    1307             :     //=====  XServiceInfo  ====================================================
    1308             : 
    1309           0 : OUString SAL_CALL ScAccessibleSpreadsheet::getImplementationName(void)
    1310             :         throw (uno::RuntimeException, std::exception)
    1311             : {
    1312           0 :     return OUString("ScAccessibleSpreadsheet");
    1313             : }
    1314             : 
    1315             : uno::Sequence< OUString> SAL_CALL
    1316           0 :     ScAccessibleSpreadsheet::getSupportedServiceNames (void)
    1317             :         throw (uno::RuntimeException, std::exception)
    1318             : {
    1319           0 :     uno::Sequence< OUString > aSequence = ScAccessibleTableBase::getSupportedServiceNames();
    1320           0 :     sal_Int32 nOldSize(aSequence.getLength());
    1321           0 :     aSequence.realloc(nOldSize + 1);
    1322             : 
    1323           0 :     aSequence[nOldSize] = "com.sun.star.AccessibleSpreadsheet";
    1324             : 
    1325           0 :     return aSequence;
    1326             : }
    1327             : 
    1328             : //=====  XTypeProvider  =======================================================
    1329             : 
    1330             : uno::Sequence<sal_Int8> SAL_CALL
    1331           0 :     ScAccessibleSpreadsheet::getImplementationId(void)
    1332             :     throw (uno::RuntimeException, std::exception)
    1333             : {
    1334           0 :     return css::uno::Sequence<sal_Int8>();
    1335             : }
    1336             : 
    1337             : ///=====  XAccessibleEventBroadcaster  =====================================
    1338             : 
    1339           5 : void SAL_CALL ScAccessibleSpreadsheet::addAccessibleEventListener(const uno::Reference<XAccessibleEventListener>& xListener)
    1340             :         throw (uno::RuntimeException, std::exception)
    1341             : {
    1342           5 :     SolarMutexGuard aGuard;
    1343           5 :     IsObjectValid();
    1344           5 :     ScAccessibleTableBase::addAccessibleEventListener(xListener);
    1345             : 
    1346           5 : }
    1347             : 
    1348             : //====  internal  =========================================================
    1349             : 
    1350           1 : Rectangle ScAccessibleSpreadsheet::GetBoundingBoxOnScreen() const
    1351             :     throw (uno::RuntimeException, std::exception)
    1352             : {
    1353           1 :     Rectangle aRect;
    1354           1 :     if (mpViewShell)
    1355             :     {
    1356           1 :         Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
    1357           1 :         if (pWindow)
    1358           1 :             aRect = pWindow->GetWindowExtentsRelative(NULL);
    1359             :     }
    1360           1 :     return aRect;
    1361             : }
    1362             : 
    1363          17 : Rectangle ScAccessibleSpreadsheet::GetBoundingBox() const
    1364             :     throw (uno::RuntimeException, std::exception)
    1365             : {
    1366          17 :     Rectangle aRect;
    1367          17 :     if (mpViewShell)
    1368             :     {
    1369          17 :         Window* pWindow = mpViewShell->GetWindowByPos(meSplitPos);
    1370          17 :         if (pWindow)
    1371             :             //#101986#; extends to the same window, because the parent is the document and it has the same window
    1372          17 :             aRect = pWindow->GetWindowExtentsRelative(pWindow);
    1373             :     }
    1374          17 :     return aRect;
    1375             : }
    1376             : 
    1377          12 : bool ScAccessibleSpreadsheet::IsDefunc(
    1378             :     const uno::Reference<XAccessibleStateSet>& rxParentStates)
    1379             : {
    1380          48 :     return ScAccessibleContextBase::IsDefunc() || (mpViewShell == NULL) || !getAccessibleParent().is() ||
    1381          48 :         (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
    1382             : }
    1383             : 
    1384          12 : bool ScAccessibleSpreadsheet::IsEditable(
    1385             :     const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
    1386             : {
    1387          12 :     if (IsFormulaMode())
    1388             :     {
    1389           0 :         return false;
    1390             :     }
    1391          12 :     sal_Bool bProtected(false);
    1392          12 :     if (mpDoc && mpDoc->IsTabProtected(maRange.aStart.Tab()))
    1393           0 :         bProtected = true;
    1394          12 :     return !bProtected;
    1395             : }
    1396             : 
    1397          13 : bool ScAccessibleSpreadsheet::IsFocused()
    1398             : {
    1399          13 :     bool bFocused(false);
    1400          13 :     if (mpViewShell)
    1401             :     {
    1402          13 :         if (mpViewShell->GetViewData()->GetActivePart() == meSplitPos)
    1403          13 :             bFocused = mpViewShell->GetActiveWin()->HasFocus();
    1404             :     }
    1405          13 :     return bFocused;
    1406             : }
    1407             : 
    1408          12 : bool ScAccessibleSpreadsheet::IsCompleteSheetSelected()
    1409             : {
    1410          12 :     if (IsFormulaMode())
    1411             :     {
    1412           0 :         return false;
    1413             :     }
    1414             : 
    1415          12 :     bool bResult(false);
    1416          12 :     if(mpViewShell)
    1417             :     {
    1418             :         //#103800#; use a copy of MarkData
    1419          12 :         ScMarkData aMarkData(mpViewShell->GetViewData()->GetMarkData());
    1420          12 :         aMarkData.MarkToMulti();
    1421          12 :         if (aMarkData.IsAllMarked(maRange))
    1422           0 :             bResult = true;
    1423             :     }
    1424          12 :     return bResult;
    1425             : }
    1426             : 
    1427          14 : ScDocument* ScAccessibleSpreadsheet::GetDocument(ScTabViewShell* pViewShell)
    1428             : {
    1429          14 :     ScDocument* pDoc = NULL;
    1430          14 :     if (pViewShell)
    1431          14 :         pDoc = pViewShell->GetViewData()->GetDocument();
    1432          14 :     return pDoc;
    1433             : }
    1434             : 
    1435           2 : Rectangle ScAccessibleSpreadsheet::GetVisArea(ScTabViewShell* pViewShell, ScSplitPos eSplitPos)
    1436             : {
    1437           2 :     Rectangle aVisArea;
    1438           2 :     if (pViewShell)
    1439             :     {
    1440           2 :         Window* pWindow = pViewShell->GetWindowByPos(eSplitPos);
    1441           2 :         if (pWindow)
    1442             :         {
    1443           2 :             aVisArea.SetPos(pViewShell->GetViewData()->GetPixPos(eSplitPos));
    1444           2 :             aVisArea.SetSize(pWindow->GetSizePixel());
    1445             :         }
    1446             :     }
    1447           2 :     return aVisArea;
    1448             : }
    1449             : 
    1450           2 : Rectangle ScAccessibleSpreadsheet::GetVisCells(const Rectangle& rVisArea)
    1451             : {
    1452           2 :     if (mpViewShell)
    1453             :     {
    1454             :         SCsCOL nStartX, nEndX;
    1455             :         SCsROW nStartY, nEndY;
    1456             : 
    1457           2 :         mpViewShell->GetViewData()->GetPosFromPixel( 1, 1, meSplitPos, nStartX, nStartY);
    1458           2 :         mpViewShell->GetViewData()->GetPosFromPixel( rVisArea.GetWidth(), rVisArea.GetHeight(), meSplitPos, nEndX, nEndY);
    1459             : 
    1460           2 :         return Rectangle(nStartX, nStartY, nEndX, nEndY);
    1461             :     }
    1462             :     else
    1463           0 :         return Rectangle();
    1464             : }
    1465             : 
    1466           0 : sal_Bool SAL_CALL ScAccessibleSpreadsheet::selectRow( sal_Int32 row )
    1467             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
    1468             : {
    1469           0 :     SolarMutexGuard g;
    1470             : 
    1471           0 :     if (IsFormulaMode())
    1472             :     {
    1473           0 :         return sal_False;
    1474             :     }
    1475             : 
    1476           0 :     mpViewShell->SetTabNo( maRange.aStart.Tab() );
    1477           0 :     mpViewShell->DoneBlockMode( true ); // continue selecting
    1478           0 :     mpViewShell->InitBlockMode( 0, row, maRange.aStart.Tab(), false, false, true );
    1479           0 :     mpViewShell->MarkCursor( MAXCOL, row, maRange.aStart.Tab(), false, true );
    1480           0 :     mpViewShell->SelectionChanged();
    1481           0 :     return sal_True;
    1482             : }
    1483             : 
    1484           0 : sal_Bool SAL_CALL ScAccessibleSpreadsheet::selectColumn( sal_Int32 column )
    1485             :         throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
    1486             : {
    1487           0 :     SolarMutexGuard g;
    1488             : 
    1489           0 :     if (IsFormulaMode())
    1490             :     {
    1491           0 :         return sal_False;
    1492             :     }
    1493             : 
    1494           0 :     mpViewShell->SetTabNo( maRange.aStart.Tab() );
    1495           0 :     mpViewShell->DoneBlockMode( true ); // continue selecting
    1496           0 :     mpViewShell->InitBlockMode( static_cast<SCCOL>(column), 0, maRange.aStart.Tab(), false, true, false );
    1497           0 :     mpViewShell->MarkCursor( static_cast<SCCOL>(column), MAXROW, maRange.aStart.Tab(), true, false );
    1498           0 :     mpViewShell->SelectionChanged();
    1499           0 :     return sal_True;
    1500             : }
    1501             : 
    1502           0 : sal_Bool SAL_CALL ScAccessibleSpreadsheet::unselectRow( sal_Int32 row )
    1503             :         throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
    1504             : {
    1505           0 :     SolarMutexGuard g;
    1506             : 
    1507           0 :     if (IsFormulaMode())
    1508             :     {
    1509           0 :         return sal_False;
    1510             :     }
    1511             : 
    1512           0 :     mpViewShell->SetTabNo( maRange.aStart.Tab() );
    1513           0 :     mpViewShell->DoneBlockMode( true ); // continue selecting
    1514           0 :     mpViewShell->InitBlockMode( 0, row, maRange.aStart.Tab(), false, false, true, true );
    1515           0 :     mpViewShell->MarkCursor( MAXCOL, row, maRange.aStart.Tab(), false, true );
    1516           0 :     mpViewShell->SelectionChanged();
    1517           0 :     mpViewShell->DoneBlockMode( true );
    1518           0 :     return sal_True;
    1519             : }
    1520             : 
    1521           0 : sal_Bool SAL_CALL ScAccessibleSpreadsheet::unselectColumn( sal_Int32 column )
    1522             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
    1523             : {
    1524           0 :     SolarMutexGuard g;
    1525             : 
    1526           0 :     if (IsFormulaMode())
    1527             :     {
    1528           0 :         return sal_False;
    1529             :     }
    1530             : 
    1531           0 :     mpViewShell->SetTabNo( maRange.aStart.Tab() );
    1532           0 :     mpViewShell->DoneBlockMode( true ); // continue selecting
    1533           0 :     mpViewShell->InitBlockMode( static_cast<SCCOL>(column), 0, maRange.aStart.Tab(), false, true, false, true );
    1534           0 :     mpViewShell->MarkCursor( static_cast<SCCOL>(column), MAXROW, maRange.aStart.Tab(), true, false );
    1535           0 :     mpViewShell->SelectionChanged();
    1536           0 :     mpViewShell->DoneBlockMode( true );
    1537           0 :     return sal_True;
    1538             : }
    1539             : 
    1540           0 : void ScAccessibleSpreadsheet::FireFirstCellFocus()
    1541             : {
    1542           0 :     if (IsFormulaMode())
    1543             :     {
    1544           0 :         return ;
    1545             :     }
    1546           0 :     if (mbIsFocusSend)
    1547             :     {
    1548           0 :         return ;
    1549             :     }
    1550           0 :     mbIsFocusSend = true;
    1551           0 :     AccessibleEventObject aEvent;
    1552           0 :     aEvent.EventId = AccessibleEventId::ACTIVE_DESCENDANT_CHANGED;
    1553           0 :     aEvent.Source = uno::Reference< XAccessible >(this);
    1554           0 :     aEvent.NewValue <<= getAccessibleCellAt(maActiveCell.Row(), maActiveCell.Col());
    1555           0 :     CommitChange(aEvent);
    1556             : }
    1557             : 
    1558           0 : void ScAccessibleSpreadsheet::NotifyRefMode()
    1559             : {
    1560           0 :     ScViewData *pViewData = mpViewShell->GetViewData();
    1561           0 :     if (!pViewData->IsRefMode())
    1562             :         // Not in reference mode. Bail out.
    1563           0 :         return;
    1564             : 
    1565           0 :     sal_uInt16 nRefStartX =pViewData->GetRefStartX();
    1566           0 :     sal_Int32 nRefStartY=pViewData->GetRefStartY();
    1567           0 :     sal_uInt16 nRefEndX=pViewData->GetRefEndX();
    1568           0 :     sal_Int32 nRefEndY=pViewData->GetRefEndY();
    1569           0 :     ScAddress aFormulaAddr;
    1570           0 :     if(!GetFormulaCurrentFocusCell(aFormulaAddr))
    1571             :     {
    1572           0 :         return ;
    1573             :     }
    1574           0 :     if (m_aFormulaActiveCell != aFormulaAddr)
    1575             :     {//New Focus
    1576           0 :         m_nMinX =std::min(nRefStartX,nRefEndX);
    1577           0 :         m_nMaxX =std::max(nRefStartX,nRefEndX);
    1578           0 :         m_nMinY = std::min(nRefStartY,nRefEndY);
    1579           0 :         m_nMaxY = std::max(nRefStartY,nRefEndY);
    1580           0 :         RemoveFormulaSelection();
    1581           0 :         AccessibleEventObject aEvent;
    1582           0 :         aEvent.Source = uno::Reference< XAccessible >(this);
    1583           0 :         aEvent.EventId = AccessibleEventId::ACTIVE_DESCENDANT_CHANGED;
    1584           0 :         aEvent.Source = uno::Reference< XAccessible >(this);
    1585           0 :         aEvent.OldValue <<= uno::Reference<XAccessible>(m_pAccFormulaCell.get());
    1586           0 :         m_pAccFormulaCell = GetAccessibleCellAt(aFormulaAddr.Row(), aFormulaAddr.Col());
    1587           0 :         uno::Reference< XAccessible > xNew = m_pAccFormulaCell.get();
    1588           0 :         aEvent.NewValue <<= xNew;
    1589           0 :         CommitChange(aEvent);
    1590           0 :         if (nRefStartX == nRefEndX && nRefStartY == nRefEndY)
    1591             :         {//Selection Single
    1592           0 :             aEvent.EventId = AccessibleEventId::SELECTION_CHANGED;
    1593           0 :             aEvent.NewValue <<= xNew;
    1594           0 :             CommitChange(aEvent);
    1595           0 :             m_mapFormulaSelectionSend.insert(MAP_ADDR_XACC::value_type(aFormulaAddr,xNew));
    1596           0 :             m_vecFormulaLastMyAddr.clear();
    1597           0 :             m_vecFormulaLastMyAddr.push_back(aFormulaAddr);
    1598             :         }
    1599             :         else
    1600             :         {
    1601           0 :             VEC_MYADDR vecCurSel;
    1602           0 :             int nCurSize =  (m_nMaxX - m_nMinX +1)*(m_nMaxY - m_nMinY +1) ;
    1603           0 :             vecCurSel.reserve(nCurSize);
    1604           0 :             for (sal_uInt16 x = m_nMinX ; x <= m_nMaxX ; ++x)
    1605             :             {
    1606           0 :                 for (sal_Int32 y = m_nMinY ; y <= m_nMaxY ; ++y)
    1607             :                 {
    1608           0 :                     ScMyAddress aAddr(x,y,0);
    1609           0 :                     vecCurSel.push_back(aAddr);
    1610             :                 }
    1611             :             }
    1612           0 :             std::sort(vecCurSel.begin(), vecCurSel.end());
    1613           0 :             VEC_MYADDR vecNew;
    1614             :             std::set_difference(vecCurSel.begin(),vecCurSel.end(),
    1615             :                 m_vecFormulaLastMyAddr.begin(),m_vecFormulaLastMyAddr.end(),
    1616           0 :                 std::back_insert_iterator<VEC_MYADDR>(vecNew));
    1617           0 :             int nNewSize = vecNew.size();
    1618           0 :             if ( nNewSize > 10 )
    1619             :             {
    1620           0 :                 aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_WITHIN;
    1621           0 :                 aEvent.NewValue <<= ::com::sun::star::uno::Any();
    1622           0 :                 CommitChange(aEvent);
    1623             :             }
    1624             :             else
    1625             :             {
    1626           0 :                 VEC_MYADDR::iterator viAddr = vecNew.begin();
    1627           0 :                 for(; viAddr != vecNew.end() ; ++viAddr )
    1628             :                 {
    1629           0 :                     uno::Reference< XAccessible > xChild;
    1630           0 :                     if (*viAddr == aFormulaAddr)
    1631             :                     {
    1632           0 :                         xChild = m_pAccFormulaCell.get();
    1633             :                     }
    1634             :                     else
    1635             :                     {
    1636           0 :                         xChild = getAccessibleCellAt(viAddr->Row(),viAddr->Col());
    1637           0 :                         aEvent.EventId = AccessibleEventId::ACTIVE_DESCENDANT_CHANGED_NOFOCUS;
    1638           0 :                         aEvent.NewValue <<= xChild;
    1639           0 :                         CommitChange(aEvent);
    1640             :                     }
    1641           0 :                     aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_ADD;
    1642           0 :                     aEvent.NewValue <<= xChild;
    1643           0 :                     CommitChange(aEvent);
    1644           0 :                     m_mapFormulaSelectionSend.insert(MAP_ADDR_XACC::value_type(*viAddr,xChild));
    1645           0 :                 }
    1646             :             }
    1647           0 :             m_vecFormulaLastMyAddr.swap(vecCurSel);
    1648           0 :         }
    1649             :     }
    1650           0 :     m_aFormulaActiveCell = aFormulaAddr;
    1651             : }
    1652             : 
    1653           0 : void ScAccessibleSpreadsheet::RemoveFormulaSelection(bool bRemoveAll )
    1654             : {
    1655           0 :     AccessibleEventObject aEvent;
    1656           0 :     aEvent.Source = uno::Reference< XAccessible >(this);
    1657           0 :     aEvent.OldValue <<= ::com::sun::star::uno::Any();
    1658           0 :     MAP_ADDR_XACC::iterator miRemove = m_mapFormulaSelectionSend.begin();
    1659           0 :     for(;  miRemove != m_mapFormulaSelectionSend.end() ;)
    1660             :     {
    1661           0 :         if( !bRemoveAll && IsScAddrFormulaSel(miRemove->first) )
    1662             :         {
    1663           0 :             ++miRemove;
    1664           0 :             continue;
    1665             :         }
    1666           0 :         aEvent.EventId = AccessibleEventId::SELECTION_CHANGED_REMOVE;
    1667           0 :         aEvent.NewValue <<= miRemove->second;
    1668           0 :         CommitChange(aEvent);
    1669           0 :         MAP_ADDR_XACC::iterator miNext = miRemove;
    1670           0 :         ++miNext;
    1671           0 :         m_mapFormulaSelectionSend.erase(miRemove);
    1672           0 :         miRemove = miNext;
    1673           0 :     }
    1674           0 : }
    1675             : 
    1676           0 : bool ScAccessibleSpreadsheet::IsScAddrFormulaSel(const ScAddress &addr) const
    1677             : {
    1678           0 :     if( addr.Col() >= m_nMinX && addr.Col() <= m_nMaxX &&
    1679           0 :         addr.Row() >= m_nMinY && addr.Row() <= m_nMaxY &&
    1680           0 :         addr.Tab() == mpViewShell->GetViewData()->GetTabNo() )
    1681             :     {
    1682           0 :         return true;
    1683             :     }
    1684           0 :     return false;
    1685             : }
    1686             : 
    1687           0 : bool ScAccessibleSpreadsheet::CheckChildIndex(sal_Int32 nIndex) const
    1688             : {
    1689           0 :     sal_Int32 nMaxIndex = (m_nMaxX - m_nMinX +1)*(m_nMaxY - m_nMinY +1) -1 ;
    1690           0 :     return nIndex <= nMaxIndex && nIndex >= 0 ;
    1691             : }
    1692             : 
    1693           0 : ScAddress ScAccessibleSpreadsheet::GetChildIndexAddress(sal_Int32 nIndex) const
    1694             : {
    1695           0 :     sal_Int32 nRowAll = GetRowAll();
    1696           0 :     sal_uInt16  nColAll = GetColAll();
    1697           0 :     if (nIndex < 0 || nIndex >=  nRowAll * nColAll )
    1698             :     {
    1699           0 :         return ScAddress();
    1700             :     }
    1701             :     return ScAddress(
    1702           0 :         static_cast<SCCOL>((nIndex - nIndex % nRowAll) / nRowAll +  + m_nMinX),
    1703           0 :         nIndex % nRowAll + m_nMinY,
    1704           0 :         mpViewShell->GetViewData()->GetTabNo()
    1705           0 :         );
    1706             : }
    1707             : 
    1708           0 : sal_Int32 ScAccessibleSpreadsheet::GetAccessibleIndexFormula( sal_Int32 nRow, sal_Int32 nColumn )
    1709             : {
    1710           0 :     sal_uInt16 nColRelative = sal_uInt16(nColumn) - GetColAll();
    1711           0 :     sal_Int32 nRowRelative = nRow - GetRowAll();
    1712           0 :     if (nRow < 0 || nColumn < 0  || nRowRelative >= GetRowAll() || nColRelative >= GetColAll() )
    1713             :     {
    1714           0 :         return -1;
    1715             :     }
    1716           0 :     return GetRowAll() * nRowRelative + nColRelative;
    1717             : }
    1718             : 
    1719          53 : bool ScAccessibleSpreadsheet::IsFormulaMode()
    1720             : {
    1721          53 :     ScViewData *pViewData = mpViewShell->GetViewData();
    1722          53 :     m_bFormulaMode = pViewData->IsRefMode() || SC_MOD()->IsFormulaMode();
    1723          53 :     return m_bFormulaMode ;
    1724             : }
    1725             : 
    1726           0 : bool ScAccessibleSpreadsheet::GetFormulaCurrentFocusCell(ScAddress &addr)
    1727             : {
    1728           0 :     ScViewData *pViewData = mpViewShell->GetViewData();
    1729           0 :     sal_uInt16 nRefX=0;
    1730           0 :     sal_Int32 nRefY=0;
    1731           0 :     if(m_bFormulaLastMode)
    1732             :     {
    1733           0 :         nRefX=pViewData->GetRefEndX();
    1734           0 :         nRefY=pViewData->GetRefEndY();
    1735             :     }
    1736             :     else
    1737             :     {
    1738           0 :         nRefX=pViewData->GetRefStartX();
    1739           0 :         nRefY=pViewData->GetRefStartY();
    1740             :     }
    1741           0 :     if( /* Always true: nRefX >= 0 && */ nRefX <= MAXCOL && nRefY >= 0 && nRefY <= MAXROW)
    1742             :     {
    1743           0 :         addr = ScAddress(nRefX,nRefY,pViewData->GetTabNo());
    1744           0 :         return true;
    1745             :     }
    1746           0 :     return false;
    1747             : }
    1748             : 
    1749           0 : uno::Reference < XAccessible > ScAccessibleSpreadsheet::GetActiveCell()
    1750             : {
    1751           0 :     if( m_mapSelectionSend.find( maActiveCell ) != m_mapSelectionSend.end() )
    1752           0 :             return m_mapSelectionSend[maActiveCell];
    1753             :         else
    1754           0 :             return getAccessibleCellAt(maActiveCell.Row(), maActiveCell .Col());
    1755         102 : }
    1756             : 
    1757             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10