2.34.0
[platform/upstream/at-spi2-core.git] / atspi / atspi-action.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 #include "atspi-private.h"
25
26 /**
27  * atspi_action_get_n_actions:
28  * @obj: a pointer to the #AtspiAction to query.
29  *
30  * Get the number of actions invokable on an #AtspiAction implementor.
31  *
32  * Returns: an integer indicating the number of invocable actions.
33  **/
34 gint
35 atspi_action_get_n_actions (AtspiAction *obj, GError **error)
36 {
37   dbus_int32_t retval = 0;
38
39   g_return_val_if_fail (obj != NULL, -1);
40
41   _atspi_dbus_get_property (obj, atspi_interface_action, "NActions", error, "i", &retval);
42
43   return retval;
44 }
45
46 /**
47  * atspi_action_get_description: (rename-to atspi_action_get_action_description)
48  * @obj: a pointer to the #AtspiAction implementor to query.
49  * @i: an integer indicating which action to query.
50  *
51  * Get the description of '@i-th' action invocable on an
52  *      object implementing #AtspiAction.
53  *
54  * Returns: a UTF-8 string describing the '@i-th' invocable action.
55  *
56  * Deprecated: 2.10: Use atspi_action_get_action_description instead.
57  **/
58 gchar *
59 atspi_action_get_description (AtspiAction *obj, int i, GError **error)
60 {
61   return atspi_action_get_action_description (obj, i, error);
62 }
63
64 /**
65  * atspi_action_get_action_description:
66  * @obj: a pointer to the #AtspiAction implementor to query.
67  * @i: an integer indicating which action to query.
68  *
69  * Get the description of '@i-th' action invocable on an
70  *      object implementing #AtspiAction.
71  *
72  * Returns: a UTF-8 string describing the '@i-th' invocable action.
73  **/
74 gchar *
75 atspi_action_get_action_description (AtspiAction *obj, int i, GError **error)
76 {
77   dbus_int32_t d_i = i;
78   char *retval = NULL;
79
80   g_return_val_if_fail (obj != NULL, NULL);
81
82   _atspi_dbus_call (obj, atspi_interface_action, "GetDescription", error, "i=>s", d_i, &retval);
83
84   return retval;
85 }
86
87 /**
88  * atspi_action_get_key_binding:
89  * @obj: a pointer to the #AtspiAction implementor to query.
90  * @i: an integer indicating which action to query.
91  *
92  * Get the keybindings for the @i-th action invocable on an
93  *      object implementing #AtspiAction, if any are defined.
94  *      The keybindings string format is as follows:
95  *        there are multiple parts to a keybinding string (typically 3).
96  *        They are delimited with ";".  The first is the action's
97  *        keybinding which is usable if the object implementing the action
98  *        is currently posted to the screen, e.g. if a menu is posted 
99  *        then these keybindings for the corresponding menu-items are
100  *        available.  The second keybinding substring is the full key sequence
101  *        necessary to post the action's widget and activate it, e.g. for
102  *        a menu item such as "File->Open" it would both post the menu and
103  *        activate the item.  Thus the second keybinding string is available
104  *        during the lifetime of the containing toplevel window as a whole,
105  *        whereas the first keybinding string only works while the object
106  *        implementing AtkAction is posted.  The third (and optional)
107  *        keybinding string is the "keyboard shortcut" which invokes the 
108  *        action without posting any menus. 
109  *        Meta-keys are indicated by the conventional strings
110  *        "<Control>", "<Alt>", "<Shift>", "<Mod2>",
111  *        etc. (we use the same string as gtk_accelerator_name() in 
112  *        gtk+-2.X.
113  *
114  * Returns: a UTF-8 string which can be parsed to determine the @i-th
115  *       invocable action's keybindings.
116  **/
117 gchar *
118 atspi_action_get_key_binding (AtspiAction *obj, gint i, GError **error)
119 {
120   dbus_int32_t d_i = i;
121   char *retval = NULL;
122
123   g_return_val_if_fail (obj != NULL, NULL);
124
125   _atspi_dbus_call (obj, atspi_interface_action, "GetKeyBinding", error, "i=>s", d_i, &retval);
126
127   return retval;
128 }
129
130 /**
131  * atspi_action_get_name: (rename-to atspi_action_get_action_name)
132  * @obj: a pointer to the #AtspiAction implementor to query.
133  * @i: an integer indicating which action to query.
134  *
135  * Get the name of the '@i-th' action invocable on an
136  *      object implementing #AtspiAction.
137  *
138  * Returns: the non-localized name of the action, as a UTF-8 string.
139  *
140  * Deprecated: 2.10: Use atspi_action_get_action_name instead.
141  **/
142 gchar *
143 atspi_action_get_name (AtspiAction *obj, gint i, GError **error)
144 {
145   return atspi_action_get_action_name (obj, i, error);
146 }
147
148 /**
149  * atspi_action_get_action_name:
150  * @obj: a pointer to the #AtspiAction implementor to query.
151  * @i: an integer indicating which action to query.
152  *
153  * Get the name of the '@i-th' action invocable on an
154  *      object implementing #AtspiAction.
155  *
156  * Returns: the non-localized name of the action, as a UTF-8 string.
157  **/
158 gchar *
159 atspi_action_get_action_name (AtspiAction *obj, gint i, GError **error)
160 {
161   dbus_int32_t d_i = i;
162   char *retval = NULL;
163
164   g_return_val_if_fail (obj != NULL, NULL);
165
166   _atspi_dbus_call (obj, atspi_interface_action, "GetName", error, "i=>s", d_i, &retval);
167
168   return retval;
169 }
170
171 /**
172  * atspi_action_get_localized_name:
173  * @obj: a pointer to the #AtspiAction implementor to query.
174  * @i: an integer indicating which action to query.
175  *
176  * Get the name of the '@i-th' action invocable on an
177  *      object implementing #AtspiAction.
178  *
179  * Returns: the name of the action, as a UTF-8 string.
180  **/
181 gchar *
182 atspi_action_get_localized_name (AtspiAction *obj, gint i, GError **error)
183 {
184   dbus_int32_t d_i = i;
185   char *retval = NULL;
186
187   g_return_val_if_fail (obj != NULL, NULL);
188
189   _atspi_dbus_call (obj, atspi_interface_action, "GetLocalizedName", error,
190                     "i=>s", d_i, &retval);
191
192   return retval;
193 }
194
195 /**
196  * atspi_action_do_action:
197  * @obj: a pointer to the #AtspiAction to query.
198  * @i: an integer specifying which action to invoke.
199  *
200  * Invoke the action indicated by #index.
201  *
202  * Returns: #TRUE if the action is successfully invoked, otherwise #FALSE.
203  **/
204 gboolean
205 atspi_action_do_action (AtspiAction *obj, gint i, GError **error)
206 {
207   dbus_int32_t d_i = i;
208   dbus_bool_t retval = FALSE;
209
210   g_return_val_if_fail (obj != NULL, FALSE);
211
212   _atspi_dbus_call (obj, atspi_interface_action, "DoAction", error, "i=>b", d_i, &retval);
213
214   return retval;
215 }
216
217 static void
218 atspi_action_base_init (AtspiAction *klass)
219 {
220 }
221
222 GType
223 atspi_action_get_type (void)
224 {
225   static GType type = 0;
226
227   if (!type) {
228     static const GTypeInfo tinfo =
229     {
230       sizeof (AtspiAction),
231       (GBaseInitFunc) atspi_action_base_init,
232       (GBaseFinalizeFunc) NULL,
233     };
234
235     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiAction", &tinfo, 0);
236
237   }
238   return type;
239 }