xref: /trunk/main/vcl/unx/gtk/a11y/atkvalue.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "atkwrapper.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleValue.hpp>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <stdio.h>
32cdf0e10cSrcweir #include <string.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace ::com::sun::star;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir static accessibility::XAccessibleValue*
getValue(AtkValue * pValue)37cdf0e10cSrcweir     getValue( AtkValue *pValue ) throw (uno::RuntimeException)
38cdf0e10cSrcweir {
39cdf0e10cSrcweir     AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pValue );
40cdf0e10cSrcweir     if( pWrap )
41cdf0e10cSrcweir     {
42cdf0e10cSrcweir         if( !pWrap->mpValue && pWrap->mpContext )
43cdf0e10cSrcweir         {
44cdf0e10cSrcweir             uno::Any any = pWrap->mpContext->queryInterface( accessibility::XAccessibleValue::static_type(NULL) );
45cdf0e10cSrcweir             pWrap->mpValue = reinterpret_cast< accessibility::XAccessibleValue * > (any.pReserved);
46cdf0e10cSrcweir             pWrap->mpValue->acquire();
47cdf0e10cSrcweir         }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir         return pWrap->mpValue;
50cdf0e10cSrcweir     }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     return NULL;
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
anyToGValue(uno::Any aAny,GValue * pValue)55cdf0e10cSrcweir static void anyToGValue( uno::Any aAny, GValue *pValue )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     // FIXME: expand to lots of types etc.
58cdf0e10cSrcweir     double aDouble=0;
59cdf0e10cSrcweir     aAny >>= aDouble;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     memset( pValue,  0, sizeof( GValue ) );
62cdf0e10cSrcweir     g_value_init( pValue, G_TYPE_DOUBLE );
63cdf0e10cSrcweir     g_value_set_double( pValue, aDouble );
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir extern "C" {
67cdf0e10cSrcweir 
68cdf0e10cSrcweir static void
value_wrapper_get_current_value(AtkValue * value,GValue * gval)69cdf0e10cSrcweir value_wrapper_get_current_value( AtkValue *value,
70cdf0e10cSrcweir                                  GValue   *gval )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     try {
73cdf0e10cSrcweir         accessibility::XAccessibleValue* pValue = getValue( value );
74cdf0e10cSrcweir         if( pValue )
75cdf0e10cSrcweir             anyToGValue( pValue->getCurrentValue(), gval );
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir     catch(const uno::Exception& e) {
78cdf0e10cSrcweir         g_warning( "Exception in getCurrentValue()" );
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir static void
value_wrapper_get_maximum_value(AtkValue * value,GValue * gval)83cdf0e10cSrcweir value_wrapper_get_maximum_value( AtkValue *value,
84cdf0e10cSrcweir                                  GValue   *gval )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     try {
87cdf0e10cSrcweir         accessibility::XAccessibleValue* pValue = getValue( value );
88cdf0e10cSrcweir         if( pValue )
89cdf0e10cSrcweir             anyToGValue( pValue->getMaximumValue(), gval );
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir     catch(const uno::Exception& e) {
92cdf0e10cSrcweir         g_warning( "Exception in getCurrentValue()" );
93cdf0e10cSrcweir     }
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir static void
value_wrapper_get_minimum_value(AtkValue * value,GValue * gval)97cdf0e10cSrcweir value_wrapper_get_minimum_value( AtkValue *value,
98cdf0e10cSrcweir                                  GValue   *gval )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     try {
101cdf0e10cSrcweir         accessibility::XAccessibleValue* pValue = getValue( value );
102cdf0e10cSrcweir         if( pValue )
103cdf0e10cSrcweir             anyToGValue( pValue->getMinimumValue(), gval );
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir     catch(const uno::Exception& e) {
106cdf0e10cSrcweir         g_warning( "Exception in getCurrentValue()" );
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir static gboolean
value_wrapper_set_current_value(AtkValue * value,const GValue * gval)111cdf0e10cSrcweir value_wrapper_set_current_value( AtkValue     *value,
112cdf0e10cSrcweir                                  const GValue *gval )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     try {
115cdf0e10cSrcweir         accessibility::XAccessibleValue* pValue = getValue( value );
116cdf0e10cSrcweir         if( pValue )
117cdf0e10cSrcweir         {
118cdf0e10cSrcweir             // FIXME - this needs expanding
119cdf0e10cSrcweir             double aDouble = g_value_get_double( gval );
120cdf0e10cSrcweir             uno::Any aAny;
121cdf0e10cSrcweir             aAny <<= aDouble;
122cdf0e10cSrcweir             return pValue->setCurrentValue( aAny );
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir     catch(const uno::Exception& e) {
126cdf0e10cSrcweir         g_warning( "Exception in getCurrentValue()" );
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     return FALSE;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir } // extern "C"
133cdf0e10cSrcweir 
134cdf0e10cSrcweir void
valueIfaceInit(AtkValueIface * iface)135cdf0e10cSrcweir valueIfaceInit (AtkValueIface *iface)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir   g_return_if_fail (iface != NULL);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir   iface->get_current_value = value_wrapper_get_current_value;
140cdf0e10cSrcweir   iface->get_maximum_value = value_wrapper_get_maximum_value;
141cdf0e10cSrcweir   iface->get_minimum_value = value_wrapper_get_minimum_value;
142cdf0e10cSrcweir   iface->set_current_value = value_wrapper_set_current_value;
143cdf0e10cSrcweir }
144