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