1 /*
2  * Copyright 2008 Codethink Ltd.
3  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include <glib.h>
22 #include <string.h>
23 #include <atk/atk.h>
24 #include <stdio.h>
25 
26 #include "my-atk-object.h"
27 #include "my-atk-value.h"
28 
29 typedef struct _MyAtkValueInfo MyAtkValueInfo;
30 
31 static void atk_value_interface_init (AtkValueIface *iface);
32 
33 G_DEFINE_TYPE_WITH_CODE (MyAtkValue,
34                          my_atk_value,
35                          MY_TYPE_ATK_OBJECT,
36                          G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE,
37                              atk_value_interface_init));
38 
39 guint
my_atk_set_value(AtkValue * obj,gdouble min,gdouble cur,gdouble max,gdouble step)40 my_atk_set_value (AtkValue *obj, gdouble min, gdouble cur, gdouble max, gdouble step)
41 {
42   MyAtkValue *self = MY_ATK_VALUE (obj);
43   g_return_val_if_fail (MY_IS_ATK_VALUE (obj), -1);
44 
45   self->min = min;
46   self->cur = cur;
47   self->max = max;
48   self->step = step;
49 
50   return 0;
51 }
52 
53 static void
my_atk_value_get_value_and_text(AtkValue * obj,gdouble * value,gchar ** text)54 my_atk_value_get_value_and_text (AtkValue *obj, gdouble *value, gchar **text)
55 {
56   MyAtkValue *self = MY_ATK_VALUE (obj);
57   g_return_if_fail (MY_IS_ATK_VALUE (obj));
58 
59   *value = self->cur;
60   *text = g_strdup_printf ("%f", self->cur);
61 }
62 
63 static AtkRange*
my_atk_value_get_range(AtkValue * obj)64 my_atk_value_get_range (AtkValue *obj)
65 {
66   MyAtkValue *self = MY_ATK_VALUE (obj);
67   g_return_val_if_fail (MY_IS_ATK_VALUE (obj), NULL);
68 
69   return atk_range_new (self->min, self->max, NULL);
70 }
71 
72 static gdouble
my_atk_value_get_increment(AtkValue * obj)73 my_atk_value_get_increment (AtkValue *obj)
74 {
75   MyAtkValue *self = MY_ATK_VALUE (obj);
76   g_return_val_if_fail (MY_IS_ATK_VALUE (obj), 0);
77   return self->step;
78 }
79 
80 static GSList*
my_atk_value_get_sub_ranges(AtkValue * obj)81 my_atk_value_get_sub_ranges (AtkValue *obj)
82 {
83   g_return_val_if_fail (MY_IS_ATK_VALUE (obj), NULL);
84 
85   return NULL;
86 }
87 
88 static void
my_atk_value_set_value(AtkValue * obj,const gdouble val)89 my_atk_value_set_value (AtkValue *obj, const gdouble val)
90 {
91   MyAtkValue *self = MY_ATK_VALUE (obj);
92   g_return_if_fail (MY_IS_ATK_VALUE (obj));
93 
94   if ( self->min < val && val < self->max )
95     self->cur = val;
96   return;
97 }
98 
99 static void
atk_value_interface_init(AtkValueIface * iface)100 atk_value_interface_init (AtkValueIface *iface)
101 {
102   if (!iface) return;
103   iface->get_value_and_text = my_atk_value_get_value_and_text;
104   iface->get_range = my_atk_value_get_range;
105   iface->get_increment = my_atk_value_get_increment;
106   iface->get_sub_ranges = my_atk_value_get_sub_ranges;
107   iface->set_value = my_atk_value_set_value;
108 }
109 
110 static void
my_atk_value_init(MyAtkValue * self)111 my_atk_value_init (MyAtkValue *self)
112 {
113   self->min = 0;
114   self->cur = 0;
115   self->max = 0;
116   self->step = 0;
117 }
118 
119 static void
my_atk_value_class_initialize(AtkObject * obj,gpointer data)120 my_atk_value_class_initialize (AtkObject *obj, gpointer data)
121 {
122 }
123 
124 static void
my_atk_value_class_finalize(GObject * obj)125 my_atk_value_class_finalize (GObject *obj)
126 {
127 }
128 
129 static void
my_atk_value_class_init(MyAtkValueClass * my_class)130 my_atk_value_class_init(MyAtkValueClass *my_class)
131 {
132   AtkObjectClass *atk_class = ATK_OBJECT_CLASS(my_class);
133   GObjectClass *gobject_class = G_OBJECT_CLASS(my_class);
134 
135   gobject_class->finalize = my_atk_value_class_finalize;
136 
137   atk_class->initialize = my_atk_value_class_initialize;
138 }
139