Bug 572829 - Allow disabling "insert emoji" context menu entry in GTK+

With this change, SWT allows disabling the "Insert Emoji" context menu
entry added to text fields by GTK3. This is made available on GTK3, for
GTK 3.22.20+ (as the option for this is available only after this GTK3
version).

The menu entry can be disabled by providing command line argument:

-DSWT_GTK_INPUT_HINT_NO_EMOJI=true

Change-Id: Icc8d206b2a6fb492aa6979befe23312742b9e44c
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
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 c01f1ea..be5a0fd 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
@@ -5324,6 +5324,16 @@
 }
 #endif
 
+#ifndef NO_gtk_1entry_1set_1input_1hints
+JNIEXPORT void JNICALL GTK_NATIVE(gtk_1entry_1set_1input_1hints)
+	(JNIEnv *env, jclass that, jlong arg0, jint arg1)
+{
+	GTK_NATIVE_ENTER(env, that, gtk_1entry_1set_1input_1hints_FUNC);
+	gtk_entry_set_input_hints((GtkEntry *)arg0, (GtkInputHints)arg1);
+	GTK_NATIVE_EXIT(env, that, gtk_1entry_1set_1input_1hints_FUNC);
+}
+#endif
+
 #ifndef NO_gtk_1entry_1set_1invisible_1char
 JNIEXPORT void JNICALL GTK_NATIVE(gtk_1entry_1set_1invisible_1char)
 	(JNIEnv *env, jclass that, jlong arg0, jchar arg1)
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 b3f39b1..7d034ba 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
@@ -430,6 +430,7 @@
 	"gtk_1entry_1set_1icon_1activatable",
 	"gtk_1entry_1set_1icon_1from_1icon_1name",
 	"gtk_1entry_1set_1icon_1sensitive",
+	"gtk_1entry_1set_1input_1hints",
 	"gtk_1entry_1set_1invisible_1char",
 	"gtk_1entry_1set_1max_1length",
 	"gtk_1entry_1set_1placeholder_1text",
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 164e4e8..eb3f9d8 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
@@ -428,6 +428,7 @@
 	gtk_1entry_1set_1icon_1activatable_FUNC,
 	gtk_1entry_1set_1icon_1from_1icon_1name_FUNC,
 	gtk_1entry_1set_1icon_1sensitive_FUNC,
+	gtk_1entry_1set_1input_1hints_FUNC,
 	gtk_1entry_1set_1invisible_1char_FUNC,
 	gtk_1entry_1set_1max_1length_FUNC,
 	gtk_1entry_1set_1placeholder_1text_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
index c352f87..aca4cda 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
@@ -155,6 +155,7 @@
 	public static final int GTK_WRAP_WORD = 2;
 	public static final int GTK_WRAP_WORD_CHAR = 3;
 	public static final int GTK_SHORTCUT_SCOPE_GLOBAL = 2;
+	public static final int GTK_INPUT_HINT_NO_EMOJI = 1024;
 
 	/** Classes */
 	public static final byte[] GTK_STYLE_CLASS_VIEW = OS.ascii("view");
@@ -823,6 +824,11 @@
 	 */
 	public static final native long gtk_entry_get_buffer(long entry);
 
+	/**
+	 * @param entry cast=(GtkEntry *)
+	 * @param hint cast=(GtkInputHints)
+	 */
+	public static final native void gtk_entry_set_input_hints(long entry, int hint);
 
 	/* GtkEntryBuffer */
 	/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
index 671c6ab..a449226 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java
@@ -65,6 +65,10 @@
  * @noextend This class is not intended to be subclassed by clients.
  */
 public class Text extends Scrollable {
+
+	// allows to disable context menu entry for "insert emoji"
+	private static final boolean DISABLE_EMOJI = Boolean.getBoolean("SWT_GTK_INPUT_HINT_NO_EMOJI");
+
 	long bufferHandle;
 	long imContext;
 	int tabs = 8, lastEventTime = 0;
@@ -181,6 +185,9 @@
 			this.style &= ~SWT.ICON_CANCEL;
 		}
 	}
+	if (DISABLE_EMOJI && GTK.GTK_VERSION >= OS.VERSION(3, 22, 20)) {
+	    GTK.gtk_entry_set_input_hints(handle, GTK.GTK_INPUT_HINT_NO_EMOJI);
+	}
 }
 
 static int checkStyle (int style) {