LCOV - code coverage report
Current view: top level - accessibility/source/extended - accessibletablistboxtable.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 189 0.5 %
Date: 2015-06-13 12:38:46 Functions: 2 28 7.1 %
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 "accessibility/extended/accessibletablistboxtable.hxx"
      22             : #include "accessibility/extended/AccessibleBrowseBoxTableCell.hxx"
      23             : #include "accessibility/extended/AccessibleBrowseBoxCheckBoxCell.hxx"
      24             : #include <svtools/svtabbx.hxx>
      25             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      26             : 
      27             : 
      28             : namespace accessibility
      29             : {
      30             : 
      31             : 
      32             :     // class AccessibleTabListBoxTable ---------------------------------------------
      33             : 
      34             :     using namespace ::com::sun::star::accessibility;
      35             :     using namespace ::com::sun::star::uno;
      36             :     using namespace ::com::sun::star::lang;
      37             :     using namespace ::com::sun::star;
      38             : 
      39             : 
      40             :     // Ctor() and Dtor()
      41             : 
      42           0 :     AccessibleTabListBoxTable::AccessibleTabListBoxTable( const Reference< XAccessible >& rxParent, SvHeaderTabListBox& rBox ) :
      43             : 
      44             :         AccessibleBrowseBoxTable( rxParent, rBox ),
      45             : 
      46           0 :         m_pTabListBox   ( &rBox )
      47             : 
      48             :     {
      49           0 :         m_pTabListBox->AddEventListener( LINK( this, AccessibleTabListBoxTable, WindowEventListener ) );
      50           0 :     }
      51             : 
      52           0 :     AccessibleTabListBoxTable::~AccessibleTabListBoxTable()
      53             :     {
      54           0 :         if ( isAlive() )
      55             :         {
      56           0 :             m_pTabListBox = NULL;
      57             : 
      58             :             // increment ref count to prevent double call of Dtor
      59           0 :             osl_atomic_increment( &m_refCount );
      60           0 :             dispose();
      61             :         }
      62           0 :     }
      63             : 
      64           0 :     void AccessibleTabListBoxTable::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
      65             :     {
      66           0 :         if ( isAlive() )
      67             :         {
      68           0 :             sal_uLong nEventId = rVclWindowEvent.GetId();
      69           0 :             switch ( nEventId )
      70             :             {
      71             :                 case  VCLEVENT_OBJECT_DYING :
      72             :                 {
      73           0 :                     m_pTabListBox->RemoveEventListener( LINK( this, AccessibleTabListBoxTable, WindowEventListener ) );
      74           0 :                     m_pTabListBox = NULL;
      75           0 :                     break;
      76             :                 }
      77             : 
      78             :                 case VCLEVENT_CONTROL_GETFOCUS :
      79             :                 case VCLEVENT_CONTROL_LOSEFOCUS :
      80             :                 {
      81           0 :                     uno::Any aOldValue, aNewValue;
      82           0 :                     if ( VCLEVENT_CONTROL_GETFOCUS == nEventId )
      83           0 :                         aNewValue <<= AccessibleStateType::FOCUSED;
      84             :                     else
      85           0 :                         aOldValue <<= AccessibleStateType::FOCUSED;
      86           0 :                     commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
      87           0 :                     break;
      88             :                 }
      89             : 
      90             :                 case VCLEVENT_LISTBOX_SELECT :
      91             :                 {
      92             :                     // First send an event that tells the listeners of a
      93             :                     // modified selection.  The active descendant event is
      94             :                     // send after that so that the receiving AT has time to
      95             :                     // read the text or name of the active child.
      96           0 :                     commitEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
      97           0 :                     if ( m_pTabListBox && m_pTabListBox->HasFocus() )
      98             :                     {
      99           0 :                         SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
     100           0 :                         if ( pEntry )
     101             :                         {
     102           0 :                             sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
     103           0 :                             sal_uInt16 nCol = m_pTabListBox->GetCurrColumn();
     104             :                             Reference< XAccessible > xChild =
     105           0 :                                 m_pTabListBox->CreateAccessibleCell( nRow, nCol );
     106           0 :                             uno::Any aOldValue, aNewValue;
     107             : 
     108           0 :                             if ( m_pTabListBox->IsTransientChildrenDisabled() )
     109             :                             {
     110           0 :                                 aNewValue <<= AccessibleStateType::FOCUSED;
     111           0 :                                 TriState eState = TRISTATE_INDET;
     112           0 :                                 if ( m_pTabListBox->IsCellCheckBox( nRow, nCol, eState ) )
     113             :                                 {
     114             :                                     AccessibleCheckBoxCell* pCell =
     115           0 :                                         static_cast< AccessibleCheckBoxCell* >( xChild.get() );
     116           0 :                                     pCell->commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
     117             :                                 }
     118             :                                 else
     119             :                                 {
     120             :                                     AccessibleBrowseBoxTableCell* pCell =
     121           0 :                                         static_cast< AccessibleBrowseBoxTableCell* >( xChild.get() );
     122           0 :                                     pCell->commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
     123             :                                 }
     124             :                             }
     125             :                             else
     126             :                             {
     127           0 :                                 aNewValue <<= xChild;
     128           0 :                                 commitEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aNewValue, aOldValue );
     129           0 :                             }
     130             :                         }
     131             :                     }
     132           0 :                     break;
     133             :                 }
     134             :                 case VCLEVENT_WINDOW_GETFOCUS :
     135             :                 {
     136           0 :                     uno::Any aOldValue, aNewValue;
     137           0 :                     aNewValue <<= AccessibleStateType::FOCUSED;
     138           0 :                     commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
     139           0 :                     break;
     140             : 
     141             :                 }
     142             :                 case VCLEVENT_WINDOW_LOSEFOCUS :
     143             :                 {
     144           0 :                     uno::Any aOldValue, aNewValue;
     145           0 :                     aOldValue <<= AccessibleStateType::FOCUSED;
     146           0 :                     commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue, aOldValue );
     147           0 :                     break;
     148             :                 }
     149             :                 case VCLEVENT_LISTBOX_TREESELECT:
     150             :                     {
     151           0 :                         SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
     152           0 :                         if (pEntry)
     153             :                         {
     154           0 :                             sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
     155           0 :                             Reference< XAccessible > xChild = m_pTabListBox->CreateAccessibleCell( nRow, m_pTabListBox->GetCurrColumn() );
     156           0 :                             TriState eState = TRISTATE_INDET;
     157           0 :                             if ( m_pTabListBox->IsCellCheckBox( nRow, m_pTabListBox->GetCurrColumn(), eState ) )
     158             :                             {
     159           0 :                                 AccessibleCheckBoxCell* pCell = static_cast< AccessibleCheckBoxCell* >( xChild.get() );
     160           0 :                                 pCell->commitEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
     161             :                             }
     162             :                             else
     163             :                             {
     164           0 :                                 AccessibleBrowseBoxTableCell* pCell = static_cast< AccessibleBrowseBoxTableCell* >( xChild.get() );
     165           0 :                                 pCell->commitEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
     166           0 :                             }
     167             :                         }
     168             :                     }
     169           0 :                     break;
     170             :                 case VCLEVENT_LISTBOX_TREEFOCUS:
     171             :                     {
     172           0 :                         if ( m_pTabListBox && m_pTabListBox->HasFocus() )
     173             :                         {
     174           0 :                             uno::Any aOldValue, aNewValue;
     175           0 :                             SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
     176           0 :                             if ( pEntry )
     177             :                             {
     178           0 :                                 sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
     179           0 :                                 m_xCurChild = m_pTabListBox->CreateAccessibleCell( nRow, m_pTabListBox->GetCurrColumn() );
     180           0 :                                 aNewValue <<= m_xCurChild;
     181           0 :                                 commitEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aNewValue ,aOldValue);
     182             :                             }
     183             :                             else
     184             :                             {
     185           0 :                                 aNewValue <<= AccessibleStateType::FOCUSED;
     186           0 :                                 commitEvent( AccessibleEventId::STATE_CHANGED, aNewValue ,aOldValue);
     187           0 :                             }
     188             :                         }
     189             :                     }
     190           0 :                     break;
     191             : 
     192             :                 case VCLEVENT_CHECKBOX_TOGGLE :
     193             :                 {
     194           0 :                     if ( m_pTabListBox && m_pTabListBox->HasFocus() )
     195             :                     {
     196           0 :                         SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
     197           0 :                         if ( pEntry )
     198             :                         {
     199           0 :                             sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
     200           0 :                             sal_uInt16 nCol = m_pTabListBox->GetCurrColumn();
     201           0 :                             TriState eState = TRISTATE_INDET;
     202           0 :                             if ( m_pTabListBox->IsCellCheckBox( nRow, nCol, eState ) )
     203             :                             {
     204             :                                 Reference< XAccessible > xChild =
     205           0 :                                     m_pTabListBox->CreateAccessibleCell( nRow, nCol );
     206             :                                 AccessibleCheckBoxCell* pCell =
     207           0 :                                     static_cast< AccessibleCheckBoxCell* >( xChild.get() );
     208           0 :                                 pCell->SetChecked( SvHeaderTabListBox::IsItemChecked( pEntry, nCol ) );
     209             :                             }
     210             :                         }
     211             :                     }
     212           0 :                     break;
     213             :                 }
     214             : 
     215             :                 case VCLEVENT_TABLECELL_NAMECHANGED :
     216             :                 {
     217           0 :                     if ( m_pTabListBox->IsTransientChildrenDisabled() )
     218             :                     {
     219           0 :                         commitEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
     220           0 :                         TabListBoxEventData* pData = static_cast< TabListBoxEventData* >( rVclWindowEvent.GetData() );
     221           0 :                         SvTreeListEntry* pEntry = pData != NULL ? pData->m_pEntry : NULL;
     222           0 :                         if ( pEntry )
     223             :                         {
     224           0 :                             sal_Int32 nRow = m_pTabListBox->GetEntryPos( pEntry );
     225           0 :                             sal_uInt16 nCol = pData->m_nColumn;
     226             :                             Reference< XAccessible > xChild =
     227           0 :                                 m_pTabListBox->CreateAccessibleCell( nRow, nCol );
     228           0 :                             uno::Any aOldValue, aNewValue;
     229           0 :                             aOldValue <<= OUString( pData->m_sOldText );
     230           0 :                             OUString sNewText( m_pTabListBox->GetCellText( nRow, nCol ) );
     231           0 :                             aNewValue <<= sNewText;
     232           0 :                             TriState eState = TRISTATE_INDET;
     233             : 
     234           0 :                             if ( m_pTabListBox->IsCellCheckBox( nRow, nCol, eState ) )
     235             :                             {
     236             :                                 AccessibleCheckBoxCell* pCell =
     237           0 :                                     static_cast< AccessibleCheckBoxCell* >( xChild.get() );
     238           0 :                                 pCell->commitEvent( AccessibleEventId::NAME_CHANGED, aNewValue, aOldValue );
     239             :                             }
     240             :                             else
     241             :                             {
     242             :                                 AccessibleBrowseBoxTableCell* pCell =
     243           0 :                                     static_cast< AccessibleBrowseBoxTableCell* >( xChild.get() );
     244           0 :                                 pCell->nameChanged( sNewText, pData->m_sOldText );
     245           0 :                             }
     246             :                         }
     247             :                     }
     248           0 :                     break;
     249             :                 }
     250             :             }
     251             :         }
     252           0 :     }
     253             : 
     254           0 :     IMPL_LINK( AccessibleTabListBoxTable, WindowEventListener, VclSimpleEvent*, pEvent )
     255             :     {
     256             :         OSL_ENSURE( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
     257           0 :         if ( pEvent && pEvent->ISA( VclWindowEvent ) )
     258             :         {
     259             :             OSL_ENSURE( static_cast<VclWindowEvent*>( pEvent )->GetWindow() && m_pTabListBox, "no event window" );
     260           0 :             ProcessWindowEvent( *static_cast<VclWindowEvent*>(pEvent) );
     261             :         }
     262           0 :         return 0;
     263             :     }
     264             :     // helpers --------------------------------------------------------------------
     265             : 
     266           0 :     void AccessibleTabListBoxTable::ensureValidIndex( sal_Int32 _nIndex ) const
     267             :     {
     268           0 :         if ( ( _nIndex < 0 ) || ( _nIndex >= implGetCellCount() ) )
     269           0 :             throw IndexOutOfBoundsException();
     270           0 :     }
     271             : 
     272           0 :     bool AccessibleTabListBoxTable::implIsRowSelected( sal_Int32 _nRow ) const
     273             :     {
     274           0 :         return m_pTabListBox && m_pTabListBox->IsSelected( m_pTabListBox->GetEntry( _nRow ) );
     275             :     }
     276             : 
     277           0 :     void AccessibleTabListBoxTable::implSelectRow( sal_Int32 _nRow, bool _bSelect )
     278             :     {
     279           0 :         if ( m_pTabListBox )
     280           0 :             m_pTabListBox->Select( m_pTabListBox->GetEntry( _nRow ), _bSelect );
     281           0 :     }
     282             : 
     283           0 :     sal_Int32 AccessibleTabListBoxTable::implGetRowCount() const
     284             :     {
     285           0 :         return m_pTabListBox ? m_pTabListBox->GetEntryCount() : 0;
     286             :     }
     287             : 
     288           0 :     sal_Int32 AccessibleTabListBoxTable::implGetColumnCount() const
     289             :     {
     290           0 :         return m_pTabListBox ? m_pTabListBox->GetColumnCount() : 0;
     291             :     }
     292             : 
     293           0 :     sal_Int32 AccessibleTabListBoxTable::implGetSelRowCount() const
     294             :     {
     295           0 :         return m_pTabListBox ? m_pTabListBox->GetSelectionCount() : 0;
     296             :     }
     297             : 
     298           0 :     sal_Int32 AccessibleTabListBoxTable::implGetSelRow( sal_Int32 nSelRow ) const
     299             :     {
     300           0 :         if ( m_pTabListBox )
     301             :         {
     302           0 :             sal_Int32 nRow = 0;
     303           0 :             SvTreeListEntry* pEntry = m_pTabListBox->FirstSelected();
     304           0 :             while ( pEntry )
     305             :             {
     306           0 :                 ++nRow;
     307           0 :                 if ( nRow == nSelRow )
     308           0 :                     return m_pTabListBox->GetEntryPos( pEntry );
     309           0 :                 pEntry = m_pTabListBox->NextSelected( pEntry );
     310             :             }
     311             :         }
     312             : 
     313           0 :         return 0;
     314             :     }
     315             : 
     316             :     // XInterface & XTypeProvider
     317             : 
     318           0 :     IMPLEMENT_FORWARD_XINTERFACE2(AccessibleTabListBoxTable, AccessibleBrowseBoxTable, AccessibleTabListBoxTableImplHelper)
     319           0 :     IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleTabListBoxTable, AccessibleBrowseBoxTable, AccessibleTabListBoxTableImplHelper)
     320             : 
     321             :     // XServiceInfo
     322             : 
     323           0 :     OUString AccessibleTabListBoxTable::getImplementationName() throw (RuntimeException, std::exception)
     324             :     {
     325           0 :         return OUString( "com.sun.star.comp.svtools.AccessibleTabListBoxTable" );
     326             :     }
     327             : 
     328             :     // XAccessibleSelection
     329             : 
     330           0 :     void SAL_CALL AccessibleTabListBoxTable::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     331             :     {
     332           0 :         SolarMutexGuard aSolarGuard;
     333           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     334             : 
     335           0 :         ensureIsAlive();
     336           0 :         ensureValidIndex( nChildIndex );
     337             : 
     338           0 :         implSelectRow( implGetRow( nChildIndex ), true );
     339           0 :     }
     340             : 
     341           0 :     sal_Bool SAL_CALL AccessibleTabListBoxTable::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     342             :     {
     343           0 :         SolarMutexGuard aSolarGuard;
     344           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     345             : 
     346           0 :         ensureIsAlive();
     347           0 :         ensureValidIndex( nChildIndex );
     348             : 
     349           0 :         return implIsRowSelected( implGetRow( nChildIndex ) );
     350             :     }
     351             : 
     352           0 :     void SAL_CALL AccessibleTabListBoxTable::clearAccessibleSelection(  ) throw (RuntimeException, std::exception)
     353             :     {
     354           0 :         SolarMutexGuard aSolarGuard;
     355           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     356             : 
     357           0 :         ensureIsAlive();
     358             : 
     359           0 :         m_pTabListBox->SetNoSelection();
     360           0 :     }
     361             : 
     362           0 :     void SAL_CALL AccessibleTabListBoxTable::selectAllAccessibleChildren(  ) throw (RuntimeException, std::exception)
     363             :     {
     364           0 :         SolarMutexGuard aSolarGuard;
     365           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     366             : 
     367           0 :         ensureIsAlive();
     368             : 
     369           0 :         m_pTabListBox->SelectAll();
     370           0 :     }
     371             : 
     372           0 :     sal_Int32 SAL_CALL AccessibleTabListBoxTable::getSelectedAccessibleChildCount(  ) throw (RuntimeException, std::exception)
     373             :     {
     374           0 :         SolarMutexGuard aSolarGuard;
     375           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     376             : 
     377           0 :         ensureIsAlive();
     378             : 
     379           0 :         return implGetColumnCount() * implGetSelRowCount();
     380             :     }
     381             : 
     382           0 :     Reference< XAccessible > SAL_CALL AccessibleTabListBoxTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     383             :     {
     384           0 :         SolarMutexGuard aSolarGuard;
     385           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     386             : 
     387           0 :         ensureIsAlive();
     388             : 
     389           0 :         sal_Int32 nRows = implGetSelRowCount();
     390           0 :         if ( nRows == 0 )
     391           0 :             throw IndexOutOfBoundsException();
     392             : 
     393           0 :         sal_Int32 nRow = implGetSelRow( nSelectedChildIndex % nRows );
     394           0 :         sal_Int32 nColumn = nSelectedChildIndex / nRows;
     395           0 :         return getAccessibleCellAt( nRow, nColumn );
     396             :     }
     397             : 
     398           0 :     void SAL_CALL AccessibleTabListBoxTable::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     399             :     {
     400           0 :         SolarMutexGuard aSolarGuard;
     401           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     402             : 
     403           0 :         ensureIsAlive();
     404           0 :         ensureValidIndex( nSelectedChildIndex );
     405             : 
     406           0 :         implSelectRow( implGetRow( nSelectedChildIndex ), false );
     407           0 :     }
     408             : 
     409             : 
     410          36 : }// namespace accessibility
     411             : 
     412             : 
     413             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11