New functions which checks whether the specified AtkHyperlink is selected
[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 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 ()
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   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
93
94   if (iface->get_link)
95     return (*(iface->get_link)) (hypertext, link_index);
96   else
97     return NULL;
98 }
99
100 /**
101  * atk_hypertext_get_n_links:
102  * @hypertext: an #AtkHypertext
103  *
104  * Gets the number of links within this hypertext document.
105  *
106  * Returns: the number of links within this hypertext document
107  **/
108 gint 
109 atk_hypertext_get_n_links (AtkHypertext  *hypertext)
110 {
111   AtkHypertextIface *iface;
112
113   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), 0);
114
115   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
116
117   if (iface->get_n_links)
118     return (*(iface->get_n_links)) (hypertext);
119   else
120     return 0;
121 }
122
123 /**
124  * atk_hypertext_get_link_index:
125  * @hypertext: an #AtkHypertext
126  * @char_index: a character index
127  *
128  * Gets the index into the array of hyperlinks that is associated with
129  * the character specified by @char_index, or -1 if there is no hyperlink
130  * associated with this character.
131  *
132  * Returns: an index into the array of hyperlinks in @hypertext
133  **/
134 gint 
135 atk_hypertext_get_link_index (AtkHypertext  *hypertext,
136                               gint          char_index)
137 {
138   AtkHypertextIface *iface;
139
140   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), -1);
141
142   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
143
144   if (iface->get_link_index)
145     return (*(iface->get_link_index)) (hypertext, char_index);
146   else
147     return -1;
148 }