LCOV - code coverage report
Current view: top level - sw/source/core/access - accframe.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 146 208 70.2 %
Date: 2014-04-11 Functions: 18 19 94.7 %
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 <hintids.hxx>
      21             : #include <editeng/brushitem.hxx>
      22             : #include <flyfrm.hxx>
      23             : #include <rootfrm.hxx>
      24             : #include <txtfrm.hxx>
      25             : #include <sectfrm.hxx>
      26             : #include <section.hxx>
      27             : #include <viewsh.hxx>
      28             : #include <viewopt.hxx>
      29             : #include <doc.hxx>
      30             : #include <frmatr.hxx>
      31             : #include <pagefrm.hxx>
      32             : #include <pagedesc.hxx>
      33             : #include <fmtanchr.hxx>
      34             : #include <fldbas.hxx>
      35             : #include <dcontact.hxx>
      36             : #include <accmap.hxx>
      37             : #include <accfrmobjslist.hxx>
      38             : #include <accfrmobjmap.hxx>
      39             : #include <accframe.hxx>
      40             : 
      41             : using namespace sw::access;
      42             : 
      43             : // Regarding visibility (or in terms of accessibility: regarding the showing
      44             : // state): A frame is visible and therefore contained in the tree if its frame
      45             : // size overlaps with the visible area. The bounding box however is the
      46             : // frame's paint area.
      47         224 : sal_Int32 SwAccessibleFrame::GetChildCount( SwAccessibleMap& rAccMap,
      48             :                                             const SwRect& rVisArea,
      49             :                                             const SwFrm *pFrm,
      50             :                                             sal_Bool bInPagePreview )
      51             : {
      52         224 :     sal_Int32 nCount = 0;
      53             : 
      54         224 :     const SwAccessibleChildSList aVisList( rVisArea, *pFrm, rAccMap );
      55             : 
      56         224 :     SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
      57         712 :     while( aIter != aVisList.end() )
      58             :     {
      59         264 :         const SwAccessibleChild& rLower = *aIter;
      60         264 :         if( rLower.IsAccessible( bInPagePreview ) )
      61             :         {
      62         140 :             nCount++;
      63             :         }
      64         124 :         else if( rLower.GetSwFrm() )
      65             :         {
      66             :             // There are no unaccessible SdrObjects that count
      67             :             nCount += GetChildCount( rAccMap,
      68             :                                      rVisArea, rLower.GetSwFrm(),
      69         124 :                                      bInPagePreview );
      70             :         }
      71         264 :         ++aIter;
      72             :     }
      73             : 
      74         224 :     return nCount;
      75             : }
      76             : 
      77         116 : SwAccessibleChild SwAccessibleFrame::GetChild(
      78             :                                    SwAccessibleMap& rAccMap,
      79             :                                    const SwRect& rVisArea,
      80             :                                    const SwFrm& rFrm,
      81             :                                    sal_Int32& rPos,
      82             :                                    sal_Bool bInPagePreview )
      83             : {
      84         116 :     SwAccessibleChild aRet;
      85             : 
      86         116 :     if( rPos >= 0 )
      87             :     {
      88         112 :         if( SwAccessibleChildMap::IsSortingRequired( rFrm ) )
      89             :         {
      90             :             // We need a sorted list here
      91           2 :             const SwAccessibleChildMap aVisMap( rVisArea, rFrm, rAccMap );
      92           2 :             SwAccessibleChildMap::const_iterator aIter( aVisMap.begin() );
      93           7 :             while( aIter != aVisMap.end() && !aRet.IsValid() )
      94             :             {
      95           3 :                 const SwAccessibleChild& rLower = (*aIter).second;
      96           3 :                 if( rLower.IsAccessible( bInPagePreview ) )
      97             :                 {
      98           1 :                     if( 0 == rPos )
      99           1 :                         aRet = rLower;
     100             :                     else
     101           0 :                         rPos--;
     102             :                 }
     103           2 :                 else if( rLower.GetSwFrm() )
     104             :                 {
     105             :                     // There are no unaccessible SdrObjects that count
     106           6 :                     aRet = GetChild( rAccMap,
     107           2 :                                      rVisArea, *(rLower.GetSwFrm()), rPos,
     108           2 :                                      bInPagePreview );
     109             :                 }
     110           3 :                 ++aIter;
     111           2 :             }
     112             :         }
     113             :         else
     114             :         {
     115             :             // The unsorted list is sorted enough, because it returns lower
     116             :             // frames in the correct order.
     117         110 :             const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
     118         110 :             SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
     119         348 :             while( aIter != aVisList.end() && !aRet.IsValid() )
     120             :             {
     121         128 :                 const SwAccessibleChild& rLower = *aIter;
     122         128 :                 if( rLower.IsAccessible( bInPagePreview ) )
     123             :                 {
     124          71 :                     if( 0 == rPos )
     125          48 :                         aRet = rLower;
     126             :                     else
     127          23 :                         rPos--;
     128             :                 }
     129          57 :                 else if( rLower.GetSwFrm() )
     130             :                 {
     131             :                     // There are no unaccessible SdrObjects that count
     132         171 :                     aRet = GetChild( rAccMap,
     133          57 :                                      rVisArea, *(rLower.GetSwFrm()), rPos,
     134          57 :                                      bInPagePreview );
     135             :                 }
     136         128 :                 ++aIter;
     137             :             }
     138             :         }
     139             :     }
     140             : 
     141         116 :     return aRet;
     142             : }
     143             : 
     144          15 : sal_Bool SwAccessibleFrame::GetChildIndex(
     145             :                                    SwAccessibleMap& rAccMap,
     146             :                                    const SwRect& rVisArea,
     147             :                                    const SwFrm& rFrm,
     148             :                                    const SwAccessibleChild& rChild,
     149             :                                    sal_Int32& rPos,
     150             :                                    sal_Bool bInPagePreview )
     151             : {
     152          15 :     sal_Bool bFound = sal_False;
     153             : 
     154          15 :     if( SwAccessibleChildMap::IsSortingRequired( rFrm ) )
     155             :     {
     156             :         // We need a sorted list here
     157           0 :         const SwAccessibleChildMap aVisMap( rVisArea, rFrm, rAccMap );
     158           0 :         SwAccessibleChildMap::const_iterator aIter( aVisMap.begin() );
     159           0 :         while( aIter != aVisMap.end() && !bFound )
     160             :         {
     161           0 :             const SwAccessibleChild& rLower = (*aIter).second;
     162           0 :             if( rLower.IsAccessible( bInPagePreview ) )
     163             :             {
     164           0 :                 if( rChild == rLower )
     165           0 :                     bFound = sal_True;
     166             :                 else
     167           0 :                     rPos++;
     168             :             }
     169           0 :             else if( rLower.GetSwFrm() )
     170             :             {
     171             :                 // There are no unaccessible SdrObjects that count
     172             :                 bFound = GetChildIndex( rAccMap,
     173           0 :                                         rVisArea, *(rLower.GetSwFrm()), rChild,
     174           0 :                                         rPos, bInPagePreview );
     175             :             }
     176           0 :             ++aIter;
     177           0 :         }
     178             :     }
     179             :     else
     180             :     {
     181             :         // The unsorted list is sorted enough, because it returns lower
     182             :         // frames in the correct order.
     183             : 
     184          15 :         const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
     185          15 :         SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
     186          46 :         while( aIter != aVisList.end() && !bFound )
     187             :         {
     188          16 :             const SwAccessibleChild& rLower = *aIter;
     189          16 :             if( rLower.IsAccessible( bInPagePreview ) )
     190             :             {
     191           8 :                 if( rChild == rLower )
     192           7 :                     bFound = sal_True;
     193             :                 else
     194           1 :                     rPos++;
     195             :             }
     196           8 :             else if( rLower.GetSwFrm() )
     197             :             {
     198             :                 // There are no unaccessible SdrObjects that count
     199             :                 bFound = GetChildIndex( rAccMap,
     200           8 :                                         rVisArea, *(rLower.GetSwFrm()), rChild,
     201          16 :                                         rPos, bInPagePreview );
     202             :             }
     203          16 :             ++aIter;
     204             :         }
     205             :     }
     206             : 
     207          15 :     return bFound;
     208             : }
     209             : 
     210           4 : SwAccessibleChild SwAccessibleFrame::GetChildAtPixel( const SwRect& rVisArea,
     211             :                                           const SwFrm& rFrm,
     212             :                                           const Point& rPixPos,
     213             :                                           sal_Bool bInPagePreview,
     214             :                                           SwAccessibleMap& rAccMap )
     215             : {
     216           4 :     SwAccessibleChild aRet;
     217             : 
     218           4 :     if( SwAccessibleChildMap::IsSortingRequired( rFrm ) )
     219             :     {
     220             :         // We need a sorted list here, and we have to reverse iterate,
     221             :         // because objects in front should be returned.
     222           0 :         const SwAccessibleChildMap aVisMap( rVisArea, rFrm, rAccMap );
     223           0 :         SwAccessibleChildMap::const_reverse_iterator aRIter( aVisMap.rbegin() );
     224           0 :         while( aRIter != aVisMap.rend() && !aRet.IsValid() )
     225             :         {
     226           0 :             const SwAccessibleChild& rLower = (*aRIter).second;
     227             :             // A frame is returned if it's frame size is inside the visarea
     228             :             // and the positiion is inside the frame's paint area.
     229           0 :             if( rLower.IsAccessible( bInPagePreview ) )
     230             :             {
     231           0 :                 SwRect aLogBounds( rLower.GetBounds( rAccMap ) );
     232           0 :                 if( !aLogBounds.IsEmpty() )
     233             :                 {
     234           0 :                     Rectangle aPixBounds( rAccMap.CoreToPixel( aLogBounds.SVRect() ) );
     235           0 :                     if( aPixBounds.IsInside( rPixPos ) )
     236           0 :                         aRet = rLower;
     237             :                 }
     238             :             }
     239           0 :             else if( rLower.GetSwFrm() )
     240             :             {
     241             :                 // There are no unaccessible SdrObjects that count
     242           0 :                 aRet = GetChildAtPixel( rVisArea, *(rLower.GetSwFrm()), rPixPos,
     243           0 :                                         bInPagePreview, rAccMap );
     244             :             }
     245           0 :             ++aRIter;
     246           0 :         }
     247             :     }
     248             :     else
     249             :     {
     250             :         // The unsorted list is sorted enough, because it returns lower
     251             :         // frames in the correct order. Morover, we can iterate forward,
     252             :         // because the lowers don't overlap!
     253           4 :         const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
     254           4 :         SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
     255          12 :         while( aIter != aVisList.end() && !aRet.IsValid() )
     256             :         {
     257           4 :             const SwAccessibleChild& rLower = *aIter;
     258             :             // A frame is returned if it's frame size is inside the visarea
     259             :             // and the positiion is inside the frame's paint area.
     260           4 :             if( rLower.IsAccessible( bInPagePreview ) )
     261             :             {
     262           4 :                 SwRect aLogBounds( rLower.GetBounds( rAccMap ) );
     263           4 :                 if( !aLogBounds.IsEmpty() )
     264             :                 {
     265           4 :                     Rectangle aPixBounds( rAccMap.CoreToPixel( aLogBounds.SVRect() ) );
     266           4 :                     if( aPixBounds.IsInside( rPixPos ) )
     267           2 :                         aRet = rLower;
     268             :                 }
     269             :             }
     270           0 :             else if( rLower.GetSwFrm() )
     271             :             {
     272             :                 // There are no unaccessible SdrObjects that count
     273           0 :                 aRet = GetChildAtPixel( rVisArea, *(rLower.GetSwFrm()), rPixPos,
     274           0 :                                    bInPagePreview, rAccMap );
     275             :             }
     276           4 :             ++aIter;
     277             :         }
     278             :     }
     279             : 
     280           4 :     return aRet;
     281             : }
     282             : 
     283          16 : void SwAccessibleFrame::GetChildren( SwAccessibleMap& rAccMap,
     284             :                                      const SwRect& rVisArea,
     285             :                                      const SwFrm& rFrm,
     286             :                                      ::std::list< SwAccessibleChild >& rChildren,
     287             :                                      sal_Bool bInPagePreview )
     288             : {
     289          16 :     if( SwAccessibleChildMap::IsSortingRequired( rFrm ) )
     290             :     {
     291             :         // We need a sorted list here
     292           0 :         const SwAccessibleChildMap aVisMap( rVisArea, rFrm, rAccMap );
     293           0 :         SwAccessibleChildMap::const_iterator aIter( aVisMap.begin() );
     294           0 :         while( aIter != aVisMap.end() )
     295             :         {
     296           0 :             const SwAccessibleChild& rLower = (*aIter).second;
     297           0 :             if( rLower.IsAccessible( bInPagePreview ) )
     298             :             {
     299           0 :                 rChildren.push_back( rLower );
     300             :             }
     301           0 :             else if( rLower.GetSwFrm() )
     302             :             {
     303             :                 // There are no unaccessible SdrObjects that count
     304           0 :                 GetChildren( rAccMap, rVisArea, *(rLower.GetSwFrm()),
     305           0 :                              rChildren, bInPagePreview );
     306             :             }
     307           0 :             ++aIter;
     308           0 :         }
     309             :     }
     310             :     else
     311             :     {
     312             :         // The unsorted list is sorted enough, because it returns lower
     313             :         // frames in the correct order.
     314          16 :         const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
     315          16 :         SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
     316          40 :         while( aIter != aVisList.end() )
     317             :         {
     318           8 :             const SwAccessibleChild& rLower = *aIter;
     319           8 :             if( rLower.IsAccessible( bInPagePreview ) )
     320             :             {
     321           8 :                 rChildren.push_back( rLower );
     322             :             }
     323           0 :             else if( rLower.GetSwFrm() )
     324             :             {
     325             :                 // There are no unaccessible SdrObjects that count
     326           0 :                 GetChildren( rAccMap, rVisArea, *(rLower.GetSwFrm()),
     327           0 :                              rChildren, bInPagePreview );
     328             :             }
     329           8 :             ++aIter;
     330             :         }
     331             :     }
     332          16 : }
     333             : 
     334        3139 : SwRect SwAccessibleFrame::GetBounds( const SwAccessibleMap& rAccMap,
     335             :                                      const SwFrm *pFrm )
     336             : {
     337        3139 :     if( !pFrm )
     338           0 :         pFrm = GetFrm();
     339             : 
     340        3139 :     SwAccessibleChild aFrm( pFrm );
     341        3139 :     SwRect aBounds( aFrm.GetBounds( rAccMap ).Intersection( maVisArea ) );
     342        3139 :     return aBounds;
     343             : }
     344             : 
     345          73 : sal_Bool SwAccessibleFrame::IsEditable( SwViewShell *pVSh ) const
     346             : {
     347          73 :     const SwFrm *pFrm = GetFrm();
     348          73 :     if( !pFrm )
     349           0 :         return sal_False;
     350             : 
     351             :     OSL_ENSURE( pVSh, "no view shell" );
     352         146 :     if( pVSh && (pVSh->GetViewOptions()->IsReadonly() ||
     353          73 :                  pVSh->IsPreview()) )
     354           0 :         return sal_False;
     355             : 
     356          73 :     if( !pFrm->IsRootFrm() && pFrm->IsProtected() )
     357           0 :         return sal_False;
     358             : 
     359          73 :     return sal_True;
     360             : }
     361             : 
     362          73 : sal_Bool SwAccessibleFrame::IsOpaque( SwViewShell *pVSh ) const
     363             : {
     364          73 :     SwAccessibleChild aFrm( GetFrm() );
     365          73 :     if( !aFrm.GetSwFrm() )
     366           0 :         return sal_False;
     367             : 
     368             :     OSL_ENSURE( pVSh, "no view shell" );
     369          73 :     if( !pVSh )
     370           0 :         return sal_False;
     371             : 
     372          73 :     const SwViewOption *pVOpt = pVSh->GetViewOptions();
     373         127 :     do
     374             :     {
     375         139 :         const SwFrm *pFrm = aFrm.GetSwFrm();
     376         139 :         if( pFrm->IsRootFrm() )
     377          12 :             return sal_True;
     378             : 
     379         127 :         if( pFrm->IsPageFrm() && !pVOpt->IsPageBack() )
     380           0 :             return sal_False;
     381             : 
     382         127 :         const SvxBrushItem &rBack = pFrm->GetAttrSet()->GetBackground();
     383         254 :         if( !rBack.GetColor().GetTransparency() ||
     384         127 :              rBack.GetGraphicPos() != GPOS_NONE )
     385           0 :             return sal_True;
     386             : 
     387             :         // If a fly frame has a transparent background color, we have to consider the background.
     388             :         // But a background color "no fill"/"auto fill" should *not* be considered.
     389         508 :         if( pFrm->IsFlyFrm() &&
     390         256 :             (rBack.GetColor().GetTransparency() != 0) &&
     391         130 :             (rBack.GetColor() != COL_TRANSPARENT)
     392             :           )
     393           0 :             return sal_True;
     394             : 
     395         127 :         if( pFrm->IsSctFrm() )
     396             :         {
     397           0 :             const SwSection* pSection = ((SwSectionFrm*)pFrm)->GetSection();
     398           0 :             if( pSection && ( TOX_HEADER_SECTION == pSection->GetType() ||
     399           0 :                 TOX_CONTENT_SECTION == pSection->GetType() ) &&
     400           0 :                 !pVOpt->IsReadonly() &&
     401           0 :                 SwViewOption::IsIndexShadings() )
     402           0 :                 return sal_True;
     403             :         }
     404         127 :         if( pFrm->IsFlyFrm() )
     405           1 :             aFrm = static_cast<const SwFlyFrm*>(pFrm)->GetAnchorFrm();
     406             :         else
     407         126 :             aFrm = pFrm->GetUpper();
     408         127 :     } while( aFrm.GetSwFrm() && !aFrm.IsAccessible( IsInPagePreview() ) );
     409             : 
     410          61 :     return sal_False;
     411             : }
     412             : 
     413          73 : SwAccessibleFrame::SwAccessibleFrame( const SwRect& rVisArea,
     414             :                                       const SwFrm *pF,
     415             :                                       sal_Bool bIsPagePreview ) :
     416             :     maVisArea( rVisArea ),
     417             :     mpFrm( pF ),
     418             :     mbIsInPagePreview( bIsPagePreview ),
     419          73 :     bIsAccDocUse( sal_False )
     420             : {
     421          73 : }
     422             : 
     423          73 : SwAccessibleFrame::~SwAccessibleFrame()
     424             : {
     425          73 : }
     426             : 
     427        2516 : const SwFrm* SwAccessibleFrame::GetParent( const SwAccessibleChild& rFrmOrObj,
     428             :                                            sal_Bool bInPagePreview )
     429             : {
     430        2516 :     return rFrmOrObj.GetParent( bInPagePreview );
     431             : }
     432             : 
     433           2 : OUString SwAccessibleFrame::GetFormattedPageNumber() const
     434             : {
     435           2 :     sal_uInt16 nPageNum = GetFrm()->GetVirtPageNum();
     436             :     sal_uInt32 nFmt = GetFrm()->FindPageFrm()->GetPageDesc()
     437           2 :                               ->GetNumType().GetNumberingType();
     438           2 :     if( SVX_NUM_NUMBER_NONE == nFmt )
     439           0 :         nFmt = SVX_NUM_ARABIC;
     440             : 
     441           2 :     OUString sRet( FormatNumber( nPageNum, nFmt ) );
     442           2 :     return sRet;
     443             : }
     444             : 
     445         100 : sal_Int32 SwAccessibleFrame::GetChildCount( SwAccessibleMap& rAccMap ) const
     446             : {
     447         100 :     return GetChildCount( rAccMap, maVisArea, mpFrm, IsInPagePreview() );
     448             : }
     449             : 
     450          57 : sw::access::SwAccessibleChild SwAccessibleFrame::GetChild(
     451             :                                                 SwAccessibleMap& rAccMap,
     452             :                                                 sal_Int32 nPos ) const
     453             : {
     454          57 :     return SwAccessibleFrame::GetChild( rAccMap, maVisArea, *mpFrm, nPos, IsInPagePreview() );
     455             : }
     456             : 
     457           7 : sal_Int32 SwAccessibleFrame::GetChildIndex( SwAccessibleMap& rAccMap,
     458             :                                             const sw::access::SwAccessibleChild& rChild ) const
     459             : {
     460           7 :     sal_Int32 nPos = 0;
     461           7 :     return GetChildIndex( rAccMap, maVisArea, *mpFrm, rChild, nPos, IsInPagePreview() )
     462             :            ? nPos
     463           7 :            : -1L;
     464             : }
     465             : 
     466           4 : sw::access::SwAccessibleChild SwAccessibleFrame::GetChildAtPixel(
     467             :                                                 const Point& rPos,
     468             :                                                 SwAccessibleMap& rAccMap ) const
     469             : {
     470           4 :     return GetChildAtPixel( maVisArea, *mpFrm, rPos, IsInPagePreview(), rAccMap );
     471             : }
     472             : 
     473          16 : void SwAccessibleFrame::GetChildren( SwAccessibleMap& rAccMap,
     474             :                                      ::std::list< sw::access::SwAccessibleChild >& rChildren ) const
     475             : {
     476          16 :     GetChildren( rAccMap, maVisArea, *mpFrm, rChildren, IsInPagePreview() );
     477          16 : }
     478             : 
     479         147 : sal_Bool SwAccessibleFrame::IsShowing( const SwAccessibleMap& rAccMap,
     480             :                                        const sw::access::SwAccessibleChild& rFrmOrObj ) const
     481             : {
     482         147 :     return IsShowing( rFrmOrObj.GetBox( rAccMap ) );
     483             : }
     484             : 
     485             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10