7962df438d29b43bdad1079b11e791e11c1f1f34
[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 index corresponding to the action to be performed 
46  *
47  * Perform the specified action on the object.
48  **/
49 gboolean
50 atk_action_do_action (AtkAction *obj,
51                       gint      i)
52 {
53   AtkActionIface *iface;
54
55   g_return_val_if_fail (ATK_IS_ACTION (obj), FALSE);
56
57   iface = ATK_ACTION_GET_IFACE (obj);
58
59   if (iface->do_action)
60     return (iface->do_action) (obj, i);
61   else
62     return FALSE;
63 }
64
65 /**
66  * atk_action_get_n_actions:
67  * @action: a #GObject instance that implements AtkActionIface
68  * 
69  * Gets the number of accessible actions available on the object.
70  * If there are more than one, the first one is considered the
71  * "default" action of the object.
72  *
73  * Returns: a the number of actions, or 0 if @action does not
74  * implement this interface.
75  **/
76 gint
77 atk_action_get_n_actions  (AtkAction *obj)
78 {
79   AtkActionIface *iface;
80
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: the action index corresponding to the action to be performed 
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 (ATK_IS_ACTION (obj), NULL);
108
109   iface = ATK_ACTION_GET_IFACE (obj);
110
111   if (iface->get_description)
112     return (iface->get_description) (obj, i);
113   else
114     return NULL;
115 }
116
117 /**
118  * atk_action_get_name:
119  * @action: a #GObject instance that implements AtkActionIface
120  * @i: the action index corresponding to the action to be performed 
121  *
122  * Returns the name of the specified action of the object.
123  *
124  * Returns a name string, or %NULL
125  * if @action does not implement this interface.
126  **/
127 G_CONST_RETURN gchar*
128 atk_action_get_name (AtkAction *obj,
129                      gint      i)
130 {
131   AtkActionIface *iface;
132
133   g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
134
135   iface = ATK_ACTION_GET_IFACE (obj);
136
137   if (iface->get_name)
138     return (iface->get_name) (obj, i);
139   else
140     return NULL;
141 }
142
143 /**
144  * atk_action_get_keybinding:
145  * @action: a #GObject instance that implements AtkActionIface
146  * @i: the action index corresponding to the action to be performed 
147  *
148  * Returns a keybinding associated with this action, if one exists.
149  *
150  * Returns a string representing the keybinding, or %NULL
151  * if there is no keybinding for this action.
152  *
153  **/
154 G_CONST_RETURN gchar*
155 atk_action_get_keybinding (AtkAction *obj,
156                            gint      i)
157 {
158   AtkActionIface *iface;
159
160   g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
161
162   iface = ATK_ACTION_GET_IFACE (obj);
163
164   if (iface->get_keybinding)
165     return (iface->get_keybinding) (obj, i);
166   else
167     return NULL;
168 }
169
170 /**
171  * atk_action_set_description:
172  * @action: a #GObject instance that implements AtkActionIface
173  * @i: the action index corresponding to the action to be performed 
174  * @desc: the description to be assigned to this action
175  *
176  * Sets a description of the specified action of the object.
177  *
178  * Returns: a gboolean representing if the description was successfully set;
179  **/
180 gboolean
181 atk_action_set_description (AtkAction   *obj,
182                             gint        i,
183                             const gchar *desc)
184 {
185   AtkActionIface *iface;
186
187   g_return_val_if_fail (ATK_IS_ACTION (obj), FALSE);
188
189   iface = ATK_ACTION_GET_IFACE (obj);
190
191   if (iface->set_description)
192     return (iface->set_description) (obj, i, desc);
193   else
194     return FALSE;
195 }