LCOV - code coverage report
Current view: top level - sw/source/core/access - accframe.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 147 209 70.3 %
Date: 2014-11-03 Functions: 20 21 95.2 %
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         448 : sal_Int32 SwAccessibleFrame::GetChildCount( SwAccessibleMap& rAccMap,
      48             :                                             const SwRect& rVisArea,
      49             :                                             const SwFrm *pFrm,
      50             :                                             bool bInPagePreview )
      51             : {
      52         448 :     sal_Int32 nCount = 0;
      53             : 
      54         448 :     const SwAccessibleChildSList aVisList( rVisArea, *pFrm, rAccMap );
      55             : 
      56         448 :     SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
      57        1424 :     while( aIter != aVisList.end() )
      58             :     {
      59         528 :         const SwAccessibleChild& rLower = *aIter;
      60         528 :         if( rLower.IsAccessible( bInPagePreview ) )
      61             :         {
      62         280 :             nCount++;
      63             :         }
      64         248 :         else if( rLower.GetSwFrm() )
      65             :         {
      66             :             // There are no unaccessible SdrObjects that count
      67             :             nCount += GetChildCount( rAccMap,
      68             :                                      rVisArea, rLower.GetSwFrm(),
      69         248 :                                      bInPagePreview );
      70             :         }
      71         528 :         ++aIter;
      72             :     }
      73             : 
      74         448 :     return nCount;
      75             : }
      76             : 
      77         232 : SwAccessibleChild SwAccessibleFrame::GetChild(
      78             :                                    SwAccessibleMap& rAccMap,
      79             :                                    const SwRect& rVisArea,
      80             :                                    const SwFrm& rFrm,
      81             :                                    sal_Int32& rPos,
      82             :                                    bool bInPagePreview )
      83             : {
      84         232 :     SwAccessibleChild aRet;
      85             : 
      86         232 :     if( rPos >= 0 )
      87             :     {
      88         224 :         if( SwAccessibleChildMap::IsSortingRequired( rFrm ) )
      89             :         {
      90             :             // We need a sorted list here
      91           4 :             const SwAccessibleChildMap aVisMap( rVisArea, rFrm, rAccMap );
      92           4 :             SwAccessibleChildMap::const_iterator aIter( aVisMap.begin() );
      93          14 :             while( aIter != aVisMap.end() && !aRet.IsValid() )
      94             :             {
      95           6 :                 const SwAccessibleChild& rLower = (*aIter).second;
      96           6 :                 if( rLower.IsAccessible( bInPagePreview ) )
      97             :                 {
      98           2 :                     if( 0 == rPos )
      99           2 :                         aRet = rLower;
     100             :                     else
     101           0 :                         rPos--;
     102             :                 }
     103           4 :                 else if( rLower.GetSwFrm() )
     104             :                 {
     105             :                     // There are no unaccessible SdrObjects that count
     106          12 :                     aRet = GetChild( rAccMap,
     107           4 :                                      rVisArea, *(rLower.GetSwFrm()), rPos,
     108           4 :                                      bInPagePreview );
     109             :                 }
     110           6 :                 ++aIter;
     111           4 :             }
     112             :         }
     113             :         else
     114             :         {
     115             :             // The unsorted list is sorted enough, because it returns lower
     116             :             // frames in the correct order.
     117         220 :             const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
     118         220 :             SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
     119         696 :             while( aIter != aVisList.end() && !aRet.IsValid() )
     120             :             {
     121         256 :                 const SwAccessibleChild& rLower = *aIter;
     122         256 :                 if( rLower.IsAccessible( bInPagePreview ) )
     123             :                 {
     124         142 :                     if( 0 == rPos )
     125          96 :                         aRet = rLower;
     126             :                     else
     127          46 :                         rPos--;
     128             :                 }
     129         114 :                 else if( rLower.GetSwFrm() )
     130             :                 {
     131             :                     // There are no unaccessible SdrObjects that count
     132         342 :                     aRet = GetChild( rAccMap,
     133         114 :                                      rVisArea, *(rLower.GetSwFrm()), rPos,
     134         114 :                                      bInPagePreview );
     135             :                 }
     136         256 :                 ++aIter;
     137             :             }
     138             :         }
     139             :     }
     140             : 
     141         232 :     return aRet;
     142             : }
     143             : 
     144          30 : bool SwAccessibleFrame::GetChildIndex(
     145             :                                    SwAccessibleMap& rAccMap,
     146             :                                    const SwRect& rVisArea,
     147             :                                    const SwFrm& rFrm,
     148             :                                    const SwAccessibleChild& rChild,
     149             :                                    sal_Int32& rPos,
     150             :                                    bool bInPagePreview )
     151             : {
     152          30 :     bool bFound = false;
     153             : 
     154          30 :     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 = 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          30 :         const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
     185          30 :         SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
     186          92 :         while( aIter != aVisList.end() && !bFound )
     187             :         {
     188          32 :             const SwAccessibleChild& rLower = *aIter;
     189          32 :             if( rLower.IsAccessible( bInPagePreview ) )
     190             :             {
     191          16 :                 if( rChild == rLower )
     192          14 :                     bFound = true;
     193             :                 else
     194           2 :                     rPos++;
     195             :             }
     196          16 :             else if( rLower.GetSwFrm() )
     197             :             {
     198             :                 // There are no unaccessible SdrObjects that count
     199             :                 bFound = GetChildIndex( rAccMap,
     200          16 :                                         rVisArea, *(rLower.GetSwFrm()), rChild,
     201          32 :                                         rPos, bInPagePreview );
     202             :             }
     203          32 :             ++aIter;
     204             :         }
     205             :     }
     206             : 
     207          30 :     return bFound;
     208             : }
     209             : 
     210           8 : SwAccessibleChild SwAccessibleFrame::GetChildAtPixel( const SwRect& rVisArea,
     211             :                                           const SwFrm& rFrm,
     212             :                                           const Point& rPixPos,
     213             :                                           bool bInPagePreview,
     214             :                                           SwAccessibleMap& rAccMap )
     215             : {
     216           8 :     SwAccessibleChild aRet;
     217             : 
     218           8 :     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 position 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           8 :         const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
     254           8 :         SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
     255          24 :         while( aIter != aVisList.end() && !aRet.IsValid() )
     256             :         {
     257           8 :             const SwAccessibleChild& rLower = *aIter;
     258             :             // A frame is returned if it's frame size is inside the visarea
     259             :             // and the position is inside the frame's paint area.
     260           8 :             if( rLower.IsAccessible( bInPagePreview ) )
     261             :             {
     262           8 :                 SwRect aLogBounds( rLower.GetBounds( rAccMap ) );
     263           8 :                 if( !aLogBounds.IsEmpty() )
     264             :                 {
     265           8 :                     Rectangle aPixBounds( rAccMap.CoreToPixel( aLogBounds.SVRect() ) );
     266           8 :                     if( aPixBounds.IsInside( rPixPos ) )
     267           4 :                         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           8 :             ++aIter;
     277             :         }
     278             :     }
     279             : 
     280           8 :     return aRet;
     281             : }
     282             : 
     283          32 : void SwAccessibleFrame::GetChildren( SwAccessibleMap& rAccMap,
     284             :                                      const SwRect& rVisArea,
     285             :                                      const SwFrm& rFrm,
     286             :                                      ::std::list< SwAccessibleChild >& rChildren,
     287             :                                      bool bInPagePreview )
     288             : {
     289          32 :     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          32 :         const SwAccessibleChildSList aVisList( rVisArea, rFrm, rAccMap );
     315          32 :         SwAccessibleChildSList::const_iterator aIter( aVisList.begin() );
     316          80 :         while( aIter != aVisList.end() )
     317             :         {
     318          16 :             const SwAccessibleChild& rLower = *aIter;
     319          16 :             if( rLower.IsAccessible( bInPagePreview ) )
     320             :             {
     321          16 :                 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          16 :             ++aIter;
     330             :         }
     331             :     }
     332          32 : }
     333             : 
     334        3086 : SwRect SwAccessibleFrame::GetBounds( const SwAccessibleMap& rAccMap,
     335             :                                      const SwFrm *pFrm )
     336             : {
     337        3086 :     if( !pFrm )
     338           0 :         pFrm = GetFrm();
     339             : 
     340        3086 :     SwAccessibleChild aFrm( pFrm );
     341        3086 :     SwRect aBounds( aFrm.GetBounds( rAccMap ).Intersection( maVisArea ) );
     342        3086 :     return aBounds;
     343             : }
     344             : 
     345         208 : bool SwAccessibleFrame::IsEditable( SwViewShell *pVSh ) const
     346             : {
     347         208 :     const SwFrm *pFrm = GetFrm();
     348         208 :     if( !pFrm )
     349           0 :         return false;
     350             : 
     351             :     OSL_ENSURE( pVSh, "no view shell" );
     352         416 :     if( pVSh && (pVSh->GetViewOptions()->IsReadonly() ||
     353         208 :                  pVSh->IsPreview()) )
     354           0 :         return false;
     355             : 
     356         208 :     if( !pFrm->IsRootFrm() && pFrm->IsProtected() )
     357           0 :         return false;
     358             : 
     359         208 :     return true;
     360             : }
     361             : 
     362         208 : bool SwAccessibleFrame::IsOpaque( SwViewShell *pVSh ) const
     363             : {
     364         208 :     SwAccessibleChild aFrm( GetFrm() );
     365         208 :     if( !aFrm.GetSwFrm() )
     366           0 :         return false;
     367             : 
     368             :     OSL_ENSURE( pVSh, "no view shell" );
     369         208 :     if( !pVSh )
     370           0 :         return false;
     371             : 
     372         208 :     const SwViewOption *pVOpt = pVSh->GetViewOptions();
     373         356 :     do
     374             :     {
     375         380 :         const SwFrm *pFrm = aFrm.GetSwFrm();
     376         380 :         if( pFrm->IsRootFrm() )
     377          24 :             return true;
     378             : 
     379         356 :         if( pFrm->IsPageFrm() && !pVOpt->IsPageBack() )
     380           0 :             return false;
     381             : 
     382         356 :         const SvxBrushItem &rBack = pFrm->GetAttrSet()->GetBackground();
     383         712 :         if( !rBack.GetColor().GetTransparency() ||
     384         356 :              rBack.GetGraphicPos() != GPOS_NONE )
     385           0 :             return 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        1424 :         if( pFrm->IsFlyFrm() &&
     390         716 :             (rBack.GetColor().GetTransparency() != 0) &&
     391         362 :             (rBack.GetColor() != COL_TRANSPARENT)
     392             :           )
     393           0 :             return true;
     394             : 
     395         356 :         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 true;
     403             :         }
     404         356 :         if( pFrm->IsFlyFrm() )
     405           2 :             aFrm = static_cast<const SwFlyFrm*>(pFrm)->GetAnchorFrm();
     406             :         else
     407         354 :             aFrm = pFrm->GetUpper();
     408         356 :     } while( aFrm.GetSwFrm() && !aFrm.IsAccessible( IsInPagePreview() ) );
     409             : 
     410         184 :     return false;
     411             : }
     412             : 
     413         208 : SwAccessibleFrame::SwAccessibleFrame( const SwRect& rVisArea,
     414             :                                       const SwFrm *pF,
     415             :                                       bool bIsPagePreview ) :
     416             :     maVisArea( rVisArea ),
     417             :     mpFrm( pF ),
     418             :     mbIsInPagePreview( bIsPagePreview ),
     419         208 :     bIsAccDocUse( false )
     420             : {
     421         208 : }
     422             : 
     423         208 : SwAccessibleFrame::~SwAccessibleFrame()
     424             : {
     425         208 : }
     426             : 
     427        2892 : const SwFrm* SwAccessibleFrame::GetParent( const SwAccessibleChild& rFrmOrObj,
     428             :                                            bool bInPagePreview )
     429             : {
     430        2892 :     return rFrmOrObj.GetParent( bInPagePreview );
     431             : }
     432             : 
     433           4 : OUString SwAccessibleFrame::GetFormattedPageNumber() const
     434             : {
     435           4 :     sal_uInt16 nPageNum = GetFrm()->GetVirtPageNum();
     436             :     sal_uInt32 nFmt = GetFrm()->FindPageFrm()->GetPageDesc()
     437           4 :                               ->GetNumType().GetNumberingType();
     438           4 :     if( SVX_NUM_NUMBER_NONE == nFmt )
     439           0 :         nFmt = SVX_NUM_ARABIC;
     440             : 
     441           4 :     OUString sRet( FormatNumber( nPageNum, nFmt ) );
     442           4 :     return sRet;
     443             : }
     444             : 
     445         200 : sal_Int32 SwAccessibleFrame::GetChildCount( SwAccessibleMap& rAccMap ) const
     446             : {
     447         200 :     return GetChildCount( rAccMap, maVisArea, mpFrm, IsInPagePreview() );
     448             : }
     449             : 
     450         114 : sw::access::SwAccessibleChild SwAccessibleFrame::GetChild(
     451             :                                                 SwAccessibleMap& rAccMap,
     452             :                                                 sal_Int32 nPos ) const
     453             : {
     454         114 :     return SwAccessibleFrame::GetChild( rAccMap, maVisArea, *mpFrm, nPos, IsInPagePreview() );
     455             : }
     456             : 
     457          14 : sal_Int32 SwAccessibleFrame::GetChildIndex( SwAccessibleMap& rAccMap,
     458             :                                             const sw::access::SwAccessibleChild& rChild ) const
     459             : {
     460          14 :     sal_Int32 nPos = 0;
     461          14 :     return GetChildIndex( rAccMap, maVisArea, *mpFrm, rChild, nPos, IsInPagePreview() )
     462             :            ? nPos
     463          14 :            : -1L;
     464             : }
     465             : 
     466           8 : sw::access::SwAccessibleChild SwAccessibleFrame::GetChildAtPixel(
     467             :                                                 const Point& rPos,
     468             :                                                 SwAccessibleMap& rAccMap ) const
     469             : {
     470           8 :     return GetChildAtPixel( maVisArea, *mpFrm, rPos, IsInPagePreview(), rAccMap );
     471             : }
     472             : 
     473          32 : void SwAccessibleFrame::GetChildren( SwAccessibleMap& rAccMap,
     474             :                                      ::std::list< sw::access::SwAccessibleChild >& rChildren ) const
     475             : {
     476          32 :     GetChildren( rAccMap, maVisArea, *mpFrm, rChildren, IsInPagePreview() );
     477          32 : }
     478             : 
     479         364 : bool SwAccessibleFrame::IsShowing( const SwAccessibleMap& rAccMap,
     480             :                                        const sw::access::SwAccessibleChild& rFrmOrObj ) const
     481             : {
     482         364 :     return IsShowing( rFrmOrObj.GetBox( rAccMap ) );
     483         270 : }
     484             : 
     485             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10