4 #include "my-atk-object.h"
5 #include "my-atk-value.h"
7 //*************************implementation***********************
8 //implementation of virtual functions
9 //******************get_current_value*******************
10 static void my_atk_value_get_current_value(AtkValue *obj, GValue *value)
12 g_return_if_fail(MY_IS_ATK_VALUE(obj));
13 MyAtkValue* self = (MyAtkValue*)obj;
15 g_value_init(value, G_TYPE_INT);
16 g_value_set_int(value, self->current);
18 //******************get_maximum_value*******************
19 static void my_atk_value_get_maximum_value(AtkValue *obj, GValue *value)
21 g_return_if_fail(MY_IS_ATK_VALUE(obj));
22 MyAtkValue* self = (MyAtkValue*)obj;
24 g_value_init(value, G_TYPE_INT);
25 g_value_set_int(value, self->maximum);
27 //******************get_minimum_value*******************
28 static void my_atk_value_get_minimum_value(AtkValue *obj, GValue *value)
30 g_return_if_fail(MY_IS_ATK_VALUE(obj));
31 MyAtkValue* self = (MyAtkValue*)obj;
33 g_value_init(value, G_TYPE_INT);
34 g_value_set_int(value, self->minimum);
36 //******************set_current_value*******************
37 static gboolean my_atk_value_set_current_value(AtkValue *obj, const GValue *value)
39 g_return_val_if_fail(MY_IS_ATK_VALUE(obj), FALSE);
40 MyAtkValue* self = (MyAtkValue*)obj;
42 if(self->readonly) return FALSE;
44 gint new_value = g_value_get_int(value);
45 if(new_value < self->minimum || new_value > self->maximum) return FALSE;
47 self->current = new_value;
52 MyAtkValue* my_atk_value_new(gint minimum, gint maximum, gint current)
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;
62 static void my_atk_value_instance_init(GTypeInstance *obj, gpointer g_class)
64 MyAtkValue *self = (MyAtkValue*)obj;
70 self->readonly = FALSE;
72 static void my_atk_value_interface_init(gpointer g_iface, gpointer iface_data)
74 AtkValueIface *klass = (AtkValueIface*)g_iface;
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;
80 klass->set_current_value = my_atk_value_set_current_value;
83 GType my_atk_value_get_type()
85 static GType type = 0;
88 static const GTypeInfo typeInfo =
90 sizeof(MyAtkValueClass),
94 NULL, //class_finalize
98 my_atk_value_instance_init //instance_init
101 static const GInterfaceInfo iface_info =
103 my_atk_value_interface_init, /* interface_init*/
104 NULL, /* interface_finalize*/
105 NULL /* interface_data */
107 type = g_type_register_static(MY_TYPE_ATK_OBJECT, "MyAtkValue", &typeInfo, 0);
108 g_type_add_interface_static(type,