Skip to content

Commit 9c42733

Browse files
committed
Fix Combo crash with Bug379271_ComboCaretLocationOffset on Gtk 4
Method getCaretPosition is implemented with Gtk 4. The other method getCaredLocation is simply bypassed on Gtk 4 with TODO to prevent the crash for now.
1 parent 29753aa commit 9c42733

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,18 @@ JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1editable_1get_1text)
706706
}
707707
#endif
708708

709+
#ifndef NO_gtk_1entry_1buffer_1get_1text
710+
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1entry_1buffer_1get_1text)
711+
(JNIEnv *env, jclass that, jlong arg0)
712+
{
713+
jlong rc = 0;
714+
GTK4_NATIVE_ENTER(env, that, gtk_1entry_1buffer_1get_1text_FUNC);
715+
rc = (jlong)gtk_entry_buffer_get_text((GtkEntryBuffer *)arg0);
716+
GTK4_NATIVE_EXIT(env, that, gtk_1entry_1buffer_1get_1text_FUNC);
717+
return rc;
718+
}
719+
#endif
720+
709721
#ifndef NO_gtk_1entry_1get_1buffer
710722
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1entry_1get_1buffer)
711723
(JNIEnv *env, jclass that, jlong arg0)

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
@@ -75,6 +75,7 @@ typedef enum {
7575
gtk_1drop_1target_1async_1set_1formats_FUNC,
7676
gtk_1editable_1get_1delegate_FUNC,
7777
gtk_1editable_1get_1text_FUNC,
78+
gtk_1entry_1buffer_1get_1text_FUNC,
7879
gtk_1entry_1get_1buffer_FUNC,
7980
gtk_1entry_1get_1text_1length_FUNC,
8081
gtk_1entry_1set_1buffer_FUNC,

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public class GTK4 {
197197
public static final native long gtk_file_dialog_new();
198198
/**
199199
* @method flags=dynamic
200-
*
200+
*
201201
* @param parent cast=(GtkWindow *)
202202
* @param cancellable cast=(GCancellable *)
203203
* @param callback cast=(GAsyncReadyCallback)
@@ -206,55 +206,55 @@ public class GTK4 {
206206
public static final native void gtk_file_dialog_select_folder(long self, long parent, long cancellable, long callback, long user_data);
207207
/**
208208
* @method flags=dynamic
209-
*
209+
*
210210
* @param result cast=(GAsyncResult *)
211211
* @param error cast=(GError **)
212212
*/
213213
public static final native long gtk_file_dialog_select_folder_finish(long self, long result, long[] error);
214214
/**
215215
* @method flags=dynamic
216-
*
216+
*
217217
* @param folder cast=(GFile *)
218218
*/
219219
public static final native void gtk_file_dialog_set_initial_folder(long self, long folder);
220220
/**
221221
* @method flags=dynamic
222-
*
222+
*
223223
* @param title cast=(char *)
224224
*/
225225
public static final native void gtk_file_dialog_set_initial_name(long self, byte[] title);
226226
/**
227227
* @method flags=dynamic
228-
*
228+
*
229229
* @param file cast=(GFile *)
230230
*/
231231
public static final native void gtk_file_dialog_set_initial_file(long self, long file);
232232
/**
233233
* @method flags=dynamic
234-
*
234+
*
235235
* @param title cast=(char *)
236236
*/
237237
public static final native void gtk_file_dialog_set_title(long self, byte[] title);
238238
/**
239239
* @method flags=dynamic
240-
*
240+
*
241241
* @param filter cast=(GtkFileFilter *)
242242
*/
243243
public static final native void gtk_file_dialog_set_default_filter(long self, long filter);
244244
/**
245245
* @method flags=dynamic
246-
*
246+
*
247247
* @param filters cast=(GListModel *)
248248
*/
249249
public static final native void gtk_file_dialog_set_filters(long self, long filters);
250250
/**
251251
* @method flags=dynamic
252-
*
252+
*
253253
*/
254254
public static final native long gtk_file_dialog_get_default_filter(long self);
255255
/**
256256
* @method flags=dynamic
257-
*
257+
*
258258
* @param parent cast=(GtkWindow *)
259259
* @param cancellable cast=(GCancellable *)
260260
* @param callback cast=(GAsyncReadyCallback)
@@ -263,13 +263,13 @@ public class GTK4 {
263263
public static final native void gtk_file_dialog_open_multiple(long self, long parent, long cancellable, long callback, long user_data);
264264
/**
265265
* @method flags=dynamic
266-
*
266+
*
267267
* @param result cast=(GAsyncResult *)
268268
* @param error cast=(GError **)
269269
*/
270270
public static final native long gtk_file_dialog_open_multiple_finish(long self, long result, long[] error);
271271
/**
272-
*
272+
*
273273
* @param parent cast=(GtkWindow *)
274274
* @param cancellable cast=(GCancellable *)
275275
* @param callback cast=(GAsyncReadyCallback)
@@ -279,14 +279,14 @@ public class GTK4 {
279279
public static final native void gtk_file_dialog_open(long self, long parent, long cancellable, long callback, long user_data);
280280
/**
281281
* @method flags=dynamic
282-
*
282+
*
283283
* @param result cast=(GAsyncResult *)
284284
* @param error cast=(GError **)
285285
*/
286286
public static final native long gtk_file_dialog_open_finish(long self, long result, long[] error);
287287
/**
288288
* @method flags=dynamic
289-
*
289+
*
290290
* @param parent cast=(GtkWindow *)
291291
* @param cancellable cast=(GCancellable *)
292292
* @param callback cast=(GAsyncReadyCallback)
@@ -295,7 +295,7 @@ public class GTK4 {
295295
public static final native void gtk_file_dialog_save(long self, long parent, long cancellable, long callback, long user_data);
296296
/**
297297
* @method flags=dynamic
298-
*
298+
*
299299
* @param result cast=(GAsyncResult *)
300300
* @param error cast=(GError **)
301301
*/
@@ -534,6 +534,8 @@ public class GTK4 {
534534
* @param buffer cast=(GtkEntryBuffer *)
535535
*/
536536
public static final native void gtk_entry_set_buffer(long entry, long buffer);
537+
/** @param entry cast=(GtkEntryBuffer *) */
538+
public static final native long gtk_entry_buffer_get_text(long entry);
537539
/** @param entry cast=(GtkEntry *) */
538540
public static final native long gtk_entry_get_buffer(long entry);
539541
/** @param entry cast=(GtkEntry *) */

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2020 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -1091,16 +1091,21 @@ Point getCaretLocationInPixels () {
10911091
return new Point (0, 0);
10921092
}
10931093
int index = GTK.gtk_editable_get_position (entryHandle);
1094-
index = GTK3.gtk_entry_text_index_to_layout_index (entryHandle, index);
10951094
int [] offset_x = new int [1], offset_y = new int [1];
1096-
GTK3.gtk_entry_get_layout_offsets (entryHandle, offset_x, offset_y);
1097-
long layout = GTK3.gtk_entry_get_layout (entryHandle);
1098-
PangoRectangle pos = new PangoRectangle ();
1099-
OS.pango_layout_index_to_pos (layout, index, pos);
1100-
Point thickness = getThickness (entryHandle);
1101-
int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidthInPixels () - thickness.x;
1102-
int y = offset_y [0] + OS.PANGO_PIXELS (pos.y) - thickness.y;
1103-
return new Point (x, y);
1095+
if (GTK.GTK4) {
1096+
// TODO GTK 4.x implementation
1097+
return new Point (0, 0);
1098+
} else {
1099+
index = GTK3.gtk_entry_text_index_to_layout_index (entryHandle, index);
1100+
GTK3.gtk_entry_get_layout_offsets (entryHandle, offset_x, offset_y);
1101+
long layout = GTK3.gtk_entry_get_layout (entryHandle);
1102+
PangoRectangle pos = new PangoRectangle ();
1103+
OS.pango_layout_index_to_pos (layout, index, pos);
1104+
Point thickness = getThickness (entryHandle);
1105+
int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidthInPixels () - thickness.x;
1106+
int y = offset_y [0] + OS.PANGO_PIXELS (pos.y) - thickness.y;
1107+
return new Point (x, y);
1108+
}
11041109
}
11051110

11061111
/**
@@ -1123,7 +1128,7 @@ public int getCaretPosition () {
11231128
if ((style & SWT.READ_ONLY) != 0) {
11241129
return 0;
11251130
}
1126-
long ptr = GTK3.gtk_entry_get_text (entryHandle);
1131+
long ptr = GTK.GTK4? GTK4.gtk_entry_buffer_get_text(GTK4.gtk_entry_get_buffer(entryHandle)) : GTK3.gtk_entry_get_text (entryHandle);
11271132
return (int)OS.g_utf8_offset_to_utf16_offset (ptr, GTK.gtk_editable_get_position (entryHandle));
11281133
}
11291134

0 commit comments

Comments
 (0)