summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--ChangeLog.pre-2-1015
-rw-r--r--ChangeLog.pre-2-615
-rw-r--r--ChangeLog.pre-2-815
-rw-r--r--gtk/gtkaccelgroup.c49
-rw-r--r--gtk/gtkaccelgroup.h2
-rw-r--r--gtk/gtkaccellabel.c134
-rw-r--r--gtk/gtkaccellabel.h13
8 files changed, 189 insertions, 69 deletions
diff --git a/ChangeLog b/ChangeLog
index f5a7846040..459fbc2ac9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
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.
+
+2004-10-05 Matthias Clasen <mclasen@redhat.com>
+
* gtk/gtkcombobox.c (gtk_combo_box_set_model): Resize the
popup if a new model is set. (#154129, Bernd Demian)
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index f5a7846040..459fbc2ac9 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,5 +1,20 @@
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.
+
+2004-10-05 Matthias Clasen <mclasen@redhat.com>
+
* gtk/gtkcombobox.c (gtk_combo_box_set_model): Resize the
popup if a new model is set. (#154129, Bernd Demian)
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index f5a7846040..459fbc2ac9 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,5 +1,20 @@
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.
+
+2004-10-05 Matthias Clasen <mclasen@redhat.com>
+
* gtk/gtkcombobox.c (gtk_combo_box_set_model): Resize the
popup if a new model is set. (#154129, Bernd Demian)
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index f5a7846040..459fbc2ac9 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,5 +1,20 @@
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.
+
+2004-10-05 Matthias Clasen <mclasen@redhat.com>
+
* gtk/gtkcombobox.c (gtk_combo_box_set_model): Resize the
popup if a new model is set. (#154129, Bernd Demian)
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
diff --git a/gtk/gtkaccelgroup.h b/gtk/gtkaccelgroup.h
index b4f1b032e7..a9adf4af5b 100644
--- a/gtk/gtkaccelgroup.h
+++ b/gtk/gtkaccelgroup.h
@@ -148,6 +148,8 @@ void gtk_accelerator_parse (const gchar *accelerator,
GdkModifierType *accelerator_mods);
gchar* gtk_accelerator_name (guint accelerator_key,
GdkModifierType accelerator_mods);
+gchar* gtk_accelerator_display_name (guint accelerator_key,
+ GdkModifierType accelerator_mods);
void gtk_accelerator_set_default_mod_mask (GdkModifierType default_mod_mask);
guint gtk_accelerator_get_default_mod_mask (void);
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 ("-/-");
diff --git a/gtk/gtkaccellabel.h b/gtk/gtkaccellabel.h
index 9d15ba6a74..4eb842a610 100644
--- a/gtk/gtkaccellabel.h
+++ b/gtk/gtkaccellabel.h
@@ -34,10 +34,7 @@
#include <gtk/gtklabel.h>
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
+G_BEGIN_DECLS
#define GTK_TYPE_ACCEL_LABEL (gtk_accel_label_get_type ())
#define GTK_ACCEL_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ACCEL_LABEL, GtkAccelLabel))
@@ -97,9 +94,11 @@ void gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
GClosure *accel_closure);
gboolean gtk_accel_label_refetch (GtkAccelLabel *accel_label);
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+/* private */
+gchar * _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
+ guint accelerator_key,
+ GdkModifierType accelerator_mods);
+G_END_DECLS
#endif /* __GTK_ACCEL_LABEL_H__ */