a3e0ddb8b690206a9bf315c3010eade464d5c106
[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 Action bonobo object
39  */
40 #include "action.h"
41
42 /*
43  * Static function declarations
44  */
45
46 static void
47 action_class_init (ActionClass *klass);
48 static void
49 action_init (Action *action);
50 static void
51 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 GType
74 action_get_type (void)
75 {
76   static GType type = 0;
77
78   if (!type) {
79     static const GTypeInfo tinfo = {
80       sizeof (ActionClass),
81       (GBaseInitFunc) NULL,
82       (GBaseFinalizeFunc) NULL,
83       (GClassInitFunc) action_class_init,
84       (GClassFinalizeFunc) NULL,
85       NULL, /* class data */
86       sizeof (Action),
87       0, /* n preallocs */
88       (GInstanceInitFunc) action_init,
89                         NULL /* value table */
90     };
91
92     /*
93      * Bonobo_type_unique auto-generates a load of
94      * CORBA structures for us. All derived types must
95      * use bonobo_type_unique.
96      */
97     type = bonobo_type_unique (
98                                BONOBO_OBJECT_TYPE,
99                                POA_Accessibility_Action__init,
100                                NULL,
101                                G_STRUCT_OFFSET (ActionClass, epv),
102                                &tinfo,
103                                "AccessibleAction");
104   }
105
106   return type;
107 }
108
109 static void
110 action_class_init (ActionClass *klass)
111 {
112   GObjectClass * object_class = (GObjectClass *) klass;
113   POA_Accessibility_Action__epv *epv = &klass->epv;
114   parent_class = g_type_class_peek_parent (klass);
115
116   object_class->finalize = action_finalize;
117
118
119   /* Initialize epv table */
120
121   epv->_get_nActions = impl__get_nActions;
122   epv->doAction = impl_doAction;
123   epv->getDescription = impl_getDescription;
124   epv->getName = impl_getName;
125   epv->getKeyBinding = impl_getKeyBinding;
126 }
127
128 static void
129 action_init (Action *action)
130 {
131 }
132
133 static void
134 action_finalize (GObject *obj)
135 {
136   Action *action = ACTION (obj);
137   action->atk_action = NULL;
138   parent_class->finalize (obj);
139 }
140
141 Action *
142 action_new (AtkAction *action)
143 {
144   Action *new_action = 
145     ACTION(g_object_new (ACTION_TYPE, NULL));
146   new_action->atk_action = action;
147   return new_action;
148 }
149
150 static CORBA_long
151 impl__get_nActions(PortableServer_Servant servant,
152             CORBA_Environment * ev)
153 {
154   Action *action = ACTION (bonobo_object_from_servant(servant));
155   return (CORBA_long) atk_action_get_n_actions (action->atk_action);
156 }
157
158 static CORBA_boolean
159 impl_doAction (PortableServer_Servant servant,
160                const CORBA_long index, CORBA_Environment * ev)
161 {
162   Action *action = ACTION (bonobo_object_from_servant (servant));
163   return (CORBA_boolean) atk_action_do_action (action->atk_action, (gint) index);
164 }
165
166
167 static CORBA_string
168 impl_getDescription (PortableServer_Servant servant,
169                 const CORBA_long index,
170                 CORBA_Environment * ev)
171 {
172   Action *action = ACTION (bonobo_object_from_servant(servant));
173   return CORBA_string_dup (atk_action_get_description (action->atk_action, (gint) index));
174 }
175
176
177 static CORBA_string
178 impl_getName (PortableServer_Servant servant,
179                 const CORBA_long index,
180                 CORBA_Environment * ev)
181 {
182   Action *action = ACTION (bonobo_object_from_servant(servant));
183   return CORBA_string_dup (atk_action_get_name (action->atk_action, (gint) index));
184 }
185
186 static CORBA_string
187 impl_getKeyBinding (PortableServer_Servant servant,
188                     const CORBA_long index,
189                     CORBA_Environment * ev)
190 {
191   Action *action = ACTION (bonobo_object_from_servant(servant));
192   return CORBA_string_dup (atk_action_get_keybinding (action->atk_action, (gint) index));
193 }