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/XAccessibleValue.hpp>
23
24 #include <string.h>
25
26 using namespace ::com::sun::star;
27
28 /// @throws uno::RuntimeException
29 static css::uno::Reference<css::accessibility::XAccessibleValue>
getValue(AtkValue * pValue)30 getValue( AtkValue *pValue )
31 {
32 AtkObjectWrapper *pWrap = ATK_OBJECT_WRAPPER( pValue );
33 if( pWrap )
34 {
35 if( !pWrap->mpValue.is() )
36 {
37 pWrap->mpValue.set(pWrap->mpContext, css::uno::UNO_QUERY);
38 }
39
40 return pWrap->mpValue;
41 }
42
43 return css::uno::Reference<css::accessibility::XAccessibleValue>();
44 }
45
anyToGValue(const uno::Any & aAny,GValue * pValue)46 static void anyToGValue( const uno::Any& aAny, GValue *pValue )
47 {
48 // FIXME: expand to lots of types etc.
49 double aDouble=0;
50 aAny >>= aDouble;
51
52 memset( pValue, 0, sizeof( GValue ) );
53 g_value_init( pValue, G_TYPE_DOUBLE );
54 g_value_set_double( pValue, aDouble );
55 }
56
57 extern "C" {
58
59 static void
value_wrapper_get_current_value(AtkValue * value,GValue * gval)60 value_wrapper_get_current_value( AtkValue *value,
61 GValue *gval )
62 {
63 try {
64 css::uno::Reference<css::accessibility::XAccessibleValue> pValue
65 = getValue( value );
66 if( pValue.is() )
67 anyToGValue( pValue->getCurrentValue(), gval );
68 }
69 catch(const uno::Exception&) {
70 g_warning( "Exception in getCurrentValue()" );
71 }
72 }
73
74 static void
value_wrapper_get_maximum_value(AtkValue * value,GValue * gval)75 value_wrapper_get_maximum_value( AtkValue *value,
76 GValue *gval )
77 {
78 try {
79 css::uno::Reference<css::accessibility::XAccessibleValue> pValue
80 = getValue( value );
81 if( pValue.is() )
82 anyToGValue( pValue->getMaximumValue(), gval );
83 }
84 catch(const uno::Exception&) {
85 g_warning( "Exception in getCurrentValue()" );
86 }
87 }
88
89 static void
value_wrapper_get_minimum_value(AtkValue * value,GValue * gval)90 value_wrapper_get_minimum_value( AtkValue *value,
91 GValue *gval )
92 {
93 try {
94 css::uno::Reference<css::accessibility::XAccessibleValue> pValue
95 = getValue( value );
96 if( pValue.is() )
97 anyToGValue( pValue->getMinimumValue(), gval );
98 }
99 catch(const uno::Exception&) {
100 g_warning( "Exception in getCurrentValue()" );
101 }
102 }
103
104 static gboolean
value_wrapper_set_current_value(AtkValue * value,const GValue * gval)105 value_wrapper_set_current_value( AtkValue *value,
106 const GValue *gval )
107 {
108 try {
109 css::uno::Reference<css::accessibility::XAccessibleValue> pValue
110 = getValue( value );
111 if( pValue.is() )
112 {
113 // FIXME - this needs expanding
114 double aDouble = g_value_get_double( gval );
115 return pValue->setCurrentValue( uno::Any(aDouble) );
116 }
117 }
118 catch(const uno::Exception&) {
119 g_warning( "Exception in getCurrentValue()" );
120 }
121
122 return FALSE;
123 }
124
125 } // extern "C"
126
127 void
valueIfaceInit(AtkValueIface * iface)128 valueIfaceInit (AtkValueIface *iface)
129 {
130 g_return_if_fail (iface != nullptr);
131
132 iface->get_current_value = value_wrapper_get_current_value;
133 iface->get_maximum_value = value_wrapper_get_maximum_value;
134 iface->get_minimum_value = value_wrapper_get_minimum_value;
135 iface->set_current_value = value_wrapper_set_current_value;
136 }
137
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
139