1 /* gtkpopupmenupeer.c -- Native implementation of GtkPopupMenuPeer
2    Copyright (C) 1999, 2004 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_GtkPopupMenuPeer.h"
41 
42 struct pos
43 {
44   gint x;
45   gint y;
46 };
47 
48 static void
menu_pos(GtkMenu * menu,gint * x,gint * y,gboolean * push_in,gpointer user_data)49 menu_pos (GtkMenu *menu __attribute__((unused)),
50 	  gint *x, gint *y,
51 	  gboolean *push_in,
52 	  gpointer user_data)
53 {
54   struct pos *p = (struct pos *) user_data;
55 
56   *x = p->x;
57   *y = p->y;
58   *push_in = TRUE;
59 }
60 
61 JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_show(JNIEnv * env,jobject obj,jint x,jint y,jlong time)62 Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_show
63   (JNIEnv *env, jobject obj, jint x, jint y, jlong time)
64 {
65   void *ptr;
66   struct pos *p;
67 
68   gdk_threads_enter ();
69 
70   ptr = gtkpeer_get_widget (env, obj);
71 
72   p = g_malloc (sizeof (struct pos));
73   p->x = x;
74   p->y = y;
75 
76   gtk_menu_popup (GTK_MENU (GTK_MENU_ITEM (ptr)->submenu),
77 		  NULL, NULL, menu_pos, p, 0, time);
78 
79   g_free (p);
80 
81   gdk_threads_leave ();
82 }
83 
84 JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_setupAccelGroup(JNIEnv * env,jobject obj,jobject parent)85 Java_gnu_java_awt_peer_gtk_GtkPopupMenuPeer_setupAccelGroup
86   (JNIEnv *env, jobject obj, jobject parent __attribute__((unused)))
87 {
88   void *ptr1;
89   GtkMenu *menu;
90 #if 0
91   void *ptr2;
92 #endif
93 
94   gdk_threads_enter ();
95 
96   ptr1 = gtkpeer_get_widget (env, obj);
97 
98   menu = GTK_MENU (GTK_MENU_ITEM (ptr1)->submenu);
99   gtk_menu_set_accel_group (menu, gtk_accel_group_new ());
100   /* FIXME: update this to use GTK-2.4 GtkActions. */
101   // FIXME: _gtk_accel_group_attach is a GTK-private function, so
102   // we'll need a different approach here
103 #if 0
104   ptr2 = gtkpeer_get_widget (env, parent);
105   _gtk_accel_group_attach (gtk_menu_get_accel_group (menu),
106 			   G_OBJECT (gtk_widget_get_toplevel (ptr2)));
107 #endif
108 
109   gdk_threads_leave ();
110 }
111