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