Community
Participate
Working Groups
I'm writing automated DnD tests for the CNF, and the problem is that for some platforms it's difficult to reliably create a drag gesture that starts the whole process. I have tried things like moving the mouse 10 pixels (using Display.post(), moving it back, various things with delays, and none work consistently on all platforms. The code that I'm trying to make with is in org.eclipse.ui.tests.harness SWTEventHelper, in the performDndInternal method. The current code I have seems to work 100% on Linux, mostly on Windows, and not at all on the Mac (carbon) It would be nice if there were a way to post a "drag gesture" event so that we could be sure that the platform drag has really started and not have to worry about platform differences in our code. See also bug 109101
I think you have to emulate gestures using mouse down and mouse moves (as you are doing already). I think that should work on all platforms. Please, post some simple code that shows it working on linux but not on mac.
(In reply to comment #1) > I think you have to emulate gestures using mouse down and mouse moves (as you > are doing already). I think that should work on all platforms. > Please, post some simple code that shows it working on linux but not on mac. > If you run the org.eclipse.ui.tests.navigator.DnDTest on a Mac, you will see that it does not work. The test passes, but you will see sysouts that say the drag gesture failed. The same tests works on Unix (you don't see the sysouts). You don't need any special setup to run that test beyond having the platform-ui-tests checked out. Is that simple enough?
Created attachment 126346 [details] sample code I'm surprised you have this working on linux. I've been hacking a bit today and I quickly got to working code on carbon and win32, but gtk has beaten me so far. Anyway, it's not a solution, but maybe there's something in my code that's helpful to you?
This code works for me on carbon, windows, and gtk. /******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package dnd; /* * Drag and Drop example snippet: drag text between two labels * * For a list of all SWT example snippets see * http://www.eclipse.org/swt/snippets/ */ import java.util.Timer; import java.util.TimerTask; import org.eclipse.swt.*; import org.eclipse.swt.dnd.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public class PR263695 { public static void main(String[] args) { final Display display = new Display(); Listener listener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.MouseDown: System.out.println("down"); break; case SWT.MouseUp: System.out.println("up"); break; case SWT.MouseMove: System.out.println("move"); break; } } }; display.addFilter(SWT.MouseMove, listener); display.addFilter(SWT.MouseDown, listener); display.addFilter(SWT.MouseUp, listener); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Label label1 = new Label(shell, SWT.BORDER); label1.setText("TEXT"); final Label label2 = new Label(shell, SWT.BORDER); setDragDrop(label1); setDragDrop(label2); shell.setSize(200, 200); shell.open(); Rectangle bounds = label1.getBounds(); bounds = display.map(label1.getParent(), null, bounds); final int downX = bounds.x + (bounds.width / 2); final int downY = bounds.y + (bounds.height / 2); bounds = label2.getBounds(); bounds = display.map(label2.getParent(), null, bounds); final int upX = bounds.x + (bounds.width / 2); final int upY = bounds.y + (bounds.height / 2); display.setCursorLocation(downX, downY); Thread t = new Thread(new Runnable(){ public void run() { try { Thread.sleep(2000); } catch (InterruptedException e) {} int sleep = 50; Event event = new Event(); event.type = SWT.MouseDown; event.button = 1; display.post(event); try { Thread.sleep(sleep); } catch (InterruptedException e) {} event = new Event(); event.type = SWT.MouseMove; event.x = downX; event.y = downY+20; display.post(event); try { Thread.sleep(sleep); } catch (InterruptedException e) {} System.out.println("move to target"); event = new Event(); event.type = SWT.MouseMove; event.x = upX; event.y = upY; display.post(event); try { Thread.sleep(sleep); } catch (InterruptedException e) {} System.out.println("move inside target"); event = new Event(); event.type = SWT.MouseMove; event.x = upX; event.y = upY + 20; display.post(event); try { Thread.sleep(sleep); } catch (InterruptedException e) {} System.out.println("release"); event = new Event(); event.type = SWT.MouseUp; event.button = 1; display.post(event); } }); t.start(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } public static void setDragDrop(final Label label) { Transfer[] types = new Transfer[] { TextTransfer.getInstance() }; int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; final DragSource source = new DragSource(label, operations); source.setTransfer(types); source.addDragListener(new DragSourceListener() { public void dragStart(DragSourceEvent event) { event.doit = (label.getText().length() != 0); } public void dragSetData(DragSourceEvent event) { event.data = label.getText(); } public void dragFinished(DragSourceEvent event) { if (event.detail == DND.DROP_MOVE) label.setText(""); } }); DropTarget target = new DropTarget(label, operations); target.setTransfer(types); target.addDropListener(new DropTargetAdapter() { public void drop(DropTargetEvent event) { System.out.println("got event"); if (event.data == null) { event.detail = DND.DROP_NONE; return; } label.setText((String) event.data); } }); } }
Thanks Kevin...
Thanks for this Kevin (and sorry for my delay in trying this out). Unfortunately this does not work on my Fedora 9 X64 System (it does not see the drag gesture). Below are my gtk versions. I had the original code working on my system and then it stopped seeing the dragStart (so I think it was not picking up the drag gesture). I suspect what happen is that I updated my system and some newer version of gtk is different in getting the drag gesture. I stay pretty current with the Fedora updates. Let me know if there is something I can do to help. I tried hacking a few different things to try to get it to pick up a drag gesture (a loop moving pixel by pixel, etc), but I could not. Installed Packages gtk+.x86_64 1:1.2.10-66.fc9 installed gtk-doc.noarch 1.9-4.fc9 installed gtk-nodoka-engine.i386 0.7.1-2.fc9 installed gtk-nodoka-engine.x86_64 0.7.1-2.fc9 installed gtk-sharp2.x86_64 2.12.1-1.fc9 installed gtk-vnc.x86_64 0.3.8-1.fc9 installed gtk-vnc-python.x86_64 0.3.8-1.fc9 installed gtk2.i386 2.12.12-2.fc9 installed gtk2.x86_64 2.12.12-2.fc9 installed gtk2-devel.i386 2.12.12-2.fc9 installed gtk2-devel.x86_64 2.12.12-2.fc9 installed gtk2-engines.i386 2.14.3-1.fc9 installed gtk2-engines.x86_64 2.14.3-1.fc9 installed gtkglext-libs.x86_64 1.2.0-6.fc9 installed gtkhtml2.x86_64 2.11.1-3.fc9 installed gtkhtml3.x86_64 3.18.3-1.fc9 installed gtkmm24.x86_64 2.12.7-1.fc9 installed gtksourceview.x86_64 1:1.8.5-4.fc9 installed gtksourceview2.x86_64 2.2.2-1.fc9 installed gtkspell.i386 2.0.11-8.fc9 installed gtkspell.x86_64 2.0.11-8.fc9 installed
I just upgraded to Fedora 10, and it also does not work. Below are the versions: gtk+.x86_64 1:1.2.10-66.fc10 installed gtk-doc.noarch 1.10-2.fc10 installed gtk-nodoka-engine.i386 0.7.2-1.fc10 installed gtk-nodoka-engine.x86_64 0.7.2-1.fc10 installed gtk-sharp2.x86_64 2.12.7-1.fc10.1 installed gtk-vnc.x86_64 0.3.8-1.fc10 installed gtk-vnc-python.x86_64 0.3.8-1.fc10 installed gtk2.i386 2.14.7-1.fc10 installed gtk2.x86_64 2.14.7-1.fc10 installed gtk2-devel.i386 2.14.7-1.fc10 installed gtk2-devel.x86_64 2.14.7-1.fc10 installed gtk2-engines.i386 2.16.1-1.fc10 installed gtk2-engines.x86_64 2.16.1-1.fc10 installed gtkglext-libs.x86_64 1.2.0-7.fc10 installed gtkhtml2.x86_64 2.11.1-4.fc10 installed gtkhtml3.x86_64 3.24.5-1.fc10 installed gtkmm24.x86_64 2.14.3-1.fc10 installed gtksourceview.x86_64 1:1.8.5-5.fc10 installed gtksourceview2.x86_64 2.4.2-1.fc10 installed gtkspell.i386 2.0.15-1.fc10 installed gtkspell.x86_64 2.0.15-1.fc10
Made some changes to Cocoa's post() for mouse events based on this bug.
Comment 4 is also no good for me on Gentoo Linux with gtk+-2.14.7-r2.
When I click and drag I do not get any MouseMove events. This seems to contradict the post(Event) invocations in comment 4. Is this the expected behaviour?