* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include <config.h>
+#include "config.h"
#include <string.h>
#include "gtkaccellabel.h"
#include "gtkaccelmap.h"
#include "gtkmain.h"
+#include "gtkprivate.h"
#include "gtkintl.h"
#include "gtkalias.h"
+#include <gdk/gdkkeysyms.h>
enum {
PROP_0,
PROP_ACCEL_WIDGET
};
-static void gtk_accel_label_class_init (GtkAccelLabelClass *klass);
-static void gtk_accel_label_init (GtkAccelLabel *accel_label);
static void gtk_accel_label_set_property (GObject *object,
guint prop_id,
const GValue *value,
static const gchar *gtk_accel_label_get_string (GtkAccelLabel *accel_label);
-static GtkLabelClass *parent_class = NULL;
-
-GType
-gtk_accel_label_get_type (void)
-{
- static GType accel_label_type = 0;
-
- if (!accel_label_type)
- {
- static const GTypeInfo accel_label_info =
- {
- sizeof (GtkAccelLabelClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_accel_label_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkAccelLabel),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_accel_label_init,
- };
-
- accel_label_type =
- g_type_register_static (GTK_TYPE_LABEL, "GtkAccelLabel",
- &accel_label_info, 0);
- }
-
- return accel_label_type;
-}
+G_DEFINE_TYPE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_LABEL)
static void
gtk_accel_label_class_init (GtkAccelLabelClass *class)
GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
- parent_class = g_type_class_peek_parent (class);
-
gobject_class->finalize = gtk_accel_label_finalize;
gobject_class->set_property = gtk_accel_label_set_property;
gobject_class->get_property = gtk_accel_label_get_property;
class->signal_quote1 = g_strdup ("<:");
class->signal_quote2 = g_strdup (":>");
+
+#ifndef GDK_WINDOWING_QUARTZ
/* This is the text that should appear next to menu accelerators
* that use the shift key. If the text on this key isn't typically
* translated on keyboards used for your language, don't translate
* this.
+ *
+ * Don't include the prefix "keyboard label|" in the translation.
*/
- class->mod_name_shift = g_strdup (_("Shift"));
+ class->mod_name_shift = g_strdup (Q_("keyboard label|Shift"));
/* This is the text that should appear next to menu accelerators
* that use the control key. If the text on this key isn't typically
* translated on keyboards used for your language, don't translate
* this.
+ *
+ * Don't include the prefix "keyboard label|" in the translation.
*/
- class->mod_name_control = g_strdup (_("Ctrl"));
+ class->mod_name_control = g_strdup (Q_("keyboard label|Ctrl"));
/* This is the text that should appear next to menu accelerators
* that use the alt key. If the text on this key isn't typically
* translated on keyboards used for your language, don't translate
* this.
+ *
+ * Don't include the prefix "keyboard label|" in the translation.
*/
- class->mod_name_alt = g_strdup (_("Alt"));
+ class->mod_name_alt = g_strdup (Q_("keyboard label|Alt"));
class->mod_separator = g_strdup ("+");
+#else /* GDK_WINDOWING_QUARTZ */
+
+ /* U+21E7 UPWARDS WHITE ARROW */
+ class->mod_name_shift = g_strdup ("\xe2\x87\xa7");
+ /* U+2303 UP ARROWHEAD */
+ class->mod_name_control = g_strdup ("\xe2\x8c\x83");
+ /* U+2325 OPTION KEY */
+ class->mod_name_alt = g_strdup ("\xe2\x8c\xa5");
+ class->mod_separator = g_strdup ("");
+
+#endif /* GDK_WINDOWING_QUARTZ */
+
class->accel_seperator = g_strdup (" / ");
class->latin1_to_char = TRUE;
-#define STATIC_STRINGS G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
-
g_object_class_install_property (gobject_class,
PROP_ACCEL_CLOSURE,
g_param_spec_boxed ("accel-closure",
P_("Accelerator Closure"),
P_("The closure to be monitored for accelerator changes"),
G_TYPE_CLOSURE,
- G_PARAM_READWRITE|STATIC_STRINGS));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_ACCEL_WIDGET,
g_param_spec_object ("accel-widget",
P_("Accelerator Widget"),
P_("The widget to be monitored for accelerator changes"),
GTK_TYPE_WIDGET,
- G_PARAM_READWRITE|STATIC_STRINGS));
+ GTK_PARAM_READWRITE));
}
static void
gtk_accel_label_set_accel_widget (accel_label, NULL);
gtk_accel_label_set_accel_closure (accel_label, NULL);
- GTK_OBJECT_CLASS (parent_class)->destroy (object);
+ GTK_OBJECT_CLASS (gtk_accel_label_parent_class)->destroy (object);
}
static void
g_free (accel_label->accel_string);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
}
/**
PangoLayout *layout;
gint width;
- if (GTK_WIDGET_CLASS (parent_class)->size_request)
- GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
+ if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request)
+ GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request (widget, requisition);
layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
pango_layout_get_pixel_size (layout, &width, NULL);
pango_layout_get_width (label_layout)
- ac_width * PANGO_SCALE);
- if (GTK_WIDGET_CLASS (parent_class)->expose_event)
- GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+ if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
+ GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
if (direction == GTK_TEXT_DIR_RTL)
widget->allocation.x -= ac_width;
widget->allocation.width += ac_width;
}
else
{
- if (GTK_WIDGET_CLASS (parent_class)->expose_event)
- GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+ if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
+ GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
}
}
accel_label, G_CONNECT_SWAPPED);
refetch_widget_accel_closure (accel_label);
}
- g_object_notify (G_OBJECT (accel_label), "accel_widget");
+ g_object_notify (G_OBJECT (accel_label), "accel-widget");
}
}
accel_label, 0);
}
gtk_accel_label_reset (accel_label);
- g_object_notify (G_OBJECT (accel_label), "accel_closure");
+ g_object_notify (G_OBJECT (accel_label), "accel-closure");
}
}
*p = ' ';
}
+/* On Mac, if the key has symbolic representation (e.g. arrow keys),
+ * append it to gstring and return TRUE; otherwise return FALSE.
+ * See http://docs.info.apple.com/article.html?path=Mac/10.5/en/cdb_symbs.html
+ * for the list of special keys. */
+static gboolean
+append_keyval_symbol (guint accelerator_key,
+ GString *gstring)
+{
+#ifdef GDK_WINDOWING_QUARTZ
+ switch (accelerator_key)
+ {
+ case GDK_Return:
+ /* U+21A9 LEFTWARDS ARROW WITH HOOK */
+ g_string_append (gstring, "\xe2\x86\xa9");
+ return TRUE;
+
+ case GDK_ISO_Enter:
+ /* U+2324 UP ARROWHEAD BETWEEN TWO HORIZONTAL BARS */
+ g_string_append (gstring, "\xe2\x8c\xa4");
+ return TRUE;
+
+ case GDK_Left:
+ /* U+2190 LEFTWARDS ARROW */
+ g_string_append (gstring, "\xe2\x86\x90");
+ return TRUE;
+
+ case GDK_Up:
+ /* U+2191 UPWARDS ARROW */
+ g_string_append (gstring, "\xe2\x86\x91");
+ return TRUE;
+
+ case GDK_Right:
+ /* U+2192 RIGHTWARDS ARROW */
+ g_string_append (gstring, "\xe2\x86\x92");
+ return TRUE;
+
+ case GDK_Down:
+ /* U+2193 DOWNWARDS ARROW */
+ g_string_append (gstring, "\xe2\x86\x93");
+ return TRUE;
+
+ case GDK_Page_Up:
+ /* U+21DE UPWARDS ARROW WITH DOUBLE STROKE */
+ g_string_append (gstring, "\xe2\x87\x9e");
+ return TRUE;
+
+ case GDK_Page_Down:
+ /* U+21DF DOWNWARDS ARROW WITH DOUBLE STROKE */
+ g_string_append (gstring, "\xe2\x87\x9f");
+ return TRUE;
+
+ case GDK_Home:
+ /* U+2196 NORTH WEST ARROW */
+ g_string_append (gstring, "\xe2\x86\x96");
+ return TRUE;
+
+ case GDK_End:
+ /* U+2198 SOUTH EAST ARROW */
+ g_string_append (gstring, "\xe2\x86\x98");
+ return TRUE;
+
+ case GDK_Escape:
+ /* U+238B BROKEN CIRCLE WITH NORTHWEST ARROW */
+ g_string_append (gstring, "\xe2\x8e\x8b");
+ return TRUE;
+
+ case GDK_BackSpace:
+ /* U+232B ERASE TO THE LEFT */
+ g_string_append (gstring, "\xe2\x8c\xab");
+ return TRUE;
+
+ case GDK_Delete:
+ /* U+2326 ERASE TO THE RIGHT */
+ g_string_append (gstring, "\xe2\x8c\xa6");
+ return TRUE;
+
+ default:
+ return FALSE;
+ }
+#else /* !GDK_WINDOWING_QUARTZ */
+ return FALSE;
+#endif
+}
+
gchar *
_gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
guint accelerator_key,
g_string_append (gstring, klass->mod_name_alt);
seen_mod = TRUE;
}
+ if (accelerator_mods & GDK_MOD2_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ g_string_append (gstring, "Mod2");
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_MOD3_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ g_string_append (gstring, "Mod3");
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_MOD4_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ g_string_append (gstring, "Mod4");
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_MOD5_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ g_string_append (gstring, "Mod5");
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_SUPER_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ /* This is the text that should appear next to menu accelerators
+ * that use the super key. If the text on this key isn't typically
+ * translated on keyboards used for your language, don't translate
+ * this.
+ * And do not translate the part before the |.
+ */
+ g_string_append (gstring, Q_("keyboard label|Super"));
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_HYPER_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+ /* This is the text that should appear next to menu accelerators
+ * that use the hyper key. If the text on this key isn't typically
+ * translated on keyboards used for your language, don't translate
+ * this.
+ * And do not translate the part before the |.
+ */
+ g_string_append (gstring, Q_("keyboard label|Hyper"));
+ seen_mod = TRUE;
+ }
+ if (accelerator_mods & GDK_META_MASK)
+ {
+ if (seen_mod)
+ g_string_append (gstring, klass->mod_separator);
+
+#ifndef GDK_WINDOWING_QUARTZ
+ /* This is the text that should appear next to menu accelerators
+ * that use the meta key. If the text on this key isn't typically
+ * translated on keyboards used for your language, don't translate
+ * this.
+ * And do not translate the part before the |.
+ */
+ g_string_append (gstring, Q_("keyboard label|Meta"));
+#else
+ /* Command key symbol U+2318 PLACE OF INTEREST SIGN */
+ g_string_append (gstring, "\xe2\x8c\x98");
+#endif
+ seen_mod = TRUE;
+ }
if (seen_mod)
g_string_append (gstring, klass->mod_separator);
switch (ch)
{
case ' ':
- g_string_append (gstring, "Space");
+ /* do not translate the part before the | */
+ g_string_append (gstring, Q_("keyboard label|Space"));
break;
case '\\':
- g_string_append (gstring, "Backslash");
+ /* do not translate the part before the | */
+ g_string_append (gstring, Q_("keyboard label|Backslash"));
break;
default:
g_string_append_unichar (gstring, g_unichar_toupper (ch));
break;
}
}
- else
+ else if (!append_keyval_symbol (accelerator_key, gstring))
{
gchar *tmp;
-
- tmp = gtk_accelerator_name (accelerator_key, 0);
- if (tmp[0] != 0 && tmp[1] == 0)
- tmp[0] = g_ascii_toupper (tmp[0]);
- substitute_underscores (tmp);
- g_string_append (gstring, tmp);
- g_free (tmp);
+
+ tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
+ if (tmp != NULL)
+ {
+ if (tmp[0] != 0 && tmp[1] == 0)
+ g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
+ else
+ {
+ gchar msg[128];
+ gchar *str;
+
+ strcpy (msg, "keyboard label|");
+ g_strlcat (msg, tmp, 128);
+ str = _(msg);
+ if (str == msg)
+ {
+ g_string_append (gstring, tmp);
+ substitute_underscores (gstring->str);
+ }
+ else
+ g_string_append (gstring, str);
+ }
+ }
}
return g_string_free (gstring, FALSE);
gboolean
gtk_accel_label_refetch (GtkAccelLabel *accel_label)
{
- GtkAccelLabelClass *class;
+ gboolean enable_accels;
g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
- class = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
-
if (accel_label->accel_string)
{
g_free (accel_label->accel_string);
accel_label->accel_string = NULL;
}
- if (accel_label->accel_closure)
+ g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
+ "gtk-enable-accels", &enable_accels,
+ NULL);
+
+ if (enable_accels && accel_label->accel_closure)
{
GtkAccelKey *key = gtk_accel_group_find (accel_label->accel_group, find_accel, accel_label->accel_closure);