Added new functions to AtkUtil.
[platform/upstream/atk.git] / atk / atkhypertext.c
1 /* ATK - The Accessibility Toolkit for GTK+
2  * Copyright 2001 Sun Microsystems Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "atkhypertext.h"
21
22 struct _AtkHypertextIfaceClass
23 {
24   GObjectClass parent;
25 };
26
27 typedef struct _AtkHypertextIfaceClass AtkHypertextIfaceClass;
28
29 static void atk_hypertext_interface_init (AtkHypertextIfaceClass *klass);
30
31 static gpointer parent_class = NULL;
32
33
34 GType
35 atk_hypertext_get_type ()
36 {
37   static GType type = 0;
38
39   if (!type) {
40     static const GTypeInfo tinfo =
41     {
42       sizeof (AtkHypertextIface),
43       (GBaseInitFunc) NULL,
44       (GBaseFinalizeFunc) NULL,
45       (GInterfaceInitFunc) atk_hypertext_interface_init,
46     };
47
48     type = g_type_register_static (G_TYPE_INTERFACE, "AtkHypertext", &tinfo, 0);
49   }
50
51   return type;
52 }
53
54 static void
55 atk_hypertext_interface_init (AtkHypertextIfaceClass *klass)
56 {
57   parent_class = g_type_class_ref (ATK_TYPE_HYPERTEXT);
58 }
59
60 /**
61  * atk_hypertext_get_link:
62  * @hypertext: an #AtkHypertext
63  * @link_index: an integer specifying the desired link
64  *
65  * Gets the link in this hypertext document at index 
66  * @link_index
67  *
68  * Returns: the link in this hypertext document at
69  * index @link_index
70  **/
71 AtkHyperLink* 
72 atk_hypertext_get_link (AtkHypertext  *hypertext,
73                         gint          link_index)
74 {
75   AtkHypertextIface *iface;
76
77   g_return_val_if_fail (hypertext != NULL, NULL);
78   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), NULL);
79
80   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
81
82   if (iface->get_link)
83     return (*(iface->get_link)) (hypertext, link_index);
84   else
85     return NULL;
86 }
87
88 /**
89  * atk_hypertext_get_n_links:
90  * @hypertext: an #AtkHypertext
91  *
92  * Gets the number of links within this hypertext document.
93  *
94  * Returns: the number of links within this hypertext document
95  **/
96 gint 
97 atk_hypertext_get_n_links (AtkHypertext  *hypertext)
98 {
99   AtkHypertextIface *iface;
100
101   g_return_val_if_fail (hypertext != NULL, 0);
102   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), 0);
103
104   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
105
106   if (iface->get_n_links)
107     return (*(iface->get_n_links)) (hypertext);
108   else
109     return 0;
110 }
111
112 /**
113  * atk_hypertext_get_link_index:
114  * @hypertext: an #AtkHypertext
115  * @char_index: a character index
116  *
117  * Gets the index into the array of hyperlinks that is associated with
118  * the character specified by @char_index, or -1 if there is no hyperlink
119  * associated with this character.
120  *
121  * Returns: an index into the array of hyperlinks in @hypertext
122  **/
123 gint 
124 atk_hypertext_get_link_index (AtkHypertext  *hypertext,
125                               gint          char_index)
126 {
127   AtkHypertextIface *iface;
128
129   g_return_val_if_fail (hypertext != NULL, -1);
130   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), -1);
131
132   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
133
134   if (iface->get_link_index)
135     return (*(iface->get_link_index)) (hypertext, char_index);
136   else
137     return -1;
138 }