Updated HACKING, and fixed memory leak in libspi/text.c
[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, Ximian 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 <atk/atkhypertext.h>
28 #include <libspi/hyperlink.h>
29 #include <libspi/hypertext.h>
30
31 #define PARENT_TYPE SPI_TYPE_BASE
32
33 SpiHypertext *
34 spi_hypertext_interface_new (AtkObject *obj)
35 {
36   SpiHypertext *new_hypertext = g_object_new (SPI_HYPERTEXT_TYPE, NULL);
37
38   spi_base_construct (SPI_BASE (new_hypertext), G_OBJECT (obj));
39
40   return new_hypertext;
41 }
42
43
44 static AtkHypertext *
45 get_hypertext_from_servant (PortableServer_Servant servant)
46 {
47   SpiBase *object = SPI_BASE (bonobo_object_from_servant (servant));
48
49   g_return_val_if_fail (object, NULL);
50   g_return_val_if_fail (ATK_IS_OBJECT(object->gobj), NULL);
51   return ATK_HYPERTEXT (object->gobj);
52 }
53
54
55 static CORBA_long
56 impl_getNLinks (PortableServer_Servant servant,
57                 CORBA_Environment     *ev)
58 {
59   AtkHypertext *hypertext = get_hypertext_from_servant (servant);
60
61   g_return_val_if_fail (hypertext != NULL, 0);
62
63   return atk_hypertext_get_n_links (hypertext);
64 }
65
66
67 static Accessibility_Hyperlink
68 impl_getLink (PortableServer_Servant servant,
69               const CORBA_long       linkIndex,
70               CORBA_Environment     *ev)
71 {
72   AtkHyperlink *link;
73   Accessibility_Hyperlink rv;
74   AtkHypertext *hypertext = get_hypertext_from_servant (servant);
75
76   g_return_val_if_fail (hypertext != NULL, CORBA_OBJECT_NIL);
77   
78   link = atk_hypertext_get_link (hypertext, linkIndex);
79   g_return_val_if_fail (link != NULL, CORBA_OBJECT_NIL);
80
81   rv = BONOBO_OBJREF (spi_hyperlink_new (ATK_OBJECT (link)));
82
83   return CORBA_Object_duplicate (rv, ev);
84 }
85
86
87 static CORBA_long
88 impl_getLinkIndex (PortableServer_Servant servant,
89                    const CORBA_long       characterIndex,
90                    CORBA_Environment     *ev)
91 {
92   AtkHypertext *hypertext = get_hypertext_from_servant (servant);
93
94   g_return_val_if_fail (hypertext != NULL, 0);
95
96   return atk_hypertext_get_link_index (hypertext,
97                                   characterIndex);
98 }
99
100
101 static void
102 spi_hypertext_class_init (SpiHypertextClass *klass)
103 {
104   POA_Accessibility_Hypertext__epv *epv = &klass->epv;
105
106   /* Initialize epv table */
107
108   epv->getNLinks = impl_getNLinks;
109   epv->getLink = impl_getLink;
110   epv->getLinkIndex = impl_getLinkIndex;
111 }
112
113
114 static void
115 spi_hypertext_init (SpiHypertext *hypertext)
116 {
117 }
118
119
120 BONOBO_TYPE_FUNC_FULL (SpiHypertext,
121                        Accessibility_Hypertext,
122                        PARENT_TYPE,
123                        spi_hypertext);