LCOV - code coverage report
Current view: top level - vcl/unx/gtk/a11y - atkaction.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 109 0.0 %
Date: 2012-08-25 Functions: 0 12 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 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                 :            : 
      30                 :            : #include "atkwrapper.hxx"
      31                 :            : 
      32                 :            : #include <com/sun/star/accessibility/XAccessibleAction.hpp>
      33                 :            : #include <com/sun/star/accessibility/XAccessibleKeyBinding.hpp>
      34                 :            : 
      35                 :            : #include <com/sun/star/awt/Key.hpp>
      36                 :            : #include <com/sun/star/awt/KeyModifier.hpp>
      37                 :            : 
      38                 :            : #include <rtl/strbuf.hxx>
      39                 :            : #include <algorithm>
      40                 :            : #include <map>
      41                 :            : 
      42                 :            : #include <stdio.h>
      43                 :            : 
      44                 :            : using namespace ::com::sun::star;
      45                 :            : 
      46                 :            : // FIXME
      47                 :            : static G_CONST_RETURN gchar *
      48                 :          0 : getAsConst( const rtl::OString& rString )
      49                 :            : {
      50                 :            :     static const int nMax = 10;
      51                 :          0 :     static rtl::OString aUgly[nMax];
      52                 :            :     static int nIdx = 0;
      53                 :          0 :     nIdx = (nIdx + 1) % nMax;
      54                 :          0 :     aUgly[nIdx] = rString;
      55                 :          0 :     return aUgly[ nIdx ].getStr();
      56                 :            : }
      57                 :            : 
      58                 :            : static accessibility::XAccessibleAction*
      59                 :          0 :         getAction( AtkAction *action ) throw (uno::RuntimeException)
      60                 :            : {
      61                 :          0 :     AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( action );
      62                 :            : 
      63                 :          0 :     if( pWrap )
      64                 :            :     {
      65                 :          0 :         if( !pWrap->mpAction && pWrap->mpContext )
      66                 :            :         {
      67                 :          0 :             uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleAction::static_type(NULL) );
      68                 :          0 :             pWrap->mpAction = reinterpret_cast< accessibility::XAccessibleAction * > (any.pReserved);
      69                 :          0 :             pWrap->mpAction->acquire();
      70                 :            :         }
      71                 :            : 
      72                 :          0 :         return pWrap->mpAction;
      73                 :            :     }
      74                 :            : 
      75                 :          0 :     return NULL;
      76                 :            : }
      77                 :            : 
      78                 :            : extern "C" {
      79                 :            : 
      80                 :            : static gboolean
      81                 :          0 : action_wrapper_do_action (AtkAction *action,
      82                 :            :                           gint       i)
      83                 :            : {
      84                 :            :     try {
      85                 :          0 :         accessibility::XAccessibleAction* pAction = getAction( action );
      86                 :          0 :         if( pAction )
      87                 :          0 :             return pAction->doAccessibleAction( i );
      88                 :            :     }
      89                 :          0 :     catch(const uno::Exception& e) {
      90                 :          0 :         g_warning( "Exception in doAccessibleAction()" );
      91                 :            :     }
      92                 :            : 
      93                 :          0 :     return FALSE;
      94                 :            : }
      95                 :            : 
      96                 :            : static gint
      97                 :          0 : action_wrapper_get_n_actions (AtkAction *action)
      98                 :            : {
      99                 :            :     try {
     100                 :          0 :         accessibility::XAccessibleAction* pAction = getAction( action );
     101                 :          0 :         if( pAction )
     102                 :          0 :             return pAction->getAccessibleActionCount();
     103                 :            :     }
     104                 :          0 :     catch(const uno::Exception& e) {
     105                 :          0 :         g_warning( "Exception in getAccessibleActionCount()" );
     106                 :            :     }
     107                 :            : 
     108                 :          0 :     return 0;
     109                 :            : }
     110                 :            : 
     111                 :            : static G_CONST_RETURN gchar *
     112                 :          0 : action_wrapper_get_description (AtkAction *, gint)
     113                 :            : {
     114                 :            :     // GAIL implement this only for cells
     115                 :          0 :     g_warning( "Not implemented: get_description()" );
     116                 :          0 :     return "";
     117                 :            : }
     118                 :            : 
     119                 :            : static G_CONST_RETURN gchar *
     120                 :          0 : action_wrapper_get_localized_name (AtkAction *, gint)
     121                 :            : {
     122                 :            :     // GAIL doesn't implement this as well
     123                 :          0 :     g_warning( "Not implemented: get_localized_name()" );
     124                 :          0 :     return "";
     125                 :            : }
     126                 :            : 
     127                 :            : #define ACTION_NAME_PAIR( OOoName, AtkName ) \
     128                 :            :     std::pair< const rtl::OUString, const gchar * > ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OOoName ) ), AtkName )
     129                 :            : 
     130                 :            : static G_CONST_RETURN gchar *
     131                 :          0 : action_wrapper_get_name (AtkAction *action,
     132                 :            :                          gint       i)
     133                 :            : {
     134                 :          0 :     static std::map< rtl::OUString, const gchar * > aNameMap;
     135                 :            : 
     136                 :          0 :     if( aNameMap.empty() )
     137                 :            :     {
     138                 :          0 :         aNameMap.insert( ACTION_NAME_PAIR( "click", "click" ) );
     139                 :          0 :         aNameMap.insert( ACTION_NAME_PAIR( "select", "click" ) );
     140                 :          0 :         aNameMap.insert( ACTION_NAME_PAIR( "togglePopup", "push" ) );
     141                 :            :     }
     142                 :            : 
     143                 :            :     try {
     144                 :          0 :         accessibility::XAccessibleAction* pAction = getAction( action );
     145                 :          0 :         if( pAction )
     146                 :            :         {
     147                 :          0 :             std::map< rtl::OUString, const gchar * >::iterator iter;
     148                 :            : 
     149                 :          0 :             rtl::OUString aDesc( pAction->getAccessibleActionDescription( i ) );
     150                 :            : 
     151                 :          0 :             iter = aNameMap.find( aDesc );
     152                 :          0 :             if( iter != aNameMap.end() )
     153                 :          0 :                 return iter->second;
     154                 :            : 
     155                 :            :             std::pair< const rtl::OUString, const gchar * > aNewVal( aDesc,
     156                 :          0 :                 g_strdup( OUStringToConstGChar(aDesc) ) );
     157                 :            : 
     158                 :          0 :             if( aNameMap.insert( aNewVal ).second )
     159                 :          0 :                 return aNewVal.second;
     160                 :            :         }
     161                 :            :     }
     162                 :          0 :     catch(const uno::Exception& e) {
     163                 :          0 :         g_warning( "Exception in getAccessibleActionDescription()" );
     164                 :            :     }
     165                 :            : 
     166                 :          0 :     return "";
     167                 :            : }
     168                 :            : 
     169                 :            : /*
     170                 :            : *  GNOME Expects a string in the format:
     171                 :            : *
     172                 :            : *  <nmemonic>;<full-path>;<accelerator>
     173                 :            : *
     174                 :            : *  The keybindings in <full-path> should be separated by ":"
     175                 :            : */
     176                 :            : 
     177                 :            : static inline void
     178                 :          0 : appendKeyStrokes(rtl::OStringBuffer& rBuffer, const uno::Sequence< awt::KeyStroke >& rKeyStrokes)
     179                 :            : {
     180                 :          0 :     for( sal_Int32 i = 0; i < rKeyStrokes.getLength(); i++ )
     181                 :            :     {
     182                 :          0 :         if( rKeyStrokes[i].Modifiers &  awt::KeyModifier::SHIFT )
     183                 :          0 :             rBuffer.append("<Shift>");
     184                 :          0 :         if( rKeyStrokes[i].Modifiers &  awt::KeyModifier::MOD1 )
     185                 :          0 :             rBuffer.append("<Control>");
     186                 :          0 :         if( rKeyStrokes[i].Modifiers &  awt::KeyModifier::MOD2 )
     187                 :          0 :             rBuffer.append("<Alt>");
     188                 :            : 
     189                 :          0 :         if( ( rKeyStrokes[i].KeyCode >= awt::Key::A ) && ( rKeyStrokes[i].KeyCode <= awt::Key::Z ) )
     190                 :          0 :             rBuffer.append( (sal_Char) ( 'a' + ( rKeyStrokes[i].KeyCode - awt::Key::A ) ) );
     191                 :            :         else
     192                 :            :         {
     193                 :          0 :             sal_Char c = '\0';
     194                 :            : 
     195                 :          0 :             switch( rKeyStrokes[i].KeyCode )
     196                 :            :             {
     197                 :          0 :                 case awt::Key::TAB:      c = '\t'; break;
     198                 :          0 :                 case awt::Key::SPACE:    c = ' '; break;
     199                 :          0 :                 case awt::Key::ADD:      c = '+'; break;
     200                 :          0 :                 case awt::Key::SUBTRACT: c = '-'; break;
     201                 :          0 :                 case awt::Key::MULTIPLY: c = '*'; break;
     202                 :          0 :                 case awt::Key::DIVIDE:   c = '/'; break;
     203                 :          0 :                 case awt::Key::POINT:    c = '.'; break;
     204                 :          0 :                 case awt::Key::COMMA:    c = ','; break;
     205                 :          0 :                 case awt::Key::LESS:     c = '<'; break;
     206                 :          0 :                 case awt::Key::GREATER:  c = '>'; break;
     207                 :          0 :                 case awt::Key::EQUAL:    c = '='; break;
     208                 :            :                 case 0:
     209                 :          0 :                     break;
     210                 :            :                 default:
     211                 :          0 :                     g_warning( "Unmapped KeyCode: %d", rKeyStrokes[i].KeyCode );
     212                 :          0 :                     break;
     213                 :            :             }
     214                 :            : 
     215                 :          0 :             if( c != '\0' )
     216                 :          0 :                 rBuffer.append( c );
     217                 :            :         }
     218                 :            :     }
     219                 :          0 : }
     220                 :            : 
     221                 :            : 
     222                 :            : static G_CONST_RETURN gchar *
     223                 :          0 : action_wrapper_get_keybinding (AtkAction *action,
     224                 :            :                                gint       i)
     225                 :            : {
     226                 :            :     try {
     227                 :          0 :         accessibility::XAccessibleAction* pAction = getAction( action );
     228                 :          0 :         if( pAction )
     229                 :            :         {
     230                 :          0 :             uno::Reference< accessibility::XAccessibleKeyBinding > xBinding( pAction->getAccessibleActionKeyBinding( i ));
     231                 :            : 
     232                 :          0 :             if( xBinding.is() )
     233                 :            :             {
     234                 :          0 :                 rtl::OStringBuffer aRet;
     235                 :            : 
     236                 :          0 :                 sal_Int32 nmax = std::min( xBinding->getAccessibleKeyBindingCount(), (sal_Int32) 3 );
     237                 :          0 :                 for( sal_Int32 n = 0; n < nmax; n++ )
     238                 :            :                 {
     239                 :          0 :                     appendKeyStrokes( aRet,  xBinding->getAccessibleKeyBinding( n ) );
     240                 :            : 
     241                 :          0 :                     if( n < 2 )
     242                 :          0 :                         aRet.append( (sal_Char) ';' );
     243                 :            :                 }
     244                 :            : 
     245                 :            :                 // !! FIXME !! remember keystroke in wrapper object ?
     246                 :          0 :                 return getAsConst( aRet.makeStringAndClear() );
     247                 :          0 :             }
     248                 :            :         }
     249                 :            :     }
     250                 :          0 :     catch(const uno::Exception& e) {
     251                 :          0 :         g_warning( "Exception in get_keybinding()" );
     252                 :            :     }
     253                 :            : 
     254                 :          0 :     return "";
     255                 :            : }
     256                 :            : 
     257                 :            : static gboolean
     258                 :          0 : action_wrapper_set_description (AtkAction *, gint, const gchar *)
     259                 :            : {
     260                 :          0 :     return FALSE;
     261                 :            : }
     262                 :            : 
     263                 :            : } // extern "C"
     264                 :            : 
     265                 :            : void
     266                 :          0 : actionIfaceInit (AtkActionIface *iface)
     267                 :            : {
     268                 :          0 :   g_return_if_fail (iface != NULL);
     269                 :            : 
     270                 :          0 :   iface->do_action = action_wrapper_do_action;
     271                 :          0 :   iface->get_n_actions = action_wrapper_get_n_actions;
     272                 :          0 :   iface->get_description = action_wrapper_get_description;
     273                 :          0 :   iface->get_keybinding = action_wrapper_get_keybinding;
     274                 :          0 :   iface->get_name = action_wrapper_get_name;
     275                 :          0 :   iface->get_localized_name = action_wrapper_get_localized_name;
     276                 :          0 :   iface->set_description = action_wrapper_set_description;
     277                 :            : }
     278                 :            : 
     279                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10