2002-03-27 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / libspi / 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 Sun Microsystems Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /* component.c : bonobo wrapper for accessible component implementation */
24
25 #include <config.h>
26 #include <stdio.h>
27 #include <libspi/action.h>
28 #include <atk/atkaction.h>
29
30 /*
31  * Static function declarations
32  */
33
34 static void
35 spi_action_class_init (SpiActionClass *klass);
36 static void
37 spi_action_init (SpiAction *action);
38 static CORBA_long
39 impl__get_nActions(PortableServer_Servant servant,
40                  CORBA_Environment * ev);
41 static CORBA_string
42 impl_getDescription (PortableServer_Servant servant,
43                      const CORBA_long index,
44                      CORBA_Environment * ev);
45 static CORBA_boolean 
46 impl_doAction (PortableServer_Servant servant,
47                const CORBA_long index, CORBA_Environment * ev);
48 static CORBA_string
49 impl_getName (PortableServer_Servant servant,
50               const CORBA_long index,
51               CORBA_Environment * ev);
52 static CORBA_string
53 impl_getKeyBinding (PortableServer_Servant servant,
54                     const CORBA_long index,
55                     CORBA_Environment * ev);
56
57 BONOBO_TYPE_FUNC_FULL (SpiAction,
58                        Accessibility_Action,
59                        SPI_TYPE_BASE,
60                        spi_action);
61
62 static void
63 spi_action_class_init (SpiActionClass *klass)
64 {
65   POA_Accessibility_Action__epv *epv = &klass->epv;
66
67   /* Initialize epv table */
68
69   epv->_get_nActions = impl__get_nActions;
70   epv->doAction = impl_doAction;
71   epv->getDescription = impl_getDescription;
72   epv->getName = impl_getName;
73   epv->getKeyBinding = impl_getKeyBinding;
74 }
75
76 static void
77 spi_action_init (SpiAction *action)
78 {
79 }
80
81 SpiAction *
82 spi_action_interface_new (AtkObject *obj)
83 {
84   SpiAction *new_action = g_object_new (SPI_ACTION_TYPE, NULL);
85
86   spi_base_construct (SPI_BASE (new_action), G_OBJECT(obj));
87
88   return new_action;
89 }
90
91 static AtkAction *
92 get_action_from_servant (PortableServer_Servant servant)
93 {
94   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
95   g_return_val_if_fail (object != NULL, NULL);
96   g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
97   return ATK_ACTION (object->gobj);
98 }
99
100 static CORBA_long
101 impl__get_nActions (PortableServer_Servant servant,
102                     CORBA_Environment     *ev)
103 {
104   AtkAction *action = get_action_from_servant (servant);
105   return (CORBA_long) atk_action_get_n_actions (action);
106 }
107
108 static CORBA_boolean
109 impl_doAction (PortableServer_Servant servant,
110                const CORBA_long index, CORBA_Environment * ev)
111 {
112   AtkAction *action = get_action_from_servant (servant);
113   return (CORBA_boolean) atk_action_do_action (action, (gint) index);
114 }
115
116 static CORBA_string
117 impl_getDescription (PortableServer_Servant servant,
118                 const CORBA_long index,
119                 CORBA_Environment * ev)
120 {
121   AtkAction *action = get_action_from_servant (servant);
122   const gchar *rv;
123   
124   rv = atk_action_get_description (action, (gint) index);
125   if (rv)
126     return CORBA_string_dup (rv);
127   else
128     return CORBA_string_dup ("");
129 }
130
131 static CORBA_string
132 impl_getName (PortableServer_Servant servant,
133                 const CORBA_long index,
134                 CORBA_Environment * ev)
135 {
136   AtkAction *action = get_action_from_servant (servant);
137   const gchar *rv;
138   
139   rv = atk_action_get_name (action, (gint) index);
140   if (rv)
141     return CORBA_string_dup (rv);
142   else
143     return CORBA_string_dup ("");
144 }
145
146 static CORBA_string
147 impl_getKeyBinding (PortableServer_Servant servant,
148                     const CORBA_long index,
149                     CORBA_Environment * ev)
150 {
151   AtkAction *action = get_action_from_servant (servant);
152   const gchar *rv;
153   
154   rv = atk_action_get_keybinding (action, (gint) index);
155   if (rv)
156     return CORBA_string_dup (rv);
157   else
158     return CORBA_string_dup ("");
159 }