Updated Esperanto translation
[gtkhtml.git] / a11y / hyperlink.c
blobeed97a2320cb34956dd5cafa01c7fe7d25e91c70
1 /* This file is part of the GtkHTML library.
3 * Copyright 2002 Ximian, Inc.
5 * Author: Radek Doulik
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #include <config.h>
25 #include <atk/atkhyperlink.h>
27 #include "htmltext.h"
29 #include "object.h"
30 #include "html.h"
31 #include "hyperlink.h"
33 static void html_a11y_hyper_link_class_init (HTMLA11YHyperLinkClass *klass);
34 static void html_a11y_hyper_link_init (HTMLA11YHyperLink *a11y_hyper_link);
36 static void atk_action_interface_init (AtkActionIface *iface);
38 static gboolean html_a11y_hyper_link_do_action (AtkAction *action, gint i);
39 static gint html_a11y_hyper_link_get_n_actions (AtkAction *action);
40 static const gchar * html_a11y_hyper_link_get_description (AtkAction *action, gint i);
41 static const gchar * html_a11y_hyper_link_get_name (AtkAction *action, gint i);
42 static gboolean html_a11y_hyper_link_set_description (AtkAction *action, gint i, const gchar *description);
44 static AtkObjectClass *parent_class = NULL;
46 GType
47 html_a11y_hyper_link_get_type (void)
49 static GType type = 0;
51 if (!type) {
52 static const GTypeInfo tinfo = {
53 sizeof (HTMLA11YHyperLinkClass),
54 NULL, /* base init */
55 NULL, /* base finalize */
56 (GClassInitFunc) html_a11y_hyper_link_class_init, /* class init */
57 NULL, /* class finalize */
58 NULL, /* class data */
59 sizeof (HTMLA11YHyperLink), /* instance size */
60 0, /* nb preallocs */
61 (GInstanceInitFunc) html_a11y_hyper_link_init, /* instance init */
62 NULL /* value table */
65 static const GInterfaceInfo atk_action_info = {
66 (GInterfaceInitFunc) atk_action_interface_init,
67 (GInterfaceFinalizeFunc) NULL,
68 NULL
71 type = g_type_register_static (ATK_TYPE_HYPERLINK, "HTMLA11YHyperLink", &tinfo, 0);
72 g_type_add_interface_static (type, ATK_TYPE_ACTION, &atk_action_info);
75 return type;
78 static void
79 atk_action_interface_init (AtkActionIface *iface)
81 g_return_if_fail (iface != NULL);
83 iface->do_action = html_a11y_hyper_link_do_action;
84 iface->get_n_actions = html_a11y_hyper_link_get_n_actions;
85 iface->get_description = html_a11y_hyper_link_get_description;
86 iface->get_name = html_a11y_hyper_link_get_name;
87 iface->set_description = html_a11y_hyper_link_set_description;
90 static void
91 html_a11y_hyper_link_finalize (GObject *obj)
93 HTMLA11YHyperLink *hl = HTML_A11Y_HYPER_LINK (obj);
95 if (hl->a11y.object)
96 g_object_remove_weak_pointer (G_OBJECT (hl->a11y.object),
97 &hl->a11y.weakref);
99 G_OBJECT_CLASS (parent_class)->finalize (obj);
102 static gint
103 html_a11y_hyper_link_get_start_index (AtkHyperlink *link)
105 HTMLA11YHyperLink *hl = HTML_A11Y_HYPER_LINK (link);
106 HTMLText *text = HTML_TEXT (HTML_A11Y_HTML (hl->a11y.object));
107 Link *a = (Link *) g_slist_nth_data (text->links, hl->num);
108 return a ? a->start_offset : -1;
111 static gint
112 html_a11y_hyper_link_get_end_index (AtkHyperlink *link)
114 HTMLA11YHyperLink *hl = HTML_A11Y_HYPER_LINK (link);
115 Link *a = (Link *) g_slist_nth_data (HTML_TEXT (HTML_A11Y_HTML (hl->a11y.object))->links, hl->num);
116 return a ? a->end_offset : -1;
119 static void
120 html_a11y_hyper_link_class_init (HTMLA11YHyperLinkClass *klass)
122 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
123 AtkHyperlinkClass *atk_hyperlink_class = ATK_HYPERLINK_CLASS (klass);
124 parent_class = g_type_class_peek_parent (klass);
126 atk_hyperlink_class->get_start_index = html_a11y_hyper_link_get_start_index;
127 atk_hyperlink_class->get_end_index = html_a11y_hyper_link_get_end_index;
128 gobject_class->finalize = html_a11y_hyper_link_finalize;
131 static void
132 html_a11y_hyper_link_init (HTMLA11YHyperLink *a11y_hyper_link)
134 a11y_hyper_link->description = NULL;
137 AtkHyperlink *
138 html_a11y_hyper_link_new (HTMLA11Y *a11y,
139 gint link_index)
141 HTMLA11YHyperLink *hl;
143 g_return_val_if_fail (G_IS_HTML_A11Y (a11y), NULL);
145 hl = HTML_A11Y_HYPER_LINK (g_object_new (G_TYPE_HTML_A11Y_HYPER_LINK, NULL));
147 hl->a11y.object = a11y;
148 hl->num = link_index;
149 hl->offset = ((Link *) g_slist_nth_data (HTML_TEXT (HTML_A11Y_HTML (a11y))->links, link_index))->start_offset;
150 g_object_add_weak_pointer (G_OBJECT (hl->a11y.object), &hl->a11y.weakref);
152 return ATK_HYPERLINK (hl);
156 * Action interface
159 static gboolean
160 html_a11y_hyper_link_do_action (AtkAction *action,
161 gint i)
163 HTMLA11YHyperLink *hl;
164 gboolean result = FALSE;
166 hl = HTML_A11Y_HYPER_LINK (action);
168 if (i == 0 && hl->a11y.object) {
169 HTMLText *text = HTML_TEXT (HTML_A11Y_HTML (hl->a11y.object));
170 gchar *url = html_object_get_complete_url (HTML_OBJECT (text), hl->offset);
172 if (url && *url) {
173 GObject *gtkhtml = GTK_HTML_A11Y_GTKHTML_POINTER
174 (html_a11y_get_gtkhtml_parent (HTML_A11Y (hl->a11y.object)));
176 g_signal_emit_by_name (gtkhtml, "link_clicked", url);
177 result = TRUE;
180 g_free (url);
183 return result;
186 static gint
187 html_a11y_hyper_link_get_n_actions (AtkAction *action)
189 return 1;
192 static const gchar *
193 html_a11y_hyper_link_get_description (AtkAction *action,
194 gint i)
196 if (i == 0) {
197 HTMLA11YHyperLink *hl;
199 hl = HTML_A11Y_HYPER_LINK (action);
201 return hl->description;
204 return NULL;
207 static const gchar *
208 html_a11y_hyper_link_get_name (AtkAction *action,
209 gint i)
211 return i == 0 ? "link click" : NULL;
214 static gboolean
215 html_a11y_hyper_link_set_description (AtkAction *action,
216 gint i,
217 const gchar *description)
219 if (i == 0) {
220 HTMLA11YHyperLink *hl;
222 hl = HTML_A11Y_HYPER_LINK (action);
224 g_free (hl->description);
225 hl->description = g_strdup (description);
227 return TRUE;
230 return FALSE;