atktext: Fixing some typos on atk_text_get_text_at_offset deprecation
[atk.git] / atk / atkaction.c
blob089a2fd0a2be01d83b34d53e5ebbedacced30a77
1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
20 #include "atkaction.h"
22 /**
23 * SECTION:atkaction
24 * @Short_description: The ATK interface provided by UI components
25 * which the user can activate/interact with.
26 * @Title:AtkAction
28 * #AtkAction should be implemented by instances of #AtkObject classes
29 * with which the user can interact directly, i.e. buttons,
30 * checkboxes, scrollbars, e.g. components which are not "passive"
31 * providers of UI information.
33 * Exceptions: when the user interaction is already covered by another
34 * appropriate interface such as #AtkEditableText (insert/delete text,
35 * etc.) or #AtkValue (set value) then these actions should not be
36 * exposed by #AtkAction as well.
38 * Though most UI interactions on components should be invocable via
39 * keyboard as well as mouse, there will generally be a close mapping
40 * between "mouse actions" that are possible on a component and the
41 * AtkActions. Where mouse and keyboard actions are redundant in
42 * effect, #AtkAction should expose only one action rather than
43 * exposing redundant actions if possible. By convention we have been
44 * using "mouse centric" terminology for #AtkAction names.
48 GType
49 atk_action_get_type (void)
51 static GType type = 0;
53 if (!type) {
54 GTypeInfo tinfo =
56 sizeof (AtkActionIface),
57 (GBaseInitFunc) NULL,
58 (GBaseFinalizeFunc) NULL,
62 type = g_type_register_static (G_TYPE_INTERFACE, "AtkAction", &tinfo, 0);
65 return type;
68 /**
69 * atk_action_do_action:
70 * @action: a #GObject instance that implements AtkActionIface
71 * @i: the action index corresponding to the action to be performed
73 * Perform the specified action on the object.
75 * Returns: %TRUE if success, %FALSE otherwise
77 **/
78 gboolean
79 atk_action_do_action (AtkAction *obj,
80 gint i)
82 AtkActionIface *iface;
84 g_return_val_if_fail (ATK_IS_ACTION (obj), FALSE);
86 iface = ATK_ACTION_GET_IFACE (obj);
88 if (iface->do_action)
89 return (iface->do_action) (obj, i);
90 else
91 return FALSE;
94 /**
95 * atk_action_get_n_actions:
96 * @action: a #GObject instance that implements AtkActionIface
98 * Gets the number of accessible actions available on the object.
99 * If there are more than one, the first one is considered the
100 * "default" action of the object.
102 * Returns: a the number of actions, or 0 if @action does not
103 * implement this interface.
105 gint
106 atk_action_get_n_actions (AtkAction *obj)
108 AtkActionIface *iface;
110 g_return_val_if_fail (ATK_IS_ACTION (obj), 0);
112 iface = ATK_ACTION_GET_IFACE (obj);
114 if (iface->get_n_actions)
115 return (iface->get_n_actions) (obj);
116 else
117 return 0;
121 * atk_action_get_description:
122 * @action: a #GObject instance that implements AtkActionIface
123 * @i: the action index corresponding to the action to be performed
125 * Returns a description of the specified action of the object.
127 * Returns: a description string, or %NULL if @action does not
128 * implement this interface.
130 const gchar*
131 atk_action_get_description (AtkAction *obj,
132 gint i)
134 AtkActionIface *iface;
136 g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
138 iface = ATK_ACTION_GET_IFACE (obj);
140 if (iface->get_description)
141 return (iface->get_description) (obj, i);
142 else
143 return NULL;
147 * atk_action_get_name:
148 * @action: a #GObject instance that implements AtkActionIface
149 * @i: the action index corresponding to the action to be performed
151 * Returns a non-localized string naming the specified action of the
152 * object. This name is generally not descriptive of the end result
153 * of the action, but instead names the 'interaction type' which the
154 * object supports. By convention, the above strings should be used to
155 * represent the actions which correspond to the common point-and-click
156 * interaction techniques of the same name: i.e.
157 * "click", "press", "release", "drag", "drop", "popup", etc.
158 * The "popup" action should be used to pop up a context menu for the
159 * object, if one exists.
161 * For technical reasons, some toolkits cannot guarantee that the
162 * reported action is actually 'bound' to a nontrivial user event;
163 * i.e. the result of some actions via atk_action_do_action() may be
164 * NIL.
166 * Returns: a name string, or %NULL if @action does not implement this
167 * interface.
169 const gchar*
170 atk_action_get_name (AtkAction *obj,
171 gint i)
173 AtkActionIface *iface;
175 g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
177 iface = ATK_ACTION_GET_IFACE (obj);
179 if (iface->get_name)
180 return (iface->get_name) (obj, i);
181 else
182 return NULL;
186 * atk_action_get_localized_name:
187 * @action: a #GObject instance that implements AtkActionIface
188 * @i: the action index corresponding to the action to be performed
190 * Returns the localized name of the specified action of the object.
192 * Returns: a name string, or %NULL if @action does not implement this
193 * interface.
195 const gchar*
196 atk_action_get_localized_name (AtkAction *obj,
197 gint i)
199 AtkActionIface *iface;
201 g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
203 iface = ATK_ACTION_GET_IFACE (obj);
205 if (iface->get_localized_name)
206 return (iface->get_localized_name) (obj, i);
207 else
208 return NULL;
212 * atk_action_get_keybinding:
213 * @action: a #GObject instance that implements AtkActionIface
214 * @i: the action index corresponding to the action to be performed
216 * Gets the keybinding which can be used to activate this action, if one
217 * exists. The string returned should contain localized, human-readable,
218 * key sequences as they would appear when displayed on screen. It must
219 * be in the format "mnemonic;sequence;shortcut".
221 * - The mnemonic key activates the object if it is presently enabled onscreen.
222 * This typically corresponds to the underlined letter within the widget.
223 * Example: "n" in a traditional "New..." menu item or the "a" in "Apply" for
224 * a button.
225 * - The sequence is the full list of keys which invoke the action even if the
226 * relevant element is not currently shown on screen. For instance, for a menu
227 * item the sequence is the keybindings used to open the parent menus before
228 * invoking. The sequence string is colon-delimited. Example: "Alt+F:N" in a
229 * traditional "New..." menu item.
230 * - The shortcut, if it exists, will invoke the same action without showing
231 * the component or its enclosing menus or dialogs. Example: "Ctrl+N" in a
232 * traditional "New..." menu item.
234 * Example: For a traditional "New..." menu item, the expected return value
235 * would be: "N;Alt+F:N;Ctrl+N" for the English locale and "N;Alt+D:N;Strg+N"
236 * for the German locale. If, hypothetically, this menu item lacked a mnemonic,
237 * it would be represented by ";;Ctrl+N" and ";;Strg+N" respectively.
239 * Returns: the keybinding which can be used to activate this action,
240 * or %NULL if there is no keybinding for this action.
243 const gchar*
244 atk_action_get_keybinding (AtkAction *obj,
245 gint i)
247 AtkActionIface *iface;
249 g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
251 iface = ATK_ACTION_GET_IFACE (obj);
253 if (iface->get_keybinding)
254 return (iface->get_keybinding) (obj, i);
255 else
256 return NULL;
260 * atk_action_set_description:
261 * @action: a #GObject instance that implements AtkActionIface
262 * @i: the action index corresponding to the action to be performed
263 * @desc: the description to be assigned to this action
265 * Sets a description of the specified action of the object.
267 * Returns: a gboolean representing if the description was successfully set;
269 gboolean
270 atk_action_set_description (AtkAction *obj,
271 gint i,
272 const gchar *desc)
274 AtkActionIface *iface;
276 g_return_val_if_fail (ATK_IS_ACTION (obj), FALSE);
278 iface = ATK_ACTION_GET_IFACE (obj);
280 if (iface->set_description)
281 return (iface->set_description) (obj, i, desc);
282 else
283 return FALSE;