17b6302a139483f33be8793fa73f80ecd22abbb2
[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 Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 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  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, 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:
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  * Rename to: atspi_action_get_action_description
58  **/
59 gchar *
60 atspi_action_get_description (AtspiAction *obj, int i, GError **error)
61 {
62   return atspi_action_get_action_description (obj, i, error);
63 }
64
65 /**
66  * atspi_action_get_action_description:
67  * @obj: a pointer to the #AtspiAction implementor to query.
68  * @i: an integer indicating which action to query.
69  *
70  * Get the description of '@i-th' action invocable on an
71  *      object implementing #AtspiAction.
72  *
73  * Returns: a UTF-8 string describing the '@i-th' invocable action.
74  **/
75 gchar *
76 atspi_action_get_action_description (AtspiAction *obj, int i, GError **error)
77 {
78   dbus_int32_t d_i = i;
79   char *retval = NULL;
80
81   g_return_val_if_fail (obj != NULL, NULL);
82
83   _atspi_dbus_call (obj, atspi_interface_action, "GetDescription", error, "i=>s", d_i, &retval);
84
85   return retval;
86 }
87
88 /**
89  * atspi_action_get_key_binding:
90  * @obj: a pointer to the #AtspiAction implementor to query.
91  * @i: an integer indicating which action to query.
92  *
93  * Get the keybindings for the @i-th action invocable on an
94  *      object implementing #AtspiAction, if any are defined.
95  *      The keybindings string format is as follows:
96  *        there are multiple parts to a keybinding string (typically 3).
97  *        They are delimited with ";".  The first is the action's
98  *        keybinding which is usable if the object implementing the action
99  *        is currently posted to the screen, e.g. if a menu is posted 
100  *        then these keybindings for the corresponding menu-items are
101  *        available.  The second keybinding substring is the full key sequence
102  *        necessary to post the action's widget and activate it, e.g. for
103  *        a menu item such as "File->Open" it would both post the menu and
104  *        activate the item.  Thus the second keybinding string is available
105  *        during the lifetime of the containing toplevel window as a whole,
106  *        whereas the first keybinding string only works while the object
107  *        implementing AtkAction is posted.  The third (and optional)
108  *        keybinding string is the "keyboard shortcut" which invokes the 
109  *        action without posting any menus. 
110  *        Meta-keys are indicated by the conventional strings
111  *        "<Control>", "<Alt>", "<Shift>", "<Mod2>",
112  *        etc. (we use the same string as gtk_accelerator_name() in 
113  *        gtk+-2.X.
114  *
115  * Returns: a UTF-8 string which can be parsed to determine the @i-th
116  *       invocable action's keybindings.
117  **/
118 gchar *
119 atspi_action_get_key_binding (AtspiAction *obj, gint i, GError **error)
120 {
121   dbus_int32_t d_i = i;
122   char *retval = NULL;
123
124   g_return_val_if_fail (obj != NULL, NULL);
125
126   _atspi_dbus_call (obj, atspi_interface_action, "GetKeyBinding", error, "i=>s", d_i, &retval);
127
128   return retval;
129 }
130
131 /**
132  * atspi_action_get_name:
133  * @obj: a pointer to the #AtspiAction implementor to query.
134  * @i: an integer indicating which action to query.
135  *
136  * Get the name of the '@i-th' action invocable on an
137  *      object implementing #AtspiAction.
138  *
139  * Returns: the non-localized name of the action, as a UTF-8 string.
140  *
141  * Deprecated: 2.10: Use atspi_action_get_action_name instead.
142  * Rename to: atspi_action_get_action_name
143  **/
144 gchar *
145 atspi_action_get_name (AtspiAction *obj, gint i, GError **error)
146 {
147   return atspi_action_get_action_name (obj, i, error);
148 }
149
150 /**
151  * atspi_action_get_action_name:
152  * @obj: a pointer to the #AtspiAction implementor to query.
153  * @i: an integer indicating which action to query.
154  *
155  * Get the name of the '@i-th' action invocable on an
156  *      object implementing #AtspiAction.
157  *
158  * Returns: the non-localized name of the action, as a UTF-8 string.
159  **/
160 gchar *
161 atspi_action_get_action_name (AtspiAction *obj, gint i, GError **error)
162 {
163   dbus_int32_t d_i = i;
164   char *retval = NULL;
165
166   g_return_val_if_fail (obj != NULL, NULL);
167
168   _atspi_dbus_call (obj, atspi_interface_action, "GetName", error, "i=>s", d_i, &retval);
169
170   return retval;
171 }
172
173 /**
174  * atspi_action_get_localized_name:
175  * @obj: a pointer to the #AtspiAction implementor to query.
176  * @i: an integer indicating which action to query.
177  *
178  * Get the name of the '@i-th' action invocable on an
179  *      object implementing #AtspiAction.
180  *
181  * Returns: the name of the action, as a UTF-8 string.
182  **/
183 gchar *
184 atspi_action_get_localized_name (AtspiAction *obj, gint i, GError **error)
185 {
186   dbus_int32_t d_i = i;
187   char *retval = NULL;
188
189   g_return_val_if_fail (obj != NULL, NULL);
190
191   _atspi_dbus_call (obj, atspi_interface_action, "GetLocalizedName", error,
192                     "i=>s", d_i, &retval);
193
194   return retval;
195 }
196
197 /**
198  * atspi_action_do_action:
199  * @obj: a pointer to the #AtspiAction to query.
200  * @i: an integer specifying which action to invoke.
201  *
202  * Invoke the action indicated by #index.
203  *
204  * Returns: #TRUE if the action is successfully invoked, otherwise #FALSE.
205  **/
206 gboolean
207 atspi_action_do_action (AtspiAction *obj, gint i, GError **error)
208 {
209   dbus_int32_t d_i = i;
210   dbus_bool_t retval = FALSE;
211
212   g_return_val_if_fail (obj != NULL, FALSE);
213
214   _atspi_dbus_call (obj, atspi_interface_action, "DoAction", error, "i=>b", d_i, &retval);
215
216   return retval;
217 }
218
219 static void
220 atspi_action_base_init (AtspiAction *klass)
221 {
222 }
223
224 GType
225 atspi_action_get_type (void)
226 {
227   static GType type = 0;
228
229   if (!type) {
230     static const GTypeInfo tinfo =
231     {
232       sizeof (AtspiAction),
233       (GBaseInitFunc) atspi_action_base_init,
234       (GBaseFinalizeFunc) NULL,
235     };
236
237     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiAction", &tinfo, 0);
238
239   }
240   return type;
241 }