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

Generated by: LCOV version 1.11