X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkaccellabel.c;h=d8bb7e96fa4069247059cc3183863c7fdc3af6ec;hb=32aa7f0582febb614c41e4130ad34ac44ef6efd2;hp=3b6ac41bbd218489eb632116ee54903407c29c5e;hpb=221442aa2a4da11f8b342e0e0696cdb1228b9e29;p=~andy%2Fgtk diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c index 3b6ac41bb..d8bb7e96f 100644 --- a/gtk/gtkaccellabel.c +++ b/gtk/gtkaccellabel.c @@ -15,9 +15,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library. If not, see . */ /* @@ -106,6 +104,9 @@ struct _GtkAccelLabelPrivate gchar *accel_string; /* has set function */ guint accel_padding; /* should be style property? */ guint16 accel_string_width; /* seems to be private */ + + guint accel_key; /* manual accel key specification if != 0 */ + GdkModifierType accel_mods; }; static void gtk_accel_label_set_property (GObject *object, @@ -835,12 +836,13 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass, #endif seen_mod = TRUE; } - if (seen_mod) - g_string_append (gstring, klass->mod_separator); ch = gdk_keyval_to_unicode (accelerator_key); if (ch && ch < 0x80 && (g_unichar_isgraph (ch) || ch == ' ')) { + if (seen_mod) + g_string_append (gstring, klass->mod_separator); + switch (ch) { case ' ': @@ -861,6 +863,9 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass, tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key)); if (tmp != NULL) { + if (seen_mod) + g_string_append (gstring, klass->mod_separator); + if (tmp[0] != 0 && tmp[1] == 0) g_string_append_c (gstring, g_ascii_toupper (tmp[0])); else @@ -905,26 +910,52 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label) "gtk-enable-accels", &enable_accels, NULL); - if (enable_accels && accel_label->priv->accel_closure) + if (enable_accels && (accel_label->priv->accel_closure || accel_label->priv->accel_key)) { - GtkAccelKey *key = gtk_accel_group_find (accel_label->priv->accel_group, find_accel, accel_label->priv->accel_closure); + gboolean have_accel = FALSE; + guint accel_key; + GdkModifierType accel_mods; + + /* First check for a manual accel set with _set_accel() */ + if (accel_label->priv->accel_key) + { + accel_mods = accel_label->priv->accel_mods; + accel_key = accel_label->priv->accel_key; + have_accel = TRUE; + } - if (key && key->accel_flags & GTK_ACCEL_VISIBLE) + /* If we don't have a hardcoded value, check the accel group */ + if (!have_accel) + { + GtkAccelKey *key; + + key = gtk_accel_group_find (accel_label->priv->accel_group, find_accel, accel_label->priv->accel_closure); + + if (key && key->accel_flags & GTK_ACCEL_VISIBLE) + { + accel_key = key->accel_key; + accel_mods = key->accel_mods; + have_accel = TRUE; + } + } + + /* If we found a key using either method, set it */ + if (have_accel) { 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); + tmp = _gtk_accel_label_class_get_accelerator_label (klass, accel_key, accel_mods); accel_label->priv->accel_string = g_strconcat (" ", tmp, NULL); g_free (tmp); } - if (!accel_label->priv->accel_string) - accel_label->priv->accel_string = g_strdup ("-/-"); + + else + /* Otherwise we have a closure with no key. Show "-/-". */ + accel_label->priv->accel_string = g_strdup ("-/-"); } - + if (!accel_label->priv->accel_string) accel_label->priv->accel_string = g_strdup (""); @@ -932,3 +963,30 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label) return FALSE; } + +/** + * gtk_accel_label_set_accel: + * @accel_label: a #GtkAccelLabel + * @accelerator_key: a keyval, or 0 + * @accelerator_mods: the modifier mask for the accel + * + * Manually sets a keyval and modifier mask as the accelerator rendered + * by @accel_label. + * + * If a keyval and modifier are explicitly set then these values are + * used regardless of any associated accel closure or widget. + * + * Providing an @accelerator_key of 0 removes the manual setting. + * + * Since: 3.6 + */ +void +gtk_accel_label_set_accel (GtkAccelLabel *accel_label, + guint accelerator_key, + GdkModifierType accelerator_mods) +{ + accel_label->priv->accel_key = accelerator_key; + accel_label->priv->accel_mods = accelerator_mods; + + gtk_accel_label_reset (accel_label); +}