OSDN Git Service

9a8cc32efd8a6e7acd7220d6aad3372c6afd958b
[pf3gnuchains/gcc-fork.git] / libjava / jni / gtk-peer / gnu_java_awt_peer_gtk_GtkWindowPeer.c
1 /* gtkwindowpeer.c -- Native implementation of GtkWindowPeer
2    Copyright (C) 1998, 1999, 2002 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_GtkWindowPeer.h"
41 #include "gnu_java_awt_peer_gtk_GtkFramePeer.h"
42 #include <gdk/gdkprivate.h>
43 #include <gdk/gdkx.h>
44
45 static void setBounds (GtkWidget *, jint, jint, jint, jint);
46
47 /*
48  * Make a new window (any type)
49  */
50
51 JNIEXPORT void JNICALL 
52 Java_gnu_java_awt_peer_gtk_GtkWindowPeer_create 
53   (JNIEnv *env, jobject obj, jint type)
54 {
55   gpointer window;
56   GtkWidget *vbox, *layout;
57
58   gdk_threads_enter ();
59   window = gtk_window_new (type);
60
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);
65
66   gtk_widget_show (layout);
67   gtk_widget_show (vbox);
68
69   gdk_threads_leave ();
70
71   NSA_SET_PTR (env, obj, window);
72 }
73
74 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setVisible
75   (JNIEnv *env, jobject obj, jboolean visible)
76 {
77   void *ptr;
78
79   ptr = NSA_GET_PTR (env, obj);
80
81   gdk_threads_enter ();
82
83   if (visible)
84     gtk_widget_show (GTK_WIDGET (ptr));
85   else
86     gtk_widget_hide (GTK_WIDGET (ptr));
87
88   XFlush (GDK_DISPLAY ());
89   gdk_threads_leave ();
90 }
91
92 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectHooks
93   (JNIEnv *env, jobject obj)
94 {
95   void *ptr;
96   GtkVBox* vbox;
97   GtkWidget *layout;
98   GList* children;
99   char* name;
100   ptr = NSA_GET_PTR (env, obj);
101
102   gdk_threads_enter ();
103
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))
108      {
109        printf("*** this is not a vbox\n");
110      }
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))
115      {
116       printf("*** widget is not a layout ***");
117      }
118
119   gtk_widget_realize (layout);
120
121   connect_awt_hook (env, obj, 1, GTK_LAYOUT (layout)->bin_window);
122   
123     gtk_widget_realize (ptr);
124
125   connect_awt_hook (env, obj, 1, GTK_WIDGET (ptr)->window);
126   
127   gdk_threads_leave ();
128 }
129
130 void
131 setup_window (JNIEnv *env, jobject obj, GtkWidget *window, jint width, 
132               jint height, jboolean visible)
133 {
134   GtkWidget *layout, *vbox;
135
136   gdk_threads_enter();
137   gtk_window_set_policy (GTK_WINDOW (window), 1, 1, 0);
138   gtk_widget_set_usize (window, width, height);
139
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);
148
149   gtk_widget_realize (window);
150 /*    setBounds (window, x, y, width, height); */
151
152   connect_awt_hook (env, obj, 1, window->window);
153   set_visible (window, visible);
154   gdk_threads_leave ();
155 }
156
157 /*
158  * Set a frame's title
159  */
160
161 JNIEXPORT void JNICALL 
162 Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setTitle
163   (JNIEnv *env, jobject obj, jstring title)
164 {
165   void *ptr;
166   const char *str;
167
168   ptr = NSA_GET_PTR (env, obj);
169   
170   str = (*env)->GetStringUTFChars (env, title, NULL);
171   
172   gdk_threads_enter ();
173   gtk_window_set_title (GTK_WINDOW (ptr), str);
174   gdk_threads_leave ();
175   
176   (*env)->ReleaseStringUTFChars (env, title, str);
177 }
178
179 /*
180  * Set a window's resizing policy
181  */
182
183 JNIEXPORT void JNICALL
184 Java_gnu_java_awt_peer_gtk_GtkWindowPeer_setResizable
185   (JNIEnv *env, jobject obj, jboolean resize)
186 {
187   void *ptr;
188   
189   ptr = NSA_GET_PTR (env, obj);
190   
191   gdk_threads_enter ();
192   gtk_window_set_policy (GTK_WINDOW (ptr), resize, resize, 0);
193   gdk_threads_leave ();
194 }
195
196
197 /*
198  * Lower the z-level of a window. 
199  */
200
201 JNIEXPORT void JNICALL 
202 Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toBack (JNIEnv *env, 
203     jobject obj)
204 {
205   void *ptr;
206   ptr = NSA_GET_PTR (env, obj);
207     
208   gdk_threads_enter ();
209   gdk_window_lower (GTK_WIDGET (ptr)->window);
210
211   XFlush (GDK_DISPLAY ());
212   gdk_threads_leave ();
213 }
214
215 /*
216  * Raise the z-level of a window.
217  */
218
219 JNIEXPORT void JNICALL 
220 Java_gnu_java_awt_peer_gtk_GtkWindowPeer_toFront (JNIEnv *env, 
221     jobject obj)
222 {
223   void *ptr;
224   ptr = NSA_GET_PTR (env, obj);
225     
226   gdk_threads_enter ();
227   gdk_window_raise (GTK_WIDGET (ptr)->window);
228
229   XFlush (GDK_DISPLAY ());
230   gdk_threads_leave ();
231 }
232
233 static void
234 setBounds (GtkWidget *widget, jint x, jint y, jint width, jint height)
235 {
236 /*    gdk_window_get_root_origin (widget->window, &current_x, &current_y); */
237
238 /*    if (current_x != x || current_y != y) */
239 /*      { */
240 /*        gdk_window_set_hints (widget->window, x, y, 0, 0, 0, 0, GDK_HINT_POS); */
241 /*        gdk_window_move (widget->window, x, y); */
242 /*      } */
243
244   gtk_widget_set_usize (widget, width, height);
245 }
246
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)
249 {
250   void *ptr;
251   GtkWidget *widget;
252
253   ptr = NSA_GET_PTR (env, obj);
254
255   gdk_threads_enter ();
256
257   widget = GTK_WIDGET (ptr);
258   setBounds (widget, x, y, width, height);
259
260   gdk_threads_leave ();
261 }
262
263 JNIEXPORT void JNICALL
264 Java_gnu_java_awt_peer_gtk_GtkFramePeer_setMenuBarPeer
265   (JNIEnv *env, jobject obj, jobject menubar)
266 {
267   void *wptr, *mptr;
268   GtkBox *box;
269
270   if (!menubar) return;
271
272   wptr = NSA_GET_PTR (env, obj);
273   mptr = NSA_GET_PTR (env, menubar);
274
275   if (!mptr) return; /* this case should remove a menu */
276
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 ();
281 }
282
283 JNIEXPORT jint JNICALL
284 Java_gnu_java_awt_peer_gtk_GtkFramePeer_getMenuBarHeight
285   (JNIEnv *env, jobject obj)
286 {
287   void *ptr;
288   GList *children;
289   jint height = 0;
290
291   ptr = NSA_GET_PTR (env, obj);
292
293   gdk_threads_enter ();
294   children = gtk_container_children (GTK_CONTAINER (GTK_BIN (ptr)->child));
295   if (g_list_length (children) == 2)
296     {
297       GtkWidget *menubar = GTK_WIDGET (children->data);
298       height = menubar->allocation.height;
299
300     }
301   gdk_threads_leave ();
302
303   return height;
304 }
305
306
307 void
308 gdk_window_get_root_geometry (GdkWindow *window,
309                               gint      *x,
310                               gint      *y,
311                               gint      *width,
312                               gint      *height,
313                               gint      *border,
314                               gint      *depth)
315 {
316   GdkWindow *private;
317   unsigned int nchildren;
318   
319   g_return_if_fail (window != NULL);
320   
321   private = (GdkWindow*) window;
322   if (x)
323     *x = 0;
324   if (y)
325     *y = 0;
326   if (width)
327     *width = 0;
328   if (height)
329     *height = 0;
330   if (border)
331     *border = 0;
332   if (depth)
333     *depth = 0;
334
335   if (GDK_WINDOW_DESTROYED (private))
336     return;
337   
338   private = gdk_window_get_toplevel (private);
339   if (GDK_WINDOW_DESTROYED(private))
340     return;
341   
342   gdk_window_get_geometry (private, x, y, width, height, depth);
343       
344 }
345