LCOV - code coverage report
Current view: top level - sw/source/core/access - accframebase.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 84 176 47.7 %
Date: 2014-04-11 Functions: 11 15 73.3 %
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 <com/sun/star/accessibility/AccessibleStateType.hpp>
      21             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      22             : #include <unotools/accessiblestatesethelper.hxx>
      23             : #include <osl/mutex.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <vcl/window.hxx>
      26             : #include <frmfmt.hxx>
      27             : #include <ndnotxt.hxx>
      28             : #include <flyfrm.hxx>
      29             : #include <cntfrm.hxx>
      30             : #include <fmtcntnt.hxx>
      31             : #include <ndindex.hxx>
      32             : #include "fesh.hxx"
      33             : #include <hints.hxx>
      34             : #include "accmap.hxx"
      35             : #include "accframebase.hxx"
      36             : 
      37             : #include <crsrsh.hxx>
      38             : #include <txtfrm.hxx>
      39             : #include <ndtxt.hxx>
      40             : #include <dcontact.hxx>
      41             : #include <fmtanchr.hxx>
      42             : 
      43             : using namespace ::com::sun::star;
      44             : using namespace ::com::sun::star::accessibility;
      45             : 
      46          25 : sal_Bool SwAccessibleFrameBase::IsSelected()
      47             : {
      48          25 :     sal_Bool bRet = sal_False;
      49             : 
      50             :     OSL_ENSURE( GetMap(), "no map?" );
      51          25 :     const SwViewShell *pVSh = GetMap()->GetShell();
      52             :     OSL_ENSURE( pVSh, "no shell?" );
      53          25 :     if( pVSh->ISA( SwFEShell ) )
      54             :     {
      55          25 :         const SwFEShell *pFESh = static_cast< const SwFEShell * >( pVSh );
      56          25 :         const SwFrm *pFlyFrm = pFESh->GetCurrFlyFrm();
      57          25 :         if( pFlyFrm == GetFrm() )
      58           0 :             bRet = sal_True;
      59             :     }
      60             : 
      61          25 :     return bRet;
      62             : }
      63             : 
      64           2 : void SwAccessibleFrameBase::GetStates(
      65             :         ::utl::AccessibleStateSetHelper& rStateSet )
      66             : {
      67           2 :     SwAccessibleContext::GetStates( rStateSet );
      68             : 
      69           2 :     const SwViewShell *pVSh = GetMap()->GetShell();
      70             :     OSL_ENSURE( pVSh, "no shell?" );
      71           2 :     sal_Bool bSelectable =  pVSh->ISA( SwFEShell );
      72             : 
      73             :     // SELECTABLE
      74           2 :     if( bSelectable )
      75           2 :         rStateSet.AddState( AccessibleStateType::SELECTABLE );
      76             : 
      77             :     // FOCUSABLE
      78           2 :     if( bSelectable )
      79           2 :         rStateSet.AddState( AccessibleStateType::FOCUSABLE );
      80             : 
      81             :     // SELECTED and FOCUSED
      82           2 :     if( IsSelected() )
      83             :     {
      84           0 :         rStateSet.AddState( AccessibleStateType::SELECTED );
      85             :         OSL_ENSURE( bIsSelected, "bSelected out of sync" );
      86           0 :         ::rtl::Reference < SwAccessibleContext > xThis( this );
      87           0 :         GetMap()->SetCursorContext( xThis );
      88             : 
      89           0 :         Window *pWin = GetWindow();
      90           0 :         if( pWin && pWin->HasFocus() )
      91           0 :             rStateSet.AddState( AccessibleStateType::FOCUSED );
      92             :     }
      93           2 :     if( GetSelectedState() )
      94           0 :         rStateSet.AddState( AccessibleStateType::SELECTED );
      95           2 : }
      96             : 
      97           1 : sal_uInt8 SwAccessibleFrameBase::GetNodeType( const SwFlyFrm *pFlyFrm )
      98             : {
      99           1 :     sal_uInt8 nType = ND_TEXTNODE;
     100           1 :     if( pFlyFrm->Lower() )
     101             :     {
     102           1 :          if( pFlyFrm->Lower()->IsNoTxtFrm() )
     103             :         {
     104             :             const SwCntntFrm *pCntFrm =
     105           1 :                 static_cast<const SwCntntFrm *>( pFlyFrm->Lower() );
     106           1 :             nType = pCntFrm->GetNode()->GetNodeType();
     107             :         }
     108             :     }
     109             :     else
     110             :     {
     111           0 :         const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
     112           0 :         const SwFmtCntnt& rCntnt = pFrmFmt->GetCntnt();
     113           0 :         const SwNodeIndex *pNdIdx = rCntnt.GetCntntIdx();
     114           0 :         if( pNdIdx )
     115             :         {
     116             :             const SwCntntNode *pCNd =
     117           0 :                 (pNdIdx->GetNodes())[pNdIdx->GetIndex()+1]->GetCntntNode();
     118           0 :             if( pCNd )
     119           0 :                 nType = pCNd->GetNodeType();
     120             :         }
     121             :     }
     122             : 
     123           1 :     return nType;
     124             : }
     125             : 
     126           1 : SwAccessibleFrameBase::SwAccessibleFrameBase(
     127             :         SwAccessibleMap* pInitMap,
     128             :         sal_Int16 nInitRole,
     129             :         const SwFlyFrm* pFlyFrm  ) :
     130             :     SwAccessibleContext( pInitMap, nInitRole, pFlyFrm ),
     131           1 :     bIsSelected( sal_False )
     132             : {
     133           1 :     SolarMutexGuard aGuard;
     134             : 
     135           1 :     const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
     136           1 :     const_cast< SwFrmFmt * >( pFrmFmt )->Add( this );
     137             : 
     138           1 :     SetName( pFrmFmt->GetName() );
     139             : 
     140           1 :     bIsSelected = IsSelected();
     141           1 : }
     142             : 
     143           0 : void SwAccessibleFrameBase::_InvalidateCursorPos()
     144             : {
     145           0 :     sal_Bool bNewSelected = IsSelected();
     146             :     sal_Bool bOldSelected;
     147             : 
     148             :     {
     149           0 :         osl::MutexGuard aGuard( aMutex );
     150           0 :         bOldSelected = bIsSelected;
     151           0 :         bIsSelected = bNewSelected;
     152             :     }
     153             : 
     154           0 :     if( bNewSelected )
     155             :     {
     156             :         // remember that object as the one that has the caret. This is
     157             :         // necessary to notify that object if the cursor leaves it.
     158           0 :         ::rtl::Reference < SwAccessibleContext > xThis( this );
     159           0 :         GetMap()->SetCursorContext( xThis );
     160             :     }
     161             : 
     162           0 :     if( bOldSelected != bNewSelected )
     163             :     {
     164           0 :         Window *pWin = GetWindow();
     165           0 :         if( pWin && pWin->HasFocus() && bNewSelected )
     166           0 :             FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected );
     167           0 :         if( pWin && pWin->HasFocus() && !bNewSelected )
     168           0 :             FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected );
     169           0 :         if(bNewSelected)
     170             :         {
     171           0 :             uno::Reference< XAccessible > xParent( GetWeakParent() );
     172           0 :             if( xParent.is() )
     173             :             {
     174             :                 SwAccessibleContext *pAcc =
     175           0 :                     static_cast <SwAccessibleContext *>( xParent.get() );
     176             : 
     177           0 :                 AccessibleEventObject aEvent;
     178           0 :                 aEvent.EventId = AccessibleEventId::SELECTION_CHANGED;
     179           0 :                 uno::Reference< XAccessible > xChild(this);
     180           0 :                 aEvent.NewValue <<= xChild;
     181           0 :                 pAcc->FireAccessibleEvent( aEvent );
     182           0 :             }
     183             :         }
     184             :     }
     185           0 : }
     186             : 
     187           0 : void SwAccessibleFrameBase::_InvalidateFocus()
     188             : {
     189           0 :     Window *pWin = GetWindow();
     190           0 :     if( pWin )
     191             :     {
     192             :         sal_Bool bSelected;
     193             : 
     194             :         {
     195           0 :             osl::MutexGuard aGuard( aMutex );
     196           0 :             bSelected = bIsSelected;
     197             :         }
     198             :         OSL_ENSURE( bSelected, "focus object should be selected" );
     199             : 
     200             :         FireStateChangedEvent( AccessibleStateType::FOCUSED,
     201           0 :                                pWin->HasFocus() && bSelected );
     202             :     }
     203           0 : }
     204             : 
     205           1 : sal_Bool SwAccessibleFrameBase::HasCursor()
     206             : {
     207           1 :     osl::MutexGuard aGuard( aMutex );
     208           1 :     return bIsSelected;
     209             : }
     210             : 
     211           1 : SwAccessibleFrameBase::~SwAccessibleFrameBase()
     212             : {
     213           1 : }
     214             : 
     215           0 : void SwAccessibleFrameBase::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
     216             : {
     217           0 :     sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
     218           0 :     const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm * >( GetFrm() );
     219           0 :     switch( nWhich )
     220             :     {
     221             :     case RES_NAME_CHANGED:
     222           0 :         if(  pFlyFrm )
     223             :         {
     224           0 :             const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
     225             :             OSL_ENSURE( pFrmFmt == GetRegisteredIn(), "invalid frame" );
     226             : 
     227           0 :             const OUString sOldName( GetName() );
     228             :             OSL_ENSURE( !pOld ||
     229             :                     static_cast < const SwStringMsgPoolItem * >( pOld )->GetString() == GetName(),
     230             :                     "invalid old name" );
     231             : 
     232           0 :             SetName( pFrmFmt->GetName() );
     233             :             OSL_ENSURE( !pNew ||
     234             :                     static_cast < const SwStringMsgPoolItem * >( pNew )->GetString() == GetName(),
     235             :                     "invalid new name" );
     236             : 
     237           0 :             if( sOldName != GetName() )
     238             :             {
     239           0 :                 AccessibleEventObject aEvent;
     240           0 :                 aEvent.EventId = AccessibleEventId::NAME_CHANGED;
     241           0 :                 aEvent.OldValue <<= sOldName;
     242           0 :                 aEvent.NewValue <<= GetName();
     243           0 :                 FireAccessibleEvent( aEvent );
     244           0 :             }
     245             :         }
     246           0 :         break;
     247             :     case RES_OBJECTDYING:
     248             :         // mba: it seems that this class intentionally does not call code in base class SwClient
     249           0 :         if( pOld && ( GetRegisteredIn() == static_cast< SwModify *>( static_cast< const SwPtrMsgPoolItem * >( pOld )->pObject ) ) )
     250           0 :             GetRegisteredInNonConst()->Remove( this );
     251           0 :         break;
     252             : 
     253             :     case RES_FMT_CHG:
     254           0 :         if( pOld &&
     255           0 :             static_cast< const SwFmtChg * >(pNew)->pChangedFmt == GetRegisteredIn() &&
     256           0 :             static_cast< const SwFmtChg * >(pOld)->pChangedFmt->IsFmtInDTOR() )
     257           0 :             GetRegisteredInNonConst()->Remove( this );
     258           0 :         break;
     259             : 
     260             :     default:
     261             :         // mba: former call to base class method removed as it is meant to handle only RES_OBJECTDYING
     262           0 :         break;
     263             :     }
     264           0 : }
     265             : 
     266           1 : void SwAccessibleFrameBase::Dispose( sal_Bool bRecursive )
     267             : {
     268           1 :     SolarMutexGuard aGuard;
     269             : 
     270           1 :     if( GetRegisteredIn() )
     271           1 :         GetRegisteredInNonConst()->Remove( this );
     272             : 
     273           1 :     SwAccessibleContext::Dispose( bRecursive );
     274           1 : }
     275             : 
     276             : //Get the selection cursor of the document.
     277          24 : SwPaM* SwAccessibleFrameBase::GetCrsr()
     278             : {
     279             :     // get the cursor shell; if we don't have any, we don't have a
     280             :     // cursor/selection either
     281          24 :     SwPaM* pCrsr = NULL;
     282          24 :     SwCrsrShell* pCrsrShell = GetCrsrShell();
     283          24 :     if( pCrsrShell != NULL && !pCrsrShell->IsTableMode() )
     284             :     {
     285          24 :         SwFEShell *pFESh = pCrsrShell->ISA( SwFEShell )
     286          24 :                             ? static_cast< SwFEShell * >( pCrsrShell ) : 0;
     287          72 :         if( !pFESh ||
     288          48 :             !(pFESh->IsFrmSelected() || pFESh->IsObjSelected() > 0) )
     289             :         {
     290             :             // get the selection, and test whether it affects our text node
     291          24 :             pCrsr = pCrsrShell->GetCrsr( sal_False /* ??? */ );
     292             :         }
     293             :     }
     294             : 
     295          24 :     return pCrsr;
     296             : }
     297             : 
     298             : //Return the selected state of the object.
     299             : //when the object's anchor are in the selection cursor, we should return true.
     300          24 : sal_Bool SwAccessibleFrameBase::GetSelectedState( )
     301             : {
     302          24 :     SolarMutexGuard aGuard;
     303             : 
     304          24 :     if(GetMap()->IsDocumentSelAll())
     305             :     {
     306           0 :         return sal_True;
     307             :     }
     308             : 
     309             :     // SELETED.
     310          24 :     SwFlyFrm* pFlyFrm = getFlyFrm();
     311          24 :     const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
     312          24 :     const SwFmtAnchor& pAnchor = pFrmFmt->GetAnchor();
     313          24 :     const SwPosition *pPos = pAnchor.GetCntntAnchor();
     314          24 :     if( !pPos )
     315           0 :         return sal_False;
     316          24 :     int pIndex = pPos->nContent.GetIndex();
     317          24 :     if( pPos->nNode.GetNode().GetTxtNode() )
     318             :     {
     319          24 :         SwPaM* pCrsr = GetCrsr();
     320          24 :         if( pCrsr != NULL )
     321             :         {
     322          24 :             const SwTxtNode* pNode = pPos->nNode.GetNode().GetTxtNode();
     323          24 :             sal_uLong nHere = pNode->GetIndex();
     324             : 
     325             :             // iterate over ring
     326          24 :             SwPaM* pRingStart = pCrsr;
     327          24 :             do
     328             :             {
     329             :                 // ignore, if no mark
     330          24 :                 if( pCrsr->HasMark() )
     331             :                 {
     332             :                     // check whether nHere is 'inside' pCrsr
     333           0 :                     SwPosition* pStart = pCrsr->Start();
     334           0 :                     sal_uLong nStartIndex = pStart->nNode.GetIndex();
     335           0 :                     SwPosition* pEnd = pCrsr->End();
     336           0 :                     sal_uLong nEndIndex = pEnd->nNode.GetIndex();
     337           0 :                     if( ( nHere >= nStartIndex ) && (nHere <= nEndIndex)  )
     338             :                     {
     339           0 :                         if( pAnchor.GetAnchorId() == FLY_AS_CHAR )
     340             :                         {
     341           0 :                             if( ((nHere == nStartIndex) && (pIndex >= pStart->nContent.GetIndex())) || (nHere > nStartIndex) )
     342           0 :                                 if( ((nHere == nEndIndex) && (pIndex < pEnd->nContent.GetIndex())) || (nHere < nEndIndex) )
     343           0 :                                     return sal_True;
     344             :                         }
     345           0 :                         else if( pAnchor.GetAnchorId() == FLY_AT_PARA )
     346             :                         {
     347           0 :                             if( ((nHere > nStartIndex) || pStart->nContent.GetIndex() ==0 )
     348           0 :                                 && (nHere < nEndIndex ) )
     349           0 :                                 return sal_True;
     350             :                         }
     351           0 :                         break;
     352             :                     }
     353             :                     // else: this PaM doesn't point to this paragraph
     354             :                 }
     355             :                 // else: this PaM is collapsed and doesn't select anything
     356             : 
     357             :                 // next PaM in ring
     358          24 :                 pCrsr = static_cast<SwPaM*>( pCrsr->GetNext() );
     359             :             }
     360             :             while( pCrsr != pRingStart );
     361             :         }
     362             :     }
     363          24 :     return sal_False;
     364             : }
     365             : 
     366          24 : SwFlyFrm* SwAccessibleFrameBase::getFlyFrm() const
     367             : {
     368          24 :     SwFlyFrm* pFlyFrm = NULL;
     369             : 
     370          24 :     const SwFrm* pFrm = GetFrm();
     371             :     DBG_ASSERT( pFrm != NULL, "frame expected" );
     372          24 :     if( pFrm->IsFlyFrm() )
     373             :     {
     374          24 :         pFlyFrm = static_cast<SwFlyFrm*>( const_cast<SwFrm*>( pFrm ) );
     375             :     }
     376             : 
     377          24 :     return pFlyFrm;
     378             : }
     379             : 
     380          22 : sal_Bool SwAccessibleFrameBase::SetSelectedState( sal_Bool )
     381             : {
     382          22 :     sal_Bool bParaSeleted = GetSelectedState() || IsSelected();
     383             : 
     384          22 :     if(bIsSeletedInDoc != bParaSeleted)
     385             :     {
     386           0 :         bIsSeletedInDoc = bParaSeleted;
     387           0 :         FireStateChangedEvent( AccessibleStateType::SELECTED, bParaSeleted );
     388           0 :         return sal_True;
     389             :     }
     390          22 :     return sal_False;
     391             : }
     392             : 
     393             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10