+2003-10-08 Thomas Fitzsimmons <fitzsim@redhat.com>
+
+ * gnu/java/awt/peer/gtk/GtkButtonPeer.java,
+ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c
+ (gtkSetFont): Handle BOLD and ITALIC style specifiers.
+ (gtkWidgetSetForeground): New method.
+ * gnu/java/awt/peer/gtk/GtkComponentPeer.java,
+ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c
+ (gtkWidgetSetBackground, gtkWidgetSetForeground): New methods.
+ (setBackground, setForeground): Implement.
+ * gnu/java/awt/peer/gtk/GtkTextAreaPeer.java,
+ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextAreaPeer.c
+ (gtkSetFont): Handle BOLD and ITALIC style specifiers.
+ * gnu/java/awt/peer/gtk/GtkTextFieldPeer.java,
+ jni/gtk-peer/gnu_java_awt_peer_gtk_GtkTextFieldPeer.c: Likewise.
+ * 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.
+
+ * java/awt/FlowLayout.java (layoutContainer): Fix offset problem
+ for CENTER and RIGHT alignments.
+
2003-10-08 Michael Koch <konqueror@gmx.de>
* java/security/Security.java: Reformated.
{
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)
{
public void setFont (Font f)
{
- gtkSetFont(f.getName(), f.getSize());
+ gtkSetFont(f.getName(), f.getStyle(), f.getSize());
}
}
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 ()
{
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());
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);
public void setForeground (Color c)
{
- // System.out.println ("setForeground [UNIMPLEMENTED");
+ gtkWidgetSetForeground (c.getRed(), c.getGreen(), c.getBlue());
}
public Color getForeground ()
{
native void create (int scrollbarVisibility);
- native void gtkSetFont(String xlfd, int size);
+ native void gtkSetFont(String name, int style, int size);
void create ()
{
public void setFont (Font f)
{
- gtkSetFont(f.getName(), f.getSize());
+ gtkSetFont(f.getName(), f.getStyle(), f.getSize());
}
}
native void gtkEntryGetSize (int dims[]);
- native void gtkSetFont(String xlfd, int size);
+ native void gtkSetFont(String name, int style, int size);
public GtkTextFieldPeer (TextField tf)
{
public void setFont (Font f)
{
- gtkSetFont(f.getName(), f.getSize());
+ gtkSetFont(f.getName(), f.getStyle(), f.getSize());
}
public void handleEvent (AWTEvent e)
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)
{
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);
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 ();
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;
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 ();
}
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)
{
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;
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);
}
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;
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);
}
#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;