fe27eb1325687820129b6f153e105f1ab40ce075
[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 (void)
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  * Returns: %TRUE if success, %FALSE otherwise
50  *
51  **/
52 gboolean
53 atk_action_do_action (AtkAction *obj,
54                       gint      i)
55 {
56   AtkActionIface *iface;
57
58   g_return_val_if_fail (ATK_IS_ACTION (obj), FALSE);
59
60   iface = ATK_ACTION_GET_IFACE (obj);
61
62   if (iface->do_action)
63     return (iface->do_action) (obj, i);
64   else
65     return FALSE;
66 }
67
68 /**
69  * atk_action_get_n_actions:
70  * @action: a #GObject instance that implements AtkActionIface
71  * 
72  * Gets the number of accessible actions available on the object.
73  * If there are more than one, the first one is considered the
74  * "default" action of the object.
75  *
76  * Returns: a the number of actions, or 0 if @action does not
77  * implement this interface.
78  **/
79 gint
80 atk_action_get_n_actions  (AtkAction *obj)
81 {
82   AtkActionIface *iface;
83
84   g_return_val_if_fail (ATK_IS_ACTION (obj), 0);
85
86   iface = ATK_ACTION_GET_IFACE (obj);
87
88   if (iface->get_n_actions)
89     return (iface->get_n_actions) (obj);
90   else
91     return 0;
92 }
93
94 /**
95  * atk_action_get_description:
96  * @action: a #GObject instance that implements AtkActionIface
97  * @i: the action index corresponding to the action to be performed 
98  *
99  * Returns a description of the specified action of the object.
100  *
101  * Returns a description string, or %NULL
102  * if @action does not implement this interface.
103  **/
104 const gchar*
105 atk_action_get_description (AtkAction *obj,
106                             gint      i)
107 {
108   AtkActionIface *iface;
109
110   g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
111
112   iface = ATK_ACTION_GET_IFACE (obj);
113
114   if (iface->get_description)
115     return (iface->get_description) (obj, i);
116   else
117     return NULL;
118 }
119
120 /**
121  * atk_action_get_name:
122  * @action: a #GObject instance that implements AtkActionIface
123  * @i: the action index corresponding to the action to be performed 
124  *
125  * Returns a non-localized string naming the specified action of the 
126  * object. This name is generally not descriptive of the end result 
127  * of the action, but instead names the 'interaction type' which the 
128  * object supports. By convention, the above strings should be used to 
129  * represent the actions which correspond to the common point-and-click 
130  * interaction techniques of the same name: i.e. 
131  * "click", "press", "release", "drag", "drop", "popup", etc.
132  * The "popup" action should be used to pop up a context menu for the 
133  * object, if one exists.
134  *
135  * For technical reasons, some toolkits cannot guarantee that the 
136  * reported action is actually 'bound' to a nontrivial user event;
137  * i.e. the result of some actions via atk_action_do_action() may be
138  * NIL.
139  *
140  * Returns a name string, or %NULL
141  * if @action does not implement this interface.
142  **/
143 const gchar*
144 atk_action_get_name (AtkAction *obj,
145                      gint      i)
146 {
147   AtkActionIface *iface;
148
149   g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
150
151   iface = ATK_ACTION_GET_IFACE (obj);
152
153   if (iface->get_name)
154     return (iface->get_name) (obj, i);
155   else
156     return NULL;
157 }
158
159 /**
160  * atk_action_get_localized_name:
161  * @action: a #GObject instance that implements AtkActionIface
162  * @i: the action index corresponding to the action to be performed 
163  *
164  * Returns the localized name of the specified action of the object.
165  *
166  * Returns a name string, or %NULL
167  * if @action does not implement this interface.
168  **/
169 const gchar*
170 atk_action_get_localized_name (AtkAction *obj,
171                                gint      i)
172 {
173   AtkActionIface *iface;
174
175   g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
176
177   iface = ATK_ACTION_GET_IFACE (obj);
178
179   if (iface->get_localized_name)
180     return (iface->get_localized_name) (obj, i);
181   else
182     return NULL;
183 }
184
185 /**
186  * atk_action_get_keybinding:
187  * @action: a #GObject instance that implements AtkActionIface
188  * @i: the action index corresponding to the action to be performed
189  *
190  * Gets the keybinding which can be used to activate this action, if one
191  * exists. The string returned should contain localized, human-readable,
192  * key sequences as they would appear when displayed on screen. It must
193  * be in the format "mnemonic;sequence;shortcut".
194  *
195  * - The mnemonic key activates the object if it is presently enabled onscreen.
196  *   This typically corresponds to the underlined letter within the widget.
197  *   Example: "n" in a traditional "New..." menu item or the "a" in "Apply" for
198  *   a button.
199  * - The sequence is the full list of keys which invoke the action even if the
200  *   relevant element is not currently shown on screen. For instance, for a menu
201  *   item the sequence is the keybindings used to open the parent menus before
202  *   invoking. The sequence string is colon-delimited. Example: "Alt+F:N" in a
203  *   traditional "New..." menu item.
204  * - The shortcut, if it exists, will invoke the same action without showing
205  *   the component or its enclosing menus or dialogs. Example: "Ctrl+N" in a
206  *   traditional "New..." menu item.
207  *
208  * Example: For a traditional "New..." menu item, the expected return value
209  * would be: "N;Alt+F:N;Ctrl+N" for the English locale and "N;Alt+D:N;Strg+N"
210  * for the German locale. If, hypothetically, this menu item lacked a mnemonic,
211  * it would be represented by ";;Ctrl+N" and ";;Strg+N" respectively.
212  *
213  * Returns the keybinding which can be used to activate this action, or %NULL
214  * if there is no keybinding for this action.
215  *
216  **/
217 const gchar*
218 atk_action_get_keybinding (AtkAction *obj,
219                            gint      i)
220 {
221   AtkActionIface *iface;
222
223   g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
224
225   iface = ATK_ACTION_GET_IFACE (obj);
226
227   if (iface->get_keybinding)
228     return (iface->get_keybinding) (obj, i);
229   else
230     return NULL;
231 }
232
233 /**
234  * atk_action_set_description:
235  * @action: a #GObject instance that implements AtkActionIface
236  * @i: the action index corresponding to the action to be performed 
237  * @desc: the description to be assigned to this action
238  *
239  * Sets a description of the specified action of the object.
240  *
241  * Returns: a gboolean representing if the description was successfully set;
242  **/
243 gboolean
244 atk_action_set_description (AtkAction   *obj,
245                             gint        i,
246                             const gchar *desc)
247 {
248   AtkActionIface *iface;
249
250   g_return_val_if_fail (ATK_IS_ACTION (obj), FALSE);
251
252   iface = ATK_ACTION_GET_IFACE (obj);
253
254   if (iface->set_description)
255     return (iface->set_description) (obj, i, desc);
256   else
257     return FALSE;
258 }