4 #include "my-atk-value.h"
6 //*************************implementation***********************
7 //implementation of virtual functions
8 //******************get_current_value*******************
9 static void my_atk_value_get_current_value(AtkValue *obj, GValue *value)
11 g_return_if_fail(MY_IS_ATK_VALUE(obj));
12 MyAtkValue* self = (MyAtkValue*)obj;
14 g_value_init(value, G_TYPE_INT);
15 g_value_set_int(value, self->current);
17 //******************get_maximum_value*******************
18 static void my_atk_value_get_maximum_value(AtkValue *obj, GValue *value)
20 g_return_if_fail(MY_IS_ATK_VALUE(obj));
21 MyAtkValue* self = (MyAtkValue*)obj;
23 g_value_init(value, G_TYPE_INT);
24 g_value_set_int(value, self->maximum);
26 //******************get_minimum_value*******************
27 static void my_atk_value_get_minimum_value(AtkValue *obj, GValue *value)
29 g_return_if_fail(MY_IS_ATK_VALUE(obj));
30 MyAtkValue* self = (MyAtkValue*)obj;
32 g_value_init(value, G_TYPE_INT);
33 g_value_set_int(value, self->minimum);
35 //******************set_current_value*******************
36 static gboolean my_atk_value_set_current_value(AtkValue *obj, const GValue *value)
38 g_return_val_if_fail(MY_IS_ATK_VALUE(obj), FALSE);
39 MyAtkValue* self = (MyAtkValue*)obj;
41 if(self->readonly) return FALSE;
43 gint new_value = g_value_get_int(value);
44 if(new_value < self->minimum || new_value > self->maximum) return FALSE;
46 self->current = new_value;
51 MyAtkValue* my_atk_value_new(gint minimum, gint maximum, gint current)
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;
61 static void my_atk_value_instance_init(GTypeInstance *obj, gpointer g_class)
63 MyAtkValue *self = (MyAtkValue*)obj;
69 self->readonly = FALSE;
71 static void my_atk_value_interface_init(gpointer g_iface, gpointer iface_data)
73 AtkValueIface *klass = (AtkValueIface*)g_iface;
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;
79 klass->set_current_value = my_atk_value_set_current_value;
82 GType my_atk_value_get_type()
84 static GType type = 0;
87 static const GTypeInfo typeInfo =
89 sizeof(MyAtkValueClass),
93 NULL, //class_finalize
97 my_atk_value_instance_init //instance_init
100 static const GInterfaceInfo iface_info =
102 my_atk_value_interface_init, /* interface_init*/
103 NULL, /* interface_finalize*/
104 NULL /* interface_data */
106 type = g_type_register_static(ATK_TYPE_OBJECT, "MyAtkValue", &typeInfo, 0);
107 g_type_add_interface_static(type,