OSDN Git Service

2004-11-30 Thomas Fitzsimmons <fitzsim@redhat.com>
[pf3gnuchains/gcc-fork.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkLabelPeer.c
1 /* gtklabelpeer.c -- Native implementation of GtkLabelPeer
2    Copyright (C) 1998, 1999 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
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.
10
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.
15
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
19 02111-1307 USA.
20
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.
25
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. */
37
38
39 #include "gtkpeer.h"
40 #include "gnu_java_awt_peer_gtk_GtkLabelPeer.h"
41
42 JNIEXPORT void JNICALL
43 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_create
44   (JNIEnv *env, jobject obj, jstring text, jfloat xalign)
45 {
46   GtkWidget *label;
47   GtkWidget *eventbox;
48   const char *str;
49
50   NSA_SET_GLOBAL_REF (env, obj);
51
52   str = (*env)->GetStringUTFChars (env, text, 0);
53
54   gdk_threads_enter ();
55
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);
61
62   gdk_threads_leave ();
63
64   (*env)->ReleaseStringUTFChars (env, text, str);
65
66   NSA_SET_PTR (env, obj, eventbox);
67 }
68
69 JNIEXPORT void JNICALL
70 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetModifyFont
71   (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
72 {
73   const char *font_name;
74   void *ptr;
75   GtkWidget *label;
76   PangoFontDescription *font_desc;
77
78   ptr = NSA_GET_PTR (env, obj);
79
80   font_name = (*env)->GetStringUTFChars (env, name, NULL);
81
82   gdk_threads_enter ();
83
84   label = gtk_bin_get_child (GTK_BIN (ptr));
85
86   if (!label)
87     return;
88
89   font_desc = pango_font_description_from_string (font_name);
90   pango_font_description_set_size (font_desc, size * dpi_conversion_factor);
91
92   if (style & AWT_STYLE_BOLD)
93     pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
94
95   if (style & AWT_STYLE_ITALIC)
96     pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
97
98   gtk_widget_modify_font (GTK_WIDGET (label), font_desc);
99
100   pango_font_description_free (font_desc);
101
102   gdk_threads_leave ();
103
104   (*env)->ReleaseStringUTFChars (env, name, font_name);
105 }
106
107 JNIEXPORT void JNICALL
108 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setText
109   (JNIEnv *env, jobject obj, jstring text)
110 {
111   const char *str;
112   void *ptr;
113   GtkWidget *label;
114
115   ptr = NSA_GET_PTR (env, obj);
116
117   str = (*env)->GetStringUTFChars (env, text, 0);
118
119   gdk_threads_enter ();
120
121   label = gtk_bin_get_child (GTK_BIN (ptr));
122
123   gtk_label_set_label (GTK_LABEL (label), str);
124
125   gdk_threads_leave ();
126
127   (*env)->ReleaseStringUTFChars (env, text, str);
128 }
129
130 JNIEXPORT void JNICALL
131 Java_gnu_java_awt_peer_gtk_GtkLabelPeer_nativeSetAlignment
132   (JNIEnv *env, jobject obj, jfloat xalign)
133 {
134   void *ptr;
135   GtkWidget *label;
136
137   ptr = NSA_GET_PTR (env, obj);
138
139   gdk_threads_enter ();
140
141   label = gtk_bin_get_child (GTK_BIN(ptr));
142
143   gtk_misc_set_alignment (GTK_MISC (label), xalign, 0.5);
144
145   gdk_threads_leave ();
146 }
147
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)
151 {
152   GtkWidget *widget;
153   void *ptr;
154
155   ptr = NSA_GET_PTR (env, obj);
156
157   gdk_threads_enter ();
158
159   widget = GTK_WIDGET (ptr);
160
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;
165
166   if (!(width == 0 && height == 0))
167     {
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)),
172                                    width, height);
173
174       if (widget->parent != NULL)
175         gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y);
176     }
177
178   gdk_threads_leave ();
179 }