diff options
author | Xi Yan | 2018-11-20 20:15:57 +0000 |
---|---|---|
committer | Eric Williams | 2018-11-23 19:58:22 +0000 |
commit | d53c584eda3df3e021b22226a63edc7cdb3e65c3 (patch) | |
tree | cd27b9856ab22669d9db6f44247bcbe6bd51f670 | |
parent | 66f203aed81e3fb64b92711af69e97dfe86645e6 (diff) | |
download | eclipse.platform.swt-d53c584eda3df3e021b22226a63edc7cdb3e65c3.tar.gz eclipse.platform.swt-d53c584eda3df3e021b22226a63edc7cdb3e65c3.tar.xz eclipse.platform.swt-d53c584eda3df3e021b22226a63edc7cdb3e65c3.zip |
Bug 518080 - Use GtkSearchEntry instead of gtkEntry + icon
Use GtkSearchEntry, removed code to handle "clear" icon press events,
workaround default look to support search entry without icons.
Change-Id: Id29044f5b1f362841048cb4ada2c4c4854f26953
Signed-off-by: Xi Yan <xixiyan@redhat.com>
5 files changed, 80 insertions, 21 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 a73986657f..f2f5628966 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 @@ -5099,6 +5099,16 @@ JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1entry_1set_1has_1frame) } #endif +#ifndef NO__1gtk_1entry_1set_1icon_1activatable +JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1entry_1set_1icon_1activatable) + (JNIEnv *env, jclass that, jintLong arg0, jint arg1, jboolean arg2) +{ + GTK_NATIVE_ENTER(env, that, _1gtk_1entry_1set_1icon_1activatable_FUNC); + gtk_entry_set_icon_activatable((GtkEntry *)arg0, (GtkEntryIconPosition)arg1, (gboolean)arg2); + GTK_NATIVE_EXIT(env, that, _1gtk_1entry_1set_1icon_1activatable_FUNC); +} +#endif + #ifndef NO__1gtk_1entry_1set_1icon_1from_1icon_1name JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1entry_1set_1icon_1from_1icon_1name) (JNIEnv *env, jclass that, jintLong arg0, jint arg1, jbyteArray arg2) @@ -8654,6 +8664,18 @@ JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1scrolled_1window_1set_1shadow_1type) } #endif +#ifndef NO__1gtk_1search_1entry_1new +JNIEXPORT jintLong JNICALL GTK_NATIVE(_1gtk_1search_1entry_1new) + (JNIEnv *env, jclass that) +{ + jintLong rc = 0; + GTK_NATIVE_ENTER(env, that, _1gtk_1search_1entry_1new_FUNC); + rc = (jintLong)gtk_search_entry_new(); + GTK_NATIVE_EXIT(env, that, _1gtk_1search_1entry_1new_FUNC); + return rc; +} +#endif + #ifndef NO__1gtk_1selection_1data_1free JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1selection_1data_1free) (JNIEnv *env, jclass that, jintLong arg0) 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 1b0fc6f29e..49d1f175c3 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 @@ -466,6 +466,7 @@ char * GTK_nativeFunctionNames[] = { "_1gtk_1entry_1new", "_1gtk_1entry_1set_1alignment", "_1gtk_1entry_1set_1has_1frame", + "_1gtk_1entry_1set_1icon_1activatable", "_1gtk_1entry_1set_1icon_1from_1icon_1name", "_1gtk_1entry_1set_1icon_1sensitive", "_1gtk_1entry_1set_1invisible_1char", @@ -776,6 +777,7 @@ char * GTK_nativeFunctionNames[] = { "_1gtk_1scrolled_1window_1new", "_1gtk_1scrolled_1window_1set_1policy", "_1gtk_1scrolled_1window_1set_1shadow_1type", + "_1gtk_1search_1entry_1new", "_1gtk_1selection_1data_1free", "_1gtk_1selection_1data_1get_1data", "_1gtk_1selection_1data_1get_1data_1type", 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 c465448940..fe65213b89 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 @@ -464,6 +464,7 @@ typedef enum { _1gtk_1entry_1new_FUNC, _1gtk_1entry_1set_1alignment_FUNC, _1gtk_1entry_1set_1has_1frame_FUNC, + _1gtk_1entry_1set_1icon_1activatable_FUNC, _1gtk_1entry_1set_1icon_1from_1icon_1name_FUNC, _1gtk_1entry_1set_1icon_1sensitive_FUNC, _1gtk_1entry_1set_1invisible_1char_FUNC, @@ -774,6 +775,7 @@ typedef enum { _1gtk_1scrolled_1window_1new_FUNC, _1gtk_1scrolled_1window_1set_1policy_FUNC, _1gtk_1scrolled_1window_1set_1shadow_1type_FUNC, + _1gtk_1search_1entry_1new_FUNC, _1gtk_1selection_1data_1free_FUNC, _1gtk_1selection_1data_1get_1data_FUNC, _1gtk_1selection_1data_1get_1data_1type_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 86f6b19176..83957e0607 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 @@ -213,8 +213,6 @@ public class GTK extends OS { * Icon preview tool: gtk3-icon-browser * Snippets often demonstrate usage of these. E.x 309, 258. * */ - public static final byte[] GTK_NAMED_ICON_FIND = OS.ascii("system-search-symbolic"); //Replacement of GTK_STOCK_FIND - public static final byte[] GTK_NAMED_ICON_CLEAR = OS.ascii("edit-clear-symbolic"); //Replacement of GTK_STOCK_CLEAR public static final byte[] GTK_NAMED_ICON_GO_UP = OS.ascii ("go-up-symbolic"); public static final byte[] GTK_NAMED_ICON_GO_DOWN = OS.ascii ("go-down-symbolic"); public static final byte[] GTK_NAMED_ICON_GO_NEXT = OS.ascii ("go-next-symbolic"); @@ -2107,6 +2105,20 @@ public class GTK extends OS { /** * @param entry cast=(GtkEntry *) * @param icon_pos cast=(GtkEntryIconPosition) + * @param activatable cast=(gboolean) + */ + public static final native void _gtk_entry_set_icon_activatable(long /*int*/ entry, int icon_pos, boolean activatable); + public static final void gtk_entry_set_icon_activatable(long /*int*/ entry, int icon_pos, boolean activatable) { + lock.lock(); + try { + _gtk_entry_set_icon_activatable(entry, icon_pos, activatable); + } finally { + lock.unlock(); + } + } + /** + * @param entry cast=(GtkEntry *) + * @param icon_pos cast=(GtkEntryIconPosition) * @param sensitive cast=(gboolean) */ public static final native void _gtk_entry_set_icon_sensitive(long /*int*/ entry, int icon_pos, boolean sensitive); @@ -3179,6 +3191,15 @@ public class GTK extends OS { lock.unlock(); } } + public static final native long /*int*/ _gtk_search_entry_new(); + public static final long /*int*/ gtk_search_entry_new() { + lock.lock(); + try { + return _gtk_search_entry_new(); + } finally { + lock.unlock(); + } + } /** * @param orientation cast=(GtkOrientation) */ 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 86dd953e41..502d912a8e 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 @@ -150,20 +150,28 @@ public Text (Composite parent, int style) { if ((style & SWT.SEARCH) != 0) { /* * Ensure that SWT.ICON_CANCEL and ICON_SEARCH are set. - * NOTE: ICON_CANCEL has the same value as H_SCROLL and - * ICON_SEARCH has the same value as V_SCROLL so it is - * necessary to first clear these bits to avoid a scroll - * bar and then reset the bit using the original style - * supplied by the programmer. + * NOTE: ICON_CANCEL has the same value as H_SCROLL and CON_SEARCH has the same value as V_SCROLL + * so it is necessary to first clear these bits to avoid a scroll bar and then reset the + * bit using the original style upplied by the programmer. + * + * NOTE2: Default GtkSearchEntry shows both "find" icon and "clear" icon. + * "find" icon can be manually removed here while "clear" icon must be removed depending on text. + * See gtk_changed. */ - if ((style & SWT.ICON_CANCEL) != 0) { - this.style |= SWT.ICON_CANCEL; - GTK.gtk_entry_set_icon_from_icon_name (handle, GTK.GTK_ENTRY_ICON_SECONDARY, GTK.GTK_NAMED_ICON_CLEAR); - GTK.gtk_entry_set_icon_sensitive (handle, GTK.GTK_ENTRY_ICON_SECONDARY, false); + this.style |= SWT.ICON_SEARCH | SWT.ICON_CANCEL; + + if ((style & SWT.ICON_SEARCH) == 0) { + this.style &= ~SWT.ICON_SEARCH; + GTK.gtk_entry_set_icon_from_icon_name(handle, GTK.GTK_ENTRY_ICON_PRIMARY, null); + } else { + // Default GtkSearchEntry always shows inactive "find" icon + // make it active and sensitive to be consistent with other platforms + GTK.gtk_entry_set_icon_activatable(handle, GTK.GTK_ENTRY_ICON_PRIMARY, true); + GTK.gtk_entry_set_icon_sensitive(handle, GTK.GTK_ENTRY_ICON_PRIMARY, true); } - if ((style & SWT.ICON_SEARCH) != 0) { - this.style |= SWT.ICON_SEARCH; - GTK.gtk_entry_set_icon_from_icon_name (handle, GTK.GTK_ENTRY_ICON_PRIMARY, GTK.GTK_NAMED_ICON_FIND); + + if ((style & SWT.ICON_CANCEL) == 0) { + this.style &= ~SWT.ICON_CANCEL; } } } @@ -205,7 +213,11 @@ void createHandle (int index) { if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); gtk_widget_set_has_surface_or_window (fixedHandle, true); if ((style & SWT.SINGLE) != 0) { - handle = GTK.gtk_entry_new (); + if ((style & SWT.SEARCH) != 0) { + handle = GTK.gtk_search_entry_new(); + } else { + handle = GTK.gtk_entry_new (); + } if (handle == 0) error (SWT.ERROR_NO_HANDLES); GTK.gtk_container_add (fixedHandle, handle); GTK.gtk_editable_set_editable (handle, (style & SWT.READ_ONLY) == 0); @@ -1479,9 +1491,10 @@ long /*int*/ gtk_changed (long /*int*/ widget) { sendEvent (SWT.Modify); } if ((style & SWT.SEARCH) != 0) { - if ((style & SWT.ICON_CANCEL) != 0) { - long /*int*/ ptr = GTK.gtk_entry_get_text (handle); - GTK.gtk_entry_set_icon_sensitive (handle, GTK.GTK_ENTRY_ICON_SECONDARY, OS.g_utf16_strlen (ptr, -1) > 0); + if ((style & SWT.ICON_CANCEL) == 0) { + // Default GtkSearchEntry shows "clear" icon when there is text, manually revert this + // when "cancel" icon style is not set + GTK.gtk_entry_set_icon_from_icon_name(handle, GTK.GTK_ENTRY_ICON_SECONDARY, null); } } return 0; @@ -1673,7 +1686,6 @@ long /*int*/ gtk_icon_release (long /*int*/ widget, long /*int*/ icon_pos, long e.detail = SWT.ICON_SEARCH; } else { e.detail = SWT.ICON_CANCEL; - GTK.gtk_editable_delete_text (handle, 0, -1); } sendSelectionEvent (SWT.DefaultSelection, e, false); return 0; @@ -2647,8 +2659,8 @@ void setText (char [] text) { } sendEvent (SWT.Modify); if ((style & SWT.SEARCH) != 0) { - if ((style & SWT.ICON_CANCEL) != 0) { - GTK.gtk_entry_set_icon_sensitive (handle, GTK.GTK_ENTRY_ICON_SECONDARY, true); + if ((style & SWT.ICON_CANCEL) == 0) { + GTK.gtk_entry_set_icon_from_icon_name(handle, GTK.GTK_ENTRY_ICON_SECONDARY, null); } } applySegments (); |