misc: set proper file permissions to source files
[atk.git] / atk / atkaction.c
blobbc12cb23cc145ad35dae12a4de5660eb20f081ca
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 "config.h"
22 #include "atkaction.h"
24 /**
25 * SECTION:atkaction
26 * @Short_description: The ATK interface provided by UI components
27 * which the user can activate/interact with.
28 * @Title:AtkAction
30 * #AtkAction should be implemented by instances of #AtkObject classes
31 * with which the user can interact directly, i.e. buttons,
32 * checkboxes, scrollbars, e.g. components which are not "passive"
33 * providers of UI information.
35 * Exceptions: when the user interaction is already covered by another
36 * appropriate interface such as #AtkEditableText (insert/delete text,
37 * etc.) or #AtkValue (set value) then these actions should not be
38 * exposed by #AtkAction as well.
40 * Though most UI interactions on components should be invocable via
41 * keyboard as well as mouse, there will generally be a close mapping
42 * between "mouse actions" that are possible on a component and the
43 * AtkActions. Where mouse and keyboard actions are redundant in
44 * effect, #AtkAction should expose only one action rather than
45 * exposing redundant actions if possible. By convention we have been
46 * using "mouse centric" terminology for #AtkAction names.
50 GType
51 atk_action_get_type (void)
53 static GType type = 0;
55 if (!type) {
56 GTypeInfo tinfo =
58 sizeof (AtkActionIface),
59 (GBaseInitFunc) NULL,
60 (GBaseFinalizeFunc) NULL,
64 type = g_type_register_static (G_TYPE_INTERFACE, "AtkAction", &tinfo, 0);
67 return type;
70 /**
71 * atk_action_do_action:
72 * @action: a #GObject instance that implements AtkActionIface
73 * @i: the action index corresponding to the action to be performed
75 * Perform the specified action on the object.
77 * Returns: %TRUE if success, %FALSE otherwise
79 **/
80 gboolean
81 atk_action_do_action (AtkAction *obj,
82 gint i)
84 AtkActionIface *iface;
86 g_return_val_if_fail (ATK_IS_ACTION (obj), FALSE);
88 iface = ATK_ACTION_GET_IFACE (obj);
90 if (iface->do_action)
91 return (iface->do_action) (obj, i);
92 else
93 return FALSE;
96 /**
97 * atk_action_get_n_actions:
98 * @action: a #GObject instance that implements AtkActionIface
100 * Gets the number of accessible actions available on the object.
101 * If there are more than one, the first one is considered the
102 * "default" action of the object.
104 * Returns: a the number of actions, or 0 if @action does not
105 * implement this interface.
107 gint
108 atk_action_get_n_actions (AtkAction *obj)
110 AtkActionIface *iface;
112 g_return_val_if_fail (ATK_IS_ACTION (obj), 0);
114 iface = ATK_ACTION_GET_IFACE (obj);
116 if (iface->get_n_actions)
117 return (iface->get_n_actions) (obj);
118 else
119 return 0;
123 * atk_action_get_description:
124 * @action: a #GObject instance that implements AtkActionIface
125 * @i: the action index corresponding to the action to be performed
127 * Returns a description of the specified action of the object.
129 * Returns: (nullable): a description string, or %NULL if @action does
130 * not implement this interface.
132 const gchar*
133 atk_action_get_description (AtkAction *obj,
134 gint i)
136 AtkActionIface *iface;
138 g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
140 iface = ATK_ACTION_GET_IFACE (obj);
142 if (iface->get_description)
143 return (iface->get_description) (obj, i);
144 else
145 return NULL;
149 * atk_action_get_name:
150 * @action: a #GObject instance that implements AtkActionIface
151 * @i: the action index corresponding to the action to be performed
153 * Returns a non-localized string naming the specified action of the
154 * object. This name is generally not descriptive of the end result
155 * of the action, but instead names the 'interaction type' which the
156 * object supports. By convention, the above strings should be used to
157 * represent the actions which correspond to the common point-and-click
158 * interaction techniques of the same name: i.e.
159 * "click", "press", "release", "drag", "drop", "popup", etc.
160 * The "popup" action should be used to pop up a context menu for the
161 * object, if one exists.
163 * For technical reasons, some toolkits cannot guarantee that the
164 * reported action is actually 'bound' to a nontrivial user event;
165 * i.e. the result of some actions via atk_action_do_action() may be
166 * NIL.
168 * Returns: (nullable): a name string, or %NULL if @action does not
169 * implement this interface.
171 const gchar*
172 atk_action_get_name (AtkAction *obj,
173 gint i)
175 AtkActionIface *iface;
177 g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
179 iface = ATK_ACTION_GET_IFACE (obj);
181 if (iface->get_name)
182 return (iface->get_name) (obj, i);
183 else
184 return NULL;
188 * atk_action_get_localized_name:
189 * @action: a #GObject instance that implements AtkActionIface
190 * @i: the action index corresponding to the action to be performed
192 * Returns the localized name of the specified action of the object.
194 * Returns: (nullable): a name string, or %NULL if @action does not
195 * implement this interface.
197 const gchar*
198 atk_action_get_localized_name (AtkAction *obj,
199 gint i)
201 AtkActionIface *iface;
203 g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
205 iface = ATK_ACTION_GET_IFACE (obj);
207 if (iface->get_localized_name)
208 return (iface->get_localized_name) (obj, i);
209 else
210 return NULL;
214 * atk_action_get_keybinding:
215 * @action: a #GObject instance that implements AtkActionIface
216 * @i: the action index corresponding to the action to be performed
218 * Gets the keybinding which can be used to activate this action, if one
219 * exists. The string returned should contain localized, human-readable,
220 * key sequences as they would appear when displayed on screen. It must
221 * be in the format "mnemonic;sequence;shortcut".
223 * - The mnemonic key activates the object if it is presently enabled onscreen.
224 * This typically corresponds to the underlined letter within the widget.
225 * Example: "n" in a traditional "New..." menu item or the "a" in "Apply" for
226 * a button.
227 * - The sequence is the full list of keys which invoke the action even if the
228 * relevant element is not currently shown on screen. For instance, for a menu
229 * item the sequence is the keybindings used to open the parent menus before
230 * invoking. The sequence string is colon-delimited. Example: "Alt+F:N" in a
231 * traditional "New..." menu item.
232 * - The shortcut, if it exists, will invoke the same action without showing
233 * the component or its enclosing menus or dialogs. Example: "Ctrl+N" in a
234 * traditional "New..." menu item.
236 * Example: For a traditional "New..." menu item, the expected return value
237 * would be: "N;Alt+F:N;Ctrl+N" for the English locale and "N;Alt+D:N;Strg+N"
238 * for the German locale. If, hypothetically, this menu item lacked a mnemonic,
239 * it would be represented by ";;Ctrl+N" and ";;Strg+N" respectively.
241 * Returns: (nullable): the keybinding which can be used to activate
242 * this action, or %NULL if there is no keybinding for this action.
245 const gchar*
246 atk_action_get_keybinding (AtkAction *obj,
247 gint i)
249 AtkActionIface *iface;
251 g_return_val_if_fail (ATK_IS_ACTION (obj), NULL);
253 iface = ATK_ACTION_GET_IFACE (obj);
255 if (iface->get_keybinding)
256 return (iface->get_keybinding) (obj, i);
257 else
258 return NULL;
262 * atk_action_set_description:
263 * @action: a #GObject instance that implements AtkActionIface
264 * @i: the action index corresponding to the action to be performed
265 * @desc: the description to be assigned to this action
267 * Sets a description of the specified action of the object.
269 * Returns: a gboolean representing if the description was successfully set;
271 gboolean
272 atk_action_set_description (AtkAction *obj,
273 gint i,
274 const gchar *desc)
276 AtkActionIface *iface;
278 g_return_val_if_fail (ATK_IS_ACTION (obj), FALSE);
280 iface = ATK_ACTION_GET_IFACE (obj);
282 if (iface->set_description)
283 return (iface->set_description) (obj, i, desc);
284 else
285 return FALSE;