2001-12-10 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), 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 (servant);
95   return ATK_ACTION (object->atko);
96 }
97
98 static CORBA_long
99 impl__get_nActions (PortableServer_Servant servant,
100                     CORBA_Environment     *ev)
101 {
102   AtkAction *action = get_action_from_servant (servant);
103   return (CORBA_long) atk_action_get_n_actions (action);
104 }
105
106 static CORBA_boolean
107 impl_doAction (PortableServer_Servant servant,
108                const CORBA_long index, CORBA_Environment * ev)
109 {
110   AtkAction *action = get_action_from_servant (servant);
111   return (CORBA_boolean) atk_action_do_action (action, (gint) index);
112 }
113
114 static CORBA_string
115 impl_getDescription (PortableServer_Servant servant,
116                 const CORBA_long index,
117                 CORBA_Environment * ev)
118 {
119   AtkAction *action = get_action_from_servant (servant);
120   const gchar *rv;
121   
122   rv = atk_action_get_description (action, (gint) index);
123   if (rv)
124     return CORBA_string_dup (rv);
125   else
126     return CORBA_string_dup ("");
127 }
128
129 static CORBA_string
130 impl_getName (PortableServer_Servant servant,
131                 const CORBA_long index,
132                 CORBA_Environment * ev)
133 {
134   AtkAction *action = get_action_from_servant (servant);
135   const gchar *rv;
136   
137   rv = atk_action_get_name (action, (gint) index);
138   if (rv)
139     return CORBA_string_dup (rv);
140   else
141     return CORBA_string_dup ("");
142 }
143
144 static CORBA_string
145 impl_getKeyBinding (PortableServer_Servant servant,
146                     const CORBA_long index,
147                     CORBA_Environment * ev)
148 {
149   AtkAction *action = get_action_from_servant (servant);
150   const gchar *rv;
151   
152   rv = atk_action_get_keybinding (action, (gint) index);
153   if (rv)
154     return CORBA_string_dup (rv);
155   else
156     return CORBA_string_dup ("");
157 }