662aa1ac9b0dacd37cba487d7bff28009670d142
[platform/upstream/atk.git] / atk / atkaction.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "atkaction.h"
21
22 GType
23 atk_action_get_type ()
24 {
25   static GType type = 0;
26
27   if (!type) {
28     GTypeInfo tinfo =
29     {
30       sizeof (AtkActionIface),
31       (GBaseInitFunc) NULL,
32       (GBaseFinalizeFunc) NULL,
33
34     };
35
36     type = g_type_register_static (G_TYPE_INTERFACE, "AtkAction", &tinfo, 0);
37   }
38
39   return type;
40 }
41
42 /**
43  * atk_action_do_action:
44  * @action: a #GObject instance that implements AtkActionIface
45  * @i: the action to be performed 
46  *
47  * Perform the specified action on the object
48  **/
49 void
50 atk_action_do_action (AtkAction *obj,
51                       gint      i)
52 {
53   AtkActionIface *iface;
54
55   g_return_if_fail (obj != NULL);
56   g_return_if_fail (ATK_IS_ACTION (obj));
57
58   iface = ATK_ACTION_GET_IFACE (obj);
59
60   if (iface->do_action)
61     (iface->do_action) (obj, i);
62 }
63
64 /**
65  * atk_action_get_n_actions:
66  * @action: a #GObject instance that implements AtkActionIface
67  * 
68  * Gets the number of accessible actions available on the object.
69  * If there are more than one, the first one is considered the
70  * "default" action of the object.
71  *
72  * Returns: a the number of actions , or 0
73  * if @action does not implement this interface.
74  **/
75 gint
76 atk_action_get_n_actions  (AtkAction *obj)
77 {
78   AtkActionIface *iface;
79
80   g_return_val_if_fail (obj != NULL, 0);
81   g_return_val_if_fail (ATK_IS_ACTION (obj), 0);
82
83   iface = ATK_ACTION_GET_IFACE (obj);
84
85   if (iface->get_n_actions)
86     return (iface->get_n_actions) (obj);
87   else
88     return 0;
89 }
90
91 /**
92  * atk_action_get_description:
93  * @action: a #GObject instance that implements AtkActionIface
94  * @i: a %gint indicating the action
95  *
96  * Returns a description of the specified action of the object
97  *
98  * Returns a description string, or %NULL
99  * if @action does not implement this interface.
100  **/
101 G_CONST_RETURN gchar*
102 atk_action_get_description (AtkAction *obj,
103                             gint      i)
104 {
105   AtkActionIface *iface;
106
107   g_return_val_if_fail (obj != NULL, NULL);
108   g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
109
110   iface = ATK_ACTION_GET_IFACE (obj);
111
112   if (iface->get_description)
113     return (iface->get_description) (obj, i);
114   else
115     return NULL;
116 }
117
118 /**
119  * atk_action_get_keybinding:
120  * @action: a #GObject instance that implements AtkActionIface
121  * @i: a %gint indicating the action
122  *
123  * Returns a keybinding associated with this action, if one exists.
124  *
125  * Returns a string representing the keybinding, or %NULL
126  * if there is no keybinding for this action.
127  *
128  **/
129 G_CONST_RETURN gchar*
130 atk_action_get_keybinding (AtkAction *obj,
131                            gint      i)
132 {
133   AtkActionIface *iface;
134
135   g_return_val_if_fail (obj != NULL, NULL);
136   g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
137
138   iface = ATK_ACTION_GET_IFACE (obj);
139
140   if (iface->get_keybinding)
141     return (iface->get_keybinding) (obj, i);
142   else
143     return NULL;
144 }