2001-11-19 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 /*
24  * component.c : bonobo wrapper for accessible component implementation
25  *
26  */
27 #include <config.h>
28 #include <bonobo/Bonobo.h>
29
30 #include <stdio.h>
31
32 /*
33  * This pulls the CORBA definitions for the "Accessibility::Accessible" server
34  */
35 #include <libspi/Accessibility.h>
36
37 /*
38  * This pulls the definition of the SpiAction bonobo object
39  */
40 #include "action.h"
41
42 /*
43  * Static function declarations
44  */
45
46 static void
47 spi_action_class_init (SpiActionClass *klass);
48 static void
49 spi_action_init (SpiAction *action);
50 static void
51 spi_action_finalize (GObject *obj);
52 static CORBA_long
53 impl__get_nActions(PortableServer_Servant servant,
54                  CORBA_Environment * ev);
55 static CORBA_string
56 impl_getDescription (PortableServer_Servant servant,
57                      const CORBA_long index,
58                      CORBA_Environment * ev);
59 static CORBA_boolean 
60 impl_doAction (PortableServer_Servant servant,
61                const CORBA_long index, CORBA_Environment * ev);
62 static CORBA_string
63 impl_getName (PortableServer_Servant servant,
64               const CORBA_long index,
65               CORBA_Environment * ev);
66 static CORBA_string
67 impl_getKeyBinding (PortableServer_Servant servant,
68                     const CORBA_long index,
69                     CORBA_Environment * ev);
70
71 static GObjectClass *parent_class;
72
73 BONOBO_TYPE_FUNC_FULL (SpiAction,
74                        Accessibility_Action,
75                        BONOBO_OBJECT_TYPE,
76                        spi_action);
77
78 static void
79 spi_action_class_init (SpiActionClass *klass)
80 {
81   GObjectClass * object_class = (GObjectClass *) klass;
82   POA_Accessibility_Action__epv *epv = &klass->epv;
83   parent_class = g_type_class_peek_parent (klass);
84
85   object_class->finalize = spi_action_finalize;
86
87
88   /* Initialize epv table */
89
90   epv->_get_nActions = impl__get_nActions;
91   epv->doAction = impl_doAction;
92   epv->getDescription = impl_getDescription;
93   epv->getName = impl_getName;
94   epv->getKeyBinding = impl_getKeyBinding;
95 }
96
97 static void
98 spi_action_init (SpiAction *action)
99 {
100 }
101
102 static void
103 spi_action_finalize (GObject *obj)
104 {
105   SpiAction *action = SPI_ACTION (obj);
106   g_object_unref (action->atko);
107   action->atko = NULL;
108   parent_class->finalize (obj);
109 }
110
111 SpiAction *
112 spi_action_interface_new (AtkObject *obj)
113 {
114   SpiAction *new_action = 
115     SPI_ACTION(g_object_new (SPI_ACTION_TYPE, NULL));
116   new_action->atko = obj;
117   g_object_ref (obj);
118   return new_action;
119 }
120
121 static CORBA_long
122 impl__get_nActions(PortableServer_Servant servant,
123             CORBA_Environment * ev)
124 {
125   SpiAction *action = SPI_ACTION (bonobo_object_from_servant(servant));
126   return (CORBA_long) atk_action_get_n_actions (ATK_ACTION(action->atko));
127 }
128
129 static CORBA_boolean
130 impl_doAction (PortableServer_Servant servant,
131                const CORBA_long index, CORBA_Environment * ev)
132 {
133   SpiAction *action = SPI_ACTION (bonobo_object_from_servant (servant));
134   return (CORBA_boolean) atk_action_do_action (ATK_ACTION(action->atko), (gint) index);
135 }
136
137
138 static CORBA_string
139 impl_getDescription (PortableServer_Servant servant,
140                 const CORBA_long index,
141                 CORBA_Environment * ev)
142 {
143   SpiAction *action = SPI_ACTION (bonobo_object_from_servant(servant));
144   const gchar *rv;
145   
146   rv = atk_action_get_description (ATK_ACTION(action->atko), (gint) index);
147   if (rv)
148     return CORBA_string_dup (rv);
149   else
150     return CORBA_string_dup ("");
151 }
152
153
154 static CORBA_string
155 impl_getName (PortableServer_Servant servant,
156                 const CORBA_long index,
157                 CORBA_Environment * ev)
158 {
159   SpiAction *action = SPI_ACTION (bonobo_object_from_servant(servant));
160   const gchar *rv;
161   
162   rv = atk_action_get_name (ATK_ACTION(action->atko), (gint) index);
163   if (rv)
164     return CORBA_string_dup (rv);
165   else
166     return CORBA_string_dup ("");
167 }
168
169 static CORBA_string
170 impl_getKeyBinding (PortableServer_Servant servant,
171                     const CORBA_long index,
172                     CORBA_Environment * ev)
173 {
174   SpiAction *action = SPI_ACTION (bonobo_object_from_servant(servant));
175   const gchar *rv;
176   
177   rv = atk_action_get_keybinding (ATK_ACTION(action->atko), (gint) index);
178   if (rv)
179     return CORBA_string_dup (rv);
180   else
181     return CORBA_string_dup ("");
182 }