OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [gtk-peer/] [gnu_java_awt_peer_gtk_GtkLabelPeer.c] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* 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., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 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
  gdk_threads_enter ();
51
 
52
  gtkpeer_set_global_ref (env, obj);
53
 
54
  str = (*env)->GetStringUTFChars (env, text, 0);
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
  (*env)->ReleaseStringUTFChars (env, text, str);
63
 
64
  gtkpeer_set_widget (env, obj, eventbox);
65
 
66
  gdk_threads_leave ();
67
}
68
 
69
JNIEXPORT void JNICALL
70
Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetGetPreferredDimensions
71
  (JNIEnv *env, jobject obj, jintArray jdims)
72
{
73
  void *ptr;
74
  jint *dims;
75
  GtkWidget *label;
76
  GtkRequisition current_req;
77
  GtkRequisition natural_req;
78
 
79
  gdk_threads_enter ();
80
 
81
  ptr = gtkpeer_get_widget (env, obj);
82
 
83
  label = gtk_bin_get_child (GTK_BIN (ptr));
84
 
85
  dims = (*env)->GetIntArrayElements (env, jdims, 0);
86
  dims[0] = dims[1] = 0;
87
 
88
  /* Save the widget's current size request. */
89
  gtk_widget_size_request (GTK_WIDGET (label), &current_req);
90
 
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);
94
 
95
  /* Reset the widget's size request. */
96
  gtk_widget_set_size_request (GTK_WIDGET (label),
97
                               current_req.width, current_req.height);
98
 
99
  dims[0] = natural_req.width;
100
  dims[1] = natural_req.height;
101
 
102
  (*env)->ReleaseIntArrayElements (env, jdims, dims, 0);
103
 
104
  gdk_threads_leave ();
105
}
106
 
107
JNIEXPORT void JNICALL
108
Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetModifyFont
109
  (JNIEnv *env, jobject obj, jstring name, jint style, jint size)
110
{
111
  const char *font_name;
112
  void *ptr;
113
  GtkWidget *label;
114
  PangoFontDescription *font_desc;
115
 
116
  gdk_threads_enter ();
117
 
118
  ptr = gtkpeer_get_widget (env, obj);
119
 
120
  font_name = (*env)->GetStringUTFChars (env, name, NULL);
121
 
122
  label = gtk_bin_get_child (GTK_BIN (ptr));
123
 
124
  if (!label)
125
    {
126
      gdk_threads_leave ();
127
      return;
128
    }
129
 
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);
133
 
134
  if (style & AWT_STYLE_BOLD)
135
    pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
136
 
137
  if (style & AWT_STYLE_ITALIC)
138
    pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE);
139
 
140
  gtk_widget_modify_font (GTK_WIDGET (label), font_desc);
141
 
142
  pango_font_description_free (font_desc);
143
 
144
  (*env)->ReleaseStringUTFChars (env, name, font_name);
145
 
146
  gdk_threads_leave ();
147
}
148
 
149
JNIEXPORT void JNICALL
150
Java_gnu_java_awt_peer_gtk_GtkLabelPeer_setNativeText
151
  (JNIEnv *env, jobject obj, jstring text)
152
{
153
  const char *str;
154
  void *ptr;
155
  GtkWidget *label;
156
 
157
  gdk_threads_enter ();
158
 
159
  ptr = gtkpeer_get_widget (env, obj);
160
 
161
  str = (*env)->GetStringUTFChars (env, text, 0);
162
 
163
  label = gtk_bin_get_child (GTK_BIN (ptr));
164
 
165
  gtk_label_set_label (GTK_LABEL (label), str);
166
 
167
  (*env)->ReleaseStringUTFChars (env, text, str);
168
 
169
  gdk_threads_leave ();
170
}
171
 
172
JNIEXPORT void JNICALL
173
Java_gnu_java_awt_peer_gtk_GtkLabelPeer_nativeSetAlignment
174
  (JNIEnv *env, jobject obj, jfloat xalign)
175
{
176
  void *ptr;
177
  GtkWidget *label;
178
 
179
  gdk_threads_enter ();
180
 
181
  ptr = gtkpeer_get_widget (env, obj);
182
 
183
  label = gtk_bin_get_child (GTK_BIN(ptr));
184
 
185
  gtk_misc_set_alignment (GTK_MISC (label), xalign, 0.5);
186
 
187
  gdk_threads_leave ();
188
}
189
 
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)
193
{
194
  GtkWidget *widget;
195
  void *ptr;
196
 
197
  gdk_threads_enter ();
198
 
199
  ptr = gtkpeer_get_widget (env, obj);
200
 
201
  widget = GTK_WIDGET (ptr);
202
 
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;
207
 
208
  if (!(width == 0 && height == 0))
209
    {
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);
215
 
216
      if (widget->parent != NULL && GTK_IS_FIXED (widget->parent))
217
        gtk_fixed_move (GTK_FIXED (widget->parent), widget, x, y);
218
    }
219
 
220
  gdk_threads_leave ();
221
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.