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

Generated by: LCOV version 1.10