5 #include "my-atk-action.h"
7 static GObjectClass *parent_class = NULL;
8 //implementaion of the interface
9 static gboolean my_atk_action_do_action(AtkAction *action, gint i)
11 MyAtkAction *self = (MyAtkAction*)action;
12 gboolean result = (i>=0) && (i < self->n);
13 self->last_performed_action = result? i : -1;
16 static gint my_atk_action_get_n_actions(AtkAction *action)
18 MyAtkAction *self = (MyAtkAction*)action;
21 static const gchar* my_atk_action_get_description(AtkAction *action, gint i)
23 MyAtkAction *self = (MyAtkAction*)action;
24 if((i>=0) && (i<self->n))
26 return self->actions[i].description;
30 printf("get_description: Wrong index.\n");
34 static const gchar* my_atk_action_get_name(AtkAction *action, gint i)
36 MyAtkAction *self = (MyAtkAction*)action;
37 if((i >= 0) && (i < self->n))
39 return self->actions[i].name;
43 printf("get_name: Wrong index.\n");
47 static const gchar* my_atk_action_get_localized_name(AtkAction *action, gint i)
49 return my_atk_action_get_name(action,i);
52 static const gchar* my_atk_action_get_keybinding(AtkAction *action, gint i)
54 MyAtkAction *self = (MyAtkAction*)action;
55 if((i >= 0) && (i < self->n))
57 gchar* keyb = self->actions[i].keybinding;
58 if(keyb == NULL || keybinding_note_define == NULL)
60 //anywhere(if action has keybinding or not) NULL will return
65 //verify, if string mean "no keybinding"
66 return strcmp(keyb, keybinding_note_define) != 0 ? keyb : NULL;
71 printf("get_keybinding: Wrong index.\n");
75 static gboolean my_atk_action_set_description(AtkAction *action, gint i, const gchar *desc)
77 MyAtkAction *self = (MyAtkAction*)action;
79 if(!((i >= 0) && (i < self->n)) )
81 //index out of range, but this is not application error according documentation
84 //index in correct range
85 if(self->actions[i].description == desc)
87 //self assignment - return immediately
90 if(self->actions[i].description != NULL)
92 //free old value of description if it is not NULL
93 free(self->actions[i].description);
97 //dump new value of description if it is not NULL
98 self->actions[i].description = (gchar*)strdup((const char*)desc);
103 static void my_atk_action_instance_init(GTypeInstance *instance, gpointer g_class)
106 MyAtkAction *self = (MyAtkAction*)instance;
107 self->n = DEFAULT_NUMBER_ACTIONS;
108 self->actions = g_new(struct OneAction, self->n);
109 if(self->actions == NULL)
114 //init fields of action 0 with values which differ from others actions
115 self->actions[0].name = (gchar*)strdup(FIRST_ACTION_NAME);
116 self->actions[0].description = (gchar*)strdup(FIRST_ACTION_DESCRIPTION);
117 self->actions[0].keybinding = (gchar*)strdup(FIRST_ACTION_KEYBINDING);
119 for(i = 1; i < self->n; i++)
121 self->actions[i].name = (gchar*)strdup(DEFAULT_ACTION_NAME);
122 self->actions[i].description = (gchar*)strdup(DEFAULT_ACTION_DESCRIPTION);
123 self->actions[i].keybinding = (gchar*)strdup(DEFAULT_ACTION_KEYBINDING);
125 self->disposed = FALSE;
126 self->last_performed_action = -1;
130 my_atk_action_interface_init(gpointer g_iface, gpointer iface_data)
132 AtkActionIface *klass = (AtkActionIface *)g_iface;
134 klass->do_action = my_atk_action_do_action;
135 klass->get_n_actions = my_atk_action_get_n_actions;
136 klass->get_description = my_atk_action_get_description;
137 klass->get_name = my_atk_action_get_name;
138 klass->get_localized_name = my_atk_action_get_localized_name;
139 klass->get_keybinding = my_atk_action_get_keybinding;
140 klass->set_description = my_atk_action_set_description;
144 my_atk_action_dispose(GObject *obj)
146 MyAtkAction *self = (MyAtkAction*)obj;
152 self->disposed = TRUE;
154 G_OBJECT_CLASS(parent_class)->dispose(obj);
158 my_atk_action_finalize(GObject *obj)
160 MyAtkAction *self = (MyAtkAction*)obj;
163 for(i = 0; i < self->n; i++)
165 struct OneAction oneAction = self->actions[i];
166 if(oneAction.name != NULL)
167 free(oneAction.name);
168 if(oneAction.description != NULL)
169 free(oneAction.description);
170 if(oneAction.keybinding != NULL)
171 free(oneAction.keybinding);
173 if(self->actions != NULL)
174 g_free(self->actions);
176 G_OBJECT_CLASS(parent_class)->finalize(obj);
179 my_atk_action_class_init (gpointer g_class, gpointer g_class_data)
181 GObjectClass *gobject_class = G_OBJECT_CLASS(g_class);
182 MyAtkActionClass *klass = MY_ATK_ACTION_CLASS (g_class);
184 gobject_class->dispose = my_atk_action_dispose;
185 gobject_class->finalize = my_atk_action_finalize;
187 parent_class = g_type_class_peek_parent(klass);
189 GType my_atk_action_get_type(void)
191 static GType type = 0;
194 static const GTypeInfo info =
196 sizeof (MyAtkActionClass),
197 NULL, /* base_init */
198 NULL, /* base_finalize */
199 my_atk_action_class_init, /* class_init */
200 NULL, /* class_finalize */
201 NULL, /* class_data */
202 sizeof (MyAtkAction),
204 my_atk_action_instance_init /* instance_init */
207 static const GInterfaceInfo iface_info =
209 (GInterfaceInitFunc) my_atk_action_interface_init, /* interface_init */
210 NULL, /* interface_finalize */
211 NULL /* interface_data */
213 type = g_type_register_static (G_TYPE_OBJECT,
216 g_type_add_interface_static (type,