5 #include "my-atk-object.h"
6 #include "my-atk-action.h"
8 static GObjectClass *parent_class = NULL;
9 //implementaion of the interface
10 static gboolean my_atk_action_do_action(AtkAction *action, gint i)
12 MyAtkAction *self = (MyAtkAction*)action;
13 gboolean result = (i>=0) && (i < self->n);
14 self->last_performed_action = result? i : -1;
17 static gint my_atk_action_get_n_actions(AtkAction *action)
19 MyAtkAction *self = (MyAtkAction*)action;
22 static const gchar* my_atk_action_get_description(AtkAction *action, gint i)
24 MyAtkAction *self = (MyAtkAction*)action;
25 if((i>=0) && (i<self->n))
27 return self->actions[i].description;
31 printf("get_description: Wrong index.\n");
35 static const gchar* my_atk_action_get_name(AtkAction *action, gint i)
37 MyAtkAction *self = (MyAtkAction*)action;
38 if((i >= 0) && (i < self->n))
40 return self->actions[i].name;
44 printf("get_name: Wrong index.\n");
48 static const gchar* my_atk_action_get_localized_name(AtkAction *action, gint i)
50 return my_atk_action_get_name(action,i);
53 static const gchar* my_atk_action_get_keybinding(AtkAction *action, gint i)
55 MyAtkAction *self = (MyAtkAction*)action;
56 if((i >= 0) && (i < self->n))
58 gchar* keyb = self->actions[i].keybinding;
59 if(keyb == NULL || keybinding_note_define == NULL)
61 //anywhere(if action has keybinding or not) NULL will return
66 //verify, if string mean "no keybinding"
67 return strcmp(keyb, keybinding_note_define) != 0 ? keyb : NULL;
72 printf("get_keybinding: Wrong index.\n");
76 static gboolean my_atk_action_set_description(AtkAction *action, gint i, const gchar *desc)
78 MyAtkAction *self = (MyAtkAction*)action;
80 if(!((i >= 0) && (i < self->n)) )
82 //index out of range, but this is not application error according documentation
85 //index in correct range
86 if(self->actions[i].description == desc)
88 //self assignment - return immediately
91 if(self->actions[i].description != NULL)
93 //free old value of description if it is not NULL
94 free(self->actions[i].description);
98 //dump new value of description if it is not NULL
99 self->actions[i].description = (gchar*)strdup((const char*)desc);
104 static void my_atk_action_instance_init(GTypeInstance *instance, gpointer g_class)
107 MyAtkAction *self = (MyAtkAction*)instance;
108 self->n = DEFAULT_NUMBER_ACTIONS;
109 self->actions = g_new(struct OneAction, self->n);
110 if(self->actions == NULL)
115 //init fields of action 0 with values which differ from others actions
116 self->actions[0].name = (gchar*)strdup(FIRST_ACTION_NAME);
117 self->actions[0].description = (gchar*)strdup(FIRST_ACTION_DESCRIPTION);
118 self->actions[0].keybinding = (gchar*)strdup(FIRST_ACTION_KEYBINDING);
120 for(i = 1; i < self->n; i++)
122 self->actions[i].name = (gchar*)strdup(DEFAULT_ACTION_NAME);
123 self->actions[i].description = (gchar*)strdup(DEFAULT_ACTION_DESCRIPTION);
124 self->actions[i].keybinding = (gchar*)strdup(DEFAULT_ACTION_KEYBINDING);
126 self->disposed = FALSE;
127 self->last_performed_action = -1;
131 my_atk_action_interface_init(gpointer g_iface, gpointer iface_data)
133 AtkActionIface *klass = (AtkActionIface *)g_iface;
135 klass->do_action = my_atk_action_do_action;
136 klass->get_n_actions = my_atk_action_get_n_actions;
137 klass->get_description = my_atk_action_get_description;
138 klass->get_name = my_atk_action_get_name;
139 klass->get_localized_name = my_atk_action_get_localized_name;
140 klass->get_keybinding = my_atk_action_get_keybinding;
141 klass->set_description = my_atk_action_set_description;
145 my_atk_action_dispose(GObject *obj)
147 MyAtkAction *self = (MyAtkAction*)obj;
153 self->disposed = TRUE;
155 G_OBJECT_CLASS(parent_class)->dispose(obj);
159 my_atk_action_finalize(GObject *obj)
161 MyAtkAction *self = (MyAtkAction*)obj;
164 for(i = 0; i < self->n; i++)
166 struct OneAction oneAction = self->actions[i];
167 if(oneAction.name != NULL)
168 free(oneAction.name);
169 if(oneAction.description != NULL)
170 free(oneAction.description);
171 if(oneAction.keybinding != NULL)
172 free(oneAction.keybinding);
174 if(self->actions != NULL)
175 g_free(self->actions);
177 G_OBJECT_CLASS(parent_class)->finalize(obj);
180 my_atk_action_class_init (gpointer g_class, gpointer g_class_data)
182 GObjectClass *gobject_class = G_OBJECT_CLASS(g_class);
183 MyAtkActionClass *klass = MY_ATK_ACTION_CLASS (g_class);
185 gobject_class->dispose = my_atk_action_dispose;
186 gobject_class->finalize = my_atk_action_finalize;
188 parent_class = g_type_class_peek_parent(klass);
190 GType my_atk_action_get_type(void)
192 static GType type = 0;
195 static const GTypeInfo info =
197 sizeof (MyAtkActionClass),
198 NULL, /* base_init */
199 NULL, /* base_finalize */
200 my_atk_action_class_init, /* class_init */
201 NULL, /* class_finalize */
202 NULL, /* class_data */
203 sizeof (MyAtkAction),
205 my_atk_action_instance_init /* instance_init */
208 static const GInterfaceInfo iface_info =
210 (GInterfaceInitFunc) my_atk_action_interface_init, /* interface_init */
211 NULL, /* interface_finalize */
212 NULL /* interface_data */
214 type = g_type_register_static (MY_TYPE_ATK_OBJECT,
217 g_type_add_interface_static (type,