This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: Peer colour and font fixes
- From: Thomas Fitzsimmons <fitzsim at redhat dot com>
- To: GCJ Patches <java-patches at gcc dot gnu dot org>
- Date: Tue, 07 Oct 2003 16:09:43 -0400
- Subject: Patch: Peer colour and font fixes
Hello,
This patch fixes some colour and font problems in the GTK peers, as well
as a small FlowLayout problem.
OK to commit?
Tom
2003-10-07 Thomas Fitzsimmons <fitzsim@redhat.com>
* gnu/java/awt/peer/gtk/GtkButtonPeer.java
(gtkSetFont): Handle BOLD and ITALIC style specifiers.
(gtkWidgetSetForeground): New method.
* gnu/java/awt/peer/gtk/GtkComponentPeer.java
(gtkWidgetSetBackground,gtkWidgetSetForeground): New methods.
(setBackground,setForeground): Implement.
* gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
(gtkSetFont): Handle BOLD and ITALIC style specifiers.
* gnu/java/awt/peer/gtk/GtkTextFieldPeer.java: Likewise.
* java/awt/FlowLayout.java (layoutContainer): Fix offset problem
for CENTER and RIGHT alignments.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c (drawString):
Position PangoLayout relative to text's baseline.
* jni/gtk-peer/gtkpeer.h: Define AWT font style constants.
Index: gnu/java/awt/peer/gtk/GtkButtonPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkButtonPeer.java,v
retrieving revision 1.4
diff -u -r1.4 GtkButtonPeer.java
--- gnu/java/awt/peer/gtk/GtkButtonPeer.java 29 Jul 2003 19:42:37 -0000 1.4
+++ gnu/java/awt/peer/gtk/GtkButtonPeer.java 7 Oct 2003 19:50:27 -0000
@@ -51,7 +51,8 @@
{
native void create ();
- native void gtkSetFont(String xlfd, int size);
+ native void gtkSetFont(String name, int style, int size);
+ native void gtkWidgetSetForeground (int red, int green, int blue);
public GtkButtonPeer (Button b)
{
@@ -95,6 +96,6 @@
public void setFont (Font f)
{
- gtkSetFont(f.getName(), f.getSize());
+ gtkSetFont(f.getName(), f.getStyle(), f.getSize());
}
}
Index: gnu/java/awt/peer/gtk/GtkComponentPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkComponentPeer.java,v
retrieving revision 1.6
diff -u -r1.6 GtkComponentPeer.java
--- gnu/java/awt/peer/gtk/GtkComponentPeer.java 2 Oct 2003 18:34:56 -0000 1.6
+++ gnu/java/awt/peer/gtk/GtkComponentPeer.java 7 Oct 2003 19:50:27 -0000
@@ -86,6 +86,8 @@
native void gtkWidgetGetDimensions(int[] dim);
native void gtkWidgetGetLocationOnScreen(int[] point);
native void gtkWidgetSetCursor (int type);
+ native void gtkWidgetSetBackground (int red, int green, int blue);
+ native void gtkWidgetSetForeground (int red, int green, int blue);
void create ()
{
@@ -114,12 +116,10 @@
connectHooks ();
- if (awtComponent.getForeground () == null)
- awtComponent.setForeground (getForeground ());
- if (awtComponent.getBackground () == null)
- awtComponent.setBackground (getBackground ());
- // if (c.getFont () == null)
- // c.setFont (cp.getFont ());
+ if (awtComponent.getForeground () != null)
+ setForeground (awtComponent.getForeground ());
+ if (awtComponent.getBackground () != null)
+ setBackground (awtComponent.getBackground ());
if (awtComponent.getFont() != null)
setFont(awtComponent.getFont());
@@ -276,7 +276,7 @@
public void setBackground (Color c)
{
- // System.out.println ("setBackground [UNIMPLEMENTED");
+ gtkWidgetSetBackground (c.getRed(), c.getGreen(), c.getBlue());
}
native public void setNativeBounds (int x, int y, int width, int height);
@@ -314,7 +314,7 @@
public void setForeground (Color c)
{
- // System.out.println ("setForeground [UNIMPLEMENTED");
+ gtkWidgetSetForeground (c.getRed(), c.getGreen(), c.getBlue());
}
public Color getForeground ()
Index: gnu/java/awt/peer/gtk/GtkTextAreaPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkTextAreaPeer.java,v
retrieving revision 1.4
diff -u -r1.4 GtkTextAreaPeer.java
--- gnu/java/awt/peer/gtk/GtkTextAreaPeer.java 29 Jul 2003 19:42:37 -0000 1.4
+++ gnu/java/awt/peer/gtk/GtkTextAreaPeer.java 7 Oct 2003 19:50:27 -0000
@@ -48,7 +48,7 @@
{
native void create (int scrollbarVisibility);
- native void gtkSetFont(String xlfd, int size);
+ native void gtkSetFont(String name, int style, int size);
void create ()
{
@@ -107,6 +107,6 @@
public void setFont (Font f)
{
- gtkSetFont(f.getName(), f.getSize());
+ gtkSetFont(f.getName(), f.getStyle(), f.getSize());
}
}
Index: gnu/java/awt/peer/gtk/GtkTextFieldPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkTextFieldPeer.java,v
retrieving revision 1.6
diff -u -r1.6 GtkTextFieldPeer.java
--- gnu/java/awt/peer/gtk/GtkTextFieldPeer.java 29 Jul 2003 19:42:37 -0000 1.6
+++ gnu/java/awt/peer/gtk/GtkTextFieldPeer.java 7 Oct 2003 19:50:28 -0000
@@ -55,7 +55,7 @@
native void gtkEntryGetSize (int cols, int dims[]);
- native void gtkSetFont(String xlfd, int size);
+ native void gtkSetFont(String name, int style, int size);
public GtkTextFieldPeer (TextField tf)
{
@@ -104,7 +104,7 @@
public void setFont (Font f)
{
- gtkSetFont(f.getName(), f.getSize());
+ gtkSetFont(f.getName(), f.getStyle(), f.getSize());
}
public void handleEvent (AWTEvent e)
Index: java/awt/FlowLayout.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/FlowLayout.java,v
retrieving revision 1.9
diff -u -r1.9 FlowLayout.java
--- java/awt/FlowLayout.java 19 Feb 2003 00:35:35 -0000 1.9
+++ java/awt/FlowLayout.java 7 Oct 2003 19:50:28 -0000
@@ -205,9 +205,9 @@
if (myalign == LEFT)
x = ins.left + hgap;
else if (myalign == CENTER)
- x = (d.width - new_w) / 2;
+ x = ins.left + (d.width - new_w) / 2 + hgap;
else
- x = d.width - new_w;
+ x = ins.left + (d.width - new_w) + hgap;
for (int k = i; k < j; ++k)
{
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c,v
retrieving revision 1.3
diff -u -r1.3 gnu_java_awt_peer_gtk_GdkGraphics.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c 22 Aug 2003 20:33:50 -0000 1.3
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c 7 Oct 2003 19:50:28 -0000
@@ -193,9 +193,11 @@
struct graphics *g;
const char *cstr;
const char *font_name;
+ int baseline_y;
PangoFontDescription *font_desc;
PangoContext *context;
PangoLayout *layout;
+ PangoLayoutIter *iter;
g = (struct graphics *) NSA_GET_PTR (env, obj);
@@ -213,11 +215,15 @@
layout = pango_layout_new (context);
pango_layout_set_text (layout, cstr, -1);
+ iter = pango_layout_get_iter (layout);
+
+ baseline_y = pango_layout_iter_get_baseline (iter);
gdk_draw_layout (g->drawable, g->gc,
- x + g->x_offset, y + g->y_offset, layout);
+ x + g->x_offset, y + g->y_offset - (baseline_y / PANGO_SCALE), layout);
pango_font_description_free (font_desc);
+ pango_layout_iter_free (iter);
gdk_threads_leave ();
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c,v
retrieving revision 1.4
diff -u -r1.4 gnu_java_awt_peer_gtk_GtkButtonPeer.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c 29 Jul 2003 19:42:37 -0000 1.4
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c 7 Oct 2003 19:50:28 -0000
@@ -53,7 +53,7 @@
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkSetFont
- (JNIEnv *env, jobject obj, jstring jname, jint size)
+ (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
{
const char *font_name;
void *ptr;
@@ -69,18 +69,52 @@
if (!label)
return;
- font_name = (*env)->GetStringUTFChars (env, jname, NULL);
+ font_name = (*env)->GetStringUTFChars (env, name, NULL);
gdk_threads_enter();
font_desc = pango_font_description_from_string (font_name);
pango_font_description_set_size (font_desc, size * PANGO_SCALE);
+ if (style & AWT_STYLE_BOLD)
+ pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
+
+ if (style & AWT_STYLE_ITALIC)
+ pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
+
gtk_widget_modify_font (GTK_WIDGET(label), font_desc);
pango_font_description_free (font_desc);
gdk_threads_leave();
- (*env)->ReleaseStringUTFChars (env, jname, font_name);
+ (*env)->ReleaseStringUTFChars (env, name, font_name);
+}
+
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetSetForeground
+ (JNIEnv *env, jobject obj, jint red, jint green, jint blue)
+{
+ GdkColor color;
+ GtkWidget *label;
+ void *ptr;
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ color.red = (red / 255.0) * 65535;
+ color.green = (green / 255.0) * 65535;
+ color.blue = (blue / 255.0) * 65535;
+
+ gdk_threads_enter ();
+
+ label = gtk_bin_get_child (GTK_BIN(ptr));
+
+ if (!label)
+ return;
+
+ gtk_widget_modify_fg (label, GTK_STATE_NORMAL, &color);
+ gtk_widget_modify_fg (label, GTK_STATE_ACTIVE, &color);
+ gtk_widget_modify_fg (label, GTK_STATE_PRELIGHT, &color);
+
+ gdk_threads_leave ();
}
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c,v
retrieving revision 1.6
diff -u -r1.6 gnu_java_awt_peer_gtk_GtkComponentPeer.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c 2 Oct 2003 18:34:56 -0000 1.6
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c 7 Oct 2003 19:50:28 -0000
@@ -399,6 +399,61 @@
return array;
}
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetBackground
+ (JNIEnv *env, jobject obj, jint red, jint green, jint blue)
+{
+ GdkColor normal_color;
+ GdkColor active_color;
+ GtkWidget *widget;
+ void *ptr;
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ normal_color.red = (red / 255.0) * 65535;
+ normal_color.green = (green / 255.0) * 65535;
+ normal_color.blue = (blue / 255.0) * 65535;
+
+ /* This calculation only approximates the active colors produced by
+ Sun's AWT. */
+ active_color.red = 0.85 * (red / 255.0) * 65535;
+ active_color.green = 0.85 * (green / 255.0) * 65535;
+ active_color.blue = 0.85 * (blue / 255.0) * 65535;
+
+ gdk_threads_enter ();
+
+ widget = GTK_WIDGET (ptr);
+
+ gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &normal_color);
+ gtk_widget_modify_bg (widget, GTK_STATE_ACTIVE, &active_color);
+ gtk_widget_modify_bg (widget, GTK_STATE_PRELIGHT, &normal_color);
+
+ gdk_threads_leave ();
+}
+
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetSetForeground
+ (JNIEnv *env, jobject obj, jint red, jint green, jint blue)
+{
+ GdkColor color;
+ GtkWidget *widget;
+ void *ptr;
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ color.red = (red / 255.0) * 65535;
+ color.green = (green / 255.0) * 65535;
+ color.blue = (blue / 255.0) * 65535;
+
+ gdk_threads_enter ();
+
+ widget = GTK_WIDGET (ptr);
+
+ gtk_widget_modify_fg (widget, GTK_STATE_NORMAL, &color);
+
+ gdk_threads_leave ();
+}
+
void
set_visible (GtkWidget *widget, jboolean visible)
{
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c,v
retrieving revision 1.5
diff -u -r1.5 gnu_java_awt_peer_gtk_GtkTextAreaPeer.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c 5 Aug 2003 18:04:09 -0000 1.5
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c 7 Oct 2003 19:50:28 -0000
@@ -162,7 +162,7 @@
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkSetFont
- (JNIEnv *env, jobject obj, jstring jname, jint size)
+ (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
{
const char *font_name;
void *ptr;
@@ -173,18 +173,24 @@
text = GTK_WIDGET (TEXT_FROM_SW (ptr));
- font_name = (*env)->GetStringUTFChars (env, jname, NULL);
+ font_name = (*env)->GetStringUTFChars (env, name, NULL);
gdk_threads_enter();
font_desc = pango_font_description_from_string (font_name);
pango_font_description_set_size (font_desc, size * PANGO_SCALE);
+ if (style & AWT_STYLE_BOLD)
+ pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
+
+ if (style & AWT_STYLE_ITALIC)
+ pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
+
gtk_widget_modify_font (GTK_WIDGET(text), font_desc);
pango_font_description_free (font_desc);
gdk_threads_leave();
- (*env)->ReleaseStringUTFChars (env, jname, font_name);
+ (*env)->ReleaseStringUTFChars (env, name, font_name);
}
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c,v
retrieving revision 1.6
diff -u -r1.6 gnu_java_awt_peer_gtk_GtkTextFieldPeer.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c 5 Aug 2003 18:04:09 -0000 1.6
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c 7 Oct 2003 19:50:28 -0000
@@ -102,7 +102,7 @@
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_gtkSetFont
- (JNIEnv *env, jobject obj, jstring jname, jint size)
+ (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
{
const char *font_name;
void *ptr;
@@ -112,18 +112,24 @@
ptr = NSA_GET_PTR (env, obj);
entry = GTK_WIDGET (ptr);
- font_name = (*env)->GetStringUTFChars (env, jname, NULL);
+ font_name = (*env)->GetStringUTFChars (env, name, NULL);
gdk_threads_enter();
font_desc = pango_font_description_from_string (font_name);
pango_font_description_set_size (font_desc, size * PANGO_SCALE);
+ if (style & AWT_STYLE_BOLD)
+ pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
+
+ if (style & AWT_STYLE_ITALIC)
+ pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
+
gtk_widget_modify_font (GTK_WIDGET(entry), font_desc);
pango_font_description_free (font_desc);
gdk_threads_leave();
- (*env)->ReleaseStringUTFChars (env, jname, font_name);
+ (*env)->ReleaseStringUTFChars (env, name, font_name);
}
Index: jni/gtk-peer/gtkpeer.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gtkpeer.h,v
retrieving revision 1.4
diff -u -r1.4 gtkpeer.h
--- jni/gtk-peer/gtkpeer.h 2 Oct 2003 18:34:56 -0000 1.4
+++ jni/gtk-peer/gtkpeer.h 7 Oct 2003 19:50:28 -0000
@@ -343,6 +343,10 @@
#define AWT_FOCUS_LOST 1004
#define AWT_FOCUS_GAINED 1005
+#define AWT_STYLE_PLAIN 0
+#define AWT_STYLE_BOLD 1
+#define AWT_STYLE_ITALIC 2
+
extern jmethodID setBoundsCallbackID;
extern jmethodID postActionEventID;