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