Updated Esperanto translation
[gtkhtml.git] / a11y / image.c
blob9a112f1e435cc36c73e0d2d561288c428a5629d0
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/atkimage.h>
27 #include "htmlimage.h"
29 #include "html.h"
30 #include "image.h"
32 #include <glib/gi18n-lib.h>
34 static void html_a11y_image_class_init (HTMLA11YImageClass *klass);
35 static void html_a11y_image_init (HTMLA11YImage *a11y_image);
36 static void atk_image_interface_init (AtkImageIface *iface);
38 static const gchar * html_a11y_image_get_name (AtkObject *accessible);
40 static void html_a11y_image_get_image_position (AtkImage *image, gint *x, gint *y, AtkCoordType coord_type);
41 static void html_a11y_image_get_image_size (AtkImage *image, gint *width, gint *height);
42 static const gchar *html_a11y_image_get_image_description (AtkImage *image);
44 static AtkObjectClass *parent_class = NULL;
46 GType
47 html_a11y_image_get_type (void)
49 static GType type = 0;
51 if (!type) {
52 static const GTypeInfo tinfo = {
53 sizeof (HTMLA11YImageClass),
54 NULL, /* base init */
55 NULL, /* base finalize */
56 (GClassInitFunc) html_a11y_image_class_init, /* class init */
57 NULL, /* class finalize */
58 NULL, /* class data */
59 sizeof (HTMLA11YImage), /* instance size */
60 0, /* nb preallocs */
61 (GInstanceInitFunc) html_a11y_image_init, /* instance init */
62 NULL /* value table */
65 static const GInterfaceInfo atk_image_info = {
66 (GInterfaceInitFunc) atk_image_interface_init,
67 (GInterfaceFinalizeFunc) NULL,
68 NULL
71 type = g_type_register_static (G_TYPE_HTML_A11Y, "HTMLA11YImage", &tinfo, 0);
72 g_type_add_interface_static (type, ATK_TYPE_IMAGE, &atk_image_info);
75 return type;
78 static void
79 atk_image_interface_init (AtkImageIface *iface)
81 g_return_if_fail (iface != NULL);
83 iface->get_image_position = html_a11y_image_get_image_position;
84 iface->get_image_size = html_a11y_image_get_image_size;
85 iface->get_image_description = html_a11y_image_get_image_description;
88 static void
89 html_a11y_image_finalize (GObject *obj)
91 G_OBJECT_CLASS (parent_class)->finalize (obj);
94 static void
95 html_a11y_image_initialize (AtkObject *obj,
96 gpointer data)
98 /* printf ("html_a11y_image_initialize\n"); */
100 if (ATK_OBJECT_CLASS (parent_class)->initialize)
101 ATK_OBJECT_CLASS (parent_class)->initialize (obj, data);
104 static void
105 html_a11y_image_class_init (HTMLA11YImageClass *klass)
107 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
108 AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
110 parent_class = g_type_class_peek_parent (klass);
112 atk_class->get_name = html_a11y_image_get_name;
113 atk_class->initialize = html_a11y_image_initialize;
114 gobject_class->finalize = html_a11y_image_finalize;
117 static void
118 html_a11y_image_init (HTMLA11YImage *a11y_image)
122 AtkObject *
123 html_a11y_image_new (HTMLObject *html_obj)
125 GObject *object;
126 AtkObject *accessible;
128 g_return_val_if_fail (HTML_IS_IMAGE (html_obj), NULL);
130 object = g_object_new (G_TYPE_HTML_A11Y_IMAGE, NULL);
132 accessible = ATK_OBJECT (object);
133 atk_object_initialize (accessible, html_obj);
135 accessible->role = ATK_ROLE_IMAGE;
137 /* printf ("created new html accessible image object\n"); */
139 return accessible;
142 static const gchar *
143 html_a11y_image_get_name (AtkObject *accessible)
145 HTMLImage *img = HTML_IMAGE (HTML_A11Y_HTML (accessible));
146 gchar *name;
148 if (accessible->name)
149 return accessible->name;
151 if (img->alt) {
152 name = g_strdup_printf (_("URL is %s, Alternative Text is %s"), img->image_ptr->url, img->alt);
153 } else
154 name = g_strdup_printf (_("URL is %s"), img->image_ptr->url);
156 atk_object_set_name (accessible, name);
157 g_free (name);
159 return accessible->name;
163 * AtkImage interface
166 static void
167 html_a11y_image_get_image_position (AtkImage *image,
168 gint *x,
169 gint *y,
170 AtkCoordType coord_type)
172 HTMLImage *img = HTML_IMAGE (HTML_A11Y_HTML (image));
174 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
176 *x += img->hspace + img->border;
177 *y += img->vspace + img->border;
180 static void
181 html_a11y_image_get_image_size (AtkImage *image,
182 gint *width,
183 gint *height)
185 HTMLImage *img = HTML_IMAGE (HTML_A11Y_HTML (image));
187 atk_component_get_size (ATK_COMPONENT (image), width, height);
189 *width -= 2*(img->hspace + img->border);
190 *height -= 2*(img->vspace + img->border);
193 static const gchar *
194 html_a11y_image_get_image_description (AtkImage *image)
196 return html_a11y_image_get_name (ATK_OBJECT (image));