LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/access - accframebase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 44 114 38.6 %
Date: 2013-07-09 Functions: 9 13 69.2 %
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             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::accessibility;
      39             : 
      40           3 : sal_Bool SwAccessibleFrameBase::IsSelected()
      41             : {
      42           3 :     sal_Bool bRet = sal_False;
      43             : 
      44             :     OSL_ENSURE( GetMap(), "no map?" );
      45           3 :     const ViewShell *pVSh = GetMap()->GetShell();
      46             :     OSL_ENSURE( pVSh, "no shell?" );
      47           3 :     if( pVSh->ISA( SwFEShell ) )
      48             :     {
      49           3 :         const SwFEShell *pFESh = static_cast< const SwFEShell * >( pVSh );
      50           3 :         const SwFrm *pFlyFrm = pFESh->GetCurrFlyFrm();
      51           3 :         if( pFlyFrm == GetFrm() )
      52           0 :             bRet = sal_True;
      53             :     }
      54             : 
      55           3 :     return bRet;
      56             : }
      57             : 
      58           2 : void SwAccessibleFrameBase::GetStates(
      59             :         ::utl::AccessibleStateSetHelper& rStateSet )
      60             : {
      61           2 :     SwAccessibleContext::GetStates( rStateSet );
      62             : 
      63           2 :     const ViewShell *pVSh = GetMap()->GetShell();
      64             :     OSL_ENSURE( pVSh, "no shell?" );
      65           2 :     sal_Bool bSelectable =  pVSh->ISA( SwFEShell );
      66             : 
      67             :     // SELECTABLE
      68           2 :     if( bSelectable )
      69           2 :         rStateSet.AddState( AccessibleStateType::SELECTABLE );
      70             : 
      71             :     // FOCUSABLE
      72           2 :     if( bSelectable )
      73           2 :         rStateSet.AddState( AccessibleStateType::FOCUSABLE );
      74             : 
      75             :     // SELECTED and FOCUSED
      76           2 :     if( IsSelected() )
      77             :     {
      78           0 :         rStateSet.AddState( AccessibleStateType::SELECTED );
      79             :         OSL_ENSURE( bIsSelected, "bSelected out of sync" );
      80           0 :         ::rtl::Reference < SwAccessibleContext > xThis( this );
      81           0 :         GetMap()->SetCursorContext( xThis );
      82             : 
      83           0 :         Window *pWin = GetWindow();
      84           0 :         if( pWin && pWin->HasFocus() )
      85           0 :             rStateSet.AddState( AccessibleStateType::FOCUSED );
      86             :     }
      87           2 : }
      88             : 
      89             : 
      90           1 : sal_uInt8 SwAccessibleFrameBase::GetNodeType( const SwFlyFrm *pFlyFrm )
      91             : {
      92           1 :     sal_uInt8 nType = ND_TEXTNODE;
      93           1 :     if( pFlyFrm->Lower() )
      94             :     {
      95           1 :          if( pFlyFrm->Lower()->IsNoTxtFrm() )
      96             :         {
      97             :             const SwCntntFrm *pCntFrm =
      98           1 :                 static_cast<const SwCntntFrm *>( pFlyFrm->Lower() );
      99           1 :             nType = pCntFrm->GetNode()->GetNodeType();
     100             :         }
     101             :     }
     102             :     else
     103             :     {
     104           0 :         const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
     105           0 :         const SwFmtCntnt& rCntnt = pFrmFmt->GetCntnt();
     106           0 :         const SwNodeIndex *pNdIdx = rCntnt.GetCntntIdx();
     107           0 :         if( pNdIdx )
     108             :         {
     109             :             const SwCntntNode *pCNd =
     110           0 :                 (pNdIdx->GetNodes())[pNdIdx->GetIndex()+1]->GetCntntNode();
     111           0 :             if( pCNd )
     112           0 :                 nType = pCNd->GetNodeType();
     113             :         }
     114             :     }
     115             : 
     116           1 :     return nType;
     117             : }
     118             : 
     119           1 : SwAccessibleFrameBase::SwAccessibleFrameBase(
     120             :         SwAccessibleMap* pInitMap,
     121             :         sal_Int16 nInitRole,
     122             :         const SwFlyFrm* pFlyFrm  ) :
     123             :     SwAccessibleContext( pInitMap, nInitRole, pFlyFrm ),
     124           1 :     bIsSelected( sal_False )
     125             : {
     126           1 :     SolarMutexGuard aGuard;
     127             : 
     128           1 :     const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
     129           1 :     const_cast< SwFrmFmt * >( pFrmFmt )->Add( this );
     130             : 
     131           1 :     SetName( pFrmFmt->GetName() );
     132             : 
     133           1 :     bIsSelected = IsSelected();
     134           1 : }
     135             : 
     136           0 : void SwAccessibleFrameBase::_InvalidateCursorPos()
     137             : {
     138           0 :     sal_Bool bNewSelected = IsSelected();
     139             :     sal_Bool bOldSelected;
     140             : 
     141             :     {
     142           0 :         osl::MutexGuard aGuard( aMutex );
     143           0 :         bOldSelected = bIsSelected;
     144           0 :         bIsSelected = bNewSelected;
     145             :     }
     146             : 
     147           0 :     if( bNewSelected )
     148             :     {
     149             :         // remember that object as the one that has the caret. This is
     150             :         // necessary to notify that object if the cursor leaves it.
     151           0 :         ::rtl::Reference < SwAccessibleContext > xThis( this );
     152           0 :         GetMap()->SetCursorContext( xThis );
     153             :     }
     154             : 
     155           0 :     if( bOldSelected != bNewSelected )
     156             :     {
     157           0 :         Window *pWin = GetWindow();
     158           0 :         if( pWin && pWin->HasFocus() && bNewSelected )
     159           0 :             FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected );
     160           0 :         FireStateChangedEvent( AccessibleStateType::SELECTED, bNewSelected );
     161           0 :         if( pWin && pWin->HasFocus() && !bNewSelected )
     162           0 :             FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected );
     163             : 
     164           0 :         uno::Reference< XAccessible > xParent( GetWeakParent() );
     165           0 :         if( xParent.is() )
     166             :         {
     167             :             SwAccessibleContext *pAcc =
     168           0 :                 static_cast <SwAccessibleContext *>( xParent.get() );
     169             : 
     170           0 :             AccessibleEventObject aEvent;
     171           0 :             aEvent.EventId = AccessibleEventId::SELECTION_CHANGED;
     172           0 :             pAcc->FireAccessibleEvent( aEvent );
     173           0 :         }
     174             :     }
     175           0 : }
     176             : 
     177           0 : void SwAccessibleFrameBase::_InvalidateFocus()
     178             : {
     179           0 :     Window *pWin = GetWindow();
     180           0 :     if( pWin )
     181             :     {
     182             :         sal_Bool bSelected;
     183             : 
     184             :         {
     185           0 :             osl::MutexGuard aGuard( aMutex );
     186           0 :             bSelected = bIsSelected;
     187             :         }
     188             :         OSL_ENSURE( bSelected, "focus object should be selected" );
     189             : 
     190             :         FireStateChangedEvent( AccessibleStateType::FOCUSED,
     191           0 :                                pWin->HasFocus() && bSelected );
     192             :     }
     193           0 : }
     194             : 
     195           1 : sal_Bool SwAccessibleFrameBase::HasCursor()
     196             : {
     197           1 :     osl::MutexGuard aGuard( aMutex );
     198           1 :     return bIsSelected;
     199             : }
     200             : 
     201             : 
     202           1 : SwAccessibleFrameBase::~SwAccessibleFrameBase()
     203             : {
     204           1 : }
     205             : 
     206           0 : void SwAccessibleFrameBase::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
     207             : {
     208           0 :     sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
     209           0 :     const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm * >( GetFrm() );
     210           0 :     switch( nWhich )
     211             :     {
     212             :     case RES_NAME_CHANGED:
     213           0 :         if(  pFlyFrm )
     214             :         {
     215           0 :             const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
     216             :             OSL_ENSURE( pFrmFmt == GetRegisteredIn(), "invalid frame" );
     217             : 
     218           0 :             OUString sOldName( GetName() );
     219             :             OSL_ENSURE( !pOld ||
     220             :                     static_cast < const SwStringMsgPoolItem * >( pOld )->GetString() == String( sOldName ),
     221             :                     "invalid old name" );
     222             : 
     223           0 :             const String& rNewName = pFrmFmt->GetName();
     224           0 :             SetName( rNewName );
     225             :             OSL_ENSURE( !pNew ||
     226             :                     static_cast < const SwStringMsgPoolItem * >( pNew )->GetString() == rNewName,
     227             :                     "invalid new name" );
     228             : 
     229           0 :             if( sOldName != GetName() )
     230             :             {
     231           0 :                 AccessibleEventObject aEvent;
     232           0 :                 aEvent.EventId = AccessibleEventId::NAME_CHANGED;
     233           0 :                 aEvent.OldValue <<= sOldName;
     234           0 :                 aEvent.NewValue <<= GetName();
     235           0 :                 FireAccessibleEvent( aEvent );
     236           0 :             }
     237             :         }
     238           0 :         break;
     239             :     case RES_OBJECTDYING:
     240             :         // mba: it seems that this class intentionally does not call code in base class SwClient
     241           0 :         if( GetRegisteredIn() ==
     242             :                 static_cast< SwModify *>( static_cast< const SwPtrMsgPoolItem * >( pOld )->pObject ) )
     243           0 :             GetRegisteredInNonConst()->Remove( this );
     244           0 :         break;
     245             : 
     246             :     case RES_FMT_CHG:
     247           0 :         if( static_cast< const SwFmtChg * >(pNew)->pChangedFmt == GetRegisteredIn() &&
     248           0 :             static_cast< const SwFmtChg * >(pOld)->pChangedFmt->IsFmtInDTOR() )
     249           0 :             GetRegisteredInNonConst()->Remove( this );
     250           0 :         break;
     251             : 
     252             :     default:
     253             :         // mba: former call to base class method removed as it is meant to handle only RES_OBJECTDYING
     254           0 :         break;
     255             :     }
     256           0 : }
     257             : 
     258           1 : void SwAccessibleFrameBase::Dispose( sal_Bool bRecursive )
     259             : {
     260           1 :     SolarMutexGuard aGuard;
     261             : 
     262           1 :     if( GetRegisteredIn() )
     263           1 :         GetRegisteredInNonConst()->Remove( this );
     264             : 
     265           1 :     SwAccessibleContext::Dispose( bRecursive );
     266         100 : }
     267             : 
     268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10