| Summary: | Native drag and drop doesn't work under linux | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Eric Bordeau <ebordeau> |
| Component: | SWT | Assignee: | Veronika Irvine <veronika_irvine> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | critical | ||
| Priority: | P3 | CC: | david_williams, dirk_baeumer, hudsonr, thatnitind |
| Version: | 2.1 | ||
| Target Milestone: | 2.1 RC3 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
I'm using RC2 on Red Hat 8.0 I also tested this with RC1 Motif and I do get the drag start. I don't get the drag finished, which I do get under Windows, but this may be a Motif "feature". We rely on the drag finished notification. If this doesn't occur on Motif, our palette buttons will stay depressed at the end of a drag. Should we open a separate bug on this issue? Your example points out an error on Windows and Motif. The drag source should not allow you to initate a drag unless a transfer type has been specified. I will change Windows and Motif to stop initiating a drag in this case. You must call DragSource.setTransfer. Opened bug 35022 on dragFinished not being sent on Motif. The workaround for us on this bug is to set the Transfer[] before dragstart callback. So i'm reducing severity, this is just a portability issue. I have modified the behaviour across platforms to send the dragStart event and
then check after the event is returned to make sure that the transfer type has
been set.
This will allow you to not specify the drag transfer type until the drag has
started. However, after you return from dragStart, a transfer type must be
set or the DND operation will not continue.
Note, after the dragStart, if the dragStart handler threw an exception or if
no transfer type is set, the drag will not start and there will be no
dragFinished event. Whether there should be a drag finished event in this
case, can be debated. I think it would be undesirable but am open to
suggestion.
The following code will now initiate a drag and get a dragStart and a dragEnd
in all cases and across all platforms (win32, motif, gtk - no others are
implemented yet):
public static void main2(String[] args) {
Shell shell = new Shell();
Canvas canvas = new Canvas(shell, SWT.BORDER);
canvas.setBounds(10, 10, 100, 100);
final DragSource ds = new DragSource(canvas, DND.DROP_MOVE |
DND.DROP_COPY | DND.DROP_LINK);
ds.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
System.out.println("Drag Start");
ds.setTransfer(new Transfer[] {TextTransfer.getInstance
()});
}
public void dragSetData(DragSourceEvent event) {
System.out.println("Drag Set Data");
}
public void dragFinished(DragSourceEvent event) {
System.out.println("Drag Finished");
}
});
shell.open();
Display display = Display.getDefault();
while (!shell.isDisposed())
if (!display.readAndDispatch())
display.sleep();
}
|
Here's a simple test case that works under Windows and not Linux (GTK or Motif)... import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.*; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class DNDTest { public static void main(String[] args) { Shell shell = new Shell(); shell.setLayout(new FillLayout()); Canvas canvas = new Canvas(shell, SWT.NONE); DragSource ds = new DragSource(canvas, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK); ds.addDragListener(new DragSourceListener() { public void dragStart(DragSourceEvent event) { System.out.println("Drag Start"); } public void dragSetData(DragSourceEvent event) { System.out.println("Drag Set Data"); } public void dragFinished(DragSourceEvent event) { System.out.println("Drag Finished"); } }); shell.open(); Display display = Display.getDefault(); while (!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep(); } }