Bug 640574: gobject-introspection annotation and documentation fixes
[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 #include "atkintl.h"
22
23 enum
24 {
25   LINK_ACTIVATED,
26
27   LAST_SIGNAL
28 };
29
30 enum
31 {
32   PROP_0,  /* gobject convention */
33
34   PROP_SELECTED_LINK,
35   PROP_NUMBER_ANCHORS,
36   PROP_END_INDEX,
37   PROP_START_INDEX,
38   PROP_LAST
39 };
40
41 static void atk_hyperlink_class_init (AtkHyperlinkClass *klass);
42 static void atk_hyperlink_init       (AtkHyperlink      *link,
43                                       AtkHyperlinkClass *klass);
44
45 static void atk_hyperlink_real_get_property (GObject            *object,
46                                              guint              prop_id,
47                                              GValue             *value,
48                                              GParamSpec         *pspec);
49
50 static void atk_hyperlink_action_iface_init (AtkActionIface *iface);
51
52 static guint atk_hyperlink_signals[LAST_SIGNAL] = { 0, };
53
54 static gpointer  parent_class = NULL;
55
56 GType
57 atk_hyperlink_get_type (void)
58 {
59   static GType type = 0;
60
61   if (!type)
62     {
63       static const GTypeInfo typeInfo =
64       {
65         sizeof (AtkHyperlinkClass),
66         (GBaseInitFunc) NULL,
67         (GBaseFinalizeFunc) NULL,
68         (GClassInitFunc) atk_hyperlink_class_init,
69         (GClassFinalizeFunc) NULL,
70         NULL,
71         sizeof (AtkHyperlink),
72         0,
73         (GInstanceInitFunc) atk_hyperlink_init,
74       } ;
75
76       static const GInterfaceInfo action_info =
77       {
78         (GInterfaceInitFunc) atk_hyperlink_action_iface_init,
79         (GInterfaceFinalizeFunc) NULL,
80         NULL
81       };
82
83       type = g_type_register_static (G_TYPE_OBJECT, "AtkHyperlink", &typeInfo, 0) ;
84       g_type_add_interface_static (type, ATK_TYPE_ACTION, &action_info);
85     }
86   return type;
87 }
88
89 static void
90 atk_hyperlink_class_init (AtkHyperlinkClass *klass)
91 {
92   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
93
94   parent_class = g_type_class_peek_parent (klass);
95
96   gobject_class->get_property = atk_hyperlink_real_get_property;
97
98   klass->link_activated = NULL;
99
100   g_object_class_install_property (gobject_class,
101                                    PROP_SELECTED_LINK,
102                                    g_param_spec_boolean ("selected-link",
103                                                          _("Selected Link"),
104                                                          _("Specifies whether the AtkHyperlink object is selected"),
105                                                          FALSE,
106                                                          G_PARAM_READABLE));
107   g_object_class_install_property (gobject_class,
108                                    PROP_NUMBER_ANCHORS,
109                                    g_param_spec_int ("number-of-anchors",
110                                                      _("Number of Anchors"),
111                                                      _("The number of anchors associated with the AtkHyperlink object"),
112                                                      0,
113                                                      G_MAXINT,
114                                                      0,
115                                                      G_PARAM_READABLE));
116   g_object_class_install_property (gobject_class,
117                                    PROP_END_INDEX,
118                                    g_param_spec_int ("end-index",
119                                                      _("End index"),
120                                                      _("The end index of the AtkHyperlink object"),
121                                                      0,
122                                                      G_MAXINT,
123                                                      0,
124                                                      G_PARAM_READABLE));
125   g_object_class_install_property (gobject_class,
126                                    PROP_START_INDEX,
127                                    g_param_spec_int ("start-index",
128                                                      _("Start index"),
129                                                      _("The start index of the AtkHyperlink object"),
130                                                      0,
131                                                      G_MAXINT,
132                                                      0,
133                                                      G_PARAM_READABLE));
134   atk_hyperlink_signals[LINK_ACTIVATED] =
135     g_signal_new ("link_activated",
136                   G_TYPE_FROM_CLASS (klass),
137                   G_SIGNAL_RUN_LAST,
138                   G_STRUCT_OFFSET (AtkHyperlinkClass, link_activated),
139                   NULL, NULL,
140                   g_cclosure_marshal_VOID__VOID,
141                   G_TYPE_NONE,
142                   0);
143
144 }
145
146 static void
147 atk_hyperlink_init  (AtkHyperlink        *link,
148                      AtkHyperlinkClass   *klass)
149 {
150 }
151
152 static void
153 atk_hyperlink_real_get_property (GObject    *object,
154                                  guint      prop_id,
155                                  GValue     *value,
156                                  GParamSpec *pspec)
157 {
158   AtkHyperlink* link;
159
160   link = ATK_HYPERLINK (object);
161
162   switch (prop_id)
163     {
164     case PROP_SELECTED_LINK:
165       g_value_set_boolean (value, atk_hyperlink_is_selected_link (link));
166       break;
167     case PROP_NUMBER_ANCHORS:
168       g_value_set_int (value,  atk_hyperlink_get_n_anchors (link));
169       break;
170     case PROP_END_INDEX:
171       g_value_set_int (value, atk_hyperlink_get_end_index (link));
172       break;
173     case PROP_START_INDEX:
174       g_value_set_int (value, atk_hyperlink_get_start_index (link));
175       break;
176     default:
177       break;
178     }
179 }
180
181 /**
182  * atk_hyperlink_get_uri:
183  * @link_: an #AtkHyperlink
184  * @i: a (zero-index) integer specifying the desired anchor
185  *
186  * Get a the URI associated with the anchor specified 
187  * by @i of @link_. 
188  *
189  * Multiple anchors are primarily used by client-side image maps.
190  *
191  * Returns: a string specifying the URI 
192  **/
193 gchar*
194 atk_hyperlink_get_uri (AtkHyperlink *link,
195                        gint         i)
196 {
197   AtkHyperlinkClass *klass;
198
199   g_return_val_if_fail (ATK_IS_HYPERLINK (link), NULL);
200
201   klass = ATK_HYPERLINK_GET_CLASS (link);
202   if (klass->get_uri)
203     return (klass->get_uri) (link, i);
204   else
205     return NULL;
206 }
207
208 /**
209  * atk_hyperlink_get_object:
210  * @link_: an #AtkHyperlink
211  * @i: a (zero-index) integer specifying the desired anchor
212  *
213  * Returns the item associated with this hyperlinks nth anchor.
214  * For instance, the returned #AtkObject will implement #AtkText
215  * if @link_ is a text hyperlink, #AtkImage if @link_ is an image
216  * hyperlink etc. 
217  * 
218  * Multiple anchors are primarily used by client-side image maps.
219  *
220  * Returns: (transfer none): an #AtkObject associated with this hyperlinks
221  * i-th anchor
222  **/
223 AtkObject*
224 atk_hyperlink_get_object (AtkHyperlink *link,
225                           gint         i)
226 {
227   AtkHyperlinkClass *klass;
228
229   g_return_val_if_fail (ATK_IS_HYPERLINK (link), NULL);
230
231   klass = ATK_HYPERLINK_GET_CLASS (link);
232   if (klass->get_object)
233     return (klass->get_object) (link, i);
234   else
235     return NULL;
236 }
237
238 /**
239  * atk_hyperlink_get_end_index:
240  * @link_: an #AtkHyperlink
241  *
242  * Gets the index with the hypertext document at which this link ends.
243  *
244  * Returns: the index with the hypertext document at which this link ends
245  **/
246 gint
247 atk_hyperlink_get_end_index (AtkHyperlink *link)
248 {
249   AtkHyperlinkClass *klass;
250
251   g_return_val_if_fail (ATK_IS_HYPERLINK (link), 0);
252
253   klass = ATK_HYPERLINK_GET_CLASS (link);
254   if (klass->get_end_index)
255     return (klass->get_end_index) (link);
256   else
257     return 0;
258 }
259
260 /**
261  * atk_hyperlink_get_start_index:
262  * @link_: an #AtkHyperlink
263  *
264  * Gets the index with the hypertext document at which this link begins.
265  *
266  * Returns: the index with the hypertext document at which this link begins
267  **/
268 gint
269 atk_hyperlink_get_start_index (AtkHyperlink *link)
270 {
271   AtkHyperlinkClass *klass;
272
273   g_return_val_if_fail (ATK_IS_HYPERLINK (link), 0);
274
275   klass = ATK_HYPERLINK_GET_CLASS (link);
276   if (klass->get_start_index)
277     return (klass->get_start_index) (link);
278   else
279     return 0;
280 }
281
282 /**
283  * atk_hyperlink_is_valid:
284  * @link_: an #AtkHyperlink
285  *
286  * Since the document that a link is associated with may have changed
287  * this method returns %TRUE if the link is still valid (with
288  * respect to the document it references) and %FALSE otherwise.
289  *
290  * Returns: whether or not this link is still valid
291  **/
292 gboolean
293 atk_hyperlink_is_valid (AtkHyperlink *link)
294 {
295   AtkHyperlinkClass *klass;
296
297   g_return_val_if_fail (ATK_IS_HYPERLINK (link), FALSE);
298
299   klass = ATK_HYPERLINK_GET_CLASS (link);
300   if (klass->is_valid)
301     return (klass->is_valid) (link);
302   else
303     return FALSE;
304 }
305
306 /**
307  * atk_hyperlink_is_inline:
308  * @link_: an #AtkHyperlink
309  *
310  * Indicates whether the link currently displays some or all of its
311  *           content inline.  Ordinary HTML links will usually return
312  *           %FALSE, but an inline <src> HTML element will return
313  *           %TRUE.
314 a *
315  * Returns: whether or not this link displays its content inline.
316  *
317  **/
318 gboolean
319 atk_hyperlink_is_inline (AtkHyperlink *link)
320 {
321   AtkHyperlinkClass *klass;
322
323   g_return_val_if_fail (ATK_IS_HYPERLINK (link), FALSE);
324
325   klass = ATK_HYPERLINK_GET_CLASS (link);
326   if (klass->link_state)
327     return (klass->link_state (link) & ATK_HYPERLINK_IS_INLINE);
328   else
329     return FALSE;
330 }
331
332 /**
333  * atk_hyperlink_get_n_anchors:
334  * @link_: an #AtkHyperlink
335  *
336  * Gets the number of anchors associated with this hyperlink.
337  *
338  * Returns: the number of anchors associated with this hyperlink
339  **/
340 gint
341 atk_hyperlink_get_n_anchors (AtkHyperlink *link)
342 {
343   AtkHyperlinkClass *klass;
344
345   g_return_val_if_fail (ATK_IS_HYPERLINK (link), 0);
346
347   klass = ATK_HYPERLINK_GET_CLASS (link);
348   if (klass->get_n_anchors)
349     return (klass->get_n_anchors) (link);
350   else
351     return 0;
352 }
353
354 /**
355  * atk_hyperlink_is_selected_link:
356  * @link_: an #AtkHyperlink
357  *
358  * Determines whether this AtkHyperlink is selected
359  *
360  * Since: 1.4
361  *
362  * @Deprecated: This method is deprecated since ATK version 1.8.
363  * Please use ATK_STATE_SELECTED to indicate when a hyperlink within a
364  * Hypertext container is selected.
365  *
366  * Returns: True is the AtkHyperlink is selected, False otherwise
367  **/
368 gboolean
369 atk_hyperlink_is_selected_link (AtkHyperlink *link)
370 {
371   AtkHyperlinkClass *klass;
372
373   g_return_val_if_fail (ATK_IS_HYPERLINK (link), FALSE);
374
375   klass = ATK_HYPERLINK_GET_CLASS (link);
376   if (klass->is_selected_link)
377     return (klass->is_selected_link) (link);
378   else
379     return FALSE;
380 }
381
382 static void atk_hyperlink_action_iface_init (AtkActionIface *iface)
383 {
384   /*
385    * We do nothing here
386    *
387    * When we come to derive a class from AtkHyperlink we will provide an
388    * implementation of the AtkAction interface. 
389    */
390 }