Cleaned up some suspect int* casts, and added assertions to text calls in libspi
[platform/core/uifw/at-spi2-atk.git] / libspi / hyperlink.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 hyperlink bonobo object
39  */
40 #include "hyperlink.h"
41
42 /*
43  * Static function declarations
44  */
45
46 static void
47 hyperlink_class_init (HyperlinkClass *klass);
48 static void
49 hyperlink_init (Hyperlink *hyperlink);
50 static void
51 hyperlink_finalize (GObject *obj);
52 static CORBA_string
53 impl_getURI (PortableServer_Servant _servant,
54              const CORBA_long i, CORBA_Environment * ev);
55 static CORBA_short
56 impl__get_n_anchors (PortableServer_Servant _servant,
57                      CORBA_Environment * ev);
58 static CORBA_long
59 impl__get_startIndex (PortableServer_Servant _servant,
60                       CORBA_Environment * ev);
61 static CORBA_long
62 impl__get_endIndex (PortableServer_Servant _servant,
63                     CORBA_Environment * ev);
64 static Accessibility_Accessible
65 impl_getObject (PortableServer_Servant _servant,
66                 const CORBA_long i,
67                 CORBA_Environment * ev);
68 static CORBA_boolean
69 impl_isValid (PortableServer_Servant _servant,
70               CORBA_Environment * ev);
71
72 static GObjectClass *parent_class;
73
74 GType
75 hyperlink_get_type (void)
76 {
77   static GType type = 0;
78
79   if (!type) {
80     static const GTypeInfo tinfo = {
81       sizeof (HyperlinkClass),
82       (GBaseInitFunc) NULL,
83       (GBaseFinalizeFunc) NULL,
84       (GClassInitFunc) hyperlink_class_init,
85       (GClassFinalizeFunc) NULL,
86       NULL, /* class data */
87       sizeof (Hyperlink),
88       0, /* n preallocs */
89       (GInstanceInitFunc) hyperlink_init,
90                         NULL /* value table */
91     };
92
93     /*
94      * Bonobo_type_unique auto-generates a load of
95      * CORBA structures for us. All derived types must
96      * use bonobo_type_unique.
97      */
98     type = bonobo_type_unique (
99                                BONOBO_OBJECT_TYPE,
100                                POA_Accessibility_Hyperlink__init,
101                                NULL,
102                                G_STRUCT_OFFSET (HyperlinkClass, epv),
103                                &tinfo,
104                                "AccessibleHyperlink");
105   }
106
107   return type;
108 }
109
110 static void
111 hyperlink_class_init (HyperlinkClass *klass)
112 {
113   GObjectClass * object_class = (GObjectClass *) klass;
114   POA_Accessibility_Hyperlink__epv *epv = &klass->epv;
115   parent_class = g_type_class_peek_parent (klass);
116
117   object_class->finalize = hyperlink_finalize;
118
119   /* Initialize epv table */
120
121   epv->_get_nAnchors = impl__get_n_anchors;
122   epv->getURI = impl_getURI;
123   epv->_get_startIndex = impl__get_startIndex;
124   epv->_get_endIndex = impl__get_endIndex;
125   epv->getObject = impl_getObject;
126   epv->isValid = impl_isValid;
127 }
128
129 static void
130 hyperlink_init (Hyperlink *hyperlink)
131 {
132 }
133
134 static void
135 hyperlink_finalize (GObject *obj)
136 {
137   Hyperlink *hyperlink = HYPERLINK(obj);
138   g_object_unref (hyperlink->atko);
139   hyperlink->atko = NULL;
140   parent_class->finalize (obj);
141 }
142
143 Hyperlink *
144 hyperlink_interface_new (AtkObject *obj)
145 {
146   Hyperlink *new_hyperlink = 
147     HYPERLINK(g_object_new (HYPERLINK_TYPE, NULL));
148   new_hyperlink->atko = obj;
149   g_object_ref (obj);
150   return new_hyperlink;
151 }
152
153
154
155 static CORBA_short
156 impl__get_n_anchors (PortableServer_Servant _servant,
157                      CORBA_Environment * ev)
158 {
159   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
160   return (CORBA_short) atk_hyperlink_get_n_anchors (ATK_HYPERLINK(link->atko));
161 }
162
163
164
165 static CORBA_long
166 impl__get_startIndex (PortableServer_Servant _servant,
167                       CORBA_Environment * ev)
168 {
169   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
170   return (CORBA_long) atk_hyperlink_get_start_index (ATK_HYPERLINK(link->atko));
171 }
172
173
174
175 static CORBA_long
176 impl__get_endIndex (PortableServer_Servant _servant,
177                     CORBA_Environment * ev)
178 {
179   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
180   return (CORBA_long) atk_hyperlink_get_end_index (ATK_HYPERLINK(link->atko));
181 }
182
183
184
185 static CORBA_string
186 impl_getURI (PortableServer_Servant _servant,
187   const CORBA_long i, CORBA_Environment * ev)
188 {
189   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
190   gchar *uri;
191   CORBA_char *rv;
192   uri = atk_hyperlink_get_uri (ATK_HYPERLINK(link->atko), (gint) i);
193   if (uri)
194     {
195       rv = CORBA_string_dup (uri);
196       g_free (uri);
197       }
198   else
199     rv = CORBA_string_dup ("");
200   return rv;
201
202
203
204
205 static Accessibility_Accessible
206 impl_getObject (PortableServer_Servant _servant,
207                 const CORBA_long i,
208                 CORBA_Environment * ev)
209 {
210   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
211   AtkObject *atk_object;
212   Accessibility_Accessible rv;
213   atk_object = atk_hyperlink_get_object (ATK_HYPERLINK(link->atko), (gint) i);
214   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
215   return rv;
216 }
217
218
219
220 static CORBA_boolean
221 impl_isValid (PortableServer_Servant _servant,
222               CORBA_Environment * ev)
223 {
224   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
225   return (CORBA_boolean) atk_hyperlink_is_valid (ATK_HYPERLINK(link->atko));
226 }
227
228