From 88ffa6b3ea08098641f0307e99d3b91e831f45af Mon Sep 17 00:00:00 2001 From: Veronika Irvine Date: Wed, 19 Nov 2003 20:06:05 +0000 Subject: improve background support --- .../Eclipse SWT PI/gtk/library/os_custom.c | 58 ++++++++++++++++++++++ .../gtk/org/eclipse/swt/internal/gtk/OS.java | 9 ++++ .../gtk/org/eclipse/swt/widgets/Button.java | 12 ++--- .../gtk/org/eclipse/swt/widgets/Combo.java | 12 +---- .../gtk/org/eclipse/swt/widgets/Control.java | 52 +++++++++++-------- .../gtk/org/eclipse/swt/widgets/Group.java | 4 +- .../gtk/org/eclipse/swt/widgets/Label.java | 12 ++--- .../gtk/org/eclipse/swt/widgets/List.java | 8 --- .../gtk/org/eclipse/swt/widgets/Table.java | 8 --- .../gtk/org/eclipse/swt/widgets/Text.java | 8 --- 10 files changed, 113 insertions(+), 70 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c index ee4acc697c..99bf26696c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.c @@ -306,6 +306,64 @@ JNIEXPORT jint JNICALL OS_NATIVE(gdk_1screen_1get_1n_1monitors) } #endif +#ifndef NO_gtk_1rc_1style_1get_1bg_1pixmap_1name +JNIEXPORT jint JNICALL OS_NATIVE(gtk_1rc_1style_1get_1bg_1pixmap_1name) + (JNIEnv *env, jclass that, jint arg0, jint arg1) +{ + jint rc; + + NATIVE_ENTER(env, that, "gtk_1rc_1style_1get_1bg_1pixmap_1name\n") + rc = (jint) ((GtkRcStyle *)arg0)->bg_pixmap_name[arg1] ; + NATIVE_EXIT(env, that, "gtk_1rc_1style_1get_1bg_1pixmap_1name\n") + return rc; +} +#endif + +#ifndef NO_gtk_1rc_1style_1get_1color_1flags +JNIEXPORT jint JNICALL OS_NATIVE(gtk_1rc_1style_1get_1color_1flags) + (JNIEnv *env, jclass that, jint arg0, jint arg1) +{ + jint rc; + + NATIVE_ENTER(env, that, "gtk_1rc_1style_1get_1color_1flags\n") + rc = (jint) ((GtkRcStyle *)arg0)->color_flags[arg1] ; + NATIVE_EXIT(env, that, "gtk_1rc_1style_1get_1color_1flags\n") + return rc; +} +#endif + +#ifndef NO_gtk_1rc_1style_1set_1bg +JNIEXPORT void JNICALL OS_NATIVE(gtk_1rc_1style_1set_1bg) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jobject arg2) +{ + GdkColor _arg2, *lparg2=NULL; + NATIVE_ENTER(env, that, "gtk_1rc_1style_1set_1bg\n") + if (arg2) lparg2 = getGdkColorFields(env, arg2, &_arg2); + ((GtkRcStyle *)arg0)->bg[arg1] = (GdkColor)_arg2; + NATIVE_EXIT(env, that, "gtk_1rc_1style_1set_1bg\n") +} +#endif + +#ifndef NO_gtk_1rc_1style_1set_1bg_1pixmap_1name +JNIEXPORT void JNICALL OS_NATIVE(gtk_1rc_1style_1set_1bg_1pixmap_1name) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2) +{ + NATIVE_ENTER(env, that, "gtk_1rc_1style_1set_1bg_1pixmap_1name\n") + ((GtkRcStyle *)arg0)->bg_pixmap_name[arg1] = (char *)arg2; + NATIVE_EXIT(env, that, "gtk_1rc_1style_1set_1bg_1pixmap_1name\n") +} +#endif + +#ifndef NO_gtk_1rc_1style_1set_1color_1flags +JNIEXPORT void JNICALL OS_NATIVE(gtk_1rc_1style_1set_1color_1flags) + (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2) +{ + NATIVE_ENTER(env, that, "gtk_1rc_1style_1set_1color_1flags\n") + ((GtkRcStyle *)arg0)->color_flags[arg1] = arg2; + NATIVE_EXIT(env, that, "gtk_1rc_1style_1set_1color_1flags\n") +} +#endif + #ifndef NO_gtk_1rc_1style_1set_1xthickness JNIEXPORT void JNICALL OS_NATIVE(gtk_1rc_1style_1set_1xthickness) (JNIEnv *env, jclass that, jint arg0, jint arg1) 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 f4003c0f03..6ebee90c14 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 @@ -210,6 +210,7 @@ public class OS { public static final int GTK_PROGRESS_BOTTOM_TO_TOP = 0x2; public static final int GTK_REALIZED = 1 << 6; public static final int GTK_RELIEF_NONE = 0x2; + public static final int GTK_RC_BG = 1 << 1; public static final int GTK_RESPONSE_OK = 0xfffffffb; public static final int GTK_SELECTION_BROWSE = 0x2; public static final int GTK_SELECTION_MULTIPLE = 0x3; @@ -219,8 +220,11 @@ public class OS { public static final int GTK_SHADOW_IN = 0x1; public static final int GTK_SHADOW_NONE = 0x0; public static final int GTK_SHADOW_OUT = 0x2; + public static final int GTK_STATE_ACTIVE = 0x1; public static final int GTK_STATE_INSENSITIVE = 0x4; public static final int GTK_STATE_NORMAL = 0x0; + public static final int GTK_STATE_PRELIGHT = 0x2; + public static final int GTK_STATE_SELECTED = 0x3; public static final int GTK_TEXT_DIR_LTR = 1; public static final int GTK_TEXT_DIR_NONE = 0 ; public static final int GTK_TEXT_DIR_RTL = 2; @@ -724,6 +728,11 @@ public static final synchronized native int gtk_range_get_adjustment(int range); public static final synchronized native void gtk_range_set_increments(int range, double step, double page); public static final synchronized native void gtk_range_set_range(int range, double min, double max); public static final synchronized native void gtk_range_set_value(int range, double value); +public static final synchronized native int gtk_rc_style_get_bg_pixmap_name(int style, int index); +public static final synchronized native int gtk_rc_style_get_color_flags(int style, int index); +public static final synchronized native void gtk_rc_style_set_bg(int style, int index, GdkColor color); +public static final synchronized native void gtk_rc_style_set_bg_pixmap_name(int style, int index, int name); +public static final synchronized native void gtk_rc_style_set_color_flags(int style, int index, int flag); public static final synchronized native void gtk_rc_style_set_xthickness(int style, int thickness); public static final synchronized native void gtk_rc_style_set_ythickness(int style, int thickness); public static final synchronized native void gtk_scale_set_digits(int scale, int digits); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java index afe2763bfb..94e9aa3c1d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java @@ -538,9 +538,9 @@ public void setAlignment (int alignment) { void setBackgroundColor (GdkColor color) { super.setBackgroundColor (color); - OS.gtk_widget_modify_bg (fixedHandle, 0, color); - if (labelHandle != 0) OS.gtk_widget_modify_bg (labelHandle, 0, color); - if (imageHandle != 0) OS.gtk_widget_modify_bg (imageHandle, 0, color); + setBackgroundColor(fixedHandle, color); + if (labelHandle != 0) setBackgroundColor(labelHandle, color); + if (imageHandle != 0) setBackgroundColor(imageHandle, color); } boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { @@ -588,9 +588,9 @@ boolean setRadioSelection (boolean value) { void setForegroundColor (GdkColor color) { super.setForegroundColor (color); - OS.gtk_widget_modify_fg (fixedHandle, 0, color); - if (labelHandle != 0) OS.gtk_widget_modify_fg (labelHandle, 0, color); - if (imageHandle != 0) OS.gtk_widget_modify_fg (imageHandle, 0, color); + OS.gtk_widget_modify_fg (fixedHandle, OS.GTK_STATE_NORMAL, color); + if (labelHandle != 0) OS.gtk_widget_modify_fg (labelHandle, OS.GTK_STATE_NORMAL, color); + if (imageHandle != 0) OS.gtk_widget_modify_fg (imageHandle, OS.GTK_STATE_NORMAL, color); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java index 2a780062e2..7027994b21 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java @@ -400,14 +400,6 @@ public void cut () { OS.gtk_editable_cut_clipboard (entryHandle); } -GdkColor defaultBackground () { - return display.COLOR_TEXT_BACKGROUND; -} - -GdkColor defaultForeground () { - return display.COLOR_TEXT_FOREGROUND; -} - void deregister () { super.deregister (); if (arrowHandle != 0) display.removeWidget (arrowHandle); @@ -1107,7 +1099,7 @@ void setForegroundColor (GdkColor color) { int count = OS.g_list_length (itemsList); for (int i=count - 1; i>=0; i--) { int widget = OS.gtk_bin_get_child (OS.g_list_nth_data (itemsList, i)); - OS.gtk_widget_modify_fg (widget, 0, color); + OS.gtk_widget_modify_fg (widget, OS.GTK_STATE_NORMAL, color); } OS.g_list_free (itemsList); } @@ -1205,7 +1197,7 @@ void setItems (String [] items, boolean keepText, boolean keepSelection) { int count = OS.g_list_length (itemsList); for (int i=count - 1; i>=0; i--) { int widget = OS.gtk_bin_get_child (OS.g_list_nth_data (itemsList, i)); - OS.gtk_widget_modify_fg (widget, 0, color); + OS.gtk_widget_modify_fg (widget, OS.GTK_STATE_NORMAL, color); OS.gtk_widget_modify_font (widget, font); } OS.g_list_free (itemsList); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java index d64c661866..03906325a6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java @@ -86,18 +86,10 @@ public Control (Composite parent, int style) { createWidget (0); } -GdkColor defaultBackground () { - return display.COLOR_WIDGET_BACKGROUND; -} - int defaultFont () { return display.defaultFont; } -GdkColor defaultForeground () { - return display.COLOR_WIDGET_FOREGROUND; -} - void deregister () { super.deregister (); if (fixedHandle != 0) display.removeWidget (fixedHandle); @@ -1344,15 +1336,17 @@ GdkColor getBackgroundColor () { GdkColor getBgColor () { int fontHandle = fontHandle (); + OS.gtk_widget_realize (fontHandle); GdkColor color = new GdkColor (); - OS.gtk_style_get_bg (OS.gtk_widget_get_style (fontHandle), 0, color); + OS.gtk_style_get_bg (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); return color; } GdkColor getBaseColor () { int fontHandle = fontHandle (); + OS.gtk_widget_realize (fontHandle); GdkColor color = new GdkColor (); - OS.gtk_style_get_base (OS.gtk_widget_get_style (fontHandle), 0, color); + OS.gtk_style_get_base (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); return color; } @@ -1433,8 +1427,9 @@ GdkColor getForegroundColor () { GdkColor getFgColor () { int fontHandle = fontHandle (); + OS.gtk_widget_realize (fontHandle); GdkColor color = new GdkColor (); - OS.gtk_style_get_fg (OS.gtk_widget_get_style (fontHandle), 0, color); + OS.gtk_style_get_fg (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); return color; } @@ -1444,8 +1439,9 @@ Point getIMCaretPos () { GdkColor getTextColor () { int fontHandle = fontHandle (); + OS.gtk_widget_realize (fontHandle); GdkColor color = new GdkColor (); - OS.gtk_style_get_text (OS.gtk_widget_get_style (fontHandle), 0, color); + OS.gtk_style_get_text (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); return color; } @@ -2290,18 +2286,32 @@ void sendMouseEvent (int type, int button, int gdkEvent) { */ public void setBackground (Color color) { checkWidget(); - GdkColor gdkColor; - if (color == null) { - gdkColor = defaultBackground (); - } else { + GdkColor gdkColor = null; + if (color != null) { if (color.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); gdkColor = color.handle; } setBackgroundColor (gdkColor); } +void setBackgroundColor (int handle, GdkColor color) { + int index = OS.GTK_STATE_NORMAL; + int style = OS.gtk_widget_get_modifier_style (handle); + int ptr = OS.gtk_rc_style_get_bg_pixmap_name (style, index); + if (ptr != 0) OS.g_free (ptr); + String name = color == null ? "" : ""; + byte[] buffer = Converter.wcsToMbcs (null, name, true); + ptr = OS.g_malloc (buffer.length); + OS.memmove (ptr, buffer, buffer.length); + OS.gtk_rc_style_set_bg_pixmap_name (style, index, ptr); + OS.gtk_rc_style_set_bg (style, index, color); + int flag = OS.gtk_rc_style_get_color_flags(style, index); + flag = (color == null) ? flag & ~OS.GTK_RC_BG : flag | OS.GTK_RC_BG; + OS.gtk_rc_style_set_color_flags(style, index, flag); + OS.gtk_widget_modify_style (handle, style); +} void setBackgroundColor (GdkColor color) { - OS.gtk_widget_modify_bg (handle, 0, color); + setBackgroundColor(handle, color); } /** @@ -2452,10 +2462,8 @@ void setFontDescription (int font) { */ public void setForeground (Color color) { checkWidget(); - GdkColor gdkColor; - if (color == null) { - gdkColor = defaultForeground (); - } else { + GdkColor gdkColor = null; + if (color != null) { if (color.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); gdkColor = color.handle; } @@ -2463,7 +2471,7 @@ public void setForeground (Color color) { } void setForegroundColor (GdkColor color) { - OS.gtk_widget_modify_fg (handle, 0, color); + OS.gtk_widget_modify_fg (handle, OS.GTK_STATE_NORMAL, color); } void setInitialSize () { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java index d4a55a8e90..a4b826fabe 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java @@ -280,7 +280,7 @@ void releaseWidget () { void setBackgroundColor (GdkColor color) { super.setBackgroundColor (color); - OS.gtk_widget_modify_bg (fixedHandle, 0, color); + setBackgroundColor(fixedHandle, color); } void setFontDescription (int font) { @@ -290,7 +290,7 @@ void setFontDescription (int font) { void setForegroundColor (GdkColor color) { super.setForegroundColor (color); - OS.gtk_widget_modify_fg (labelHandle, 0, color); + OS.gtk_widget_modify_fg (labelHandle, OS.GTK_STATE_NORMAL, color); } void setOrientation () { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java index 264d0e17c7..a6987f8506 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java @@ -385,9 +385,9 @@ public void setAlignment (int alignment) { void setBackgroundColor (GdkColor color) { super.setBackgroundColor (color); - OS.gtk_widget_modify_bg (fixedHandle, 0, color); - if (labelHandle != 0) OS.gtk_widget_modify_bg (labelHandle, 0, color); - if (imageHandle != 0) OS.gtk_widget_modify_bg (imageHandle, 0, color); + setBackgroundColor(fixedHandle, color); + if (labelHandle != 0) setBackgroundColor(labelHandle, color); + if (imageHandle != 0) setBackgroundColor(imageHandle, color); } boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { @@ -436,9 +436,9 @@ void setFontDescription (int font) { void setForegroundColor (GdkColor color) { super.setForegroundColor (color); - OS.gtk_widget_modify_fg (fixedHandle, 0, color); - if (labelHandle != 0) OS.gtk_widget_modify_fg (labelHandle, 0, color); - if (imageHandle != 0) OS.gtk_widget_modify_fg (imageHandle, 0, color); + OS.gtk_widget_modify_fg (fixedHandle, OS.GTK_STATE_NORMAL, color); + if (labelHandle != 0) OS.gtk_widget_modify_fg (labelHandle, OS.GTK_STATE_NORMAL, color); + if (imageHandle != 0) OS.gtk_widget_modify_fg (imageHandle, OS.GTK_STATE_NORMAL, color); } void setOrientation () { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java index 857a1226ae..cd3e2b4193 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java @@ -234,14 +234,6 @@ public Point computeSize (int wHint, int hHint, boolean changed) { return size; } -GdkColor defaultBackground () { - return display.COLOR_LIST_BACKGROUND; -} - -GdkColor defaultForeground () { - return display.COLOR_LIST_FOREGROUND; -} - void deregister() { super.deregister (); display.removeWidget (OS.gtk_tree_view_get_selection (handle)); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java index a46e5604d9..2a03f0331e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java @@ -404,14 +404,6 @@ void createWidget (int index) { itemCount = columnCount = 0; } -GdkColor defaultBackground () { - return display.COLOR_LIST_BACKGROUND; -} - -GdkColor defaultForeground () { - return display.COLOR_LIST_FOREGROUND; -} - void deregister() { super.deregister (); display.removeWidget (OS.gtk_tree_view_get_selection (handle)); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java index 8d53fe6507..b7a66ce28a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java @@ -375,14 +375,6 @@ public void cut () { } } -GdkColor defaultBackground () { - return display.COLOR_TEXT_BACKGROUND; -} - -GdkColor defaultForeground () { - return display.COLOR_TEXT_FOREGROUND; -} - void deregister () { super.deregister (); if (bufferHandle != 0) display.removeWidget (bufferHandle); -- cgit