1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/* gtkatspivalue.c: AT-SPI Value implementation
*
* Copyright 2020 Red Hat, Inc.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkatspivalueprivate.h"
#include "a11y/atspi/atspi-value.h"
#include "gtkaccessiblerangeprivate.h"
#include "gtkatcontextprivate.h"
#include "gtkdebug.h"
#include <gio/gio.h>
static GVariant *
handle_value_get_property (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *property_name,
GError **error,
gpointer user_data)
{
GtkATContext *ctx = GTK_AT_CONTEXT (user_data);
/* Numeric attributes */
struct {
const char *name;
GtkAccessibleProperty property;
} num_properties[] = {
{ "MinimumValue", GTK_ACCESSIBLE_PROPERTY_VALUE_MIN },
{ "MaximumValue", GTK_ACCESSIBLE_PROPERTY_VALUE_MAX },
{ "CurrentValue", GTK_ACCESSIBLE_PROPERTY_VALUE_NOW },
};
/* String attributes */
struct {
const char *name;
GtkAccessibleProperty property;
} str_properties[] = {
{ "Text", GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT },
};
for (int i = 0; i < G_N_ELEMENTS (num_properties); i++)
{
if (g_strcmp0 (property_name, num_properties[i].name) == 0)
{
if (gtk_at_context_has_accessible_property (ctx, num_properties[i].property))
{
GtkAccessibleValue *value =
gtk_at_context_get_accessible_property (ctx, num_properties[i].property);
return g_variant_new_double (gtk_number_accessible_value_get (value));
}
}
}
for (int i = 0; i < G_N_ELEMENTS (str_properties); i++)
{
if (g_strcmp0 (property_name, str_properties[i].name) == 0)
{
if (gtk_at_context_has_accessible_property (ctx, str_properties[i].property))
{
GtkAccessibleValue *value =
gtk_at_context_get_accessible_property (ctx, str_properties[i].property);
return g_variant_new_string (gtk_string_accessible_value_get (value));
}
}
}
/* Special-case MinimumIncrement as it does not have an ARIA counterpart */
if (g_strcmp0 (property_name, "MinimumIncrement") == 0)
return g_variant_new_double (0.0);
/* fall back for widgets that should have the
* properties but don't
*/
return g_variant_new_double (0.0);
}
static gboolean
handle_value_set_property (GDBusConnection *connection,
const gchar *sender,
const gchar *object_path,
const gchar *interface_name,
const gchar *property_name,
GVariant *value,
GError **error,
gpointer user_data)
{
GtkATContext *self = user_data;
GtkAccessibleRange *range = GTK_ACCESSIBLE_RANGE (gtk_at_context_get_accessible (self));
if (g_strcmp0 (property_name, "CurrentValue") == 0)
return gtk_accessible_range_set_current_value (range, g_variant_get_double (value));
return FALSE;
}
static const GDBusInterfaceVTable value_vtable = {
NULL,
handle_value_get_property,
handle_value_set_property,
};
const GDBusInterfaceVTable *
gtk_atspi_get_value_vtable (GtkAccessible *accessible)
{
if (GTK_IS_ACCESSIBLE_RANGE (accessible))
return &value_vtable;
return NULL;
}
|