LCOV - code coverage report
Current view: top level - accessibility/source/extended - AccessibleBrowseBox.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 139 0.7 %
Date: 2014-11-03 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             : #include "accessibility/extended/AccessibleBrowseBox.hxx"
      21             : #include "accessibility/extended/AccessibleBrowseBoxTable.hxx"
      22             : #include "accessibility/extended/AccessibleBrowseBoxHeaderBar.hxx"
      23             : #include <svtools/accessibletableprovider.hxx>
      24             : #include <comphelper/types.hxx>
      25             : #include <toolkit/helper/vclunohelper.hxx>
      26             : 
      27             : 
      28             : 
      29             : namespace accessibility
      30             : {
      31             : 
      32             : 
      33             : 
      34             : using namespace ::com::sun::star::uno;
      35             : using namespace ::com::sun::star;
      36             : using namespace ::com::sun::star::lang;
      37             : using namespace ::com::sun::star::accessibility;
      38             : using namespace ::svt;
      39             : 
      40             : 
      41           0 : class AccessibleBrowseBoxImpl
      42             : {
      43             : public:
      44             :     /// the XAccessible which created the AccessibleBrowseBox
      45             :     WeakReference< XAccessible >                                m_aCreator;
      46             : 
      47             :     /** The data table child. */
      48             :     Reference<
      49             :         ::com::sun::star::accessibility::XAccessible >          mxTable;
      50             :     AccessibleBrowseBoxTable*                                   m_pTable;
      51             : 
      52             :     /** The header bar for rows ("handle column"). */
      53             :     Reference<
      54             :         ::com::sun::star::accessibility::XAccessible >          mxRowHeaderBar;
      55             :     AccessibleBrowseBoxHeaderBar*                               m_pRowHeaderBar;
      56             : 
      57             :     /** The header bar for columns (first row of the table). */
      58             :     Reference<
      59             :         ::com::sun::star::accessibility::XAccessible >          mxColumnHeaderBar;
      60             :     AccessibleBrowseBoxHeaderBar*                               m_pColumnHeaderBar;
      61             : };
      62             : 
      63             : // Ctor/Dtor/disposing --------------------------------------------------------
      64             : 
      65           0 : AccessibleBrowseBox::AccessibleBrowseBox(
      66             :             const Reference< XAccessible >& _rxParent, const Reference< XAccessible >& _rxCreator,
      67             :             IAccessibleTableProvider& _rBrowseBox )
      68           0 :     : AccessibleBrowseBoxBase( _rxParent, _rBrowseBox,NULL, BBTYPE_BROWSEBOX )
      69             : {
      70           0 :     m_pImpl.reset( new AccessibleBrowseBoxImpl() );
      71           0 :     m_pImpl->m_aCreator = _rxCreator;
      72             : 
      73           0 :     m_xFocusWindow = VCLUnoHelper::GetInterface(mpBrowseBox->GetWindowInstance());
      74           0 : }
      75             : 
      76           0 : void AccessibleBrowseBox::setCreator( const Reference< XAccessible >& _rxCreator )
      77             : {
      78             : #if OSL_DEBUG_LEVEL > 0
      79             :     Reference< XAccessible > xCreator(m_pImpl->m_aCreator);
      80             :     OSL_ENSURE( !xCreator.is(), "accessibility/extended/AccessibleBrowseBox::setCreator: creator already set!" );
      81             : #endif
      82           0 :     m_pImpl->m_aCreator = _rxCreator;
      83           0 : }
      84             : 
      85             : 
      86           0 : AccessibleBrowseBox::~AccessibleBrowseBox()
      87             : {
      88           0 : }
      89             : 
      90             : 
      91           0 : void SAL_CALL AccessibleBrowseBox::disposing()
      92             : {
      93           0 :     ::osl::MutexGuard aGuard( getOslMutex() );
      94             : 
      95           0 :     m_pImpl->m_pTable           = NULL;
      96           0 :     m_pImpl->m_pColumnHeaderBar = NULL;
      97           0 :     m_pImpl->m_pRowHeaderBar    = NULL;
      98           0 :     m_pImpl->m_aCreator.clear();
      99             : 
     100           0 :     Reference< XAccessible >  xTable = m_pImpl->mxTable;
     101             : 
     102           0 :     Reference< XComponent > xComp( m_pImpl->mxTable, UNO_QUERY );
     103           0 :     if ( xComp.is() )
     104             :     {
     105           0 :         xComp->dispose();
     106             : 
     107             :     }
     108             : //!    ::comphelper::disposeComponent(m_pImpl->mxTable);
     109           0 :     ::comphelper::disposeComponent(m_pImpl->mxRowHeaderBar);
     110           0 :     ::comphelper::disposeComponent(m_pImpl->mxColumnHeaderBar);
     111             : 
     112           0 :     AccessibleBrowseBoxBase::disposing();
     113           0 : }
     114             : 
     115             : 
     116             : // XAccessibleContext ---------------------------------------------------------
     117             : 
     118           0 : sal_Int32 SAL_CALL AccessibleBrowseBox::getAccessibleChildCount()
     119             :     throw ( uno::RuntimeException, std::exception )
     120             : {
     121           0 :     SolarMutexGuard aSolarGuard;
     122           0 :     ::osl::MutexGuard aGuard( getOslMutex() );
     123           0 :     ensureIsAlive();
     124           0 :     return BBINDEX_FIRSTCONTROL + mpBrowseBox->GetAccessibleControlCount();
     125             : }
     126             : 
     127             : 
     128             : Reference< XAccessible > SAL_CALL
     129           0 : AccessibleBrowseBox::getAccessibleChild( sal_Int32 nChildIndex )
     130             :     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
     131             : {
     132           0 :     SolarMutexGuard aSolarGuard;
     133           0 :     ::osl::MutexGuard aGuard( getOslMutex() );
     134           0 :     ensureIsAlive();
     135             : 
     136           0 :     Reference< XAccessible > xRet;
     137           0 :     if( nChildIndex >= 0 )
     138             :     {
     139           0 :         if( nChildIndex < BBINDEX_FIRSTCONTROL )
     140           0 :             xRet = implGetFixedChild( nChildIndex );
     141             :         else
     142             :         {
     143             :             // additional controls
     144           0 :             nChildIndex -= BBINDEX_FIRSTCONTROL;
     145           0 :             if( nChildIndex < mpBrowseBox->GetAccessibleControlCount() )
     146           0 :                 xRet = mpBrowseBox->CreateAccessibleControl( nChildIndex );
     147             :         }
     148             :     }
     149             : 
     150           0 :     if( !xRet.is() )
     151           0 :         throw lang::IndexOutOfBoundsException();
     152           0 :     return xRet;
     153             : }
     154             : 
     155             : // XAccessibleComponent -------------------------------------------------------
     156             : 
     157             : Reference< XAccessible > SAL_CALL
     158           0 : AccessibleBrowseBox::getAccessibleAtPoint( const awt::Point& rPoint )
     159             :     throw ( uno::RuntimeException, std::exception )
     160             : {
     161           0 :     SolarMutexGuard aSolarGuard;
     162           0 :     ::osl::MutexGuard aGuard( getOslMutex() );
     163           0 :     ensureIsAlive();
     164             : 
     165           0 :     Reference< XAccessible > xChild;
     166           0 :     sal_Int32 nIndex = 0;
     167           0 :     if( mpBrowseBox->ConvertPointToControlIndex( nIndex, VCLPoint( rPoint ) ) )
     168           0 :         xChild = mpBrowseBox->CreateAccessibleControl( nIndex );
     169             :     else
     170             :     {
     171             :         // try whether point is in one of the fixed children
     172             :         // (table, header bars, corner control)
     173           0 :         Point aPoint( VCLPoint( rPoint ) );
     174           0 :         for( nIndex = 0; (nIndex < BBINDEX_FIRSTCONTROL) && !xChild.is(); ++nIndex )
     175             :         {
     176           0 :             Reference< XAccessible > xCurrChild( implGetFixedChild( nIndex ) );
     177             :             Reference< XAccessibleComponent >
     178           0 :                 xCurrChildComp( xCurrChild, uno::UNO_QUERY );
     179             : 
     180           0 :             if( xCurrChildComp.is() &&
     181           0 :                     VCLRectangle( xCurrChildComp->getBounds() ).IsInside( aPoint ) )
     182           0 :                 xChild = xCurrChild;
     183           0 :         }
     184             :     }
     185           0 :     return xChild;
     186             : }
     187             : 
     188             : 
     189           0 : void SAL_CALL AccessibleBrowseBox::grabFocus()
     190             :     throw ( uno::RuntimeException, std::exception )
     191             : {
     192           0 :     SolarMutexGuard aSolarGuard;
     193           0 :     ::osl::MutexGuard aGuard( getOslMutex() );
     194           0 :     ensureIsAlive();
     195           0 :     mpBrowseBox->GrabFocus();
     196           0 : }
     197             : 
     198             : // XServiceInfo ---------------------------------------------------------------
     199             : 
     200           0 : OUString SAL_CALL AccessibleBrowseBox::getImplementationName()
     201             :     throw ( uno::RuntimeException, std::exception )
     202             : {
     203           0 :     return OUString( "com.sun.star.comp.svtools.AccessibleBrowseBox" );
     204             : }
     205             : 
     206             : 
     207             : // internal virtual methods ---------------------------------------------------
     208             : 
     209           0 : Rectangle AccessibleBrowseBox::implGetBoundingBox()
     210             : {
     211           0 :     vcl::Window* pParent = mpBrowseBox->GetAccessibleParentWindow();
     212             :     OSL_ENSURE( pParent, "implGetBoundingBox - missing parent window" );
     213           0 :     return mpBrowseBox->GetWindowExtentsRelative( pParent );
     214             : }
     215             : 
     216             : 
     217           0 : Rectangle AccessibleBrowseBox::implGetBoundingBoxOnScreen()
     218             : {
     219           0 :     return mpBrowseBox->GetWindowExtentsRelative( NULL );
     220             : }
     221             : 
     222             : 
     223             : // internal helper methods ----------------------------------------------------
     224             : 
     225           0 : Reference< XAccessible > AccessibleBrowseBox::implGetTable()
     226             : {
     227           0 :     if( !m_pImpl->mxTable.is() )
     228             :     {
     229           0 :         m_pImpl->m_pTable = createAccessibleTable();
     230           0 :         m_pImpl->mxTable  = m_pImpl->m_pTable;
     231             : 
     232             :     }
     233           0 :     return m_pImpl->mxTable;
     234             : }
     235             : 
     236             : 
     237             : Reference< XAccessible >
     238           0 : AccessibleBrowseBox::implGetHeaderBar( AccessibleBrowseBoxObjType eObjType )
     239             : {
     240           0 :     Reference< XAccessible > xRet;
     241           0 :     Reference< XAccessible >* pxMember = NULL;
     242             : 
     243           0 :     if( eObjType == BBTYPE_ROWHEADERBAR )
     244           0 :         pxMember = &m_pImpl->mxRowHeaderBar;
     245           0 :     else if( eObjType ==  BBTYPE_COLUMNHEADERBAR )
     246           0 :         pxMember = &m_pImpl->mxColumnHeaderBar;
     247             : 
     248           0 :     if( pxMember )
     249             :     {
     250           0 :         if( !pxMember->is() )
     251             :         {
     252             :             AccessibleBrowseBoxHeaderBar* pHeaderBar = new AccessibleBrowseBoxHeaderBar(
     253           0 :                 m_pImpl->m_aCreator, *mpBrowseBox, eObjType );
     254             : 
     255           0 :             if ( BBTYPE_COLUMNHEADERBAR == eObjType)
     256           0 :                 m_pImpl->m_pColumnHeaderBar = pHeaderBar;
     257             :             else
     258           0 :                 m_pImpl->m_pRowHeaderBar    = pHeaderBar;
     259             : 
     260           0 :             *pxMember = pHeaderBar;
     261             :         }
     262           0 :         xRet = *pxMember;
     263             :     }
     264           0 :     return xRet;
     265             : }
     266             : 
     267             : 
     268             : Reference< XAccessible >
     269           0 : AccessibleBrowseBox::implGetFixedChild( sal_Int32 nChildIndex )
     270             : {
     271           0 :     Reference< XAccessible > xRet;
     272           0 :     switch( nChildIndex )
     273             :     {
     274             :         case BBINDEX_COLUMNHEADERBAR:
     275           0 :             xRet = implGetHeaderBar( BBTYPE_COLUMNHEADERBAR );
     276           0 :         break;
     277             :         case BBINDEX_ROWHEADERBAR:
     278           0 :             xRet = implGetHeaderBar( BBTYPE_ROWHEADERBAR );
     279           0 :         break;
     280             :         case BBINDEX_TABLE:
     281           0 :             xRet = implGetTable();
     282           0 :         break;
     283             :     }
     284           0 :     return xRet;
     285             : }
     286             : 
     287           0 : AccessibleBrowseBoxTable* AccessibleBrowseBox::createAccessibleTable()
     288             : {
     289           0 :     Reference< XAccessible > xCreator(m_pImpl->m_aCreator);
     290             :     OSL_ENSURE( xCreator.is(), "accessibility/extended/AccessibleBrowseBox::createAccessibleTable: my creator died - how this?" );
     291           0 :     return new AccessibleBrowseBoxTable( xCreator, *mpBrowseBox );
     292             : }
     293             : 
     294           0 : void AccessibleBrowseBox::commitTableEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
     295             : {
     296           0 :     if ( m_pImpl->mxTable.is() )
     297             :     {
     298           0 :         m_pImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
     299             :     }
     300           0 : }
     301             : 
     302           0 : void AccessibleBrowseBox::commitHeaderBarEvent( sal_Int16 _nEventId,
     303             :                                                 const Any& _rNewValue,
     304             :                                                 const Any& _rOldValue,bool _bColumnHeaderBar)
     305             : {
     306           0 :     Reference< XAccessible > xHeaderBar = _bColumnHeaderBar ? m_pImpl->mxColumnHeaderBar : m_pImpl->mxRowHeaderBar;
     307           0 :     AccessibleBrowseBoxHeaderBar* pHeaderBar = _bColumnHeaderBar ? m_pImpl->m_pColumnHeaderBar : m_pImpl->m_pRowHeaderBar;
     308           0 :     if ( xHeaderBar.is() )
     309           0 :         pHeaderBar->commitEvent(_nEventId,_rNewValue,_rOldValue);
     310           0 : }
     311             : 
     312             : 
     313             : // = AccessibleBrowseBoxAccess
     314             : 
     315           0 : AccessibleBrowseBoxAccess::AccessibleBrowseBoxAccess( const Reference< XAccessible >& _rxParent, IAccessibleTableProvider& _rBrowseBox )
     316             :         :m_xParent( _rxParent )
     317             :         ,m_rBrowseBox( _rBrowseBox )
     318           0 :         ,m_pContext( NULL )
     319             : {
     320           0 : }
     321             : 
     322             : 
     323           0 : AccessibleBrowseBoxAccess::~AccessibleBrowseBoxAccess()
     324             : {
     325           0 : }
     326             : 
     327             : 
     328           0 : void AccessibleBrowseBoxAccess::dispose()
     329             : {
     330           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     331             : 
     332           0 :     m_pContext = NULL;
     333           0 :     ::comphelper::disposeComponent( m_xContext );
     334           0 : }
     335             : 
     336             : 
     337           0 : Reference< XAccessibleContext > SAL_CALL AccessibleBrowseBoxAccess::getAccessibleContext() throw ( RuntimeException, std::exception )
     338             : {
     339           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     340             : 
     341             :     OSL_ENSURE( ( m_pContext && m_xContext.is() ) || ( !m_pContext && !m_xContext.is() ),
     342             :         "accessibility/extended/AccessibleBrowseBoxAccess::getAccessibleContext: inconsistency!" );
     343             : 
     344             :     // if the context died meanwhile (there is no listener, so it won't tell us explicitily when this happens),
     345             :     // then reset and re-create.
     346           0 :     if ( m_pContext && !m_pContext->isAlive() )
     347           0 :         m_xContext = m_pContext = NULL;
     348             : 
     349           0 :     if ( !m_xContext.is() )
     350           0 :         m_xContext = m_pContext = new AccessibleBrowseBox( m_xParent, this, m_rBrowseBox );
     351             : 
     352           0 :     return m_xContext;
     353             : }
     354             : 
     355             : 
     356           0 : bool AccessibleBrowseBoxAccess::isContextAlive() const
     357             : {
     358           0 :     return  ( NULL != m_pContext ) && m_pContext->isAlive();
     359             : }
     360             : 
     361             : 
     362             : 
     363          60 : }   // namespace accessibility
     364             : 
     365             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10