2001-11-20 Michael Meeks <michael@ximian.com>
[platform/core/uifw/at-spi2-atk.git] / libspi / hypertext.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 /* hypertext.c : implements the HyperText interface */
24
25 #include <config.h>
26 #include <stdio.h>
27 #include <libspi/hyperlink.h>
28 #include <libspi/hypertext.h>
29
30 /* Static function declarations */
31
32 static void
33 spi_hypertext_class_init (SpiHypertextClass *klass);
34 static void
35 spi_hypertext_init (SpiHypertext *hypertext);
36 static void
37 spi_hypertext_finalize (GObject *obj);
38 static CORBA_short
39 impl__get_n_anchors (PortableServer_Servant _servant,
40                      CORBA_Environment * ev);
41 static CORBA_string
42 impl__get_uri (PortableServer_Servant _servant,
43                CORBA_Environment * ev);
44 static CORBA_long
45 impl__get_startIndex (PortableServer_Servant _servant,
46                       CORBA_Environment * ev);
47 static CORBA_long
48 impl__get_endIndex (PortableServer_Servant _servant,
49                     CORBA_Environment * ev);
50 static Accessibility_Accessible
51 impl_getAnchor (PortableServer_Servant _servant,
52                 const CORBA_long i,
53                 CORBA_Environment * ev);
54 static Accessibility_Accessible
55 impl_getObject (PortableServer_Servant _servant,
56                 const CORBA_long i,
57                 CORBA_Environment * ev);
58 static CORBA_long
59 impl_getNLinks (PortableServer_Servant _servant,
60                 CORBA_Environment * ev);
61 static Accessibility_Hyperlink
62 impl_getLink (PortableServer_Servant _servant,
63               const CORBA_long linkIndex,
64               CORBA_Environment * ev);
65 static CORBA_long
66 impl_getLinkIndex (PortableServer_Servant _servant,
67                    const CORBA_long characterIndex,
68                    CORBA_Environment * ev);
69
70 static GObjectClass *parent_class;
71
72 GType
73 spi_hypertext_get_type (void)
74 {
75   static GType type = 0;
76
77   if (!type) {
78     static const GTypeInfo tinfo = {
79       sizeof (SpiHypertextClass),
80       (GBaseInitFunc) NULL,
81       (GBaseFinalizeFunc) NULL,
82       (GClassInitFunc) spi_hypertext_class_init,
83       (GClassFinalizeFunc) NULL,
84       NULL, /* class data */
85       sizeof (SpiHypertext),
86       0, /* n preallocs */
87       (GInstanceInitFunc) spi_hypertext_init,
88                         NULL /* value table */
89     };
90
91     /*
92      * Bonobo_type_unique auto-generates a load of
93      * CORBA structures for us. All derived types must
94      * use bonobo_type_unique.
95      */
96     type = bonobo_type_unique (
97                                BONOBO_OBJECT_TYPE,
98                                POA_Accessibility_Hypertext__init,
99                                NULL,
100                                G_STRUCT_OFFSET (SpiHypertextClass, epv),
101                                &tinfo,
102                                "SpiAccessibleHypertext");
103   }
104
105   return type;
106 }
107
108 static void
109 spi_hypertext_class_init (SpiHypertextClass *klass)
110 {
111   GObjectClass * object_class = (GObjectClass *) klass;
112   POA_Accessibility_Hypertext__epv *epv = &klass->epv;
113   parent_class = g_type_class_peek_parent (klass);
114
115   object_class->finalize = spi_hypertext_finalize;
116
117   /* Initialize epv table */
118
119   epv->getNLinks = impl_getNLinks;
120   epv->getLink = impl_getLink;
121   epv->getLinkIndex = impl_getLinkIndex;
122 }
123
124 static void
125 spi_hypertext_init (SpiHypertext *hypertext)
126 {
127 }
128
129 static void
130 spi_hypertext_finalize (GObject *obj)
131 {
132   SpiHypertext *hypertext = SPI_HYPERTEXT(obj);
133   g_object_unref (hypertext->atko);
134   hypertext->atko = NULL;
135   parent_class->finalize (obj);
136 }
137
138 SpiHypertext *
139 spi_hypertext_interface_new (AtkObject *obj)
140 {
141   SpiHypertext *new_hypertext = 
142     SPI_HYPERTEXT(g_object_new (SPI_HYPERTEXT_TYPE, NULL));
143   new_hypertext->atko = obj;
144   g_object_ref (obj);
145   return new_hypertext;
146 }
147
148
149
150 static CORBA_long
151 impl_getNLinks (PortableServer_Servant _servant,
152                 CORBA_Environment * ev)
153 {
154   SpiHypertext *hypertext = SPI_HYPERTEXT(bonobo_object_from_servant(_servant));
155   return (CORBA_long)
156     atk_hypertext_get_n_links (ATK_HYPERTEXT(hypertext->atko));
157 }
158
159
160
161 static Accessibility_Hyperlink
162 impl_getLink (PortableServer_Servant servant,
163               const CORBA_long       linkIndex,
164               CORBA_Environment     *ev)
165 {
166   AtkHyperlink *link;
167   SpiHypertext *hypertext;
168   Accessibility_Hyperlink rv;
169   
170   hypertext = SPI_HYPERTEXT (bonobo_object_from_servant (servant));
171
172   link = atk_hypertext_get_link (
173           ATK_HYPERTEXT (hypertext->atko), linkIndex);
174
175   rv = bonobo_object_corba_objref (BONOBO_OBJECT (
176           spi_hyperlink_new (ATK_OBJECT (link))));
177
178   return rv;
179 }
180
181
182
183 static CORBA_long
184 impl_getLinkIndex (PortableServer_Servant _servant,
185                    const CORBA_long characterIndex,
186                                   CORBA_Environment * ev)
187 {
188   SpiHypertext *hypertext = SPI_HYPERTEXT(bonobo_object_from_servant(_servant));
189   return (CORBA_long)
190     atk_hypertext_get_link_index (ATK_HYPERTEXT(hypertext->atko),
191                                   (gint) characterIndex);
192 }
193