82f58a7f9e5b6029d3532efafc828b3d81ce689f
[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 hypertext_class_init (HypertextClass *klass);
48 static void
49 hypertext_init (Hypertext *hypertext);
50 static void
51 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 hypertext_get_type (void)
88 {
89   static GType type = 0;
90
91   if (!type) {
92     static const GTypeInfo tinfo = {
93       sizeof (HypertextClass),
94       (GBaseInitFunc) NULL,
95       (GBaseFinalizeFunc) NULL,
96       (GClassInitFunc) hypertext_class_init,
97       (GClassFinalizeFunc) NULL,
98       NULL, /* class data */
99       sizeof (Hypertext),
100       0, /* n preallocs */
101       (GInstanceInitFunc) 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 (HypertextClass, epv),
115                                &tinfo,
116                                "AccessibleHypertext");
117   }
118
119   return type;
120 }
121
122 static void
123 hypertext_class_init (HypertextClass *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 = 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 hypertext_init (Hypertext *hypertext)
140 {
141 }
142
143 static void
144 hypertext_finalize (GObject *obj)
145 {
146   Hypertext *hypertext = HYPERTEXT(obj);
147   hypertext->atk_hypertext = NULL;
148   parent_class->finalize (obj);
149 }
150
151 Hypertext *
152 hypertext_new (AtkHypertext *hypertext)
153 {
154   Hypertext *new_hypertext = 
155     HYPERTEXT(g_object_new (HYPERTEXT_TYPE, NULL));
156   new_hypertext->atk_hypertext = hypertext;
157   return new_hypertext;
158 }
159
160
161
162 static CORBA_long
163 impl_getNLinks (PortableServer_Servant _servant,
164                 CORBA_Environment * ev)
165 {
166   Hypertext *hypertext = HYPERTEXT(bonobo_object_from_servant(_servant));
167   return (CORBA_long)
168     atk_hypertext_get_n_links (hypertext->atk_hypertext);
169 }
170
171
172
173 static Accessibility_Hyperlink
174 impl_getLink (PortableServer_Servant _servant,
175               const CORBA_long linkIndex,
176                                           CORBA_Environment * ev)
177 {
178   AtkHyperlink *link;
179   Hypertext *hypertext = HYPERTEXT(bonobo_object_from_servant(_servant));
180   Accessibility_Hyperlink rv;
181   
182   link = atk_hypertext_get_link (hypertext->atk_hypertext,
183                                  (gint) linkIndex);
184   rv = bonobo_object_corba_objref (BONOBO_OBJECT(hyperlink_new(link)));
185   return rv;
186 }
187
188
189
190 static CORBA_long
191 impl_getLinkIndex (PortableServer_Servant _servant,
192                    const CORBA_long characterIndex,
193                                   CORBA_Environment * ev)
194 {
195   Hypertext *hypertext = HYPERTEXT(bonobo_object_from_servant(_servant));
196   return (CORBA_long)
197     atk_hypertext_get_link_index (hypertext->atk_hypertext,
198                                   (gint) characterIndex);
199 }
200