Skip to content

Commit 10567bb

Browse files
ptzieglerakurtakov
authored andcommitted
[GTK4] Migrate deprecated FontChooser to FontDialog
This moves all native FontChooser bindings from the shared GTK to the GTK3 component and also defines new GTK4 bindings for the FontDialog API. Note: The FontDialog doesn't seem to remember the initial font that is passed as an argument. This looks like a bug within GTK, given that the same behavior also happens for the FontDialogButton[1]. [1] - https://gitlab.gnome.org/GNOME/gtk/-/issues/6892
1 parent 7ad097a commit 10567bb

File tree

10 files changed

+259
-82
lines changed

10 files changed

+259
-82
lines changed

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

+42
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,48 @@ JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1file_1chooser_1set_1uri)
992992
}
993993
#endif
994994

995+
#ifndef NO_gtk_1font_1chooser_1dialog_1new
996+
JNIEXPORT jlong JNICALL GTK3_NATIVE(gtk_1font_1chooser_1dialog_1new)
997+
(JNIEnv *env, jclass that, jbyteArray arg0, jlong arg1)
998+
{
999+
jbyte *lparg0=NULL;
1000+
jlong rc = 0;
1001+
GTK3_NATIVE_ENTER(env, that, gtk_1font_1chooser_1dialog_1new_FUNC);
1002+
if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail;
1003+
rc = (jlong)gtk_font_chooser_dialog_new((const gchar *)lparg0, (GtkWindow *)arg1);
1004+
fail:
1005+
if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0);
1006+
GTK3_NATIVE_EXIT(env, that, gtk_1font_1chooser_1dialog_1new_FUNC);
1007+
return rc;
1008+
}
1009+
#endif
1010+
1011+
#ifndef NO_gtk_1font_1chooser_1get_1font
1012+
JNIEXPORT jlong JNICALL GTK3_NATIVE(gtk_1font_1chooser_1get_1font)
1013+
(JNIEnv *env, jclass that, jlong arg0)
1014+
{
1015+
jlong rc = 0;
1016+
GTK3_NATIVE_ENTER(env, that, gtk_1font_1chooser_1get_1font_FUNC);
1017+
rc = (jlong)gtk_font_chooser_get_font((GtkFontChooser *)arg0);
1018+
GTK3_NATIVE_EXIT(env, that, gtk_1font_1chooser_1get_1font_FUNC);
1019+
return rc;
1020+
}
1021+
#endif
1022+
1023+
#ifndef NO_gtk_1font_1chooser_1set_1font
1024+
JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1font_1chooser_1set_1font)
1025+
(JNIEnv *env, jclass that, jlong arg0, jbyteArray arg1)
1026+
{
1027+
jbyte *lparg1=NULL;
1028+
GTK3_NATIVE_ENTER(env, that, gtk_1font_1chooser_1set_1font_FUNC);
1029+
if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail;
1030+
gtk_font_chooser_set_font((GtkFontChooser *)arg0, (const gchar *)lparg1);
1031+
fail:
1032+
if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0);
1033+
GTK3_NATIVE_EXIT(env, that, gtk_1font_1chooser_1set_1font_FUNC);
1034+
}
1035+
#endif
1036+
9951037
#ifndef NO_gtk_1frame_1set_1shadow_1type
9961038
JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1frame_1set_1shadow_1type)
9971039
(JNIEnv *env, jclass that, jlong arg0, jint arg1)

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

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ typedef enum {
105105
gtk_1file_1chooser_1set_1local_1only_FUNC,
106106
gtk_1file_1chooser_1set_1select_1multiple_FUNC,
107107
gtk_1file_1chooser_1set_1uri_FUNC,
108+
gtk_1font_1chooser_1dialog_1new_FUNC,
109+
gtk_1font_1chooser_1get_1font_FUNC,
110+
gtk_1font_1chooser_1set_1font_FUNC,
108111
gtk_1frame_1set_1shadow_1type_FUNC,
109112
gtk_1gesture_1drag_1new_FUNC,
110113
gtk_1gesture_1rotate_1new_FUNC,

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

+106
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,112 @@ JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1file_1dialog_1set_1title)
980980
}
981981
#endif
982982

983+
#ifndef NO_gtk_1font_1dialog_1choose_1font
984+
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1font_1dialog_1choose_1font)
985+
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlong arg2, jlong arg3, jlong arg4, jlong arg5)
986+
{
987+
GTK4_NATIVE_ENTER(env, that, gtk_1font_1dialog_1choose_1font_FUNC);
988+
/*
989+
gtk_font_dialog_choose_font(arg0, (GtkWindow *)arg1, (PangoFontDescription *)arg2, (GCancellable *)arg3, (GAsyncReadyCallback)arg4, (gpointer)arg5);
990+
*/
991+
{
992+
GTK4_LOAD_FUNCTION(fp, gtk_font_dialog_choose_font)
993+
if (fp) {
994+
((void (CALLING_CONVENTION*)(jlong, GtkWindow *, PangoFontDescription *, GCancellable *, GAsyncReadyCallback, gpointer))fp)(arg0, (GtkWindow *)arg1, (PangoFontDescription *)arg2, (GCancellable *)arg3, (GAsyncReadyCallback)arg4, (gpointer)arg5);
995+
}
996+
}
997+
GTK4_NATIVE_EXIT(env, that, gtk_1font_1dialog_1choose_1font_FUNC);
998+
}
999+
#endif
1000+
1001+
#ifndef NO_gtk_1font_1dialog_1choose_1font_1finish
1002+
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1font_1dialog_1choose_1font_1finish)
1003+
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlongArray arg2)
1004+
{
1005+
jlong *lparg2=NULL;
1006+
jlong rc = 0;
1007+
GTK4_NATIVE_ENTER(env, that, gtk_1font_1dialog_1choose_1font_1finish_FUNC);
1008+
if (arg2) if ((lparg2 = (*env)->GetLongArrayElements(env, arg2, NULL)) == NULL) goto fail;
1009+
/*
1010+
rc = (jlong)gtk_font_dialog_choose_font_finish(arg0, (GAsyncResult *)arg1, (GError **)lparg2);
1011+
*/
1012+
{
1013+
GTK4_LOAD_FUNCTION(fp, gtk_font_dialog_choose_font_finish)
1014+
if (fp) {
1015+
rc = (jlong)((jlong (CALLING_CONVENTION*)(jlong, GAsyncResult *, GError **))fp)(arg0, (GAsyncResult *)arg1, (GError **)lparg2);
1016+
}
1017+
}
1018+
fail:
1019+
if (arg2 && lparg2) (*env)->ReleaseLongArrayElements(env, arg2, lparg2, 0);
1020+
GTK4_NATIVE_EXIT(env, that, gtk_1font_1dialog_1choose_1font_1finish_FUNC);
1021+
return rc;
1022+
}
1023+
#endif
1024+
1025+
#ifndef NO_gtk_1font_1dialog_1new
1026+
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1font_1dialog_1new)
1027+
(JNIEnv *env, jclass that)
1028+
{
1029+
jlong rc = 0;
1030+
GTK4_NATIVE_ENTER(env, that, gtk_1font_1dialog_1new_FUNC);
1031+
/*
1032+
rc = (jlong)gtk_font_dialog_new();
1033+
*/
1034+
{
1035+
GTK4_LOAD_FUNCTION(fp, gtk_font_dialog_new)
1036+
if (fp) {
1037+
rc = (jlong)((jlong (CALLING_CONVENTION*)())fp)();
1038+
}
1039+
}
1040+
GTK4_NATIVE_EXIT(env, that, gtk_1font_1dialog_1new_FUNC);
1041+
return rc;
1042+
}
1043+
#endif
1044+
1045+
#ifndef NO_gtk_1font_1dialog_1set_1modal
1046+
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1font_1dialog_1set_1modal)
1047+
(JNIEnv *env, jclass that, jlong arg0, jboolean arg1)
1048+
{
1049+
jlong rc = 0;
1050+
GTK4_NATIVE_ENTER(env, that, gtk_1font_1dialog_1set_1modal_FUNC);
1051+
/*
1052+
rc = (jlong)gtk_font_dialog_set_modal(arg0, (gboolean)arg1);
1053+
*/
1054+
{
1055+
GTK4_LOAD_FUNCTION(fp, gtk_font_dialog_set_modal)
1056+
if (fp) {
1057+
rc = (jlong)((jlong (CALLING_CONVENTION*)(jlong, gboolean))fp)(arg0, (gboolean)arg1);
1058+
}
1059+
}
1060+
GTK4_NATIVE_EXIT(env, that, gtk_1font_1dialog_1set_1modal_FUNC);
1061+
return rc;
1062+
}
1063+
#endif
1064+
1065+
#ifndef NO_gtk_1font_1dialog_1set_1title
1066+
JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1font_1dialog_1set_1title)
1067+
(JNIEnv *env, jclass that, jlong arg0, jbyteArray arg1)
1068+
{
1069+
jbyte *lparg1=NULL;
1070+
jlong rc = 0;
1071+
GTK4_NATIVE_ENTER(env, that, gtk_1font_1dialog_1set_1title_FUNC);
1072+
if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail;
1073+
/*
1074+
rc = (jlong)gtk_font_dialog_set_title(arg0, (char *)lparg1);
1075+
*/
1076+
{
1077+
GTK4_LOAD_FUNCTION(fp, gtk_font_dialog_set_title)
1078+
if (fp) {
1079+
rc = (jlong)((jlong (CALLING_CONVENTION*)(jlong, char *))fp)(arg0, (char *)lparg1);
1080+
}
1081+
}
1082+
fail:
1083+
if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0);
1084+
GTK4_NATIVE_EXIT(env, that, gtk_1font_1dialog_1set_1title_FUNC);
1085+
return rc;
1086+
}
1087+
#endif
1088+
9831089
#ifndef NO_gtk_1frame_1set_1child
9841090
JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1frame_1set_1child)
9851091
(JNIEnv *env, jclass that, jlong arg0, jlong arg1)

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

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ typedef enum {
9393
gtk_1file_1dialog_1set_1initial_1folder_FUNC,
9494
gtk_1file_1dialog_1set_1initial_1name_FUNC,
9595
gtk_1file_1dialog_1set_1title_FUNC,
96+
gtk_1font_1dialog_1choose_1font_FUNC,
97+
gtk_1font_1dialog_1choose_1font_1finish_FUNC,
98+
gtk_1font_1dialog_1new_FUNC,
99+
gtk_1font_1dialog_1set_1modal_FUNC,
100+
gtk_1font_1dialog_1set_1title_FUNC,
96101
gtk_1frame_1set_1child_FUNC,
97102
gtk_1gesture_1click_1new_FUNC,
98103
gtk_1gesture_1drag_1new_FUNC,

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

-42
Original file line numberDiff line numberDiff line change
@@ -4781,48 +4781,6 @@ JNIEXPORT void JNICALL GTK_NATIVE(gtk_1file_1filter_1set_1name)
47814781
}
47824782
#endif
47834783

4784-
#ifndef NO_gtk_1font_1chooser_1dialog_1new
4785-
JNIEXPORT jlong JNICALL GTK_NATIVE(gtk_1font_1chooser_1dialog_1new)
4786-
(JNIEnv *env, jclass that, jbyteArray arg0, jlong arg1)
4787-
{
4788-
jbyte *lparg0=NULL;
4789-
jlong rc = 0;
4790-
GTK_NATIVE_ENTER(env, that, gtk_1font_1chooser_1dialog_1new_FUNC);
4791-
if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail;
4792-
rc = (jlong)gtk_font_chooser_dialog_new((const gchar *)lparg0, (GtkWindow *)arg1);
4793-
fail:
4794-
if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0);
4795-
GTK_NATIVE_EXIT(env, that, gtk_1font_1chooser_1dialog_1new_FUNC);
4796-
return rc;
4797-
}
4798-
#endif
4799-
4800-
#ifndef NO_gtk_1font_1chooser_1get_1font
4801-
JNIEXPORT jlong JNICALL GTK_NATIVE(gtk_1font_1chooser_1get_1font)
4802-
(JNIEnv *env, jclass that, jlong arg0)
4803-
{
4804-
jlong rc = 0;
4805-
GTK_NATIVE_ENTER(env, that, gtk_1font_1chooser_1get_1font_FUNC);
4806-
rc = (jlong)gtk_font_chooser_get_font((GtkFontChooser *)arg0);
4807-
GTK_NATIVE_EXIT(env, that, gtk_1font_1chooser_1get_1font_FUNC);
4808-
return rc;
4809-
}
4810-
#endif
4811-
4812-
#ifndef NO_gtk_1font_1chooser_1set_1font
4813-
JNIEXPORT void JNICALL GTK_NATIVE(gtk_1font_1chooser_1set_1font)
4814-
(JNIEnv *env, jclass that, jlong arg0, jbyteArray arg1)
4815-
{
4816-
jbyte *lparg1=NULL;
4817-
GTK_NATIVE_ENTER(env, that, gtk_1font_1chooser_1set_1font_FUNC);
4818-
if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail;
4819-
gtk_font_chooser_set_font((GtkFontChooser *)arg0, (const gchar *)lparg1);
4820-
fail:
4821-
if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0);
4822-
GTK_NATIVE_EXIT(env, that, gtk_1font_1chooser_1set_1font_FUNC);
4823-
}
4824-
#endif
4825-
48264784
#ifndef NO_gtk_1frame_1get_1label_1widget
48274785
JNIEXPORT jlong JNICALL GTK_NATIVE(gtk_1frame_1get_1label_1widget)
48284786
(JNIEnv *env, jclass that, jlong arg0)

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

-3
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,6 @@ typedef enum {
380380
gtk_1file_1filter_1get_1name_FUNC,
381381
gtk_1file_1filter_1new_FUNC,
382382
gtk_1file_1filter_1set_1name_FUNC,
383-
gtk_1font_1chooser_1dialog_1new_FUNC,
384-
gtk_1font_1chooser_1get_1font_FUNC,
385-
gtk_1font_1chooser_1set_1font_FUNC,
386383
gtk_1frame_1get_1label_1widget_FUNC,
387384
gtk_1frame_1new_FUNC,
388385
gtk_1frame_1set_1label_1widget_FUNC,

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

-16
Original file line numberDiff line numberDiff line change
@@ -776,22 +776,6 @@ public class GTK extends OS {
776776
*/
777777
public static final native double gtk_gesture_zoom_get_scale_delta(long gesture);
778778

779-
/* GtkFontChooserDialog */
780-
/**
781-
* @param title cast=(const gchar *)
782-
* @param parent cast=(GtkWindow *)
783-
*/
784-
public static final native long gtk_font_chooser_dialog_new(byte[] title, long parent);
785-
786-
/* GtkFontChooser Interface */
787-
/** @param fontchooser cast=(GtkFontChooser *) */
788-
public static final native long gtk_font_chooser_get_font(long fontchooser);
789-
/**
790-
* @param fsd cast=(GtkFontChooser *)
791-
* @param fontname cast=(const gchar *)
792-
*/
793-
public static final native void gtk_font_chooser_set_font(long fsd, byte[] fontname);
794-
795779
/* GtkFrame */
796780
/** @param label cast=(const gchar *) */
797781
public static final native long gtk_frame_new(byte[] label);

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java

+16
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,22 @@ public class GTK3 {
11101110
*/
11111111
public static final native long gtk_gesture_drag_new(long widget);
11121112

1113+
/* GtkFontChooserDialog */
1114+
/**
1115+
* @param title cast=(const gchar *)
1116+
* @param parent cast=(GtkWindow *)
1117+
*/
1118+
public static final native long gtk_font_chooser_dialog_new(byte[] title, long parent);
1119+
1120+
/* GtkFontChooser Interface */
1121+
/** @param fontchooser cast=(GtkFontChooser *) */
1122+
public static final native long gtk_font_chooser_get_font(long fontchooser);
1123+
/**
1124+
* @param fsd cast=(GtkFontChooser *)
1125+
* @param fontname cast=(const gchar *)
1126+
*/
1127+
public static final native void gtk_font_chooser_set_font(long fsd, byte[] fontname);
1128+
11131129
/* Sizeof */
11141130
public static final native int GtkTargetEntry_sizeof();
11151131
public static final native int GdkEvent_sizeof();

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

+36
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,42 @@ public class GTK4 {
283283
*/
284284
public static final native long gtk_file_dialog_save_finish(long self, long result, long[] error);
285285

286+
/* GtkFontDialog */
287+
/**
288+
* @method flags=dynamic
289+
*
290+
* @param parent cast=(GtkWindow *)
291+
* @param initial_value cast=(PangoFontDescription *)
292+
* @param cancellable cast=(GCancellable *)
293+
* @param callback cast=(GAsyncReadyCallback)
294+
* @param user_data cast=(gpointer)
295+
*/
296+
public static final native void gtk_font_dialog_choose_font(long self, long parent, long initial_value, long cancellable, long callback, long user_data);
297+
/**
298+
* @method flags=dynamic
299+
*
300+
* @param result cast=(GAsyncResult *)
301+
* @param error cast=(GError **)
302+
*/
303+
public static final native long gtk_font_dialog_choose_font_finish(long self, long result, long[] error);
304+
/**
305+
* @method flags=dynamic
306+
*/
307+
public static final native long gtk_font_dialog_new();
308+
/**
309+
* @method flags=dynamic
310+
*
311+
* @param modal cast=(gboolean)
312+
*/
313+
public static final native long gtk_font_dialog_set_modal(long self, boolean modal);
314+
/**
315+
* @method flags=dynamic
316+
*
317+
* @param title cast=(char *)
318+
*/
319+
public static final native long gtk_font_dialog_set_title(long self, byte[] title);
320+
321+
286322
/* GtkScrolledWindow */
287323
public static final native long gtk_scrolled_window_new();
288324
/** @param scrolled_window cast=(GtkScrolledWindow *) */

0 commit comments

Comments
 (0)