2d55b8b80020e7687efdb55ed026d0864167c875
[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_n_anchors = 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   hyperlink->atk_hyperlink = NULL;
139   parent_class->finalize (obj);
140 }
141
142 Hyperlink *
143 hyperlink_new (AtkHyperlink *hyperlink)
144 {
145   Hyperlink *new_hyperlink = 
146     HYPERLINK(g_object_new (HYPERLINK_TYPE, NULL));
147   new_hyperlink->atk_hyperlink = hyperlink;
148   return new_hyperlink;
149 }
150
151
152
153 static CORBA_short
154 impl__get_n_anchors (PortableServer_Servant _servant,
155                      CORBA_Environment * ev)
156 {
157   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
158   return (CORBA_short) atk_hyperlink_get_n_anchors (link->atk_hyperlink);
159 }
160
161
162
163 static CORBA_long
164 impl__get_startIndex (PortableServer_Servant _servant,
165                       CORBA_Environment * ev)
166 {
167   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
168   return (CORBA_long) atk_hyperlink_get_start_index (link->atk_hyperlink);
169 }
170
171
172
173 static CORBA_long
174 impl__get_endIndex (PortableServer_Servant _servant,
175                     CORBA_Environment * ev)
176 {
177   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
178   return (CORBA_long) atk_hyperlink_get_end_index (link->atk_hyperlink);
179 }
180
181
182
183 static CORBA_string
184 impl_getURI (PortableServer_Servant _servant,
185   const CORBA_long i, CORBA_Environment * ev)
186 {
187   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
188   gchar *uri;
189   CORBA_char *rv;
190   uri = atk_hyperlink_get_uri (link->atk_hyperlink, (gint) i);
191   rv = CORBA_string_dup (uri);
192   g_free (uri);
193   return rv;
194
195
196
197
198 static Accessibility_Accessible
199 impl_getObject (PortableServer_Servant _servant,
200                 const CORBA_long i,
201                 CORBA_Environment * ev)
202 {
203   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
204   AtkObject *atk_object;
205   Accessibility_Accessible rv;
206   atk_object = atk_hyperlink_get_object (link->atk_hyperlink, (gint) i);
207   rv = bonobo_object_corba_objref (BONOBO_OBJECT(accessible_new(atk_object)));
208   return rv;
209 }
210
211
212
213 static CORBA_boolean
214 impl_isValid (PortableServer_Servant _servant,
215               CORBA_Environment * ev)
216 {
217   Hyperlink *link = HYPERLINK(bonobo_object_from_servant(_servant));
218   return (CORBA_boolean) atk_hyperlink_is_valid (link->atk_hyperlink);
219 }
220
221