summaryrefslogtreecommitdiff
path: root/gtk/gtkaccelgroup.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2004-10-05 05:17:22 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2004-10-05 05:17:22 +0000
commit0dfe684dde3e88d42dba6a6e434b4e2ca3c6eec7 (patch)
tree3e03b663dadfb7005e7e5dfbeb21710d22f47459 /gtk/gtkaccelgroup.c
parent8e30e2d5c3ccc8845254d5029273dc731da199dc (diff)
downloadgtk+-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/gtkaccelgroup.c')
-rw-r--r--gtk/gtkaccelgroup.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/gtk/gtkaccelgroup.c b/gtk/gtkaccelgroup.c
index e9607b7670..038d73179e 100644
--- a/gtk/gtkaccelgroup.c
+++ b/gtk/gtkaccelgroup.c
@@ -30,7 +30,9 @@
#include "gtkalias.h"
#include "gtkaccelgroup.h"
+#include "gtkaccellabel.h" /* For _gtk_accel_label_class_get_accelerator_label */
#include "gtkaccelmap.h"
+#include "gtkintl.h"
#include "gtkmain.h" /* For _gtk_boolean_handled_accumulator */
#include "gdk/gdkkeysyms.h"
#include "gtkmarshalers.h"
@@ -1056,14 +1058,16 @@ gtk_accelerator_parse (const gchar *accelerator,
* gtk_accelerator_name:
* @accelerator_key: accelerator keyval
* @accelerator_mods: accelerator modifier mask
- * @returns: a newly-allocated accelerator name
*
* Converts an accelerator keyval and modifier mask
* into a string parseable by gtk_accelerator_parse().
* For example, if you pass in #GDK_q and #GDK_CONTROL_MASK,
* this function returns "&lt;Control&gt;q".
*
- * The caller of this function must free the returned string.
+ * If you need to display accelerators in the user interface,
+ * see gtk_accelerator_get_label().
+ *
+ * Returns: a newly-allocated accelerator name
*/
gchar*
gtk_accelerator_name (guint accelerator_key,
@@ -1155,6 +1159,47 @@ gtk_accelerator_name (guint accelerator_key,
return accelerator;
}
+/* Underscores in key names are better displayed as spaces
+ * E.g., Page_Up should be "Page Up"
+ */
+static void
+substitute_underscores (char *str)
+{
+ char *p;
+
+ for (p = str; *p; p++)
+ if (*p == '_')
+ *p = ' ';
+}
+
+/**
+ * gtk_accelerator_get_label:
+ * @accelerator_key: accelerator keyval
+ * @accelerator_mods: accelerator modifier mask
+ *
+ * Converts an accelerator keyval and modifier mask into a string
+ * which can be used to represent the accelerator to the user.
+ *
+ * Returns: a newly-allocated string representing the accelerator.
+ *
+ * Since: 2.6
+ */
+gchar*
+gtk_accelerator_get_label (guint accelerator_key,
+ GdkModifierType accelerator_mods)
+{
+ GtkAccelLabelClass *klass;
+ gchar *label;
+
+ klass = g_type_class_ref (GTK_TYPE_ACCEL_LABEL);
+ label = _gtk_accel_label_class_get_accelerator_label (klass,
+ accelerator_key,
+ accelerator_mods);
+ g_type_class_unref (klass); /* klass is kept alive since gtk uses static types */
+
+ return label;
+}
+
/**
* gtk_accelerator_set_default_mod_mask:
* @default_mod_mask: accelerator modifier mask