| 1 |
/* GTK+ - accessibility implementations |
| 2 |
* Copyright 2001 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, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
|
| 20 |
#include <string.h> |
| 21 |
#include <gtk/gtk.h> |
| 22 |
#include "gtkimageaccessible.h" |
| 23 |
#include "gtktoolbarprivate.h" |
| 24 |
#include "gtkintl.h" |
| 25 |
|
| 26 |
struct _GtkImageAccessiblePrivate |
| 27 |
{ |
| 28 |
gchar *image_description; |
| 29 |
gchar *stock_name; |
| 30 |
}; |
| 31 |
|
| 32 |
static void atk_image_interface_init (AtkImageIface *iface); |
| 33 |
|
| 34 |
G_DEFINE_TYPE_WITH_CODE (GtkImageAccessible, gtk_image_accessible, GTK_TYPE_WIDGET_ACCESSIBLE, |
| 35 |
G_ADD_PRIVATE (GtkImageAccessible) |
| 36 |
G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_interface_init)) |
| 37 |
|
| 38 |
static void |
| 39 |
gtk_image_accessible_initialize (AtkObject *accessible, |
| 40 |
gpointer data) |
| 41 |
{ |
| 42 |
ATK_OBJECT_CLASS (gtk_image_accessible_parent_class)->initialize (accessible, data); |
| 43 |
|
| 44 |
accessible->role = ATK_ROLE_ICON; |
| 45 |
} |
| 46 |
|
| 47 |
typedef struct { |
| 48 |
const gchar *name; |
| 49 |
const gchar *label; |
| 50 |
} NameMapEntry; |
| 51 |
|
| 52 |
static const NameMapEntry name_map[] = { |
| 53 |
{ "help-about", NC_("Stock label", "_About") }, |
| 54 |
{ "list-add", NC_("Stock label", "_Add") }, |
| 55 |
{ "format-text-bold", NC_("Stock label", "_Bold") }, |
| 56 |
{ "media-optical", NC_("Stock label", "_CD-ROM") }, |
| 57 |
{ "edit-clear", NC_("Stock label", "_Clear") }, |
| 58 |
{ "window-close", NC_("Stock label", "_Close") }, |
| 59 |
{ "window-minimize", N_("Minimize") }, |
| 60 |
{ "window-maximize", N_("Maximize") }, |
| 61 |
{ "window-restore", N_("Restore") }, |
| 62 |
{ "edit-copy", NC_("Stock label", "_Copy") }, |
| 63 |
{ "edit-cut", NC_("Stock label", "Cu_t") }, |
| 64 |
{ "edit-delete", NC_("Stock label", "_Delete") }, |
| 65 |
{ "dialog-error", NC_("Stock label", "Error") }, |
| 66 |
{ "dialog-information", NC_("Stock label", "Information") }, |
| 67 |
{ "dialog-question", NC_("Stock label", "Question") }, |
| 68 |
{ "dialog-warning", NC_("Stock label", "Warning") }, |
| 69 |
{ "system-run", NC_("Stock label", "_Execute") }, |
| 70 |
{ "text-x-generic", NC_("Stock label", "_File") }, |
| 71 |
{ "edit-find", NC_("Stock label", "_Find") }, |
| 72 |
{ "edit-find-replace", NC_("Stock label", "Find and _Replace") }, |
| 73 |
{ "media-floppy", NC_("Stock label", "_Floppy") }, |
| 74 |
{ "view-fullscreen", NC_("Stock label", "_Fullscreen") }, |
| 75 |
{ "go-bottom", NC_("Stock label, navigation", "_Bottom") }, |
| 76 |
{ "go-first", NC_("Stock label, navigation", "_First") }, |
| 77 |
{ "go-last", NC_("Stock label, navigation", "_Last") }, |
| 78 |
{ "go-top", NC_("Stock label, navigation", "_Top") }, |
| 79 |
{ "go-previous", NC_("Stock label, navigation", "_Back") }, |
| 80 |
{ "go-down", NC_("Stock label, navigation", "_Down") }, |
| 81 |
{ "go-next", NC_("Stock label, navigation", "_Forward") }, |
| 82 |
{ "go-up", NC_("Stock label, navigation", "_Up") }, |
| 83 |
{ "drive-harddisk", NC_("Stock label", "_Hard Disk") }, |
| 84 |
{ "help-contents", NC_("Stock label", "_Help") }, |
| 85 |
{ "go-home", NC_("Stock label", "_Home") }, |
| 86 |
{ "format-indent-more", NC_("Stock label", "Increase Indent") }, |
| 87 |
{ "format-text-italic", NC_("Stock label", "_Italic") }, |
| 88 |
{ "go-jump", NC_("Stock label", "_Jump to") }, |
| 89 |
{ "format-justify-center", NC_("Stock label", "_Center") }, |
| 90 |
{ "format-justify-fill", NC_("Stock label", "_Fill") }, |
| 91 |
{ "format-justify-left", NC_("Stock label", "_Left") }, |
| 92 |
{ "format-justify-right", NC_("Stock label", "_Right") }, |
| 93 |
{ "view-restore", NC_("Stock label", "_Leave Fullscreen") }, |
| 94 |
{ "media-seek-forward", NC_("Stock label, media", "_Forward") }, |
| 95 |
{ "media-skip-forward", NC_("Stock label, media", "_Next") }, |
| 96 |
{ "media-playback-pause", NC_("Stock label, media", "P_ause") }, |
| 97 |
{ "media-playback-start", NC_("Stock label, media", "_Play") }, |
| 98 |
{ "media-skip-backward", NC_("Stock label, media", "Pre_vious") }, |
| 99 |
{ "media-record", NC_("Stock label, media", "_Record") }, |
| 100 |
{ "media-seek-backward", NC_("Stock label, media", "R_ewind") }, |
| 101 |
{ "media-playback-stop", NC_("Stock label, media", "_Stop") }, |
| 102 |
{ "network-idle", NC_("Stock label", "_Network") }, |
| 103 |
{ "document-new", NC_("Stock label", "_New") }, |
| 104 |
{ "document-open", NC_("Stock label", "_Open") }, |
| 105 |
{ "edit-paste", NC_("Stock label", "_Paste") }, |
| 106 |
{ "document-print", NC_("Stock label", "_Print") }, |
| 107 |
{ "document-print-preview", NC_("Stock label", "Print Pre_view") }, |
| 108 |
{ "document-properties", NC_("Stock label", "_Properties") }, |
| 109 |
{ "application-exit", NC_("Stock label", "_Quit") }, |
| 110 |
{ "edit-redo", NC_("Stock label", "_Redo") }, |
| 111 |
{ "view-refresh", NC_("Stock label", "_Refresh") }, |
| 112 |
{ "list-remove", NC_("Stock label", "_Remove") }, |
| 113 |
{ "document-revert", NC_("Stock label", "_Revert") }, |
| 114 |
{ "document-save", NC_("Stock label", "_Save") }, |
| 115 |
{ "document-save-as", NC_("Stock label", "Save _As") }, |
| 116 |
{ "edit-select-all", NC_("Stock label", "Select _All") }, |
| 117 |
{ "view-sort-ascending", NC_("Stock label", "_Ascending") }, |
| 118 |
{ "view-sort-descending", NC_("Stock label", "_Descending") }, |
| 119 |
{ "tools-check-spelling", NC_("Stock label", "_Spell Check") }, |
| 120 |
{ "process-stop", NC_("Stock label", "_Stop") }, |
| 121 |
{ "format-text-strikethrough", NC_("Stock label", "_Strikethrough") }, |
| 122 |
{ "format-text-underline", NC_("Stock label", "_Underline") }, |
| 123 |
{ "edit-undo", NC_("Stock label", "_Undo") }, |
| 124 |
{ "format-indent-less", NC_("Stock label", "Decrease Indent") }, |
| 125 |
{ "zoom-original", NC_("Stock label", "_Normal Size") }, |
| 126 |
{ "zoom-fit-best", NC_("Stock label", "Best _Fit") }, |
| 127 |
{ "zoom-in", NC_("Stock label", "Zoom _In") }, |
| 128 |
{ "zoom-out", NC_("Stock label", "Zoom _Out") } |
| 129 |
}; |
| 130 |
|
| 131 |
static gchar * |
| 132 |
name_from_icon_name (const gchar *icon_name) |
| 133 |
{ |
| 134 |
gchar *name; |
| 135 |
const gchar *label; |
| 136 |
gint i; |
| 137 |
|
| 138 |
name = g_strdup (icon_name); |
| 139 |
if (g_str_has_suffix (name, "-symbolic")) |
| 140 |
name[strlen (name) - strlen ("-symbolic")] = '\0'; |
| 141 |
|
| 142 |
for (i = 0; i < G_N_ELEMENTS (name_map); i++) |
| 143 |
{ |
| 144 |
if (g_str_equal (name, name_map[i].name)) |
| 145 |
{ |
| 146 |
label = g_dpgettext2 (GETTEXT_PACKAGE, "Stock label", name_map[i].label); |
| 147 |
g_free (name); |
| 148 |
|
| 149 |
return _gtk_toolbar_elide_underscores (label); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
g_free (name); |
| 154 |
return NULL; |
| 155 |
} |
| 156 |
|
| 157 |
static void |
| 158 |
gtk_image_accessible_finalize (GObject *object) |
| 159 |
{ |
| 160 |
GtkImageAccessible *aimage = GTK_IMAGE_ACCESSIBLE (object); |
| 161 |
|
| 162 |
g_free (aimage->priv->image_description); |
| 163 |
g_free (aimage->priv->stock_name); |
| 164 |
|
| 165 |
G_OBJECT_CLASS (gtk_image_accessible_parent_class)->finalize (object); |
| 166 |
} |
| 167 |
|
| 168 |
static const gchar * |
| 169 |
gtk_image_accessible_get_name (AtkObject *accessible) |
| 170 |
{ |
| 171 |
GtkWidget* widget; |
| 172 |
GtkImage *image; |
| 173 |
GtkImageAccessible *image_accessible; |
| 174 |
GtkStockItem stock_item; |
| 175 |
gchar *stock_id; |
| 176 |
const gchar *name; |
| 177 |
GtkImageType storage_type; |
| 178 |
|
| 179 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)); |
| 180 |
if (widget == NULL) |
| 181 |
return NULL; |
| 182 |
|
| 183 |
name = ATK_OBJECT_CLASS (gtk_image_accessible_parent_class)->get_name (accessible); |
| 184 |
if (name) |
| 185 |
return name; |
| 186 |
|
| 187 |
image = GTK_IMAGE (widget); |
| 188 |
image_accessible = GTK_IMAGE_ACCESSIBLE (accessible); |
| 189 |
|
| 190 |
g_free (image_accessible->priv->stock_name); |
| 191 |
image_accessible->priv->stock_name = NULL; |
| 192 |
|
| 193 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 194 |
|
| 195 |
storage_type = gtk_image_get_storage_type (image); |
| 196 |
if (storage_type == GTK_IMAGE_STOCK) |
| 197 |
{ |
| 198 |
gtk_image_get_stock (image, &stock_id, NULL); |
| 199 |
if (stock_id == NULL) |
| 200 |
return NULL; |
| 201 |
|
| 202 |
if (!gtk_stock_lookup (stock_id, &stock_item)) |
| 203 |
return NULL; |
| 204 |
|
| 205 |
G_GNUC_END_IGNORE_DEPRECATIONS; |
| 206 |
|
| 207 |
image_accessible->priv->stock_name = _gtk_toolbar_elide_underscores (stock_item.label); |
| 208 |
} |
| 209 |
else if (storage_type == GTK_IMAGE_ICON_NAME) |
| 210 |
{ |
| 211 |
const gchar *icon_name; |
| 212 |
|
| 213 |
gtk_image_get_icon_name (image, &icon_name, NULL); |
| 214 |
image_accessible->priv->stock_name = name_from_icon_name (icon_name); |
| 215 |
} |
| 216 |
else if (storage_type == GTK_IMAGE_GICON) |
| 217 |
{ |
| 218 |
GIcon *icon; |
| 219 |
const gchar * const *icon_names; |
| 220 |
|
| 221 |
gtk_image_get_gicon (image, &icon, NULL); |
| 222 |
if (G_IS_THEMED_ICON (icon)) |
| 223 |
{ |
| 224 |
icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon)); |
| 225 |
image_accessible->priv->stock_name = name_from_icon_name (icon_names[0]); |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
return image_accessible->priv->stock_name; |
| 230 |
} |
| 231 |
|
| 232 |
static void |
| 233 |
gtk_image_accessible_class_init (GtkImageAccessibleClass *klass) |
| 234 |
{ |
| 235 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); |
| 236 |
AtkObjectClass *class = ATK_OBJECT_CLASS (klass); |
| 237 |
|
| 238 |
gobject_class->finalize = gtk_image_accessible_finalize; |
| 239 |
class->initialize = gtk_image_accessible_initialize; |
| 240 |
class->get_name = gtk_image_accessible_get_name; |
| 241 |
} |
| 242 |
|
| 243 |
static void |
| 244 |
gtk_image_accessible_init (GtkImageAccessible *image) |
| 245 |
{ |
| 246 |
image->priv = gtk_image_accessible_get_instance_private (image); |
| 247 |
} |
| 248 |
|
| 249 |
static const gchar * |
| 250 |
gtk_image_accessible_get_image_description (AtkImage *image) |
| 251 |
{ |
| 252 |
GtkImageAccessible *accessible = GTK_IMAGE_ACCESSIBLE (image); |
| 253 |
|
| 254 |
return accessible->priv->image_description; |
| 255 |
} |
| 256 |
|
| 257 |
static void |
| 258 |
gtk_image_accessible_get_image_position (AtkImage *image, |
| 259 |
gint *x, |
| 260 |
gint *y, |
| 261 |
AtkCoordType coord_type) |
| 262 |
{ |
| 263 |
atk_component_get_extents (ATK_COMPONENT (image), x, y, NULL, NULL, |
| 264 |
coord_type); |
| 265 |
} |
| 266 |
|
| 267 |
static void |
| 268 |
gtk_image_accessible_get_image_size (AtkImage *image, |
| 269 |
gint *width, |
| 270 |
gint *height) |
| 271 |
{ |
| 272 |
GtkWidget* widget; |
| 273 |
GtkImage *gtk_image; |
| 274 |
GtkImageType image_type; |
| 275 |
|
| 276 |
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image)); |
| 277 |
if (widget == NULL) |
| 278 |
{ |
| 279 |
*height = -1; |
| 280 |
*width = -1; |
| 281 |
return; |
| 282 |
} |
| 283 |
|
| 284 |
gtk_image = GTK_IMAGE (widget); |
| 285 |
|
| 286 |
image_type = gtk_image_get_storage_type (gtk_image); |
| 287 |
switch (image_type) |
| 288 |
{ |
| 289 |
case GTK_IMAGE_PIXBUF: |
| 290 |
{ |
| 291 |
GdkPixbuf *pixbuf; |
| 292 |
|
| 293 |
pixbuf = gtk_image_get_pixbuf (gtk_image); |
| 294 |
*height = gdk_pixbuf_get_height (pixbuf); |
| 295 |
*width = gdk_pixbuf_get_width (pixbuf); |
| 296 |
break; |
| 297 |
} |
| 298 |
case GTK_IMAGE_STOCK: |
| 299 |
case GTK_IMAGE_ICON_SET: |
| 300 |
case GTK_IMAGE_ICON_NAME: |
| 301 |
case GTK_IMAGE_GICON: |
| 302 |
{ |
| 303 |
GtkIconSize size; |
| 304 |
|
| 305 |
g_object_get (gtk_image, "icon-size", &size, NULL); |
| 306 |
gtk_icon_size_lookup (size, width, height); |
| 307 |
break; |
| 308 |
} |
| 309 |
case GTK_IMAGE_ANIMATION: |
| 310 |
{ |
| 311 |
GdkPixbufAnimation *animation; |
| 312 |
|
| 313 |
animation = gtk_image_get_animation (gtk_image); |
| 314 |
*height = gdk_pixbuf_animation_get_height (animation); |
| 315 |
*width = gdk_pixbuf_animation_get_width (animation); |
| 316 |
break; |
| 317 |
} |
| 318 |
default: |
| 319 |
{ |
| 320 |
*height = -1; |
| 321 |
*width = -1; |
| 322 |
break; |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
static gboolean |
| 328 |
gtk_image_accessible_set_image_description (AtkImage *image, |
| 329 |
const gchar *description) |
| 330 |
{ |
| 331 |
GtkImageAccessible* accessible = GTK_IMAGE_ACCESSIBLE (image); |
| 332 |
|
| 333 |
g_free (accessible->priv->image_description); |
| 334 |
accessible->priv->image_description = g_strdup (description); |
| 335 |
|
| 336 |
return TRUE; |
| 337 |
} |
| 338 |
|
| 339 |
static void |
| 340 |
atk_image_interface_init (AtkImageIface *iface) |
| 341 |
{ |
| 342 |
iface->get_image_description = gtk_image_accessible_get_image_description; |
| 343 |
iface->get_image_position = gtk_image_accessible_get_image_position; |
| 344 |
iface->get_image_size = gtk_image_accessible_get_image_size; |
| 345 |
iface->set_image_description = gtk_image_accessible_set_image_description; |
| 346 |
} |