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

Generated by: LCOV version 1.10