Skip to content

Commit 9ba7a4f

Browse files
committed
[Gtk4] Text with SWT.SEARCH fixes
GtkSearchEntry on Gtk 4 is no longer a GtkEntry thus: * BORDER can not be set anymore using gtk_entry_set_border * alignment should be set using gtk_editable_set_alignment * DISABLE_EMOJI via gtk_entry_set_input_hints has no effects. This prevents errors like: (SWT:1297545): Gtk-CRITICAL **: 10:19:51.235: gtk_entry_FUNCTION_NAME: assertion 'GTK_IS_ENTRY (entry)' failed
1 parent 67cd5aa commit 9ba7a4f

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,16 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1editable_1get_1text)
11861186
}
11871187
#endif
11881188

1189+
#ifndef NO_gtk_1editable_1set_1alignment
1190+
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1editable_1set_1alignment)
1191+
(JNIEnv *env, jclass that, jlong arg0, jfloat arg1)
1192+
{
1193+
GTK4_NATIVE_ENTER(env, that, gtk_1editable_1set_1alignment_FUNC);
1194+
gtk_editable_set_alignment((GtkEditable *)arg0, (float)arg1);
1195+
GTK4_NATIVE_EXIT(env, that, gtk_1editable_1set_1alignment_FUNC);
1196+
}
1197+
#endif
1198+
11891199
#ifndef NO_gtk_1editable_1set_1max_1width_1chars
11901200
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1editable_1set_1max_1width_1chars)
11911201
(JNIEnv *env, jclass that, jlong arg0, jint arg1)

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ typedef enum {
111111
gtk_1editable_1get_1delegate_FUNC,
112112
gtk_1editable_1get_1max_1width_1chars_FUNC,
113113
gtk_1editable_1get_1text_FUNC,
114+
gtk_1editable_1set_1alignment_FUNC,
114115
gtk_1editable_1set_1max_1width_1chars_FUNC,
115116
gtk_1editable_1set_1text_FUNC,
116117
gtk_1entry_1buffer_1get_1text_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ public class GTK4 {
133133
* @param editable cast=(GtkEditable *)
134134
*/
135135
public static final native int gtk_editable_get_max_width_chars(long editable);
136+
/**
137+
* @param editable cast=(GtkEditable *)
138+
* @param alignment cast=(float)
139+
*/
140+
public static final native void gtk_editable_set_alignment(long editable, float alignment);
136141
/**
137142
* @param editable cast=(GtkEditable *)
138143
* @param chars cast=(int)

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ void createHandle (int index) {
254254
* We need to handle borders differently in GTK3.20+. GtkEntry without frame will have a blank background color.
255255
* So let's set border via css and override the background in this case to be COLOR_LIST_BACKGROUND.
256256
*/
257-
if ((style & SWT.BORDER) == 0) {
257+
if ((style & SWT.BORDER) == 0 && !(GTK.GTK4 && (style & SWT.SEARCH) != 0) ) {
258258
GTK.gtk_entry_set_has_frame(handle, false);
259259
long context = GTK.gtk_widget_get_style_context(handle);
260260
String background = display.gtk_rgba_to_css_string(display.COLOR_LIST_BACKGROUND_RGBA);
@@ -265,11 +265,17 @@ void createHandle (int index) {
265265
if ((style & SWT.CENTER) != 0) alignment = 0.5f;
266266
if ((style & SWT.RIGHT) != 0) alignment = 1.0f;
267267
if (alignment > 0.0f) {
268-
GTK.gtk_entry_set_alignment(handle, alignment);
268+
if (!(GTK.GTK4 && (style & SWT.SEARCH) != 0)) {
269+
GTK.gtk_entry_set_alignment(handle, alignment);
270+
} else {
271+
GTK4.gtk_editable_set_alignment(handle, alignment);
272+
}
269273
}
270274

271275
if (DISABLE_EMOJI && GTK.GTK_VERSION >= OS.VERSION(3, 22, 20)) {
272-
GTK.gtk_entry_set_input_hints(handle, GTK.GTK_INPUT_HINT_NO_EMOJI);
276+
if (!(GTK.GTK4 && (style & SWT.SEARCH) != 0)) {
277+
GTK.gtk_entry_set_input_hints(handle, GTK.GTK_INPUT_HINT_NO_EMOJI);
278+
}
273279
}
274280
} else {
275281
if (GTK.GTK4) {
@@ -699,7 +705,7 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) {
699705
trim.width += tmp.left + tmp.right;
700706
trim.height += tmp.top + tmp.bottom;
701707
}
702-
if (!GTK.GTK4 || ((style & SWT.SEARCH) == 0) ) {
708+
if (!GTK.GTK4 || ((style & SWT.SEARCH) == 0) ) {
703709
GdkRectangle icon_area = new GdkRectangle();
704710
GTK.gtk_entry_get_icon_area(handle, GTK.GTK_ENTRY_ICON_PRIMARY, icon_area);
705711
trim.x -= icon_area.width;

0 commit comments

Comments
 (0)