merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / gtk / a11y / atkvalue.cxx
blob39af5f901c9cb5cb87d4c559afbc4d667a5cbbd8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: atkvalue.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #include "atkwrapper.hxx"
36 #include <com/sun/star/accessibility/XAccessibleValue.hpp>
38 #include <stdio.h>
39 #include <string.h>
41 using namespace ::com::sun::star;
43 static accessibility::XAccessibleValue*
44 getValue( AtkValue *pValue ) throw (uno::RuntimeException)
46 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pValue );
47 if( pWrap )
49 if( !pWrap->mpValue && pWrap->mpContext )
51 uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleValue::static_type(NULL) );
52 pWrap->mpValue = reinterpret_cast< accessibility::XAccessibleValue * > (any.pReserved);
53 pWrap->mpValue->acquire();
56 return pWrap->mpValue;
59 return NULL;
62 static void anyToGValue( uno::Any aAny, GValue *pValue )
64 // FIXME: expand to lots of types etc.
65 double aDouble=0;
66 aAny >>= aDouble;
68 memset( pValue, 0, sizeof( GValue ) );
69 g_value_init( pValue, G_TYPE_DOUBLE );
70 g_value_set_double( pValue, aDouble );
73 extern "C" {
75 static void
76 value_wrapper_get_current_value( AtkValue *value,
77 GValue *gval )
79 try {
80 accessibility::XAccessibleValue* pValue = getValue( value );
81 if( pValue )
82 anyToGValue( pValue->getCurrentValue(), gval );
84 catch(const uno::Exception& e) {
85 g_warning( "Exception in getCurrentValue()" );
89 static void
90 value_wrapper_get_maximum_value( AtkValue *value,
91 GValue *gval )
93 try {
94 accessibility::XAccessibleValue* pValue = getValue( value );
95 if( pValue )
96 anyToGValue( pValue->getMaximumValue(), gval );
98 catch(const uno::Exception& e) {
99 g_warning( "Exception in getCurrentValue()" );
103 static void
104 value_wrapper_get_minimum_value( AtkValue *value,
105 GValue *gval )
107 try {
108 accessibility::XAccessibleValue* pValue = getValue( value );
109 if( pValue )
110 anyToGValue( pValue->getMinimumValue(), gval );
112 catch(const uno::Exception& e) {
113 g_warning( "Exception in getCurrentValue()" );
117 static gboolean
118 value_wrapper_set_current_value( AtkValue *value,
119 const GValue *gval )
121 try {
122 accessibility::XAccessibleValue* pValue = getValue( value );
123 if( pValue )
125 // FIXME - this needs expanding
126 double aDouble = g_value_get_double( gval );
127 uno::Any aAny;
128 aAny <<= aDouble;
129 return pValue->setCurrentValue( aAny );
132 catch(const uno::Exception& e) {
133 g_warning( "Exception in getCurrentValue()" );
136 return FALSE;
139 } // extern "C"
141 void
142 valueIfaceInit (AtkValueIface *iface)
144 g_return_if_fail (iface != NULL);
146 iface->get_current_value = value_wrapper_get_current_value;
147 iface->get_maximum_value = value_wrapper_get_maximum_value;
148 iface->get_minimum_value = value_wrapper_get_minimum_value;
149 iface->set_current_value = value_wrapper_set_current_value;