1 /* gtkwindowpeer.c -- Native implementation of GtkWindowPeer
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)
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_GtkWindowPeer.h"
41 #include "gnu_java_awt_peer_gtk_GtkFramePeer.h"
42 #include <gdk/gdkprivate.h>
45 static void setBounds (GtkWidget *, jint, jint, jint, jint);
48 * Make a new window (any type)
51 JNIEXPORT void JNICALL
52 Java_gnu_java_awt_peer_gtk_GtkWindowPeer_create
53 (JNIEnv *env, jobject obj, jint type)
56 GtkWidget *vbox, *layout;
59 window = gtk_window_new (type);
61 vbox = gtk_vbox_new (0, 0);
62 layout = gtk_layout_new (NULL, NULL);
63 gtk_box_pack_end (GTK_BOX (vbox), layout, 1, 1, 0);
64 gtk_container_add (GTK_CONTAINER (window), vbox);
66 gtk_widget_show (layout);
67 gtk_widget_show (vbox);
71 NSA_SET_PTR (env, obj, window);
74 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisible
75 (JNIEnv *env, jobject obj, jboolean visible)
79 ptr = NSA_GET_PTR (env, obj);
84 gtk_widget_show (GTK_WIDGET (ptr));
86 gtk_widget_hide (GTK_WIDGET (ptr));
88 XFlush (GDK_DISPLAY ());
92 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectHooks
93 (JNIEnv *env, jobject obj)
100 ptr = NSA_GET_PTR (env, obj);
102 gdk_threads_enter ();
104 children = gtk_container_get_children(GTK_CONTAINER(ptr));
105 vbox = children->data;
106 name = GTK_OBJECT_TYPE_NAME(vbox);
107 if(!GTK_IS_VBOX(vbox))
109 printf("*** this is not a vbox\n");
111 children = gtk_container_get_children(GTK_CONTAINER(vbox));
112 layout = children->data;
113 name = GTK_OBJECT_TYPE_NAME(layout);
114 if(!GTK_IS_LAYOUT(layout))
116 printf("*** widget is not a layout ***");
119 gtk_widget_realize (layout);
121 connect_awt_hook (env, obj, 1, GTK_LAYOUT (layout)->bin_window);
123 gtk_widget_realize (ptr);
125 connect_awt_hook (env, obj, 1, GTK_WIDGET (ptr)->window);
127 gdk_threads_leave ();
131 setup_window (JNIEnv *env, jobject obj, GtkWidget *window, jint width,
132 jint height, jboolean visible)
134 GtkWidget *layout, *vbox;
137 gtk_window_set_policy (GTK_WINDOW (window), 1, 1, 0);
138 gtk_widget_set_usize (window, width, height);
140 vbox = gtk_vbox_new (0, 0);
141 layout = gtk_layout_new (NULL, NULL);
142 gtk_box_pack_end (GTK_BOX (vbox), layout, 1, 1, 0);
143 gtk_container_add (GTK_CONTAINER (window), vbox);
144 gtk_widget_realize (layout);
145 connect_awt_hook (env, obj, 1, GTK_LAYOUT(layout)->bin_window);
146 gtk_widget_show (layout);
147 gtk_widget_show (vbox);
149 gtk_widget_realize (window);
150 /* setBounds (window, x, y, width, height); */
152 connect_awt_hook (env, obj, 1, window->window);
153 set_visible (window, visible);
154 gdk_threads_leave ();
158 * Set a frame's title
161 JNIEXPORT void JNICALL
162 Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setTitle
163 (JNIEnv *env, jobject obj, jstring title)
168 ptr = NSA_GET_PTR (env, obj);
170 str = (*env)->GetStringUTFChars (env, title, NULL);
172 gdk_threads_enter ();
173 gtk_window_set_title (GTK_WINDOW (ptr), str);
174 gdk_threads_leave ();
176 (*env)->ReleaseStringUTFChars (env, title, str);
180 * Set a window's resizing policy
183 JNIEXPORT void JNICALL
184 Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setResizable
185 (JNIEnv *env, jobject obj, jboolean resize)
189 ptr = NSA_GET_PTR (env, obj);
191 gdk_threads_enter ();
192 gtk_window_set_policy (GTK_WINDOW (ptr), resize, resize, 0);
193 gdk_threads_leave ();
198 * Lower the z-level of a window.
201 JNIEXPORT void JNICALL
202 Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toBack (JNIEnv *env,
206 ptr = NSA_GET_PTR (env, obj);
208 gdk_threads_enter ();
209 gdk_window_lower (GTK_WIDGET (ptr)->window);
211 XFlush (GDK_DISPLAY ());
212 gdk_threads_leave ();
216 * Raise the z-level of a window.
219 JNIEXPORT void JNICALL
220 Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toFront (JNIEnv *env,
224 ptr = NSA_GET_PTR (env, obj);
226 gdk_threads_enter ();
227 gdk_window_raise (GTK_WIDGET (ptr)->window);
229 XFlush (GDK_DISPLAY ());
230 gdk_threads_leave ();
234 setBounds (GtkWidget *widget, jint x, jint y, jint width, jint height)
236 /* gdk_window_get_root_origin (widget->window, ¤t_x, ¤t_y); */
238 /* if (current_x != x || current_y != y) */
240 /* gdk_window_set_hints (widget->window, x, y, 0, 0, 0, 0, GDK_HINT_POS); */
241 /* gdk_window_move (widget->window, x, y); */
244 gtk_widget_set_usize (widget, width, height);
247 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setBounds
248 (JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height)
253 ptr = NSA_GET_PTR (env, obj);
255 gdk_threads_enter ();
257 widget = GTK_WIDGET (ptr);
258 setBounds (widget, x, y, width, height);
260 gdk_threads_leave ();
263 JNIEXPORT void JNICALL
264 Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarPeer
265 (JNIEnv *env, jobject obj, jobject menubar)
270 if (!menubar) return;
272 wptr = NSA_GET_PTR (env, obj);
273 mptr = NSA_GET_PTR (env, menubar);
275 if (!mptr) return; /* this case should remove a menu */
277 gdk_threads_enter ();
278 box = GTK_BOX (GTK_BIN (wptr)->child);
279 gtk_box_pack_start (box, GTK_WIDGET (mptr), 0, 0, 0);
280 gdk_threads_leave ();
283 JNIEXPORT jint JNICALL
284 Java_gnu_java_awt_peer_gtk_GtkFramePeer_getMenuBarHeight
285 (JNIEnv *env, jobject obj)
291 ptr = NSA_GET_PTR (env, obj);
293 gdk_threads_enter ();
294 children = gtk_container_children (GTK_CONTAINER (GTK_BIN (ptr)->child));
295 if (g_list_length (children) == 2)
297 GtkWidget *menubar = GTK_WIDGET (children->data);
298 height = menubar->allocation.height;
301 gdk_threads_leave ();
308 gdk_window_get_root_geometry (GdkWindow *window,
317 unsigned int nchildren;
319 g_return_if_fail (window != NULL);
321 private = (GdkWindow*) window;
335 if (GDK_WINDOW_DESTROYED (private))
338 private = gdk_window_get_toplevel (private);
339 if (GDK_WINDOW_DESTROYED(private))
342 gdk_window_get_geometry (private, x, y, width, height, depth);