LCOV - code coverage report
Current view: top level - sw/source/core/access - accframebase.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 85 177 48.0 %
Date: 2015-06-13 12:38:46 Functions: 13 17 76.5 %
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          26 : bool SwAccessibleFrameBase::IsSelected()
      47             : {
      48          26 :     bool bRet = false;
      49             : 
      50             :     assert(GetMap());
      51          26 :     const SwViewShell *pVSh = GetMap()->GetShell();
      52             :     assert(pVSh);
      53          26 :     if( pVSh->ISA( SwFEShell ) )
      54             :     {
      55          26 :         const SwFEShell *pFESh = static_cast< const SwFEShell * >( pVSh );
      56          26 :         const SwFrm *pFlyFrm = pFESh->GetCurrFlyFrm();
      57          26 :         if( pFlyFrm == GetFrm() )
      58           0 :             bRet = true;
      59             :     }
      60             : 
      61          26 :     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             :     assert(pVSh);
      71           2 :     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             :         assert(bIsSelected && "bSelected out of sync");
      86           0 :         ::rtl::Reference < SwAccessibleContext > xThis( this );
      87           0 :         GetMap()->SetCursorContext( xThis );
      88             : 
      89           0 :         vcl::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()->IsNoTextFrm() )
     103             :         {
     104             :             const SwContentFrm *pCntFrm =
     105           1 :                 static_cast<const SwContentFrm *>( pFlyFrm->Lower() );
     106           1 :             nType = pCntFrm->GetNode()->GetNodeType();
     107             :         }
     108             :     }
     109             :     else
     110             :     {
     111           0 :         const SwFrameFormat *pFrameFormat = pFlyFrm->GetFormat();
     112           0 :         const SwFormatContent& rContent = pFrameFormat->GetContent();
     113           0 :         const SwNodeIndex *pNdIdx = rContent.GetContentIdx();
     114           0 :         if( pNdIdx )
     115             :         {
     116             :             const SwContentNode *pCNd =
     117           0 :                 (pNdIdx->GetNodes())[pNdIdx->GetIndex()+1]->GetContentNode();
     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( false )
     132             : {
     133           1 :     SolarMutexGuard aGuard;
     134             : 
     135           1 :     const SwFrameFormat *pFrameFormat = pFlyFrm->GetFormat();
     136           1 :     const_cast< SwFrameFormat * >( pFrameFormat )->Add( this );
     137             : 
     138           1 :     SetName( pFrameFormat->GetName() );
     139             : 
     140           1 :     bIsSelected = IsSelected();
     141           1 : }
     142             : 
     143           0 : void SwAccessibleFrameBase::_InvalidateCursorPos()
     144             : {
     145           0 :     bool bNewSelected = IsSelected();
     146             :     bool bOldSelected;
     147             : 
     148             :     {
     149           0 :         osl::MutexGuard aGuard( m_Mutex );
     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 :         vcl::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 :     vcl::Window *pWin = GetWindow();
     190           0 :     if( pWin )
     191             :     {
     192             :         bool bSelected;
     193             : 
     194             :         {
     195           0 :             osl::MutexGuard aGuard( m_Mutex );
     196           0 :             bSelected = bIsSelected;
     197             :         }
     198             :         assert(bSelected && "focus object should be selected");
     199             : 
     200             :         FireStateChangedEvent( AccessibleStateType::FOCUSED,
     201           0 :                                pWin->HasFocus() && bSelected );
     202             :     }
     203           0 : }
     204             : 
     205           1 : bool SwAccessibleFrameBase::HasCursor()
     206             : {
     207           1 :     osl::MutexGuard aGuard( m_Mutex );
     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 SwFrameFormat *pFrameFormat = pFlyFrm->GetFormat();
     225             :             assert(pFrameFormat == GetRegisteredIn() && "invalid frame");
     226             : 
     227           0 :             const OUString sOldName( GetName() );
     228             :             assert( !pOld ||
     229             :                     static_cast<const SwStringMsgPoolItem *>(pOld)->GetString() == GetName());
     230             : 
     231           0 :             SetName( pFrameFormat->GetName() );
     232             :             assert( !pNew ||
     233             :                     static_cast<const SwStringMsgPoolItem *>(pNew)->GetString() == GetName());
     234             : 
     235           0 :             if( sOldName != GetName() )
     236             :             {
     237           0 :                 AccessibleEventObject aEvent;
     238           0 :                 aEvent.EventId = AccessibleEventId::NAME_CHANGED;
     239           0 :                 aEvent.OldValue <<= sOldName;
     240           0 :                 aEvent.NewValue <<= GetName();
     241           0 :                 FireAccessibleEvent( aEvent );
     242           0 :             }
     243             :         }
     244           0 :         break;
     245             :     case RES_OBJECTDYING:
     246             :         // mba: it seems that this class intentionally does not call code in base class SwClient
     247           0 :         if( pOld && ( GetRegisteredIn() == static_cast< SwModify *>( static_cast< const SwPtrMsgPoolItem * >( pOld )->pObject ) ) )
     248           0 :             GetRegisteredInNonConst()->Remove( this );
     249           0 :         break;
     250             : 
     251             :     case RES_FMT_CHG:
     252           0 :         if( pOld &&
     253           0 :             static_cast< const SwFormatChg * >(pNew)->pChangedFormat == GetRegisteredIn() &&
     254           0 :             static_cast< const SwFormatChg * >(pOld)->pChangedFormat->IsFormatInDTOR() )
     255           0 :             GetRegisteredInNonConst()->Remove( this );
     256           0 :         break;
     257             : 
     258             :     default:
     259             :         // mba: former call to base class method removed as it is meant to handle only RES_OBJECTDYING
     260           0 :         break;
     261             :     }
     262           0 : }
     263             : 
     264           1 : void SwAccessibleFrameBase::Dispose( bool bRecursive )
     265             : {
     266           1 :     SolarMutexGuard aGuard;
     267             : 
     268           1 :     if( GetRegisteredIn() )
     269           1 :         GetRegisteredInNonConst()->Remove( this );
     270             : 
     271           1 :     SwAccessibleContext::Dispose( bRecursive );
     272           1 : }
     273             : 
     274             : //Get the selection cursor of the document.
     275          25 : SwPaM* SwAccessibleFrameBase::GetCrsr()
     276             : {
     277             :     // get the cursor shell; if we don't have any, we don't have a
     278             :     // cursor/selection either
     279          25 :     SwPaM* pCrsr = NULL;
     280          25 :     SwCrsrShell* pCrsrShell = GetCrsrShell();
     281          25 :     if( pCrsrShell != NULL && !pCrsrShell->IsTableMode() )
     282             :     {
     283          25 :         SwFEShell *pFESh = pCrsrShell->ISA( SwFEShell )
     284          25 :                             ? static_cast< SwFEShell * >( pCrsrShell ) : 0;
     285          75 :         if( !pFESh ||
     286          50 :             !(pFESh->IsFrmSelected() || pFESh->IsObjSelected() > 0) )
     287             :         {
     288             :             // get the selection, and test whether it affects our text node
     289          25 :             pCrsr = pCrsrShell->GetCrsr( false /* ??? */ );
     290             :         }
     291             :     }
     292             : 
     293          25 :     return pCrsr;
     294             : }
     295             : 
     296             : //Return the selected state of the object.
     297             : //when the object's anchor are in the selection cursor, we should return true.
     298          25 : bool SwAccessibleFrameBase::GetSelectedState( )
     299             : {
     300          25 :     SolarMutexGuard aGuard;
     301             : 
     302          25 :     if(GetMap()->IsDocumentSelAll())
     303             :     {
     304           0 :         return true;
     305             :     }
     306             : 
     307             :     // SELETED.
     308          25 :     SwFlyFrm* pFlyFrm = getFlyFrm();
     309          25 :     const SwFrameFormat *pFrameFormat = pFlyFrm->GetFormat();
     310          25 :     const SwFormatAnchor& pAnchor = pFrameFormat->GetAnchor();
     311          25 :     const SwPosition *pPos = pAnchor.GetContentAnchor();
     312          25 :     if( !pPos )
     313           0 :         return false;
     314          25 :     int pIndex = pPos->nContent.GetIndex();
     315          25 :     if( pPos->nNode.GetNode().GetTextNode() )
     316             :     {
     317          25 :         SwPaM* pCrsr = GetCrsr();
     318          25 :         if( pCrsr != NULL )
     319             :         {
     320          25 :             const SwTextNode* pNode = pPos->nNode.GetNode().GetTextNode();
     321          25 :             sal_uLong nHere = pNode->GetIndex();
     322             : 
     323             :             // iterate over ring
     324          25 :             SwPaM* pRingStart = pCrsr;
     325          25 :             do
     326             :             {
     327             :                 // ignore, if no mark
     328          25 :                 if( pCrsr->HasMark() )
     329             :                 {
     330             :                     // check whether nHere is 'inside' pCrsr
     331           0 :                     SwPosition* pStart = pCrsr->Start();
     332           0 :                     sal_uLong nStartIndex = pStart->nNode.GetIndex();
     333           0 :                     SwPosition* pEnd = pCrsr->End();
     334           0 :                     sal_uLong nEndIndex = pEnd->nNode.GetIndex();
     335           0 :                     if( ( nHere >= nStartIndex ) && (nHere <= nEndIndex)  )
     336             :                     {
     337           0 :                         if( pAnchor.GetAnchorId() == FLY_AS_CHAR )
     338             :                         {
     339           0 :                             if( ((nHere == nStartIndex) && (pIndex >= pStart->nContent.GetIndex())) || (nHere > nStartIndex) )
     340           0 :                                 if( ((nHere == nEndIndex) && (pIndex < pEnd->nContent.GetIndex())) || (nHere < nEndIndex) )
     341           0 :                                     return true;
     342             :                         }
     343           0 :                         else if( pAnchor.GetAnchorId() == FLY_AT_PARA )
     344             :                         {
     345           0 :                             if( ((nHere > nStartIndex) || pStart->nContent.GetIndex() ==0 )
     346           0 :                                 && (nHere < nEndIndex ) )
     347           0 :                                 return true;
     348             :                         }
     349           0 :                         break;
     350             :                     }
     351             :                     // else: this PaM doesn't point to this paragraph
     352             :                 }
     353             :                 // else: this PaM is collapsed and doesn't select anything
     354             : 
     355             :                 // next PaM in ring
     356          25 :                 pCrsr = pCrsr->GetNext();
     357             :             }
     358             :             while( pCrsr != pRingStart );
     359             :         }
     360             :     }
     361          25 :     return false;
     362             : }
     363             : 
     364          25 : SwFlyFrm* SwAccessibleFrameBase::getFlyFrm() const
     365             : {
     366          25 :     SwFlyFrm* pFlyFrm = NULL;
     367             : 
     368          25 :     const SwFrm* pFrm = GetFrm();
     369             :     assert(pFrm);
     370          25 :     if( pFrm->IsFlyFrm() )
     371             :     {
     372          25 :         pFlyFrm = static_cast<SwFlyFrm*>( const_cast<SwFrm*>( pFrm ) );
     373             :     }
     374             : 
     375          25 :     return pFlyFrm;
     376             : }
     377             : 
     378          23 : bool SwAccessibleFrameBase::SetSelectedState( bool )
     379             : {
     380          23 :     bool bParaSelected = GetSelectedState() || IsSelected();
     381             : 
     382          23 :     if (m_isSelectedInDoc != bParaSelected)
     383             :     {
     384           0 :         m_isSelectedInDoc = bParaSelected;
     385           0 :         FireStateChangedEvent( AccessibleStateType::SELECTED, bParaSelected );
     386           0 :         return true;
     387             :     }
     388          23 :     return false;
     389         177 : }
     390             : 
     391             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11