Imported version 2.7.91
[platform/core/uifw/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 gchar *
57 atspi_action_get_description (AtspiAction *obj, int i, GError **error)
58 {
59   dbus_int32_t d_i = i;
60   char *retval = NULL;
61
62   g_return_val_if_fail (obj != NULL, NULL);
63
64   _atspi_dbus_call (obj, atspi_interface_action, "GetDescription", error, "i=>s", d_i, &retval);
65
66   return retval;
67 }
68
69 /**
70  * atspi_action_get_key_binding:
71  * @obj: a pointer to the #AtspiAction implementor to query.
72  * @i: an integer indicating which action to query.
73  *
74  * Get the keybindings for the @i-th action invocable on an
75  *      object implementing #AtspiAction, if any are defined.
76  *      The keybindings string format is as follows:
77  *        there are multiple parts to a keybinding string (typically 3).
78  *        They are delimited with ";".  The first is the action's
79  *        keybinding which is usable if the object implementing the action
80  *        is currently posted to the screen, e.g. if a menu is posted 
81  *        then these keybindings for the corresponding menu-items are
82  *        available.  The second keybinding substring is the full key sequence
83  *        necessary to post the action's widget and activate it, e.g. for
84  *        a menu item such as "File->Open" it would both post the menu and
85  *        activate the item.  Thus the second keybinding string is available
86  *        during the lifetime of the containing toplevel window as a whole,
87  *        whereas the first keybinding string only works while the object
88  *        implementing AtkAction is posted.  The third (and optional)
89  *        keybinding string is the "keyboard shortcut" which invokes the 
90  *        action without posting any menus. 
91  *        Meta-keys are indicated by the conventional strings
92  *        "<Control>", "<Alt>", "<Shift>", "<Mod2>",
93  *        etc. (we use the same string as gtk_accelerator_name() in 
94  *        gtk+-2.X.
95  *
96  * Returns: a UTF-8 string which can be parsed to determine the @i-th
97  *       invocable action's keybindings.
98  **/
99 gchar *
100 atspi_action_get_key_binding (AtspiAction *obj, gint i, GError **error)
101 {
102   dbus_int32_t d_i = i;
103   char *retval = NULL;
104
105   g_return_val_if_fail (obj != NULL, NULL);
106
107   _atspi_dbus_call (obj, atspi_interface_action, "GetKeyBinding", error, "i=>s", d_i, &retval);
108
109   return retval;
110 }
111
112 /**
113  * atspi_action_get_name:
114  * @obj: a pointer to the #AtspiAction implementor to query.
115  * @i: an integer indicating which action to query.
116  *
117  * Get the name of the '@i-th' action invocable on an
118  *      object implementing #AtspiAction.
119  *
120  * Returns: the non-localized name of the action, as a UTF-8 string.
121  **/
122 gchar *
123 atspi_action_get_name (AtspiAction *obj, gint i, GError **error)
124 {
125   dbus_int32_t d_i = i;
126   char *retval = NULL;
127
128   g_return_val_if_fail (obj != NULL, NULL);
129
130   _atspi_dbus_call (obj, atspi_interface_action, "GetName", error, "i=>s", d_i, &retval);
131
132   return retval;
133 }
134
135 /**
136  * atspi_action_get_localized_name:
137  * @obj: a pointer to the #AtspiAction implementor to query.
138  * @i: an integer indicating which action to query.
139  *
140  * Get the name of the '@i-th' action invocable on an
141  *      object implementing #AtspiAction.
142  *
143  * Returns: the name of the action, as a UTF-8 string.
144  **/
145 gchar *
146 atspi_action_get_localized_name (AtspiAction *obj, gint i, GError **error)
147 {
148   dbus_int32_t d_i = i;
149   char *retval = NULL;
150
151   g_return_val_if_fail (obj != NULL, NULL);
152
153   _atspi_dbus_call (obj, atspi_interface_action, "GetLocalizedName", error,
154                     "i=>s", d_i, &retval);
155
156   return retval;
157 }
158
159 /**
160  * atspi_action_do_action:
161  * @obj: a pointer to the #AtspiAction to query.
162  * @i: an integer specifying which action to invoke.
163  *
164  * Invoke the action indicated by #index.
165  *
166  * Returns: #TRUE if the action is successfully invoked, otherwise #FALSE.
167  **/
168 gboolean
169 atspi_action_do_action (AtspiAction *obj, gint i, GError **error)
170 {
171   dbus_int32_t d_i = i;
172   dbus_bool_t retval = FALSE;
173
174   g_return_val_if_fail (obj != NULL, FALSE);
175
176   _atspi_dbus_call (obj, atspi_interface_action, "DoAction", error, "i=>b", d_i, &retval);
177
178   return retval;
179 }
180
181 static void
182 atspi_action_base_init (AtspiAction *klass)
183 {
184 }
185
186 GType
187 atspi_action_get_type (void)
188 {
189   static GType type = 0;
190
191   if (!type) {
192     static const GTypeInfo tinfo =
193     {
194       sizeof (AtspiAction),
195       (GBaseInitFunc) atspi_action_base_init,
196       (GBaseFinalizeFunc) NULL,
197     };
198
199     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiAction", &tinfo, 0);
200
201   }
202   return type;
203 }