diff options
author | Carolyn MacLeod | 2012-03-07 16:45:37 +0000 |
---|---|---|
committer | Carolyn MacLeod | 2012-03-07 16:45:37 +0000 |
commit | 7fc64542adf6b6fd095c79d02a839c04648673dd (patch) | |
tree | 2aa1f987cd0bf5a33362d88acbfa883c6aee359f | |
parent | e42c3e44904fd7e5ccbad39e2ba440dcb5cf8eba (diff) | |
download | eclipse.platform.swt-7fc64542adf6b6fd095c79d02a839c04648673dd.tar.gz eclipse.platform.swt-7fc64542adf6b6fd095c79d02a839c04648673dd.tar.xz eclipse.platform.swt-7fc64542adf6b6fd095c79d02a839c04648673dd.zip |
Gtk ColorDialog get/setRGBs
5 files changed, 75 insertions, 34 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 3c39393c0a..3acdece27f 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 @@ -18894,6 +18894,30 @@ fail: } #endif +#if (!defined(NO_memmove__ILorg_eclipse_swt_internal_gtk_GdkColor_2I) && !defined(JNI64)) || (!defined(NO_memmove__JLorg_eclipse_swt_internal_gtk_GdkColor_2J) && defined(JNI64)) +#ifndef JNI64 +JNIEXPORT void JNICALL OS_NATIVE(memmove__ILorg_eclipse_swt_internal_gtk_GdkColor_2I)(JNIEnv *env, jclass that, jintLong arg0, jobject arg1, jintLong arg2) +#else +JNIEXPORT void JNICALL OS_NATIVE(memmove__JLorg_eclipse_swt_internal_gtk_GdkColor_2J)(JNIEnv *env, jclass that, jintLong arg0, jobject arg1, jintLong arg2) +#endif +{ + GdkColor _arg1, *lparg1=NULL; +#ifndef JNI64 + OS_NATIVE_ENTER(env, that, memmove__ILorg_eclipse_swt_internal_gtk_GdkColor_2I_FUNC); +#else + OS_NATIVE_ENTER(env, that, memmove__JLorg_eclipse_swt_internal_gtk_GdkColor_2J_FUNC); +#endif + if (arg1) if ((lparg1 = getGdkColorFields(env, arg1, &_arg1)) == NULL) goto fail; + memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); +fail: +#ifndef JNI64 + OS_NATIVE_EXIT(env, that, memmove__ILorg_eclipse_swt_internal_gtk_GdkColor_2I_FUNC); +#else + OS_NATIVE_EXIT(env, that, memmove__JLorg_eclipse_swt_internal_gtk_GdkColor_2J_FUNC); +#endif +} +#endif + #if (!defined(NO_memmove__ILorg_eclipse_swt_internal_gtk_GdkEventButton_2I) && !defined(JNI64)) || (!defined(NO_memmove__JLorg_eclipse_swt_internal_gtk_GdkEventButton_2J) && defined(JNI64)) #ifndef JNI64 JNIEXPORT void JNICALL OS_NATIVE(memmove__ILorg_eclipse_swt_internal_gtk_GdkEventButton_2I)(JNIEnv *env, jclass that, jintLong arg0, jobject arg1, jintLong arg2) 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 fe39c45c79..b9bc96dda4 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 @@ -18,8 +18,8 @@ #ifdef NATIVE_STATS -int OS_nativeFunctionCount = 1382; -int OS_nativeFunctionCallCount[1382]; +int OS_nativeFunctionCount = 1383; +int OS_nativeFunctionCallCount[1383]; char * OS_nativeFunctionNames[] = { #ifndef JNI64 "Call__IIII", @@ -1514,6 +1514,11 @@ char * OS_nativeFunctionNames[] = { "memmove__JLorg_eclipse_swt_internal_gtk_GTypeInfo_2I", #endif #ifndef JNI64 + "memmove__ILorg_eclipse_swt_internal_gtk_GdkColor_2I", +#else + "memmove__JLorg_eclipse_swt_internal_gtk_GdkColor_2J", +#endif +#ifndef JNI64 "memmove__ILorg_eclipse_swt_internal_gtk_GdkEventButton_2I", #else "memmove__JLorg_eclipse_swt_internal_gtk_GdkEventButton_2J", 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 b0423be00f..c3eacdd518 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 @@ -1522,6 +1522,11 @@ typedef enum { memmove__JLorg_eclipse_swt_internal_gtk_GTypeInfo_2I_FUNC, #endif #ifndef JNI64 + memmove__ILorg_eclipse_swt_internal_gtk_GdkColor_2I_FUNC, +#else + memmove__JLorg_eclipse_swt_internal_gtk_GdkColor_2J_FUNC, +#endif +#ifndef JNI64 memmove__ILorg_eclipse_swt_internal_gtk_GdkEventButton_2I_FUNC, #else memmove__JLorg_eclipse_swt_internal_gtk_GdkEventButton_2J_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java index 42768fd733..55bc32c03a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java @@ -13807,6 +13807,12 @@ public static final native void memmove(int /*long*/ dest, GtkAdjustment src); * @param src cast=(const void *),flags=no_out * @param size cast=(size_t) */ +public static final native void memmove(int /*long*/ dest, GdkColor src, int /*long*/ size); +/** + * @param dest cast=(void *) + * @param src cast=(const void *),flags=no_out + * @param size cast=(size_t) + */ public static final native void memmove(int /*long*/ dest, GdkEventButton src, int /*long*/ size); /** * @param dest cast=(void *) @@ -15261,5 +15267,4 @@ public static final int access (byte [] path, int amode) { * @param s2 cast=(const char*) */ public static final native int strcmp (int /*long*/ s1, byte [] s2); - } 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 eb384e19c7..4d18517410 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 @@ -153,21 +153,25 @@ public RGB open () { } OS.gtk_color_selection_set_has_palette (dialog.colorsel, true); if (rgbs != null) { - StringBuffer sb = new StringBuffer(); + int /*long*/ colors = OS.g_malloc(GdkColor.sizeof * rgbs.length); for (int i=0; i<rgbs.length; i++) { RGB rgb = rgbs[i]; if (rgb != null) { - sb.append("#"); // $NON_NLS1$ - sb.append(String.format("%02x", new Integer[] {new Integer(rgb.red & 0xFF)})); - sb.append(String.format("%02x", new Integer[] {new Integer(rgb.green & 0xFF)})); - sb.append(String.format("%02x", new Integer[] {new Integer(rgb.blue & 0xFF)})); - if (i<rgbs.length-1) sb.append(":"); // $NON_NLS1$ + color.red = (short)((rgb.red & 0xFF) | ((rgb.red & 0xFF) << 8)); + color.green = (short)((rgb.green & 0xFF) | ((rgb.green & 0xFF) << 8)); + color.blue = (short)((rgb.blue & 0xFF) | ((rgb.blue & 0xFF) << 8)); + OS.memmove (colors + i * GdkColor.sizeof, color, GdkColor.sizeof); } } + int /*long*/ strPtr = OS.gtk_color_selection_palette_to_string(colors, rgbs.length); + int length = OS.strlen (strPtr); + buffer = new byte [length]; + OS.memmove (buffer, strPtr, length); + String paletteString = new String (Converter.mbcsToWcs (null, buffer)); + buffer = Converter.wcsToMbcs (null, paletteString, true); + OS.g_free (colors); int /*long*/ settings = OS.gtk_settings_get_default (); if (settings != 0) { - System.out.println("Setting color palette to: " + sb.toString()); - buffer = Converter.wcsToMbcs (null, sb.toString(), true); OS.gtk_settings_set_string_property(settings, OS.gtk_color_palette, buffer, Converter.wcsToMbcs (null, "gtk_color_selection_palette_to_string", true)); } } @@ -204,29 +208,27 @@ public RGB open () { int green = (color.green >> 8) & 0xFF; int blue = (color.blue >> 8) & 0xFF; rgb = new RGB (red, green, blue); - - int /*long*/ settings = OS.gtk_settings_get_default (); - if (settings != 0) { - int /*long*/ [] gcp_buffer = new int /*long*/ [1]; - OS.g_object_get (settings, OS.gtk_color_palette, gcp_buffer, 0); - if (gcp_buffer [0] != 0) { - int /*long*/ paletteString = gcp_buffer [0]; - int length = OS.strlen (paletteString); - buffer = new byte [length + 1]; - OS.memmove (buffer, paletteString, length); - // TODO: free or not? - //OS.g_free (paletteString); - String [] gdkColorString = new String(buffer).split(":"); - rgbs = new RGB [gdkColorString.length]; - for (int i=0; i<gdkColorString.length; i++) { - String colorString = gdkColorString[i]; - buffer = Converter.wcsToMbcs (null, colorString, true); - OS.gdk_color_parse(buffer, color); - red = (color.red >> 8) & 0xFF; - green = (color.green >> 8) & 0xFF; - blue = (color.blue >> 8) & 0xFF; - rgbs [i] = new RGB (red, green, blue); - } + } + int /*long*/ settings = OS.gtk_settings_get_default (); + if (settings != 0) { + int /*long*/ [] ptr = new int /*long*/ [1]; + OS.g_object_get (settings, OS.gtk_color_palette, ptr, 0); + if (ptr [0] != 0) { + int length = OS.strlen (ptr [0]); + buffer = new byte [length]; + OS.memmove (buffer, ptr [0], length); + OS.g_free (ptr [0]); + String [] gdkColorStrings = new String(Converter.mbcsToWcs (null, buffer)).split(":"); + length = length == 0 ? 0 : gdkColorStrings.length; + rgbs = new RGB [length]; + for (int i=0; i<length; i++) { + String colorString = gdkColorStrings[i]; + buffer = Converter.wcsToMbcs (null, colorString, true); + OS.gdk_color_parse(buffer, color); + int red = (color.red >> 8) & 0xFF; + int green = (color.green >> 8) & 0xFF; + int blue = (color.blue >> 8) & 0xFF; + rgbs [i] = new RGB (red, green, blue); } } } |