Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / native / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkLabelPeer.c
blob74180a78447aaddf656a86aefe58ec50d8e26998
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)
9 any later version.
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
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
24 combination.
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. */
39 #include "gtkpeer.h"
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)
46 GtkWidget *label;
47 GtkWidget *eventbox;
48 const char *str;
50 gdk_threads_enter ();
52 NSA_SET_GLOBAL_REF (env, obj);
54 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);
62 (*env)->ReleaseStringUTFChars (env, text, str);
64 NSA_SET_PTR (env, obj, eventbox);
66 gdk_threads_leave ();
69 JNIEXPORT void JNICALL
70 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetGetPreferredDimensions
71 (JNIEnv *env, jobject obj, jintArray jdims)
73 void *ptr;
74 jint *dims;
75 GtkWidget *label;
76 GtkRequisition current_req;
77 GtkRequisition natural_req;
79 gdk_threads_enter ();
81 ptr = NSA_GET_PTR (env, obj);
83 label = gtk_bin_get_child (GTK_BIN (ptr));
85 dims = (*env)->GetIntArrayElements (env, jdims, 0);
86 dims[0] = dims[1] = 0;
88 /* Save the widget's current size request. */
89 gtk_widget_size_request (GTK_WIDGET (label), &current_req);
91 /* Get the widget's "natural" size request. */
92 gtk_widget_set_size_request (GTK_WIDGET (label), -1, -1);
93 gtk_widget_size_request (GTK_WIDGET (label), &natural_req);
95 /* Reset the widget's size request. */
96 gtk_widget_set_size_request (GTK_WIDGET (label),
97 current_req.width, current_req.height);
99 dims[0] = natural_req.width;
100 dims[1] = natural_req.height;
102 (*env)->ReleaseIntArrayElements (env, jdims, dims, 0);
104 gdk_threads_leave ();
107 JNIEXPORT void JNICALL
108 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetModifyFont
109 (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
111 const char *font_name;
112 void *ptr;
113 GtkWidget *label;
114 PangoFontDescription *font_desc;
116 gdk_threads_enter ();
118 ptr = NSA_GET_PTR (env, obj);
120 font_name = (*env)->GetStringUTFChars (env, name, NULL);
122 label = gtk_bin_get_child (GTK_BIN (ptr));
124 if (!label)
126 gdk_threads_leave ();
127 return;
130 font_desc = pango_font_description_from_string (font_name);
131 pango_font_description_set_size (font_desc,
132 size * cp_gtk_dpi_conversion_factor);
134 if (style & AWT_STYLE_BOLD)
135 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
137 if (style & AWT_STYLE_ITALIC)
138 pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
140 gtk_widget_modify_font (GTK_WIDGET (label), font_desc);
142 pango_font_description_free (font_desc);
144 (*env)->ReleaseStringUTFChars (env, name, font_name);
146 gdk_threads_leave ();
149 JNIEXPORT void JNICALL
150 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setText
151 (JNIEnv *env, jobject obj, jstring text)
153 const char *str;
154 void *ptr;
155 GtkWidget *label;
157 gdk_threads_enter ();
159 ptr = NSA_GET_PTR (env, obj);
161 str = (*env)->GetStringUTFChars (env, text, 0);
163 label = gtk_bin_get_child (GTK_BIN (ptr));
165 gtk_label_set_label (GTK_LABEL (label), str);
167 (*env)->ReleaseStringUTFChars (env, text, str);
169 gdk_threads_leave ();
172 JNIEXPORT void JNICALL
173 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_nativeSetAlignment
174 (JNIEnv *env, jobject obj, jfloat xalign)
176 void *ptr;
177 GtkWidget *label;
179 gdk_threads_enter ();
181 ptr = NSA_GET_PTR (env, obj);
183 label = gtk_bin_get_child (GTK_BIN(ptr));
185 gtk_misc_set_alignment (GTK_MISC (label), xalign, 0.5);
187 gdk_threads_leave ();
190 JNIEXPORT void JNICALL
191 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeBounds
192 (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height)
194 GtkWidget *widget;
195 void *ptr;
197 gdk_threads_enter ();
199 ptr = NSA_GET_PTR (env, obj);
201 widget = GTK_WIDGET (ptr);
203 /* We assume that -1 is a width or height and not a request for the
204 widget's natural size. */
205 width = width < 0 ? 0 : width;
206 height = height < 0 ? 0 : height;
208 if (!(width == 0 && height == 0))
210 /* Set the event box's size request... */
211 gtk_widget_set_size_request (widget, width, height);
212 /* ...and the label's size request. */
213 gtk_widget_set_size_request (gtk_bin_get_child (GTK_BIN (widget)),
214 width, height);
216 if (widget->parent != NULL)
217 gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y);
220 gdk_threads_leave ();