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