2004-02-11 Padraig O'Briain <padraig.obriain@sun.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, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc. Ximian Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 /* hypertext.c : implements the HyperText interface */
25
26 #include <config.h>
27 #include <stdio.h>
28 #include <atk/atkhypertext.h>
29 #include <libspi/hyperlink.h>
30 #include <libspi/hypertext.h>
31
32 #define PARENT_TYPE SPI_TYPE_BASE
33
34 SpiHypertext *
35 spi_hypertext_interface_new (AtkObject *obj)
36 {
37   SpiHypertext *new_hypertext = g_object_new (SPI_HYPERTEXT_TYPE, NULL);
38
39   spi_base_construct (SPI_BASE (new_hypertext), G_OBJECT (obj));
40
41   return new_hypertext;
42 }
43
44
45 static AtkHypertext *
46 get_hypertext_from_servant (PortableServer_Servant servant)
47 {
48   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
49
50   g_return_val_if_fail (object, NULL);
51   g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
52   return ATK_HYPERTEXT (object->gobj);
53 }
54
55
56 static CORBA_long
57 impl_getNLinks (PortableServer_Servant servant,
58                 CORBA_Environment     *ev)
59 {
60   AtkHypertext *hypertext = get_hypertext_from_servant (servant);
61
62   g_return_val_if_fail (hypertext != NULL, 0);
63
64   return atk_hypertext_get_n_links (hypertext);
65 }
66
67
68 static Accessibility_Hyperlink
69 impl_getLink (PortableServer_Servant servant,
70               const CORBA_long       linkIndex,
71               CORBA_Environment     *ev)
72 {
73   AtkHyperlink *link;
74   Accessibility_Hyperlink rv;
75   AtkHypertext *hypertext = get_hypertext_from_servant (servant);
76
77   g_return_val_if_fail (hypertext != NULL, CORBA_OBJECT_NIL);
78   
79   link = atk_hypertext_get_link (hypertext, linkIndex);
80   g_return_val_if_fail (link != NULL, CORBA_OBJECT_NIL);
81
82   rv = BONOBO_OBJREF (spi_hyperlink_new (link));
83
84   return CORBA_Object_duplicate (rv, ev);
85 }
86
87
88 static CORBA_long
89 impl_getLinkIndex (PortableServer_Servant servant,
90                    const CORBA_long       characterIndex,
91                    CORBA_Environment     *ev)
92 {
93   AtkHypertext *hypertext = get_hypertext_from_servant (servant);
94
95   g_return_val_if_fail (hypertext != NULL, 0);
96
97   return atk_hypertext_get_link_index (hypertext,
98                                   characterIndex);
99 }
100
101
102 static void
103 spi_hypertext_class_init (SpiHypertextClass *klass)
104 {
105   POA_Accessibility_Hypertext__epv *epv = &klass->epv;
106
107   /* Initialize epv table */
108
109   epv->getNLinks = impl_getNLinks;
110   epv->getLink = impl_getLink;
111   epv->getLinkIndex = impl_getLinkIndex;
112 }
113
114
115 static void
116 spi_hypertext_init (SpiHypertext *hypertext)
117 {
118 }
119
120
121 BONOBO_TYPE_FUNC_FULL (SpiHypertext,
122                        Accessibility_Hypertext,
123                        PARENT_TYPE,
124                        spi_hypertext)