diff options
author | Matthias Clasen <mclasen@redhat.com> | 2004-10-05 05:17:22 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2004-10-05 05:17:22 +0000 |
commit | 0dfe684dde3e88d42dba6a6e434b4e2ca3c6eec7 (patch) | |
tree | 3e03b663dadfb7005e7e5dfbeb21710d22f47459 /gtk/gtkaccellabel.c | |
parent | 8e30e2d5c3ccc8845254d5029273dc731da199dc (diff) | |
download | gtk+-0dfe684dde3e88d42dba6a6e434b4e2ca3c6eec7.tar.gz |
Provide access to the string representation of accelerators used in
2004-10-05 Matthias Clasen <mclasen@redhat.com>
Provide access to the string representation of accelerators used
in GtkAccelLabel. (#154068, John Spray)
* gtk/gtkaccelgroup.h:
* gtk/gtkaccelgroup.c (gtk_accelerator_get_label): New function
to return the accelerator label used in GtkAccelLabel.
(gtk_accelerator_name): Update docs to point to
gtk_accelerator_get_label().
* gtk/gtkaccellabel.h:
* gtk/gtkaccellabel.c (_gtk_accel_label_class_get_accelerator_label):
New auxiliary function which creates the string representing the
accelerator.
Diffstat (limited to 'gtk/gtkaccellabel.c')
-rw-r--r-- | gtk/gtkaccellabel.c | 134 |
1 files changed, 74 insertions, 60 deletions
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c index 8392552b73..73b27e52a5 100644 --- a/gtk/gtkaccellabel.c +++ b/gtk/gtkaccellabel.c @@ -528,6 +528,71 @@ substitute_underscores (char *str) *p = ' '; } +gchar * +_gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass, + guint accelerator_key, + GdkModifierType accelerator_mods) +{ + GString *gstring; + gboolean seen_mod = FALSE; + gunichar ch; + + gstring = g_string_new (""); + + if (accelerator_mods & GDK_SHIFT_MASK) + { + g_string_append (gstring, klass->mod_name_shift); + seen_mod = TRUE; + } + if (accelerator_mods & GDK_CONTROL_MASK) + { + if (seen_mod) + g_string_append (gstring, klass->mod_separator); + g_string_append (gstring, klass->mod_name_control); + seen_mod = TRUE; + } + if (accelerator_mods & GDK_MOD1_MASK) + { + if (seen_mod) + g_string_append (gstring, klass->mod_separator); + g_string_append (gstring, klass->mod_name_alt); + seen_mod = TRUE; + } + if (seen_mod) + g_string_append (gstring, klass->mod_separator); + + ch = gdk_keyval_to_unicode (accelerator_key); + if (ch && (g_unichar_isgraph (ch) || ch == ' ') && + (ch < 0x80 || klass->latin1_to_char)) + { + switch (ch) + { + case ' ': + g_string_append (gstring, "Space"); + break; + case '\\': + g_string_append (gstring, "Backslash"); + break; + default: + g_string_append_unichar (gstring, g_unichar_toupper (ch)); + break; + } + } + else + { + 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); + } + + return g_string_free (gstring, FALSE); +} + gboolean gtk_accel_label_refetch (GtkAccelLabel *accel_label) { @@ -549,66 +614,15 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label) if (key && key->accel_flags & GTK_ACCEL_VISIBLE) { - GString *gstring; - gboolean seen_mod = FALSE; - gunichar ch; - - gstring = g_string_new (accel_label->accel_string); - g_string_append (gstring, gstring->len ? class->accel_seperator : " "); - - if (key->accel_mods & GDK_SHIFT_MASK) - { - g_string_append (gstring, class->mod_name_shift); - seen_mod = TRUE; - } - if (key->accel_mods & GDK_CONTROL_MASK) - { - if (seen_mod) - g_string_append (gstring, class->mod_separator); - g_string_append (gstring, class->mod_name_control); - seen_mod = TRUE; - } - if (key->accel_mods & GDK_MOD1_MASK) - { - if (seen_mod) - g_string_append (gstring, class->mod_separator); - g_string_append (gstring, class->mod_name_alt); - seen_mod = TRUE; - } - if (seen_mod) - g_string_append (gstring, class->mod_separator); - - ch = gdk_keyval_to_unicode (key->accel_key); - if (ch && (g_unichar_isgraph (ch) || ch == ' ') && - (ch < 0x80 || class->latin1_to_char)) - { - switch (ch) - { - case ' ': - g_string_append (gstring, "Space"); - break; - case '\\': - g_string_append (gstring, "Backslash"); - break; - default: - g_string_append_unichar (gstring, g_unichar_toupper (ch)); - break; - } - } - else - { - gchar *tmp; - - tmp = gtk_accelerator_name (key->accel_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); - } - g_free (accel_label->accel_string); - accel_label->accel_string = gstring->str; - g_string_free (gstring, FALSE); + GtkAccelLabelClass *klass; + gchar *tmp; + + klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label); + tmp = _gtk_accel_label_class_get_accelerator_label (klass, + key->accel_key, + key->accel_mods); + accel_label->accel_string = g_strconcat (" ", tmp, NULL); + g_free (tmp); } if (!accel_label->accel_string) accel_label->accel_string = g_strdup ("-/-"); |