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

Generated by: LCOV version 1.10