LCOV - code coverage report
Current view: top level - accessibility/source/extended - AccessibleGridControl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 181 0.0 %
Date: 2015-06-13 12:38:46 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             : #include "accessibility/extended/AccessibleGridControl.hxx"
      21             : #include "accessibility/extended/AccessibleGridControlTable.hxx"
      22             : #include "accessibility/extended/AccessibleGridControlHeader.hxx"
      23             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      24             : #include <com/sun/star/accessibility/AccessibleTableModelChange.hpp>
      25             : #include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp>
      26             : #include <svtools/accessibletable.hxx>
      27             : #include <comphelper/types.hxx>
      28             : #include <toolkit/helper/vclunohelper.hxx>
      29             : 
      30             : 
      31             : 
      32             : namespace accessibility
      33             : {
      34             : 
      35             : 
      36             : 
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star;
      39             : using namespace ::com::sun::star::lang;
      40             : using namespace ::com::sun::star::accessibility;
      41             : using namespace ::svt;
      42             : using namespace ::svt::table;
      43             : 
      44             : 
      45           0 : class AccessibleGridControl_Impl
      46             : {
      47             : public:
      48             :     /// the XAccessible which created the AccessibleGridControl
      49             :     WeakReference< XAccessible >                                m_aCreator;
      50             : 
      51             :     /** The data table child. */
      52             :     Reference<
      53             :         ::com::sun::star::accessibility::XAccessible >          m_xTable;
      54             :     AccessibleGridControlTable*             m_pTable;
      55             : 
      56             :     /** The header bar for rows. */
      57             :     Reference<
      58             :         ::com::sun::star::accessibility::XAccessible >          m_xRowHeaderBar;
      59             :     AccessibleGridControlHeader*                m_pRowHeaderBar;
      60             : 
      61             :     /** The header bar for columns (first row of the table). */
      62             :     Reference<
      63             :         ::com::sun::star::accessibility::XAccessible >          m_xColumnHeaderBar;
      64             :     AccessibleGridControlHeader*                m_pColumnHeaderBar;
      65             : 
      66             :     /** The table cell child. */
      67             :     Reference<
      68             :         ::com::sun::star::accessibility::XAccessible >          m_xCell;
      69             :     AccessibleGridControlTableCell*             m_pCell;
      70             : 
      71             : };
      72             : 
      73           0 : AccessibleGridControl::AccessibleGridControl(
      74             :             const Reference< XAccessible >& _rxParent, const Reference< XAccessible >& _rxCreator,
      75             :             IAccessibleTable& _rTable )
      76           0 :     : AccessibleGridControlBase( _rxParent, _rTable, TCTYPE_GRIDCONTROL )
      77             : {
      78           0 :     m_xImpl.reset( new AccessibleGridControl_Impl() );
      79           0 :     m_xImpl->m_aCreator = _rxCreator;
      80           0 : }
      81             : 
      82             : 
      83           0 : AccessibleGridControl::~AccessibleGridControl()
      84             : {
      85           0 : }
      86             : 
      87             : 
      88           0 : void SAL_CALL AccessibleGridControl::disposing()
      89             : {
      90           0 :     SolarMutexGuard g;
      91             : 
      92           0 :     m_xImpl->m_pTable       = NULL;
      93           0 :     m_xImpl->m_pColumnHeaderBar = NULL;
      94           0 :     m_xImpl->m_pRowHeaderBar    = NULL;
      95           0 :     m_xImpl->m_pCell            = NULL;
      96           0 :     m_xImpl->m_aCreator.clear();
      97             : 
      98           0 :     Reference< XAccessible >  xTable = m_xImpl->m_xTable;
      99             : 
     100           0 :     Reference< XComponent > xComp( m_xImpl->m_xTable, UNO_QUERY );
     101           0 :     if ( xComp.is() )
     102             :     {
     103           0 :         xComp->dispose();
     104             :     }
     105           0 :     Reference< XAccessible >  xCell = m_xImpl->m_xCell;
     106             : 
     107           0 :     Reference< XComponent > xCellComp( m_xImpl->m_xCell, UNO_QUERY );
     108           0 :     if ( xCellComp.is() )
     109             :     {
     110           0 :         xCellComp->dispose();
     111             :     }
     112             : 
     113           0 :     ::comphelper::disposeComponent(m_xImpl->m_xRowHeaderBar);
     114           0 :     ::comphelper::disposeComponent(m_xImpl->m_xColumnHeaderBar);
     115           0 :     AccessibleGridControlBase::disposing();
     116           0 : }
     117             : 
     118             : 
     119             : // XAccessibleContext ---------------------------------------------------------
     120             : 
     121           0 : sal_Int32 SAL_CALL AccessibleGridControl::getAccessibleChildCount()
     122             :     throw ( uno::RuntimeException, std::exception )
     123             : {
     124           0 :     SolarMutexGuard aSolarGuard;
     125           0 :     ensureIsAlive();
     126           0 :     return m_aTable.GetAccessibleControlCount();
     127             : }
     128             : 
     129             : 
     130             : Reference< XAccessible > SAL_CALL
     131           0 : AccessibleGridControl::getAccessibleChild( sal_Int32 nChildIndex )
     132             :     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
     133             : {
     134           0 :     SolarMutexGuard aSolarGuard;
     135             : 
     136           0 :     if (nChildIndex<0 || nChildIndex>=getAccessibleChildCount())
     137           0 :         throw IndexOutOfBoundsException();
     138             : 
     139           0 :     Reference< XAccessible > xChild;
     140           0 :     if (isAlive())
     141             :     {
     142           0 :         if(nChildIndex == 0 && m_aTable.HasColHeader())
     143             :         {
     144           0 :             if(!m_xImpl->m_xColumnHeaderBar.is())
     145             :             {
     146           0 :                 AccessibleGridControlHeader* pColHeaderBar = new AccessibleGridControlHeader(m_xImpl->m_aCreator, m_aTable, svt::table::TCTYPE_COLUMNHEADERBAR);
     147           0 :                 m_xImpl->m_xColumnHeaderBar = pColHeaderBar;
     148             :             }
     149           0 :             xChild = m_xImpl->m_xColumnHeaderBar;
     150             :         }
     151           0 :         else if(m_aTable.HasRowHeader() && (nChildIndex == 1 || nChildIndex == 0))
     152             :         {
     153           0 :             if(!m_xImpl->m_xRowHeaderBar.is())
     154             :             {
     155           0 :                 AccessibleGridControlHeader* pRowHeaderBar = new AccessibleGridControlHeader(m_xImpl->m_aCreator, m_aTable, svt::table::TCTYPE_ROWHEADERBAR);
     156           0 :                 m_xImpl->m_xRowHeaderBar = pRowHeaderBar;
     157             :             }
     158           0 :             xChild = m_xImpl->m_xRowHeaderBar;
     159             :         }
     160             :         else
     161             :         {
     162           0 :             if(!m_xImpl->m_xTable.is())
     163             :             {
     164           0 :             AccessibleGridControlTable* pTable = new AccessibleGridControlTable(m_xImpl->m_aCreator, m_aTable, svt::table::TCTYPE_TABLE);
     165           0 :             m_xImpl->m_xTable = pTable;
     166           0 :                 m_xImpl->m_pTable = pTable;
     167             :             }
     168           0 :             xChild = m_xImpl->m_xTable;
     169             :         }
     170             :     }
     171           0 :     return xChild;
     172             : }
     173             : 
     174             : 
     175           0 : sal_Int16 SAL_CALL AccessibleGridControl::getAccessibleRole()
     176             :     throw ( uno::RuntimeException, std::exception )
     177             : {
     178           0 :     SolarMutexGuard g;
     179             : 
     180           0 :     ensureIsAlive();
     181           0 :     return AccessibleRole::PANEL;
     182             : }
     183             : 
     184             : 
     185             : // XAccessibleComponent -------------------------------------------------------
     186             : 
     187             : Reference< XAccessible > SAL_CALL
     188           0 : AccessibleGridControl::getAccessibleAtPoint( const awt::Point& rPoint )
     189             :     throw ( uno::RuntimeException, std::exception )
     190             : {
     191           0 :     SolarMutexGuard aSolarGuard;
     192           0 :     ensureIsAlive();
     193             : 
     194           0 :     Reference< XAccessible > xChild;
     195           0 :     sal_Int32 nIndex = 0;
     196           0 :     if( m_aTable.ConvertPointToControlIndex( nIndex, VCLPoint( rPoint ) ) )
     197           0 :         xChild = m_aTable.CreateAccessibleControl( nIndex );
     198             :     else
     199             :     {
     200             :         // try whether point is in one of the fixed children
     201             :         // (table, header bars, corner control)
     202           0 :         Point aPoint( VCLPoint( rPoint ) );
     203           0 :         for( nIndex = 0; (nIndex < 3) && !xChild.is(); ++nIndex )
     204             :         {
     205           0 :             Reference< XAccessible > xCurrChild( implGetFixedChild( nIndex ) );
     206             :             Reference< XAccessibleComponent >
     207           0 :             xCurrChildComp( xCurrChild, uno::UNO_QUERY );
     208             : 
     209           0 :             if( xCurrChildComp.is() &&
     210           0 :                 VCLRectangle( xCurrChildComp->getBounds() ).IsInside( aPoint ) )
     211           0 :             xChild = xCurrChild;
     212           0 :         }
     213             :     }
     214           0 :     return xChild;
     215             : }
     216             : 
     217             : 
     218           0 : void SAL_CALL AccessibleGridControl::grabFocus()
     219             :     throw ( uno::RuntimeException, std::exception )
     220             : {
     221           0 :     SolarMutexGuard aSolarGuard;
     222           0 :     ensureIsAlive();
     223           0 :         m_aTable.GrabFocus();
     224           0 : }
     225             : 
     226             : // XServiceInfo ---------------------------------------------------------------
     227             : 
     228           0 : OUString SAL_CALL AccessibleGridControl::getImplementationName()
     229             :     throw ( uno::RuntimeException, std::exception )
     230             : {
     231           0 :     return OUString( "com.sun.star.accessibility.AccessibleGridControl" );
     232             : }
     233             : 
     234             : 
     235             : // internal virtual methods ---------------------------------------------------
     236             : 
     237           0 : Rectangle AccessibleGridControl::implGetBoundingBox()
     238             : {
     239           0 :     vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
     240             :     OSL_ENSURE( pParent, "implGetBoundingBox - missing parent window" );
     241           0 :     return m_aTable.GetWindowExtentsRelative( pParent );
     242             : }
     243             : 
     244             : 
     245           0 : Rectangle AccessibleGridControl::implGetBoundingBoxOnScreen()
     246             : {
     247           0 :     return m_aTable.GetWindowExtentsRelative( NULL );
     248             : }
     249             : // internal helper methods ----------------------------------------------------
     250             : 
     251           0 : Reference< XAccessible > AccessibleGridControl::implGetTable()
     252             : {
     253           0 :     if( !m_xImpl->m_xTable.is() )
     254             :     {
     255           0 :         m_xImpl->m_pTable = createAccessibleTable();
     256           0 :         m_xImpl->m_xTable  = m_xImpl->m_pTable;
     257             :     }
     258           0 :     return m_xImpl->m_xTable;
     259             : }
     260             : 
     261             : 
     262             : Reference< XAccessible >
     263           0 : AccessibleGridControl::implGetHeaderBar( AccessibleTableControlObjType eObjType )
     264             : {
     265           0 :     Reference< XAccessible > xRet;
     266           0 :     Reference< XAccessible >* pxMember = NULL;
     267             : 
     268           0 :     if( eObjType == TCTYPE_ROWHEADERBAR )
     269           0 :         pxMember = &m_xImpl->m_xRowHeaderBar;
     270           0 :     else if( eObjType ==  TCTYPE_COLUMNHEADERBAR )
     271           0 :         pxMember = &m_xImpl->m_xColumnHeaderBar;
     272             : 
     273           0 :     if( pxMember )
     274             :     {
     275           0 :         if( !pxMember->is() )
     276             :         {
     277             :             AccessibleGridControlHeader* pHeaderBar = new AccessibleGridControlHeader(
     278           0 :                 m_xImpl->m_aCreator, m_aTable, eObjType );
     279             : 
     280           0 :             if ( TCTYPE_COLUMNHEADERBAR == eObjType)
     281           0 :                 m_xImpl->m_pColumnHeaderBar = pHeaderBar;
     282             :             else
     283           0 :                 m_xImpl->m_pRowHeaderBar    = pHeaderBar;
     284             : 
     285           0 :             *pxMember = pHeaderBar;
     286             :         }
     287           0 :         xRet = *pxMember;
     288             :     }
     289           0 :     return xRet;
     290             : }
     291             : 
     292             : Reference< XAccessible >
     293           0 : AccessibleGridControl::implGetFixedChild( sal_Int32 nChildIndex )
     294             : {
     295           0 :     Reference< XAccessible > xRet;
     296           0 :     switch( nChildIndex )
     297             :     {
     298             :           case TCINDEX_COLUMNHEADERBAR:
     299           0 :             xRet = implGetHeaderBar( TCTYPE_COLUMNHEADERBAR );
     300           0 :         break;
     301             :         case TCINDEX_ROWHEADERBAR:
     302           0 :             xRet = implGetHeaderBar( TCTYPE_ROWHEADERBAR );
     303           0 :         break;
     304             :         case TCINDEX_TABLE:
     305           0 :             xRet = implGetTable();
     306           0 :         break;
     307             :     }
     308           0 :     return xRet;
     309             : }
     310             : 
     311           0 : AccessibleGridControlTable* AccessibleGridControl::createAccessibleTable()
     312             : {
     313           0 :     Reference< XAccessible > xCreator(m_xImpl->m_aCreator);
     314             :     OSL_ENSURE( xCreator.is(), "accessibility/extended/AccessibleGirdControl::createAccessibleTable: my creator died - how this?" );
     315           0 :     return new AccessibleGridControlTable( xCreator, m_aTable, TCTYPE_TABLE );
     316             : }
     317             : 
     318           0 : void AccessibleGridControl::commitCellEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
     319             : {
     320           0 :     sal_Int32 nChildCount = getAccessibleChildCount();
     321           0 :     if(nChildCount != 0)
     322             :     {
     323           0 :         for(sal_Int32 i=0;i<nChildCount;i++)
     324             :         {
     325           0 :             Reference< XAccessible > xAccessible = getAccessibleChild(i);
     326           0 :             com::sun::star::uno::Reference< com::sun::star::accessibility::XAccessibleContext > xAccessibleChild = xAccessible->getAccessibleContext();
     327           0 :             if(m_xImpl->m_xTable == xAccessible)
     328             :             {
     329             :                 std::vector< AccessibleGridControlTableCell* >& rCells =
     330           0 :                     m_xImpl->m_pTable->getCellVector();
     331           0 :                 size_t nIndex = m_aTable.GetCurrentRow() * m_aTable.GetColumnCount()
     332           0 :                               + m_aTable.GetCurrentColumn();
     333           0 :                 if (nIndex < rCells.size() && rCells[nIndex])
     334             :                 {
     335           0 :                     m_xImpl->m_pCell = rCells[nIndex];
     336           0 :                     m_xImpl->m_pCell->commitEvent( _nEventId, _rNewValue, _rOldValue );
     337             :                 }
     338             :             }
     339           0 :         }
     340             :     }
     341             :     else
     342             :     {
     343           0 :         if ( m_xImpl->m_xTable.is() )
     344           0 :             m_xImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
     345             :     }
     346           0 : }
     347             : 
     348           0 : void AccessibleGridControl::commitTableEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
     349             : {
     350           0 :     if ( m_xImpl->m_xTable.is() )
     351             :     {
     352           0 :         if(_nEventId == AccessibleEventId::ACTIVE_DESCENDANT_CHANGED)
     353             :         {
     354           0 :             Reference< XAccessible > xChild = m_xImpl->m_pTable->getAccessibleChild(m_aTable.GetCurrentRow()*m_aTable.GetColumnCount()+m_aTable.GetCurrentColumn());
     355           0 :             m_xImpl->m_pTable->commitEvent(_nEventId, makeAny(xChild),_rOldValue);
     356             :         }
     357           0 :         else if(_nEventId == AccessibleEventId::TABLE_MODEL_CHANGED)
     358             :         {
     359           0 :             AccessibleTableModelChange aChange;
     360           0 :             if(_rNewValue >>= aChange)
     361             :             {
     362           0 :                 if(aChange.Type == AccessibleTableModelChangeType::DELETE)
     363             :                 {
     364             :                     std::vector< AccessibleGridControlTableCell* >& rCells =
     365           0 :                         m_xImpl->m_pTable->getCellVector();
     366             :                     std::vector< Reference< XAccessible > >& rAccCells =
     367           0 :                         m_xImpl->m_pTable->getAccessibleCellVector();
     368           0 :                     int nColCount = m_aTable.GetColumnCount();
     369             :                     // check valid index - entries are inserted lazily
     370           0 :                     size_t const nStart = nColCount * aChange.FirstRow;
     371           0 :                     size_t const nEnd   = nColCount * aChange.LastRow;
     372           0 :                     if (nStart < rCells.size())
     373             :                     {
     374           0 :                         m_xImpl->m_pTable->getCellVector().erase(
     375             :                             rCells.begin() + nStart,
     376           0 :                             rCells.begin() + std::min(rCells.size(), nEnd));
     377             :                     }
     378           0 :                     if (nStart < rAccCells.size())
     379             :                     {
     380           0 :                         m_xImpl->m_pTable->getAccessibleCellVector().erase(
     381             :                             rAccCells.begin() + nStart,
     382           0 :                             rAccCells.begin() + std::min(rAccCells.size(), nEnd));
     383             :                     }
     384           0 :                     m_xImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
     385             :                 }
     386             :                 else
     387           0 :                     m_xImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
     388             :             }
     389             :         }
     390             :         else
     391           0 :             m_xImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
     392             :     }
     393           0 : }
     394             : 
     395             : // = AccessibleGridControlAccess
     396             : 
     397             : 
     398             : 
     399           0 : AccessibleGridControlAccess::AccessibleGridControlAccess(
     400             :         const Reference< XAccessible >& rxParent, IAccessibleTable& rTable )
     401             :     : m_xParent( rxParent )
     402             :     , m_pTable( & rTable )
     403           0 :     , m_pContext( 0 )
     404             : {
     405           0 : }
     406             : 
     407             : 
     408           0 : AccessibleGridControlAccess::~AccessibleGridControlAccess()
     409             : {
     410           0 : }
     411             : 
     412             : 
     413           0 : void AccessibleGridControlAccess::DisposeAccessImpl()
     414             : {
     415           0 :     SolarMutexGuard g;
     416             : 
     417           0 :     m_pTable = 0;
     418           0 :     m_pContext = NULL;
     419           0 :     ::comphelper::disposeComponent( m_xContext );
     420           0 : }
     421             : 
     422             : 
     423           0 : Reference< XAccessibleContext > SAL_CALL AccessibleGridControlAccess::getAccessibleContext() throw ( RuntimeException, std::exception )
     424             : {
     425           0 :     SolarMutexGuard g;
     426             : 
     427             :     OSL_ENSURE( ( m_pContext && m_xContext.is() ) || ( !m_pContext && !m_xContext.is() ),
     428             :         "accessibility/extended/AccessibleGridControlAccess::getAccessibleContext: inconsistency!" );
     429             : 
     430             :     // if the context died meanwhile (we're no listener, so it won't tell us explicitily when this happens),
     431             :     // then reset an re-create.
     432           0 :     if ( m_pContext && !m_pContext->isAlive() )
     433           0 :         m_xContext = m_pContext = NULL;
     434             : 
     435           0 :     if (!m_xContext.is() && m_pTable)
     436           0 :         m_xContext = m_pContext =
     437           0 :             new AccessibleGridControl(m_xParent, this, *m_pTable);
     438             : 
     439           0 :     return m_xContext;
     440             : }
     441             : 
     442             : 
     443           0 : bool AccessibleGridControlAccess::isContextAlive() const
     444             : {
     445           0 :     return  ( NULL != m_pContext ) && m_pContext->isAlive();
     446             : }
     447             : 
     448             : 
     449             : 
     450             : }   // namespace accessibility
     451             : 
     452             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11