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

Generated by: LCOV version 1.10