aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSnjezana Peco2014-05-25 16:52:21 (EDT)
committerAlexander Kurtakov2014-07-16 04:43:48 (EDT)
commit5e84f7bd99a883a2b08c1d596f44e1e38be759a1 (patch)
tree50843ab621bf45c9a10c515e1b827a2bf8e96b68
parent2788992449f42c68294c7306e4dbf7f44afd21ac (diff)
downloadeclipse.platform.swt-5e84f7bd99a883a2b08c1d596f44e1e38be759a1.zip
eclipse.platform.swt-5e84f7bd99a883a2b08c1d596f44e1e38be759a1.tar.gz
eclipse.platform.swt-5e84f7bd99a883a2b08c1d596f44e1e38be759a1.tar.bz2
Bug 417601 - [GTK3] Menu items are missing keyboard shortcutsrefs/changes/47/27247/10
Change-Id: I680e70d8b93619d47543176216f6374ce1235992 Signed-off-by: Snjezana Peco <snjeza.peco@gmail.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c18
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h15
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java17
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java142
6 files changed, 135 insertions, 59 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
index 813f451..c53f7f7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
@@ -8742,6 +8742,24 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1accel_1label_1set_1accel_1widget)
}
#endif
+#ifndef NO__1gtk_1accel_1label_1set_1accel
+JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1accel_1label_1set_1accel)
+ (JNIEnv *env, jclass that, jintLong arg0, jint arg1, jint arg2)
+{
+ OS_NATIVE_ENTER(env, that, _1gtk_1accel_1label_1set_1accel_FUNC);
+/*
+ gtk_accel_label_set_accel((GtkAccelLabel *)arg0, (guint)arg1, (GdkModifierType)arg2);
+*/
+ {
+ OS_LOAD_FUNCTION(fp, gtk_accel_label_set_accel)
+ if (fp) {
+ ((void (CALLING_CONVENTION*)(GtkAccelLabel *, jint, jint))fp)((GtkAccelLabel *)arg0, arg1, arg2);
+ }
+ }
+ OS_NATIVE_EXIT(env, that, _1gtk_1accel_1label_1set_1accel_FUNC);
+}
+#endif
+
#ifndef NO__1gtk_1accelerator_1get_1default_1mod_1mask
JNIEXPORT jint JNICALL OS_NATIVE(_1gtk_1accelerator_1get_1default_1mod_1mask)
(JNIEnv *env, jclass that)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
index 3da016b..05550ad 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
@@ -516,7 +516,7 @@
#define gtk_css_provider_new_LIB LIB_GTK
#define gtk_icon_set_render_icon_pixbuf_LIB LIB_GTK
#define gtk_drag_set_icon_surface_LIB LIB_GTK
-
+#define gtk_accel_label_set_accel_LIB LIB_GTK
#ifndef g_thread_supported
#define g_thread_supported() 0
#endif
@@ -527,9 +527,18 @@
#endif
#define G_OBJECT_CLASS_CONSTRUCTOR(arg0) (arg0)->constructor
#define G_OBJECT_CLASS_SET_CONSTRUCTOR(arg0, arg1) (arg0)->constructor = (GObject* (*) (GType, guint, GObjectConstructParam *))arg1
+struct _GtkAccelLabelPrivate
+{
+ GtkWidget *accel_widget; /* done */
+ GClosure *accel_closure; /* has set function */
+ GtkAccelGroup *accel_group; /* set by set_accel_closure() */
+ gchar *accel_string; /* has set function */
+ guint accel_padding; /* should be style property? */
+ guint16 accel_string_width; /* seems to be private */
+};
#if GTK_CHECK_VERSION(3,0,0)
-#define GTK_ACCEL_LABEL_SET_ACCEL_STRING(arg0, arg1)
-#define GTK_ACCEL_LABEL_GET_ACCEL_STRING(arg0) 0
+#define GTK_ACCEL_LABEL_SET_ACCEL_STRING(arg0, arg1) (arg0)->priv->accel_string = arg1
+#define GTK_ACCEL_LABEL_GET_ACCEL_STRING(arg0) (arg0)->priv->accel_string
#else
#define GTK_ACCEL_LABEL_SET_ACCEL_STRING(arg0, arg1) (arg0)->accel_string = arg1
#define GTK_ACCEL_LABEL_GET_ACCEL_STRING(arg0) (arg0)->accel_string
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
index 16d6664..088fdb53 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
@@ -646,6 +646,7 @@ char * OS_nativeFunctionNames[] = {
"_1glib_1minor_1version",
"_1gtk_1accel_1group_1new",
"_1gtk_1accel_1label_1set_1accel_1widget",
+ "_1gtk_1accel_1label_1set_1accel",
"_1gtk_1accelerator_1get_1default_1mod_1mask",
"_1gtk_1accelerator_1parse",
"_1gtk_1accessible_1get_1widget",
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
index 78460d0..0583166 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
@@ -656,6 +656,7 @@ typedef enum {
_1glib_1minor_1version_FUNC,
_1gtk_1accel_1group_1new_FUNC,
_1gtk_1accel_1label_1set_1accel_1widget_FUNC,
+ _1gtk_1accel_1label_1set_1accel_FUNC,
_1gtk_1accelerator_1get_1default_1mod_1mask_FUNC,
_1gtk_1accelerator_1parse_FUNC,
_1gtk_1accessible_1get_1widget_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
index ab42819..9baad0b 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
@@ -136,6 +136,7 @@ public class OS extends C {
public static final int GDK_EXPOSURE_MASK = 0x2;
public static final int GDK_End = 0xff57;
public static final int GDK_Escape = 0xff1b;
+ public static final int GDK_ISO_Enter = 0xfe34;
public static final int GDK_F1 = 0xffbe;
public static final int GDK_F10 = 0xffc7;
public static final int GDK_F11 = 0xffc8;
@@ -508,6 +509,7 @@ public class OS extends C {
public static final int XA_WINDOW = 33;
/** Signals */
+ public static final byte[] accel_closures_changed = ascii("accel-closures-changed");
public static final byte[] activate = ascii("activate");
public static final byte[] backspace = ascii("backspace");
public static final byte[] button_press_event = ascii("button-press-event");
@@ -6192,6 +6194,21 @@ public static final void gtk_accel_label_set_accel_widget(long /*int*/ accel_lab
}
/**
* @method flags=dynamic
+ * @param accel_label cast=(GtkAccelLabel *)
+ * @param accel_key cast=(guint)
+ * @param accel_mods cast=(GdkModifierType)
+ */
+public static final native void _gtk_accel_label_set_accel(long /*int*/ accel_label, int accel_key, int accel_mods);
+public static final void gtk_accel_label_set_accel(long /*int*/ accel_label, int accel_key, int accel_mods) {
+ lock.lock();
+ try {
+ _gtk_accel_label_set_accel(accel_label, accel_key, accel_mods);
+ } finally {
+ lock.unlock();
+ }
+}
+/**
+ * @method flags=dynamic
* @param accessible cast=(GtkAccessible *)
*/
public static final native long /*int*/ _gtk_accessible_get_widget(long /*int*/ accessible);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
index 6cc3d48..05552d9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java
@@ -901,18 +901,33 @@ public void setText (String string) {
if (OS.GTK_IS_ACCEL_LABEL(label)) {
if (OS.GTK3) {
OS.gtk_accel_label_set_accel_widget(label, handle);
+ if (OS.GTK_VERSION >= OS.VERSION(3, 6, 0)) {
+ MaskKeysym maskKeysym = getMaskKeysym();
+ if (maskKeysym != null) {
+ OS.gtk_accel_label_set_accel(label,
+ maskKeysym.keysym, maskKeysym.mask);
+ }
+ } else {
+ setAccelLabel(label, accelString);
+ }
} else {
- buffer = Converter.wcsToMbcs (null, accelString, true);
- long /*int*/ ptr = OS.g_malloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- long /*int*/ oldPtr = OS.GTK_ACCEL_LABEL_GET_ACCEL_STRING (label);
- OS.GTK_ACCEL_LABEL_SET_ACCEL_STRING (label, ptr);
- if (oldPtr != 0) OS.g_free (oldPtr);
+ setAccelLabel(label, accelString);
}
+ // A workaround for Ubuntu Unity global menu
+ OS.g_signal_emit_by_name(handle, OS.accel_closures_changed);
}
}
}
+private void setAccelLabel(long /*int*/ label, String accelString) {
+ byte[] buffer = Converter.wcsToMbcs (null, accelString, true);
+ long /*int*/ ptr = OS.g_malloc (buffer.length);
+ OS.memmove (ptr, buffer, buffer.length);
+ long /*int*/ oldPtr = OS.GTK_ACCEL_LABEL_GET_ACCEL_STRING (label);
+ OS.GTK_ACCEL_LABEL_SET_ACCEL_STRING (label, ptr);
+ if (oldPtr != 0) OS.g_free (oldPtr);
+}
+
void updateAccelerator (long /*int*/ accelGroup, boolean add) {
if (accelerator == 0 || !getEnabled ()) return;
if ((accelerator & SWT.COMMAND) != 0) return;
@@ -940,65 +955,80 @@ void updateAccelerator (long /*int*/ accelGroup, boolean add) {
}
}
+private class MaskKeysym {
+ int mask = 0;
+ int keysym = 0;
+}
+
+private MaskKeysym getMaskKeysym() {
+ if (text == null) return null;
+ MaskKeysym maskKeysym = new MaskKeysym();
+ int accelIndex = text.indexOf ('\t');
+ if (accelIndex == -1) return null;
+ int start = accelIndex + 1;
+ int plusIndex = text.indexOf('+', start);
+ while (plusIndex != -1) {
+ String maskStr = text.substring(start, plusIndex);
+ if (maskStr.equals("Ctrl")) maskKeysym.mask |= OS.GDK_CONTROL_MASK;
+ if (maskStr.equals("Shift")) maskKeysym.mask |= OS.GDK_SHIFT_MASK;
+ if (maskStr.equals("Alt")) maskKeysym.mask |= OS.GDK_MOD1_MASK;
+ start = plusIndex + 1;
+ plusIndex = text.indexOf('+', start);
+ }
+ if ("Enter".equals(text.substring(start))) {
+ maskKeysym.keysym = OS.GDK_ISO_Enter;
+ }
+ switch (text.length() - start) {
+ case 1:
+ maskKeysym.keysym = text.charAt(start);
+ maskKeysym.keysym = Display.wcsToMbcs ((char) maskKeysym.keysym);
+ break;
+ case 2:
+ if (text.charAt(start) == 'F') {
+ switch (text.charAt(start + 1)) {
+ case '1': maskKeysym.keysym = OS.GDK_F1; break;
+ case '2': maskKeysym.keysym = OS.GDK_F2; break;
+ case '3': maskKeysym.keysym = OS.GDK_F3; break;
+ case '4': maskKeysym.keysym = OS.GDK_F4; break;
+ case '5': maskKeysym.keysym = OS.GDK_F5; break;
+ case '6': maskKeysym.keysym = OS.GDK_F6; break;
+ case '7': maskKeysym.keysym = OS.GDK_F7; break;
+ case '8': maskKeysym.keysym = OS.GDK_F8; break;
+ case '9': maskKeysym.keysym = OS.GDK_F9; break;
+ }
+ }
+ break;
+ case 3:
+ if (text.charAt(start) == 'F' && text.charAt(start + 1) == '1') {
+ switch (text.charAt(start + 2)) {
+ case '0': maskKeysym.keysym = OS.GDK_F10; break;
+ case '1': maskKeysym.keysym = OS.GDK_F11; break;
+ case '2': maskKeysym.keysym = OS.GDK_F12; break;
+ case '3': maskKeysym.keysym = OS.GDK_F13; break;
+ case '4': maskKeysym.keysym = OS.GDK_F14; break;
+ case '5': maskKeysym.keysym = OS.GDK_F15; break;
+ }
+ }
+ break;
+ }
+ return maskKeysym;
+}
boolean updateAcceleratorText (boolean show) {
if (accelerator != 0) return false;
- int mask = 0, keysym = 0;
+ MaskKeysym maskKeysym = null;
if (show) {
- int accelIndex = text.indexOf ('\t');
- if (accelIndex == -1) return true;
- int start = accelIndex + 1;
- int plusIndex = text.indexOf('+', start);
- while (plusIndex != -1) {
- String maskStr = text.substring(start, plusIndex);
- if (maskStr.equals("Ctrl")) mask |= OS.GDK_CONTROL_MASK;
- if (maskStr.equals("Shift")) mask |= OS.GDK_SHIFT_MASK;
- if (maskStr.equals("Alt")) mask |= OS.GDK_MOD1_MASK;
- start = plusIndex + 1;
- plusIndex = text.indexOf('+', start);
- }
- switch (text.length() - start) {
- case 1:
- keysym = text.charAt(start);
- keysym = Display.wcsToMbcs ((char) keysym);
- break;
- case 2:
- if (text.charAt(start) == 'F') {
- switch (text.charAt(start + 1)) {
- case '1': keysym = OS.GDK_F1; break;
- case '2': keysym = OS.GDK_F2; break;
- case '3': keysym = OS.GDK_F3; break;
- case '4': keysym = OS.GDK_F4; break;
- case '5': keysym = OS.GDK_F5; break;
- case '6': keysym = OS.GDK_F6; break;
- case '7': keysym = OS.GDK_F7; break;
- case '8': keysym = OS.GDK_F8; break;
- case '9': keysym = OS.GDK_F9; break;
- }
- }
- break;
- case 3:
- if (text.charAt(start) == 'F' && text.charAt(start + 1) == '1') {
- switch (text.charAt(start + 2)) {
- case '0': keysym = OS.GDK_F10; break;
- case '1': keysym = OS.GDK_F11; break;
- case '2': keysym = OS.GDK_F12; break;
- case '3': keysym = OS.GDK_F13; break;
- case '4': keysym = OS.GDK_F14; break;
- case '5': keysym = OS.GDK_F15; break;
- }
- }
- break;
- }
+ maskKeysym = getMaskKeysym();
}
- if (keysym != 0) {
+ if (maskKeysym == null) return true;
+ if (maskKeysym.keysym != 0) {
long /*int*/ accelGroup = getAccelGroup ();
if (show) {
- OS.gtk_widget_add_accelerator (handle, OS.activate, accelGroup, keysym, mask, OS.GTK_ACCEL_VISIBLE);
+ OS.gtk_widget_add_accelerator (handle, OS.activate, accelGroup, maskKeysym.keysym, maskKeysym.mask, OS.GTK_ACCEL_VISIBLE);
} else {
- OS.gtk_widget_remove_accelerator (handle, accelGroup, keysym, mask);
+ OS.gtk_widget_remove_accelerator (handle, accelGroup, maskKeysym.keysym, maskKeysym.mask);
}
}
- return keysym != 0;
+ return maskKeysym.keysym != 0;
}
}