1 |
774 |
jeremybenn |
/* gtkdragsourcecontextpeer.c -- Native implementation of GtkDragSourceContextPeer
|
2 |
|
|
Copyright (C) 2006 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 |
|
|
#include "gtkpeer.h"
|
39 |
|
|
#include "gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer.h"
|
40 |
|
|
|
41 |
|
|
#include <jni.h>
|
42 |
|
|
#include <gtk/gtk.h>
|
43 |
|
|
|
44 |
|
|
static GtkWidget * get_widget (GtkWidget *widget);
|
45 |
|
|
static void connect_signals_for_widget (GtkWidget *widget);
|
46 |
|
|
|
47 |
|
|
#define ACTION_COPY 1
|
48 |
|
|
#define ACTION_MOVE 2
|
49 |
|
|
#define ACTION_COPY_OR_MOVE 3
|
50 |
|
|
#define ACTION_LINK 1073741824
|
51 |
|
|
|
52 |
|
|
#define AWT_DEFAULT_CURSOR 0
|
53 |
|
|
#define AWT_CROSSHAIR_CURSOR 1
|
54 |
|
|
#define AWT_TEXT_CURSOR 2
|
55 |
|
|
#define AWT_WAIT_CURSOR 3
|
56 |
|
|
#define AWT_SW_RESIZE_CURSOR 4
|
57 |
|
|
#define AWT_SE_RESIZE_CURSOR 5
|
58 |
|
|
#define AWT_NW_RESIZE_CURSOR 6
|
59 |
|
|
#define AWT_NE_RESIZE_CURSOR 7
|
60 |
|
|
#define AWT_N_RESIZE_CURSOR 8
|
61 |
|
|
#define AWT_S_RESIZE_CURSOR 9
|
62 |
|
|
#define AWT_W_RESIZE_CURSOR 10
|
63 |
|
|
#define AWT_E_RESIZE_CURSOR 11
|
64 |
|
|
#define AWT_HAND_CURSOR 12
|
65 |
|
|
#define AWT_MOVE_CURSOR 13
|
66 |
|
|
|
67 |
|
|
static jmethodID dragEnterID;
|
68 |
|
|
static jmethodID dragExitID;
|
69 |
|
|
static jmethodID dragDropEndID;
|
70 |
|
|
static jmethodID dragMouseMovedID;
|
71 |
|
|
static jmethodID dragOverID;
|
72 |
|
|
static jmethodID dragActionChangedID;
|
73 |
|
|
static jmethodID acceptDragID;
|
74 |
|
|
static jmethodID rejectDragID;
|
75 |
|
|
static jmethodID acceptDropID;
|
76 |
|
|
static jmethodID rejectDropID;
|
77 |
|
|
static jmethodID dropCompleteID;
|
78 |
|
|
|
79 |
|
|
GtkWidget *widget;
|
80 |
|
|
GtkWidget *tgt;
|
81 |
|
|
jobject gref;
|
82 |
|
|
jobject javaObj;
|
83 |
|
|
|
84 |
|
|
JNIEXPORT void JNICALL
|
85 |
|
|
Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_create
|
86 |
|
|
(JNIEnv *env, jobject obj, jobject comp)
|
87 |
|
|
{
|
88 |
|
|
gdk_threads_enter ();
|
89 |
|
|
|
90 |
|
|
javaObj = obj;
|
91 |
|
|
gtkpeer_set_global_ref (env, obj);
|
92 |
|
|
gtkpeer_set_global_ref (env, comp);
|
93 |
|
|
|
94 |
|
|
gref = gtkpeer_get_widget (env, comp);
|
95 |
|
|
widget = get_widget (GTK_WIDGET (gref));
|
96 |
|
|
|
97 |
|
|
gdk_threads_leave ();
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
JNIEXPORT void JNICALL
|
101 |
|
|
Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_nativeSetCursor
|
102 |
|
|
(JNIEnv *env, jobject obj, jint type)
|
103 |
|
|
{
|
104 |
|
|
void *ptr;
|
105 |
|
|
GdkWindow *win;
|
106 |
|
|
GdkCursorType gdk_cursor_type;
|
107 |
|
|
GdkCursor *gdk_cursor;
|
108 |
|
|
|
109 |
|
|
gdk_threads_enter ();
|
110 |
|
|
|
111 |
|
|
javaObj = obj;
|
112 |
|
|
ptr = gtkpeer_get_global_ref (env, obj);
|
113 |
|
|
|
114 |
|
|
switch (type)
|
115 |
|
|
{
|
116 |
|
|
case AWT_CROSSHAIR_CURSOR:
|
117 |
|
|
gdk_cursor_type = GDK_CROSSHAIR;
|
118 |
|
|
break;
|
119 |
|
|
case AWT_TEXT_CURSOR:
|
120 |
|
|
gdk_cursor_type = GDK_XTERM;
|
121 |
|
|
break;
|
122 |
|
|
case AWT_WAIT_CURSOR:
|
123 |
|
|
gdk_cursor_type = GDK_WATCH;
|
124 |
|
|
break;
|
125 |
|
|
case AWT_SW_RESIZE_CURSOR:
|
126 |
|
|
gdk_cursor_type = GDK_BOTTOM_LEFT_CORNER;
|
127 |
|
|
break;
|
128 |
|
|
case AWT_SE_RESIZE_CURSOR:
|
129 |
|
|
gdk_cursor_type = GDK_BOTTOM_RIGHT_CORNER;
|
130 |
|
|
break;
|
131 |
|
|
case AWT_NW_RESIZE_CURSOR:
|
132 |
|
|
gdk_cursor_type = GDK_TOP_LEFT_CORNER;
|
133 |
|
|
break;
|
134 |
|
|
case AWT_NE_RESIZE_CURSOR:
|
135 |
|
|
gdk_cursor_type = GDK_TOP_RIGHT_CORNER;
|
136 |
|
|
break;
|
137 |
|
|
case AWT_N_RESIZE_CURSOR:
|
138 |
|
|
gdk_cursor_type = GDK_TOP_SIDE;
|
139 |
|
|
break;
|
140 |
|
|
case AWT_S_RESIZE_CURSOR:
|
141 |
|
|
gdk_cursor_type = GDK_BOTTOM_SIDE;
|
142 |
|
|
break;
|
143 |
|
|
case AWT_W_RESIZE_CURSOR:
|
144 |
|
|
gdk_cursor_type = GDK_LEFT_SIDE;
|
145 |
|
|
break;
|
146 |
|
|
case AWT_E_RESIZE_CURSOR:
|
147 |
|
|
gdk_cursor_type = GDK_RIGHT_SIDE;
|
148 |
|
|
break;
|
149 |
|
|
case AWT_HAND_CURSOR:
|
150 |
|
|
gdk_cursor_type = GDK_HAND2;
|
151 |
|
|
break;
|
152 |
|
|
case AWT_MOVE_CURSOR:
|
153 |
|
|
gdk_cursor_type = GDK_FLEUR;
|
154 |
|
|
break;
|
155 |
|
|
default:
|
156 |
|
|
gdk_cursor_type = GDK_LEFT_PTR;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
win = widget->window;
|
160 |
|
|
if ((widget->window) == NULL)
|
161 |
|
|
win = widget->window;
|
162 |
|
|
|
163 |
|
|
gdk_cursor = gdk_cursor_new (gdk_cursor_type);
|
164 |
|
|
|
165 |
|
|
gdk_window_set_cursor (win, gdk_cursor);
|
166 |
|
|
gdk_cursor_unref (gdk_cursor);
|
167 |
|
|
|
168 |
|
|
gdk_flush();
|
169 |
|
|
|
170 |
|
|
gdk_threads_leave ();
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
JNIEXPORT void JNICALL
|
174 |
|
|
Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_connectSignals
|
175 |
|
|
(JNIEnv *env, jobject obj, jobject comp)
|
176 |
|
|
{
|
177 |
|
|
jclass gtkdragsourcecontextpeer;
|
178 |
|
|
jclass gtkdroptargetcontextpeer;
|
179 |
|
|
|
180 |
|
|
gdk_threads_enter ();
|
181 |
|
|
|
182 |
|
|
javaObj = obj;
|
183 |
|
|
gref = gtkpeer_get_global_ref (env, comp);
|
184 |
|
|
|
185 |
|
|
connect_signals_for_widget (widget);
|
186 |
|
|
|
187 |
|
|
gtkdragsourcecontextpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(),
|
188 |
|
|
"gnu/java/awt/dnd/peer/gtk/GtkDragSourceContextPeer");
|
189 |
|
|
|
190 |
|
|
dragEnterID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
|
191 |
|
|
gtkdragsourcecontextpeer,
|
192 |
|
|
"dragEnter", "(II)V");
|
193 |
|
|
dragExitID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
|
194 |
|
|
gtkdragsourcecontextpeer,
|
195 |
|
|
"dragExit", "(III)V");
|
196 |
|
|
dragDropEndID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
|
197 |
|
|
gtkdragsourcecontextpeer,
|
198 |
|
|
"dragDropEnd", "(IZII)V");
|
199 |
|
|
dragMouseMovedID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
|
200 |
|
|
gtkdragsourcecontextpeer,
|
201 |
|
|
"dragMouseMoved", "(II)V");
|
202 |
|
|
dragOverID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
|
203 |
|
|
gtkdragsourcecontextpeer,
|
204 |
|
|
"dragOver", "(II)V");
|
205 |
|
|
dragActionChangedID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
|
206 |
|
|
gtkdragsourcecontextpeer,
|
207 |
|
|
"dragActionChanged", "(II)V");
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
gtkdroptargetcontextpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(),
|
211 |
|
|
"gnu/java/awt/dnd/peer/gtk/GtkDropTargetContextPeer");
|
212 |
|
|
|
213 |
|
|
acceptDragID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
|
214 |
|
|
gtkdroptargetcontextpeer,
|
215 |
|
|
"acceptDrag", "(I)V");
|
216 |
|
|
rejectDragID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
|
217 |
|
|
gtkdroptargetcontextpeer,
|
218 |
|
|
"rejectDrag", "()V");
|
219 |
|
|
acceptDropID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
|
220 |
|
|
gtkdroptargetcontextpeer,
|
221 |
|
|
"acceptDrop", "(I)V");
|
222 |
|
|
rejectDropID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
|
223 |
|
|
gtkdroptargetcontextpeer,
|
224 |
|
|
"rejectDrop", "()V");
|
225 |
|
|
dropCompleteID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
|
226 |
|
|
gtkdroptargetcontextpeer,
|
227 |
|
|
"dropComplete", "(Z)V");
|
228 |
|
|
|
229 |
|
|
gdk_threads_leave ();
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
static void
|
233 |
|
|
connect_signals_for_widget (GtkWidget *w)
|
234 |
|
|
{
|
235 |
|
|
/* FIXME: Not implemented. */
|
236 |
|
|
w = NULL;
|
237 |
|
|
}
|
238 |
|
|
|
239 |
|
|
JNIEXPORT void JNICALL
|
240 |
|
|
Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_setTarget
|
241 |
|
|
(JNIEnv *env, jobject obj, jobject target)
|
242 |
|
|
{
|
243 |
|
|
void *ptr;
|
244 |
|
|
|
245 |
|
|
gdk_threads_enter ();
|
246 |
|
|
|
247 |
|
|
javaObj = obj;
|
248 |
|
|
ptr = gtkpeer_get_widget (env, target);
|
249 |
|
|
tgt = get_widget (GTK_WIDGET (ptr));
|
250 |
|
|
connect_signals_for_widget (tgt);
|
251 |
|
|
|
252 |
|
|
gdk_threads_leave ();
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
JNIEXPORT void JNICALL
|
256 |
|
|
Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_nativeStartDrag
|
257 |
|
|
(JNIEnv *env, jobject obj, jobject img, jint x, jint y, jint act,
|
258 |
|
|
jstring target)
|
259 |
|
|
{
|
260 |
|
|
void *ptr;
|
261 |
|
|
const gchar *data;
|
262 |
|
|
GtkTargetEntry tar[1];
|
263 |
|
|
GdkEvent *event;
|
264 |
|
|
GdkPixbuf *image = NULL;
|
265 |
|
|
GdkDragContext *context = NULL;
|
266 |
|
|
GdkDragAction action = GDK_ACTION_DEFAULT;
|
267 |
|
|
|
268 |
|
|
gdk_threads_enter ();
|
269 |
|
|
|
270 |
|
|
javaObj = obj;
|
271 |
|
|
ptr = gtkpeer_get_global_ref (env, obj);
|
272 |
|
|
|
273 |
|
|
data = (*env)->GetStringUTFChars (env, target, NULL);
|
274 |
|
|
tar[0].target = (gchar *) data;
|
275 |
|
|
event = gdk_event_new (GDK_ALL_EVENTS_MASK);
|
276 |
|
|
|
277 |
|
|
switch (act)
|
278 |
|
|
{
|
279 |
|
|
case ACTION_COPY:
|
280 |
|
|
action = GDK_ACTION_COPY;
|
281 |
|
|
break;
|
282 |
|
|
case ACTION_MOVE:
|
283 |
|
|
action = GDK_ACTION_MOVE;
|
284 |
|
|
break;
|
285 |
|
|
case ACTION_COPY_OR_MOVE:
|
286 |
|
|
action = GDK_ACTION_COPY | GDK_ACTION_MOVE;
|
287 |
|
|
break;
|
288 |
|
|
case ACTION_LINK:
|
289 |
|
|
action = GDK_ACTION_LINK;
|
290 |
|
|
break;
|
291 |
|
|
default:
|
292 |
|
|
action = GDK_ACTION_DEFAULT;
|
293 |
|
|
}
|
294 |
|
|
|
295 |
|
|
gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_ALL, tar,
|
296 |
|
|
sizeof (tar) / sizeof (GtkTargetEntry),
|
297 |
|
|
action);
|
298 |
|
|
context = gtk_drag_begin (widget,
|
299 |
|
|
gtk_target_list_new (tar, sizeof (tar) / sizeof (GtkTargetEntry)),
|
300 |
|
|
action, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, event);
|
301 |
|
|
|
302 |
|
|
if (img != NULL)
|
303 |
|
|
{
|
304 |
|
|
image = cp_gtk_image_get_pixbuf (env, img);
|
305 |
|
|
gtk_drag_set_icon_pixbuf (context, image, x, y);
|
306 |
|
|
}
|
307 |
|
|
|
308 |
|
|
if (tgt != NULL)
|
309 |
|
|
gtk_drag_dest_set (tgt, GTK_DEST_DEFAULT_ALL, tar,
|
310 |
|
|
sizeof (tar) / sizeof (GtkTargetEntry),
|
311 |
|
|
action);
|
312 |
|
|
|
313 |
|
|
gdk_event_free (event);
|
314 |
|
|
(*env)->ReleaseStringUTFChars (env, target, data);
|
315 |
|
|
|
316 |
|
|
gdk_threads_leave ();
|
317 |
|
|
}
|
318 |
|
|
|
319 |
|
|
static GtkWidget *
|
320 |
|
|
get_widget (GtkWidget *widget)
|
321 |
|
|
{
|
322 |
|
|
GtkWidget *w;
|
323 |
|
|
|
324 |
|
|
if (GTK_IS_EVENT_BOX (widget) || GTK_IS_CONTAINER (widget))
|
325 |
|
|
w = gtk_bin_get_child (GTK_BIN(widget));
|
326 |
|
|
else
|
327 |
|
|
w = widget;
|
328 |
|
|
|
329 |
|
|
return w;
|
330 |
|
|
}
|