I have implemented more functions/classes for DnD. It is still a work in
progress and the native code is very much under construction, so please
don't mind the mess.
Now, we are able to drag from a source widget and drag to a target. The
target is now recognized. We cannot drop the widget onto the target just
yet.
2006-07-28 Lillian Angel <[EMAIL PROTECTED]>
* native/jni/gtk-peer/GtkDragSourceContextPeer.c:
Added more static functions to handle widget signals.
(create): Initialized the javaObj field.
(connectSignals): Added code to connect all signals to
the appropriate functions and initialized all java
function fields.
(drag_begin_cb): New callback, not implemented.
(drag_motion_cb): Likewise.
(drag_data_get_cb): Likewise.
(drag_data_delete_cb): Likewise.
(drag_drop_cb): Likewise.
(drag_end_cb): Likewise.
(drag_data_received_cb): Likewise.
(setTarget): New function.
(nativeStartDrag): Added code to set the destination and source
widgets.
* java/awt/dnd/DragSource.java
(startDrag): Removed FIXME.
* java/awt/dnd/DragGestureRecognizer.java
(fireDragGestureRecognized): Reset recognizer when events are
fired.
* java/awt/Component.java
(setDropTarget): Added code to create the DropTargetContextPeer.
* include/GtkDragSourceContextPeer.h: Regenerated.
* gnu/java/awt/dnd/peer/gtk/GtkDropTargetPeer.java: Removed
file.
* gnu/java/awt/dnd/peer/gtk/GtkDropTargetContextPeer.java
(GtkDropTargetContextPeer): Implemented.
* gnu/java/awt/dnd/peer/gtk/GtkDragSourceContextPeer.java
(GtkDragSourceContextPeer): Added code to set the target.
Index: native/jni/gtk-peer/GtkDragSourceContextPeer.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/GtkDragSourceContextPeer.c,v
retrieving revision 1.1
diff -u -r1.1 GtkDragSourceContextPeer.c
--- native/jni/gtk-peer/GtkDragSourceContextPeer.c 17 Jul 2006 18:37:19 -0000 1.1
+++ native/jni/gtk-peer/GtkDragSourceContextPeer.c 28 Jul 2006 15:44:33 -0000
@@ -42,7 +42,19 @@
#include <gtk/gtk.h>
static GtkWidget * get_widget (GtkWidget *widget);
-
+static void drag_begin_cb (GtkWidget *w, GdkDragContext *dc, gpointer data);
+static gboolean drag_motion_cb (GtkWidget *w, GdkDragContext *dc,
+ gint x, gint y, guint t, gpointer data);
+static void drag_data_get_cb (GtkWidget *w, GdkDragContext *dc, GtkSelectionData
+ *selection_data, guint info, guint t, gpointer data);
+static void drag_data_delete_cb (GtkWidget *w, GdkDragContext *dc, gpointer data);
+static gboolean drag_drop_cb (GtkWidget *w, GdkDragContext *dc, gint x,
+ gint y, guint t, gpointer data);
+static void drag_end_cb (GtkWidget *w, GdkDragContext *dc, gpointer data);
+static void drag_data_received_cb (GtkWidget *w, GdkDragContext *dc, gint x,
+ gint y, GtkSelectionData *selection_data,
+ guint info, guint t, gpointer data);
+
#define ACTION_COPY 1
#define ACTION_MOVE 2
#define ACTION_COPY_OR_MOVE 3
@@ -63,7 +75,21 @@
#define AWT_HAND_CURSOR 12
#define AWT_MOVE_CURSOR 13
+static jmethodID dragEnterID;
+static jmethodID dragExitID;
+static jmethodID dragDropEndID;
+static jmethodID dragMouseMovedID;
+static jmethodID dragOverID;
+static jmethodID dragActionChangedID;
+static jmethodID acceptDragID;
+static jmethodID rejectDragID;
+static jmethodID acceptDropID;
+static jmethodID rejectDropID;
+static jmethodID dropCompleteID;
+
GtkWidget *widget;
+GtkWidget *tgt;
+jobject javaObj;
JNIEXPORT void JNICALL
Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_create
@@ -72,7 +98,8 @@
void *ptr;
gdk_threads_enter ();
-
+
+ javaObj = obj;
NSA_SET_GLOBAL_REF (env, obj);
NSA_SET_GLOBAL_REF (env, comp);
@@ -93,6 +120,7 @@
gdk_threads_enter ();
+ javaObj = obj;
ptr = NSA_GET_GLOBAL_REF (env, obj);
switch (type)
@@ -160,29 +188,137 @@
{
jobject *gref;
void *ptr;
+ jclass gtkdragsourcecontextpeer;
+ jclass gtkdroptargetcontextpeer;
gdk_threads_enter ();
+ javaObj = obj;
ptr = NSA_GET_GLOBAL_REF (env, obj);
gref = NSA_GET_GLOBAL_REF (env, comp);
- /* Uncomment when needed:
g_signal_connect (G_OBJECT (widget), "drag_motion",
G_CALLBACK (drag_motion_cb), *gref);
- g_signal_connect (G_OBJECT (widget), "drag_begin",
- G_CALLBACK (drag_begin_cb), *gref);
+ g_signal_connect (G_OBJECT (widget), "drag_data_delete",
+ G_CALLBACK (drag_data_delete_cb), *gref);
g_signal_connect (G_OBJECT (widget), "drag_end",
G_CALLBACK (drag_end_cb), *gref);
g_signal_connect (G_OBJECT (widget), "drag_data_get",
G_CALLBACK (drag_data_get_cb), *gref);
- g_signal_connect (G_OBJECT (widget), "drag_drop",
- G_CALLBACK (drag_drop_cb), *gref);
- g_signal_connect (G_OBJECT (widget), "drag_data_delete",
- G_CALLBACK (drag_data_delete_cb), *gref);
g_signal_connect (G_OBJECT (widget), "drag_data_received",
G_CALLBACK (drag_data_received_cb), *gref);
- */
-
+ g_signal_connect (G_OBJECT (widget), "drag_begin",
+ G_CALLBACK (drag_begin_cb), *gref);
+ g_signal_connect (G_OBJECT (widget), "drag_drop",
+ G_CALLBACK (drag_drop_cb), *gref);
+
+
+ gtkdragsourcecontextpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(),
+ "gnu/java/awt/dnd/peer/gtk/GtkDragSourceContextPeer");
+
+ dragEnterID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
+ gtkdragsourcecontextpeer,
+ "dragEnter", "(II)V");
+ dragExitID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
+ gtkdragsourcecontextpeer,
+ "dragExit", "(III)V");
+ dragDropEndID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
+ gtkdragsourcecontextpeer,
+ "dragDropEnd", "(IZII)V");
+ dragMouseMovedID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
+ gtkdragsourcecontextpeer,
+ "dragMouseMoved", "(II)V");
+ dragOverID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
+ gtkdragsourcecontextpeer,
+ "dragOver", "(II)V");
+ dragActionChangedID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
+ gtkdragsourcecontextpeer,
+ "dragActionChanged", "(II)V");
+
+
+ gtkdroptargetcontextpeer = (*cp_gtk_gdk_env())->FindClass (cp_gtk_gdk_env(),
+ "gnu/java/awt/dnd/peer/gtk/GtkDropTargetContextPeer");
+
+ acceptDragID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
+ gtkdroptargetcontextpeer,
+ "acceptDrag", "(I)V");
+ rejectDragID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
+ gtkdroptargetcontextpeer,
+ "rejectDrag", "()V");
+ acceptDropID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
+ gtkdroptargetcontextpeer,
+ "acceptDrop", "(I)V");
+ rejectDropID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
+ gtkdroptargetcontextpeer,
+ "rejectDrop", "()V");
+ dropCompleteID = (*cp_gtk_gdk_env())->GetMethodID (cp_gtk_gdk_env(),
+ gtkdroptargetcontextpeer,
+ "dropComplete", "(Z)V");
+
+ gdk_threads_leave ();
+}
+
+static void
+drag_begin_cb (GtkWidget *w, GdkDragContext *dc, gpointer data)
+{
+ /* FIXME: Not implemented. */
+}
+
+static gboolean
+drag_motion_cb (GtkWidget *w, GdkDragContext *dc,
+ gint x, gint y, guint t, gpointer data)
+{
+ /* FIXME: Not implemented. */
+ return 0;
+}
+
+static void
+drag_data_get_cb (GtkWidget *w, GdkDragContext *dc, GtkSelectionData
+ *selection_data, guint info, guint t, gpointer data)
+{
+ /* FIXME: Not implemented. */
+}
+
+static void
+drag_data_delete_cb (GtkWidget *w, GdkDragContext *dc, gpointer data)
+{
+ /* FIXME: Not implemented. */
+}
+
+static gboolean
+drag_drop_cb (GtkWidget *w, GdkDragContext *dc, gint x,
+ gint y, guint t, gpointer data)
+{
+ /* FIXME: Not implemented. */
+ return 0;
+}
+
+static void
+drag_end_cb (GtkWidget *w, GdkDragContext *dc, gpointer data)
+{
+ /* FIXME: Not implemented. */
+}
+
+static void
+drag_data_received_cb (GtkWidget *w, GdkDragContext *dc, gint x,
+ gint y, GtkSelectionData *selection_data,
+ guint info, guint t, gpointer data)
+{
+ /* FIXME: Not implemented. */
+}
+
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_setTarget
+ (JNIEnv *env, jobject obj, jobject target)
+{
+ void *ptr;
+
+ gdk_threads_enter ();
+
+ javaObj = obj;
+ ptr = NSA_GET_PTR (env, target);
+ tgt = get_widget (GTK_WIDGET (ptr));
+
gdk_threads_leave ();
}
@@ -200,7 +336,8 @@
GdkDragAction action = GDK_ACTION_DEFAULT;
gdk_threads_enter ();
-
+
+ javaObj = obj;
ptr = NSA_GET_GLOBAL_REF (env, obj);
data = (*env)->GetStringUTFChars (env, target, NULL);
@@ -225,7 +362,9 @@
action = GDK_ACTION_DEFAULT;
}
- gtk_drag_highlight (widget);
+ gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_ALL, tar,
+ sizeof (tar) / sizeof (GtkTargetEntry),
+ action);
context = gtk_drag_begin (widget,
gtk_target_list_new (tar, sizeof (tar) / sizeof (GtkTargetEntry)),
action, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, event);
@@ -235,6 +374,11 @@
image = cp_gtk_image_get_pixbuf (env, img);
gtk_drag_set_icon_pixbuf (context, image, x, y);
}
+
+ if (tgt != NULL)
+ gtk_drag_dest_set (tgt, GTK_DEST_DEFAULT_ALL, tar,
+ sizeof (tar) / sizeof (GtkTargetEntry),
+ action);
gdk_event_free (event);
(*env)->ReleaseStringUTFChars (env, target, data);
Index: java/awt/dnd/DragSource.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DragSource.java,v
retrieving revision 1.11
diff -u -r1.11 DragSource.java
--- java/awt/dnd/DragSource.java 21 Jul 2006 20:44:30 -0000 1.11
+++ java/awt/dnd/DragSource.java 28 Jul 2006 15:44:33 -0000
@@ -105,7 +105,7 @@
ds = null;
throw new HeadlessException();
}
-
+
if (ds == null)
ds = new DragSource();
return ds;
@@ -140,8 +140,6 @@
// This function sends the same message to the context, which then forwards
// it to the peer, passing itself as a parameter. Now, the native system has
// access to the Transferable through the context.
-
- // FIXME: Add check to determine if dragging.
try
{
Index: java/awt/dnd/DragGestureRecognizer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DragGestureRecognizer.java,v
retrieving revision 1.6
diff -u -r1.6 DragGestureRecognizer.java
--- java/awt/dnd/DragGestureRecognizer.java 5 Jul 2006 17:45:50 -0000 1.6
+++ java/awt/dnd/DragGestureRecognizer.java 28 Jul 2006 15:44:33 -0000
@@ -164,6 +164,7 @@
if(dragGestureListener != null)
dragGestureListener.dragGestureRecognized
(new DragGestureEvent(this, dragAction, p, events));
+ resetRecognizer();
}
protected void appendEvent(InputEvent e)
Index: java/awt/Component.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.140
diff -u -r1.140 Component.java
--- java/awt/Component.java 28 Jul 2006 10:07:39 -0000 1.140
+++ java/awt/Component.java 28 Jul 2006 15:44:34 -0000
@@ -39,6 +39,8 @@
package java.awt;
+import gnu.java.awt.dnd.peer.gtk.GtkDropTargetContextPeer;
+
import java.awt.dnd.DropTarget;
import java.awt.event.ActionEvent;
import java.awt.event.AdjustmentEvent;
@@ -698,6 +700,9 @@
public void setDropTarget(DropTarget dt)
{
this.dropTarget = dt;
+ if (dropTarget != null)
+ dropTarget.getDropTargetContext().addNotify(
+ new GtkDropTargetContextPeer(this));
}
/**
Index: include/GtkDragSourceContextPeer.h
===================================================================
RCS file: /cvsroot/classpath/classpath/include/GtkDragSourceContextPeer.h,v
retrieving revision 1.1
diff -u -r1.1 GtkDragSourceContextPeer.h
--- include/GtkDragSourceContextPeer.h 17 Jul 2006 18:37:19 -0000 1.1
+++ include/GtkDragSourceContextPeer.h 28 Jul 2006 15:44:34 -0000
@@ -14,7 +14,7 @@
JNIEXPORT void JNICALL Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_connectSignals (JNIEnv *env, jobject, jobject);
JNIEXPORT void JNICALL Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_create (JNIEnv *env, jobject, jobject);
JNIEXPORT void JNICALL Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_nativeSetCursor (JNIEnv *env, jobject, jint) ;
-
+JNIEXPORT void JNICALL Java_gnu_java_awt_dnd_peer_gtk_GtkDragSourceContextPeer_setTarget (JNIEnv *env, jobject, jobject);
#ifdef __cplusplus
}
Index: gnu/java/awt/dnd/peer/gtk/GtkDropTargetPeer.java
===================================================================
RCS file: gnu/java/awt/dnd/peer/gtk/GtkDropTargetPeer.java
diff -N gnu/java/awt/dnd/peer/gtk/GtkDropTargetPeer.java
--- gnu/java/awt/dnd/peer/gtk/GtkDropTargetPeer.java 17 Jul 2006 18:37:19 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,68 +0,0 @@
-/* GtkDropTargetPeer.java --
- Copyright (C) 2006 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.awt.dnd.peer.gtk;
-
-import gnu.java.awt.peer.gtk.GtkGenericPeer;
-
-import java.awt.dnd.DropTarget;
-import java.awt.dnd.peer.DropTargetPeer;
-
-public class GtkDropTargetPeer
- extends GtkGenericPeer
- implements DropTargetPeer
-{
-
- public GtkDropTargetPeer()
- {
- super(null);
- }
-
- public void addDropTarget(DropTarget target)
- {
- // FIXME: Not Implemented
-
- }
-
- public void removeDropTarget(DropTarget target)
- {
- // FIXME: Not Implemented
-
- }
-
-}
Index: gnu/java/awt/dnd/peer/gtk/GtkDropTargetContextPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/dnd/peer/gtk/GtkDropTargetContextPeer.java,v
retrieving revision 1.2
diff -u -r1.2 GtkDropTargetContextPeer.java
--- gnu/java/awt/dnd/peer/gtk/GtkDropTargetContextPeer.java 17 Jul 2006 18:37:19 -0000 1.2
+++ gnu/java/awt/dnd/peer/gtk/GtkDropTargetContextPeer.java 28 Jul 2006 15:44:34 -0000
@@ -40,6 +40,7 @@
import gnu.java.awt.peer.gtk.GtkGenericPeer;
+import java.awt.Component;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DropTarget;
@@ -50,10 +51,11 @@
extends GtkGenericPeer
implements DropTargetContextPeer
{
-
- public GtkDropTargetContextPeer()
+
+ public GtkDropTargetContextPeer(Object obj)
{
- super(null);
+ super(obj);
+ GtkDragSourceContextPeer.target = (Component) obj;
}
public void setTargetActions(int actions)
Index: gnu/java/awt/dnd/peer/gtk/GtkDragSourceContextPeer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/dnd/peer/gtk/GtkDragSourceContextPeer.java,v
retrieving revision 1.3
diff -u -r1.3 GtkDragSourceContextPeer.java
--- gnu/java/awt/dnd/peer/gtk/GtkDragSourceContextPeer.java 19 Jul 2006 16:04:19 -0000 1.3
+++ gnu/java/awt/dnd/peer/gtk/GtkDragSourceContextPeer.java 28 Jul 2006 15:44:34 -0000
@@ -61,11 +61,13 @@
private ComponentPeer peer;
private Cursor cursor;
private DragSourceContext context;
+ public static Component target;
native void nativeStartDrag(Image i, int x, int y, int action, String target);
native void connectSignals(ComponentPeer comp);
native void create(ComponentPeer comp);
native void nativeSetCursor(int cursor);
+ native void setTarget(ComponentPeer target);
public GtkDragSourceContextPeer(DragGestureEvent e)
{
@@ -76,6 +78,7 @@
create(peer);
connectSignals(peer);
cursor = comp.getCursor();
+ setTarget(target.getPeer());
}
ComponentPeer getComponentPeer(Component c)
@@ -93,7 +96,7 @@
throws InvalidDnDOperationException
{
this.context = context;
-
+
if (p == null)
p = new Point();