summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2013-10-14 10:33:32 -0400
committerMatthias Clasen <mclasen@redhat.com>2013-10-14 10:37:58 -0400
commitf9c8fefeda2db1e672c61a5e6cba556086c42aaa (patch)
tree2c7b693736cfd4eeb629a09b114de644f3c44380 /gtk
parentcae8a44c380d998750d0fa39b92238daa8347a3e (diff)
downloadgtk+-f9c8fefeda2db1e672c61a5e6cba556086c42aaa.tar.gz
Restore accessible names for image-only buttons
With the stock system being deprecated now, we should provide meaningful accessible names for buttons that are constructed from icon names or GIcons. This commit reuses the existing translations. It is possible that some common icon names are not covered here because they were not present as stock items. These can be added to the table later.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/a11y/gtkimageaccessible.c157
1 files changed, 147 insertions, 10 deletions
diff --git a/gtk/a11y/gtkimageaccessible.c b/gtk/a11y/gtkimageaccessible.c
index 9034f69dae..21699707b6 100644
--- a/gtk/a11y/gtkimageaccessible.c
+++ b/gtk/a11y/gtkimageaccessible.c
@@ -20,6 +20,7 @@
#include <string.h>
#include <gtk/gtk.h>
#include "gtkimageaccessible.h"
+#include "gtkintl.h"
struct _GtkImageAccessiblePrivate
{
@@ -42,6 +43,117 @@ gtk_image_accessible_initialize (AtkObject *accessible,
accessible->role = ATK_ROLE_ICON;
}
+typedef struct {
+ const gchar *name;
+ const gchar *label;
+} NameMapEntry;
+
+static const NameMapEntry name_map[] = {
+ { "help-about", NC_("Stock label", "_About") },
+ { "list-add", NC_("Stock label", "_Add") },
+ { "format-text-bold", NC_("Stock label", "_Bold") },
+ { "media-optical", NC_("Stock label", "_CD-ROM") },
+ { "edit-clear", NC_("Stock label", "_Clear") },
+ { "window-close", NC_("Stock label", "_Close") },
+ { "window-minimize", N_("Minimize") },
+ { "window-maximize", N_("Maximize") },
+ { "window-restore", N_("Restore") },
+ { "edit-copy", NC_("Stock label", "_Copy") },
+ { "edit-cut", NC_("Stock label", "Cu_t") },
+ { "edit-delete", NC_("Stock label", "_Delete") },
+ { "dialog-error", NC_("Stock label", "Error") },
+ { "dialog-information", NC_("Stock label", "Information") },
+ { "dialog-question", NC_("Stock label", "Question") },
+ { "dialog-warning", NC_("Stock label", "Warning") },
+ { "system-run", NC_("Stock label", "_Execute") },
+ { "text-x-generic", NC_("Stock label", "_File") },
+ { "edit-find", NC_("Stock label", "_Find") },
+ { "edit-find-replace", NC_("Stock label", "Find and _Replace") },
+ { "media-floppy", NC_("Stock label", "_Floppy") },
+ { "view-fullscreen", NC_("Stock label", "_Fullscreen") },
+ { "go-bottom", NC_("Stock label, navigation", "_Bottom") },
+ { "go-first", NC_("Stock label, navigation", "_First") },
+ { "go-last", NC_("Stock label, navigation", "_Last") },
+ { "go-top", NC_("Stock label, navigation", "_Top") },
+ { "go-previous", NC_("Stock label, navigation", "_Back") },
+ { "go-down", NC_("Stock label, navigation", "_Down") },
+ { "go-next", NC_("Stock label, navigation", "_Forward") },
+ { "go-up", NC_("Stock label, navigation", "_Up") },
+ { "drive-harddisk", NC_("Stock label", "_Hard Disk") },
+ { "help-contents", NC_("Stock label", "_Help") },
+ { "go-home", NC_("Stock label", "_Home") },
+ { "format-indent-more", NC_("Stock label", "Increase Indent") },
+ { "dialog-information", NC_("Stock label", "_Information") },
+ { "format-text-italic", NC_("Stock label", "_Italic") },
+ { "go-jump", NC_("Stock label", "_Jump to") },
+ { "format-justify-center", NC_("Stock label", "_Center") },
+ { "format-justify-fill", NC_("Stock label", "_Fill") },
+ { "format-justify-left", NC_("Stock label", "_Left") },
+ { "format-justify-right", NC_("Stock label", "_Right") },
+ { "view-restore", NC_("Stock label", "_Leave Fullscreen") },
+ { "media-seek-forward", NC_("Stock label, media", "_Forward") },
+ { "media-skip-forward", NC_("Stock label, media", "_Next") },
+ { "media-playback-pause", NC_("Stock label, media", "P_ause") },
+ { "media-playback-start", NC_("Stock label, media", "_Play") },
+ { "media-skip-backward", NC_("Stock label, media", "Pre_vious") },
+ { "media-record", NC_("Stock label, media", "_Record") },
+ { "media-seek-backward", NC_("Stock label, media", "R_ewind") },
+ { "media-playback-stop", NC_("Stock label, media", "_Stop") },
+ { "network-idle", NC_("Stock label", "_Network") },
+ { "document-new", NC_("Stock label", "_New") },
+ { "document-open", NC_("Stock label", "_Open") },
+ { "edit-paste", NC_("Stock label", "_Paste") },
+ { "document-print", NC_("Stock label", "_Print") },
+ { "document-print-preview", NC_("Stock label", "Print Pre_view") },
+ { "document-properties", NC_("Stock label", "_Properties") },
+ { "application-exit", NC_("Stock label", "_Quit") },
+ { "edit-redo", NC_("Stock label", "_Redo") },
+ { "view-refresh", NC_("Stock label", "_Refresh") },
+ { "list-remove", NC_("Stock label", "_Remove") },
+ { "document-revert", NC_("Stock label", "_Revert") },
+ { "document-save", NC_("Stock label", "_Save") },
+ { "document-save-as", NC_("Stock label", "Save _As") },
+ { "edit-select-all", NC_("Stock label", "Select _All") },
+ { "view-sort-ascending", NC_("Stock label", "_Ascending") },
+ { "view-sort-descending", NC_("Stock label", "_Descending") },
+ { "tools-check-spelling", NC_("Stock label", "_Spell Check") },
+ { "process-stop", NC_("Stock label", "_Stop") },
+ { "format-text-strikethrough", NC_("Stock label", "_Strikethrough") },
+ { "format-text-underline", NC_("Stock label", "_Underline") },
+ { "edit-undo", NC_("Stock label", "_Undo") },
+ { "format-indent-less", NC_("Stock label", "Decrease Indent") },
+ { "zoom-original", NC_("Stock label", "_Normal Size") },
+ { "zoom-fit-best", NC_("Stock label", "Best _Fit") },
+ { "zoom-in", NC_("Stock label", "Zoom _In") },
+ { "zoom-out", NC_("Stock label", "Zoom _Out") }
+};
+
+static gchar *
+name_from_icon_name (const gchar *icon_name)
+{
+ gchar *name;
+ const gchar *label;
+ gint i;
+
+ name = g_strdup (icon_name);
+ if (g_str_has_suffix (name, "-symbolic"))
+ name[strlen (name) - strlen ("-symbolic")] = '\0';
+
+ for (i = 0; i < G_N_ELEMENTS (name_map); i++)
+ {
+ if (g_str_equal (name, name_map[i].name))
+ {
+ label = g_dpgettext2 (GETTEXT_PACKAGE, "Stock label", name_map[i].label);
+ g_free (name);
+
+ return _gtk_toolbar_elide_underscores (label);
+ }
+ }
+
+ g_free (name);
+ return NULL;
+}
+
static void
gtk_image_accessible_finalize (GObject *object)
{
@@ -62,6 +174,7 @@ gtk_image_accessible_get_name (AtkObject *accessible)
GtkStockItem stock_item;
gchar *stock_id;
const gchar *name;
+ GtkImageType storage_type;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
if (widget == NULL)
@@ -77,21 +190,45 @@ gtk_image_accessible_get_name (AtkObject *accessible)
g_free (image_accessible->priv->stock_name);
image_accessible->priv->stock_name = NULL;
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
- if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK)
- return NULL;
+ storage_type = gtk_image_get_storage_type (image);
+ if (storage_type == GTK_IMAGE_STOCK)
+ {
+ gtk_image_get_stock (image, &stock_id, NULL);
+ if (stock_id == NULL)
+ return NULL;
- gtk_image_get_stock (image, &stock_id, NULL);
- if (stock_id == NULL)
- return NULL;
+ if (!gtk_stock_lookup (stock_id, &stock_item))
+ return NULL;
- if (!gtk_stock_lookup (stock_id, &stock_item))
- return NULL;
+g_print ("looking up stock %s\n", stock_id);
+G_GNUC_END_IGNORE_DEPRECATIONS;
- G_GNUC_END_IGNORE_DEPRECATIONS;
+ image_accessible->priv->stock_name = _gtk_toolbar_elide_underscores (stock_item.label);
+ }
+ else if (storage_type == GTK_IMAGE_ICON_NAME)
+ {
+ const gchar *icon_name;
+
+ gtk_image_get_icon_name (image, &icon_name, NULL);
+g_print ("looking up icon_name %s\n", icon_name);
+ image_accessible->priv->stock_name = name_from_icon_name (icon_name);
+ }
+ else if (storage_type == GTK_IMAGE_GICON)
+ {
+ GIcon *icon;
+ const gchar * const *icon_names;
+
+ gtk_image_get_gicon (image, &icon, NULL);
+ if (G_IS_THEMED_ICON (icon))
+ {
+ icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+g_print ("looking up gicon %s\n", icon_names[0]);
+ image_accessible->priv->stock_name = name_from_icon_name (icon_names[0]);
+ }
+ }
- image_accessible->priv->stock_name = _gtk_toolbar_elide_underscores (stock_item.label);
return image_accessible->priv->stock_name;
}