c9b123a3ed8c5643f8216e2a3c2402ed0ed8c2d3
[platform/upstream/atk.git] / atk / atkhypertext.c
1 /* ATK - The Accessibility Toolkit for GTK+
2  * Copyright 2001, 2002, 2003 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 enum {
23   LINK_SELECTED,
24   LAST_SIGNAL
25 };
26
27 static void atk_hypertext_base_init (AtkHypertextIface *class);
28
29 static guint atk_hypertext_signals[LAST_SIGNAL] = { 0 };
30
31
32 GType
33 atk_hypertext_get_type (void)
34 {
35   static GType type = 0;
36
37   if (!type) {
38     static const GTypeInfo tinfo =
39     {
40       sizeof (AtkHypertextIface),
41       (GBaseInitFunc) atk_hypertext_base_init,
42       (GBaseFinalizeFunc) NULL,
43
44     };
45
46     type = g_type_register_static (G_TYPE_INTERFACE, "AtkHypertext", &tinfo, 0);
47   }
48
49   return type;
50 }
51
52 static void
53 atk_hypertext_base_init (AtkHypertextIface *class)
54 {
55   static gboolean initialized = FALSE;
56
57   if (!initialized)
58     {
59       atk_hypertext_signals[LINK_SELECTED] =
60         g_signal_new ("link_selected",
61                       ATK_TYPE_HYPERTEXT,
62                       G_SIGNAL_RUN_LAST,
63                       G_STRUCT_OFFSET (AtkHypertextIface, link_selected),
64                       (GSignalAccumulator) NULL, NULL,
65                       g_cclosure_marshal_VOID__INT,
66                       G_TYPE_NONE,
67                       1, G_TYPE_INT);
68
69       initialized = TRUE;
70     }
71 }
72
73 /**
74  * atk_hypertext_get_link:
75  * @hypertext: an #AtkHypertext
76  * @link_index: an integer specifying the desired link
77  *
78  * Gets the link in this hypertext document at index 
79  * @link_index
80  *
81  * Returns: the link in this hypertext document at
82  * index @link_index
83  **/
84 AtkHyperlink* 
85 atk_hypertext_get_link (AtkHypertext  *hypertext,
86                         gint          link_index)
87 {
88   AtkHypertextIface *iface;
89
90   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), NULL);
91
92   if (link_index < 0)
93     return NULL;
94
95   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
96
97   if (iface->get_link)
98     return (*(iface->get_link)) (hypertext, link_index);
99   else
100     return NULL;
101 }
102
103 /**
104  * atk_hypertext_get_n_links:
105  * @hypertext: an #AtkHypertext
106  *
107  * Gets the number of links within this hypertext document.
108  *
109  * Returns: the number of links within this hypertext document
110  **/
111 gint 
112 atk_hypertext_get_n_links (AtkHypertext  *hypertext)
113 {
114   AtkHypertextIface *iface;
115
116   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), 0);
117
118   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
119
120   if (iface->get_n_links)
121     return (*(iface->get_n_links)) (hypertext);
122   else
123     return 0;
124 }
125
126 /**
127  * atk_hypertext_get_link_index:
128  * @hypertext: an #AtkHypertext
129  * @char_index: a character index
130  *
131  * Gets the index into the array of hyperlinks that is associated with
132  * the character specified by @char_index.
133  *
134  * Returns: an index into the array of hyperlinks in @hypertext,
135  * or -1 if there is no hyperlink associated with this character.
136  **/
137 gint 
138 atk_hypertext_get_link_index (AtkHypertext  *hypertext,
139                               gint          char_index)
140 {
141   AtkHypertextIface *iface;
142
143   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), -1);
144
145   if (char_index < 0)
146     return -1;
147
148   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
149
150   if (iface->get_link_index)
151     return (*(iface->get_link_index)) (hypertext, char_index);
152   else
153     return -1;
154 }