From c5f57d4780462efb081a036e2f467837cbc17b0c Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Tue, 26 Nov 2024 20:27:40 +0100 Subject: [PATCH] [GTK4] Migrate deprecated ColorChooser to ColorDialog The Color Chooser has been moved to the GTK3 class and all references inside the GTK4 blocks have been updated to use the new API. Note that the GTK4 API doesn't provide the means to set a custom palette, meaning that the colors specified with setRGBS(RGB[]) are effectively ignored. --- .../Eclipse SWT PI/gtk/library/gtk3.c | 76 ++++++++ .../Eclipse SWT PI/gtk/library/gtk3_stats.h | 6 + .../Eclipse SWT PI/gtk/library/gtk4.c | 166 ++++++++++++++++++ .../Eclipse SWT PI/gtk/library/gtk4_stats.h | 8 + .../Eclipse SWT PI/gtk/library/os.c | 76 -------- .../Eclipse SWT PI/gtk/library/os_stats.h | 6 - .../gtk/org/eclipse/swt/internal/gtk/GTK.java | 34 ---- .../org/eclipse/swt/internal/gtk3/GTK3.java | 33 ++++ .../org/eclipse/swt/internal/gtk4/GTK4.java | 50 ++++++ .../org/eclipse/swt/widgets/ColorDialog.java | 104 ++++++++--- 10 files changed, 415 insertions(+), 144 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c index a650d5f349f..5ca63c7708f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c @@ -438,6 +438,82 @@ JNIEXPORT jlong JNICALL GTK3_NATIVE(gtk_1clipboard_1wait_1for_1contents) } #endif +#ifndef NO_gtk_1color_1chooser_1add_1palette +JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1color_1chooser_1add_1palette) + (JNIEnv *env, jclass that, jlong arg0, jint arg1, jint arg2, jint arg3, jlong arg4) +{ + GTK3_NATIVE_ENTER(env, that, gtk_1color_1chooser_1add_1palette_FUNC); + gtk_color_chooser_add_palette((GtkColorChooser *)arg0, (GtkOrientation)arg1, (gint)arg2, (gint)arg3, (GdkRGBA *)arg4); + GTK3_NATIVE_EXIT(env, that, gtk_1color_1chooser_1add_1palette_FUNC); +} +#endif + +#ifndef NO_gtk_1color_1chooser_1dialog_1new +JNIEXPORT jlong JNICALL GTK3_NATIVE(gtk_1color_1chooser_1dialog_1new) + (JNIEnv *env, jclass that, jbyteArray arg0, jlong arg1) +{ + jbyte *lparg0=NULL; + jlong rc = 0; + GTK3_NATIVE_ENTER(env, that, gtk_1color_1chooser_1dialog_1new_FUNC); + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; + rc = (jlong)gtk_color_chooser_dialog_new((const gchar *)lparg0, (GtkWindow *)arg1); +fail: + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); + GTK3_NATIVE_EXIT(env, that, gtk_1color_1chooser_1dialog_1new_FUNC); + return rc; +} +#endif + +#ifndef NO_gtk_1color_1chooser_1get_1rgba +JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1color_1chooser_1get_1rgba) + (JNIEnv *env, jclass that, jlong arg0, jobject arg1) +{ + GdkRGBA _arg1, *lparg1=NULL; + GTK3_NATIVE_ENTER(env, that, gtk_1color_1chooser_1get_1rgba_FUNC); + if (arg1) if ((lparg1 = getGdkRGBAFields(env, arg1, &_arg1)) == NULL) goto fail; + gtk_color_chooser_get_rgba((GtkColorChooser *)arg0, (GdkRGBA *)lparg1); +fail: + if (arg1 && lparg1) setGdkRGBAFields(env, arg1, lparg1); + GTK3_NATIVE_EXIT(env, that, gtk_1color_1chooser_1get_1rgba_FUNC); +} +#endif + +#ifndef NO_gtk_1color_1chooser_1get_1use_1alpha +JNIEXPORT jboolean JNICALL GTK3_NATIVE(gtk_1color_1chooser_1get_1use_1alpha) + (JNIEnv *env, jclass that, jlong arg0) +{ + jboolean rc = 0; + GTK3_NATIVE_ENTER(env, that, gtk_1color_1chooser_1get_1use_1alpha_FUNC); + rc = (jboolean)gtk_color_chooser_get_use_alpha((GtkColorChooser *)arg0); + GTK3_NATIVE_EXIT(env, that, gtk_1color_1chooser_1get_1use_1alpha_FUNC); + return rc; +} +#endif + +#ifndef NO_gtk_1color_1chooser_1set_1rgba +JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1color_1chooser_1set_1rgba) + (JNIEnv *env, jclass that, jlong arg0, jobject arg1) +{ + GdkRGBA _arg1, *lparg1=NULL; + GTK3_NATIVE_ENTER(env, that, gtk_1color_1chooser_1set_1rgba_FUNC); + if (arg1) if ((lparg1 = getGdkRGBAFields(env, arg1, &_arg1)) == NULL) goto fail; + gtk_color_chooser_set_rgba((GtkColorChooser *)arg0, (GdkRGBA *)lparg1); +fail: + if (arg1 && lparg1) setGdkRGBAFields(env, arg1, lparg1); + GTK3_NATIVE_EXIT(env, that, gtk_1color_1chooser_1set_1rgba_FUNC); +} +#endif + +#ifndef NO_gtk_1color_1chooser_1set_1use_1alpha +JNIEXPORT void JNICALL GTK3_NATIVE(gtk_1color_1chooser_1set_1use_1alpha) + (JNIEnv *env, jclass that, jlong arg0, jboolean arg1) +{ + GTK3_NATIVE_ENTER(env, that, gtk_1color_1chooser_1set_1use_1alpha_FUNC); + gtk_color_chooser_set_use_alpha((GtkColorChooser *)arg0, (gboolean)arg1); + GTK3_NATIVE_EXIT(env, that, gtk_1color_1chooser_1set_1use_1alpha_FUNC); +} +#endif + #ifndef NO_gtk_1combo_1box_1get_1wrap_1width JNIEXPORT jint JNICALL GTK3_NATIVE(gtk_1combo_1box_1get_1wrap_1width) (JNIEnv *env, jclass that, jlong arg0) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h index 656e9558a8c..bcbb7039da2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h @@ -58,6 +58,12 @@ typedef enum { gtk_1clipboard_1set_1with_1owner_FUNC, gtk_1clipboard_1store_FUNC, gtk_1clipboard_1wait_1for_1contents_FUNC, + gtk_1color_1chooser_1add_1palette_FUNC, + gtk_1color_1chooser_1dialog_1new_FUNC, + gtk_1color_1chooser_1get_1rgba_FUNC, + gtk_1color_1chooser_1get_1use_1alpha_FUNC, + gtk_1color_1chooser_1set_1rgba_FUNC, + gtk_1color_1chooser_1set_1use_1alpha_FUNC, gtk_1combo_1box_1get_1wrap_1width_FUNC, gtk_1combo_1box_1set_1wrap_1width_FUNC, gtk_1container_1add_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c index dfaf3a62937..953e593e9cd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4.c @@ -436,6 +436,172 @@ JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1check_1button_1set_1use_1underline) } #endif +#ifndef NO_gtk_1color_1dialog_1choose_1rgba +JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1color_1dialog_1choose_1rgba) + (JNIEnv *env, jclass that, jlong arg0, jlong arg1, jobject arg2, jlong arg3, jlong arg4, jlong arg5) +{ + GdkRGBA _arg2, *lparg2=NULL; + GTK4_NATIVE_ENTER(env, that, gtk_1color_1dialog_1choose_1rgba_FUNC); + if (arg2) if ((lparg2 = getGdkRGBAFields(env, arg2, &_arg2)) == NULL) goto fail; +/* + gtk_color_dialog_choose_rgba(arg0, (GtkWindow *)arg1, (GdkRGBA *)lparg2, (GCancellable *)arg3, (GAsyncReadyCallback)arg4, (gpointer)arg5); +*/ + { + GTK4_LOAD_FUNCTION(fp, gtk_color_dialog_choose_rgba) + if (fp) { + ((void (CALLING_CONVENTION*)(jlong, GtkWindow *, GdkRGBA *, GCancellable *, GAsyncReadyCallback, gpointer))fp)(arg0, (GtkWindow *)arg1, (GdkRGBA *)lparg2, (GCancellable *)arg3, (GAsyncReadyCallback)arg4, (gpointer)arg5); + } + } +fail: + if (arg2 && lparg2) setGdkRGBAFields(env, arg2, lparg2); + GTK4_NATIVE_EXIT(env, that, gtk_1color_1dialog_1choose_1rgba_FUNC); +} +#endif + +#ifndef NO_gtk_1color_1dialog_1choose_1rgba_1finish +JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1color_1dialog_1choose_1rgba_1finish) + (JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlongArray arg2) +{ + jlong *lparg2=NULL; + jlong rc = 0; + GTK4_NATIVE_ENTER(env, that, gtk_1color_1dialog_1choose_1rgba_1finish_FUNC); + if (arg2) if ((lparg2 = (*env)->GetLongArrayElements(env, arg2, NULL)) == NULL) goto fail; +/* + rc = (jlong)gtk_color_dialog_choose_rgba_finish(arg0, (GAsyncResult *)arg1, (GError **)lparg2); +*/ + { + GTK4_LOAD_FUNCTION(fp, gtk_color_dialog_choose_rgba_finish) + if (fp) { + rc = (jlong)((jlong (CALLING_CONVENTION*)(jlong, GAsyncResult *, GError **))fp)(arg0, (GAsyncResult *)arg1, (GError **)lparg2); + } + } +fail: + if (arg2 && lparg2) (*env)->ReleaseLongArrayElements(env, arg2, lparg2, 0); + GTK4_NATIVE_EXIT(env, that, gtk_1color_1dialog_1choose_1rgba_1finish_FUNC); + return rc; +} +#endif + +#ifndef NO_gtk_1color_1dialog_1get_1modal +JNIEXPORT jboolean JNICALL GTK4_NATIVE(gtk_1color_1dialog_1get_1modal) + (JNIEnv *env, jclass that, jlong arg0) +{ + jboolean rc = 0; + GTK4_NATIVE_ENTER(env, that, gtk_1color_1dialog_1get_1modal_FUNC); +/* + rc = (jboolean)gtk_color_dialog_get_modal(arg0); +*/ + { + GTK4_LOAD_FUNCTION(fp, gtk_color_dialog_get_modal) + if (fp) { + rc = (jboolean)((jboolean (CALLING_CONVENTION*)(jlong))fp)(arg0); + } + } + GTK4_NATIVE_EXIT(env, that, gtk_1color_1dialog_1get_1modal_FUNC); + return rc; +} +#endif + +#ifndef NO_gtk_1color_1dialog_1get_1with_1alpha +JNIEXPORT jboolean JNICALL GTK4_NATIVE(gtk_1color_1dialog_1get_1with_1alpha) + (JNIEnv *env, jclass that, jlong arg0) +{ + jboolean rc = 0; + GTK4_NATIVE_ENTER(env, that, gtk_1color_1dialog_1get_1with_1alpha_FUNC); +/* + rc = (jboolean)gtk_color_dialog_get_with_alpha(arg0); +*/ + { + GTK4_LOAD_FUNCTION(fp, gtk_color_dialog_get_with_alpha) + if (fp) { + rc = (jboolean)((jboolean (CALLING_CONVENTION*)(jlong))fp)(arg0); + } + } + GTK4_NATIVE_EXIT(env, that, gtk_1color_1dialog_1get_1with_1alpha_FUNC); + return rc; +} +#endif + +#ifndef NO_gtk_1color_1dialog_1new +JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1color_1dialog_1new) + (JNIEnv *env, jclass that) +{ + jlong rc = 0; + GTK4_NATIVE_ENTER(env, that, gtk_1color_1dialog_1new_FUNC); +/* + rc = (jlong)gtk_color_dialog_new(); +*/ + { + GTK4_LOAD_FUNCTION(fp, gtk_color_dialog_new) + if (fp) { + rc = (jlong)((jlong (CALLING_CONVENTION*)())fp)(); + } + } + GTK4_NATIVE_EXIT(env, that, gtk_1color_1dialog_1new_FUNC); + return rc; +} +#endif + +#ifndef NO_gtk_1color_1dialog_1set_1modal +JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1color_1dialog_1set_1modal) + (JNIEnv *env, jclass that, jlong arg0, jboolean arg1) +{ + GTK4_NATIVE_ENTER(env, that, gtk_1color_1dialog_1set_1modal_FUNC); +/* + gtk_color_dialog_set_modal(arg0, (gboolean)arg1); +*/ + { + GTK4_LOAD_FUNCTION(fp, gtk_color_dialog_set_modal) + if (fp) { + ((void (CALLING_CONVENTION*)(jlong, gboolean))fp)(arg0, (gboolean)arg1); + } + } + GTK4_NATIVE_EXIT(env, that, gtk_1color_1dialog_1set_1modal_FUNC); +} +#endif + +#ifndef NO_gtk_1color_1dialog_1set_1title +JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1color_1dialog_1set_1title) + (JNIEnv *env, jclass that, jlong arg0, jbyteArray arg1) +{ + jbyte *lparg1=NULL; + jlong rc = 0; + GTK4_NATIVE_ENTER(env, that, gtk_1color_1dialog_1set_1title_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; +/* + rc = (jlong)gtk_color_dialog_set_title(arg0, (char *)lparg1); +*/ + { + GTK4_LOAD_FUNCTION(fp, gtk_color_dialog_set_title) + if (fp) { + rc = (jlong)((jlong (CALLING_CONVENTION*)(jlong, char *))fp)(arg0, (char *)lparg1); + } + } +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + GTK4_NATIVE_EXIT(env, that, gtk_1color_1dialog_1set_1title_FUNC); + return rc; +} +#endif + +#ifndef NO_gtk_1color_1dialog_1set_1with_1alpha +JNIEXPORT void JNICALL GTK4_NATIVE(gtk_1color_1dialog_1set_1with_1alpha) + (JNIEnv *env, jclass that, jlong arg0, jboolean arg1) +{ + GTK4_NATIVE_ENTER(env, that, gtk_1color_1dialog_1set_1with_1alpha_FUNC); +/* + gtk_color_dialog_set_with_alpha(arg0, (gboolean)arg1); +*/ + { + GTK4_LOAD_FUNCTION(fp, gtk_color_dialog_set_with_alpha) + if (fp) { + ((void (CALLING_CONVENTION*)(jlong, gboolean))fp)(arg0, (gboolean)arg1); + } + } + GTK4_NATIVE_EXIT(env, that, gtk_1color_1dialog_1set_1with_1alpha_FUNC); +} +#endif + #ifndef NO_gtk_1combo_1box_1get_1child JNIEXPORT jlong JNICALL GTK4_NATIVE(gtk_1combo_1box_1get_1child) (JNIEnv *env, jclass that, jlong arg0) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h index f8c9e0bd018..8ac1a288fe1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk4_stats.h @@ -58,6 +58,14 @@ typedef enum { gtk_1check_1button_1set_1group_FUNC, gtk_1check_1button_1set_1inconsistent_FUNC, gtk_1check_1button_1set_1use_1underline_FUNC, + gtk_1color_1dialog_1choose_1rgba_FUNC, + gtk_1color_1dialog_1choose_1rgba_1finish_FUNC, + gtk_1color_1dialog_1get_1modal_FUNC, + gtk_1color_1dialog_1get_1with_1alpha_FUNC, + gtk_1color_1dialog_1new_FUNC, + gtk_1color_1dialog_1set_1modal_FUNC, + gtk_1color_1dialog_1set_1title_FUNC, + gtk_1color_1dialog_1set_1with_1alpha_FUNC, gtk_1combo_1box_1get_1child_FUNC, gtk_1css_1provider_1load_1from_1data_FUNC, gtk_1drag_1source_1new_FUNC, 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 9e036be3b44..5d679390595 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 @@ -4078,82 +4078,6 @@ JNIEXPORT jlong JNICALL GTK_NATIVE(gtk_1check_1version) } #endif -#ifndef NO_gtk_1color_1chooser_1add_1palette -JNIEXPORT void JNICALL GTK_NATIVE(gtk_1color_1chooser_1add_1palette) - (JNIEnv *env, jclass that, jlong arg0, jint arg1, jint arg2, jint arg3, jlong arg4) -{ - GTK_NATIVE_ENTER(env, that, gtk_1color_1chooser_1add_1palette_FUNC); - gtk_color_chooser_add_palette((GtkColorChooser *)arg0, (GtkOrientation)arg1, (gint)arg2, (gint)arg3, (GdkRGBA *)arg4); - GTK_NATIVE_EXIT(env, that, gtk_1color_1chooser_1add_1palette_FUNC); -} -#endif - -#ifndef NO_gtk_1color_1chooser_1dialog_1new -JNIEXPORT jlong JNICALL GTK_NATIVE(gtk_1color_1chooser_1dialog_1new) - (JNIEnv *env, jclass that, jbyteArray arg0, jlong arg1) -{ - jbyte *lparg0=NULL; - jlong rc = 0; - GTK_NATIVE_ENTER(env, that, gtk_1color_1chooser_1dialog_1new_FUNC); - if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; - rc = (jlong)gtk_color_chooser_dialog_new((const gchar *)lparg0, (GtkWindow *)arg1); -fail: - if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); - GTK_NATIVE_EXIT(env, that, gtk_1color_1chooser_1dialog_1new_FUNC); - return rc; -} -#endif - -#ifndef NO_gtk_1color_1chooser_1get_1rgba -JNIEXPORT void JNICALL GTK_NATIVE(gtk_1color_1chooser_1get_1rgba) - (JNIEnv *env, jclass that, jlong arg0, jobject arg1) -{ - GdkRGBA _arg1, *lparg1=NULL; - GTK_NATIVE_ENTER(env, that, gtk_1color_1chooser_1get_1rgba_FUNC); - if (arg1) if ((lparg1 = getGdkRGBAFields(env, arg1, &_arg1)) == NULL) goto fail; - gtk_color_chooser_get_rgba((GtkColorChooser *)arg0, (GdkRGBA *)lparg1); -fail: - if (arg1 && lparg1) setGdkRGBAFields(env, arg1, lparg1); - GTK_NATIVE_EXIT(env, that, gtk_1color_1chooser_1get_1rgba_FUNC); -} -#endif - -#ifndef NO_gtk_1color_1chooser_1get_1use_1alpha -JNIEXPORT jboolean JNICALL GTK_NATIVE(gtk_1color_1chooser_1get_1use_1alpha) - (JNIEnv *env, jclass that, jlong arg0) -{ - jboolean rc = 0; - GTK_NATIVE_ENTER(env, that, gtk_1color_1chooser_1get_1use_1alpha_FUNC); - rc = (jboolean)gtk_color_chooser_get_use_alpha((GtkColorChooser *)arg0); - GTK_NATIVE_EXIT(env, that, gtk_1color_1chooser_1get_1use_1alpha_FUNC); - return rc; -} -#endif - -#ifndef NO_gtk_1color_1chooser_1set_1rgba -JNIEXPORT void JNICALL GTK_NATIVE(gtk_1color_1chooser_1set_1rgba) - (JNIEnv *env, jclass that, jlong arg0, jobject arg1) -{ - GdkRGBA _arg1, *lparg1=NULL; - GTK_NATIVE_ENTER(env, that, gtk_1color_1chooser_1set_1rgba_FUNC); - if (arg1) if ((lparg1 = getGdkRGBAFields(env, arg1, &_arg1)) == NULL) goto fail; - gtk_color_chooser_set_rgba((GtkColorChooser *)arg0, (GdkRGBA *)lparg1); -fail: - if (arg1 && lparg1) setGdkRGBAFields(env, arg1, lparg1); - GTK_NATIVE_EXIT(env, that, gtk_1color_1chooser_1set_1rgba_FUNC); -} -#endif - -#ifndef NO_gtk_1color_1chooser_1set_1use_1alpha -JNIEXPORT void JNICALL GTK_NATIVE(gtk_1color_1chooser_1set_1use_1alpha) - (JNIEnv *env, jclass that, jlong arg0, jboolean arg1) -{ - GTK_NATIVE_ENTER(env, that, gtk_1color_1chooser_1set_1use_1alpha_FUNC); - gtk_color_chooser_set_use_alpha((GtkColorChooser *)arg0, (gboolean)arg1); - GTK_NATIVE_EXIT(env, that, gtk_1color_1chooser_1set_1use_1alpha_FUNC); -} -#endif - #ifndef NO_gtk_1combo_1box_1get_1active JNIEXPORT jint JNICALL GTK_NATIVE(gtk_1combo_1box_1get_1active) (JNIEnv *env, jclass that, jlong arg0) 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 cc4d4ecce8a..c86aafd7a7f 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 @@ -321,12 +321,6 @@ typedef enum { gtk_1cell_1view_1set_1fit_1model_FUNC, gtk_1check_1button_1new_FUNC, gtk_1check_1version_FUNC, - gtk_1color_1chooser_1add_1palette_FUNC, - gtk_1color_1chooser_1dialog_1new_FUNC, - gtk_1color_1chooser_1get_1rgba_FUNC, - gtk_1color_1chooser_1get_1use_1alpha_FUNC, - gtk_1color_1chooser_1set_1rgba_FUNC, - gtk_1color_1chooser_1set_1use_1alpha_FUNC, gtk_1combo_1box_1get_1active_FUNC, gtk_1combo_1box_1get_1model_FUNC, gtk_1combo_1box_1popdown_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 919b524df51..529d1959a05 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 @@ -472,40 +472,6 @@ public class GTK extends OS { */ public static final native void gtk_enumerate_printers(long func, long data, long destroy, boolean wait); - /* GtkColorChooser Interface */ - /** - * @param chooser cast=(GtkColorChooser *) - * @param orientation cast=(GtkOrientation) - * @param colors_per_line cast=(gint) - * @param n_colors cast=(gint) - * @param colors cast=(GdkRGBA *) - */ - public static final native void gtk_color_chooser_add_palette(long chooser, int orientation, int colors_per_line, int n_colors, long colors); - /** - * @param chooser cast=(GtkColorChooser *) - * @param use_alpha cast=(gboolean) - */ - public static final native void gtk_color_chooser_set_use_alpha(long chooser, boolean use_alpha); - /** - * @param chooser cast=(GtkColorChooser *) - */ - public static final native boolean gtk_color_chooser_get_use_alpha(long chooser); - /** - * @param chooser cast=(GtkColorChooser *) - * @param color cast=(GdkRGBA *) - */ - public static final native void gtk_color_chooser_set_rgba(long chooser, GdkRGBA color); - /** - * @param chooser cast=(GtkColorChooser *) - * @param color cast=(GdkRGBA *) - */ - public static final native void gtk_color_chooser_get_rgba(long chooser, GdkRGBA color); - /** - * @param title cast=(const gchar *) - * @param parent cast=(GtkWindow *) - */ - public static final native long gtk_color_chooser_dialog_new(byte[] title, long parent); - /* GtkComboBox */ public static final native long gtk_combo_box_text_new(); public static final native long gtk_combo_box_text_new_with_entry(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java index 8b772cf1815..1d4793e8bdd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java @@ -125,6 +125,39 @@ public class GTK3 { */ public static final native void gtk_rgb_to_hsv(double r, double g, double b, double[] h, double[] s, double[] v); + /** + * @param chooser cast=(GtkColorChooser *) + * @param orientation cast=(GtkOrientation) + * @param colors_per_line cast=(gint) + * @param n_colors cast=(gint) + * @param colors cast=(GdkRGBA *) + */ + public static final native void gtk_color_chooser_add_palette(long chooser, int orientation, int colors_per_line, int n_colors, long colors); + /** + * @param chooser cast=(GtkColorChooser *) + * @param use_alpha cast=(gboolean) + */ + public static final native void gtk_color_chooser_set_use_alpha(long chooser, boolean use_alpha); + /** + * @param chooser cast=(GtkColorChooser *) + */ + public static final native boolean gtk_color_chooser_get_use_alpha(long chooser); + /** + * @param chooser cast=(GtkColorChooser *) + * @param color cast=(GdkRGBA *) + */ + public static final native void gtk_color_chooser_set_rgba(long chooser, GdkRGBA color); + /** + * @param chooser cast=(GtkColorChooser *) + * @param color cast=(GdkRGBA *) + */ + public static final native void gtk_color_chooser_get_rgba(long chooser, GdkRGBA color); + /** + * @param title cast=(const gchar *) + * @param parent cast=(GtkWindow *) + */ + public static final native long gtk_color_chooser_dialog_new(byte[] title, long parent); + /* GtkContainer */ /** * @param container cast=(GtkContainer *) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java index f255f723e25..b5ca66e58ce 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk4/GTK4.java @@ -283,6 +283,56 @@ public class GTK4 { */ public static final native long gtk_file_dialog_save_finish(long self, long result, long[] error); + /* GtkColorDialog */ + /** + * @method flags=dynamic + */ + public static final native long gtk_color_dialog_new(); + /** + * @method flags=dynamic + * + * @param title cast=(char *) + */ + public static final native long gtk_color_dialog_set_title(long self, byte[] title); + /** + * @method flags=dynamic + * + * @param with_alpha cast=(gboolean) + */ + public static final native void gtk_color_dialog_set_with_alpha(long self, boolean with_alpha); + /** + * @method flags=dynamic + */ + public static final native boolean gtk_color_dialog_get_with_alpha(long self); + /** + * @method flags=dynamic + * + * @param modal cast=(gboolean) + */ + public static final native void gtk_color_dialog_set_modal(long self, boolean modal); + /** + * @method flags=dynamic + */ + public static final native boolean gtk_color_dialog_get_modal(long self); + /** + * @method flags=dynamic + * + * @param parent cast=(GtkWindow *) + * @param initial_color cast=(GdkRGBA *) + * @param cancellable cast=(GCancellable *) + * @param callback cast=(GAsyncReadyCallback) + * @param user_data cast=(gpointer) + */ + public static final native void gtk_color_dialog_choose_rgba(long self, long parent, GdkRGBA initial_color, long cancellable, long callback, long user_data); + /** + * @method flags=dynamic + * + * @param result cast=(GAsyncResult *) + * @param error cast=(GError **) + */ + public static final native long gtk_color_dialog_choose_rgba_finish(long self, long result, long[] error); + + /* GtkScrolledWindow */ public static final native long gtk_scrolled_window_new(); /** @param scrolled_window cast=(GtkScrolledWindow *) */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java index cd0a73e4126..86dbf59eacf 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java @@ -131,7 +131,24 @@ public RGB[] getRGBs() { */ public RGB open () { byte[] buffer = Converter.javaStringToCString(title); - long handle = GTK.gtk_color_chooser_dialog_new(buffer, parent.topHandle()); + long handle; + if (GTK.GTK4) { + handle = GTK4.gtk_color_dialog_new(); + } else { + handle = GTK3.gtk_color_chooser_dialog_new(buffer, parent.topHandle()); + } + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + if (GTK.GTK4) { + // TODO The color dialog isn't opened a non-modal window. However, the + // "same" API is used for e.g. the Font Dialog, where everything works. + // So this looks like a bug within GTK... + // Error: + // g_object_new_valist: invalid object type 'SwtFixed' for value type 'GtkWindow' + // GtkDialog mapped without a transient parent. This is discouraged. + GTK4.gtk_color_dialog_set_modal(handle, true); + GTK4.gtk_color_dialog_set_title(handle, buffer); + } + Display display = parent != null ? parent.getDisplay(): Display.getCurrent(); GdkRGBA rgba = new GdkRGBA(); @@ -141,34 +158,46 @@ public RGB open () { rgba.blue = (double) rgb.blue / 255; rgba.alpha = 1; } - GTK.gtk_color_chooser_set_rgba (handle, rgba); - if (rgbs != null) { - int colorsPerRow = 9; - long gdkRGBAS = OS.g_malloc(GdkRGBA.sizeof * rgbs.length); - rgba = new GdkRGBA (); - for (int i=0; i The new GtkColorDialog api doesn't have this feature atm. We might + // > want to bring it back, but judging from application use of color + // > choosers, setting custom palettes is not very popular. + if (GTK4.gtk_color_dialog_get_with_alpha(handle)) { + GTK4.gtk_color_dialog_set_with_alpha(handle, false); } - GTK.gtk_color_chooser_add_palette(handle, GTK.GTK_ORIENTATION_HORIZONTAL, colorsPerRow, - rgbs.length, gdkRGBAS); - GTK.gtk_color_chooser_set_rgba (handle, rgba); + } else { + GTK3.gtk_color_chooser_set_rgba (handle, rgba); + if (rgbs != null) { + int colorsPerRow = 9; + long gdkRGBAS = OS.g_malloc(GdkRGBA.sizeof * rgbs.length); + rgba = new GdkRGBA (); + for (int i=0; i