Updated FSF's address
[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, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "atkhypertext.h"
19
20 /**
21  * SECTION:atkhypertext
22  * @Short_description: The ATK interface which provides standard
23  *  mechanism for manipulating hyperlinks.
24  * @Title:AtkHypertext
25  *
26  * An interface used for objects which implement linking between
27  * multiple resource or content locations, or multiple 'markers'
28  * within a single document.  A Hypertext instance is associated with
29  * one or more Hyperlinks, which are associated with particular
30  * offsets within the Hypertext's included content.  While this
31  * interface is derived from Text, there is no requirement that
32  * Hypertext instances have textual content; they may implement Image
33  * as well, and Hyperlinks need not have non-zero text offsets.
34  */
35
36 enum {
37   LINK_SELECTED,
38   LAST_SIGNAL
39 };
40
41 static void atk_hypertext_base_init (AtkHypertextIface *class);
42
43 static guint atk_hypertext_signals[LAST_SIGNAL] = { 0 };
44
45
46 GType
47 atk_hypertext_get_type (void)
48 {
49   static GType type = 0;
50
51   if (!type) {
52     static const GTypeInfo tinfo =
53     {
54       sizeof (AtkHypertextIface),
55       (GBaseInitFunc) atk_hypertext_base_init,
56       (GBaseFinalizeFunc) NULL,
57
58     };
59
60     type = g_type_register_static (G_TYPE_INTERFACE, "AtkHypertext", &tinfo, 0);
61   }
62
63   return type;
64 }
65
66 static void
67 atk_hypertext_base_init (AtkHypertextIface *class)
68 {
69   static gboolean initialized = FALSE;
70
71   if (!initialized)
72     {
73       /**
74        * AtkHypertext::link-selected:
75        * @atkhypertext: the object which received the signal.
76        * @arg1: the index of the hyperlink which is selected
77        *
78        * The "link-selected" signal is emitted by an AtkHyperText
79        * object when one of the hyperlinks associated with the object
80        * is selected.
81        */
82       atk_hypertext_signals[LINK_SELECTED] =
83         g_signal_new ("link_selected",
84                       ATK_TYPE_HYPERTEXT,
85                       G_SIGNAL_RUN_LAST,
86                       G_STRUCT_OFFSET (AtkHypertextIface, link_selected),
87                       (GSignalAccumulator) NULL, NULL,
88                       g_cclosure_marshal_VOID__INT,
89                       G_TYPE_NONE,
90                       1, G_TYPE_INT);
91
92       initialized = TRUE;
93     }
94 }
95
96 /**
97  * atk_hypertext_get_link:
98  * @hypertext: an #AtkHypertext
99  * @link_index: an integer specifying the desired link
100  *
101  * Gets the link in this hypertext document at index 
102  * @link_index
103  *
104  * Returns: (transfer none): the link in this hypertext document at
105  * index @link_index
106  **/
107 AtkHyperlink* 
108 atk_hypertext_get_link (AtkHypertext  *hypertext,
109                         gint          link_index)
110 {
111   AtkHypertextIface *iface;
112
113   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), NULL);
114
115   if (link_index < 0)
116     return NULL;
117
118   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
119
120   if (iface->get_link)
121     return (*(iface->get_link)) (hypertext, link_index);
122   else
123     return NULL;
124 }
125
126 /**
127  * atk_hypertext_get_n_links:
128  * @hypertext: an #AtkHypertext
129  *
130  * Gets the number of links within this hypertext document.
131  *
132  * Returns: the number of links within this hypertext document
133  **/
134 gint 
135 atk_hypertext_get_n_links (AtkHypertext  *hypertext)
136 {
137   AtkHypertextIface *iface;
138
139   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), 0);
140
141   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
142
143   if (iface->get_n_links)
144     return (*(iface->get_n_links)) (hypertext);
145   else
146     return 0;
147 }
148
149 /**
150  * atk_hypertext_get_link_index:
151  * @hypertext: an #AtkHypertext
152  * @char_index: a character index
153  *
154  * Gets the index into the array of hyperlinks that is associated with
155  * the character specified by @char_index.
156  *
157  * Returns: an index into the array of hyperlinks in @hypertext,
158  * or -1 if there is no hyperlink associated with this character.
159  **/
160 gint 
161 atk_hypertext_get_link_index (AtkHypertext  *hypertext,
162                               gint          char_index)
163 {
164   AtkHypertextIface *iface;
165
166   g_return_val_if_fail (ATK_IS_HYPERTEXT (hypertext), -1);
167
168   if (char_index < 0)
169     return -1;
170
171   iface = ATK_HYPERTEXT_GET_IFACE (hypertext);
172
173   if (iface->get_link_index)
174     return (*(iface->get_link_index)) (hypertext, char_index);
175   else
176     return -1;
177 }