1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_vcl.hxx" 30 31 #include "atkwrapper.hxx" 32 33 #include <com/sun/star/accessibility/XAccessibleValue.hpp> 34 35 #include <stdio.h> 36 #include <string.h> 37 38 using namespace ::com::sun::star; 39 40 static accessibility::XAccessibleValue* 41 getValue( AtkValue *pValue ) throw (uno::RuntimeException) 42 { 43 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pValue ); 44 if( pWrap ) 45 { 46 if( !pWrap->mpValue && pWrap->mpContext ) 47 { 48 uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleValue::static_type(NULL) ); 49 pWrap->mpValue = reinterpret_cast< accessibility::XAccessibleValue * > (any.pReserved); 50 pWrap->mpValue->acquire(); 51 } 52 53 return pWrap->mpValue; 54 } 55 56 return NULL; 57 } 58 59 static void anyToGValue( uno::Any aAny, GValue *pValue ) 60 { 61 // FIXME: expand to lots of types etc. 62 double aDouble=0; 63 aAny >>= aDouble; 64 65 memset( pValue, 0, sizeof( GValue ) ); 66 g_value_init( pValue, G_TYPE_DOUBLE ); 67 g_value_set_double( pValue, aDouble ); 68 } 69 70 extern "C" { 71 72 static void 73 value_wrapper_get_current_value( AtkValue *value, 74 GValue *gval ) 75 { 76 try { 77 accessibility::XAccessibleValue* pValue = getValue( value ); 78 if( pValue ) 79 anyToGValue( pValue->getCurrentValue(), gval ); 80 } 81 catch(const uno::Exception& e) { 82 g_warning( "Exception in getCurrentValue()" ); 83 } 84 } 85 86 static void 87 value_wrapper_get_maximum_value( AtkValue *value, 88 GValue *gval ) 89 { 90 try { 91 accessibility::XAccessibleValue* pValue = getValue( value ); 92 if( pValue ) 93 anyToGValue( pValue->getMaximumValue(), gval ); 94 } 95 catch(const uno::Exception& e) { 96 g_warning( "Exception in getCurrentValue()" ); 97 } 98 } 99 100 static void 101 value_wrapper_get_minimum_value( AtkValue *value, 102 GValue *gval ) 103 { 104 try { 105 accessibility::XAccessibleValue* pValue = getValue( value ); 106 if( pValue ) 107 anyToGValue( pValue->getMinimumValue(), gval ); 108 } 109 catch(const uno::Exception& e) { 110 g_warning( "Exception in getCurrentValue()" ); 111 } 112 } 113 114 static gboolean 115 value_wrapper_set_current_value( AtkValue *value, 116 const GValue *gval ) 117 { 118 try { 119 accessibility::XAccessibleValue* pValue = getValue( value ); 120 if( pValue ) 121 { 122 // FIXME - this needs expanding 123 double aDouble = g_value_get_double( gval ); 124 uno::Any aAny; 125 aAny <<= aDouble; 126 return pValue->setCurrentValue( aAny ); 127 } 128 } 129 catch(const uno::Exception& e) { 130 g_warning( "Exception in getCurrentValue()" ); 131 } 132 133 return FALSE; 134 } 135 136 } // extern "C" 137 138 void 139 valueIfaceInit (AtkValueIface *iface) 140 { 141 g_return_if_fail (iface != NULL); 142 143 iface->get_current_value = value_wrapper_get_current_value; 144 iface->get_maximum_value = value_wrapper_get_maximum_value; 145 iface->get_minimum_value = value_wrapper_get_minimum_value; 146 iface->set_current_value = value_wrapper_set_current_value; 147 } 148