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

Generated by: LCOV version 1.10