LCOV - code coverage report
Current view: top level - accessibility/source/standard - vclxaccessiblecheckbox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 147 0.0 %
Date: 2012-08-25 Functions: 0 24 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 204 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <accessibility/standard/vclxaccessiblecheckbox.hxx>
      30                 :            : 
      31                 :            : #include <toolkit/awt/vclxwindows.hxx>
      32                 :            : #include <accessibility/helper/accresmgr.hxx>
      33                 :            : #include <accessibility/helper/accessiblestrings.hrc>
      34                 :            : 
      35                 :            : #include <unotools/accessiblestatesethelper.hxx>
      36                 :            : #include <comphelper/accessiblekeybindinghelper.hxx>
      37                 :            : #include <com/sun/star/awt/KeyModifier.hpp>
      38                 :            : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      39                 :            : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      40                 :            : #include <cppuhelper/typeprovider.hxx>
      41                 :            : #include <comphelper/sequence.hxx>
      42                 :            : 
      43                 :            : #include <vcl/button.hxx>
      44                 :            : 
      45                 :            : using namespace ::com::sun::star;
      46                 :            : using namespace ::com::sun::star::uno;
      47                 :            : using namespace ::com::sun::star::lang;
      48                 :            : using namespace ::com::sun::star::beans;
      49                 :            : using namespace ::com::sun::star::accessibility;
      50                 :            : using namespace ::comphelper;
      51                 :            : 
      52                 :            : 
      53                 :            : // -----------------------------------------------------------------------------
      54                 :            : // VCLXAccessibleCheckBox
      55                 :            : // -----------------------------------------------------------------------------
      56                 :            : 
      57                 :          0 : VCLXAccessibleCheckBox::VCLXAccessibleCheckBox( VCLXWindow* pVCLWindow )
      58                 :          0 :     :VCLXAccessibleTextComponent( pVCLWindow )
      59                 :            : {
      60         [ #  # ]:          0 :     m_bChecked = IsChecked();
      61         [ #  # ]:          0 :     m_bIndeterminate = IsIndeterminate();
      62                 :          0 : }
      63                 :            : 
      64                 :            : // -----------------------------------------------------------------------------
      65                 :            : 
      66                 :          0 : VCLXAccessibleCheckBox::~VCLXAccessibleCheckBox()
      67                 :            : {
      68         [ #  # ]:          0 : }
      69                 :            : 
      70                 :            : // -----------------------------------------------------------------------------
      71                 :            : 
      72                 :          0 : bool VCLXAccessibleCheckBox::IsChecked()
      73                 :            : {
      74                 :          0 :     bool bChecked = false;
      75                 :            : 
      76         [ #  # ]:          0 :     VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() );
      77 [ #  # ][ #  # ]:          0 :     if ( pVCLXCheckBox && pVCLXCheckBox->getState() == (sal_Int16) 1 )
                 [ #  # ]
      78                 :          0 :         bChecked = true;
      79                 :            : 
      80                 :          0 :     return bChecked;
      81                 :            : }
      82                 :            : 
      83                 :            : // -----------------------------------------------------------------------------
      84                 :            : 
      85                 :          0 : bool VCLXAccessibleCheckBox::IsIndeterminate()
      86                 :            : {
      87                 :          0 :     bool bIndeterminate = false;
      88                 :            : 
      89         [ #  # ]:          0 :     VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() );
      90 [ #  # ][ #  # ]:          0 :     if ( pVCLXCheckBox && pVCLXCheckBox->getState() == (sal_Int16) 2 )
                 [ #  # ]
      91                 :          0 :         bIndeterminate = true;
      92                 :            : 
      93                 :          0 :     return bIndeterminate;
      94                 :            : }
      95                 :            : 
      96                 :            : // -----------------------------------------------------------------------------
      97                 :            : 
      98                 :          0 : void VCLXAccessibleCheckBox::SetChecked( bool bChecked )
      99                 :            : {
     100         [ #  # ]:          0 :     if ( m_bChecked != bChecked )
     101                 :            :     {
     102                 :          0 :         Any aOldValue, aNewValue;
     103         [ #  # ]:          0 :         if ( m_bChecked )
     104         [ #  # ]:          0 :             aOldValue <<= AccessibleStateType::CHECKED;
     105                 :            :         else
     106         [ #  # ]:          0 :             aNewValue <<= AccessibleStateType::CHECKED;
     107                 :          0 :         m_bChecked = bChecked;
     108         [ #  # ]:          0 :         NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
     109                 :            :     }
     110                 :          0 : }
     111                 :            : 
     112                 :            : // -----------------------------------------------------------------------------
     113                 :            : 
     114                 :          0 : void VCLXAccessibleCheckBox::SetIndeterminate( bool bIndeterminate )
     115                 :            : {
     116         [ #  # ]:          0 :     if ( m_bIndeterminate != bIndeterminate )
     117                 :            :     {
     118                 :          0 :         Any aOldValue, aNewValue;
     119         [ #  # ]:          0 :         if ( m_bIndeterminate )
     120         [ #  # ]:          0 :             aOldValue <<= AccessibleStateType::INDETERMINATE;
     121                 :            :         else
     122         [ #  # ]:          0 :             aNewValue <<= AccessibleStateType::INDETERMINATE;
     123                 :          0 :         m_bIndeterminate = bIndeterminate;
     124         [ #  # ]:          0 :         NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
     125                 :            :     }
     126                 :          0 : }
     127                 :            : 
     128                 :            : // -----------------------------------------------------------------------------
     129                 :            : 
     130                 :          0 : void VCLXAccessibleCheckBox::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
     131                 :            : {
     132         [ #  # ]:          0 :     switch ( rVclWindowEvent.GetId() )
     133                 :            :     {
     134                 :            :         case VCLEVENT_CHECKBOX_TOGGLE:
     135                 :            :         {
     136                 :          0 :             SetChecked( IsChecked() );
     137                 :          0 :             SetIndeterminate( IsIndeterminate() );
     138                 :            :         }
     139                 :          0 :         break;
     140                 :            :         default:
     141                 :          0 :             VCLXAccessibleTextComponent::ProcessWindowEvent( rVclWindowEvent );
     142                 :            :    }
     143                 :          0 : }
     144                 :            : 
     145                 :            : // -----------------------------------------------------------------------------
     146                 :            : 
     147                 :          0 : void VCLXAccessibleCheckBox::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
     148                 :            : {
     149                 :          0 :     VCLXAccessibleTextComponent::FillAccessibleStateSet( rStateSet );
     150                 :            : 
     151                 :          0 :     rStateSet.AddState( AccessibleStateType::FOCUSABLE );
     152                 :            : 
     153         [ #  # ]:          0 :     if ( IsChecked() )
     154                 :          0 :         rStateSet.AddState( AccessibleStateType::CHECKED );
     155                 :            : 
     156         [ #  # ]:          0 :     if ( IsIndeterminate() )
     157                 :          0 :         rStateSet.AddState( AccessibleStateType::INDETERMINATE );
     158                 :          0 : }
     159                 :            : 
     160                 :            : // -----------------------------------------------------------------------------
     161                 :            : // XInterface
     162                 :            : // -----------------------------------------------------------------------------
     163                 :            : 
     164 [ #  # ][ #  # ]:          0 : IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleCheckBox, VCLXAccessibleTextComponent, VCLXAccessibleCheckBox_BASE )
     165                 :            : 
     166                 :            : // -----------------------------------------------------------------------------
     167                 :            : // XTypeProvider
     168                 :            : // -----------------------------------------------------------------------------
     169                 :            : 
     170 [ #  # ][ #  # ]:          0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleCheckBox, VCLXAccessibleTextComponent, VCLXAccessibleCheckBox_BASE )
                 [ #  # ]
     171                 :            : 
     172                 :            : // -----------------------------------------------------------------------------
     173                 :            : // XServiceInfo
     174                 :            : // -----------------------------------------------------------------------------
     175                 :            : 
     176                 :          0 : ::rtl::OUString VCLXAccessibleCheckBox::getImplementationName() throw (RuntimeException)
     177                 :            : {
     178                 :          0 :     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.toolkit.AccessibleCheckBox") );
     179                 :            : }
     180                 :            : 
     181                 :            : // -----------------------------------------------------------------------------
     182                 :            : 
     183                 :          0 : Sequence< ::rtl::OUString > VCLXAccessibleCheckBox::getSupportedServiceNames() throw (RuntimeException)
     184                 :            : {
     185                 :          0 :     Sequence< ::rtl::OUString > aNames(1);
     186 [ #  # ][ #  # ]:          0 :     aNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.AccessibleCheckBox") );
     187                 :          0 :     return aNames;
     188                 :            : }
     189                 :            : 
     190                 :            : // -----------------------------------------------------------------------------
     191                 :            : // XAccessibleAction
     192                 :            : // -----------------------------------------------------------------------------
     193                 :            : 
     194                 :          0 : sal_Int32 VCLXAccessibleCheckBox::getAccessibleActionCount( ) throw (RuntimeException)
     195                 :            : {
     196         [ #  # ]:          0 :     OExternalLockGuard aGuard( this );
     197                 :            : 
     198         [ #  # ]:          0 :     return 1;
     199                 :            : }
     200                 :            : 
     201                 :            : // -----------------------------------------------------------------------------
     202                 :            : 
     203                 :          0 : sal_Bool VCLXAccessibleCheckBox::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     204                 :            : {
     205         [ #  # ]:          0 :     OExternalLockGuard aGuard( this );
     206                 :            : 
     207 [ #  # ][ #  # ]:          0 :     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
         [ #  # ][ #  # ]
     208         [ #  # ]:          0 :         throw IndexOutOfBoundsException();
     209                 :            : 
     210         [ #  # ]:          0 :     CheckBox* pCheckBox = (CheckBox*) GetWindow();
     211         [ #  # ]:          0 :     VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() );
     212 [ #  # ][ #  # ]:          0 :     if ( pCheckBox && pVCLXCheckBox )
     213                 :            :     {
     214                 :          0 :         sal_Int32 nValueMin = (sal_Int32) 0;
     215                 :          0 :         sal_Int32 nValueMax = (sal_Int32) 1;
     216                 :            : 
     217         [ #  # ]:          0 :         if ( pCheckBox->IsTriStateEnabled() )
     218                 :          0 :             nValueMax = (sal_Int32) 2;
     219                 :            : 
     220         [ #  # ]:          0 :         sal_Int32 nValue = (sal_Int32) pVCLXCheckBox->getState();
     221                 :            : 
     222                 :          0 :         ++nValue;
     223                 :            : 
     224         [ #  # ]:          0 :         if ( nValue > nValueMax )
     225                 :          0 :             nValue = nValueMin;
     226                 :            : 
     227         [ #  # ]:          0 :         pVCLXCheckBox->setState( (sal_Int16) nValue );
     228                 :            :     }
     229                 :            : 
     230         [ #  # ]:          0 :     return sal_True;
     231                 :            : }
     232                 :            : 
     233                 :            : // -----------------------------------------------------------------------------
     234                 :            : 
     235                 :          0 : ::rtl::OUString VCLXAccessibleCheckBox::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     236                 :            : {
     237         [ #  # ]:          0 :     OExternalLockGuard aGuard( this );
     238                 :            : 
     239 [ #  # ][ #  # ]:          0 :     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
         [ #  # ][ #  # ]
     240         [ #  # ]:          0 :         throw IndexOutOfBoundsException();
     241                 :            : 
     242 [ #  # ][ #  # ]:          0 :     return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK ) );
     243                 :            : }
     244                 :            : 
     245                 :            : // -----------------------------------------------------------------------------
     246                 :            : 
     247                 :          0 : Reference< XAccessibleKeyBinding > VCLXAccessibleCheckBox::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     248                 :            : {
     249         [ #  # ]:          0 :     OExternalLockGuard aGuard( this );
     250                 :            : 
     251 [ #  # ][ #  # ]:          0 :     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
         [ #  # ][ #  # ]
     252         [ #  # ]:          0 :         throw IndexOutOfBoundsException();
     253                 :            : 
     254         [ #  # ]:          0 :     OAccessibleKeyBindingHelper* pKeyBindingHelper = new OAccessibleKeyBindingHelper();
     255 [ #  # ][ #  # ]:          0 :     Reference< XAccessibleKeyBinding > xKeyBinding = pKeyBindingHelper;
     256                 :            : 
     257         [ #  # ]:          0 :     Window* pWindow = GetWindow();
     258         [ #  # ]:          0 :     if ( pWindow )
     259                 :            :     {
     260         [ #  # ]:          0 :         KeyEvent aKeyEvent = pWindow->GetActivationKey();
     261                 :          0 :         KeyCode aKeyCode = aKeyEvent.GetKeyCode();
     262         [ #  # ]:          0 :         if ( aKeyCode.GetCode() != 0 )
     263                 :            :         {
     264                 :          0 :             awt::KeyStroke aKeyStroke;
     265                 :          0 :             aKeyStroke.Modifiers = 0;
     266         [ #  # ]:          0 :             if ( aKeyCode.IsShift() )
     267                 :          0 :                 aKeyStroke.Modifiers |= awt::KeyModifier::SHIFT;
     268         [ #  # ]:          0 :             if ( aKeyCode.IsMod1() )
     269                 :          0 :                 aKeyStroke.Modifiers |= awt::KeyModifier::MOD1;
     270         [ #  # ]:          0 :             if ( aKeyCode.IsMod2() )
     271                 :          0 :                 aKeyStroke.Modifiers |= awt::KeyModifier::MOD2;
     272         [ #  # ]:          0 :             if ( aKeyCode.IsMod3() )
     273                 :          0 :                 aKeyStroke.Modifiers |= awt::KeyModifier::MOD3;
     274                 :          0 :             aKeyStroke.KeyCode = aKeyCode.GetCode();
     275                 :          0 :             aKeyStroke.KeyChar = aKeyEvent.GetCharCode();
     276         [ #  # ]:          0 :             aKeyStroke.KeyFunc = static_cast< sal_Int16 >( aKeyCode.GetFunction() );
     277         [ #  # ]:          0 :             pKeyBindingHelper->AddKeyBinding( aKeyStroke );
     278                 :            :         }
     279                 :            :     }
     280                 :            : 
     281         [ #  # ]:          0 :     return xKeyBinding;
     282                 :            : }
     283                 :            : 
     284                 :            : // -----------------------------------------------------------------------------
     285                 :            : // XAccessibleValue
     286                 :            : // -----------------------------------------------------------------------------
     287                 :            : 
     288                 :          0 : Any VCLXAccessibleCheckBox::getCurrentValue(  ) throw (RuntimeException)
     289                 :            : {
     290         [ #  # ]:          0 :     OExternalLockGuard aGuard( this );
     291                 :            : 
     292                 :          0 :     Any aValue;
     293                 :            : 
     294         [ #  # ]:          0 :     VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() );
     295         [ #  # ]:          0 :     if ( pVCLXCheckBox )
     296 [ #  # ][ #  # ]:          0 :         aValue <<= (sal_Int32) pVCLXCheckBox->getState();
     297                 :            : 
     298         [ #  # ]:          0 :     return aValue;
     299                 :            : }
     300                 :            : 
     301                 :            : // -----------------------------------------------------------------------------
     302                 :            : 
     303                 :          0 : sal_Bool VCLXAccessibleCheckBox::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
     304                 :            : {
     305         [ #  # ]:          0 :     OExternalLockGuard aGuard( this );
     306                 :            : 
     307                 :          0 :     sal_Bool bReturn = sal_False;
     308                 :            : 
     309         [ #  # ]:          0 :     VCLXCheckBox* pVCLXCheckBox = static_cast< VCLXCheckBox* >( GetVCLXWindow() );
     310         [ #  # ]:          0 :     if ( pVCLXCheckBox )
     311                 :            :     {
     312                 :          0 :         sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0;
     313                 :          0 :         OSL_VERIFY( aNumber >>= nValue );
     314         [ #  # ]:          0 :         OSL_VERIFY( getMinimumValue() >>= nValueMin );
     315         [ #  # ]:          0 :         OSL_VERIFY( getMaximumValue() >>= nValueMax );
     316                 :            : 
     317         [ #  # ]:          0 :         if ( nValue < nValueMin )
     318                 :          0 :             nValue = nValueMin;
     319         [ #  # ]:          0 :         else if ( nValue > nValueMax )
     320                 :          0 :             nValue = nValueMax;
     321                 :            : 
     322         [ #  # ]:          0 :         pVCLXCheckBox->setState( (sal_Int16) nValue );
     323                 :          0 :         bReturn = sal_True;
     324                 :            :     }
     325                 :            : 
     326         [ #  # ]:          0 :     return bReturn;
     327                 :            : }
     328                 :            : 
     329                 :            : // -----------------------------------------------------------------------------
     330                 :            : 
     331                 :          0 : Any VCLXAccessibleCheckBox::getMaximumValue(  ) throw (RuntimeException)
     332                 :            : {
     333         [ #  # ]:          0 :     OExternalLockGuard aGuard( this );
     334                 :            : 
     335                 :          0 :     Any aValue;
     336                 :            : 
     337         [ #  # ]:          0 :     CheckBox* pCheckBox = (CheckBox*) GetWindow();
     338 [ #  # ][ #  # ]:          0 :     if ( pCheckBox && pCheckBox->IsTriStateEnabled() )
                 [ #  # ]
     339         [ #  # ]:          0 :         aValue <<= (sal_Int32) 2;
     340                 :            :     else
     341         [ #  # ]:          0 :         aValue <<= (sal_Int32) 1;
     342                 :            : 
     343         [ #  # ]:          0 :     return aValue;
     344                 :            : }
     345                 :            : 
     346                 :            : // -----------------------------------------------------------------------------
     347                 :            : 
     348                 :          0 : Any VCLXAccessibleCheckBox::getMinimumValue(  ) throw (RuntimeException)
     349                 :            : {
     350         [ #  # ]:          0 :     OExternalLockGuard aGuard( this );
     351                 :            : 
     352                 :          0 :     Any aValue;
     353         [ #  # ]:          0 :     aValue <<= (sal_Int32) 0;
     354                 :            : 
     355         [ #  # ]:          0 :     return aValue;
     356                 :            : }
     357                 :            : 
     358                 :            : // -----------------------------------------------------------------------------
     359                 :            : 
     360                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10