LCOV - code coverage report
Current view: top level - libreoffice/accessibility/source/standard - vclxaccessibleradiobutton.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 120 0.0 %
Date: 2012-12-17 Functions: 0 21 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/standard/vclxaccessibleradiobutton.hxx>
      21             : 
      22             : #include <toolkit/awt/vclxwindows.hxx>
      23             : #include <accessibility/helper/accresmgr.hxx>
      24             : #include <accessibility/helper/accessiblestrings.hrc>
      25             : 
      26             : #include <unotools/accessiblerelationsethelper.hxx>
      27             : #include <unotools/accessiblestatesethelper.hxx>
      28             : #include <comphelper/accessiblekeybindinghelper.hxx>
      29             : #include <com/sun/star/awt/KeyModifier.hpp>
      30             : #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
      31             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      32             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      33             : #include <cppuhelper/typeprovider.hxx>
      34             : #include <comphelper/sequence.hxx>
      35             : #include <vcl/window.hxx>
      36             : #include <vcl/button.hxx>
      37             : 
      38             : 
      39             : using namespace ::com::sun::star;
      40             : using namespace ::com::sun::star::uno;
      41             : using namespace ::com::sun::star::lang;
      42             : using namespace ::com::sun::star::beans;
      43             : using namespace ::com::sun::star::accessibility;
      44             : using namespace ::comphelper;
      45             : 
      46             : 
      47             : // -----------------------------------------------------------------------------
      48             : // VCLXAccessibleRadioButton
      49             : // -----------------------------------------------------------------------------
      50             : 
      51           0 : VCLXAccessibleRadioButton::VCLXAccessibleRadioButton( VCLXWindow* pVCLWindow )
      52           0 :     :VCLXAccessibleTextComponent( pVCLWindow )
      53             : {
      54           0 : }
      55             : 
      56             : // -----------------------------------------------------------------------------
      57             : 
      58           0 : VCLXAccessibleRadioButton::~VCLXAccessibleRadioButton()
      59             : {
      60           0 : }
      61             : 
      62             : // -----------------------------------------------------------------------------
      63             : 
      64           0 : void VCLXAccessibleRadioButton::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
      65             : {
      66           0 :     switch ( rVclWindowEvent.GetId() )
      67             :     {
      68             :         case VCLEVENT_RADIOBUTTON_TOGGLE:
      69             :         {
      70           0 :             Any aOldValue;
      71           0 :             Any aNewValue;
      72             : 
      73           0 :             VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
      74           0 :             if ( pVCLXRadioButton && pVCLXRadioButton->getState() )
      75           0 :                 aNewValue <<= AccessibleStateType::CHECKED;
      76             :             else
      77           0 :                 aOldValue <<= AccessibleStateType::CHECKED;
      78             : 
      79           0 :             NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
      80             :         }
      81           0 :         break;
      82             :         default:
      83           0 :             VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent );
      84             :    }
      85           0 : }
      86             : 
      87             : // -----------------------------------------------------------------------------
      88             : 
      89           0 : void VCLXAccessibleRadioButton::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet )
      90             : {
      91           0 :     VCLXAccessibleTextComponent::FillAccessibleRelationSet( rRelationSet );
      92             : 
      93           0 :     RadioButton* pRadioButton = dynamic_cast< RadioButton* >( GetWindow() );
      94           0 :     if ( pRadioButton )
      95             :     {
      96           0 :         ::std::vector< RadioButton* > aGroup(pRadioButton->GetRadioButtonGroup(true));
      97           0 :         if (!aGroup.empty())
      98             :         {
      99           0 :             sal_Int32 i = 0;
     100           0 :             Sequence< Reference< XInterface > > aSequence( static_cast< sal_Int32 >( aGroup.size() ) );
     101           0 :             ::std::vector< RadioButton* >::const_iterator aEndItr = aGroup.end();
     102           0 :             for ( ::std::vector< RadioButton* >::const_iterator aItr = aGroup.begin(); aItr < aEndItr; ++aItr )
     103             :             {
     104           0 :                 aSequence[i++] = (*aItr)->GetAccessible();
     105             :             }
     106           0 :             rRelationSet.AddRelation( AccessibleRelation( AccessibleRelationType::MEMBER_OF, aSequence ) );
     107           0 :         }
     108             :     }
     109           0 : }
     110             : 
     111             : // -----------------------------------------------------------------------------
     112             : 
     113           0 : void VCLXAccessibleRadioButton::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
     114             : {
     115           0 :     VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet );
     116             : 
     117           0 :     VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
     118           0 :     if ( pVCLXRadioButton )
     119             :     {
     120           0 :         rStateSet.AddState( AccessibleStateType::FOCUSABLE );
     121           0 :         if ( pVCLXRadioButton->getState() )
     122           0 :             rStateSet.AddState( AccessibleStateType::CHECKED );
     123             :     }
     124           0 : }
     125             : 
     126             : // -----------------------------------------------------------------------------
     127             : // XInterface
     128             : // -----------------------------------------------------------------------------
     129             : 
     130           0 : IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleRadioButton, VCLXAccessibleTextComponent, VCLXAccessibleRadioButton_BASE )
     131             : 
     132             : // -----------------------------------------------------------------------------
     133             : // XTypeProvider
     134             : // -----------------------------------------------------------------------------
     135             : 
     136           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleRadioButton, VCLXAccessibleTextComponent, VCLXAccessibleRadioButton_BASE )
     137             : 
     138             : // -----------------------------------------------------------------------------
     139             : // XServiceInfo
     140             : // -----------------------------------------------------------------------------
     141             : 
     142           0 : OUString VCLXAccessibleRadioButton::getImplementationName() throw (RuntimeException)
     143             : {
     144           0 :     return OUString( "com.sun.star.comp.toolkit.AccessibleRadioButton" );
     145             : }
     146             : 
     147             : // -----------------------------------------------------------------------------
     148             : 
     149           0 : Sequence< OUString > VCLXAccessibleRadioButton::getSupportedServiceNames() throw (RuntimeException)
     150             : {
     151           0 :     Sequence< OUString > aNames(1);
     152           0 :     aNames[0] = "com.sun.star.awt.AccessibleRadioButton";
     153           0 :     return aNames;
     154             : }
     155             : 
     156             : // -----------------------------------------------------------------------------
     157             : // XAccessibleAction
     158             : // -----------------------------------------------------------------------------
     159             : 
     160           0 : sal_Int32 VCLXAccessibleRadioButton::getAccessibleActionCount( ) throw (RuntimeException)
     161             : {
     162           0 :     OExternalLockGuard aGuard( this );
     163             : 
     164           0 :     return 1;
     165             : }
     166             : 
     167             : // -----------------------------------------------------------------------------
     168             : 
     169           0 : sal_Bool VCLXAccessibleRadioButton::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     170             : {
     171           0 :     OExternalLockGuard aGuard( this );
     172             : 
     173           0 :     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
     174           0 :         throw IndexOutOfBoundsException();
     175             : 
     176           0 :     VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
     177           0 :     if ( pVCLXRadioButton && !pVCLXRadioButton->getState() )
     178           0 :         pVCLXRadioButton->setState( sal_True );
     179             : 
     180           0 :     return sal_True;
     181             : }
     182             : 
     183             : // -----------------------------------------------------------------------------
     184             : 
     185           0 : OUString VCLXAccessibleRadioButton::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     186             : {
     187           0 :     OExternalLockGuard aGuard( this );
     188             : 
     189           0 :     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
     190           0 :         throw IndexOutOfBoundsException();
     191             : 
     192           0 :     return OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK ) );
     193             : }
     194             : 
     195             : // -----------------------------------------------------------------------------
     196             : 
     197           0 : Reference< XAccessibleKeyBinding > VCLXAccessibleRadioButton::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     198             : {
     199           0 :     OExternalLockGuard aGuard( this );
     200             : 
     201           0 :     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
     202           0 :         throw IndexOutOfBoundsException();
     203             : 
     204           0 :     OAccessibleKeyBindingHelper* pKeyBindingHelper = new OAccessibleKeyBindingHelper();
     205           0 :     Reference< XAccessibleKeyBinding > xKeyBinding = pKeyBindingHelper;
     206             : 
     207           0 :     Window* pWindow = GetWindow();
     208           0 :     if ( pWindow )
     209             :     {
     210           0 :         KeyEvent aKeyEvent = pWindow->GetActivationKey();
     211           0 :         KeyCode aKeyCode = aKeyEvent.GetKeyCode();
     212           0 :         if ( aKeyCode.GetCode() != 0 )
     213             :         {
     214           0 :             awt::KeyStroke aKeyStroke;
     215           0 :             aKeyStroke.Modifiers = 0;
     216           0 :             if ( aKeyCode.IsShift() )
     217           0 :                 aKeyStroke.Modifiers |= awt::KeyModifier::SHIFT;
     218           0 :             if ( aKeyCode.IsMod1() )
     219           0 :                 aKeyStroke.Modifiers |= awt::KeyModifier::MOD1;
     220           0 :             if ( aKeyCode.IsMod2() )
     221           0 :                 aKeyStroke.Modifiers |= awt::KeyModifier::MOD2;
     222           0 :             if ( aKeyCode.IsMod3() )
     223           0 :                 aKeyStroke.Modifiers |= awt::KeyModifier::MOD3;
     224           0 :             aKeyStroke.KeyCode = aKeyCode.GetCode();
     225           0 :             aKeyStroke.KeyChar = aKeyEvent.GetCharCode();
     226           0 :             aKeyStroke.KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() );
     227           0 :             pKeyBindingHelper->AddKeyBinding( aKeyStroke );
     228             :         }
     229             :     }
     230             : 
     231           0 :     return xKeyBinding;
     232             : }
     233             : 
     234             : // -----------------------------------------------------------------------------
     235             : // XAccessibleValue
     236             : // -----------------------------------------------------------------------------
     237             : 
     238           0 : Any VCLXAccessibleRadioButton::getCurrentValue(  ) throw (RuntimeException)
     239             : {
     240           0 :     OExternalLockGuard aGuard( this );
     241             : 
     242           0 :     Any aValue;
     243             : 
     244           0 :     VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
     245           0 :     if ( pVCLXRadioButton )
     246           0 :         aValue <<= (sal_Int32) pVCLXRadioButton->getState();
     247             : 
     248           0 :     return aValue;
     249             : }
     250             : 
     251             : // -----------------------------------------------------------------------------
     252             : 
     253           0 : sal_Bool VCLXAccessibleRadioButton::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
     254             : {
     255           0 :     OExternalLockGuard aGuard( this );
     256             : 
     257           0 :     sal_Bool bReturn = sal_False;
     258             : 
     259           0 :     VCLXRadioButton* pVCLXRadioButton = static_cast< VCLXRadioButton* >( GetVCLXWindow() );
     260           0 :     if ( pVCLXRadioButton )
     261             :     {
     262           0 :         sal_Int32 nValue = 0;
     263           0 :         OSL_VERIFY( aNumber >>= nValue );
     264             : 
     265           0 :         if ( nValue < 0 )
     266           0 :             nValue = 0;
     267           0 :         else if ( nValue > 1 )
     268           0 :             nValue = 1;
     269             : 
     270           0 :         pVCLXRadioButton->setState( (sal_Bool) nValue );
     271           0 :         bReturn = sal_True;
     272             :     }
     273             : 
     274           0 :     return bReturn;
     275             : }
     276             : 
     277             : // -----------------------------------------------------------------------------
     278             : 
     279           0 : Any VCLXAccessibleRadioButton::getMaximumValue(  ) throw (RuntimeException)
     280             : {
     281           0 :     OExternalLockGuard aGuard( this );
     282             : 
     283           0 :     Any aValue;
     284           0 :     aValue <<= (sal_Int32) 1;
     285             : 
     286           0 :     return aValue;
     287             : }
     288             : 
     289             : // -----------------------------------------------------------------------------
     290             : 
     291           0 : Any VCLXAccessibleRadioButton::getMinimumValue(  ) throw (RuntimeException)
     292             : {
     293           0 :     OExternalLockGuard aGuard( this );
     294             : 
     295           0 :     Any aValue;
     296           0 :     aValue <<= (sal_Int32) 0;
     297             : 
     298           0 :     return aValue;
     299             : }
     300             : 
     301             : // -----------------------------------------------------------------------------
     302             : 
     303             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10