Fix memory leak. (bug #124877)
[platform/upstream/atk.git] / atk / atkhyperlink.c
1 /* ATK -  Accessibility Toolkit
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 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 enum
23 {
24   PROP_0,  /* gobject convention */
25
26   PROP_SELECTED_LINK,
27   PROP_LAST
28 };
29
30 static void atk_hyperlink_class_init (AtkHyperlinkClass *klass);
31 static void atk_hyperlink_init       (AtkHyperlink      *link,
32                                       AtkHyperlinkClass *klass);
33
34 static void atk_hyperlink_real_get_property (GObject            *object,
35                                              guint              prop_id,
36                                              GValue             *value,
37                                              GParamSpec         *pspec);
38
39 static void atk_hyperlink_action_iface_init (AtkActionIface *iface);
40
41 static gpointer  parent_class = NULL;
42
43 GType
44 atk_hyperlink_get_type (void)
45 {
46   static GType type = 0;
47
48   if (!type)
49     {
50       static const GTypeInfo typeInfo =
51       {
52         sizeof (AtkHyperlinkClass),
53         (GBaseInitFunc) NULL,
54         (GBaseFinalizeFunc) NULL,
55         (GClassInitFunc) atk_hyperlink_class_init,
56         (GClassFinalizeFunc) NULL,
57         NULL,
58         sizeof (AtkHyperlink),
59         0,
60         (GInstanceInitFunc) atk_hyperlink_init,
61       } ;
62
63       static const GInterfaceInfo action_info =
64       {
65         (GInterfaceInitFunc) atk_hyperlink_action_iface_init,
66         (GInterfaceFinalizeFunc) NULL,
67         NULL
68       };
69
70       type = g_type_register_static (G_TYPE_OBJECT, "AtkHyperlink", &typeInfo, 0) ;
71       g_type_add_interface_static (type, ATK_TYPE_ACTION, &action_info);
72     }
73   return type;
74 }
75
76 static void
77 atk_hyperlink_class_init (AtkHyperlinkClass *klass)
78 {
79   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
80
81   parent_class = g_type_class_peek_parent (klass);
82
83   gobject_class->get_property = atk_hyperlink_real_get_property;
84
85   g_object_class_install_property (gobject_class,
86                                    PROP_SELECTED_LINK,
87                                    g_param_spec_boolean ("selected-link",
88                                                          "Selected Link",
89                                                          "Specifies whether the AtkHyperlink object is selected",
90                                                          FALSE,
91                                                          G_PARAM_READABLE));
92 }
93
94 static void
95 atk_hyperlink_init  (AtkHyperlink        *link,
96                      AtkHyperlinkClass   *klass)
97 {
98 }
99
100 static void
101 atk_hyperlink_real_get_property (GObject    *object,
102                                  guint      prop_id,
103                                  GValue     *value,
104                                  GParamSpec *pspec)
105 {
106   AtkHyperlink* link;
107
108   link = ATK_HYPERLINK (object);
109
110   switch (prop_id)
111     {
112     case PROP_SELECTED_LINK:
113       g_value_set_boolean (value, atk_hyperlink_is_selected_link (link));
114       break;
115     default:
116       break;
117     }
118 }
119
120 /**
121  * atk_hyperlink_get_uri:
122  * @link_: an #AtkHyperlink
123  * @i: a (zero-index) integer specifying the desired anchor
124  *
125  * Get a the URI associated with the anchor specified 
126  * by @i of @link_. 
127  *
128  * Multiple anchors are primarily used by client-side image maps.
129  *
130  * Returns: a string specifying the URI 
131  **/
132 gchar*
133 atk_hyperlink_get_uri (AtkHyperlink *link,
134                        gint         i)
135 {
136   AtkHyperlinkClass *klass;
137
138   g_return_val_if_fail (ATK_IS_HYPERLINK (link), NULL);
139
140   klass = ATK_HYPERLINK_GET_CLASS (link);
141   if (klass->get_uri)
142     return (klass->get_uri) (link, i);
143   else
144     return NULL;
145 }
146
147 /**
148  * atk_hyperlink_get_object:
149  * @link_: an #AtkHyperlink
150  * @i: a (zero-index) integer specifying the desired anchor
151  *
152  * Returns the item associated with this hyperlinks nth anchor.
153  * For instance, the returned #AtkObject will implement #AtkText
154  * if @link_ is a text hyperlink, #AtkImage if @link_ is an image
155  * hyperlink etc. 
156  * 
157  * Multiple anchors are primarily used by client-side image maps.
158  *
159  * Returns: an #AtkObject associated with this hyperlinks i-th anchor
160  **/
161 AtkObject*
162 atk_hyperlink_get_object (AtkHyperlink *link,
163                           gint         i)
164 {
165   AtkHyperlinkClass *klass;
166
167   g_return_val_if_fail (ATK_IS_HYPERLINK (link), NULL);
168
169   klass = ATK_HYPERLINK_GET_CLASS (link);
170   if (klass->get_object)
171     return (klass->get_object) (link, i);
172   else
173     return NULL;
174 }
175
176 /**
177  * atk_hyperlink_get_end_index:
178  * @link_: an #AtkHyperlink
179  *
180  * Gets the index with the hypertext document at which this link ends.
181  *
182  * Returns: the index with the hypertext document at which this link ends
183  **/
184 gint
185 atk_hyperlink_get_end_index (AtkHyperlink *link)
186 {
187   AtkHyperlinkClass *klass;
188
189   g_return_val_if_fail (ATK_IS_HYPERLINK (link), 0);
190
191   klass = ATK_HYPERLINK_GET_CLASS (link);
192   if (klass->get_end_index)
193     return (klass->get_end_index) (link);
194   else
195     return 0;
196 }
197
198 /**
199  * atk_hyperlink_get_start_index:
200  * @link_: an #AtkHyperlink
201  *
202  * Gets the index with the hypertext document at which this link begins.
203  *
204  * Returns: the index with the hypertext document at which this link begins
205  **/
206 gint
207 atk_hyperlink_get_start_index (AtkHyperlink *link)
208 {
209   AtkHyperlinkClass *klass;
210
211   g_return_val_if_fail (ATK_IS_HYPERLINK (link), 0);
212
213   klass = ATK_HYPERLINK_GET_CLASS (link);
214   if (klass->get_start_index)
215     return (klass->get_start_index) (link);
216   else
217     return 0;
218 }
219
220 /**
221  * atk_hyperlink_is_valid:
222  * @link_: an #AtkHyperlink
223  *
224  * Since the document that a link is associated with may have changed
225  * this method returns %TRUE if the link is still valid (with
226  * respect to the document it references) and %FALSE otherwise.
227  *
228  * Returns: whether or not this link is still valid
229  **/
230 gboolean
231 atk_hyperlink_is_valid (AtkHyperlink *link)
232 {
233   AtkHyperlinkClass *klass;
234
235   g_return_val_if_fail (ATK_IS_HYPERLINK (link), FALSE);
236
237   klass = ATK_HYPERLINK_GET_CLASS (link);
238   if (klass->is_valid)
239     return (klass->is_valid) (link);
240   else
241     return FALSE;
242 }
243
244 /**
245  * atk_hyperlink_is_inline:
246  * @link_: an #AtkHyperlink
247  *
248  * Indicates whether the link currently displays some or all of its
249  *           content inline.  Ordinary HTML links will usually return
250  *           %FALSE, but an inline <src> HTML element will return
251  *           %TRUE.
252 a *
253  * Returns: whether or not this link displays its content inline.
254  *
255  **/
256 gboolean
257 atk_hyperlink_is_inline (AtkHyperlink *link)
258 {
259   AtkHyperlinkClass *klass;
260
261   g_return_val_if_fail (ATK_IS_HYPERLINK (link), FALSE);
262
263   klass = ATK_HYPERLINK_GET_CLASS (link);
264   if (klass->link_state)
265     return (klass->link_state (link) & ATK_HYPERLINK_IS_INLINE);
266   else
267     return FALSE;
268 }
269
270 /**
271  * atk_hyperlink_get_n_anchors:
272  * @link_: an #AtkHyperlink
273  *
274  * Gets the number of anchors associated with this hyperlink.
275  *
276  * Returns: the number of anchors associated with this hyperlink
277  **/
278 gint
279 atk_hyperlink_get_n_anchors (AtkHyperlink *link)
280 {
281   AtkHyperlinkClass *klass;
282
283   g_return_val_if_fail (ATK_IS_HYPERLINK (link), 0);
284
285   klass = ATK_HYPERLINK_GET_CLASS (link);
286   if (klass->get_n_anchors)
287     return (klass->get_n_anchors) (link);
288   else
289     return 0;
290 }
291
292 /**
293  * atk_hyperlink_is_selected_link:
294  * @link_: an #AtkHyperlink
295  *
296  * Determines whether this AtkHyperlink is selected
297  *
298  * Returns: True is the AtkHyperlink is selected, False otherwise
299  **/
300 gboolean
301 atk_hyperlink_is_selected_link (AtkHyperlink *link)
302 {
303   AtkHyperlinkClass *klass;
304
305   g_return_val_if_fail (ATK_IS_HYPERLINK (link), FALSE);
306
307   klass = ATK_HYPERLINK_GET_CLASS (link);
308   if (klass->is_selected_link)
309     return (klass->is_selected_link) (link);
310   else
311     return FALSE;
312 }
313
314 static void atk_hyperlink_action_iface_init (AtkActionIface *iface)
315 {
316   /*
317    * We do nothing here
318    *
319    * When we come to derive a class from AtkHyperlink we will provide an
320    * implementation of the AtkAction interface. 
321    */
322 }