LCOV - code coverage report
Current view: top level - sw/source/core/access - accfrmobj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 111 175 63.4 %
Date: 2012-08-25 Functions: 23 25 92.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 59 162 36.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            :  /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <accfrmobj.hxx>
      31                 :            : 
      32                 :            : #include <accmap.hxx>
      33                 :            : #include <acccontext.hxx>
      34                 :            : 
      35                 :            : #include <viewsh.hxx>
      36                 :            : #include <rootfrm.hxx>
      37                 :            : #include <flyfrm.hxx>
      38                 :            : #include <pagefrm.hxx>
      39                 :            : #include <cellfrm.hxx>
      40                 :            : #include <swtable.hxx>
      41                 :            : #include <dflyobj.hxx>
      42                 :            : #include <frmfmt.hxx>
      43                 :            : #include <fmtanchr.hxx>
      44                 :            : #include <dcontact.hxx>
      45                 :            : 
      46                 :            : #include <vcl/window.hxx>
      47                 :            : 
      48                 :            : namespace css = ::com::sun::star;
      49                 :            : 
      50                 :            : namespace sw { namespace access {
      51                 :            : 
      52                 :       2766 : SwAccessibleChild::SwAccessibleChild()
      53                 :            :     : mpFrm( 0 )
      54                 :            :     , mpDrawObj( 0 )
      55                 :       2766 :     , mpWindow( 0 )
      56                 :       2766 : {}
      57                 :            : 
      58                 :          0 : SwAccessibleChild::SwAccessibleChild( const SdrObject* pDrawObj )
      59                 :            :     : mpFrm( 0 )
      60                 :            :     , mpDrawObj( 0 )
      61                 :          0 :     , mpWindow( 0 )
      62                 :            : {
      63                 :          0 :     Init( pDrawObj );
      64                 :          0 : }
      65                 :            : 
      66                 :      18374 : SwAccessibleChild::SwAccessibleChild( const SwFrm* pFrm )
      67                 :            :     : mpFrm( 0 )
      68                 :            :     , mpDrawObj( 0 )
      69                 :      18374 :     , mpWindow( 0 )
      70                 :            : {
      71                 :      18374 :     Init( pFrm );
      72                 :      18374 : }
      73                 :            : 
      74                 :        134 : SwAccessibleChild::SwAccessibleChild( Window* pWindow )
      75                 :            :     : mpFrm( 0 )
      76                 :            :     , mpDrawObj( 0 )
      77                 :        134 :     , mpWindow( 0 )
      78                 :            : {
      79                 :        134 :     Init( pWindow );
      80                 :        134 : }
      81                 :            : 
      82                 :            : 
      83                 :        117 : SwAccessibleChild::SwAccessibleChild( const SwFrm* pFrm,
      84                 :            :                                       const SdrObject* pDrawObj,
      85                 :            :                                       Window* pWindow )
      86                 :            : {
      87         [ +  - ]:        117 :     if ( pFrm )
      88                 :            :     {
      89                 :        117 :         Init( pFrm );
      90                 :            :     }
      91         [ #  # ]:          0 :     else if ( pDrawObj )
      92                 :            :     {
      93                 :          0 :         Init( pDrawObj );
      94                 :            :     }
      95         [ #  # ]:          0 :     else if ( pWindow )
      96                 :            :     {
      97                 :          0 :         Init( pWindow );
      98                 :            :     }
      99                 :            :     OSL_ENSURE( (!pFrm || pFrm == mpFrm) &&
     100                 :            :             (!pDrawObj || pDrawObj == mpDrawObj) &&
     101                 :            :             (!pWindow || pWindow == mpWindow),
     102                 :            :             "invalid frame/object/window combination" );
     103                 :            : 
     104                 :        117 : }
     105                 :            : 
     106                 :        298 : void SwAccessibleChild::Init( const SdrObject* pDrawObj )
     107                 :            : {
     108                 :        298 :     mpDrawObj = pDrawObj;
     109                 :         56 :     mpFrm = mpDrawObj && mpDrawObj->ISA(SwVirtFlyDrawObj)
     110                 :         56 :             ? static_cast < const SwVirtFlyDrawObj * >( mpDrawObj )->GetFlyFrm()
     111   [ +  +  +  - ]:        354 :             : 0;
     112                 :        298 :     mpWindow = 0;
     113                 :        298 : }
     114                 :            : 
     115                 :      28168 : void SwAccessibleChild::Init( const SwFrm* pFrm )
     116                 :            : {
     117                 :      28168 :     mpFrm = pFrm;
     118                 :      26996 :     mpDrawObj = mpFrm && mpFrm->IsFlyFrm()
     119                 :         50 :                 ? static_cast < const SwFlyFrm * >( mpFrm )->GetVirtDrawObj()
     120   [ +  +  +  + ]:      55164 :                 : 0;
     121                 :      28168 :     mpWindow = 0;
     122                 :      28168 : }
     123                 :            : 
     124                 :        134 : void SwAccessibleChild::Init( Window* pWindow )
     125                 :            : {
     126                 :        134 :     mpWindow = pWindow;
     127                 :        134 :     mpFrm = 0;
     128                 :        134 :     mpDrawObj = 0;
     129                 :        134 : }
     130                 :            : 
     131                 :      14604 : bool SwAccessibleChild::IsAccessible( sal_Bool bPagePreview ) const
     132                 :            : {
     133                 :      14604 :     bool bRet( false );
     134                 :            : 
     135         [ +  - ]:      14604 :     if ( mpFrm )
     136                 :            :     {
     137                 :      14604 :         bRet = mpFrm->IsAccessibleFrm() &&
     138                 :       9371 :                ( !mpFrm->IsCellFrm() ||
     139                 :        294 :                  static_cast<const SwCellFrm *>( mpFrm )->GetTabBox()->GetSttNd() != 0 ) &&
     140                 :       9371 :                !mpFrm->IsInCoveredCell() &&
     141                 :            :                ( bPagePreview ||
     142 [ +  - ][ +  + ]:      33640 :                  !mpFrm->IsPageFrm() );
           [ +  +  +  +  
             +  -  +  - ]
     143                 :            :     }
     144         [ #  # ]:          0 :     else if ( mpDrawObj )
     145                 :            :     {
     146                 :          0 :         bRet = true;
     147                 :            :     }
     148         [ #  # ]:          0 :     else if ( mpWindow )
     149                 :            :     {
     150                 :          0 :         bRet = true;
     151                 :            :     }
     152                 :            : 
     153                 :      14604 :     return bRet;
     154                 :            : }
     155                 :            : 
     156                 :        776 : bool SwAccessibleChild::IsBoundAsChar() const
     157                 :            : {
     158                 :        776 :     bool bRet( false );
     159                 :            : 
     160         [ +  - ]:        776 :     if ( mpFrm )
     161                 :            :     {
     162                 :        776 :         bRet = mpFrm->IsFlyFrm() &&
     163 [ -  + ][ +  + ]:        776 :                static_cast< const SwFlyFrm *>(mpFrm)->IsFlyInCntFrm();
     164                 :            :     }
     165         [ #  # ]:          0 :     else if ( mpDrawObj )
     166                 :            :     {
     167                 :          0 :         const SwFrmFmt* mpFrmFmt = ::FindFrmFmt( mpDrawObj );
     168                 :            :         bRet = mpFrmFmt
     169                 :          0 :                ? (FLY_AS_CHAR == mpFrmFmt->GetAnchor().GetAnchorId())
     170   [ #  #  #  # ]:          0 :                : false;
     171                 :            :     }
     172         [ #  # ]:          0 :     else if ( mpWindow )
     173                 :            :     {
     174                 :          0 :         bRet = false;
     175                 :            :     }
     176                 :            : 
     177                 :        776 :     return bRet;
     178                 :            : }
     179                 :            : 
     180                 :        308 : SwAccessibleChild::SwAccessibleChild( const SwAccessibleChild& r )
     181                 :            :     : mpFrm( r.mpFrm )
     182                 :            :     , mpDrawObj( r.mpDrawObj )
     183                 :        308 :     , mpWindow( r.mpWindow )
     184                 :        308 : {}
     185                 :            : 
     186                 :        344 : SwAccessibleChild& SwAccessibleChild::operator=( const SwAccessibleChild& r )
     187                 :            : {
     188                 :        344 :     mpDrawObj = r.mpDrawObj;
     189                 :        344 :     mpFrm = r.mpFrm;
     190                 :        344 :     mpWindow = r.mpWindow;
     191                 :            : 
     192                 :        344 :     return *this;
     193                 :            : }
     194                 :            : 
     195                 :        298 : SwAccessibleChild& SwAccessibleChild::operator=( const SdrObject* pDrawObj )
     196                 :            : {
     197                 :        298 :     Init( pDrawObj );
     198                 :        298 :     return *this;
     199                 :            : }
     200                 :            : 
     201                 :       9677 : SwAccessibleChild& SwAccessibleChild::operator=( const SwFrm* pFrm )
     202                 :            : {
     203                 :       9677 :     Init( pFrm );
     204                 :       9677 :     return *this;
     205                 :            : }
     206                 :            : 
     207                 :          0 : SwAccessibleChild& SwAccessibleChild::operator=( Window* pWindow )
     208                 :            : {
     209                 :          0 :     Init( pWindow );
     210                 :          0 :     return *this;
     211                 :            : }
     212                 :            : 
     213                 :       2556 : bool SwAccessibleChild::operator==( const SwAccessibleChild& r ) const
     214                 :            : {
     215                 :            :     return mpFrm == r.mpFrm &&
     216                 :            :            mpDrawObj == r.mpDrawObj &&
     217 [ +  + ][ +  - ]:       2556 :            mpWindow == r.mpWindow;
                 [ +  - ]
     218                 :            : }
     219                 :            : 
     220                 :       1862 : bool SwAccessibleChild::IsValid() const
     221                 :            : {
     222                 :            :     return mpFrm != 0 ||
     223                 :            :            mpDrawObj != 0 ||
     224 [ +  + ][ +  - ]:       1862 :            mpWindow != 0;
                 [ -  + ]
     225                 :            : }
     226                 :            : 
     227                 :       1334 : const SdrObject* SwAccessibleChild::GetDrawObject() const
     228                 :            : {
     229                 :       1334 :     return mpDrawObj;
     230                 :            : }
     231                 :            : 
     232                 :      34807 : const SwFrm *SwAccessibleChild::GetSwFrm() const
     233                 :            : {
     234                 :      34807 :     return mpFrm;
     235                 :            : }
     236                 :            : 
     237                 :       1304 : Window* SwAccessibleChild::GetWindow() const
     238                 :            : {
     239                 :       1304 :     return mpWindow;
     240                 :            : }
     241                 :            : 
     242                 :       1235 : bool SwAccessibleChild::IsVisibleChildrenOnly() const
     243                 :            : {
     244                 :       1235 :     bool bRet( false );
     245                 :            : 
     246         [ -  + ]:       1235 :     if ( !mpFrm )
     247                 :            :     {
     248                 :          0 :         bRet = true;
     249                 :            :     }
     250                 :            :     else
     251                 :            :     {
     252                 :       1235 :         bRet = mpFrm->IsRootFrm() ||
     253                 :       1056 :                !( mpFrm->IsTabFrm() ||
     254                 :        976 :                   mpFrm->IsInTab() ||
     255                 :        750 :                   ( IsBoundAsChar() &&
     256 [ #  # ][ +  +  :       4017 :                     static_cast<const SwFlyFrm*>(mpFrm)->GetAnchorFrm()->IsInTab() ) );
          +  +  +  +  -  
                      + ]
     257                 :            :     }
     258                 :            : 
     259                 :       1235 :     return bRet;
     260                 :            : }
     261                 :            : 
     262                 :       1086 : SwRect SwAccessibleChild::GetBox( const SwAccessibleMap& rAccMap ) const
     263                 :            : {
     264                 :       1086 :     SwRect aBox;
     265                 :            : 
     266         [ +  - ]:       1086 :     if ( mpFrm )
     267                 :            :     {
     268   [ +  +  -  + ]:       1308 :         if ( mpFrm->IsPageFrm() &&
                 [ -  + ]
     269                 :        222 :              static_cast< const SwPageFrm * >( mpFrm )->IsEmptyPage() )
     270                 :            :         {
     271                 :          0 :             aBox = SwRect( mpFrm->Frm().Left(), mpFrm->Frm().Top()-1, 1, 1 );
     272                 :            :         }
     273         [ +  + ]:       1086 :         else if ( mpFrm->IsTabFrm() )
     274                 :            :         {
     275                 :         34 :             aBox = SwRect( mpFrm->Frm() );
     276                 :         34 :             aBox.Intersection( mpFrm->GetUpper()->Frm() );
     277                 :            :         }
     278                 :            :         else
     279                 :            :         {
     280                 :       1052 :             aBox = mpFrm->Frm();
     281                 :            :         }
     282                 :            :     }
     283         [ #  # ]:          0 :     else if( mpDrawObj )
     284                 :            :     {
     285                 :          0 :         aBox = SwRect( mpDrawObj->GetCurrentBoundRect() );
     286                 :            :     }
     287         [ #  # ]:          0 :     else if ( mpWindow )
     288                 :            :     {
     289                 :          0 :         aBox = SwRect( rAccMap.GetShell()->GetWin()->PixelToLogic(
     290                 :          0 :                                         Rectangle( mpWindow->GetPosPixel(),
     291         [ #  # ]:          0 :                                                    mpWindow->GetSizePixel() ) ) );
           [ #  #  #  # ]
                 [ #  # ]
     292                 :            : }
     293                 :            : 
     294                 :       1086 :     return aBox;
     295                 :            : }
     296                 :            : 
     297                 :       5938 : SwRect SwAccessibleChild::GetBounds( const SwAccessibleMap& rAccMap ) const
     298                 :            : {
     299                 :       5938 :     SwRect aBound;
     300                 :            : 
     301         [ +  - ]:       5938 :     if( mpFrm )
     302                 :            :     {
     303   [ -  +  #  # ]:       5938 :         if( mpFrm->IsPageFrm() &&
                 [ -  + ]
     304                 :          0 :             static_cast< const SwPageFrm * >( mpFrm )->IsEmptyPage() )
     305                 :            :         {
     306                 :          0 :             aBound = SwRect( mpFrm->Frm().Left(), mpFrm->Frm().Top()-1, 0, 0 );
     307                 :            :         }
     308                 :            :         else
     309                 :       5938 :             aBound = mpFrm->PaintArea();
     310                 :            :     }
     311         [ #  # ]:          0 :     else if( mpDrawObj )
     312                 :            :     {
     313                 :          0 :         aBound = GetBox( rAccMap );
     314                 :            :     }
     315         [ #  # ]:          0 :     else if ( mpWindow )
     316                 :            :     {
     317                 :          0 :         aBound = GetBox( rAccMap );
     318                 :            :     }
     319                 :            : 
     320                 :       5938 :     return aBound;
     321                 :            : }
     322                 :            : 
     323                 :        653 : bool SwAccessibleChild::AlwaysIncludeAsChild() const
     324                 :            : {
     325                 :        653 :     bool bAlwaysIncludedAsChild( false );
     326                 :            : 
     327         [ -  + ]:        653 :     if ( mpWindow )
     328                 :            :     {
     329                 :          0 :         bAlwaysIncludedAsChild = true;
     330                 :            :     }
     331                 :            : 
     332                 :        653 :     return bAlwaysIncludedAsChild;
     333                 :            : }
     334                 :            : 
     335                 :       4798 : const SwFrm* SwAccessibleChild::GetParent( const sal_Bool bInPagePreview ) const
     336                 :            : {
     337                 :       4798 :     const SwFrm* pParent( 0 );
     338                 :            : 
     339         [ +  - ]:       4798 :     if ( mpFrm )
     340                 :            :     {
     341         [ -  + ]:       4798 :         if( mpFrm->IsFlyFrm() )
     342                 :            :         {
     343                 :          0 :             const SwFlyFrm* pFly = static_cast< const SwFlyFrm *>( mpFrm );
     344         [ #  # ]:          0 :             if( pFly->IsFlyInCntFrm() )
     345                 :            :             {
     346                 :            :                 // For FLY_AS_CHAR the parent is the anchor
     347                 :          0 :                 pParent = pFly->GetAnchorFrm();
     348                 :            :                 OSL_ENSURE( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ),
     349                 :            :                         "parent is not accessible" );
     350                 :            :             }
     351                 :            :             else
     352                 :            :             {
     353                 :            :                 // In any other case the parent is the root frm
     354                 :            :                 // (in page preview, the page frame)
     355         [ #  # ]:          0 :                 if( bInPagePreview )
     356                 :          0 :                     pParent = pFly->FindPageFrm();
     357                 :            :                 else
     358                 :          0 :                     pParent = pFly->getRootFrm();
     359                 :            :             }
     360                 :            :         }
     361                 :            :         else
     362                 :            :         {
     363         [ +  - ]:       4798 :             SwAccessibleChild aUpper( mpFrm->GetUpper() );
     364 [ +  - ][ +  - ]:      13016 :             while( aUpper.GetSwFrm() && !aUpper.IsAccessible(bInPagePreview) )
         [ +  + ][ +  + ]
     365                 :            :             {
     366         [ +  - ]:       8218 :                 aUpper = aUpper.GetSwFrm()->GetUpper();
     367                 :            :             }
     368                 :       4798 :             pParent = aUpper.GetSwFrm();
     369                 :            :         }
     370                 :            :     }
     371         [ #  # ]:          0 :     else if( mpDrawObj )
     372                 :            :     {
     373                 :            :         const SwDrawContact *pContact =
     374                 :          0 :             static_cast< const SwDrawContact* >( GetUserCall( mpDrawObj ) );
     375                 :            :         OSL_ENSURE( pContact, "sdr contact is missing" );
     376         [ #  # ]:          0 :         if( pContact )
     377                 :            :         {
     378                 :          0 :             const SwFrmFmt *pFrmFmt = pContact->GetFmt();
     379                 :            :             OSL_ENSURE( pFrmFmt, "frame format is missing" );
     380 [ #  # ][ #  # ]:          0 :             if( pFrmFmt && FLY_AS_CHAR == pFrmFmt->GetAnchor().GetAnchorId() )
                 [ #  # ]
     381                 :            :             {
     382                 :            :                 // For FLY_AS_CHAR the parent is the anchor
     383                 :          0 :                 pParent = pContact->GetAnchorFrm();
     384                 :            :                 OSL_ENSURE( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ),
     385                 :            :                         "parent is not accessible" );
     386                 :            : 
     387                 :            :             }
     388                 :            :             else
     389                 :            :             {
     390                 :            :                 // In any other case the parent is the root frm
     391         [ #  # ]:          0 :                 if( bInPagePreview )
     392                 :          0 :                     pParent = pContact->GetAnchorFrm()->FindPageFrm();
     393                 :            :                 else
     394                 :          0 :                     pParent = pContact->GetAnchorFrm()->getRootFrm();
     395                 :            :             }
     396                 :            :         }
     397                 :            :     }
     398         [ #  # ]:          0 :     else if ( mpWindow )
     399                 :            :     {
     400                 :            :         css::uno::Reference < css::accessibility::XAccessible > xAcc =
     401         [ #  # ]:          0 :                                                     mpWindow->GetAccessible();
     402         [ #  # ]:          0 :         if ( xAcc.is() )
     403                 :            :         {
     404                 :            :             css::uno::Reference < css::accessibility::XAccessibleContext > xAccContext =
     405 [ #  # ][ #  # ]:          0 :                                                 xAcc->getAccessibleContext();
     406         [ #  # ]:          0 :             if ( xAccContext.is() )
     407                 :            :             {
     408                 :            :                 css::uno::Reference < css::accessibility::XAccessible > xAccParent =
     409 [ #  # ][ #  # ]:          0 :                                                 xAccContext->getAccessibleParent();
     410         [ #  # ]:          0 :                 if ( xAccParent.is() )
     411                 :            :                 {
     412                 :            :                     SwAccessibleContext* pAccParentImpl =
     413 [ #  # ][ #  # ]:          0 :                                 dynamic_cast< SwAccessibleContext *>( xAccParent.get() );
     414         [ #  # ]:          0 :                     if ( pAccParentImpl )
     415                 :            :                     {
     416                 :          0 :                         pParent = pAccParentImpl->GetFrm();
     417                 :            :                     }
     418                 :          0 :                 }
     419                 :          0 :             }
     420                 :          0 :         }
     421                 :            :     }
     422                 :            : 
     423                 :       4798 :     return pParent;
     424                 :            : }
     425                 :            : 
     426                 :            : } } // eof of namespace sw::access
     427                 :            : 
     428                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10