Added improved comments (from Oisin), fixed a couple of minor bugs.
[platform/upstream/atk.git] / atk / atkhyperlink.c
1 /* ATK -  Accessibility Toolkit
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 Lesser 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser 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 "atkhyperlink.h"
21
22
23 static void atk_hyperlink_class_init (AtkHyperlinkClass *klass);
24 static void atk_hyperlink_init       (AtkHyperlink      *link,
25                                       AtkHyperlinkClass *klass);
26
27 static void atk_hyperlink_action_iface_init (AtkActionIface *iface);
28
29 static gpointer  parent_class = NULL;
30
31 GType
32 atk_hyperlink_get_type (void)
33 {
34   static GType type = 0;
35
36   if (!type)
37     {
38       static const GTypeInfo typeInfo =
39       {
40         sizeof (AtkHyperlinkClass),
41         (GBaseInitFunc) NULL,
42         (GBaseFinalizeFunc) NULL,
43         (GClassInitFunc) atk_hyperlink_class_init,
44         (GClassFinalizeFunc) NULL,
45         NULL,
46         sizeof (AtkObject),
47         0,
48         (GInstanceInitFunc) atk_hyperlink_init,
49       } ;
50
51       static const GInterfaceInfo action_info =
52       {
53         (GInterfaceInitFunc) atk_hyperlink_action_iface_init,
54         (GInterfaceFinalizeFunc) NULL,
55         NULL
56       };
57
58       type = g_type_register_static (G_TYPE_OBJECT, "AtkHyperlink", &typeInfo, 0) ;
59       g_type_add_interface_static (type, ATK_TYPE_ACTION, &action_info);
60     }
61   return type;
62 }
63
64 static void
65 atk_hyperlink_class_init (AtkHyperlinkClass *klass)
66 {
67   parent_class = g_type_class_ref (G_TYPE_OBJECT);
68
69 }
70
71 static void
72 atk_hyperlink_init  (AtkHyperlink        *link,
73                      AtkHyperlinkClass   *klass)
74 {
75 }
76
77 /**
78  * atk_hyperlink_get_uri:
79  * @link: an #AtkHyperlink
80  * @i: a (zero-index) integer specifying the desired anchor
81  *
82  * Get a the URI associated with the anchor specified 
83  * by @i of @link. 
84  *
85  * Multiple anchors are primarily used by client-side image maps.
86  *
87  * Returns: a string specifying the URI 
88  **/
89 gchar*
90 atk_hyperlink_get_uri (AtkHyperlink *link,
91                        gint         i)
92 {
93   AtkHyperlinkClass *klass;
94
95   g_return_val_if_fail ((link != NULL), NULL);
96   g_return_val_if_fail (ATK_IS_HYPERLINK (link), NULL);
97
98   klass = ATK_HYPERLINK_GET_CLASS (link);
99   g_return_val_if_fail ((klass->get_uri != NULL), NULL);
100
101   return (klass->get_uri) (link, i);
102 }
103
104 /**
105  * atk_hyperlink_get_object:
106  * @link: an #AtkHyperlink
107  * @i: a (zero-index) integer specifying the desired anchor
108  *
109  * Returns the item associated with this hyperlinks nth anchor. For instance,
110  * the returned #AtkObject will implement #AtkText if @link is a text hyperlink, 
111  * #AtkImage if @link is an image hyperlink etc. 
112  * 
113  * Multiple anchors are primarily used by client-side image maps.
114  *
115  * Returns: an #AtkObject associated with this hyperlinks i-th anchor.
116  **/
117 AtkObject*
118 atk_hyperlink_get_object (AtkHyperlink *link,
119                           gint         i)
120 {
121   AtkHyperlinkClass *klass;
122
123   g_return_val_if_fail ((link != NULL), NULL);
124   g_return_val_if_fail (ATK_IS_HYPERLINK (link), NULL);
125
126   klass = ATK_HYPERLINK_GET_CLASS (link);
127   g_return_val_if_fail ((klass->get_object != NULL), NULL);
128
129   return (klass->get_object) (link, i);
130 }
131
132 /**
133  * atk_hyperlink_get_end_index:
134  * @link: an #AtkHyperlink
135  *
136  * Gets the index with the hypertext document at which this link ends
137  *
138  * Returns: the index with the hypertext document at which this link ends
139  **/
140 gint
141 atk_hyperlink_get_end_index (AtkHyperlink *link)
142 {
143   AtkHyperlinkClass *klass;
144
145   g_return_val_if_fail ((link != NULL), 0);
146   g_return_val_if_fail (ATK_IS_HYPERLINK (link), 0);
147
148   klass = ATK_HYPERLINK_GET_CLASS (link);
149   g_return_val_if_fail ((klass->get_end_index != NULL), 0);
150
151   return (klass->get_end_index) (link);
152 }
153
154 /**
155  * atk_hyperlink_get_start_index:
156  * @link: an #AtkHyperlink
157  *
158  * Gets the index with the hypertext document at which this link begins 
159  *
160  * Returns: the index with the hypertext document at which this link begins
161  **/
162 gint
163 atk_hyperlink_get_start_index (AtkHyperlink *link)
164 {
165   AtkHyperlinkClass *klass;
166
167   g_return_val_if_fail ((link != NULL), 0);
168   g_return_val_if_fail (ATK_IS_HYPERLINK (link), 0);
169
170   klass = ATK_HYPERLINK_GET_CLASS (link);
171   g_return_val_if_fail ((klass->get_start_index != NULL), 0);
172
173   return (klass->get_start_index) (link);
174 }
175
176 /**
177  * atk_hyperlink_is_valid:
178  * @link: an #AtkHyperlink
179  *
180  * Since the document a link is associated with may have changed, this 
181  * method returns whether or not this link is still valid (with respect
182  * to the document is references)
183  *
184  * Returns: whether or not this link is still valid.
185  **/
186 gboolean
187 atk_hyperlink_is_valid (AtkHyperlink *link)
188 {
189   AtkHyperlinkClass *klass;
190
191   g_return_val_if_fail ((link != NULL), FALSE);
192   g_return_val_if_fail (ATK_IS_HYPERLINK (link), FALSE);
193
194   klass = ATK_HYPERLINK_GET_CLASS (link);
195   g_return_val_if_fail ((klass->is_valid != NULL), FALSE);
196
197   return (klass->is_valid) (link);
198 }
199
200 /**
201  * atk_hyperlink_get_n_anchors:
202  * @link: an #AtkHyperlink
203  *
204  * Gets the number of anchors associated with this hyperlink
205  *
206  * Returns: the number of anchors associated with this hyperlink
207  **/
208 gint
209 atk_hyperlink_get_n_anchors (AtkHyperlink *link)
210 {
211   AtkHyperlinkClass *klass;
212
213   g_return_val_if_fail ((link != NULL), 0);
214   g_return_val_if_fail (ATK_IS_HYPERLINK (link), 0);
215
216   klass = ATK_HYPERLINK_GET_CLASS (link);
217   g_return_val_if_fail ((klass->get_n_anchors != NULL), 0);
218
219   return (klass->get_n_anchors) (link);
220 }
221
222 static void atk_hyperlink_action_iface_init (AtkActionIface *iface)
223 {
224   /*
225    * We do nothing here
226    *
227    * When we come to derive a class from AtkHyperlink we will provide an
228    * implementation of the AtkAction interface. 
229    *
230    * This depends on being able to override an interface in a derived class
231    * which currently (March 2001) is not implemented but will be in GTK+ 2.0.
232    */
233 }