LCOV - code coverage report
Current view: top level - libreoffice/accessibility/source/extended - accessiblelistbox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 183 0.0 %
Date: 2012-12-27 Functions: 0 32 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/accessiblelistbox.hxx>
      21             : #include <accessibility/extended/accessiblelistboxentry.hxx>
      22             : #include <svtools/treelistbox.hxx>
      23             : #include <com/sun/star/awt/Point.hpp>
      24             : #include <com/sun/star/awt/Rectangle.hpp>
      25             : #include <com/sun/star/awt/Size.hpp>
      26             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      27             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      28             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      29             : #include <cppuhelper/supportsservice.hxx>
      30             : #include <vcl/svapp.hxx>
      31             : #include <toolkit/awt/vclxwindow.hxx>
      32             : #include <toolkit/helper/convert.hxx>
      33             : #include <unotools/accessiblestatesethelper.hxx>
      34             : 
      35             : //........................................................................
      36             : namespace accessibility
      37             : {
      38             : //........................................................................
      39             : 
      40             :     // class AccessibleListBox -----------------------------------------------------
      41             : 
      42             :     using namespace ::com::sun::star::accessibility;
      43             :     using namespace ::com::sun::star::uno;
      44             :     using namespace ::com::sun::star::lang;
      45             :     using namespace ::com::sun::star;
      46             : 
      47             :     // -----------------------------------------------------------------------------
      48             :     // Ctor() and Dtor()
      49             :     // -----------------------------------------------------------------------------
      50           0 :     AccessibleListBox::AccessibleListBox( SvTreeListBox& _rListBox, const Reference< XAccessible >& _xParent ) :
      51             : 
      52             :         VCLXAccessibleComponent( _rListBox.GetWindowPeer() ),
      53           0 :         m_xParent( _xParent )
      54             :     {
      55           0 :     }
      56             :     // -----------------------------------------------------------------------------
      57           0 :     AccessibleListBox::~AccessibleListBox()
      58             :     {
      59           0 :         if ( isAlive() )
      60             :         {
      61             :             // increment ref count to prevent double call of Dtor
      62           0 :             osl_atomic_increment( &m_refCount );
      63           0 :             dispose();
      64             :         }
      65           0 :     }
      66           0 :     IMPLEMENT_FORWARD_XINTERFACE2(AccessibleListBox, VCLXAccessibleComponent, AccessibleListBox_BASE)
      67           0 :     IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleListBox, VCLXAccessibleComponent, AccessibleListBox_BASE)
      68             :     // -----------------------------------------------------------------------------
      69           0 :     SvTreeListBox* AccessibleListBox::getListBox() const
      70             :     {
      71           0 :         return  static_cast< SvTreeListBox* >( const_cast<AccessibleListBox*>(this)->GetWindow() );
      72             :     }
      73             :     // -----------------------------------------------------------------------------
      74           0 :     void AccessibleListBox::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
      75             :     {
      76           0 :         if ( isAlive() )
      77             :         {
      78           0 :             switch ( rVclWindowEvent.GetId() )
      79             :             {
      80             :                 case  VCLEVENT_CHECKBOX_TOGGLE :
      81             :                 {
      82           0 :                     if ( getListBox() && getListBox()->HasFocus() )
      83             :                     {
      84           0 :                         SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
      85           0 :                         if ( !pEntry )
      86           0 :                             pEntry = getListBox()->GetCurEntry();
      87             : 
      88           0 :                         if ( pEntry )
      89             :                         {
      90           0 :                             Reference< XAccessible > xChild = new AccessibleListBoxEntry( *getListBox(), pEntry, this );
      91           0 :                             uno::Any aOldValue, aNewValue;
      92           0 :                             aNewValue <<= xChild;
      93           0 :                             NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue );
      94             :                         }
      95             :                     }
      96           0 :                     break;
      97             :                 }
      98             : 
      99             :                 case VCLEVENT_LISTBOX_SELECT :
     100             :                 {
     101             :                     // First send an event that tells the listeners of a
     102             :                     // modified selection.  The active descendant event is
     103             :                     // send after that so that the receiving AT has time to
     104             :                     // read the text or name of the active child.
     105           0 :                     NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
     106           0 :                     if ( getListBox() && getListBox()->HasFocus() )
     107             :                     {
     108           0 :                         SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
     109           0 :                         if ( pEntry )
     110             :                         {
     111           0 :                             Reference< XAccessible > xChild = new AccessibleListBoxEntry( *getListBox(), pEntry, this );
     112           0 :                             uno::Any aOldValue, aNewValue;
     113           0 :                             aNewValue <<= xChild;
     114           0 :                             NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue );
     115             :                         }
     116             :                     }
     117           0 :                     break;
     118             : 
     119             :                 // #i92103#
     120             :                 case VCLEVENT_ITEM_EXPANDED :
     121             :                 case VCLEVENT_ITEM_COLLAPSED :
     122             :                 {
     123           0 :                     SvTreeListEntry* pEntry = static_cast< SvTreeListEntry* >( rVclWindowEvent.GetData() );
     124           0 :                     if ( pEntry )
     125             :                     {
     126             :                         AccessibleListBoxEntry* pAccListBoxEntry =
     127           0 :                             new AccessibleListBoxEntry( *getListBox(), pEntry, this );
     128           0 :                         Reference< XAccessible > xChild = pAccListBoxEntry;
     129             :                         const short nAccEvent =
     130           0 :                                 ( rVclWindowEvent.GetId() == VCLEVENT_ITEM_EXPANDED )
     131             :                                 ? AccessibleEventId::LISTBOX_ENTRY_EXPANDED
     132           0 :                                 : AccessibleEventId::LISTBOX_ENTRY_COLLAPSED;
     133           0 :                         uno::Any aListBoxEntry;
     134           0 :                         aListBoxEntry <<= xChild;
     135           0 :                         NotifyAccessibleEvent( nAccEvent, Any(), aListBoxEntry );
     136           0 :                         if ( getListBox() && getListBox()->HasFocus() )
     137             :                         {
     138           0 :                             NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, Any(), aListBoxEntry );
     139           0 :                         }
     140             :                     }
     141           0 :                     break;
     142             :                 }
     143             :                 }
     144             :                 default:
     145           0 :                     VCLXAccessibleComponent::ProcessWindowEvent (rVclWindowEvent);
     146             :             }
     147             :         }
     148           0 :     }
     149             :     // -----------------------------------------------------------------------------
     150           0 :     void AccessibleListBox::ProcessWindowChildEvent( const VclWindowEvent& rVclWindowEvent )
     151             :     {
     152           0 :         switch ( rVclWindowEvent.GetId() )
     153             :         {
     154             :             case VCLEVENT_WINDOW_SHOW:
     155             :             case VCLEVENT_WINDOW_HIDE:
     156             :             {
     157             :             }
     158           0 :             break;
     159             :             default:
     160             :             {
     161           0 :                 VCLXAccessibleComponent::ProcessWindowChildEvent( rVclWindowEvent );
     162             :             }
     163           0 :             break;
     164             :         }
     165           0 :     }
     166             : 
     167             :     // -----------------------------------------------------------------------------
     168             :     // XComponent
     169             :     // -----------------------------------------------------------------------------
     170           0 :     void SAL_CALL AccessibleListBox::disposing()
     171             :     {
     172           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     173             : 
     174           0 :         VCLXAccessibleComponent::disposing();
     175           0 :         m_xParent = NULL;
     176           0 :     }
     177             :     // -----------------------------------------------------------------------------
     178             :     // XServiceInfo
     179             :     // -----------------------------------------------------------------------------
     180           0 :     OUString SAL_CALL AccessibleListBox::getImplementationName() throw(RuntimeException)
     181             :     {
     182           0 :         return getImplementationName_Static();
     183             :     }
     184             :     // -----------------------------------------------------------------------------
     185           0 :     Sequence< OUString > SAL_CALL AccessibleListBox::getSupportedServiceNames() throw(RuntimeException)
     186             :     {
     187           0 :         return getSupportedServiceNames_Static();
     188             :     }
     189             :     // -----------------------------------------------------------------------------
     190           0 :     sal_Bool SAL_CALL AccessibleListBox::supportsService( const OUString& _rServiceName ) throw (RuntimeException)
     191             :     {
     192           0 :         return cppu::supportsService(this, _rServiceName);
     193             :     }
     194             :     // -----------------------------------------------------------------------------
     195             :     // XServiceInfo - static methods
     196             :     // -----------------------------------------------------------------------------
     197           0 :     Sequence< OUString > AccessibleListBox::getSupportedServiceNames_Static(void) throw( RuntimeException )
     198             :     {
     199           0 :         Sequence< OUString > aSupported(3);
     200           0 :         aSupported[0] = "com.sun.star.accessibility.AccessibleContext";
     201           0 :         aSupported[1] = "com.sun.star.accessibility.AccessibleComponent";
     202           0 :         aSupported[2] = "com.sun.star.awt.AccessibleTreeListBox";
     203           0 :         return aSupported;
     204             :     }
     205             :     // -----------------------------------------------------------------------------
     206           0 :     OUString AccessibleListBox::getImplementationName_Static(void) throw( RuntimeException )
     207             :     {
     208           0 :         return OUString( "com.sun.star.comp.svtools.AccessibleTreeListBox" );
     209             :     }
     210             :     // -----------------------------------------------------------------------------
     211             :     // XAccessible
     212             :     // -----------------------------------------------------------------------------
     213           0 :     Reference< XAccessibleContext > SAL_CALL AccessibleListBox::getAccessibleContext(  ) throw (RuntimeException)
     214             :     {
     215           0 :         ensureAlive();
     216           0 :         return this;
     217             :     }
     218             :     // -----------------------------------------------------------------------------
     219             :     // XAccessibleContext
     220             :     // -----------------------------------------------------------------------------
     221           0 :     sal_Int32 SAL_CALL AccessibleListBox::getAccessibleChildCount(  ) throw (RuntimeException)
     222             :     {
     223           0 :         ::comphelper::OExternalLockGuard aGuard( this );
     224             : 
     225           0 :         ensureAlive();
     226             : 
     227           0 :         sal_Int32 nCount = 0;
     228           0 :         SvTreeListBox* pSvTreeListBox = getListBox();
     229           0 :         if ( pSvTreeListBox )
     230           0 :             nCount = pSvTreeListBox->GetLevelChildCount( NULL );
     231             : 
     232           0 :         return nCount;
     233             :     }
     234             :     // -----------------------------------------------------------------------------
     235           0 :     Reference< XAccessible > SAL_CALL AccessibleListBox::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException,RuntimeException)
     236             :     {
     237           0 :         ::comphelper::OExternalLockGuard aGuard( this );
     238             : 
     239           0 :         ensureAlive();
     240           0 :         SvTreeListEntry* pEntry = getListBox()->GetEntry(i);
     241           0 :         if ( !pEntry )
     242           0 :             throw IndexOutOfBoundsException();
     243             : 
     244           0 :         return new AccessibleListBoxEntry( *getListBox(), pEntry, this );
     245             :     }
     246             :     // -----------------------------------------------------------------------------
     247           0 :     Reference< XAccessible > SAL_CALL AccessibleListBox::getAccessibleParent(  ) throw (RuntimeException)
     248             :     {
     249           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     250             : 
     251           0 :         ensureAlive();
     252           0 :         return m_xParent;
     253             :     }
     254             :     // -----------------------------------------------------------------------------
     255           0 :     sal_Int16 SAL_CALL AccessibleListBox::getAccessibleRole(  ) throw (RuntimeException)
     256             :     {
     257           0 :         return AccessibleRole::TREE;
     258             :     }
     259             :     // -----------------------------------------------------------------------------
     260           0 :     OUString SAL_CALL AccessibleListBox::getAccessibleDescription(  ) throw (RuntimeException)
     261             :     {
     262           0 :         ::comphelper::OExternalLockGuard aGuard( this );
     263             : 
     264           0 :         ensureAlive();
     265           0 :         return getListBox()->GetAccessibleDescription();
     266             :     }
     267             :     // -----------------------------------------------------------------------------
     268           0 :     OUString SAL_CALL AccessibleListBox::getAccessibleName(  ) throw (RuntimeException)
     269             :     {
     270           0 :         ::comphelper::OExternalLockGuard aGuard( this );
     271             : 
     272           0 :         ensureAlive();
     273           0 :         return getListBox()->GetAccessibleName();
     274             :     }
     275             :     // -----------------------------------------------------------------------------
     276             :     // XAccessibleSelection
     277             :     // -----------------------------------------------------------------------------
     278           0 :     void SAL_CALL AccessibleListBox::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     279             :     {
     280           0 :         ::comphelper::OExternalLockGuard aGuard( this );
     281             : 
     282           0 :         ensureAlive();
     283             : 
     284           0 :         SvTreeListEntry* pEntry = getListBox()->GetEntry( nChildIndex );
     285           0 :         if ( !pEntry )
     286           0 :             throw IndexOutOfBoundsException();
     287             : 
     288           0 :         getListBox()->Select( pEntry, sal_True );
     289           0 :     }
     290             :     // -----------------------------------------------------------------------------
     291           0 :     sal_Bool SAL_CALL AccessibleListBox::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     292             :     {
     293           0 :         ::comphelper::OExternalLockGuard aGuard( this );
     294             : 
     295           0 :         ensureAlive();
     296             : 
     297           0 :         SvTreeListEntry* pEntry = getListBox()->GetEntry( nChildIndex );
     298           0 :         if ( !pEntry )
     299           0 :             throw IndexOutOfBoundsException();
     300             : 
     301           0 :         return getListBox()->IsSelected( pEntry );
     302             :     }
     303             :     // -----------------------------------------------------------------------------
     304           0 :     void SAL_CALL AccessibleListBox::clearAccessibleSelection(  ) throw (RuntimeException)
     305             :     {
     306           0 :         ::comphelper::OExternalLockGuard aGuard( this );
     307             : 
     308           0 :         ensureAlive();
     309             : 
     310           0 :         sal_Int32 nCount = getListBox()->GetLevelChildCount( NULL );
     311           0 :         for ( sal_Int32 i = 0; i < nCount; ++i )
     312             :         {
     313           0 :             SvTreeListEntry* pEntry = getListBox()->GetEntry( i );
     314           0 :             if ( getListBox()->IsSelected( pEntry ) )
     315           0 :                 getListBox()->Select( pEntry, sal_False );
     316           0 :         }
     317           0 :     }
     318             :     // -----------------------------------------------------------------------------
     319           0 :     void SAL_CALL AccessibleListBox::selectAllAccessibleChildren(  ) throw (RuntimeException)
     320             :     {
     321           0 :         ::comphelper::OExternalLockGuard aGuard( this );
     322             : 
     323           0 :         ensureAlive();
     324             : 
     325           0 :         sal_Int32 nCount = getListBox()->GetLevelChildCount( NULL );
     326           0 :         for ( sal_Int32 i = 0; i < nCount; ++i )
     327             :         {
     328           0 :             SvTreeListEntry* pEntry = getListBox()->GetEntry( i );
     329           0 :             if ( !getListBox()->IsSelected( pEntry ) )
     330           0 :                 getListBox()->Select( pEntry, sal_True );
     331           0 :         }
     332           0 :     }
     333             :     // -----------------------------------------------------------------------------
     334           0 :     sal_Int32 SAL_CALL AccessibleListBox::getSelectedAccessibleChildCount(  ) throw (RuntimeException)
     335             :     {
     336           0 :         ::comphelper::OExternalLockGuard aGuard( this );
     337             : 
     338           0 :         ensureAlive();
     339             : 
     340           0 :         sal_Int32 nSelCount = 0;
     341           0 :         sal_Int32 nCount = getListBox()->GetLevelChildCount( NULL );
     342           0 :         for ( sal_Int32 i = 0; i < nCount; ++i )
     343             :         {
     344           0 :             SvTreeListEntry* pEntry = getListBox()->GetEntry( i );
     345           0 :             if ( getListBox()->IsSelected( pEntry ) )
     346           0 :                 ++nSelCount;
     347             :         }
     348             : 
     349           0 :         return nSelCount;
     350             :     }
     351             :     // -----------------------------------------------------------------------------
     352           0 :     Reference< XAccessible > SAL_CALL AccessibleListBox::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     353             :     {
     354           0 :         ::comphelper::OExternalLockGuard aGuard( this );
     355             : 
     356           0 :         ensureAlive();
     357             : 
     358           0 :         if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
     359           0 :             throw IndexOutOfBoundsException();
     360             : 
     361           0 :         Reference< XAccessible > xChild;
     362           0 :         sal_Int32 nSelCount= 0;
     363           0 :         sal_Int32 nCount = getListBox()->GetLevelChildCount( NULL );
     364           0 :         for ( sal_Int32 i = 0; i < nCount; ++i )
     365             :         {
     366           0 :             SvTreeListEntry* pEntry = getListBox()->GetEntry( i );
     367           0 :             if ( getListBox()->IsSelected( pEntry ) )
     368           0 :                 ++nSelCount;
     369             : 
     370           0 :             if ( nSelCount == ( nSelectedChildIndex + 1 ) )
     371             :             {
     372           0 :                 xChild = new AccessibleListBoxEntry( *getListBox(), pEntry, this );
     373           0 :                 break;
     374             :             }
     375             :         }
     376             : 
     377           0 :         return xChild;
     378             :     }
     379             :     // -----------------------------------------------------------------------------
     380           0 :     void SAL_CALL AccessibleListBox::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     381             :     {
     382           0 :         ::comphelper::OExternalLockGuard aGuard( this );
     383             : 
     384           0 :         ensureAlive();
     385             : 
     386           0 :         SvTreeListEntry* pEntry = getListBox()->GetEntry( nSelectedChildIndex );
     387           0 :         if ( !pEntry )
     388           0 :             throw IndexOutOfBoundsException();
     389             : 
     390           0 :         getListBox()->Select( pEntry, sal_False );
     391           0 :     }
     392             :     // -----------------------------------------------------------------------------
     393           0 :     void AccessibleListBox::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
     394             :     {
     395           0 :         VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
     396           0 :         if ( getListBox() && isAlive() )
     397             :         {
     398           0 :             rStateSet.AddState( AccessibleStateType::FOCUSABLE );
     399           0 :             rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
     400           0 :             if ( getListBox()->GetSelectionMode() == MULTIPLE_SELECTION )
     401           0 :                 rStateSet.AddState( AccessibleStateType::MULTI_SELECTABLE );
     402             :         }
     403           0 :     }
     404             : 
     405             : 
     406             : //........................................................................
     407             : }// namespace accessibility
     408             : //........................................................................
     409             : 
     410             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10