summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd
diff options
context:
space:
mode:
authorFelipe Heidrich <fheidric>2009-06-30 22:00:12 +0000
committerFelipe Heidrich <fheidric>2009-06-30 22:00:12 +0000
commitf664d297f7bb009784868bf3fcf0b3e3bb9a646b (patch)
tree54012fe4929893eef4891c88cbbf5841272ff433 /bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd
parentbc18a5e014088ce811f09c603b88361094486062 (diff)
downloadeclipse.platform.swt-f664d297f7bb009784868bf3fcf0b3e3bb9a646b.tar.gz
eclipse.platform.swt-f664d297f7bb009784868bf3fcf0b3e3bb9a646b.tar.xz
eclipse.platform.swt-f664d297f7bb009784868bf3fcf0b3e3bb9a646b.zip
*** empty log message ***
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ByteArrayTransfer.java189
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Clipboard.java622
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ClipboardProxy.java191
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java633
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DropTarget.java812
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/FileTransfer.java217
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/HTMLTransfer.java113
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ImageTransfer.java174
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/RTFTransfer.java114
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDragSourceEffect.java142
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDropTargetEffect.java186
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TextTransfer.java144
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Transfer.java154
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TransferData.java98
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDragSourceEffect.java141
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDropTargetEffect.java222
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/URLTransfer.java115
17 files changed, 0 insertions, 4267 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ByteArrayTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ByteArrayTransfer.java
deleted file mode 100644
index 6620e7491a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ByteArrayTransfer.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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 org.eclipse.swt.dnd;
-
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * The class <code>ByteArrayTransfer</code> provides a platform specific
- * mechanism for converting a java <code>byte[]</code> to a platform
- * specific representation of the byte array and vice versa.
- *
- * <p><code>ByteArrayTransfer</code> is never used directly but is sub-classed
- * by transfer agents that convert between data in a java format such as a
- * <code>String</code> and a platform specific byte array.
- *
- * <p>If the data you are converting <b>does not</b> map to a
- * <code>byte[]</code>, you should sub-class <code>Transfer</code> directly
- * and do your own mapping to a platform data type.</p>
- *
- * <p>The following snippet shows a subclass of ByteArrayTransfer that transfers
- * data defined by the class <code>MyType</code>.</p>
- *
- * <pre><code>
- * public class MyType {
- * public String fileName;
- * public long fileLength;
- * public long lastModified;
- * }
- * </code></pre>
- *
- * <pre><code>
- * public class MyTypeTransfer extends ByteArrayTransfer {
- *
- * private static final String MYTYPENAME = "my_type_name";
- * private static final int MYTYPEID = registerType(MYTYPENAME);
- * private static MyTypeTransfer _instance = new MyTypeTransfer();
- *
- * private MyTypeTransfer() {}
- *
- * public static MyTypeTransfer getInstance () {
- * return _instance;
- * }
- * public void javaToNative (Object object, TransferData transferData) {
- * if (object == null || !(object instanceof MyType[])) return;
- *
- * if (isSupportedType(transferData)) {
- * MyType[] myTypes = (MyType[]) object;
- * try {
- * // write data to a byte array and then ask super to convert to pMedium
- * ByteArrayOutputStream out = new ByteArrayOutputStream();
- * DataOutputStream writeOut = new DataOutputStream(out);
- * for (int i = 0, length = myTypes.length; i &lt; length; i++){
- * byte[] buffer = myTypes[i].fileName.getBytes();
- * writeOut.writeInt(buffer.length);
- * writeOut.write(buffer);
- * writeOut.writeLong(myTypes[i].fileLength);
- * writeOut.writeLong(myTypes[i].lastModified);
- * }
- * byte[] buffer = out.toByteArray();
- * writeOut.close();
- *
- * super.javaToNative(buffer, transferData);
- *
- * } catch (IOException e) {
- * }
- * }
- * }
- * public Object nativeToJava(TransferData transferData){
- *
- * if (isSupportedType(transferData)) {
- *
- * byte[] buffer = (byte[])super.nativeToJava(transferData);
- * if (buffer == null) return null;
- *
- * MyType[] myData = new MyType[0];
- * try {
- * ByteArrayInputStream in = new ByteArrayInputStream(buffer);
- * DataInputStream readIn = new DataInputStream(in);
- * while(readIn.available() > 20) {
- * MyType datum = new MyType();
- * int size = readIn.readInt();
- * byte[] name = new byte[size];
- * readIn.read(name);
- * datum.fileName = new String(name);
- * datum.fileLength = readIn.readLong();
- * datum.lastModified = readIn.readLong();
- * MyType[] newMyData = new MyType[myData.length + 1];
- * System.arraycopy(myData, 0, newMyData, 0, myData.length);
- * newMyData[myData.length] = datum;
- * myData = newMyData;
- * }
- * readIn.close();
- * } catch (IOException ex) {
- * return null;
- * }
- * return myData;
- * }
- *
- * return null;
- * }
- * protected String[] getTypeNames(){
- * return new String[]{MYTYPENAME};
- * }
- * protected int[] getTypeIds(){
- * return new int[] {MYTYPEID};
- * }
- * }
- * </code></pre>
- *
- * @see Transfer
- */
-public abstract class ByteArrayTransfer extends Transfer {
-
-public TransferData[] getSupportedTypes() {
- int[] types = getTypeIds();
- TransferData[] data = new TransferData[types.length];
- for (int i = 0; i < types.length; i++) {
- data[i] = new TransferData();
- data[i].type = types[i];
- }
- return data;
-}
-
-public boolean isSupportedType(TransferData transferData){
- if (transferData == null) return false;
- int[] types = getTypeIds();
- for (int i = 0; i < types.length; i++) {
- if (transferData.type == types[i]) return true;
- }
- return false;
-}
-
-/**
- * This implementation of <code>javaToNative</code> converts a java
- * <code>byte[]</code> to a platform specific representation.
- *
- * @param object a java <code>byte[]</code> containing the data to be converted
- * @param transferData an empty <code>TransferData</code> object that will
- * be filled in on return with the platform specific format of the data
- *
- * @see Transfer#nativeToJava
- */
-protected void javaToNative (Object object, TransferData transferData) {
- transferData.result = 0;
- if (!checkByteArray(object) || !isSupportedType(transferData)) {
- DND.error(DND.ERROR_INVALID_DATA);
- }
- byte[] buffer = (byte[])object;
- if (buffer.length == 0) return;
- int /*long*/ pValue = OS.g_malloc(buffer.length);
- if (pValue == 0) return;
- OS.memmove(pValue, buffer, buffer.length);
- transferData.length = buffer.length;
- transferData.format = 8;
- transferData.pValue = pValue;
- transferData.result = 1;
-}
-
-/**
- * This implementation of <code>nativeToJava</code> converts a platform specific
- * representation of a byte array to a java <code>byte[]</code>.
- *
- * @param transferData the platform specific representation of the data to be converted
- * @return a java <code>byte[]</code> containing the converted data if the conversion was
- * successful; otherwise null
- *
- * @see Transfer#javaToNative
- */
-protected Object nativeToJava(TransferData transferData) {
- if ( !isSupportedType(transferData) || transferData.pValue == 0) return null;
- int size = transferData.format * transferData.length / 8;
- if (size == 0) return null;
- byte[] buffer = new byte[size];
- OS.memmove(buffer, transferData.pValue, size);
- return buffer;
-}
-
-boolean checkByteArray(Object object) {
- return (object != null && object instanceof byte[] && ((byte[])object).length > 0);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Clipboard.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Clipboard.java
deleted file mode 100644
index 87b1e171ce..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Clipboard.java
+++ /dev/null
@@ -1,622 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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 org.eclipse.swt.dnd;
-
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.internal.Converter;
-import org.eclipse.swt.internal.gtk.GtkSelectionData;
-import org.eclipse.swt.internal.gtk.OS;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * The <code>Clipboard</code> provides a mechanism for transferring data from one
- * application to another or within an application.
- *
- * <p>IMPORTANT: This class is <em>not</em> intended to be subclassed.</p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#clipboard">Clipboard snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ClipboardExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class Clipboard {
-
- private Display display;
-
- static int /*long*/ GTKCLIPBOARD;
- static int /*long*/ GTKPRIMARYCLIPBOARD;
- private static int /*long*/ TARGET;
-
- static {
- GTKCLIPBOARD = OS.gtk_clipboard_get(OS.GDK_NONE);
- byte[] buffer = Converter.wcsToMbcs(null, "PRIMARY", true);
- int /*long*/ primary = OS.gdk_atom_intern(buffer, false);
- GTKPRIMARYCLIPBOARD = OS.gtk_clipboard_get(primary);
- buffer = Converter.wcsToMbcs(null, "TARGETS", true);
- TARGET = OS.gdk_atom_intern(buffer, false);
- }
-
-/**
- * Constructs a new instance of this class. Creating an instance of a Clipboard
- * may cause system resources to be allocated depending on the platform. It is therefore
- * mandatory that the Clipboard instance be disposed when no longer required.
- *
- * @param display the display on which to allocate the clipboard
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- *
- * @see Clipboard#dispose
- * @see Clipboard#checkSubclass
- */
-public Clipboard(Display display) {
- checkSubclass ();
- if (display == null) {
- display = Display.getCurrent();
- if (display == null) {
- display = Display.getDefault();
- }
- }
- if (display.getThread() != Thread.currentThread()) {
- DND.error(SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- this.display = display;
-}
-
-/**
- * Checks that this class can be subclassed.
- * <p>
- * The SWT class library is intended to be subclassed
- * only at specific, controlled points. This method enforces this
- * rule unless it is overridden.
- * </p><p>
- * <em>IMPORTANT:</em> By providing an implementation of this
- * method that allows a subclass of a class which does not
- * normally allow subclassing to be created, the implementer
- * agrees to be fully responsible for the fact that any such
- * subclass will likely fail between SWT releases and will be
- * strongly platform specific. No support is provided for
- * user-written classes which are implemented in this fashion.
- * </p><p>
- * The ability to subclass outside of the allowed SWT classes
- * is intended purely to enable those not on the SWT development
- * team to implement patches in order to get around specific
- * limitations in advance of when those limitations can be
- * addressed by the team. Subclassing should not be attempted
- * without an intimate and detailed understanding of the hierarchy.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- */
-protected void checkSubclass () {
- String name = getClass().getName ();
- String validName = Clipboard.class.getName();
- if (!validName.equals(name)) {
- DND.error (SWT.ERROR_INVALID_SUBCLASS);
- }
-}
-/**
- * Throws an <code>SWTException</code> if the receiver can not
- * be accessed by the caller. This may include both checks on
- * the state of the receiver and more generally on the entire
- * execution context. This method <em>should</em> be called by
- * widget implementors to enforce the standard SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code>) on a widget that has had its
- * <code>dispose()</code> method called. It is also an error
- * to call widget methods from any thread that is different
- * from the thread that created the widget.
- * </p><p>
- * In future releases of SWT, there may be more or fewer error
- * checks and exceptions may be thrown for different reasons.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-protected void checkWidget () {
- Display display = this.display;
- if (display == null) DND.error (SWT.ERROR_WIDGET_DISPOSED);
- if (display.getThread() != Thread.currentThread ()) DND.error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (display.isDisposed()) DND.error(SWT.ERROR_WIDGET_DISPOSED);
-}
-
-/**
- * If this clipboard is currently the owner of the data on the system clipboard,
- * clear the contents. If this clipboard is not the owner, then nothing is done.
- * Note that there are clipboard assistant applications that take ownership of
- * data or make copies of data when it is placed on the clipboard. In these
- * cases, it may not be possible to clear the clipboard.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 3.1
- */
-public void clearContents() {
- clearContents(DND.CLIPBOARD);
-}
-
-/**
- * If this clipboard is currently the owner of the data on the specified
- * clipboard, clear the contents. If this clipboard is not the owner, then
- * nothing is done.
- *
- * <p>Note that there are clipboard assistant applications that take ownership
- * of data or make copies of data when it is placed on the clipboard. In these
- * cases, it may not be possible to clear the clipboard.</p>
- *
- * <p>The clipboards value is either one of the clipboard constants defined in
- * class <code>DND</code>, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>DND</code> clipboard constants.</p>
- *
- * @param clipboards to be cleared
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DND#CLIPBOARD
- * @see DND#SELECTION_CLIPBOARD
- *
- * @since 3.1
- */
-public void clearContents(int clipboards) {
- checkWidget();
- ClipboardProxy proxy = ClipboardProxy._getInstance(display);
- proxy.clear(this, clipboards);
-}
-
-/**
- * Disposes of the operating system resources associated with the clipboard.
- * The data will still be available on the system clipboard after the dispose
- * method is called.
- *
- * <p>NOTE: On some platforms the data will not be available once the application
- * has exited or the display has been disposed.</p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * </ul>
- */
-public void dispose () {
- if (isDisposed()) return;
- if (display.getThread() != Thread.currentThread()) DND.error(SWT.ERROR_THREAD_INVALID_ACCESS);
- display = null;
-}
-
-/**
- * Retrieve the data of the specified type currently available on the system
- * clipboard. Refer to the specific subclass of <code>Transfer</code> to
- * determine the type of object returned.
- *
- * <p>The following snippet shows text and RTF text being retrieved from the
- * clipboard:</p>
- *
- * <code><pre>
- * Clipboard clipboard = new Clipboard(display);
- * TextTransfer textTransfer = TextTransfer.getInstance();
- * String textData = (String)clipboard.getContents(textTransfer);
- * if (textData != null) System.out.println("Text is "+textData);
- * RTFTransfer rtfTransfer = RTFTransfer.getInstance();
- * String rtfData = (String)clipboard.getContents(rtfTransfer);
- * if (rtfData != null) System.out.println("RTF Text is "+rtfData);
- * clipboard.dispose();
- * </code></pre>
- *
- * @param transfer the transfer agent for the type of data being requested
- * @return the data obtained from the clipboard or null if no data of this type is available
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if transfer is null</li>
- * </ul>
- *
- * @see Transfer
- */
-public Object getContents(Transfer transfer) {
- return getContents(transfer, DND.CLIPBOARD);
-}
-
-/**
- * Retrieve the data of the specified type currently available on the specified
- * clipboard. Refer to the specific subclass of <code>Transfer</code> to
- * determine the type of object returned.
- *
- * <p>The following snippet shows text and RTF text being retrieved from the
- * clipboard:</p>
- *
- * <code><pre>
- * Clipboard clipboard = new Clipboard(display);
- * TextTransfer textTransfer = TextTransfer.getInstance();
- * String textData = (String)clipboard.getContents(textTransfer);
- * if (textData != null) System.out.println("Text is "+textData);
- * RTFTransfer rtfTransfer = RTFTransfer.getInstance();
- * String rtfData = (String)clipboard.getContents(rtfTransfer, DND.CLIPBOARD);
- * if (rtfData != null) System.out.println("RTF Text is "+rtfData);
- * clipboard.dispose();
- * </code></pre>
- *
- * <p>The clipboards value is either one of the clipboard constants defined in
- * class <code>DND</code>, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>DND</code> clipboard constants.</p>
- *
- * @param transfer the transfer agent for the type of data being requested
- * @param clipboards on which to look for data
- *
- * @return the data obtained from the clipboard or null if no data of this type is available
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if transfer is null</li>
- * </ul>
- *
- * @see Transfer
- * @see DND#CLIPBOARD
- * @see DND#SELECTION_CLIPBOARD
- *
- * @since 3.1
- */
-public Object getContents(Transfer transfer, int clipboards) {
- checkWidget();
- if (transfer == null) DND.error(SWT.ERROR_NULL_ARGUMENT);
- int /*long*/ selection_data = 0;
- int[] typeIds = transfer.getTypeIds();
- for (int i = 0; i < typeIds.length; i++) {
- if ((clipboards & DND.CLIPBOARD) != 0) {
- selection_data = gtk_clipboard_wait_for_contents(GTKCLIPBOARD, typeIds[i]);
- }
- if (selection_data != 0) break;
- if ((clipboards & DND.SELECTION_CLIPBOARD) != 0) {
- selection_data = gtk_clipboard_wait_for_contents(GTKPRIMARYCLIPBOARD, typeIds[i]);
- }
- }
- if (selection_data == 0) return null;
- GtkSelectionData gtkSelectionData = new GtkSelectionData();
- OS.memmove(gtkSelectionData, selection_data, GtkSelectionData.sizeof);
- TransferData tdata = new TransferData();
- tdata.type = gtkSelectionData.type;
- tdata.pValue = gtkSelectionData.data;
- tdata.length = gtkSelectionData.length;
- tdata.format = gtkSelectionData.format;
- Object result = transfer.nativeToJava(tdata);
- OS.gtk_selection_data_free(selection_data);
- return result;
-}
-
-/**
- * Returns <code>true</code> if the clipboard has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the clipboard.
- * When a clipboard has been disposed, it is an error to
- * invoke any other method using the clipboard.
- * </p>
- *
- * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise
- *
- * @since 3.0
- */
-public boolean isDisposed () {
- return (display == null);
-}
-
-/**
- * Place data of the specified type on the system clipboard. More than one type
- * of data can be placed on the system clipboard at the same time. Setting the
- * data clears any previous data from the system clipboard, regardless of type.
- *
- * <p>NOTE: On some platforms, the data is immediately copied to the system
- * clipboard but on other platforms it is provided upon request. As a result,
- * if the application modifies the data object it has set on the clipboard, that
- * modification may or may not be available when the data is subsequently
- * requested.</p>
- *
- * <p>The following snippet shows text and RTF text being set on the copy/paste
- * clipboard:
- * </p>
- *
- * <code><pre>
- * Clipboard clipboard = new Clipboard(display);
- * String textData = "Hello World";
- * String rtfData = "{\\rtf1\\b\\i Hello World}";
- * TextTransfer textTransfer = TextTransfer.getInstance();
- * RTFTransfer rtfTransfer = RTFTransfer.getInstance();
- * Transfer[] transfers = new Transfer[]{textTransfer, rtfTransfer};
- * Object[] data = new Object[]{textData, rtfData};
- * clipboard.setContents(data, transfers);
- * clipboard.dispose();
- * </code></pre>
- *
- * @param data the data to be set in the clipboard
- * @param dataTypes the transfer agents that will convert the data to its
- * platform specific format; each entry in the data array must have a
- * corresponding dataType
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if data is null or datatypes is null
- * or the length of data is not the same as the length of dataTypes</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_SET_CLIPBOARD - if the clipboard is locked or otherwise unavailable</li>
- * </ul>
- *
- * <p>NOTE: ERROR_CANNOT_SET_CLIPBOARD should be an SWTException, since it is a
- * recoverable error, but can not be changed due to backward compatibility.</p>
- */
-public void setContents(Object[] data, Transfer[] dataTypes) {
- setContents(data, dataTypes, DND.CLIPBOARD);
-}
-
-/**
- * Place data of the specified type on the specified clipboard. More than one
- * type of data can be placed on the specified clipboard at the same time.
- * Setting the data clears any previous data from the specified
- * clipboard, regardless of type.
- *
- * <p>NOTE: On some platforms, the data is immediately copied to the specified
- * clipboard but on other platforms it is provided upon request. As a result,
- * if the application modifies the data object it has set on the clipboard, that
- * modification may or may not be available when the data is subsequently
- * requested.</p>
- *
- * <p>The clipboards value is either one of the clipboard constants defined in
- * class <code>DND</code>, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>DND</code> clipboard constants.</p>
- *
- * <p>The following snippet shows text and RTF text being set on the copy/paste
- * clipboard:
- * </p>
- *
- * <code><pre>
- * Clipboard clipboard = new Clipboard(display);
- * String textData = "Hello World";
- * String rtfData = "{\\rtf1\\b\\i Hello World}";
- * TextTransfer textTransfer = TextTransfer.getInstance();
- * RTFTransfer rtfTransfer = RTFTransfer.getInstance();
- * Transfer[] transfers = new Transfer[]{textTransfer, rtfTransfer};
- * Object[] data = new Object[]{textData, rtfData};
- * clipboard.setContents(data, transfers, DND.CLIPBOARD);
- * clipboard.dispose();
- * </code></pre>
- *
- * @param data the data to be set in the clipboard
- * @param dataTypes the transfer agents that will convert the data to its
- * platform specific format; each entry in the data array must have a
- * corresponding dataType
- * @param clipboards on which to set the data
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if data is null or datatypes is null
- * or the length of data is not the same as the length of dataTypes</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_SET_CLIPBOARD - if the clipboard is locked or otherwise unavailable</li>
- * </ul>
- *
- * <p>NOTE: ERROR_CANNOT_SET_CLIPBOARD should be an SWTException, since it is a
- * recoverable error, but can not be changed due to backward compatibility.</p>
- *
- * @see DND#CLIPBOARD
- * @see DND#SELECTION_CLIPBOARD
- *
- * @since 3.1
- */
-public void setContents(Object[] data, Transfer[] dataTypes, int clipboards) {
- checkWidget();
- if (data == null || dataTypes == null || data.length != dataTypes.length || data.length == 0) {
- DND.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- for (int i = 0; i < data.length; i++) {
- if (data[i] == null || dataTypes[i] == null || !dataTypes[i].validate(data[i])) {
- DND.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- ClipboardProxy proxy = ClipboardProxy._getInstance(display);
- if (!proxy.setData(this, data, dataTypes, clipboards)) {
- DND.error(DND.ERROR_CANNOT_SET_CLIPBOARD);
- }
-}
-
-/**
- * Returns an array of the data types currently available on the system
- * clipboard. Use with Transfer.isSupportedType.
- *
- * @return array of data types currently available on the system clipboard
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Transfer#isSupportedType
- *
- * @since 3.0
- */
-public TransferData[] getAvailableTypes() {
- return getAvailableTypes(DND.CLIPBOARD);
-}
-
-/**
- * Returns an array of the data types currently available on the specified
- * clipboard. Use with Transfer.isSupportedType.
- *
- * <p>The clipboards value is either one of the clipboard constants defined in
- * class <code>DND</code>, or must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>DND</code> clipboard constants.</p>
- *
- * @param clipboards from which to get the data types
- * @return array of data types currently available on the specified clipboard
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Transfer#isSupportedType
- * @see DND#CLIPBOARD
- * @see DND#SELECTION_CLIPBOARD
- *
- * @since 3.1
- */
-public TransferData[] getAvailableTypes(int clipboards) {
- checkWidget();
- TransferData[] result = null;
- if ((clipboards & DND.CLIPBOARD) != 0) {
- int[] types = getAvailableClipboardTypes();
- result = new TransferData[types.length];
- for (int i = 0; i < types.length; i++) {
- result[i] = new TransferData();
- result[i].type = types[i];
- }
- }
- if ((clipboards & DND.SELECTION_CLIPBOARD) != 0) {
- int[] types = getAvailablePrimaryTypes();
- int offset = 0;
- if (result != null) {
- TransferData[] newResult = new TransferData[result.length + types.length];
- System.arraycopy(result,0, newResult, 0, result.length);
- offset = result.length;
- result = newResult;
- } else {
- result = new TransferData[types.length];
- }
- for (int i = 0; i < types.length; i++) {
- result[offset+i] = new TransferData();
- result[offset+i].type = types[i];
- }
- }
- return result == null ? new TransferData[0] : result;
-}
-
-/**
- * Returns a platform specific list of the data types currently available on the
- * system clipboard.
- *
- * <p>Note: <code>getAvailableTypeNames</code> is a utility for writing a Transfer
- * sub-class. It should NOT be used within an application because it provides
- * platform specific information.</p>
- *
- * @return a platform specific list of the data types currently available on the
- * system clipboard
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public String[] getAvailableTypeNames() {
- checkWidget();
- int[] types1 = getAvailableClipboardTypes();
- int[] types2 = getAvailablePrimaryTypes();
- String[] result = new String[types1.length + types2.length];
- int count = 0;
- for (int i = 0; i < types1.length; i++) {
- int /*long*/ pName = OS.gdk_atom_name(types1[i]);
- if (pName == 0) {
- continue;
- }
- byte[] buffer = new byte [OS.strlen(pName)];
- OS.memmove (buffer, pName, buffer.length);
- OS.g_free (pName);
- result[count++] = "GTKCLIPBOARD "+new String (Converter.mbcsToWcs (null, buffer));
- }
- for (int i = 0; i < types2.length; i++) {
- int /*long*/ pName = OS.gdk_atom_name(types2[i]);
- if (pName == 0) {
- continue;
- }
- byte[] buffer = new byte [OS.strlen(pName)];
- OS.memmove (buffer, pName, buffer.length);
- OS.g_free (pName);
- result[count++] = "GTKPRIMARYCLIPBOARD "+new String (Converter.mbcsToWcs (null, buffer));
- }
- if (count < result.length){
- String[] temp = new String[count];
- System.arraycopy(result, 0, temp, 0, count);
- result = temp;
- }
- return result;
-}
-
-private int[] getAvailablePrimaryTypes() {
- int[] types = new int[0];
- int /*long*/ selection_data = gtk_clipboard_wait_for_contents(GTKPRIMARYCLIPBOARD, TARGET);
- if (selection_data != 0) {
- try {
- GtkSelectionData gtkSelectionData = new GtkSelectionData();
- OS.memmove(gtkSelectionData, selection_data, GtkSelectionData.sizeof);
- if (gtkSelectionData.length != 0) {
- types = new int[gtkSelectionData.length * 8 / gtkSelectionData.format];
- OS.memmove(types, gtkSelectionData.data, gtkSelectionData.length);
- }
- } finally {
- OS.gtk_selection_data_free(selection_data);
- }
- }
- return types;
-}
-private int[] getAvailableClipboardTypes () {
- int[] types = new int[0];
- int /*long*/ selection_data = gtk_clipboard_wait_for_contents(GTKCLIPBOARD, TARGET);
- if (selection_data != 0) {
- try {
- GtkSelectionData gtkSelectionData = new GtkSelectionData();
- OS.memmove(gtkSelectionData, selection_data, GtkSelectionData.sizeof);
- if (gtkSelectionData.length != 0) {
- types = new int[gtkSelectionData.length * 8 / gtkSelectionData.format];
- OS.memmove(types, gtkSelectionData.data, gtkSelectionData.length);
- }
- } finally {
- OS.gtk_selection_data_free(selection_data);
- }
- }
- return types;
-}
-
-int /*long*/ gtk_clipboard_wait_for_contents(int /*long*/ clipboard, int /*long*/ target) {
- String key = "org.eclipse.swt.internal.gtk.dispatchEvent";
- Display display = this.display;
- display.setData(key, new int[]{OS.GDK_PROPERTY_NOTIFY, OS.GDK_SELECTION_CLEAR, OS.GDK_SELECTION_REQUEST, OS.GDK_SELECTION_NOTIFY});
- int /*long*/ selection_data = OS.gtk_clipboard_wait_for_contents(clipboard, target);
- display.setData(key, null);
- return selection_data;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ClipboardProxy.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ClipboardProxy.java
deleted file mode 100644
index 6e122cc0ed..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ClipboardProxy.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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 org.eclipse.swt.dnd;
-
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.internal.Callback;
-import org.eclipse.swt.internal.Converter;
-import org.eclipse.swt.internal.gtk.GtkSelectionData;
-import org.eclipse.swt.internal.gtk.GtkTargetEntry;
-import org.eclipse.swt.internal.gtk.OS;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-
-class ClipboardProxy {
- /* Data is not flushed to the clipboard immediately.
- * This class will remember the data and provide it when requested.
- */
- Object[] clipboardData;
- Transfer[] clipboardDataTypes;
- Object[] primaryClipboardData;
- Transfer[] primaryClipboardDataTypes;
-
- Display display;
- Clipboard activeClipboard = null;
- Clipboard activePrimaryClipboard = null;
- Callback getFunc;
- Callback clearFunc;
-
- static String ID = "CLIPBOARD PROXY OBJECT"; //$NON-NLS-1$
-
-static ClipboardProxy _getInstance(final Display display) {
- ClipboardProxy proxy = (ClipboardProxy) display.getData(ID);
- if (proxy != null) return proxy;
- proxy = new ClipboardProxy(display);
- display.setData(ID, proxy);
- display.addListener(SWT.Dispose, new Listener() {
- public void handleEvent(Event event) {
- ClipboardProxy clipbordProxy = (ClipboardProxy)display.getData(ID);
- if (clipbordProxy == null) return;
- display.setData(ID, null);
- clipbordProxy.dispose();
- }
- });
- return proxy;
-}
-
-ClipboardProxy(Display display) {
- this.display = display;
- getFunc = new Callback( this, "getFunc", 4); //$NON-NLS-1$
- if (getFunc.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- clearFunc = new Callback( this, "clearFunc", 2); //$NON-NLS-1$
- if (clearFunc.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
-}
-
-void clear (Clipboard owner, int clipboards) {
- if ((clipboards & DND.CLIPBOARD) != 0 && activeClipboard == owner) {
- OS.gtk_clipboard_clear(Clipboard.GTKCLIPBOARD);
- }
- if ((clipboards & DND.SELECTION_CLIPBOARD) != 0 && activePrimaryClipboard == owner) {
- OS.gtk_clipboard_clear(Clipboard.GTKPRIMARYCLIPBOARD);
- }
-}
-
-int /*long*/ clearFunc(int /*long*/ clipboard,int /*long*/ user_data_or_owner){
- if (clipboard == Clipboard.GTKCLIPBOARD) {
- activeClipboard = null;
- clipboardData = null;
- clipboardDataTypes = null;
- }
- if (clipboard == Clipboard.GTKPRIMARYCLIPBOARD) {
- activePrimaryClipboard = null;
- primaryClipboardData = null;
- primaryClipboardDataTypes = null;
- }
- return 1;
-}
-
-void dispose () {
- if (display == null) return;
- if (activeClipboard != null) OS.gtk_clipboard_clear(Clipboard.GTKCLIPBOARD);
- if (activePrimaryClipboard != null) OS.gtk_clipboard_clear(Clipboard.GTKPRIMARYCLIPBOARD);
- display = null;
- if (getFunc != null ) getFunc.dispose();
- getFunc = null;
- if (clearFunc != null) clearFunc.dispose();
- clearFunc = null;
- clipboardData = null;
- clipboardDataTypes = null;
- primaryClipboardData = null;
- primaryClipboardDataTypes = null;
-}
-
-/**
- * This function provides the data to the clipboard on request.
- * When this clipboard is disposed, the data will no longer be available.
- */
-int /*long*/ getFunc(int /*long*/ clipboard, int /*long*/ selection_data, int /*long*/ info, int /*long*/ user_data_or_owner){
- if (selection_data == 0) return 0;
- GtkSelectionData selectionData = new GtkSelectionData();
- OS.memmove(selectionData, selection_data, GtkSelectionData.sizeof);
- TransferData tdata = new TransferData();
- tdata.type = selectionData.target;
- Transfer[] types = (clipboard == Clipboard.GTKCLIPBOARD) ? clipboardDataTypes : primaryClipboardDataTypes;
- int index = -1;
- for (int i = 0; i < types.length; i++) {
- if (types[i].isSupportedType(tdata)) {
- index = i;
- break;
- }
- }
- if (index == -1) return 0;
- Object[] data = (clipboard == Clipboard.GTKCLIPBOARD) ? clipboardData : primaryClipboardData;
- types[index].javaToNative(data[index], tdata);
- if (tdata.format < 8 || tdata.format % 8 != 0) {
- return 0;
- }
- OS.gtk_selection_data_set(selection_data, tdata.type, tdata.format, tdata.pValue, tdata.length);
- OS.g_free(tdata.pValue);
- return 1;
-}
-
-boolean setData(Clipboard owner, Object[] data, Transfer[] dataTypes, int clipboards) {
- GtkTargetEntry[] entries = new GtkTargetEntry [0];
- int /*long*/ pTargetsList = 0;
- try {
- for (int i = 0; i < dataTypes.length; i++) {
- Transfer transfer = dataTypes[i];
- int[] typeIds = transfer.getTypeIds();
- String[] typeNames = transfer.getTypeNames();
- for (int j = 0; j < typeIds.length; j++) {
- GtkTargetEntry entry = new GtkTargetEntry();
- entry.info = typeIds[j];
- byte[] buffer = Converter.wcsToMbcs(null, typeNames[j], true);
- int /*long*/ pName = OS.g_malloc(buffer.length);
- OS.memmove(pName, buffer, buffer.length);
- entry.target = pName;
- GtkTargetEntry[] tmp = new GtkTargetEntry [entries.length + 1];
- System.arraycopy(entries, 0, tmp, 0, entries.length);
- tmp[entries.length] = entry;
- entries = tmp;
- }
- }
-
- pTargetsList = OS.g_malloc(GtkTargetEntry.sizeof * entries.length);
- int offset = 0;
- for (int i = 0; i < entries.length; i++) {
- OS.memmove(pTargetsList + offset, entries[i], GtkTargetEntry.sizeof);
- offset += GtkTargetEntry.sizeof;
- }
- if ((clipboards & DND.CLIPBOARD) != 0) {
- if (activeClipboard != null) OS.gtk_clipboard_clear(Clipboard.GTKCLIPBOARD);
- clipboardData = data;
- clipboardDataTypes = dataTypes;
- int /*long*/ getFuncProc = getFunc.getAddress();
- int /*long*/ clearFuncProc = clearFunc.getAddress();
- if (!OS.gtk_clipboard_set_with_data(Clipboard.GTKCLIPBOARD, pTargetsList, entries.length, getFuncProc, clearFuncProc, 0)) {
- return false;
- }
- activeClipboard = owner;
- }
- if ((clipboards & DND.SELECTION_CLIPBOARD) != 0) {
- if (activePrimaryClipboard != null) OS.gtk_clipboard_clear(Clipboard.GTKPRIMARYCLIPBOARD);
- primaryClipboardData = data;
- primaryClipboardDataTypes = dataTypes;
- int /*long*/ getFuncProc = getFunc.getAddress();
- int /*long*/ clearFuncProc = clearFunc.getAddress();
- if (!OS.gtk_clipboard_set_with_data(Clipboard.GTKPRIMARYCLIPBOARD, pTargetsList, entries.length, getFuncProc, clearFuncProc, 0)) {
- return false;
- }
- activePrimaryClipboard = owner;
- }
- return true;
- } finally {
- for (int i = 0; i < entries.length; i++) {
- GtkTargetEntry entry = entries[i];
- if( entry.target != 0) OS.g_free(entry.target);
- }
- if (pTargetsList != 0) OS.g_free(pTargetsList);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java
deleted file mode 100644
index 3874254e25..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DragSource.java
+++ /dev/null
@@ -1,633 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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 org.eclipse.swt.dnd;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- *
- * <code>DragSource</code> defines the source object for a drag and drop transfer.
- *
- * <p>IMPORTANT: This class is <em>not</em> intended to be subclassed.</p>
- *
- * <p>A drag source is the object which originates a drag and drop operation. For the specified widget,
- * it defines the type of data that is available for dragging and the set of operations that can
- * be performed on that data. The operations can be any bit-wise combination of DND.MOVE, DND.COPY or
- * DND.LINK. The type of data that can be transferred is specified by subclasses of Transfer such as
- * TextTransfer or FileTransfer. The type of data transferred can be a predefined system type or it
- * can be a type defined by the application. For instructions on how to define your own transfer type,
- * refer to <code>ByteArrayTransfer</code>.</p>
- *
- * <p>You may have several DragSources in an application but you can only have one DragSource
- * per Control. Data dragged from this DragSource can be dropped on a site within this application
- * or it can be dropped on another application such as an external Text editor.</p>
- *
- * <p>The application supplies the content of the data being transferred by implementing the
- * <code>DragSourceListener</code> and associating it with the DragSource via DragSource#addDragListener.</p>
- *
- * <p>When a successful move operation occurs, the application is required to take the appropriate
- * action to remove the data from its display and remove any associated operating system resources or
- * internal references. Typically in a move operation, the drop target makes a copy of the data
- * and the drag source deletes the original. However, sometimes copying the data can take a long
- * time (such as copying a large file). Therefore, on some platforms, the drop target may actually
- * move the data in the operating system rather than make a copy. This is usually only done in
- * file transfers. In this case, the drag source is informed in the DragEnd event that a
- * DROP_TARGET_MOVE was performed. It is the responsibility of the drag source at this point to clean
- * up its displayed information. No action needs to be taken on the operating system resources.</p>
- *
- * <p> The following example shows a Label widget that allows text to be dragged from it.</p>
- *
- * <code><pre>
- * // Enable a label as a Drag Source
- * Label label = new Label(shell, SWT.NONE);
- * // This example will allow text to be dragged
- * Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
- * // This example will allow the text to be copied or moved to the drop target
- * int operations = DND.DROP_MOVE | DND.DROP_COPY;
- *
- * DragSource source = new DragSource(label, operations);
- * source.setTransfer(types);
- * source.addDragListener(new DragSourceListener() {
- * public void dragStart(DragSourceEvent e) {
- * // Only start the drag if there is actually text in the
- * // label - this text will be what is dropped on the target.
- * if (label.getText().length() == 0) {
- * event.doit = false;
- * }
- * };
- * public void dragSetData(DragSourceEvent event) {
- * // A drop has been performed, so provide the data of the
- * // requested type.
- * // (Checking the type of the requested data is only
- * // necessary if the drag source supports more than
- * // one data type but is shown here as an example).
- * if (TextTransfer.getInstance().isSupportedType(event.dataType)){
- * event.data = label.getText();
- * }
- * }
- * public void dragFinished(DragSourceEvent event) {
- * // A Move operation has been performed so remove the data
- * // from the source
- * if (event.detail == DND.DROP_MOVE)
- * label.setText("");
- * }
- * });
- * </pre></code>
- *
- *
- * <dl>
- * <dt><b>Styles</b></dt> <dd>DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK</dd>
- * <dt><b>Events</b></dt> <dd>DND.DragStart, DND.DragSetData, DND.DragEnd</dd>
- * </dl>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: DNDExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DragSource extends Widget {
-
- // info for registering as a drag source
- Control control;
- Listener controlListener;
- Transfer[] transferAgents = new Transfer[0];
- DragSourceEffect dragEffect;
-
- int /*long*/ targetList;
-
- //workaround - remember action performed for DragEnd
- boolean moveData = false;
-
- static final String DEFAULT_DRAG_SOURCE_EFFECT = "DEFAULT_DRAG_SOURCE_EFFECT"; //$NON-NLS-1$
-
- static Callback DragGetData;
- static Callback DragEnd;
- static Callback DragDataDelete;
- static {
- DragGetData = new Callback(DragSource.class, "DragGetData", 5); //$NON-NLS-1$
- if (DragGetData.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- DragEnd = new Callback(DragSource.class, "DragEnd", 2); //$NON-NLS-1$
- if (DragEnd.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- DragDataDelete = new Callback(DragSource.class, "DragDataDelete", 2); //$NON-NLS-1$
- if (DragDataDelete.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- }
-
-/**
- * Creates a new <code>DragSource</code> to handle dragging from the specified <code>Control</code>.
- * Creating an instance of a DragSource may cause system resources to be allocated depending on the platform.
- * It is therefore mandatory that the DragSource instance be disposed when no longer required.
- *
- * @param control the <code>Control</code> that the user clicks on to initiate the drag
- * @param style the bitwise OR'ing of allowed operations; this may be a combination of any of
- * DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_INIT_DRAG - unable to initiate drag source; this will occur if more than one
- * drag source is created for a control or if the operating system will not allow the creation
- * of the drag source</li>
- * </ul>
- *
- * <p>NOTE: ERROR_CANNOT_INIT_DRAG should be an SWTException, since it is a
- * recoverable error, but can not be changed due to backward compatibility.</p>
- *
- * @see Widget#dispose
- * @see DragSource#checkSubclass
- * @see DND#DROP_NONE
- * @see DND#DROP_COPY
- * @see DND#DROP_MOVE
- * @see DND#DROP_LINK
- */
-public DragSource(Control control, int style) {
- super (control, checkStyle(style));
- this.control = control;
- if (DragGetData == null || DragEnd == null || DragDataDelete == null) {
- DND.error(DND.ERROR_CANNOT_INIT_DRAG);
- }
- if (control.getData(DND.DRAG_SOURCE_KEY) != null) {
- DND.error(DND.ERROR_CANNOT_INIT_DRAG);
- }
- control.setData(DND.DRAG_SOURCE_KEY, this);
-
- OS.g_signal_connect(control.handle, OS.drag_data_get, DragGetData.getAddress(), 0);
- OS.g_signal_connect(control.handle, OS.drag_end, DragEnd.getAddress(), 0);
- OS.g_signal_connect(control.handle, OS.drag_data_delete, DragDataDelete.getAddress(), 0);
-
- controlListener = new Listener () {
- public void handleEvent (Event event) {
- if (event.type == SWT.Dispose) {
- if (!DragSource.this.isDisposed()) {
- DragSource.this.dispose();
- }
- }
- if (event.type == SWT.DragDetect) {
- if (!DragSource.this.isDisposed()) {
- DragSource.this.drag(event);
- }
- }
- }
- };
- control.addListener (SWT.Dispose, controlListener);
- control.addListener (SWT.DragDetect, controlListener);
-
- Object effect = control.getData(DEFAULT_DRAG_SOURCE_EFFECT);
- if (effect instanceof DragSourceEffect) {
- dragEffect = (DragSourceEffect) effect;
- } else if (control instanceof Tree) {
- dragEffect = new TreeDragSourceEffect((Tree) control);
- } else if (control instanceof Table) {
- dragEffect = new TableDragSourceEffect((Table) control);
- }
-
- this.addListener(SWT.Dispose, new Listener() {
- public void handleEvent(Event e) {
- onDispose();
- }
- });
-}
-
-static int checkStyle (int style) {
- if (style == SWT.NONE) return DND.DROP_MOVE;
- return style;
-}
-
-static int /*long*/ DragDataDelete(int /*long*/ widget, int /*long*/ context){
- DragSource source = FindDragSource(widget);
- if (source == null) return 0;
- source.dragDataDelete(widget, context);
- return 0;
-}
-
-static int /*long*/ DragEnd(int /*long*/ widget, int /*long*/ context){
- DragSource source = FindDragSource(widget);
- if (source == null) return 0;
- source.dragEnd(widget, context);
- return 0;
-}
-
-static int /*long*/ DragGetData(int /*long*/ widget, int /*long*/ context, int /*long*/ selection_data, int /*long*/ info, int /*long*/ time){
- DragSource source = FindDragSource(widget);
- if (source == null) return 0;
- source.dragGetData(widget, context, selection_data, (int)/*64*/info, (int)/*64*/time);
- return 0;
-}
-
-static DragSource FindDragSource(int /*long*/ handle) {
- Display display = Display.findDisplay(Thread.currentThread());
- if (display == null || display.isDisposed()) return null;
- Widget widget = display.findWidget(handle);
- if (widget == null) return null;
- return (DragSource)widget.getData(DND.DRAG_SOURCE_KEY);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when a drag and drop operation is in progress, by sending
- * it one of the messages defined in the <code>DragSourceListener</code>
- * interface.
- *
- * <p><ul>
- * <li><code>dragStart</code> is called when the user has begun the actions required to drag the widget.
- * This event gives the application the chance to decide if a drag should be started.
- * <li><code>dragSetData</code> is called when the data is required from the drag source.
- * <li><code>dragFinished</code> is called when the drop has successfully completed (mouse up
- * over a valid target) or has been terminated (such as hitting the ESC key). Perform cleanup
- * such as removing data from the source side on a successful move operation.
- * </ul></p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragSourceListener
- * @see #getDragListeners
- * @see #removeDragListener
- * @see DragSourceEvent
- */
-public void addDragListener(DragSourceListener listener) {
- if (listener == null) DND.error (SWT.ERROR_NULL_ARGUMENT);
- DNDListener typedListener = new DNDListener (listener);
- typedListener.dndWidget = this;
- addListener (DND.DragStart, typedListener);
- addListener (DND.DragSetData, typedListener);
- addListener (DND.DragEnd, typedListener);
-}
-
-protected void checkSubclass () {
- String name = getClass().getName ();
- String validName = DragSource.class.getName();
- if (!validName.equals(name)) {
- DND.error (SWT.ERROR_INVALID_SUBCLASS);
- }
-}
-
-void drag(Event dragEvent) {
- moveData = false;
- DNDEvent event = new DNDEvent();
- event.widget = this;
- event.x = dragEvent.x;
- event.y = dragEvent.y;
- event.time = dragEvent.time;
- event.doit = true;
- notifyListeners(DND.DragStart, event);
- if (!event.doit || transferAgents == null || transferAgents.length == 0) return;
- if (targetList == 0) return;
-
- int actions = opToOsOp(getStyle());
- Image image = event.image;
- int /*long*/ context = OS.gtk_drag_begin(control.handle, targetList, actions, 1, 0);
- if (context != 0 && image != null) {
- int /*long*/ pixbuf = createPixbuf(image);
- OS.gtk_drag_set_icon_pixbuf(context, pixbuf, 0, 0);
- OS.g_object_unref(pixbuf);
- }
-}
-
-void dragEnd(int /*long*/ widget, int /*long*/ context){
- /*
- * Bug in GTK. If a drag is initiated using gtk_drag_begin and the
- * mouse is released immediately, the mouse and keyboard remain
- * grabbed. The fix is to release the grab on the mouse and keyboard
- * whenever the drag is terminated.
- *
- * NOTE: We believe that it is never an error to ungrab when
- * a drag is finished.
- */
- OS.gdk_pointer_ungrab(OS.GDK_CURRENT_TIME);
- OS.gdk_keyboard_ungrab(OS.GDK_CURRENT_TIME);
-
- int operation = DND.DROP_NONE;
- if (context != 0) {
- GdkDragContext gdkDragContext = new GdkDragContext ();
- OS.memmove(gdkDragContext, context, GdkDragContext.sizeof);
- if (gdkDragContext.dest_window != 0) { //NOTE: if dest_window is 0, drag was aborted
- if (moveData) {
- operation = DND.DROP_MOVE;
- } else {
- operation = osOpToOp(gdkDragContext.action);
- if (operation == DND.DROP_MOVE) operation = DND.DROP_NONE;
- }
- }
- }
-
- DNDEvent event = new DNDEvent();
- event.widget = this;
- //event.time = ???
- event.doit = operation != 0;
- event.detail = operation;
- notifyListeners(DND.DragEnd, event);
- moveData = false;
-}
-
-void dragGetData(int /*long*/ widget, int /*long*/ context, int /*long*/ selection_data, int info, int time){
- if (selection_data == 0) return;
- GtkSelectionData gtkSelectionData = new GtkSelectionData();
- OS.memmove(gtkSelectionData, selection_data, GtkSelectionData.sizeof);
- if (gtkSelectionData.target == 0) return;
-
- TransferData transferData = new TransferData();
- transferData.type = gtkSelectionData.target;
- transferData.pValue = gtkSelectionData.data;
- transferData.length = gtkSelectionData.length;
- transferData.format = gtkSelectionData.format;
-
- DNDEvent event = new DNDEvent();
- event.widget = this;
- event.time = time;
- event.dataType = transferData;
- notifyListeners(DND.DragSetData, event);
-
- if (!event.doit) return;
- Transfer transfer = null;
- for (int i = 0; i < transferAgents.length; i++) {
- Transfer transferAgent = transferAgents[i];
- if (transferAgent != null && transferAgent.isSupportedType(transferData)) {
- transfer = transferAgent;
- break;
- }
- }
- if (transfer == null) return;
- transfer.javaToNative(event.data, transferData);
- if (transferData.result != 1) return;
- OS.gtk_selection_data_set(selection_data, transferData.type, transferData.format, transferData.pValue, transferData.length);
- OS.g_free(transferData.pValue);
- return;
-}
-
-void dragDataDelete(int /*long*/ widget, int /*long*/ context){
- moveData = true;
-}
-
-/**
- * Returns the Control which is registered for this DragSource. This is the control that the
- * user clicks in to initiate dragging.
- *
- * @return the Control which is registered for this DragSource
- */
-public Control getControl () {
- return control;
-}
-
-/**
- * Returns an array of listeners who will be notified when a drag and drop
- * operation is in progress, by sending it one of the messages defined in
- * the <code>DragSourceListener</code> interface.
- *
- * @return the listeners who will be notified when a drag and drop
- * operation is in progress
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragSourceListener
- * @see #addDragListener
- * @see #removeDragListener
- * @see DragSourceEvent
- *
- * @since 3.4
- */
-public DragSourceListener[] getDragListeners() {
- Listener[] listeners = getListeners(DND.DragStart);
- int length = listeners.length;
- DragSourceListener[] dragListeners = new DragSourceListener[length];
- int count = 0;
- for (int i = 0; i < length; i++) {
- Listener listener = listeners[i];
- if (listener instanceof DNDListener) {
- dragListeners[count] = (DragSourceListener) ((DNDListener) listener).getEventListener();
- count++;
- }
- }
- if (count == length) return dragListeners;
- DragSourceListener[] result = new DragSourceListener[count];
- System.arraycopy(dragListeners, 0, result, 0, count);
- return result;
-}
-
-/**
- * Returns the drag effect that is registered for this DragSource. This drag
- * effect will be used during a drag and drop operation.
- *
- * @return the drag effect that is registered for this DragSource
- *
- * @since 3.3
- */
-public DragSourceEffect getDragSourceEffect() {
- return dragEffect;
-}
-
-/**
- * Returns the list of data types that can be transferred by this DragSource.
- *
- * @return the list of data types that can be transferred by this DragSource
- */
-public Transfer[] getTransfer(){
- return transferAgents;
-}
-
-void onDispose() {
- if (control == null) return;
- if (targetList != 0) {
- OS.gtk_target_list_unref(targetList);
- }
- targetList = 0;
- if (controlListener != null) {
- control.removeListener(SWT.Dispose, controlListener);
- control.removeListener(SWT.DragDetect, controlListener);
- }
- controlListener = null;
- control.setData(DND.DRAG_SOURCE_KEY, null);
- control = null;
- transferAgents = null;
-}
-
-int opToOsOp(int operation){
- int osOperation = 0;
-
- if ((operation & DND.DROP_COPY) == DND.DROP_COPY)
- osOperation |= OS.GDK_ACTION_COPY;
- if ((operation & DND.DROP_MOVE) == DND.DROP_MOVE)
- osOperation |= OS.GDK_ACTION_MOVE;
- if ((operation & DND.DROP_LINK) == DND.DROP_LINK)
- osOperation |= OS.GDK_ACTION_LINK;
-
- return osOperation;
-}
-
-int osOpToOp(int osOperation){
- int operation = DND.DROP_NONE;
-
- if ((osOperation & OS.GDK_ACTION_COPY) == OS.GDK_ACTION_COPY)
- operation |= DND.DROP_COPY;
- if ((osOperation & OS.GDK_ACTION_MOVE) == OS.GDK_ACTION_MOVE)
- operation |= DND.DROP_MOVE;
- if ((osOperation & OS.GDK_ACTION_LINK) == OS.GDK_ACTION_LINK)
- operation |= DND.DROP_LINK;
-
- return operation;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when a drag and drop operation is in progress.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DragSourceListener
- * @see #addDragListener
- * @see #getDragListeners
- */
-public void removeDragListener(DragSourceListener listener) {
- if (listener == null) DND.error (SWT.ERROR_NULL_ARGUMENT);
- removeListener (DND.DragStart, listener);
- removeListener (DND.DragSetData, listener);
- removeListener (DND.DragEnd, listener);
-}
-
-/**
- * Specifies the drag effect for this DragSource. This drag effect will be
- * used during a drag and drop operation.
- *
- * @param effect the drag effect that is registered for this DragSource
- *
- * @since 3.3
- */
-public void setDragSourceEffect(DragSourceEffect effect) {
- dragEffect = effect;
-}
-
-/**
- * Specifies the list of data types that can be transferred by this DragSource.
- * The application must be able to provide data to match each of these types when
- * a successful drop has occurred.
- *
- * @param transferAgents a list of Transfer objects which define the types of data that can be
- * dragged from this source
- */
-public void setTransfer(Transfer[] transferAgents){
- if (targetList != 0) {
- OS.gtk_target_list_unref(targetList);
- targetList = 0;
- }
- this.transferAgents = transferAgents;
- if (transferAgents == null || transferAgents.length == 0) return;
-
- GtkTargetEntry[] targets = new GtkTargetEntry[0];
- for (int i = 0; i < transferAgents.length; i++) {
- Transfer transfer = transferAgents[i];
- if (transfer != null) {
- int[] typeIds = transfer.getTypeIds();
- String[] typeNames = transfer.getTypeNames();
- for (int j = 0; j < typeIds.length; j++) {
- GtkTargetEntry entry = new GtkTargetEntry();
- byte[] buffer = Converter.wcsToMbcs(null, typeNames[j], true);
- entry.target = OS.g_malloc(buffer.length);
- OS.memmove(entry.target, buffer, buffer.length);
- entry.info = typeIds[j];
- GtkTargetEntry[] newTargets = new GtkTargetEntry[targets.length + 1];
- System.arraycopy(targets, 0, newTargets, 0, targets.length);
- newTargets[targets.length] = entry;
- targets = newTargets;
- }
- }
- }
-
- int /*long*/ pTargets = OS.g_malloc(targets.length * GtkTargetEntry.sizeof);
- for (int i = 0; i < targets.length; i++) {
- OS.memmove(pTargets + i*GtkTargetEntry.sizeof, targets[i], GtkTargetEntry.sizeof);
- }
- targetList = OS.gtk_target_list_new(pTargets, targets.length);
-
- for (int i = 0; i < targets.length; i++) {
- OS.g_free(targets[i].target);
- }
-}
-
-static int /*long*/ createPixbuf(Image image) {
- int [] w = new int [1], h = new int [1];
- OS.gdk_drawable_get_size (image.pixmap, w, h);
- int /*long*/ colormap = OS.gdk_colormap_get_system ();
- int /*long*/ pixbuf;
- boolean hasMask = image.mask != 0 && OS.gdk_drawable_get_depth (image.mask) == 1;
- if (hasMask) {
- pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w [0], h [0]);
- if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]);
- int /*long*/ maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, w [0], h [0]);
- if (maskPixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.gdk_pixbuf_get_from_drawable(maskPixbuf, image.mask, 0, 0, 0, 0, 0, w [0], h [0]);
- int stride = OS.gdk_pixbuf_get_rowstride(pixbuf);
- int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf);
- byte[] line = new byte[stride];
- int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf);
- int /*long*/ maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf);
- byte[] maskLine = new byte[maskStride];
- for (int y=0; y<h[0]; y++) {
- int /*long*/ offset = pixels + (y * stride);
- OS.memmove(line, offset, stride);
- int /*long*/ maskOffset = maskPixels + (y * maskStride);
- OS.memmove(maskLine, maskOffset, maskStride);
- for (int x=0; x<w[0]; x++) {
- if (maskLine[x * 3] == 0) {
- line[x * 4 + 3] = 0;
- }
- }
- OS.memmove(offset, line, stride);
- }
- OS.g_object_unref(maskPixbuf);
- } else {
- ImageData data = image.getImageData ();
- boolean hasAlpha = data.getTransparencyType () == SWT.TRANSPARENCY_ALPHA;
- pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, hasAlpha, 8, w [0], h [0]);
- if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]);
- if (hasAlpha) {
- byte [] alpha = data.alphaData;
- int stride = OS.gdk_pixbuf_get_rowstride (pixbuf);
- int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf);
- byte [] line = new byte [stride];
- for (int y = 0; y < h [0]; y++) {
- int /*long*/ offset = pixels + (y * stride);
- OS.memmove (line, offset, stride);
- for (int x = 0; x < w [0]; x++) {
- line [x*4+3] = alpha [y*w [0]+x];
- }
- OS.memmove (offset, line, stride);
- }
- }
- }
- return pixbuf;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DropTarget.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DropTarget.java
deleted file mode 100644
index c9cc25ade2..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DropTarget.java
+++ /dev/null
@@ -1,812 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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 org.eclipse.swt.dnd;
-
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- *
- * Class <code>DropTarget</code> defines the target object for a drag and drop transfer.
- *
- * <p>IMPORTANT: This class is <em>not</em> intended to be subclassed.</p>
- *
- * <p>This class identifies the <code>Control</code> over which the user must position the cursor
- * in order to drop the data being transferred. It also specifies what data types can be dropped on
- * this control and what operations can be performed. You may have several DropTragets in an
- * application but there can only be a one to one mapping between a <code>Control</code> and a <code>DropTarget</code>.
- * The DropTarget can receive data from within the same application or from other applications
- * (such as text dragged from a text editor like Word).</p>
- *
- * <code><pre>
- * int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;
- * Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
- * DropTarget target = new DropTarget(label, operations);
- * target.setTransfer(types);
- * </code></pre>
- *
- * <p>The application is notified of data being dragged over this control and of when a drop occurs by
- * implementing the interface <code>DropTargetListener</code> which uses the class
- * <code>DropTargetEvent</code>. The application can modify the type of drag being performed
- * on this Control at any stage of the drag by modifying the <code>event.detail</code> field or the
- * <code>event.currentDataType</code> field. When the data is dropped, it is the responsibility of
- * the application to copy this data for its own purposes.
- *
- * <code><pre>
- * target.addDropListener (new DropTargetListener() {
- * public void dragEnter(DropTargetEvent event) {};
- * public void dragOver(DropTargetEvent event) {};
- * public void dragLeave(DropTargetEvent event) {};
- * public void dragOperationChanged(DropTargetEvent event) {};
- * public void dropAccept(DropTargetEvent event) {}
- * public void drop(DropTargetEvent event) {
- * // A drop has occurred, copy over the data
- * if (event.data == null) { // no data to copy, indicate failure in event.detail
- * event.detail = DND.DROP_NONE;
- * return;
- * }
- * label.setText ((String) event.data); // data copied to label text
- * }
- * });
- * </pre></code>
- *
- * <dl>
- * <dt><b>Styles</b></dt> <dd>DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK</dd>
- * <dt><b>Events</b></dt> <dd>DND.DragEnter, DND.DragLeave, DND.DragOver, DND.DragOperationChanged,
- * DND.DropAccept, DND.Drop </dd>
- * </dl>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: DNDExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class DropTarget extends Widget {
-
- Control control;
- Listener controlListener;
- Transfer[] transferAgents = new Transfer[0];
- DropTargetEffect dropEffect;
-
- // Track application selections
- TransferData selectedDataType;
- int selectedOperation;
-
- // workaround - There is no event for "operation changed" so track operation based on key state
- int keyOperation = -1;
-
- // workaround - Simulate events when the mouse is not moving
- long dragOverStart;
- Runnable dragOverHeartbeat;
- DNDEvent dragOverEvent;
-
- int drag_motion_handler;
- int drag_leave_handler;
- int drag_data_received_handler;
- int drag_drop_handler;
-
- static final String DEFAULT_DROP_TARGET_EFFECT = "DEFAULT_DROP_TARGET_EFFECT"; //$NON-NLS-1$
- static final String IS_ACTIVE = "org.eclipse.swt.internal.control.isactive"; //$NON-NLS-1$
- static final int DRAGOVER_HYSTERESIS = 50;
-
- static Callback Drag_Motion;
- static Callback Drag_Leave;
- static Callback Drag_Data_Received;
- static Callback Drag_Drop;
-
- static {
- Drag_Motion = new Callback(DropTarget.class, "Drag_Motion", 5); //$NON-NLS-1$
- if (Drag_Motion.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- Drag_Leave = new Callback(DropTarget.class, "Drag_Leave", 3); //$NON-NLS-1$
- if (Drag_Leave.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- Drag_Data_Received = new Callback(DropTarget.class, "Drag_Data_Received", 7); //$NON-NLS-1$
- if (Drag_Data_Received.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- Drag_Drop = new Callback(DropTarget.class, "Drag_Drop", 5); //$NON-NLS-1$
- if (Drag_Drop.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS);
- }
-
-/**
- * Creates a new <code>DropTarget</code> to allow data to be dropped on the specified
- * <code>Control</code>.
- * Creating an instance of a DropTarget may cause system resources to be allocated
- * depending on the platform. It is therefore mandatory that the DropTarget instance
- * be disposed when no longer required.
- *
- * @param control the <code>Control</code> over which the user positions the cursor to drop the data
- * @param style the bitwise OR'ing of allowed operations; this may be a combination of any of
- * DND.DROP_NONE, DND.DROP_COPY, DND.DROP_MOVE, DND.DROP_LINK
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_INIT_DROP - unable to initiate drop target; this will occur if more than one
- * drop target is created for a control or if the operating system will not allow the creation
- * of the drop target</li>
- * </ul>
- *
- * <p>NOTE: ERROR_CANNOT_INIT_DROP should be an SWTException, since it is a
- * recoverable error, but can not be changed due to backward compatibility.</p>
- *
- * @see Widget#dispose
- * @see DropTarget#checkSubclass
- * @see DND#DROP_NONE
- * @see DND#DROP_COPY
- * @see DND#DROP_MOVE
- * @see DND#DROP_LINK
- */
-public DropTarget(Control control, int style) {
- super(control, checkStyle(style));
- this.control = control;
- if (Drag_Motion == null || Drag_Leave == null || Drag_Data_Received == null || Drag_Drop == null) {
- DND.error(DND.ERROR_CANNOT_INIT_DROP);
- }
- if (control.getData(DND.DROP_TARGET_KEY) != null) {
- DND.error(DND.ERROR_CANNOT_INIT_DROP);
- }
- control.setData(DND.DROP_TARGET_KEY, this);
-
- drag_motion_handler = OS.g_signal_connect(control.handle, OS.drag_motion, Drag_Motion.getAddress(), 0);
- drag_leave_handler = OS.g_signal_connect(control.handle, OS.drag_leave, Drag_Leave.getAddress(), 0);
- drag_data_received_handler = OS.g_signal_connect(control.handle, OS.drag_data_received, Drag_Data_Received.getAddress(), 0);
- drag_drop_handler = OS.g_signal_connect(control.handle, OS.drag_drop, Drag_Drop.getAddress(), 0);
-
- // Dispose listeners
- controlListener = new Listener(){
- public void handleEvent(Event event){
- if (!DropTarget.this.isDisposed()){
- DropTarget.this.dispose();
- }
- }
- };
- control.addListener(SWT.Dispose, controlListener);
-
- this.addListener(SWT.Dispose, new Listener(){
- public void handleEvent(Event event){
- onDispose();
- }
- });
-
- Object effect = control.getData(DEFAULT_DROP_TARGET_EFFECT);
- if (effect instanceof DropTargetEffect) {
- dropEffect = (DropTargetEffect) effect;
- } else if (control instanceof Table) {
- dropEffect = new TableDropTargetEffect((Table) control);
- } else if (control instanceof Tree) {
- dropEffect = new TreeDropTargetEffect((Tree) control);
- }
-
- dragOverHeartbeat = new Runnable() {
- public void run() {
- Control control = DropTarget.this.control;
- if (control == null || control.isDisposed() || dragOverStart == 0) return;
- long time = System.currentTimeMillis();
- int delay = DRAGOVER_HYSTERESIS;
- if (time < dragOverStart) {
- delay = (int)(dragOverStart - time);
- } else {
- dragOverEvent.time += DRAGOVER_HYSTERESIS;
- int allowedOperations = dragOverEvent.operations;
- TransferData[] allowedTypes = dragOverEvent.dataTypes;
- //pass a copy of data types in to listeners in case application modifies it
- TransferData[] dataTypes = new TransferData[allowedTypes.length];
- System.arraycopy(allowedTypes, 0, dataTypes, 0, dataTypes.length);
-
- DNDEvent event = new DNDEvent();
- event.widget = dragOverEvent.widget;
- event.x = dragOverEvent.x;
- event.y = dragOverEvent.y;
- event.time = dragOverEvent.time;
- event.feedback = DND.FEEDBACK_SELECT;
- event.dataTypes = dataTypes;
- event.dataType = selectedDataType;
- event.operations = dragOverEvent.operations;
- event.detail = selectedOperation;
- if (dropEffect != null) {
- event.item = dropEffect.getItem(dragOverEvent.x, dragOverEvent.y);
- }
- selectedDataType = null;
- selectedOperation = DND.DROP_NONE;
- notifyListeners(DND.DragOver, event);
- if (event.dataType != null) {
- for (int i = 0; i < allowedTypes.length; i++) {
- if (allowedTypes[i].type == event.dataType.type) {
- selectedDataType = event.dataType;
- break;
- }
- }
- }
- if (selectedDataType != null && (event.detail & allowedOperations) != 0) {
- selectedOperation = event.detail;
- }
- }
- control = DropTarget.this.control;
- if (control == null || control.isDisposed()) return;
- control.getDisplay().timerExec(delay, dragOverHeartbeat);
- }
- };
-}
-
-static int checkStyle (int style) {
- if (style == SWT.NONE) return DND.DROP_MOVE;
- return style;
-}
-
-static int /*long*/ Drag_Data_Received ( int /*long*/ widget, int /*long*/ context, int /*long*/ x, int /*long*/ y, int /*long*/ data, int /*long*/ info, int /*long*/ time){
- DropTarget target = FindDropTarget(widget);
- if (target == null) return 0;
- target.drag_data_received (widget, context, (int)/*64*/x, (int)/*64*/y, data, (int)/*64*/info, (int)/*64*/time);
- return 0;
-}
-
-static int /*long*/ Drag_Drop(int /*long*/ widget, int /*long*/ context, int /*long*/ x, int /*long*/ y, int /*long*/ time) {
- DropTarget target = FindDropTarget(widget);
- if (target == null) return 0;
- return target.drag_drop (widget, context, (int)/*64*/x, (int)/*64*/y, (int)/*64*/time) ? 1 : 0;
-}
-
-static int /*long*/ Drag_Leave ( int /*long*/ widget, int /*long*/ context, int /*long*/ time){
- DropTarget target = FindDropTarget(widget);
- if (target == null) return 0;
- target.drag_leave (widget, context, (int)/*64*/time);
- return 0;
-}
-
-static int /*long*/ Drag_Motion ( int /*long*/ widget, int /*long*/ context, int /*long*/ x, int /*long*/ y, int /*long*/ time){
- DropTarget target = FindDropTarget(widget);
- if (target == null) return 0;
- return target.drag_motion (widget, context, (int)/*64*/x, (int)/*64*/y, (int)/*64*/time) ? 1 : 0;
-}
-
-static DropTarget FindDropTarget(int /*long*/ handle) {
- Display display = Display.findDisplay(Thread.currentThread());
- if (display == null || display.isDisposed()) return null;
- Widget widget = display.findWidget(handle);
- if (widget == null) return null;
- return (DropTarget)widget.getData(DND.DROP_TARGET_KEY);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when a drag and drop operation is in progress, by sending
- * it one of the messages defined in the <code>DropTargetListener</code>
- * interface.
- *
- * <p><ul>
- * <li><code>dragEnter</code> is called when the cursor has entered the drop target boundaries
- * <li><code>dragLeave</code> is called when the cursor has left the drop target boundaries and just before
- * the drop occurs or is cancelled.
- * <li><code>dragOperationChanged</code> is called when the operation being performed has changed
- * (usually due to the user changing the selected modifier key(s) while dragging)
- * <li><code>dragOver</code> is called when the cursor is moving over the drop target
- * <li><code>dropAccept</code> is called just before the drop is performed. The drop target is given
- * the chance to change the nature of the drop or veto the drop by setting the <code>event.detail</code> field
- * <li><code>drop</code> is called when the data is being dropped
- * </ul></p>
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DropTargetListener
- * @see #getDropListeners
- * @see #removeDropListener
- * @see DropTargetEvent
- */
-public void addDropListener(DropTargetListener listener) {
- if (listener == null) DND.error (SWT.ERROR_NULL_ARGUMENT);
- DNDListener typedListener = new DNDListener (listener);
- typedListener.dndWidget = this;
- addListener (DND.DragEnter, typedListener);
- addListener (DND.DragLeave, typedListener);
- addListener (DND.DragOver, typedListener);
- addListener (DND.DragOperationChanged, typedListener);
- addListener (DND.Drop, typedListener);
- addListener (DND.DropAccept, typedListener);
-}
-
-protected void checkSubclass () {
- String name = getClass().getName ();
- String validName = DropTarget.class.getName();
- if (!validName.equals(name)) {
- DND.error (SWT.ERROR_INVALID_SUBCLASS);
- }
-}
-
-void drag_data_received ( int /*long*/ widget, int /*long*/ context, int x, int y, int /*long*/ data, int info, int time){
- DNDEvent event = new DNDEvent();
- if (data == 0 || !setEventData(context, x, y, time, event)) {
- keyOperation = -1;
- return;
- }
- keyOperation = -1;
-
- int allowedOperations = event.operations;
-
- // Get data in a Java format
- Object object = null;
- TransferData transferData = new TransferData();
- GtkSelectionData selectionData = new GtkSelectionData();
- OS.memmove(selectionData, data, GtkSelectionData.sizeof);
- if (selectionData.data != 0) {
- transferData.type = selectionData.type;
- transferData.length = selectionData.length;
- transferData.pValue = selectionData.data;
- transferData.format = selectionData.format;
- for (int i = 0; i < transferAgents.length; i++) {
- Transfer transfer = transferAgents[i];
- if (transfer != null && transfer.isSupportedType(transferData)) {
- object = transfer.nativeToJava(transferData);
- break;
- }
- }
- }
- if (object == null) {
- selectedOperation = DND.DROP_NONE;
- }
-
- event.detail = selectedOperation;
- event.dataType = transferData;
- event.data = object;
- selectedOperation = DND.DROP_NONE;
- notifyListeners(DND.Drop, event);
- if ((allowedOperations & event.detail) == event.detail) {
- selectedOperation = event.detail;
- }
- //stop native handler
- OS.g_signal_stop_emission_by_name(widget, OS.drag_data_received);
-
- //notify source of action taken
- OS.gtk_drag_finish(context, selectedOperation != DND.DROP_NONE, selectedOperation== DND.DROP_MOVE, time);
- return;
-}
-
-boolean drag_drop(int /*long*/ widget, int /*long*/ context, int x, int y, int time) {
- DNDEvent event = new DNDEvent();
- if (!setEventData(context, x, y, time, event)) {
- keyOperation = -1;
- return false;
- }
- keyOperation = -1;
-
- int allowedOperations = event.operations;
- TransferData[] allowedDataTypes = new TransferData[event.dataTypes.length];
- System.arraycopy(event.dataTypes, 0, allowedDataTypes, 0, allowedDataTypes.length);
-
- event.dataType = selectedDataType;
- event.detail = selectedOperation;
- selectedDataType = null;
- selectedOperation = DND.DROP_NONE;
- notifyListeners(DND.DropAccept,event);
- if (event.dataType != null) {
- for (int i = 0; i < allowedDataTypes.length; i++) {
- if (allowedDataTypes[i].type == event.dataType.type) {
- selectedDataType = allowedDataTypes[i];
- break;
- }
- }
- }
- if (selectedDataType != null && ((event.detail & allowedOperations) == event.detail)) {
- selectedOperation = event.detail;
- }
- if (selectedOperation == DND.DROP_NONE) {
- // this was not a successful drop
- return false;
- }
- // ask drag source for dropped data
- OS.gtk_drag_get_data(widget, context, selectedDataType.type, time);
- return true;
-}
-
-void drag_leave ( int /*long*/ widget, int /*long*/ context, int time){
- updateDragOverHover(0, null);
-
- if (keyOperation == -1) return;
- keyOperation = -1;
-
- DNDEvent event = new DNDEvent();
- event.widget = this;
- event.time = time;
- event.detail = DND.DROP_NONE;
- notifyListeners(DND.DragLeave, event);
-}
-
-boolean drag_motion ( int /*long*/ widget, int /*long*/ context, int x, int y, int time){
- int oldKeyOperation = keyOperation;
-
- /*
- * Bug in GTK. GTK allows drag & drop on a shell even if a modal
- * dialog/window is opened on that shell. The fix is to check for
- * any active modal dialogs/shells before allowing the drop.
- */
- if ((oldKeyOperation == -1) || !((Boolean) control.getData(IS_ACTIVE)).booleanValue()) { //drag enter
- selectedDataType = null;
- selectedOperation = DND.DROP_NONE;
- }
-
- DNDEvent event = new DNDEvent();
- if (!setEventData(context, x, y, time, event)) {
- keyOperation = -1;
- OS.gdk_drag_status(context, 0, time);
- return false;
- }
-
- int allowedOperations = event.operations;
- TransferData[] allowedDataTypes = new TransferData[event.dataTypes.length];
- System.arraycopy(event.dataTypes, 0, allowedDataTypes, 0, allowedDataTypes.length);
-
- if (oldKeyOperation == -1) {
- event.type = DND.DragEnter;
- } else {
- if (keyOperation == oldKeyOperation) {
- event.type = DND.DragOver;
- event.dataType = selectedDataType;
- event.detail = selectedOperation;
- } else {
- event.type = DND.DragOperationChanged;
- event.dataType = selectedDataType;
- }
- }
- updateDragOverHover(DRAGOVER_HYSTERESIS, event);
- selectedDataType = null;
- selectedOperation = DND.DROP_NONE;
- notifyListeners(event.type, event);
- if (event.detail == DND.DROP_DEFAULT) {
- event.detail = (allowedOperations & DND.DROP_MOVE) != 0 ? DND.DROP_MOVE : DND.DROP_NONE;
- }
- if (event.dataType != null) {
- for (int i = 0; i < allowedDataTypes.length; i++) {
- if (allowedDataTypes[i].type == event.dataType.type) {
- selectedDataType = allowedDataTypes[i];
- break;
- }
- }
- }
- if (selectedDataType != null && (allowedOperations & event.detail) != 0) {
- selectedOperation = event.detail;
- }
-
- switch (selectedOperation) {
- case DND.DROP_NONE:
- OS.gdk_drag_status(context, 0, time);
- break;
- case DND.DROP_COPY:
- OS.gdk_drag_status(context, OS.GDK_ACTION_COPY, time);
- break;
- case DND.DROP_MOVE:
- OS.gdk_drag_status(context, OS.GDK_ACTION_MOVE, time);
- break;
- case DND.DROP_LINK:
- OS.gdk_drag_status(context, OS.GDK_ACTION_LINK, time);
- break;
- }
-
- if (oldKeyOperation == -1) {
- dragOverHeartbeat.run();
- }
- return true;
-}
-
-/**
- * Returns the Control which is registered for this DropTarget. This is the control over which the
- * user positions the cursor to drop the data.
- *
- * @return the Control which is registered for this DropTarget
- */
-public Control getControl () {
- return control;
-}
-
-/**
- * Returns an array of listeners who will be notified when a drag and drop
- * operation is in progress, by sending it one of the messages defined in
- * the <code>DropTargetListener</code> interface.
- *
- * @return the listeners who will be notified when a drag and drop
- * operation is in progress
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DropTargetListener
- * @see #addDropListener
- * @see #removeDropListener
- * @see DropTargetEvent
- *
- * @since 3.4
- */
-public DropTargetListener[] getDropListeners() {
- Listener[] listeners = getListeners(DND.DragEnter);
- int length = listeners.length;
- DropTargetListener[] dropListeners = new DropTargetListener[length];
- int count = 0;
- for (int i = 0; i < length; i++) {
- Listener listener = listeners[i];
- if (listener instanceof DNDListener) {
- dropListeners[count] = (DropTargetListener) ((DNDListener) listener).getEventListener();
- count++;
- }
- }
- if (count == length) return dropListeners;
- DropTargetListener[] result = new DropTargetListener[count];
- System.arraycopy(dropListeners, 0, result, 0, count);
- return result;
-}
-
-/**
- * Returns the drop effect for this DropTarget. This drop effect will be
- * used during a drag and drop to display the drag under effect on the
- * target widget.
- *
- * @return the drop effect that is registered for this DropTarget
- *
- * @since 3.3
- */
-public DropTargetEffect getDropTargetEffect() {
- return dropEffect;
-}
-
-int getOperationFromKeyState() {
- int[] state = new int[1];
- OS.gdk_window_get_pointer(0, null, null, state);
- boolean ctrl = (state[0] & OS.GDK_CONTROL_MASK) != 0;
- boolean shift = (state[0] & OS.GDK_SHIFT_MASK) != 0;
- if (ctrl && shift) return DND.DROP_LINK;
- if (ctrl)return DND.DROP_COPY;
- if (shift)return DND.DROP_MOVE;
- return DND.DROP_DEFAULT;
-}
-
-/**
- * Returns a list of the data types that can be transferred to this DropTarget.
- *
- * @return a list of the data types that can be transferred to this DropTarget
- */
-public Transfer[] getTransfer() {
- return transferAgents;
-}
-
-void onDispose(){
- if (control == null) return;
- OS.g_signal_handler_disconnect(control.handle, drag_motion_handler);
- OS.g_signal_handler_disconnect(control.handle, drag_leave_handler);
- OS.g_signal_handler_disconnect(control.handle, drag_data_received_handler);
- OS.g_signal_handler_disconnect(control.handle, drag_drop_handler);
- if (transferAgents.length != 0)
- OS.gtk_drag_dest_unset(control.handle);
- transferAgents = null;
- if (controlListener != null)
- control.removeListener(SWT.Dispose, controlListener);
- control.setData(DND.DROP_TARGET_KEY, null);
- control = null;
- controlListener = null;
-}
-
-int opToOsOp(int operation){
- int osOperation = 0;
- if ((operation & DND.DROP_COPY) == DND.DROP_COPY)
- osOperation |= OS.GDK_ACTION_COPY;
- if ((operation & DND.DROP_MOVE) == DND.DROP_MOVE)
- osOperation |= OS.GDK_ACTION_MOVE;
- if ((operation & DND.DROP_LINK) == DND.DROP_LINK)
- osOperation |= OS.GDK_ACTION_LINK;
- return osOperation;
-}
-
-int osOpToOp(int osOperation){
- int operation = DND.DROP_NONE;
- if ((osOperation & OS.GDK_ACTION_COPY) == OS.GDK_ACTION_COPY)
- operation |= DND.DROP_COPY;
- if ((osOperation & OS.GDK_ACTION_MOVE) == OS.GDK_ACTION_MOVE)
- operation |= DND.DROP_MOVE;
- if ((osOperation & OS.GDK_ACTION_LINK) == OS.GDK_ACTION_LINK)
- operation |= DND.DROP_LINK;
- return operation;
-}
-
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when a drag and drop operation is in progress.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see DropTargetListener
- * @see #addDropListener
- * @see #getDropListeners
- */
-public void removeDropListener(DropTargetListener listener) {
- if (listener == null) DND.error (SWT.ERROR_NULL_ARGUMENT);
- removeListener (DND.DragEnter, listener);
- removeListener (DND.DragLeave, listener);
- removeListener (DND.DragOver, listener);
- removeListener (DND.DragOperationChanged, listener);
- removeListener (DND.Drop, listener);
- removeListener (DND.DropAccept, listener);
-}
-
-/**
- * Specifies the data types that can be transferred to this DropTarget. If data is
- * being dragged that does not match one of these types, the drop target will be notified of
- * the drag and drop operation but the currentDataType will be null and the operation
- * will be DND.NONE.
- *
- * @param transferAgents a list of Transfer objects which define the types of data that can be
- * dropped on this target
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if transferAgents is null</li>
- * </ul>
- */
-public void setTransfer(Transfer[] transferAgents){
- if (transferAgents == null) DND.error(SWT.ERROR_NULL_ARGUMENT);
-
- if (this.transferAgents.length != 0) {
- OS.gtk_drag_dest_unset(control.handle);
- }
- this.transferAgents = transferAgents;
-
- GtkTargetEntry[] targets = new GtkTargetEntry[0];
- for (int i = 0; i < transferAgents.length; i++) {
- Transfer transfer = transferAgents[i];
- if (transfer != null) {
- int[] typeIds = transfer.getTypeIds();
- String[] typeNames = transfer.getTypeNames();
- for (int j = 0; j < typeIds.length; j++) {
- GtkTargetEntry entry = new GtkTargetEntry();
- byte[] buffer = Converter.wcsToMbcs(null, typeNames[j], true);
- entry.target = OS.g_malloc(buffer.length);
- OS.memmove(entry.target, buffer, buffer.length);
- entry.info = typeIds[j];
- GtkTargetEntry[] newTargets = new GtkTargetEntry[targets.length + 1];
- System.arraycopy(targets, 0, newTargets, 0, targets.length);
- newTargets[targets.length] = entry;
- targets = newTargets;
- }
- }
- }
-
- int /*long*/ pTargets = OS.g_malloc(targets.length * GtkTargetEntry.sizeof);
- for (int i = 0; i < targets.length; i++) {
- OS.memmove(pTargets + i*GtkTargetEntry.sizeof, targets[i], GtkTargetEntry.sizeof);
- }
-
- int actions = opToOsOp(getStyle());
- if (control instanceof Combo) {
- if ((control.getStyle() & SWT.READ_ONLY) == 0) {
- int /*long*/ entryHandle = OS.gtk_bin_get_child (control.handle);
- if (entryHandle != 0) {
- OS.gtk_drag_dest_unset(entryHandle);
- }
- }
- }
- OS.gtk_drag_dest_set(control.handle, 0, pTargets, targets.length, actions);
-
- for (int i = 0; i < targets.length; i++) {
- OS.g_free(targets[i].target);
- }
-}
-
-/**
- * Specifies the drop effect for this DropTarget. This drop effect will be
- * used during a drag and drop to display the drag under effect on the
- * target widget.
- *
- * @param effect the drop effect that is registered for this DropTarget
- *
- * @since 3.3
- */
-public void setDropTargetEffect(DropTargetEffect effect) {
- dropEffect = effect;
-}
-
-boolean setEventData(int /*long*/ context, int x, int y, int time, DNDEvent event) {
- if (context == 0) return false;
- GdkDragContext dragContext = new GdkDragContext();
- OS.memmove(dragContext, context, GdkDragContext.sizeof);
- if (dragContext.targets == 0) return false;
-
- // get allowed operations
- int style = getStyle();
- int operations = osOpToOp(dragContext.actions) & style;
- if (operations == DND.DROP_NONE) return false;
-
- // get current operation
- int operation = getOperationFromKeyState();
- keyOperation = operation;
- if (operation == DND.DROP_DEFAULT) {
- if ((style & DND.DROP_DEFAULT) == 0) {
- operation = (operations & DND.DROP_MOVE) != 0 ? DND.DROP_MOVE : DND.DROP_NONE;
- }
- } else {
- if ((operation & operations) == 0) operation = DND.DROP_NONE;
- }
-
- // Get allowed transfer types
- int length = OS.g_list_length(dragContext.targets);
- TransferData[] dataTypes = new TransferData[0];
- for (int i = 0; i < length; i++) {
- int /*long*/ pData = OS.g_list_nth(dragContext.targets, i);
- GtkTargetPair gtkTargetPair = new GtkTargetPair();
- OS.memmove(gtkTargetPair, pData, GtkTargetPair.sizeof);
- TransferData data = new TransferData();
- data.type = gtkTargetPair.target;
- for (int j = 0; j < transferAgents.length; j++) {
- Transfer transfer = transferAgents[j];
- if (transfer != null && transfer.isSupportedType(data)) {
- TransferData[] newDataTypes = new TransferData[dataTypes.length + 1];
- System.arraycopy(dataTypes, 0, newDataTypes, 0, dataTypes.length);
- newDataTypes[dataTypes.length] = data;
- dataTypes = newDataTypes;
- break;
- }
- }
- }
- if (dataTypes.length == 0) return false;
-
- int /*long*/ window = OS.GTK_WIDGET_WINDOW(control.handle);
- int [] origin_x = new int[1], origin_y = new int[1];
- OS.gdk_window_get_origin(window, origin_x, origin_y);
- Point coordinates = new Point(origin_x[0] + x, origin_y[0] + y);
-
- event.widget = this;
- event.x = coordinates.x;
- event.y = coordinates.y;
- event.time = time;
- event.feedback = DND.FEEDBACK_SELECT;
- event.dataTypes = dataTypes;
- event.dataType = dataTypes[0];
- event.operations = operations;
- event.detail = operation;
- if (dropEffect != null) {
- event.item = dropEffect.getItem(coordinates.x, coordinates.y);
- }
- return true;
-}
-
-void updateDragOverHover(long delay, DNDEvent event) {
- if (delay == 0) {
- dragOverStart = 0;
- dragOverEvent = null;
- return;
- }
- dragOverStart = System.currentTimeMillis() + delay;
- if (dragOverEvent == null) dragOverEvent = new DNDEvent();
- dragOverEvent.x = event.x;
- dragOverEvent.y = event.y;
- TransferData[] dataTypes = new TransferData[ event.dataTypes.length];
- System.arraycopy( event.dataTypes, 0, dataTypes, 0, dataTypes.length);
- dragOverEvent.dataTypes = dataTypes;
- dragOverEvent.operations = event.operations;
- dragOverEvent.time = event.time;
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/FileTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/FileTransfer.java
deleted file mode 100644
index 8b0338f891..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/FileTransfer.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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 org.eclipse.swt.dnd;
-
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * The class <code>FileTransfer</code> provides a platform specific mechanism
- * for converting a list of files represented as a java <code>String[]</code> to a
- * platform specific representation of the data and vice versa.
- * Each <code>String</code> in the array contains the absolute path for a single
- * file or directory.
- *
- * <p>An example of a java <code>String[]</code> containing a list of files is shown
- * below:</p>
- *
- * <code><pre>
- * File file1 = new File("C:\temp\file1");
- * File file2 = new File("C:\temp\file2");
- * String[] fileData = new String[2];
- * fileData[0] = file1.getAbsolutePath();
- * fileData[1] = file2.getAbsolutePath();
- * </code></pre>
- *
- * @see Transfer
- */
-public class FileTransfer extends ByteArrayTransfer {
-
- private static FileTransfer _instance = new FileTransfer();
- private static final String URI_LIST = "text/uri-list"; //$NON-NLS-1$
- private static final int URI_LIST_ID = registerType(URI_LIST);
- private static final String GNOME_LIST = "x-special/gnome-copied-files"; //$NON-NLS-1$
- private static final int GNOME_LIST_ID = registerType(GNOME_LIST);
-
-private FileTransfer() {}
-
-/**
- * Returns the singleton instance of the FileTransfer class.
- *
- * @return the singleton instance of the FileTransfer class
- */
-public static FileTransfer getInstance () {
- return _instance;
-}
-
-/**
- * This implementation of <code>javaToNative</code> converts a list of file names
- * represented by a java <code>String[]</code> to a platform specific representation.
- * Each <code>String</code> in the array contains the absolute path for a single
- * file or directory.
- *
- * @param object a java <code>String[]</code> containing the file names to be converted
- * @param transferData an empty <code>TransferData</code> object that will
- * be filled in on return with the platform specific format of the data
- *
- * @see Transfer#nativeToJava
- */
-public void javaToNative(Object object, TransferData transferData) {
- transferData.result = 0;
- if (!checkFile(object) || !isSupportedType(transferData)) {
- DND.error(DND.ERROR_INVALID_DATA);
- }
- boolean gnomeList = transferData.type == GNOME_LIST_ID;
- byte[] buffer, separator;
- if (gnomeList) {
- buffer = new byte[] {'c','o','p','y'};
- separator = new byte[] {'\n'};
- } else {
- buffer = new byte[0];
- separator = new byte[] {'\r', '\n'};
- }
- String[] files = (String[])object;
- for (int i = 0; i < files.length; i++) {
- String string = files[i];
- if (string == null) continue;
- int length = string.length();
- if (length == 0) continue;
- char[] chars = new char[length];
- string.getChars(0, length, chars, 0);
- int /*long*/[] error = new int /*long*/[1];
- int /*long*/ utf8Ptr = OS.g_utf16_to_utf8(chars, chars.length, null, null, error);
- if (error[0] != 0 || utf8Ptr == 0) continue;
- int /*long*/ localePtr = OS.g_filename_from_utf8(utf8Ptr, -1, null, null, error);
- OS.g_free(utf8Ptr);
- if (error[0] != 0 || localePtr == 0) continue;
- int /*long*/ uriPtr = OS.g_filename_to_uri(localePtr, 0, error);
- OS.g_free(localePtr);
- if (error[0] != 0 || uriPtr == 0) continue;
- length = OS.strlen(uriPtr);
- byte[] temp = new byte[length];
- OS.memmove (temp, uriPtr, length);
- OS.g_free(uriPtr);
- int newLength = (buffer.length > 0) ? buffer.length+separator.length+temp.length : temp.length;
- byte[] newBuffer = new byte[newLength];
- int offset = 0;
- if (buffer.length > 0) {
- System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
- offset += buffer.length;
- System.arraycopy(separator, 0, newBuffer, offset, separator.length);
- offset += separator.length;
- }
- System.arraycopy(temp, 0, newBuffer, offset, temp.length);
- buffer = newBuffer;
- }
- if (buffer.length == 0) return;
- int /*long*/ ptr = OS.g_malloc(buffer.length+1);
- OS.memset(ptr, '\0', buffer.length+1);
- OS.memmove(ptr, buffer, buffer.length);
- transferData.pValue = ptr;
- transferData.length = buffer.length;
- transferData.format = 8;
- transferData.result = 1;
-}
-/**
- * This implementation of <code>nativeToJava</code> converts a platform specific
- * representation of a list of file names to a java <code>String[]</code>.
- * Each String in the array contains the absolute path for a single file or directory.
- *
- * @param transferData the platform specific representation of the data to be converted
- * @return a java <code>String[]</code> containing a list of file names if the conversion
- * was successful; otherwise null
- *
- * @see Transfer#javaToNative
- */
-public Object nativeToJava(TransferData transferData) {
- if ( !isSupportedType(transferData) || transferData.pValue == 0 || transferData.length <= 0 ) return null;
- int length = transferData.length;
- byte[] temp = new byte[length];
- OS.memmove(temp, transferData.pValue, length);
- boolean gnomeList = transferData.type == GNOME_LIST_ID;
- int sepLength = gnomeList ? 1 : 2;
- int /*long*/[] files = new int /*long*/[0];
- int offset = 0;
- for (int i = 0; i < temp.length - 1; i++) {
- boolean terminator = gnomeList ? temp[i] == '\n' : temp[i] == '\r' && temp[i+1] == '\n';
- if (terminator) {
- if (!(gnomeList && offset == 0)) {
- /* The content of the first line in a gnome-list is always either 'copy' or 'cut' */
- int size = i - offset;
- int /*long*/ file = OS.g_malloc(size + 1);
- byte[] fileBuffer = new byte[size + 1];
- System.arraycopy(temp, offset, fileBuffer, 0, size);
- OS.memmove(file, fileBuffer, size + 1);
- int /*long*/[] newFiles = new int /*long*/[files.length + 1];
- System.arraycopy(files, 0, newFiles, 0, files.length);
- newFiles[files.length] = file;
- files = newFiles;
- }
- offset = i + sepLength;
- }
- }
- if (offset < temp.length - sepLength) {
- int size = temp.length - offset;
- int /*long*/ file = OS.g_malloc(size + 1);
- byte[] fileBuffer = new byte[size + 1];
- System.arraycopy(temp, offset, fileBuffer, 0, size);
- OS.memmove(file, fileBuffer, size + 1);
- int /*long*/[] newFiles = new int /*long*/[files.length + 1];
- System.arraycopy(files, 0, newFiles, 0, files.length);
- newFiles[files.length] = file;
- files = newFiles;
- }
- String[] fileNames = new String[0];
- for (int i = 0; i < files.length; i++) {
- int /*long*/[] error = new int /*long*/[1];
- int /*long*/ localePtr = OS.g_filename_from_uri(files[i], null, error);
- OS.g_free(files[i]);
- if (error[0] != 0 || localePtr == 0) continue;
- int /*long*/ utf8Ptr = OS.g_filename_to_utf8(localePtr, -1, null, null, error);
- OS.g_free(localePtr);
- if (error[0] != 0 || utf8Ptr == 0) continue;
- int /*long*/[] items_written = new int /*long*/[1];
- int /*long*/ utf16Ptr = OS.g_utf8_to_utf16(utf8Ptr, -1, null, items_written, null);
- OS.g_free(utf8Ptr);
- length = (int)/*64*/items_written[0];
- char[] buffer = new char[length];
- OS.memmove(buffer, utf16Ptr, length * 2);
- OS.g_free(utf16Ptr);
- String name = new String(buffer);
- String[] newFileNames = new String[fileNames.length + 1];
- System.arraycopy(fileNames, 0, newFileNames, 0, fileNames.length);
- newFileNames[fileNames.length] = name;
- fileNames = newFileNames;
- }
- if (fileNames.length == 0) return null;
- return fileNames;
-}
-
-protected int[] getTypeIds(){
- return new int[]{URI_LIST_ID, GNOME_LIST_ID};
-}
-
-protected String[] getTypeNames(){
- return new String[]{URI_LIST, GNOME_LIST};
-}
-
-boolean checkFile(Object object) {
- if (object == null || !(object instanceof String[]) || ((String[])object).length == 0) return false;
- String[] strings = (String[])object;
- for (int i = 0; i < strings.length; i++) {
- if (strings[i] == null || strings[i].length() == 0) return false;
- }
- return true;
-}
-
-protected boolean validate(Object object) {
- return checkFile(object);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/HTMLTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/HTMLTransfer.java
deleted file mode 100644
index 5d0ccaeb91..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/HTMLTransfer.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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 org.eclipse.swt.dnd;
-
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * The class <code>HTMLTransfer</code> provides a platform specific mechanism
- * for converting text in HTML format represented as a java <code>String</code>
- * to a platform specific representation of the data and vice versa.
- *
- * <p>An example of a java <code>String</code> containing HTML text is shown
- * below:</p>
- *
- * <code><pre>
- * String htmlData = "<p>This is a paragraph of text.</p>";
- * </code></pre>
- *
- * @see Transfer
- */
-public class HTMLTransfer extends ByteArrayTransfer {
-
- private static HTMLTransfer _instance = new HTMLTransfer();
- private static final String TEXT_HTML = "text/html"; //$NON-NLS-1$
- private static final int TEXT_HTML_ID = registerType(TEXT_HTML);
- private static final String TEXT_HTML2 = "TEXT/HTML"; //$NON-NLS-1$
- private static final int TEXT_HTML2_ID = registerType(TEXT_HTML2);
-
-private HTMLTransfer() {}
-
-/**
- * Returns the singleton instance of the HTMLTransfer class.
- *
- * @return the singleton instance of the HTMLTransfer class
- */
-public static HTMLTransfer getInstance () {
- return _instance;
-}
-
-/**
- * This implementation of <code>javaToNative</code> converts HTML-formatted text
- * represented by a java <code>String</code> to a platform specific representation.
- *
- * @param object a java <code>String</code> containing HTML text
- * @param transferData an empty <code>TransferData</code> object that will
- * be filled in on return with the platform specific format of the data
- *
- * @see Transfer#nativeToJava
- */
-public void javaToNative (Object object, TransferData transferData){
- transferData.result = 0;
- if (!checkHTML(object) || !isSupportedType(transferData)) {
- DND.error(DND.ERROR_INVALID_DATA);
- }
- String string = (String)object;
- int charCount = string.length();
- char [] chars = new char[charCount +1];
- string.getChars(0, charCount , chars, 0);
- int byteCount = chars.length*2;
- int /*long*/ pValue = OS.g_malloc(byteCount);
- if (pValue == 0) return;
- OS.memmove(pValue, chars, byteCount);
- transferData.length = byteCount;
- transferData.format = 8;
- transferData.pValue = pValue;
- transferData.result = 1;
-}
-
-/**
- * This implementation of <code>nativeToJava</code> converts a platform specific
- * representation of HTML text to a java <code>String</code>.
- *
- * @param transferData the platform specific representation of the data to be converted
- * @return a java <code>String</code> containing HTML text if the conversion was successful;
- * otherwise null
- *
- * @see Transfer#javaToNative
- */
-public Object nativeToJava(TransferData transferData){
- if ( !isSupportedType(transferData) || transferData.pValue == 0 ) return null;
- /* Ensure byteCount is a multiple of 2 bytes */
- int size = (transferData.format * transferData.length / 8) / 2 * 2;
- if (size <= 0) return null;
- char[] chars = new char [size/2];
- OS.memmove (chars, transferData.pValue, size);
- String string = new String (chars);
- int end = string.indexOf('\0');
- return (end == -1) ? string : string.substring(0, end);
-}
-protected int[] getTypeIds() {
- return new int[] {TEXT_HTML_ID, TEXT_HTML2_ID};
-}
-
-protected String[] getTypeNames() {
- return new String[] {TEXT_HTML, TEXT_HTML2};
-}
-
-boolean checkHTML(Object object) {
- return (object != null && object instanceof String && ((String)object).length() > 0);
-}
-
-protected boolean validate(Object object) {
- return checkHTML(object);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ImageTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ImageTransfer.java
deleted file mode 100644
index cf28027468..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ImageTransfer.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 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 org.eclipse.swt.dnd;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.Converter;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * The class <code>ImageTransfer</code> provides a platform specific mechanism
- * for converting an Image represented as a java <code>ImageData</code> to a
- * platform specific representation of the data and vice versa.
- *
- * <p>An example of a java <code>ImageData</code> is shown below:</p>
- *
- * <code><pre>
- * Image image = new Image(display, "C:\temp\img1.gif");
- * ImageData imgData = image.getImageData();
- * </code></pre>
- *
- * @see Transfer
- *
- * @since 3.4
- */
-public class ImageTransfer extends ByteArrayTransfer {
-
- private static ImageTransfer _instance = new ImageTransfer();
-
- private static final String JPEG = "image/jpeg"; //$NON-NLS-1$
- private static final int JPEG_ID = registerType(JPEG);
- private static final String PNG = "image/png"; //$NON-NLS-1$
- private static final int PNG_ID = registerType(PNG);
- private static final String BMP = "image/bmp"; //$NON-NLS-1$
- private static final int BMP_ID = registerType(BMP);
- private static final String EPS = "image/eps"; //$NON-NLS-1$
- private static final int EPS_ID = registerType(EPS);
- private static final String PCX = "image/pcx"; //$NON-NLS-1$
- private static final int PCX_ID = registerType(PCX);
- private static final String PPM = "image/ppm"; //$NON-NLS-1$
- private static final int PPM_ID = registerType(PPM);
- private static final String RGB = "image/ppm"; //$NON-NLS-1$
- private static final int RGB_ID = registerType(RGB);
- private static final String TGA = "image/tga"; //$NON-NLS-1$
- private static final int TGA_ID = registerType(TGA);
- private static final String XBM = "image/xbm"; //$NON-NLS-1$
- private static final int XBM_ID = registerType(XBM);
- private static final String XPM = "image/xpm"; //$NON-NLS-1$
- private static final int XPM_ID = registerType(XPM);
- private static final String XV = "image/xv"; //$NON-NLS-1$
- private static final int XV_ID = registerType(XV);
-
-private ImageTransfer() {}
-
-/**
- * Returns the singleton instance of the ImageTransfer class.
- *
- * @return the singleton instance of the ImageTransfer class
- */
-public static ImageTransfer getInstance () {
- return _instance;
-}
-
-/**
- * This implementation of <code>javaToNative</code> converts an ImageData object represented
- * by java <code>ImageData</code> to a platform specific representation.
- *
- * @param object a java <code>ImageData</code> containing the ImageData to be converted
- * @param transferData an empty <code>TransferData</code> object that will
- * be filled in on return with the platform specific format of the data
- *
- * @see Transfer#nativeToJava
- */
-public void javaToNative(Object object, TransferData transferData) {
- if (!checkImage(object) || !isSupportedType(transferData)) {
- DND.error(DND.ERROR_INVALID_DATA);
- }
- if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) return;
-
- ImageData imgData = (ImageData)object;
- if (imgData == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- Image image = new Image(Display.getCurrent(), imgData);
- int /*long*/ pixmap = image.pixmap;
- int width = imgData.width;
- int height = imgData.height;
- int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, width, height);
- if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int /*long*/ colormap = OS.gdk_colormap_get_system();
- OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height);
-
- String typeStr = "";
- if (transferData.type == JPEG_ID) typeStr = "jpeg";
- if (transferData.type == PNG_ID) typeStr = "png";
- if (transferData.type == BMP_ID) typeStr = "bmp";
- if (transferData.type == EPS_ID) typeStr = "eps";
- if (transferData.type == PCX_ID) typeStr = "pcx";
- if (transferData.type == PPM_ID) typeStr = "ppm";
- if (transferData.type == RGB_ID) typeStr = "rgb";
- if (transferData.type == TGA_ID) typeStr = "tga";
- if (transferData.type == XBM_ID) typeStr = "xbm";
- if (transferData.type == XPM_ID) typeStr = "xpm";
- if (transferData.type == XV_ID) typeStr = "xv";
- byte[] type = Converter.wcsToMbcs(null, typeStr , true);
- int /*long*/ [] buffer = new int /*long*/ [1];
- int /*long*/ [] len = new int /*long*/ [1];
- if (type == null) return;
- OS.gdk_pixbuf_save_to_bufferv(pixbuf, buffer, len, type, null, null, null);
- OS.g_object_unref(pixbuf);
- image.dispose();
- transferData.pValue = buffer[0];
- transferData.length = (int)(len[0] + 3) / 4 * 4;
- transferData.result = 1;
- transferData.format = 32;
-}
-
-/**
- * This implementation of <code>nativeToJava</code> converts a platform specific
- * representation of an image to java <code>ImageData</code>.
- *
- * @param transferData the platform specific representation of the data to be converted
- * @return a java <code>ImageData</code> of the image if the conversion was successful;
- * otherwise null
- *
- * @see Transfer#javaToNative
- */
-public Object nativeToJava(TransferData transferData) {
- ImageData imgData = null;
- if (transferData.length > 0)
- {
- int /*long*/ loader = OS.gdk_pixbuf_loader_new();
- OS.gdk_pixbuf_loader_write(loader, transferData.pValue, transferData.length, null);
- OS.gdk_pixbuf_loader_close(loader, null);
- int /*long*/ pixbuf = OS.gdk_pixbuf_loader_get_pixbuf(loader);
- if (pixbuf != 0) {
- OS.g_object_ref(pixbuf);
- int /*long*/ [] pixmap_return = new int /*long*/ [1];
- OS.gdk_pixbuf_render_pixmap_and_mask(pixbuf, pixmap_return, null, 0);
- int /*long*/ handle = pixmap_return[0];
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.g_object_unref(loader);
- Image img = Image.gtk_new(Display.getCurrent(), SWT.BITMAP, handle, 0);
- imgData = img.getImageData();
- img.dispose();
- }
- }
- return imgData;
-}
-
-protected int[] getTypeIds(){
- return new int[]{JPEG_ID, PNG_ID, BMP_ID, EPS_ID, PCX_ID, PPM_ID, RGB_ID, TGA_ID, XBM_ID, XPM_ID, XV_ID};
-}
-
-protected String[] getTypeNames(){
- return new String[]{JPEG, PNG, BMP, EPS, PCX, PPM, RGB, TGA, XBM, XPM, XV};
-}
-
-boolean checkImage(Object object) {
- if (object == null || !(object instanceof ImageData)) return false;
- return true;
-}
-
-protected boolean validate(Object object) {
- return checkImage(object);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/RTFTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/RTFTransfer.java
deleted file mode 100644
index 74aae33125..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/RTFTransfer.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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 org.eclipse.swt.dnd;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * The class <code>RTFTransfer</code> provides a platform specific mechanism
- * for converting text in RTF format represented as a java <code>String</code>
- * to a platform specific representation of the data and vice versa.
- *
- * <p>An example of a java <code>String</code> containing RTF text is shown
- * below:</p>
- *
- * <code><pre>
- * String rtfData = "{\\rtf1{\\colortbl;\\red255\\green0\\blue0;}\\uc1\\b\\i Hello World}";
- * </code></pre>
- *
- * @see Transfer
- */
-public class RTFTransfer extends ByteArrayTransfer {
-
- private static RTFTransfer _instance = new RTFTransfer();
- private static final String TEXT_RTF = "text/rtf"; //$NON-NLS-1$
- private static final int TEXT_RTF_ID = registerType(TEXT_RTF);
- private static final String TEXT_RTF2 = "TEXT/RTF"; //$NON-NLS-1$
- private static final int TEXT_RTF2_ID = registerType(TEXT_RTF2);
- private static final String APPLICATION_RTF = "application/rtf"; //$NON-NLS-1$
- private static final int APPLICATION_RTF_ID = registerType(APPLICATION_RTF);
-
-private RTFTransfer() {}
-
-/**
- * Returns the singleton instance of the RTFTransfer class.
- *
- * @return the singleton instance of the RTFTransfer class
- */
-public static RTFTransfer getInstance () {
- return _instance;
-}
-
-/**
- * This implementation of <code>javaToNative</code> converts RTF-formatted text
- * represented by a java <code>String</code> to a platform specific representation.
- *
- * @param object a java <code>String</code> containing RTF text
- * @param transferData an empty <code>TransferData</code> object that will
- * be filled in on return with the platform specific format of the data
- *
- * @see Transfer#nativeToJava
- */
-public void javaToNative (Object object, TransferData transferData){
- transferData.result = 0;
- if (!checkRTF(object) || !isSupportedType(transferData)) {
- DND.error(DND.ERROR_INVALID_DATA);
- }
- String string = (String)object;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int /*long*/ pValue = OS.g_malloc(buffer.length);
- if (pValue == 0) return;
- OS.memmove(pValue, buffer, buffer.length);
- transferData.length = buffer.length - 1;
- transferData.format = 8;
- transferData.pValue = pValue;
- transferData.result = 1;
-}
-
-/**
- * This implementation of <code>nativeToJava</code> converts a platform specific
- * representation of RTF text to a java <code>String</code>.
- *
- * @param transferData the platform specific representation of the data to be converted
- * @return a java <code>String</code> containing RTF text if the conversion was successful;
- * otherwise null
- *
- * @see Transfer#javaToNative
- */
-public Object nativeToJava(TransferData transferData){
- if ( !isSupportedType(transferData) || transferData.pValue == 0 ) return null;
- int size = transferData.format * transferData.length / 8;
- if (size == 0) return null;
- byte[] buffer = new byte[size];
- OS.memmove(buffer, transferData.pValue, size);
- char [] chars = Converter.mbcsToWcs (null, buffer);
- String string = new String (chars);
- int end = string.indexOf('\0');
- return (end == -1) ? string : string.substring(0, end);
-}
-
-protected int[] getTypeIds() {
- return new int[] {TEXT_RTF_ID, TEXT_RTF2_ID, APPLICATION_RTF_ID};
-}
-
-protected String[] getTypeNames() {
- return new String[] {TEXT_RTF, TEXT_RTF2, APPLICATION_RTF};
-}
-
-boolean checkRTF(Object object) {
- return (object != null && object instanceof String && ((String)object).length() > 0);
-}
-
-protected boolean validate(Object object) {
- return checkRTF(object);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDragSourceEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDragSourceEffect.java
deleted file mode 100644
index b3656bb1da..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDragSourceEffect.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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 org.eclipse.swt.dnd;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * This class provides default implementations to display a source image
- * when a drag is initiated from a <code>Table</code>.
- *
- * <p>Classes that wish to provide their own source image for a <code>Table</code> can
- * extend the <code>TableDragSourceEffect</code> class, override the
- * <code>TableDragSourceEffect.dragStart</code> method and set the field
- * <code>DragSourceEvent.image</code> with their own image.</p>
- *
- * Subclasses that override any methods of this class must call the corresponding
- * <code>super</code> method to get the default drag source effect implementation.
- *
- * @see DragSourceEffect
- * @see DragSourceEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- */
-public class TableDragSourceEffect extends DragSourceEffect {
- Image dragSourceImage = null;
-
- /**
- * Creates a new <code>TableDragSourceEffect</code> to handle drag effect
- * from the specified <code>Table</code>.
- *
- * @param table the <code>Table</code> that the user clicks on to initiate the drag
- */
- public TableDragSourceEffect(Table table) {
- super(table);
- }
-
- /**
- * This implementation of <code>dragFinished</code> disposes the image
- * that was created in <code>TableDragSourceEffect.dragStart</code>.
- *
- * Subclasses that override this method should call <code>super.dragFinished(event)</code>
- * to dispose the image in the default implementation.
- *
- * @param event the information associated with the drag finished event
- */
- public void dragFinished(DragSourceEvent event) {
- if (dragSourceImage != null) dragSourceImage.dispose();
- dragSourceImage = null;
- }
-
- /**
- * This implementation of <code>dragStart</code> will create a default
- * image that will be used during the drag. The image should be disposed
- * when the drag is completed in the <code>TableDragSourceEffect.dragFinished</code>
- * method.
- *
- * Subclasses that override this method should call <code>super.dragStart(event)</code>
- * to use the image from the default implementation.
- *
- * @param event the information associated with the drag start event
- */
- public void dragStart(DragSourceEvent event) {
- event.image = getDragSourceImage(event);
- }
-
- Image getDragSourceImage(DragSourceEvent event) {
- if (dragSourceImage != null) dragSourceImage.dispose();
- dragSourceImage = null;
-
- Table table = (Table) control;
- if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) return null;
- //TEMPORARY CODE
- if (table.isListening(SWT.EraseItem) || table.isListening (SWT.PaintItem)) return null;
- /*
- * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults
- * in versions smaller than 2.2.4 if the model is NULL. The fix is
- * to give a valid pointer instead.
- */
- int /*long*/ handle = table.handle;
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null;
- int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model);
- if (list == 0) return null;
- int count = Math.min(10, OS.g_list_length (list));
-
- Display display = table.getDisplay();
- if (count == 1) {
- int /*long*/ path = OS.g_list_nth_data (list, 0);
- int /*long*/ pixmap = OS.gtk_tree_view_create_row_drag_icon(handle, path);
- dragSourceImage = Image.gtk_new(display, SWT.ICON, pixmap, 0);
- } else {
- int width = 0, height = 0;
- int[] w = new int[1], h = new int[1];
- int[] yy = new int[count], hh = new int[count];
- int /*long*/ [] pixmaps = new int /*long*/ [count];
- GdkRectangle rect = new GdkRectangle ();
- for (int i=0; i<count; i++) {
- int /*long*/ path = OS.g_list_nth_data (list, i);
- OS.gtk_tree_view_get_cell_area (handle, path, 0, rect);
- pixmaps[i] = OS.gtk_tree_view_create_row_drag_icon(handle, path);
- OS.gdk_drawable_get_size(pixmaps[i], w, h);
- width = Math.max(width, w[0]);
- height = rect.y + h[0] - yy[0];
- yy[i] = rect.y;
- hh[i] = h[0];
- }
- int /*long*/ source = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, -1);
- int /*long*/ gcSource = OS.gdk_gc_new(source);
- int /*long*/ mask = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, 1);
- int /*long*/ gcMask = OS.gdk_gc_new(mask);
- GdkColor color = new GdkColor();
- color.pixel = 0;
- OS.gdk_gc_set_foreground(gcMask, color);
- OS.gdk_draw_rectangle(mask, gcMask, 1, 0, 0, width, height);
- color.pixel = 1;
- OS.gdk_gc_set_foreground(gcMask, color);
- for (int i=0; i<count; i++) {
- OS.gdk_draw_drawable(source, gcSource, pixmaps[i], 0, 0, 0, yy[i] - yy[0], -1, -1);
- OS.gdk_draw_rectangle(mask, gcMask, 1, 0, yy[i] - yy[0], width, hh[i]);
- OS.g_object_unref(pixmaps[i]);
- }
- OS.g_object_unref(gcSource);
- OS.g_object_unref(gcMask);
- dragSourceImage = Image.gtk_new(display, SWT.ICON, source, mask);
- }
- OS.g_list_free (list);
-
- return dragSourceImage;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDropTargetEffect.java
deleted file mode 100644
index f4ab889ff1..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDropTargetEffect.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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 org.eclipse.swt.dnd;
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * This class provides a default drag under effect (eg. select, insert and scroll)
- * when a drag occurs over a <code>Table</code>.
- *
- * <p>Classes that wish to provide their own drag under effect for a <code>Table</code>
- * can extend the <code>TableDropTargetEffect</code> and override any applicable methods
- * in <code>TableDropTargetEffect</code> to display their own drag under effect.</p>
- *
- * Subclasses that override any methods of this class must call the corresponding
- * <code>super</code> method to get the default drag under effect implementation.
- *
- * <p>The feedback value is either one of the FEEDBACK constants defined in
- * class <code>DND</code> which is applicable to instances of this class,
- * or it must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>DND</code> effect constants.
- * </p>
- * <p>
- * <dl>
- * <dt><b>Feedback:</b></dt>
- * <dd>FEEDBACK_SELECT, FEEDBACK_SCROLL</dd>
- * </dl>
- * </p>
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- */
-public class TableDropTargetEffect extends DropTargetEffect {
- static final int SCROLL_HYSTERESIS = 150; // milli seconds
-
- int scrollIndex;
- long scrollBeginTime;
-
- /**
- * Creates a new <code>TableDropTargetEffect</code> to handle the drag under effect on the specified
- * <code>Table</code>.
- *
- * @param table the <code>Table</code> over which the user positions the cursor to drop the data
- */
- public TableDropTargetEffect(Table table) {
- super(table);
- }
-
- int checkEffect(int effect) {
- // Some effects are mutually exclusive. Make sure that only one of the mutually exclusive effects has been specified.
- if ((effect & DND.FEEDBACK_SELECT) != 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER & ~DND.FEEDBACK_INSERT_BEFORE;
- if ((effect & DND.FEEDBACK_INSERT_BEFORE) != 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER;
- return effect;
- }
-
- /**
- * This implementation of <code>dragEnter</code> provides a default drag under effect
- * for the feedback specified in <code>event.feedback</code>.
- *
- * For additional information see <code>DropTargetAdapter.dragEnter</code>.
- *
- * Subclasses that override this method should call <code>super.dragEnter(event)</code>
- * to get the default drag under effect implementation.
- *
- * @param event the information associated with the drag enter event
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- */
- public void dragEnter(DropTargetEvent event) {
- scrollBeginTime = 0;
- scrollIndex = -1;
- }
-
- /**
- * This implementation of <code>dragLeave</code> provides a default drag under effect
- * for the feedback specified in <code>event.feedback</code>.
- *
- * For additional information see <code>DropTargetAdapter.dragLeave</code>.
- *
- * Subclasses that override this method should call <code>super.dragLeave(event)</code>
- * to get the default drag under effect implementation.
- *
- * @param event the information associated with the drag leave event
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- */
- public void dragLeave(DropTargetEvent event) {
- Table table = (Table) control;
- int /*long*/ handle = table.handle;
- OS.gtk_tree_view_set_drag_dest_row(handle, 0, OS.GTK_TREE_VIEW_DROP_BEFORE);
-
- scrollBeginTime = 0;
- scrollIndex = -1;
- }
-
- /**
- * This implementation of <code>dragOver</code> provides a default drag under effect
- * for the feedback specified in <code>event.feedback</code>. The class description
- * lists the FEEDBACK constants that are applicable to the class.
- *
- * For additional information see <code>DropTargetAdapter.dragOver</code>.
- *
- * Subclasses that override this method should call <code>super.dragOver(event)</code>
- * to get the default drag under effect implementation.
- *
- * @param event the information associated with the drag over event
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- * @see DND#FEEDBACK_SELECT
- * @see DND#FEEDBACK_SCROLL
- */
- public void dragOver(DropTargetEvent event) {
- Table table = (Table) control;
- int /*long*/ handle = table.handle;
- int effect = checkEffect(event.feedback);
- Point coordinates = new Point(event.x, event.y);
- coordinates = table.toControl(coordinates);
- int /*long*/ [] path = new int /*long*/ [1];
- OS.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, path, null, null, null);
- int index = -1;
- if (path[0] != 0) {
- int /*long*/ indices = OS.gtk_tree_path_get_indices (path[0]);
- if (indices != 0) {
- int[] temp = new int[1];
- OS.memmove (temp, indices, 4);
- index = temp[0];
- }
- }
- if ((effect & DND.FEEDBACK_SCROLL) == 0) {
- scrollBeginTime = 0;
- scrollIndex = -1;
- } else {
- if (index != -1 && scrollIndex == index && scrollBeginTime != 0) {
- if (System.currentTimeMillis() >= scrollBeginTime) {
- if (coordinates.y < table.getItemHeight()) {
- OS.gtk_tree_path_prev(path[0]);
- } else {
- OS.gtk_tree_path_next(path[0]);
- }
- if (path[0] != 0) {
- OS.gtk_tree_view_scroll_to_cell(handle, path[0], 0, false, 0, 0);
- OS.gtk_tree_path_free(path[0]);
- path[0] = 0;
- OS.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, path, null, null, null);
- }
- scrollBeginTime = 0;
- scrollIndex = -1;
- }
- } else {
- scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS;
- scrollIndex = index;
- }
- }
- if (path[0] != 0) {
- int position = 0;
- if ((effect & DND.FEEDBACK_SELECT) != 0) position = OS.GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
- //if ((effect & DND.FEEDBACK_INSERT_BEFORE) != 0) position = OS.GTK_TREE_VIEW_DROP_BEFORE;
- //if ((effect & DND.FEEDBACK_INSERT_AFTER) != 0) position = OS.GTK_TREE_VIEW_DROP_AFTER;
- if (position != 0) {
- OS.gtk_tree_view_set_drag_dest_row(handle, path[0], OS.GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
- } else {
- OS.gtk_tree_view_set_drag_dest_row(handle, 0, OS.GTK_TREE_VIEW_DROP_BEFORE);
- }
- } else {
- OS.gtk_tree_view_set_drag_dest_row(handle, 0, OS.GTK_TREE_VIEW_DROP_BEFORE);
- }
- if (path[0] != 0) OS.gtk_tree_path_free (path [0]);
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TextTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TextTransfer.java
deleted file mode 100644
index 6a6dabc616..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TextTransfer.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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 org.eclipse.swt.dnd;
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * The class <code>TextTransfer</code> provides a platform specific mechanism
- * for converting plain text represented as a java <code>String</code>
- * to a platform specific representation of the data and vice versa.
- *
- * <p>An example of a java <code>String</code> containing plain text is shown
- * below:</p>
- *
- * <code><pre>
- * String textData = "Hello World";
- * </code></pre>
- *
- * @see Transfer
- */
-public class TextTransfer extends ByteArrayTransfer {
-
- private static TextTransfer _instance = new TextTransfer();
- private static final String COMPOUND_TEXT = "COMPOUND_TEXT"; //$NON-NLS-1$
- private static final String UTF8_STRING = "UTF8_STRING"; //$NON-NLS-1$
- private static final String STRING = "STRING"; //$NON-NLS-1$
- private static final int COMPOUND_TEXT_ID = registerType(COMPOUND_TEXT);
- private static final int UTF8_STRING_ID = registerType(UTF8_STRING);
- private static final int STRING_ID = registerType(STRING);
-
-private TextTransfer() {}
-
-/**
- * Returns the singleton instance of the TextTransfer class.
- *
- * @return the singleton instance of the TextTransfer class
- */
-public static TextTransfer getInstance () {
- return _instance;
-}
-
-/**
- * This implementation of <code>javaToNative</code> converts plain text
- * represented by a java <code>String</code> to a platform specific representation.
- *
- * @param object a java <code>String</code> containing text
- * @param transferData an empty <code>TransferData</code> object that will
- * be filled in on return with the platform specific format of the data
- *
- * @see Transfer#nativeToJava
- */
-public void javaToNative (Object object, TransferData transferData) {
- transferData.result = 0;
- if (!checkText(object) || !isSupportedType(transferData)) {
- DND.error(DND.ERROR_INVALID_DATA);
- }
- String string = (String)object;
- byte[] utf8 = Converter.wcsToMbcs (null, string, true);
- if (transferData.type == COMPOUND_TEXT_ID) {
- int /*long*/[] encoding = new int /*long*/[1];
- int[] format = new int[1];
- int /*long*/[] ctext = new int /*long*/[1];
- int[] length = new int[1];
- boolean result = OS.gdk_utf8_to_compound_text(utf8, encoding, format, ctext, length);
- if (!result) return;
- transferData.type = encoding[0];
- transferData.format = format[0];
- transferData.length = length[0];
- transferData.pValue = ctext[0];
- transferData.result = 1;
- }
- if (transferData.type == UTF8_STRING_ID) {
- int /*long*/ pValue = OS.g_malloc(utf8.length);
- if (pValue == 0) return;
- OS.memmove(pValue, utf8, utf8.length);
- transferData.type = UTF8_STRING_ID;
- transferData.format = 8;
- transferData.length = utf8.length - 1;
- transferData.pValue = pValue;
- transferData.result = 1;
- }
- if (transferData.type == STRING_ID) {
- int /*long*/ string_target = OS.gdk_utf8_to_string_target(utf8);
- if (string_target == 0) return;
- transferData.type = STRING_ID;
- transferData.format = 8;
- transferData.length = OS.strlen(string_target);
- transferData.pValue = string_target;
- transferData.result = 1;
- }
-}
-
-/**
- * This implementation of <code>nativeToJava</code> converts a platform specific
- * representation of plain text to a java <code>String</code>.
- *
- * @param transferData the platform specific representation of the data to be converted
- * @return a java <code>String</code> containing text if the conversion was successful; otherwise null
- *
- * @see Transfer#javaToNative
- */
-public Object nativeToJava(TransferData transferData){
- if (!isSupportedType(transferData) || transferData.pValue == 0) return null;
- int /*long*/[] list = new int /*long*/[1];
- int count = OS.gdk_text_property_to_utf8_list(transferData.type, transferData.format, transferData.pValue, transferData.length, list);
- if (count == 0) return null;
- int /*long*/[] ptr = new int /*long*/[1];
- OS.memmove(ptr, list[0], OS.PTR_SIZEOF);
- int length = OS.strlen(ptr[0]);
- byte[] utf8 = new byte[length];
- OS.memmove(utf8, ptr[0], length);
- OS.g_strfreev(list[0]);
- // convert utf8 byte array to a unicode string
- char [] unicode = Converter.mbcsToWcs (null, utf8);
- String string = new String (unicode);
- int end = string.indexOf('\0');
- return (end == -1) ? string : string.substring(0, end);
-}
-
-protected int[] getTypeIds() {
- return new int[] {UTF8_STRING_ID, COMPOUND_TEXT_ID, STRING_ID};
-}
-
-protected String[] getTypeNames() {
- return new String[] {UTF8_STRING, COMPOUND_TEXT, STRING};
-}
-
-boolean checkText(Object object) {
- return (object != null && object instanceof String && ((String)object).length() > 0);
-}
-
-protected boolean validate(Object object) {
- return checkText(object);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Transfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Transfer.java
deleted file mode 100644
index 3369b97bb9..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/Transfer.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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 org.eclipse.swt.dnd;
-
-
-import org.eclipse.swt.internal.Converter;
-import org.eclipse.swt.internal.gtk.OS;
-
-/**
- * <code>Transfer</code> provides a mechanism for converting between a java
- * representation of data and a platform specific representation of data and
- * vice versa. It is used in data transfer operations such as drag and drop and
- * clipboard copy/paste.
- *
- * <p>You should only need to become familiar with this class if you are
- * implementing a Transfer subclass and you are unable to subclass the
- * ByteArrayTransfer class.</p>
- *
- * @see ByteArrayTransfer
- * @see <a href="http://www.eclipse.org/swt/snippets/#dnd">Drag and Drop snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: DNDExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public abstract class Transfer {
-
-/**
- * Returns a list of the platform specific data types that can be converted using
- * this transfer agent.
- *
- * <p>Only the data type fields of the <code>TransferData</code> objects are filled
- * in.</p>
- *
- * @return a list of the data types that can be converted using this transfer agent
- */
-abstract public TransferData[] getSupportedTypes();
-
-/**
- * Returns true if the <code>TransferData</code> data type can be converted
- * using this transfer agent, or false otherwise (including if transferData is
- * <code>null</code>).
- *
- * @param transferData a platform specific description of a data type; only the data
- * type fields of the <code>TransferData</code> object need to be filled in
- *
- * @return true if the transferData data type can be converted using this transfer
- * agent
- */
-abstract public boolean isSupportedType(TransferData transferData);
-
-/**
- * Returns the platform specific names of the data types that can be converted
- * using this transfer agent.
- *
- * @return the platform specific names of the data types that can be converted
- * using this transfer agent.
- */
-abstract protected String[] getTypeNames();
-
-/**
- * Returns the platform specific ids of the data types that can be converted using
- * this transfer agent.
- *
- * @return the platform specific ids of the data types that can be converted using
- * this transfer agent
- */
-abstract protected int[] getTypeIds();
-
-/**
- * Converts a java representation of data to a platform specific representation of
- * the data.
- *
- * <p>On a successful conversion, the transferData.result field will be set as follows:
- * <ul>
- * <li>Windows: COM.S_OK
- * <li>Motif: 1
- * <li>GTK: 1
- * <li>Photon: 1
- * </ul></p>
- *
- * <p>If this transfer agent is unable to perform the conversion, the transferData.result
- * field will be set to a failure value as follows:
- * <ul>
- * <li>Windows: COM.DV_E_TYMED or COM.E_FAIL
- * <li>Motif: 0
- * <li>GTK: 0
- * <li>Photon: 0
- * </ul></p>
- *
- * @param object a java representation of the data to be converted; the type of
- * Object that is passed in is dependent on the <code>Transfer</code> subclass.
- *
- * @param transferData an empty TransferData object; this object will be
- * filled in on return with the platform specific representation of the data
- *
- * @exception org.eclipse.swt.SWTException <ul>
- * <li>ERROR_INVALID_DATA - if object does not contain data in a valid format or is <code>null</code></li>
- * </ul>
- */
-abstract protected void javaToNative (Object object, TransferData transferData);
-
-/**
- * Converts a platform specific representation of data to a java representation.
- *
- * @param transferData the platform specific representation of the data to be
- * converted
- *
- * @return a java representation of the converted data if the conversion was
- * successful; otherwise null. If transferData is <code>null</code> then
- * <code>null</code> is returned. The type of Object that is returned is
- * dependent on the <code>Transfer</code> subclass.
- */
-abstract protected Object nativeToJava(TransferData transferData);
-
-/**
- * Registers a name for a data type and returns the associated unique identifier.
- *
- * <p>You may register the same type more than once, the same unique identifier
- * will be returned if the type has been previously registered.</p>
- *
- * <p>Note: On windows, do <b>not</b> call this method with pre-defined
- * Clipboard Format types such as CF_TEXT or CF_BITMAP because the
- * pre-defined identifier will not be returned</p>
- *
- * @param formatName the name of a data type
- *
- * @return the unique identifier associated with this data type
- */
-public static int registerType(String formatName){
- if (formatName == null) return OS.GDK_NONE;
- byte[] buffer = Converter.wcsToMbcs(null, formatName, true);
- return (int)/*64*/OS.gdk_atom_intern(buffer, false);
-}
-
-/**
- * Test that the object is of the correct format for this Transfer class.
- *
- * @param object a java representation of the data to be converted
- *
- * @return true if object is of the correct form for this transfer type
- *
- * @since 3.1
- */
-protected boolean validate(Object object) {
- return true;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TransferData.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TransferData.java
deleted file mode 100644
index 275a9da91e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TransferData.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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 org.eclipse.swt.dnd;
-
-
-/**
- * The <code>TransferData</code> class is a platform specific data structure for
- * describing the type and the contents of data being converted by a transfer agent.
- *
- * <p>As an application writer, you do not need to know the specifics of
- * TransferData. TransferData instances are passed to a subclass of Transfer
- * and the Transfer object manages the platform specific issues.
- * You can ask a Transfer subclass if it can handle this data by calling
- * Transfer.isSupportedType(transferData).</p>
- *
- * <p>You should only need to become familiar with the fields in this class if you
- * are implementing a Transfer subclass and you are unable to subclass the
- * ByteArrayTransfer class.</p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- */
-public class TransferData {
- /**
- * The type is a unique identifier of a system format or user defined format.
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ type;
-
- /**
- * Specifies the number of units in pValue.
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- *
- * @see TransferData#format for the size of one unit
- */
- public int length;
-
- /**
- * Specifies the size in bits of a single unit in pValue.
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- *
- * This is most commonly 8 bits.
- */
- public int format;
-
- /**
- * Pointer to the data being transferred.
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- */
- public int /*long*/ pValue;
-
- /**
- * The result field contains the result of converting a
- * java data type into a platform specific value.
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- * <p>The value of result is 1 if the conversion was successful.
- * The value of result is 0 if the conversion failed.</p>
- */
- public int result;
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDragSourceEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDragSourceEffect.java
deleted file mode 100644
index f6e0067a4a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDragSourceEffect.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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 org.eclipse.swt.dnd;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * This class provides default implementations to display a source image
- * when a drag is initiated from a <code>Tree</code>.
- *
- * <p>Classes that wish to provide their own source image for a <code>Tree</code> can
- * extend <code>TreeDragSourceEffect</code> class and override the <code>TreeDragSourceEffect.dragStart</code>
- * method and set the field <code>DragSourceEvent.image</code> with their own image.</p>
- *
- * Subclasses that override any methods of this class must call the corresponding
- * <code>super</code> method to get the default drag under effect implementation.
- *
- * @see DragSourceEffect
- * @see DragSourceEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- */
-public class TreeDragSourceEffect extends DragSourceEffect {
- Image dragSourceImage = null;
-
- /**
- * Creates a new <code>TreeDragSourceEffect</code> to handle drag effect
- * from the specified <code>Tree</code>.
- *
- * @param tree the <code>Tree</code> that the user clicks on to initiate the drag
- */
- public TreeDragSourceEffect(Tree tree) {
- super(tree);
- }
-
- /**
- * This implementation of <code>dragFinished</code> disposes the image
- * that was created in <code>TreeDragSourceEffect.dragStart</code>.
- *
- * Subclasses that override this method should call <code>super.dragFinished(event)</code>
- * to dispose the image in the default implementation.
- *
- * @param event the information associated with the drag finished event
- */
- public void dragFinished(DragSourceEvent event) {
- if (dragSourceImage != null) dragSourceImage.dispose();
- dragSourceImage = null;
- }
-
- /**
- * This implementation of <code>dragStart</code> will create a default
- * image that will be used during the drag. The image should be disposed
- * when the drag is completed in the <code>TreeDragSourceEffect.dragFinished</code>
- * method.
- *
- * Subclasses that override this method should call <code>super.dragStart(event)</code>
- * to use the image from the default implementation.
- *
- * @param event the information associated with the drag start event
- */
- public void dragStart(DragSourceEvent event) {
- event.image = getDragSourceImage(event);
- }
-
- Image getDragSourceImage(DragSourceEvent event) {
- if (dragSourceImage != null) dragSourceImage.dispose();
- dragSourceImage = null;
-
- Tree tree = (Tree) control;
- if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) return null;
- //TEMPORARY CODE
- if (tree.isListening(SWT.EraseItem) || tree.isListening (SWT.PaintItem)) return null;
- /*
- * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults
- * in versions smaller than 2.2.4 if the model is NULL. The fix is
- * to give a valid pointer instead.
- */
- int /*long*/ handle = tree.handle;
- int /*long*/ selection = OS.gtk_tree_view_get_selection (handle);
- int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null;
- int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model);
- if (list == 0) return null;
- int count = Math.min(10, OS.g_list_length (list));
-
- Display display = tree.getDisplay();
- if (count == 1) {
- int /*long*/ path = OS.g_list_nth_data (list, 0);
- int /*long*/ pixmap = OS.gtk_tree_view_create_row_drag_icon(handle, path);
- dragSourceImage = Image.gtk_new(display, SWT.ICON, pixmap, 0);
- } else {
- int width = 0, height = 0;
- int[] w = new int[1], h = new int[1];
- int[] yy = new int[count], hh = new int[count];
- int /*long*/ [] pixmaps = new int /*long*/ [count];
- GdkRectangle rect = new GdkRectangle ();
- for (int i=0; i<count; i++) {
- int /*long*/ path = OS.g_list_nth_data (list, i);
- OS.gtk_tree_view_get_cell_area (handle, path, 0, rect);
- pixmaps[i] = OS.gtk_tree_view_create_row_drag_icon(handle, path);
- OS.gdk_drawable_get_size(pixmaps[i], w, h);
- width = Math.max(width, w[0]);
- height = rect.y + h[0] - yy[0];
- yy[i] = rect.y;
- hh[i] = h[0];
- }
- int /*long*/ source = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, -1);
- int /*long*/ gcSource = OS.gdk_gc_new(source);
- int /*long*/ mask = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, 1);
- int /*long*/ gcMask = OS.gdk_gc_new(mask);
- GdkColor color = new GdkColor();
- color.pixel = 0;
- OS.gdk_gc_set_foreground(gcMask, color);
- OS.gdk_draw_rectangle(mask, gcMask, 1, 0, 0, width, height);
- color.pixel = 1;
- OS.gdk_gc_set_foreground(gcMask, color);
- for (int i=0; i<count; i++) {
- OS.gdk_draw_drawable(source, gcSource, pixmaps[i], 0, 0, 0, yy[i] - yy[0], -1, -1);
- OS.gdk_draw_rectangle(mask, gcMask, 1, 0, yy[i] - yy[0], width, hh[i]);
- OS.g_object_unref(pixmaps[i]);
- }
- OS.g_object_unref(gcSource);
- OS.g_object_unref(gcMask);
- dragSourceImage = Image.gtk_new(display, SWT.ICON, source, mask);
- }
- OS.g_list_free (list);
-
- return dragSourceImage;
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDropTargetEffect.java
deleted file mode 100644
index ace9718800..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TreeDropTargetEffect.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 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 org.eclipse.swt.dnd;
-
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.widgets.*;
-
-/**
- * This class provides a default drag under effect (eg. select, insert, scroll and expand)
- * when a drag occurs over a <code>Tree</code>.
- *
- * <p>Classes that wish to provide their own drag under effect for a <code>Tree</code>
- * can extend the <code>TreeDropTargetEffect</code> class and override any applicable methods
- * in <code>TreeDropTargetEffect</code> to display their own drag under effect.</p>
- *
- * Subclasses that override any methods of this class must call the corresponding
- * <code>super</code> method to get the default drag under effect implementation.
- *
- * <p>The feedback value is either one of the FEEDBACK constants defined in
- * class <code>DND</code> which is applicable to instances of this class,
- * or it must be built by <em>bitwise OR</em>'ing together
- * (that is, using the <code>int</code> "|" operator) two or more
- * of those <code>DND</code> effect constants.
- * </p>
- * <p>
- * <dl>
- * <dt><b>Feedback:</b></dt>
- * <dd>FEEDBACK_SELECT, FEEDBACK_INSERT_BEFORE, FEEDBACK_INSERT_AFTER, FEEDBACK_EXPAND, FEEDBACK_SCROLL</dd>
- * </dl>
- * </p><p>
- * Note: Only one of the styles FEEDBACK_SELECT, FEEDBACK_INSERT_BEFORE or
- * FEEDBACK_INSERT_AFTER may be specified.
- * </p>
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.3
- */
-public class TreeDropTargetEffect extends DropTargetEffect {
- static final int SCROLL_HYSTERESIS = 150; // milli seconds
- static final int EXPAND_HYSTERESIS = 1000; // milli seconds
-
- int scrollIndex = -1;
- long scrollBeginTime;
-
- int expandIndex = -1;
- long expandBeginTime;
-
- /**
- * Creates a new <code>TreeDropTargetEffect</code> to handle the drag under effect on the specified
- * <code>Tree</code>.
- *
- * @param tree the <code>Tree</code> over which the user positions the cursor to drop the data
- */
- public TreeDropTargetEffect(Tree tree) {
- super(tree);
- }
-
- int checkEffect(int effect) {
- // Some effects are mutually exclusive. Make sure that only one of the mutually exclusive effects has been specified.
- if ((effect & DND.FEEDBACK_SELECT) != 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER & ~DND.FEEDBACK_INSERT_BEFORE;
- if ((effect & DND.FEEDBACK_INSERT_BEFORE) != 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER;
- return effect;
- }
-
- /**
- * This implementation of <code>dragEnter</code> provides a default drag under effect
- * for the feedback specified in <code>event.feedback</code>.
- *
- * For additional information see <code>DropTargetAdapter.dragEnter</code>.
- *
- * Subclasses that override this method should call <code>super.dragEnter(event)</code>
- * to get the default drag under effect implementation.
- *
- * @param event the information associated with the drag enter event
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- */
- public void dragEnter(DropTargetEvent event) {
- expandBeginTime = 0;
- expandIndex = -1;
- scrollBeginTime = 0;
- scrollIndex = -1;
- }
-
- /**
- * This implementation of <code>dragLeave</code> provides a default drag under effect
- * for the feedback specified in <code>event.feedback</code>.
- *
- * For additional information see <code>DropTargetAdapter.dragLeave</code>.
- *
- * Subclasses that override this method should call <code>super.dragLeave(event)</code>
- * to get the default drag under effect implementation.
- *
- * @param event the information associated with the drag leave event
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- */
- public void dragLeave(DropTargetEvent event) {
- Tree tree = (Tree) control;
- int /*long*/ handle = tree.handle;
- OS.gtk_tree_view_set_drag_dest_row(handle, 0, OS.GTK_TREE_VIEW_DROP_BEFORE);
-
- scrollBeginTime = 0;
- scrollIndex = -1;
- expandBeginTime = 0;
- expandIndex = -1;
- }
-
- /**
- * This implementation of <code>dragOver</code> provides a default drag under effect
- * for the feedback specified in <code>event.feedback</code>.
- *
- * For additional information see <code>DropTargetAdapter.dragOver</code>.
- *
- * Subclasses that override this method should call <code>super.dragOver(event)</code>
- * to get the default drag under effect implementation.
- *
- * @param event the information associated with the drag over event
- *
- * @see DropTargetAdapter
- * @see DropTargetEvent
- * @see DND#FEEDBACK_SELECT
- * @see DND#FEEDBACK_INSERT_BEFORE
- * @see DND#FEEDBACK_INSERT_AFTER
- * @see DND#FEEDBACK_SCROLL
- */
- public void dragOver(DropTargetEvent event) {
- Tree tree = (Tree) control;
- int effect = checkEffect(event.feedback);
-
- int /*long*/ handle = tree.handle;
- Point coordinates = new Point(event.x, event.y);
- coordinates = tree.toControl(coordinates);
- int /*long*/ [] path = new int /*long*/ [1];
- OS.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, path, null, null, null);
- int index = -1;
- if (path[0] != 0) {
- int /*long*/ indices = OS.gtk_tree_path_get_indices(path[0]);
- if (indices != 0) {
- int depth = OS.gtk_tree_path_get_depth(path[0]);
- int[] temp = new int[depth];
- OS.memmove (temp, indices, temp.length * 4);
- index = temp[temp.length - 1];
- }
- }
- if ((effect & DND.FEEDBACK_SCROLL) == 0) {
- scrollBeginTime = 0;
- scrollIndex = -1;
- } else {
- if (index != -1 && scrollIndex == index && scrollBeginTime != 0) {
- if (System.currentTimeMillis() >= scrollBeginTime) {
- GdkRectangle cellRect = new GdkRectangle ();
- OS.gtk_tree_view_get_cell_area (handle, path[0], 0, cellRect);
- if (cellRect.y < cellRect.height) {
- int[] tx = new int[1], ty = new int[1];
- OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y - cellRect.height, tx, ty);
- OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]);
- } else {
- //scroll down
- OS.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y + cellRect.height, path, null, null, null);
- if (path[0] != 0) {
- OS.gtk_tree_view_scroll_to_cell(handle, path[0], 0, false, 0, 0);
- OS.gtk_tree_path_free(path[0]);
- path[0] = 0;
- }
- OS.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, path, null, null, null);
- }
- scrollBeginTime = 0;
- scrollIndex = -1;
- }
- } else {
- scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS;
- scrollIndex = index;
- }
- }
- if ((effect & DND.FEEDBACK_EXPAND) == 0) {
- expandBeginTime = 0;
- expandIndex = -1;
- } else {
- if (index != -1 && expandIndex == index && expandBeginTime != 0) {
- if (System.currentTimeMillis() >= expandBeginTime) {
- OS.gtk_tree_view_expand_row (handle, path[0], false);
- expandBeginTime = 0;
- expandIndex = -1;
- }
- } else {
- expandBeginTime = System.currentTimeMillis() + EXPAND_HYSTERESIS;
- expandIndex = index;
- }
- }
- if (path[0] != 0) {
- int position = -1;
- if ((effect & DND.FEEDBACK_SELECT) != 0) position = OS.GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
- if ((effect & DND.FEEDBACK_INSERT_BEFORE) != 0) position = OS.GTK_TREE_VIEW_DROP_BEFORE;
- if ((effect & DND.FEEDBACK_INSERT_AFTER) != 0) position = OS.GTK_TREE_VIEW_DROP_AFTER;
- if (position != -1) {
- OS.gtk_tree_view_set_drag_dest_row(handle, path[0], position);
- } else {
- OS.gtk_tree_view_set_drag_dest_row(handle, 0, OS.GTK_TREE_VIEW_DROP_BEFORE);
- }
- } else {
- OS.gtk_tree_view_set_drag_dest_row(handle, 0, OS.GTK_TREE_VIEW_DROP_BEFORE);
- }
-
- if (path[0] != 0) OS.gtk_tree_path_free (path [0]);
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/URLTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/URLTransfer.java
deleted file mode 100644
index 63226b1416..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/URLTransfer.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 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 org.eclipse.swt.dnd;
-
-import org.eclipse.swt.internal.gtk.*;
-
-/**
- * The class <code>URLTransfer</code> provides a platform specific mechanism
- * for converting text in URL format represented as a java <code>String</code>
- * to a platform specific representation of the data and vice versa. The string
- * must contain a fully specified url.
- *
- * <p>An example of a java <code>String</code> containing a URL is shown below:</p>
- *
- * <code><pre>
- * String url = "http://www.eclipse.org";
- * </code></pre>
- *
- * @see Transfer
- * @since 3.4
- */
-public class URLTransfer extends ByteArrayTransfer {
-
- static URLTransfer _instance = new URLTransfer();
- private static final String TEXT_UNICODE = "text/unicode"; //$NON-NLS-1$
- private static final String TEXT_XMOZURL = "text/x-moz-url"; //$NON-NLS-1$
- private static final int TEXT_UNICODE_ID = registerType(TEXT_UNICODE);
- private static final int TEXT_XMOZURL_ID = registerType(TEXT_XMOZURL);
-
-private URLTransfer() {}
-
-/**
- * Returns the singleton instance of the URLTransfer class.
- *
- * @return the singleton instance of the URLTransfer class
- */
-public static URLTransfer getInstance () {
- return _instance;
-}
-
-/**
- * This implementation of <code>javaToNative</code> converts a URL
- * represented by a java <code>String</code> to a platform specific representation.
- *
- * @param object a java <code>String</code> containing a URL
- * @param transferData an empty <code>TransferData</code> object that will
- * be filled in on return with the platform specific format of the data
- *
- * @see Transfer#nativeToJava
- */
-public void javaToNative (Object object, TransferData transferData){
- transferData.result = 0;
- if (!checkURL(object) || !isSupportedType(transferData)) {
- DND.error(DND.ERROR_INVALID_DATA);
- }
- String string = (String)object;
- int charCount = string.length();
- char [] chars = new char[charCount +1];
- string.getChars(0, charCount , chars, 0);
- int byteCount = chars.length*2;
- int /*long*/ pValue = OS.g_malloc(byteCount);
- if (pValue == 0) return;
- OS.memmove(pValue, chars, byteCount);
- transferData.length = byteCount;
- transferData.format = 8;
- transferData.pValue = pValue;
- transferData.result = 1;
-}
-
-/**
- * This implementation of <code>nativeToJava</code> converts a platform
- * specific representation of a URL to a java <code>String</code>.
- *
- * @param transferData the platform specific representation of the data to be converted
- * @return a java <code>String</code> containing a URL if the conversion was successful;
- * otherwise null
- *
- * @see Transfer#javaToNative
- */
-public Object nativeToJava(TransferData transferData){
- if (!isSupportedType(transferData) || transferData.pValue == 0) return null;
- /* Ensure byteCount is a multiple of 2 bytes */
- int size = (transferData.format * transferData.length / 8) / 2 * 2;
- if (size <= 0) return null;
- char[] chars = new char [size/2];
- OS.memmove (chars, transferData.pValue, size);
- String string = new String (chars);
- int end = string.indexOf('\0');
- return (end == -1) ? string : string.substring(0, end);
-}
-
-protected int[] getTypeIds(){
- return new int[] {TEXT_XMOZURL_ID, TEXT_UNICODE_ID};
-}
-
-protected String[] getTypeNames(){
- return new String[] {TEXT_XMOZURL, TEXT_UNICODE};
-}
-
-boolean checkURL(Object object) {
- return object != null && (object instanceof String) && ((String)object).length() > 0;
-}
-
-protected boolean validate(Object object) {
- return checkURL(object);
-}
-}