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.

From-SVN: r72246
This commit is contained in:
Thomas Fitzsimmons 2003-10-08 23:38:45 +00:00 committed by Thomas Fitzsimmons
parent 769e49eb03
commit a5586c3865
12 changed files with 160 additions and 26 deletions

View File

@ -1,3 +1,25 @@
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.

View File

@ -51,7 +51,8 @@ public class GtkButtonPeer extends GtkComponentPeer
{
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 class GtkButtonPeer extends GtkComponentPeer
public void setFont (Font f)
{
gtkSetFont(f.getName(), f.getSize());
gtkSetFont(f.getName(), f.getStyle(), f.getSize());
}
}

View File

@ -86,6 +86,8 @@ public class GtkComponentPeer extends GtkGenericPeer
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 @@ public class GtkComponentPeer extends GtkGenericPeer
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 class GtkComponentPeer extends GtkGenericPeer
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 class GtkComponentPeer extends GtkGenericPeer
public void setForeground (Color c)
{
// System.out.println ("setForeground [UNIMPLEMENTED");
gtkWidgetSetForeground (c.getRed(), c.getGreen(), c.getBlue());
}
public Color getForeground ()

View File

@ -48,7 +48,7 @@ public class GtkTextAreaPeer extends GtkTextComponentPeer
{
native void create (int scrollbarVisibility);
native void gtkSetFont(String xlfd, int size);
native void gtkSetFont(String name, int style, int size);
void create ()
{
@ -106,6 +106,6 @@ public class GtkTextAreaPeer extends GtkTextComponentPeer
public void setFont (Font f)
{
gtkSetFont(f.getName(), f.getSize());
gtkSetFont(f.getName(), f.getStyle(), f.getSize());
}
}

View File

@ -55,7 +55,7 @@ public class GtkTextFieldPeer extends GtkTextComponentPeer
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)
{
@ -104,7 +104,7 @@ public class GtkTextFieldPeer extends GtkTextComponentPeer
public void setFont (Font f)
{
gtkSetFont(f.getName(), f.getSize());
gtkSetFont(f.getName(), f.getStyle(), f.getSize());
}
public void handleEvent (AWTEvent e)

View File

@ -205,9 +205,9 @@ public class FlowLayout implements LayoutManager, Serializable
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)
{

View File

@ -193,9 +193,11 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawString
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 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawString
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 ();

View File

@ -53,7 +53,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkButtonPeer_create
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 @@ Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkSetFont
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 ();
}

View File

@ -276,6 +276,61 @@ Java_gnu_java_awt_peer_gtk_GtkComponentPeer_gtkWidgetGetForeground
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)
{

View File

@ -158,7 +158,7 @@ Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_replaceRange
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;
@ -169,18 +169,24 @@ Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkSetFont
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);
}

View File

@ -102,7 +102,7 @@ Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_setEchoChar
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 @@ Java_gnu_java_awt_peer_gtk_GtkTextFieldPeer_gtkSetFont
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);
}

View File

@ -347,6 +347,10 @@ struct graphics
#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;