Merge from the pain train
[official-gcc.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkFramePeer.c
blob52da40cae5d31b40e7065c336d5df3fa7c441a41
1 /* gtkframepeer.c -- Native implementation of GtkFramePeer
2 Copyright (C) 1998, 1999, 2002 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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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. */
38 #include "gtkpeer.h"
39 #include "gnu_java_awt_peer_gtk_GtkFramePeer.h"
41 JNIEXPORT void JNICALL
42 Java_gnu_java_awt_peer_gtk_GtkFramePeer_removeMenuBarPeer
43 (JNIEnv *env, jobject obj)
45 void *ptr;
46 void *mptr;
47 void *fixed;
48 GList* children;
50 ptr = NSA_GET_PTR (env, obj);
52 gdk_threads_enter ();
54 fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data;
55 children = gtk_container_get_children (GTK_CONTAINER (fixed));
57 while (children != NULL && !GTK_IS_MENU_SHELL (children->data))
59 children = children->next;
62 /* If there's a menu bar, remove it. */
63 if (children != NULL)
65 mptr = children->data;
67 /* This will actually destroy the MenuBar. By removing it from
68 its parent, the reference count for the MenuBar widget will
69 decrement to 0. The widget will be automatically destroyed by
70 GTK. */
71 gtk_container_remove (GTK_CONTAINER (fixed), GTK_WIDGET (mptr));
74 gdk_threads_leave ();
77 JNIEXPORT void JNICALL
78 Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarPeer
79 (JNIEnv *env, jobject obj, jobject menubar)
81 void *ptr;
82 void *mptr;
83 void *fixed;
85 ptr = NSA_GET_PTR (env, obj);
86 mptr = NSA_GET_PTR (env, menubar);
88 gdk_threads_enter ();
90 fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data;
91 gtk_fixed_put (GTK_FIXED (fixed), mptr, 0, 0);
92 gtk_widget_show (mptr);
94 gdk_threads_leave ();
97 JNIEXPORT jint JNICALL
98 Java_gnu_java_awt_peer_gtk_GtkFramePeer_getMenuBarHeight
99 (JNIEnv *env, jobject obj __attribute__((unused)), jobject menubar)
101 GtkWidget *ptr;
102 GtkRequisition requisition;
104 ptr = NSA_GET_PTR (env, menubar);
106 gdk_threads_enter ();
108 gtk_widget_size_request (ptr, &requisition);
110 gdk_threads_leave ();
112 return requisition.height;
115 JNIEXPORT void JNICALL
116 Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarWidth
117 (JNIEnv *env, jobject obj __attribute__((unused)), jobject menubar, jint width)
119 GtkWidget *ptr;
120 GtkRequisition natural_req;
122 ptr = NSA_GET_PTR (env, menubar);
124 gdk_threads_enter ();
126 /* Get the menubar's natural size request. */
127 gtk_widget_set_size_request (GTK_WIDGET (ptr), -1, -1);
128 gtk_widget_size_request (GTK_WIDGET (ptr), &natural_req);
130 /* Set the menubar's size request to width by natural_req.height. */
131 gtk_widget_set_size_request (GTK_WIDGET (ptr),
132 width, natural_req.height);
134 gdk_threads_leave ();
137 JNIEXPORT void JNICALL
138 Java_gnu_java_awt_peer_gtk_GtkFramePeer_gtkFixedSetVisible
139 (JNIEnv *env, jobject obj, jboolean visible)
141 void *ptr;
142 void *fixed;
144 ptr = NSA_GET_PTR (env, obj);
146 gdk_threads_enter ();
148 fixed = gtk_container_get_children (GTK_CONTAINER (ptr))->data;
150 if (visible)
151 gtk_widget_show (GTK_WIDGET (fixed));
152 else
153 gtk_widget_hide (GTK_WIDGET (fixed));
155 gdk_threads_leave ();
158 JNIEXPORT void JNICALL
159 Java_gnu_java_awt_peer_gtk_GtkFramePeer_nativeSetIconImageFromDecoder
160 (JNIEnv *env, jobject obj, jobject decoder)
162 void *ptr;
163 GdkPixbufLoader *loader = NULL;
164 GdkPixbuf *pixbuf = NULL;
166 ptr = NSA_GET_PTR (env, obj);
168 loader = NSA_GET_PB_PTR (env, decoder);
169 g_assert (loader != NULL);
171 gdk_threads_enter ();
173 pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
174 g_assert (pixbuf != NULL);
176 gtk_window_set_icon (GTK_WINDOW (ptr), pixbuf);
178 gdk_threads_leave ();
181 static void
182 free_pixbuf_data (guchar *pixels, gpointer data __attribute__((unused)))
184 free(pixels);
187 JNIEXPORT void JNICALL
188 Java_gnu_java_awt_peer_gtk_GtkFramePeer_nativeSetIconImageFromData
189 (JNIEnv *env, jobject obj, jintArray pixelArray, jint width, jint height)
191 void *ptr;
192 GdkPixbuf *pixbuf;
193 jint *pixels;
194 int pixels_length, i;
195 guchar *data;
197 ptr = NSA_GET_PTR (env, obj);
199 pixels = (*env)->GetIntArrayElements (env, pixelArray, 0);
200 pixels_length = (*env)->GetArrayLength (env, pixelArray);
202 data = malloc (sizeof (guchar) * pixels_length);
203 for (i = 0; i < pixels_length; i++)
204 data[i] = (guchar) pixels[i];
206 gdk_threads_enter ();
208 pixbuf = gdk_pixbuf_new_from_data (data,
209 GDK_COLORSPACE_RGB,
210 TRUE,
212 width,
213 height,
214 width*4,
215 free_pixbuf_data,
216 NULL);
218 gtk_window_set_icon (GTK_WINDOW (ptr), pixbuf);
220 gdk_threads_leave ();
222 (*env)->ReleaseIntArrayElements(env, pixelArray, pixels, 0);