2009-27-09 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / tests / dummyatk / my-atk-value.c
1 #include <atk/atk.h>
2 #include <limits.h>
3
4 #include "my-atk-object.h"
5 #include "my-atk-value.h"
6
7 //*************************implementation***********************
8 //implementation of virtual functions
9 //******************get_current_value*******************
10 static void my_atk_value_get_current_value(AtkValue *obj, GValue *value)
11 {
12     g_return_if_fail(MY_IS_ATK_VALUE(obj));
13     MyAtkValue* self = (MyAtkValue*)obj;
14     
15     g_value_init(value, G_TYPE_INT);
16     g_value_set_int(value, self->current);
17 }
18 //******************get_maximum_value*******************
19 static void my_atk_value_get_maximum_value(AtkValue *obj, GValue *value)
20 {
21     g_return_if_fail(MY_IS_ATK_VALUE(obj));
22     MyAtkValue* self = (MyAtkValue*)obj;
23     
24     g_value_init(value, G_TYPE_INT);
25     g_value_set_int(value, self->maximum);
26 }
27 //******************get_minimum_value*******************
28 static void my_atk_value_get_minimum_value(AtkValue *obj, GValue *value)
29 {
30     g_return_if_fail(MY_IS_ATK_VALUE(obj));
31     MyAtkValue* self = (MyAtkValue*)obj;
32     
33     g_value_init(value, G_TYPE_INT);
34     g_value_set_int(value, self->minimum);
35 }
36 //******************set_current_value*******************
37 static gboolean my_atk_value_set_current_value(AtkValue *obj, const GValue *value)
38 {
39     g_return_val_if_fail(MY_IS_ATK_VALUE(obj), FALSE);
40     MyAtkValue* self = (MyAtkValue*)obj;
41     
42     if(self->readonly) return FALSE;
43     
44     gint new_value = g_value_get_int(value);
45     if(new_value < self->minimum || new_value > self->maximum) return FALSE;
46     
47     self->current = new_value;
48     return TRUE;
49 }
50
51 //others
52 MyAtkValue* my_atk_value_new(gint minimum, gint maximum, gint current)
53 {
54     MyAtkValue* result = g_object_new(MY_TYPE_ATK_VALUE, NULL);
55     if(result == NULL) return NULL;
56     result->minimum = minimum;
57     result->maximum = maximum;
58     result->current = current;
59     
60     return result;
61 }
62 static void my_atk_value_instance_init(GTypeInstance *obj, gpointer g_class)
63 {
64     MyAtkValue *self = (MyAtkValue*)obj;
65     
66     self->minimum = 0;
67     self->maximum = 0;
68     self->current = 0;
69     
70     self->readonly = FALSE;
71 }
72 static void my_atk_value_interface_init(gpointer g_iface, gpointer iface_data)
73 {
74     AtkValueIface *klass = (AtkValueIface*)g_iface;
75     
76     klass->get_current_value = my_atk_value_get_current_value;
77     klass->get_minimum_value = my_atk_value_get_minimum_value;
78     klass->get_maximum_value = my_atk_value_get_maximum_value;
79     
80     klass->set_current_value = my_atk_value_set_current_value;
81 }
82
83 GType my_atk_value_get_type()
84 {
85     static GType type = 0;
86     if(type == 0)
87     {
88         static const GTypeInfo typeInfo = 
89         {
90             sizeof(MyAtkValueClass),
91             NULL, //base_init
92             NULL, //base_finalize
93             NULL, //class_init
94             NULL, //class_finalize
95             NULL, //class_data
96             sizeof(MyAtkValue),
97             0, //n_preallocs
98             my_atk_value_instance_init //instance_init
99         };
100
101         static const GInterfaceInfo iface_info = 
102         {
103             my_atk_value_interface_init,        /* interface_init*/
104             NULL,                               /* interface_finalize*/
105             NULL                                /* interface_data */
106         };
107         type = g_type_register_static(MY_TYPE_ATK_OBJECT, "MyAtkValue", &typeInfo, 0);
108         g_type_add_interface_static(type,
109             ATK_TYPE_VALUE,
110             &iface_info);
111     }
112     return type;    
113 }