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

Generated by: LCOV version 1.10