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