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