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