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