1 /* gtklabelpeer.c -- Native implementation of GtkLabelPeer
2 Copyright (C) 1998, 1999 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
40 #include "gnu_java_awt_peer_gtk_GtkLabelPeer.h"
42 JNIEXPORT
void JNICALL
43 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_create
44 (JNIEnv
*env
, jobject obj
, jstring text
, jfloat xalign
)
50 NSA_SET_GLOBAL_REF (env
, obj
);
52 str
= (*env
)->GetStringUTFChars (env
, text
, 0);
56 eventbox
= gtk_event_box_new ();
57 label
= gtk_label_new (str
);
58 gtk_misc_set_alignment (GTK_MISC (label
), xalign
, 0.5);
59 gtk_container_add (GTK_CONTAINER (eventbox
), label
);
60 gtk_widget_show (label
);
64 (*env
)->ReleaseStringUTFChars (env
, text
, str
);
66 NSA_SET_PTR (env
, obj
, eventbox
);
69 JNIEXPORT
void JNICALL
70 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetModifyFont
71 (JNIEnv
*env
, jobject obj
, jstring name
, jint style
, jint size
)
73 const char *font_name
;
76 PangoFontDescription
*font_desc
;
78 ptr
= NSA_GET_PTR (env
, obj
);
80 font_name
= (*env
)->GetStringUTFChars (env
, name
, NULL
);
84 label
= gtk_bin_get_child (GTK_BIN (ptr
));
89 font_desc
= pango_font_description_from_string (font_name
);
90 pango_font_description_set_size (font_desc
, size
* dpi_conversion_factor
);
92 if (style
& AWT_STYLE_BOLD
)
93 pango_font_description_set_weight (font_desc
, PANGO_WEIGHT_BOLD
);
95 if (style
& AWT_STYLE_ITALIC
)
96 pango_font_description_set_style (font_desc
, PANGO_STYLE_OBLIQUE
);
98 gtk_widget_modify_font (GTK_WIDGET (label
), font_desc
);
100 pango_font_description_free (font_desc
);
102 gdk_threads_leave ();
104 (*env
)->ReleaseStringUTFChars (env
, name
, font_name
);
107 JNIEXPORT
void JNICALL
108 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setText
109 (JNIEnv
*env
, jobject obj
, jstring text
)
115 ptr
= NSA_GET_PTR (env
, obj
);
117 str
= (*env
)->GetStringUTFChars (env
, text
, 0);
119 gdk_threads_enter ();
121 label
= gtk_bin_get_child (GTK_BIN (ptr
));
123 gtk_label_set_label (GTK_LABEL (label
), str
);
125 gdk_threads_leave ();
127 (*env
)->ReleaseStringUTFChars (env
, text
, str
);
130 JNIEXPORT
void JNICALL
131 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_nativeSetAlignment
132 (JNIEnv
*env
, jobject obj
, jfloat xalign
)
137 ptr
= NSA_GET_PTR (env
, obj
);
139 gdk_threads_enter ();
141 label
= gtk_bin_get_child (GTK_BIN(ptr
));
143 gtk_misc_set_alignment (GTK_MISC (label
), xalign
, 0.5);
145 gdk_threads_leave ();
148 JNIEXPORT
void JNICALL
149 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeBounds
150 (JNIEnv
*env
, jobject obj
, jint x
, jint y
, jint width
, jint height
)
155 ptr
= NSA_GET_PTR (env
, obj
);
157 gdk_threads_enter ();
159 widget
= GTK_WIDGET (ptr
);
161 /* We assume that -1 is a width or height and not a request for the
162 widget's natural size. */
163 width
= width
< 0 ? 0 : width
;
164 height
= height
< 0 ? 0 : height
;
166 if (!(width
== 0 && height
== 0))
168 /* Set the event box's size request... */
169 gtk_widget_set_size_request (widget
, width
, height
);
170 /* ...and the label's size request. */
171 gtk_widget_set_size_request (gtk_bin_get_child (GTK_BIN (widget
)),
174 if (widget
->parent
!= NULL
)
175 gtk_fixed_move (GTK_FIXED (widget
->parent
), widget
, x
, y
);
178 gdk_threads_leave ();