diff options
author | Michael Natterer <mitch@lanedo.com> | 2011-09-16 16:12:23 +0200 |
---|---|---|
committer | Michael Natterer <mitch@gimp.org> | 2011-09-26 16:01:50 +0200 |
commit | 24a42839babddc8130226663a97453fe8b0f8d45 (patch) | |
tree | c38d8476162d93616e7d176c748e921daf1d248f /gtk/gtkaccelgroup.c | |
parent | 2a8be23d1717a9b48d957a7ccfce9032b1e18a64 (diff) | |
download | gtk+-24a42839babddc8130226663a97453fe8b0f8d45.tar.gz |
gtk: allow to specify accelerators in a platform-independent way
Introduce <Primary> in accelerator strings, which resolves to
GDK_CONTROL_MASK on X11/Win23, and to GDK_META_MASK on quartz.
Also serialize CONTROL/META as <Primary> depending on the platform.
Diffstat (limited to 'gtk/gtkaccelgroup.c')
-rw-r--r-- | gtk/gtkaccelgroup.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/gtk/gtkaccelgroup.c b/gtk/gtkaccelgroup.c index 7631ece85a..b134aa1a72 100644 --- a/gtk/gtkaccelgroup.c +++ b/gtk/gtkaccelgroup.c @@ -35,7 +35,7 @@ #include "gtkintl.h" #include "gtkmainprivate.h" #include "gtkmarshalers.h" - +#include "gtkprivate.h" /** * SECTION:gtkaccelgroup @@ -1152,6 +1152,20 @@ is_hyper (const gchar *string) (string[6] == '>')); } +static inline gboolean +is_primary (const gchar *string) +{ + return ((string[0] == '<') && + (string[1] == 'p' || string[1] == 'P') && + (string[2] == 'r' || string[2] == 'R') && + (string[3] == 'i' || string[3] == 'I') && + (string[4] == 'm' || string[4] == 'M') && + (string[5] == 'a' || string[5] == 'A') && + (string[6] == 'r' || string[6] == 'R') && + (string[7] == 'y' || string[7] == 'Y') && + (string[8] == '>')); +} + /** * gtk_accelerator_parse: * @accelerator: string representing an accelerator @@ -1201,6 +1215,12 @@ gtk_accelerator_parse (const gchar *accelerator, len -= 9; mods |= GDK_RELEASE_MASK; } + else if (len >= 9 && is_primary (accelerator)) + { + accelerator += 9; + len -= 9; + mods |= GTK_DEFAULT_ACCEL_MOD_MASK; + } else if (len >= 9 && is_control (accelerator)) { accelerator += 9; @@ -1314,6 +1334,7 @@ gtk_accelerator_name (guint accelerator_key, GdkModifierType accelerator_mods) { static const gchar text_release[] = "<Release>"; + static const gchar text_primary[] = "<Primary>"; static const gchar text_shift[] = "<Shift>"; static const gchar text_control[] = "<Control>"; static const gchar text_mod1[] = "<Alt>"; @@ -1324,6 +1345,7 @@ gtk_accelerator_name (guint accelerator_key, static const gchar text_meta[] = "<Meta>"; static const gchar text_super[] = "<Super>"; static const gchar text_hyper[] = "<Hyper>"; + GdkModifierType saved_mods; guint l; gchar *keyval_name; gchar *accelerator; @@ -1334,9 +1356,15 @@ gtk_accelerator_name (guint accelerator_key, if (!keyval_name) keyval_name = ""; + saved_mods = accelerator_mods; l = 0; if (accelerator_mods & GDK_RELEASE_MASK) l += sizeof (text_release) - 1; + if (accelerator_mods & GTK_DEFAULT_ACCEL_MOD_MASK) + { + l += sizeof (text_primary) - 1; + accelerator_mods &= ~GTK_DEFAULT_ACCEL_MOD_MASK; /* consume the default accel */ + } if (accelerator_mods & GDK_SHIFT_MASK) l += sizeof (text_shift) - 1; if (accelerator_mods & GDK_CONTROL_MASK) @@ -1361,6 +1389,7 @@ gtk_accelerator_name (guint accelerator_key, accelerator = g_new (gchar, l + 1); + accelerator_mods = saved_mods; l = 0; accelerator[l] = 0; if (accelerator_mods & GDK_RELEASE_MASK) @@ -1368,6 +1397,12 @@ gtk_accelerator_name (guint accelerator_key, strcpy (accelerator + l, text_release); l += sizeof (text_release) - 1; } + if (accelerator_mods & GTK_DEFAULT_ACCEL_MOD_MASK) + { + strcpy (accelerator + l, text_primary); + l += sizeof (text_primary) - 1; + accelerator_mods &= ~GTK_DEFAULT_ACCEL_MOD_MASK; /* consume the default accel */ + } if (accelerator_mods & GDK_SHIFT_MASK) { strcpy (accelerator + l, text_shift); |