LCOV - code coverage report
Current view: top level - accessibility/source/extended - accessibletablistboxtable.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 188 0.0 %
Date: 2014-04-14 Functions: 0 26 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             : 
      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( m_pTabListBox->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, aOldValue, aNewValue );
     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( ( (VclWindowEvent*)pEvent )->GetWindow() && m_pTabListBox, "no event window" );
     260           0 :             ProcessWindowEvent( *(VclWindowEvent*)pEvent );
     261             :         }
     262           0 :         return 0;
     263             :     }
     264             :     // helpers --------------------------------------------------------------------
     265             : 
     266           0 :     void AccessibleTabListBoxTable::ensureValidIndex( sal_Int32 _nIndex ) const
     267             :             SAL_THROW( ( IndexOutOfBoundsException ) )
     268             :     {
     269           0 :         if ( ( _nIndex < 0 ) || ( _nIndex >= implGetCellCount() ) )
     270           0 :             throw IndexOutOfBoundsException();
     271           0 :     }
     272             : 
     273           0 :     sal_Bool AccessibleTabListBoxTable::implIsRowSelected( sal_Int32 _nRow ) const
     274             :     {
     275           0 :         return m_pTabListBox ? m_pTabListBox->IsSelected( m_pTabListBox->GetEntry( _nRow ) ) : sal_False;
     276             :     }
     277             : 
     278           0 :     void AccessibleTabListBoxTable::implSelectRow( sal_Int32 _nRow, sal_Bool _bSelect )
     279             :     {
     280           0 :         if ( m_pTabListBox )
     281           0 :             m_pTabListBox->Select( m_pTabListBox->GetEntry( _nRow ), _bSelect );
     282           0 :     }
     283             : 
     284           0 :     sal_Int32 AccessibleTabListBoxTable::implGetRowCount() const
     285             :     {
     286           0 :         return m_pTabListBox ? m_pTabListBox->GetEntryCount() : 0;
     287             :     }
     288             : 
     289           0 :     sal_Int32 AccessibleTabListBoxTable::implGetColumnCount() const
     290             :     {
     291           0 :         return m_pTabListBox ? m_pTabListBox->GetColumnCount() : 0;
     292             :     }
     293             : 
     294           0 :     sal_Int32 AccessibleTabListBoxTable::implGetSelRowCount() const
     295             :     {
     296           0 :         return m_pTabListBox ? m_pTabListBox->GetSelectionCount() : 0;
     297             :     }
     298             : 
     299           0 :     sal_Int32 AccessibleTabListBoxTable::implGetSelRow( sal_Int32 nSelRow ) const
     300             :     {
     301           0 :         if ( m_pTabListBox )
     302             :         {
     303           0 :             sal_Int32 nRow = 0;
     304           0 :             SvTreeListEntry* pEntry = m_pTabListBox->FirstSelected();
     305           0 :             while ( pEntry )
     306             :             {
     307           0 :                 ++nRow;
     308           0 :                 if ( nRow == nSelRow )
     309           0 :                     return m_pTabListBox->GetEntryPos( pEntry );
     310           0 :                 pEntry = m_pTabListBox->NextSelected( pEntry );
     311             :             }
     312             :         }
     313             : 
     314           0 :         return 0;
     315             :     }
     316             : 
     317             :     // XInterface & XTypeProvider
     318             : 
     319           0 :     IMPLEMENT_FORWARD_XINTERFACE2(AccessibleTabListBoxTable, AccessibleBrowseBoxTable, AccessibleTabListBoxTableImplHelper)
     320           0 :     IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleTabListBoxTable, AccessibleBrowseBoxTable, AccessibleTabListBoxTableImplHelper)
     321             : 
     322             :     // XServiceInfo
     323             : 
     324           0 :     OUString AccessibleTabListBoxTable::getImplementationName (void) throw (RuntimeException, std::exception)
     325             :     {
     326           0 :         return OUString( "com.sun.star.comp.svtools.AccessibleTabListBoxTable" );
     327             :     }
     328             : 
     329             :     // XAccessibleSelection
     330             : 
     331           0 :     void SAL_CALL AccessibleTabListBoxTable::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     332             :     {
     333           0 :         SolarMutexGuard aSolarGuard;
     334           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     335             : 
     336           0 :         ensureIsAlive();
     337           0 :         ensureValidIndex( nChildIndex );
     338             : 
     339           0 :         implSelectRow( implGetRow( nChildIndex ), sal_True );
     340           0 :     }
     341             : 
     342           0 :     sal_Bool SAL_CALL AccessibleTabListBoxTable::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     343             :     {
     344           0 :         SolarMutexGuard aSolarGuard;
     345           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     346             : 
     347           0 :         ensureIsAlive();
     348           0 :         ensureValidIndex( nChildIndex );
     349             : 
     350           0 :         return implIsRowSelected( implGetRow( nChildIndex ) );
     351             :     }
     352             : 
     353           0 :     void SAL_CALL AccessibleTabListBoxTable::clearAccessibleSelection(  ) throw (RuntimeException, std::exception)
     354             :     {
     355           0 :         SolarMutexGuard aSolarGuard;
     356           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     357             : 
     358           0 :         ensureIsAlive();
     359             : 
     360           0 :         m_pTabListBox->SetNoSelection();
     361           0 :     }
     362             : 
     363           0 :     void SAL_CALL AccessibleTabListBoxTable::selectAllAccessibleChildren(  ) throw (RuntimeException, std::exception)
     364             :     {
     365           0 :         SolarMutexGuard aSolarGuard;
     366           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     367             : 
     368           0 :         ensureIsAlive();
     369             : 
     370           0 :         m_pTabListBox->SelectAll();
     371           0 :     }
     372             : 
     373           0 :     sal_Int32 SAL_CALL AccessibleTabListBoxTable::getSelectedAccessibleChildCount(  ) throw (RuntimeException, std::exception)
     374             :     {
     375           0 :         SolarMutexGuard aSolarGuard;
     376           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     377             : 
     378           0 :         ensureIsAlive();
     379             : 
     380           0 :         return implGetColumnCount() * implGetSelRowCount();
     381             :     }
     382             : 
     383           0 :     Reference< XAccessible > SAL_CALL AccessibleTabListBoxTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     384             :     {
     385           0 :         SolarMutexGuard aSolarGuard;
     386           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     387             : 
     388           0 :         ensureIsAlive();
     389             : 
     390           0 :         sal_Int32 nRows = implGetSelRowCount();
     391           0 :         if ( nRows == 0 )
     392           0 :             throw IndexOutOfBoundsException();
     393             : 
     394           0 :         sal_Int32 nRow = implGetSelRow( nSelectedChildIndex % nRows );
     395           0 :         sal_Int32 nColumn = nSelectedChildIndex / nRows;
     396           0 :         return getAccessibleCellAt( nRow, nColumn );
     397             :     }
     398             : 
     399           0 :     void SAL_CALL AccessibleTabListBoxTable::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     400             :     {
     401           0 :         SolarMutexGuard aSolarGuard;
     402           0 :         ::osl::MutexGuard aGuard( getOslMutex() );
     403             : 
     404           0 :         ensureIsAlive();
     405           0 :         ensureValidIndex( nSelectedChildIndex );
     406             : 
     407           0 :         implSelectRow( implGetRow( nSelectedChildIndex ), sal_False );
     408           0 :     }
     409             : 
     410             : 
     411             : }// namespace accessibility
     412             : 
     413             : 
     414             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10