LCOV - code coverage report
Current view: top level - sw/source/core/access - accfrmobj.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 117 181 64.6 %
Date: 2014-04-11 Functions: 23 25 92.0 %
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 <accfrmobj.hxx>
      21             : 
      22             : #include <accmap.hxx>
      23             : #include <acccontext.hxx>
      24             : 
      25             : #include <viewsh.hxx>
      26             : #include <rootfrm.hxx>
      27             : #include <flyfrm.hxx>
      28             : #include <pagefrm.hxx>
      29             : #include <cellfrm.hxx>
      30             : #include <swtable.hxx>
      31             : #include <dflyobj.hxx>
      32             : #include <frmfmt.hxx>
      33             : #include <fmtanchr.hxx>
      34             : #include <dcontact.hxx>
      35             : 
      36             : #include <pam.hxx>
      37             : 
      38             : #include <vcl/window.hxx>
      39             : 
      40             : namespace sw { namespace access {
      41             : 
      42        1506 : SwAccessibleChild::SwAccessibleChild()
      43             :     : mpFrm( 0 )
      44             :     , mpDrawObj( 0 )
      45        1506 :     , mpWindow( 0 )
      46        1506 : {}
      47             : 
      48           0 : SwAccessibleChild::SwAccessibleChild( const SdrObject* pDrawObj )
      49             :     : mpFrm( 0 )
      50             :     , mpDrawObj( 0 )
      51           0 :     , mpWindow( 0 )
      52             : {
      53           0 :     Init( pDrawObj );
      54           0 : }
      55             : 
      56        9796 : SwAccessibleChild::SwAccessibleChild( const SwFrm* pFrm )
      57             :     : mpFrm( 0 )
      58             :     , mpDrawObj( 0 )
      59        9796 :     , mpWindow( 0 )
      60             : {
      61        9796 :     Init( pFrm );
      62        9796 : }
      63             : 
      64          84 : SwAccessibleChild::SwAccessibleChild( Window* pWindow )
      65             :     : mpFrm( 0 )
      66             :     , mpDrawObj( 0 )
      67          84 :     , mpWindow( 0 )
      68             : {
      69          84 :     Init( pWindow );
      70          84 : }
      71             : 
      72          77 : SwAccessibleChild::SwAccessibleChild( const SwFrm* pFrm,
      73             :                                       const SdrObject* pDrawObj,
      74             :                                       Window* pWindow )
      75             :     : mpFrm( 0 )
      76             :     , mpDrawObj( 0 )
      77          77 :     , mpWindow( 0 )
      78             : {
      79          77 :     if ( pFrm )
      80             :     {
      81          77 :         Init( pFrm );
      82             :     }
      83           0 :     else if ( pDrawObj )
      84             :     {
      85           0 :         Init( pDrawObj );
      86             :     }
      87           0 :     else if ( pWindow )
      88             :     {
      89           0 :         Init( pWindow );
      90             :     }
      91             :     OSL_ENSURE( (!pFrm || pFrm == mpFrm) &&
      92             :             (!pDrawObj || pDrawObj == mpDrawObj) &&
      93             :             (!pWindow || pWindow == mpWindow),
      94             :             "invalid frame/object/window combination" );
      95             : 
      96          77 : }
      97             : 
      98         146 : void SwAccessibleChild::Init( const SdrObject* pDrawObj )
      99             : {
     100         146 :     mpDrawObj = pDrawObj;
     101          28 :     mpFrm = mpDrawObj && mpDrawObj->ISA(SwVirtFlyDrawObj)
     102          28 :             ? static_cast < const SwVirtFlyDrawObj * >( mpDrawObj )->GetFlyFrm()
     103         174 :             : 0;
     104         146 :     mpWindow = 0;
     105         146 : }
     106             : 
     107       15056 : void SwAccessibleChild::Init( const SwFrm* pFrm )
     108             : {
     109       15056 :     mpFrm = pFrm;
     110       14376 :     mpDrawObj = mpFrm && mpFrm->IsFlyFrm()
     111          25 :                 ? static_cast < const SwFlyFrm * >( mpFrm )->GetVirtDrawObj()
     112       15081 :                 : 0;
     113       15056 :     mpWindow = 0;
     114       15056 : }
     115             : 
     116          84 : void SwAccessibleChild::Init( Window* pWindow )
     117             : {
     118          84 :     mpWindow = pWindow;
     119          84 :     mpFrm = 0;
     120          84 :     mpDrawObj = 0;
     121          84 : }
     122             : 
     123        7738 : bool SwAccessibleChild::IsAccessible( sal_Bool bPagePreview ) const
     124             : {
     125        7738 :     bool bRet( false );
     126             : 
     127        7738 :     if ( mpFrm )
     128             :     {
     129       12734 :         bRet = mpFrm->IsAccessibleFrm() &&
     130        5242 :                ( !mpFrm->IsCellFrm() ||
     131        5242 :                  static_cast<const SwCellFrm *>( mpFrm )->GetTabBox()->GetSttNd() != 0 ) &&
     132       20819 :                !mpFrm->IsInCoveredCell() &&
     133        4996 :                ( bPagePreview ||
     134       12734 :                  !mpFrm->IsPageFrm() );
     135             :     }
     136           0 :     else if ( mpDrawObj )
     137             :     {
     138           0 :         bRet = true;
     139             :     }
     140           0 :     else if ( mpWindow )
     141             :     {
     142           0 :         bRet = true;
     143             :     }
     144             : 
     145        7738 :     return bRet;
     146             : }
     147             : 
     148         386 : bool SwAccessibleChild::IsBoundAsChar() const
     149             : {
     150         386 :     bool bRet( false );
     151             : 
     152         386 :     if ( mpFrm )
     153             :     {
     154         410 :         bRet = mpFrm->IsFlyFrm() &&
     155         410 :                static_cast< const SwFlyFrm *>(mpFrm)->IsFlyInCntFrm();
     156             :     }
     157           0 :     else if ( mpDrawObj )
     158             :     {
     159           0 :         const SwFrmFmt* mpFrmFmt = ::FindFrmFmt( mpDrawObj );
     160             :         bRet = mpFrmFmt
     161           0 :                ? (FLY_AS_CHAR == mpFrmFmt->GetAnchor().GetAnchorId())
     162           0 :                : false;
     163             :     }
     164           0 :     else if ( mpWindow )
     165             :     {
     166           0 :         bRet = false;
     167             :     }
     168             : 
     169         386 :     return bRet;
     170             : }
     171             : 
     172         200 : SwAccessibleChild::SwAccessibleChild( const SwAccessibleChild& r )
     173             :     : mpFrm( r.mpFrm )
     174             :     , mpDrawObj( r.mpDrawObj )
     175         200 :     , mpWindow( r.mpWindow )
     176         200 : {}
     177             : 
     178         194 : SwAccessibleChild& SwAccessibleChild::operator=( const SwAccessibleChild& r )
     179             : {
     180         194 :     mpDrawObj = r.mpDrawObj;
     181         194 :     mpFrm = r.mpFrm;
     182         194 :     mpWindow = r.mpWindow;
     183             : 
     184         194 :     return *this;
     185             : }
     186             : 
     187         146 : SwAccessibleChild& SwAccessibleChild::operator=( const SdrObject* pDrawObj )
     188             : {
     189         146 :     Init( pDrawObj );
     190         146 :     return *this;
     191             : }
     192             : 
     193        5183 : SwAccessibleChild& SwAccessibleChild::operator=( const SwFrm* pFrm )
     194             : {
     195        5183 :     Init( pFrm );
     196        5183 :     return *this;
     197             : }
     198             : 
     199           0 : SwAccessibleChild& SwAccessibleChild::operator=( Window* pWindow )
     200             : {
     201           0 :     Init( pWindow );
     202           0 :     return *this;
     203             : }
     204             : 
     205        1522 : bool SwAccessibleChild::operator==( const SwAccessibleChild& r ) const
     206             : {
     207        2207 :     return mpFrm == r.mpFrm &&
     208        2207 :            mpDrawObj == r.mpDrawObj &&
     209        2207 :            mpWindow == r.mpWindow;
     210             : }
     211             : 
     212         943 : bool SwAccessibleChild::IsValid() const
     213             : {
     214        1504 :     return mpFrm != 0 ||
     215        1504 :            mpDrawObj != 0 ||
     216        1504 :            mpWindow != 0;
     217             : }
     218             : 
     219         822 : const SdrObject* SwAccessibleChild::GetDrawObject() const
     220             : {
     221         822 :     return mpDrawObj;
     222             : }
     223             : 
     224       18867 : const SwFrm *SwAccessibleChild::GetSwFrm() const
     225             : {
     226       18867 :     return mpFrm;
     227             : }
     228             : 
     229         804 : Window* SwAccessibleChild::GetWindow() const
     230             : {
     231         804 :     return mpWindow;
     232             : }
     233             : 
     234         653 : bool SwAccessibleChild::IsVisibleChildrenOnly() const
     235             : {
     236         653 :     bool bRet( false );
     237             : 
     238         653 :     if ( !mpFrm )
     239             :     {
     240           0 :         bRet = true;
     241             :     }
     242             :     else
     243             :     {
     244        1679 :         bRet = mpFrm->IsRootFrm() ||
     245        1073 :                !( mpFrm->IsTabFrm() ||
     246         517 :                   mpFrm->IsInTab() ||
     247         373 :                   ( IsBoundAsChar() &&
     248        1026 :                     static_cast<const SwFlyFrm*>(mpFrm)->GetAnchorFrm()->IsInTab() ) );
     249             :     }
     250             : 
     251         653 :     return bRet;
     252             : }
     253             : 
     254         585 : SwRect SwAccessibleChild::GetBox( const SwAccessibleMap& rAccMap ) const
     255             : {
     256         585 :     SwRect aBox;
     257             : 
     258         585 :     if ( mpFrm )
     259             :     {
     260         693 :         if ( mpFrm->IsPageFrm() &&
     261         108 :              static_cast< const SwPageFrm * >( mpFrm )->IsEmptyPage() )
     262             :         {
     263           0 :             aBox = SwRect( mpFrm->Frm().Left(), mpFrm->Frm().Top()-1, 1, 1 );
     264             :         }
     265         585 :         else if ( mpFrm->IsTabFrm() )
     266             :         {
     267          26 :             aBox = SwRect( mpFrm->Frm() );
     268          26 :             aBox.Intersection( mpFrm->GetUpper()->Frm() );
     269             :         }
     270             :         else
     271             :         {
     272         559 :             aBox = mpFrm->Frm();
     273             :         }
     274             :     }
     275           0 :     else if( mpDrawObj )
     276             :     {
     277           0 :         aBox = SwRect( mpDrawObj->GetCurrentBoundRect() );
     278             :     }
     279           0 :     else if ( mpWindow )
     280             :     {
     281           0 :         aBox = SwRect( rAccMap.GetShell()->GetWin()->PixelToLogic(
     282           0 :                                         Rectangle( mpWindow->GetPosPixel(),
     283           0 :                                                    mpWindow->GetSizePixel() ) ) );
     284             : }
     285             : 
     286         585 :     return aBox;
     287             : }
     288             : 
     289        3143 : SwRect SwAccessibleChild::GetBounds( const SwAccessibleMap& rAccMap ) const
     290             : {
     291        3143 :     SwRect aBound;
     292             : 
     293        3143 :     if( mpFrm )
     294             :     {
     295        3143 :         if( mpFrm->IsPageFrm() &&
     296           0 :             static_cast< const SwPageFrm * >( mpFrm )->IsEmptyPage() )
     297             :         {
     298           0 :             aBound = SwRect( mpFrm->Frm().Left(), mpFrm->Frm().Top()-1, 0, 0 );
     299             :         }
     300             :         else
     301        3143 :             aBound = mpFrm->PaintArea();
     302             :     }
     303           0 :     else if( mpDrawObj )
     304             :     {
     305           0 :         aBound = GetBox( rAccMap );
     306             :     }
     307           0 :     else if ( mpWindow )
     308             :     {
     309           0 :         aBound = GetBox( rAccMap );
     310             :     }
     311             : 
     312        3143 :     return aBound;
     313             : }
     314             : 
     315         326 : bool SwAccessibleChild::AlwaysIncludeAsChild() const
     316             : {
     317         326 :     bool bAlwaysIncludedAsChild( false );
     318             : 
     319         326 :     if ( mpWindow )
     320             :     {
     321           0 :         bAlwaysIncludedAsChild = true;
     322             :     }
     323             : 
     324         326 :     return bAlwaysIncludedAsChild;
     325             : }
     326             : 
     327        2516 : const SwFrm* SwAccessibleChild::GetParent( const sal_Bool bInPagePreview ) const
     328             : {
     329        2516 :     const SwFrm* pParent( 0 );
     330             : 
     331        2516 :     if ( mpFrm )
     332             :     {
     333        2516 :         if( mpFrm->IsFlyFrm() )
     334             :         {
     335           0 :             const SwFlyFrm* pFly = static_cast< const SwFlyFrm *>( mpFrm );
     336           0 :             if( pFly->IsFlyInCntFrm() )
     337             :             {
     338             :                 // For FLY_AS_CHAR the parent is the anchor
     339           0 :                 pParent = pFly->GetAnchorFrm();
     340             :                 OSL_ENSURE( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ),
     341             :                         "parent is not accessible" );
     342             :             }
     343             :             else
     344             :             {
     345             :                 // In any other case the parent is the root frm
     346             :                 // (in page preview, the page frame)
     347           0 :                 if( bInPagePreview )
     348           0 :                     pParent = pFly->FindPageFrm();
     349             :                 else
     350           0 :                     pParent = pFly->getRootFrm();
     351             :             }
     352             :         }
     353             :         else
     354             :         {
     355        2516 :             SwAccessibleChild aUpper( mpFrm->GetUpper() );
     356        9276 :             while( aUpper.GetSwFrm() && !aUpper.IsAccessible(bInPagePreview) )
     357             :             {
     358        4244 :                 aUpper = aUpper.GetSwFrm()->GetUpper();
     359             :             }
     360        2516 :             pParent = aUpper.GetSwFrm();
     361             :         }
     362             :     }
     363           0 :     else if( mpDrawObj )
     364             :     {
     365             :         const SwDrawContact *pContact =
     366           0 :             static_cast< const SwDrawContact* >( GetUserCall( mpDrawObj ) );
     367             :         OSL_ENSURE( pContact, "sdr contact is missing" );
     368           0 :         if( pContact )
     369             :         {
     370           0 :             const SwFrmFmt *pFrmFmt = pContact->GetFmt();
     371             :             OSL_ENSURE( pFrmFmt, "frame format is missing" );
     372           0 :             if( pFrmFmt && FLY_AS_CHAR == pFrmFmt->GetAnchor().GetAnchorId() )
     373             :             {
     374             :                 // For FLY_AS_CHAR the parent is the anchor
     375           0 :                 pParent = pContact->GetAnchorFrm();
     376             :                 OSL_ENSURE( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ),
     377             :                         "parent is not accessible" );
     378             : 
     379             :             }
     380             :             else
     381             :             {
     382             :                 // In any other case the parent is the root frm
     383           0 :                 if( bInPagePreview )
     384           0 :                     pParent = pContact->GetAnchorFrm()->FindPageFrm();
     385             :                 else
     386           0 :                     pParent = pContact->GetAnchorFrm()->getRootFrm();
     387             :             }
     388             :         }
     389             :     }
     390           0 :     else if ( mpWindow )
     391             :     {
     392             :         css::uno::Reference < css::accessibility::XAccessible > xAcc =
     393           0 :                                                     mpWindow->GetAccessible();
     394           0 :         if ( xAcc.is() )
     395             :         {
     396             :             css::uno::Reference < css::accessibility::XAccessibleContext > xAccContext =
     397           0 :                                                 xAcc->getAccessibleContext();
     398           0 :             if ( xAccContext.is() )
     399             :             {
     400             :                 css::uno::Reference < css::accessibility::XAccessible > xAccParent =
     401           0 :                                                 xAccContext->getAccessibleParent();
     402           0 :                 if ( xAccParent.is() )
     403             :                 {
     404             :                     SwAccessibleContext* pAccParentImpl =
     405           0 :                                 dynamic_cast< SwAccessibleContext *>( xAccParent.get() );
     406           0 :                     if ( pAccParentImpl )
     407             :                     {
     408           0 :                         pParent = pAccParentImpl->GetFrm();
     409             :                     }
     410           0 :                 }
     411           0 :             }
     412           0 :         }
     413             :     }
     414             : 
     415        2516 :     return pParent;
     416             : }
     417             : 
     418             : } } // eof of namespace sw::access
     419             : 
     420             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10