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

Generated by: LCOV version 1.10