diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org')
17 files changed, 0 insertions, 4304 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/ByteArrayTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/ByteArrayTransfer.java deleted file mode 100755 index 000bf58658..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/ByteArrayTransfer.java +++ /dev/null @@ -1,188 +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.motif.*; - -/** - * 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 < 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; - int pValue = OS.XtMalloc(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/motif/org/eclipse/swt/dnd/Clipboard.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Clipboard.java deleted file mode 100755 index 7c0068a0f2..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Clipboard.java +++ /dev/null @@ -1,545 +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.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.widgets.*; - -/** - * 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 { - - Display display; - -/** - * 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); - ClipboardProxy proxy = ClipboardProxy._getInstance(display); - Object result = null; - if ((clipboards & DND.CLIPBOARD) != 0) { - result = proxy.getContents(transfer, DND.CLIPBOARD); - } - if (result != null) return result; - if ((clipboards & DND.SELECTION_CLIPBOARD) != 0) { - result = proxy.getContents(transfer, DND.SELECTION_CLIPBOARD); - } - 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); -} - -/** - * 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(); - ClipboardProxy proxy = ClipboardProxy._getInstance(display); - int[] types = null; - if ((clipboards & DND.CLIPBOARD) != 0) { - types = proxy.getAvailableTypes(DND.CLIPBOARD); - } - if ((clipboards & DND.SELECTION_CLIPBOARD) != 0) { - int[] primaryTypes = proxy.getAvailableTypes(DND.SELECTION_CLIPBOARD); - if (types == null) { - types = primaryTypes; - } else { - int[] newTypes = new int[types.length + primaryTypes.length]; - System.arraycopy(types, 0, newTypes, 0, types.length); - System.arraycopy(primaryTypes, 0, newTypes, types.length, primaryTypes.length); - types = newTypes; - } - } - if (types == null) return new TransferData[0]; - TransferData[] result = new TransferData[types.length]; - for (int i = 0; i < types.length; i++) { - result[i] = new TransferData(); - result[i].type = types[i]; - } - return 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(); - ClipboardProxy proxy = ClipboardProxy._getInstance(display); - int[] types = proxy.getAvailableTypes(DND.CLIPBOARD); - int[] primaryTypes = proxy.getAvailableTypes(DND.SELECTION_CLIPBOARD); - String[] names = new String[types.length + primaryTypes.length]; - int index = 0; - int xDisplay = display.xDisplay; - for (int i = 0; i < types.length; i++) { - int ptr = OS.XmGetAtomName(xDisplay, types[i]); - int length = OS.strlen(ptr); - byte[] nameBuf = new byte[length]; - OS.memmove(nameBuf, ptr, length); - OS.XtFree(ptr); - /* Use the character encoding for the default locale */ - String name = new String(Converter.mbcsToWcs(null, nameBuf)); - names[index++] = "CLIPBOARD "+name; - } - for (int i = 0; i < primaryTypes.length; i++) { - int ptr = OS.XmGetAtomName(xDisplay, primaryTypes[i]); - int length = OS.strlen(ptr); - byte[] nameBuf = new byte[length]; - OS.memmove(nameBuf, ptr, length); - OS.XtFree(ptr); - /* Use the character encoding for the default locale */ - String name = new String(Converter.mbcsToWcs(null, nameBuf)); - names[index++] = "PRIMARY "+name; - } - return names; -} - -/** - * 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); - proxy.setContents(this, data, dataTypes, clipboards); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/ClipboardProxy.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/ClipboardProxy.java deleted file mode 100644 index 3af544be46..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/ClipboardProxy.java +++ /dev/null @@ -1,393 +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.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.widgets.*; - -class ClipboardProxy { - - Display display; - int shellHandle; - int atomAtom, clipboardAtom, motifClipboardAtom, primaryAtom, targetsAtom; - int[][] convertData = new int[10][3]; - Clipboard activeClipboard = null; - Clipboard activePrimaryClipboard = null; - Object[] clipboardData; - Transfer[] clipboardDataTypes; - Object[] primaryClipboardData; - Transfer[] primaryClipboardDataTypes; - - boolean done = false; - Object selectionValue; - Transfer selectionTransfer; - - Callback XtConvertSelectionCallback; - Callback XtLoseSelectionCallback; - Callback XtSelectionDoneCallback; - Callback XtSelectionCallbackCallback; - - static byte [] ATOM = Converter.wcsToMbcs (null, "ATOM", true); //$NON-NLS-1$ - static byte [] CLIPBOARD = Converter.wcsToMbcs (null, "CLIPBOARD", true); //$NON-NLS-1$ - static byte [] PRIMARY = Converter.wcsToMbcs (null, "PRIMARY", true); //$NON-NLS-1$ - static byte [] TARGETS = Converter.wcsToMbcs (null, "TARGETS", true); //$NON-NLS-1$ - static byte [] _MOTIF_CLIPBOARD_TARGETS = Converter.wcsToMbcs (null, "_MOTIF_CLIPBOARD_TARGETS", true); //$NON-NLS-1$ - 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; - XtConvertSelectionCallback = new Callback(this, "XtConvertSelection", 7); //$NON-NLS-1$ - if (XtConvertSelectionCallback.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - XtLoseSelectionCallback = new Callback(this, "XtLoseSelection", 2); //$NON-NLS-1$ - if (XtLoseSelectionCallback.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - XtSelectionDoneCallback = new Callback(this, "XtSelectionDone", 3); //$NON-NLS-1$ - if (XtSelectionDoneCallback.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - XtSelectionCallbackCallback = new Callback(this, "XtSelectionCallback", 7); //$NON-NLS-1$ - if (XtSelectionCallbackCallback.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - - int widgetClass = OS.topLevelShellWidgetClass (); - shellHandle = OS.XtAppCreateShell (null, null, widgetClass, display.xDisplay, null, 0); - OS.XtSetMappedWhenManaged (shellHandle, false); - OS.XtRealizeWidget (shellHandle); - int xDisplay = OS.XtDisplay(shellHandle); - atomAtom = OS.XmInternAtom(xDisplay, ATOM, true); - clipboardAtom = OS.XmInternAtom(xDisplay, CLIPBOARD, true); - motifClipboardAtom = OS.XmInternAtom(xDisplay, _MOTIF_CLIPBOARD_TARGETS, true); - primaryAtom = OS.XmInternAtom(xDisplay, PRIMARY, true); - targetsAtom = OS.XmInternAtom(xDisplay, TARGETS, true); -} - - - void clear(Clipboard owner, int clipboards) { - int xDisplay = OS.XtDisplay(shellHandle); - if (xDisplay == 0) return; - if ((clipboards & DND.CLIPBOARD) != 0 && activeClipboard == owner) { - OS.XtDisownSelection(shellHandle, clipboardAtom, OS.CurrentTime); - } - if ((clipboards & DND.SELECTION_CLIPBOARD) != 0 && activePrimaryClipboard == owner) { - OS.XtDisownSelection(shellHandle, primaryAtom, OS.CurrentTime); - } -} - - void dispose () { - if (display == null) return; - if (shellHandle != 0) { - OS.XtDestroyWidget (shellHandle); - shellHandle = 0; - } - if (XtConvertSelectionCallback != null) XtConvertSelectionCallback.dispose(); - XtConvertSelectionCallback = null; - if (XtLoseSelectionCallback != null) XtLoseSelectionCallback.dispose(); - XtLoseSelectionCallback = null; - if (XtSelectionCallbackCallback != null) XtSelectionCallbackCallback.dispose(); - XtSelectionCallbackCallback = null; - if (XtSelectionDoneCallback != null) XtSelectionDoneCallback.dispose(); - XtSelectionDoneCallback = null; - activeClipboard = null; - activePrimaryClipboard = null; - clipboardData = null; - clipboardDataTypes = null; - primaryClipboardData = null; - primaryClipboardDataTypes = null; -} - -Object getContents(Transfer transfer, int clipboardType) { - int[] types = getAvailableTypes(clipboardType); - int index = -1; - TransferData transferData = new TransferData(); - for (int i = 0; i < types.length; i++) { - transferData.type = types[i]; - if (transfer.isSupportedType(transferData)) { - index = i; - break; - } - } - if (index == -1) return null; - done = false; - selectionValue = null; selectionTransfer = transfer; - int selection = clipboardType == DND.CLIPBOARD ? clipboardAtom : primaryAtom; - OS.XtGetSelectionValue(shellHandle, selection, types[index], XtSelectionCallbackCallback.getAddress(), 0, OS.CurrentTime); - if (!done) { - int xDisplay = OS.XtDisplay (shellHandle); - if (xDisplay == 0) return null; - int xtContext = OS.XtDisplayToApplicationContext(xDisplay); - int selectionTimeout = OS.XtAppGetSelectionTimeout(xtContext); - wait(selectionTimeout); - } - return (!done) ? null : selectionValue; -} - -int[] getAvailableTypes(int clipboardType) { - int xDisplay = OS.XtDisplay (shellHandle); - if (xDisplay == 0) return new int[0]; - done = false; - selectionValue = null; selectionTransfer = null; - int selection = clipboardType == DND.CLIPBOARD ? clipboardAtom : primaryAtom; - int target = targetsAtom; - OS.XtGetSelectionValue(shellHandle, selection, target, XtSelectionCallbackCallback.getAddress(), 0, OS.CurrentTime); - if (!done) { - int xtContext = OS.XtDisplayToApplicationContext(xDisplay); - int selectionTimeout = OS.XtAppGetSelectionTimeout(xtContext); - wait(selectionTimeout); - - } - if (done && selectionValue == null) { - done = false; - target = motifClipboardAtom; - OS.XtGetSelectionValue(shellHandle, selection, target, XtSelectionCallbackCallback.getAddress(), 0, OS.CurrentTime); - if (!done) { - int xtContext = OS.XtDisplayToApplicationContext(xDisplay); - int selectionTimeout = OS.XtAppGetSelectionTimeout(xtContext); - wait(selectionTimeout); - - } - } - if (done && selectionValue == null) { - done = false; - target = atomAtom; - OS.XtGetSelectionValue(shellHandle, selection, target, XtSelectionCallbackCallback.getAddress(), 0, OS.CurrentTime); - if (!done) { - int xtContext = OS.XtDisplayToApplicationContext(xDisplay); - int selectionTimeout = OS.XtAppGetSelectionTimeout(xtContext); - wait(selectionTimeout); - - } - } - return (!done || selectionValue == null) ? new int[0] : (int[])selectionValue; -} - -void setContents(Clipboard owner, Object[] data, Transfer[] dataTypes, int clipboards) { - if ((clipboards & DND.CLIPBOARD) != 0) { - clipboardData = data; - clipboardDataTypes = dataTypes; - int XtConvertSelectionProc = XtConvertSelectionCallback.getAddress(); - int XtLoseSelectionProc = XtLoseSelectionCallback.getAddress(); - int XtSelectionDoneProc = XtSelectionDoneCallback.getAddress(); - if (!OS.XtOwnSelection(shellHandle, clipboardAtom, OS.CurrentTime, XtConvertSelectionProc, XtLoseSelectionProc, XtSelectionDoneProc)) { - DND.error(DND.ERROR_CANNOT_SET_CLIPBOARD); - } - activeClipboard = owner; - } - if ((clipboards & DND.SELECTION_CLIPBOARD) != 0) { - primaryClipboardData = data; - primaryClipboardDataTypes = dataTypes; - int XtConvertSelectionProc = XtConvertSelectionCallback.getAddress(); - int XtLoseSelectionProc = XtLoseSelectionCallback.getAddress(); - int XtSelectionDoneProc = XtSelectionDoneCallback.getAddress(); - if (!OS.XtOwnSelection(shellHandle, primaryAtom, OS.CurrentTime, XtConvertSelectionProc, XtLoseSelectionProc, XtSelectionDoneProc)) { - DND.error(DND.ERROR_CANNOT_SET_CLIPBOARD); - } - activePrimaryClipboard = owner; - } -} - -void storePtr(int ptr, int selection, int target) { - int index = -1; - for (int i = 0; i < convertData.length; i++) { - if (convertData[i][0] == 0){ - index = i; - break; - } - } - if (index == -1) { - int[][] newConvertData = new int[convertData.length + 4][3]; - System.arraycopy(convertData, 0, newConvertData, 0, convertData.length); - index = convertData.length; - convertData = newConvertData; - } - convertData[index][0] = selection; - convertData[index][1] = target; - convertData[index][2] = ptr; -} - -void wait(int timeout) { - int xDisplay = OS.XtDisplay(shellHandle); - if (xDisplay == 0) return; - long start = System.currentTimeMillis(); - Callback checkEventCallback = new Callback(this, "checkEvent", 3); //$NON-NLS-1$ - int checkEventProc = checkEventCallback.getAddress(); - if (checkEventProc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - int xEvent = OS.XtMalloc (XEvent.sizeof); - display.timerExec(timeout, new Runnable() { - public void run() { - // timer required to force display.sleep() to wake up - // in the case where no events are received - } - }); - while (!done && System.currentTimeMillis() - start < timeout && display != null) { - if (OS.XCheckIfEvent (xDisplay, xEvent, checkEventProc, 0) != 0) { - OS.XtDispatchEvent(xEvent); - } else { - display.sleep(); - } - } - OS.XtFree (xEvent); - checkEventCallback.dispose(); -} -int checkEvent(int display, int event, int arg) { - XEvent xEvent = new XEvent(); - OS.memmove (xEvent, event, XEvent.sizeof); - switch (xEvent.type) { - case OS.SelectionClear: - case OS.SelectionNotify: - case OS.SelectionRequest: - case OS.PropertyNotify: - return 1; - } - return 0; -} -int XtConvertSelection(int widget, int selection, int target, int type, int value, int length, int format) { - int selectionAtom = 0; - if (selection != 0) { - int[] dest = new int[1]; - OS.memmove(dest, selection, 4); - selectionAtom = dest[0]; - } - if (selectionAtom == 0) return 0; - Transfer[] types = null; - if (selectionAtom == clipboardAtom) types = clipboardDataTypes; - if (selectionAtom == primaryAtom) types = primaryClipboardDataTypes; - if (types == null) return 0; - - int targetAtom = 0; - if (target != 0) { - int[] dest = new int[1]; - OS.memmove(dest, target, 4); - targetAtom = dest[0]; - } - if (targetAtom == atomAtom || - targetAtom == targetsAtom || - targetAtom == motifClipboardAtom) { - int[] transferTypes = new int[] {targetAtom}; - for (int i = 0; i < types.length; i++) { - TransferData[] subTypes = types[i].getSupportedTypes(); - int[] newtransferTypes = new int[transferTypes.length + subTypes.length]; - System.arraycopy(transferTypes, 0, newtransferTypes, 0, transferTypes.length); - int index = transferTypes.length; - transferTypes = newtransferTypes; - for (int j = 0; j < subTypes.length; j++) { - transferTypes[index++] = subTypes[j].type; - } - } - int ptr = OS.XtMalloc(transferTypes.length*4); - storePtr(ptr, selectionAtom, targetAtom); - OS.memmove(ptr, transferTypes, transferTypes.length*4); - OS.memmove(type, new int[]{targetAtom}, 4); - OS.memmove(value, new int[] {ptr}, 4); - OS.memmove(length, new int[]{transferTypes.length}, 4); - OS.memmove(format, new int[]{32}, 4); - return 1; - } - - TransferData tdata = new TransferData(); - tdata.type = targetAtom; - 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 = selectionAtom == clipboardAtom ? clipboardData : primaryClipboardData; - types[index].javaToNative(data[index], tdata); - if (tdata.format < 8 || tdata.format % 8 != 0) { - OS.XtFree(tdata.pValue); - return 0; - } - // copy data back to value - OS.memmove(type, new int[]{tdata.type}, 4); - OS.memmove(value, new int[]{tdata.pValue}, 4); - OS.memmove(length, new int[]{tdata.length}, 4); - OS.memmove(format, new int[]{tdata.format}, 4); - storePtr(tdata.pValue, selectionAtom, targetAtom); - return 1; -} - -int XtLoseSelection(int widget, int selection) { - if (selection == clipboardAtom) { - activeClipboard = null; - clipboardData = null; - clipboardDataTypes = null; - } - if (selection == primaryAtom) { - activePrimaryClipboard = null; - primaryClipboardData = null; - primaryClipboardDataTypes = null; - } - return 0; -} - -int XtSelectionCallback(int widget, int client_data, int selection, int type, int value, int length, int format) { - done = true; - int[] selectionType = new int[1]; - if (type != 0) OS.memmove(selectionType, type, 4); - if (selectionType[0] == 0) return 0; - int[] selectionLength = new int[1]; - if (length != 0) OS.memmove(selectionLength, length, 4); - if (selectionLength[0] == 0) return 0; - int[] selectionFormat = new int[1]; - if (format != 0) OS.memmove(selectionFormat, format, 4); - if (selectionType[0] == atomAtom || - selectionType[0] == targetsAtom || - selectionType[0] == motifClipboardAtom) { - int[] targets = new int[selectionLength[0]]; - OS.memmove(targets, value, selectionLength[0] * selectionFormat [0] / 8); - selectionValue = targets; - return 0; - } - if (selectionTransfer != null) { - TransferData transferData = new TransferData(); - transferData.type = selectionType[0]; - transferData.length = selectionLength[0]; - transferData.format = selectionFormat[0]; - transferData.pValue = value; - transferData.result = 1; - selectionValue = selectionTransfer.nativeToJava(transferData); - } - return 0; -} - -int XtSelectionDone(int widget, int selection, int target) { - if (target == 0 || selection == 0) return 0; - int[] selectionAtom = new int[1]; - OS.memmove(selectionAtom, selection, 4); - int[] targetAtom = new int[1]; - OS.memmove(targetAtom, target, 4); - for (int i = 0; i < convertData.length; i++) { - if (convertData[i][0] == selectionAtom[0] && convertData[i][1] == targetAtom[0]) { - OS.XtFree(convertData[i][2]); - convertData[i][0] = convertData[i][1] = convertData[i][2] = 0; - break; - } - } - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/DragSource.java deleted file mode 100755 index ccdc81e613..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/DragSource.java +++ /dev/null @@ -1,616 +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.widgets.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; - -/** - * - * <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; - - static final String DEFAULT_DRAG_SOURCE_EFFECT = "DEFAULT_DRAG_SOURCE_EFFECT"; //$NON-NLS-1$ - - static Callback ConvertProc; - static Callback DragDropFinish; - static Callback DropFinish; - static { - ConvertProc = new Callback(DragSource.class, "ConvertProcCallback", 10); //$NON-NLS-1$ - if (ConvertProc.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - DragDropFinish = new Callback(DragSource.class, "DragDropFinishCallback", 3); //$NON-NLS-1$ - if (DragDropFinish.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - DropFinish = new Callback(DragSource.class, "DropFinishCallback", 3); //$NON-NLS-1$ - if (DropFinish.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - } - boolean moveRequested; - - int dragContext; - -/** - * 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)); - if (ConvertProc == null || DragDropFinish == null || DropFinish == null) - DND.error(DND.ERROR_CANNOT_INIT_DRAG); - this.control = control; - if (control.getData(DND.DRAG_SOURCE_KEY) != null) - DND.error(DND.ERROR_CANNOT_INIT_DRAG); - control.setData(DND.DRAG_SOURCE_KEY, this); - - 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); - - this.addListener(SWT.Dispose, new Listener() { - public void handleEvent(Event e) { - onDispose(); - } - }); - - 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); - } -} -static DragSource FindDragSource(int handle) { - Display display = Display.findDisplay(Thread.currentThread()); - if (display == null || display.isDisposed()) return null; - return (DragSource)display.getData(Integer.toString(handle)); -} -static int ConvertProcCallback(int widget, int pSelection, int pTarget, int pType_return, int ppValue_return, int pLength_return, int pFormat_return, int max_length, int client_data, int request_id) { - DragSource source = FindDragSource(widget); - if (source == null) return 0; - return source.convertProcCallback(widget, pSelection, pTarget, pType_return, ppValue_return, pLength_return, pFormat_return, max_length, client_data, request_id); -} -static int DragDropFinishCallback(int widget, int client_data, int call_data) { - DragSource source = FindDragSource(widget); - if (source == null) return 0; - return source.dragDropFinishCallback(widget, client_data, call_data); -} -static int DropFinishCallback(int widget, int client_data, int call_data) { - DragSource source = FindDragSource(widget); - if (source == null) return 0; - return source.dropFinishCallback(widget, client_data, call_data); -} -/** - * 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); -} - -static int checkStyle (int style) { - if (style == SWT.NONE) return DND.DROP_MOVE; - return style; -} - -protected void checkSubclass () { - String name = getClass().getName (); - String validName = DragSource.class.getName(); - if (!validName.equals(name)) { - DND.error (SWT.ERROR_INVALID_SUBCLASS); - } -} - -int convertProcCallback(int widget, int pSelection, int pTarget, int pType_return, int ppValue_return, int pLength_return, int pFormat_return, int max_length, int client_data, int request_id) { - if (pSelection == 0 ) return 0; - - // is this a drop? - int[] selection = new int[1]; - OS.memmove(selection, pSelection, 4); - int xDisplay = getDisplay().xDisplay; - byte[] bName = Converter.wcsToMbcs (null, "_MOTIF_DROP", true); //$NON-NLS-1$ - int motifDropAtom = OS.XmInternAtom (xDisplay, bName, true); - if (selection[0] != motifDropAtom) return 0; - - // get the target value from pTarget - int[] target = new int[1]; - OS.memmove(target, pTarget, 4); - - // handle the "Move" case - bName = Converter.wcsToMbcs (null, "DELETE", true); // DELETE corresponds to a Move request //$NON-NLS-1$ - int deleteAtom = OS.XmInternAtom (xDisplay, bName, true); - if (target[0] == deleteAtom) { - moveRequested = true; - bName = Converter.wcsToMbcs (null, "NULL", true); //$NON-NLS-1$ - int nullAtom = OS.XmInternAtom (xDisplay, bName, true); - OS.memmove(pType_return,new int[]{nullAtom}, 4); - OS.memmove(ppValue_return, new int[]{0}, 4); - OS.memmove(pLength_return, new int[]{0}, 4); - OS.memmove(pFormat_return, new int[]{8}, 4); - return 1; - } - - // do we support the requested data type? - boolean dataMatch = false; - TransferData transferData = new TransferData(); - transferData.type = target[0]; - for (int i = 0; i < transferAgents.length; i++){ - Transfer transfer = transferAgents[i]; - if (transfer != null && transfer.isSupportedType(transferData)){ - dataMatch = true; - break; - } - } - if (!dataMatch) return 0; - - DNDEvent event = new DNDEvent(); - event.widget = control; - //event.time = ??; - event.dataType = transferData; - notifyListeners(DND.DragSetData,event); - - if (!event.doit) return 0; - Transfer transferAgent = null; - for (int i = 0; i < transferAgents.length; i++){ - Transfer transfer = transferAgents[i]; - if (transfer != null && transfer.isSupportedType(transferData)){ - transferAgent = transfer; - break; - } - } - if (transferAgent == null) return 0; - - transferAgent.javaToNative(event.data, transferData); - if (transferData.result == 1){ - OS.memmove(ppValue_return, new int[]{transferData.pValue}, 4); - OS.memmove(pType_return, new int[]{transferData.type}, 4); - OS.memmove(pLength_return, new int[]{transferData.length}, 4); - OS.memmove(pFormat_return, new int[]{transferData.format}, 4); - return 1; - } - OS.memmove(ppValue_return, new int[]{0}, 4); - OS.memmove(pLength_return, new int[]{0}, 4); - OS.memmove(pFormat_return, new int[]{8}, 4); - return 0; -} -void drag(Event dragEvent) { - moveRequested = false; - // Current event must be a Button Press event - Display display = control.getDisplay (); - XButtonEvent xEvent = new XButtonEvent(); - OS.memmove(xEvent, display.xEvent, XButtonEvent.sizeof); - if (xEvent.type != OS.ButtonPress) return; - - DNDEvent event = new DNDEvent(); - event.widget = this; - event.x = dragEvent.x; - event.y = dragEvent.y; - event.time = xEvent.time; - event.doit = true; - notifyListeners(DND.DragStart, event); - if (!event.doit || transferAgents == null || transferAgents.length == 0) { - int time = xEvent.time; - int dc = OS.XmGetDragContext(control.handle, time); - if (dc != 0){ - OS.XmDragCancel(dc); - } - return; - } - - // set the protocol (optional) - // not implemented - - // create pixmaps for icons (optional) - // not implemented - - // Copy targets to global memory - TransferData[] transferData = new TransferData[0]; - for (int i = 0; i < transferAgents.length; i++){ - Transfer transfer = transferAgents[i]; - if (transfer != null) { - TransferData[] data = transfer.getSupportedTypes(); - TransferData[] newTransferData = new TransferData[transferData.length + data.length]; - System.arraycopy(transferData, 0, newTransferData, 0, transferData.length); - System.arraycopy(data, 0, newTransferData, transferData.length, data.length); - transferData = newTransferData; - } - } - int[] dataTypes = new int[transferData.length]; - for (int i = 0; i < transferData.length; i++){ - dataTypes[i] = transferData[i].type; - } - int pExportTargets = OS.XtMalloc(dataTypes.length * 4); - OS.memmove(pExportTargets, dataTypes, dataTypes.length * 4); - - int[] args = new int[]{ - OS.XmNexportTargets, pExportTargets, - OS.XmNnumExportTargets, dataTypes.length, - OS.XmNdragOperations, opToOsOp(getStyle()), - OS.XmNconvertProc, ConvertProc.getAddress(), - OS.XmNoperationCursorIcon, 0, - OS.XmNsourceCursorIcon, 0, - OS.XmNstateCursorIcon, 0, - OS.XmNclientData, 0, - OS.XmNblendModel, OS.XmBLEND_ALL - }; - - // look for existing drag contexts - int time = xEvent.time; - dragContext = OS.XmGetDragContext(control.handle, time); - if (dragContext != 0){ - OS.XtSetValues(dragContext, args, args.length /2); - } else { - dragContext = OS.XmDragStart(this.control.handle, display.xEvent, args, args.length / 2); - } - OS.XtFree(pExportTargets); - if (dragContext == 0) return; - - // register a call back to clean up when drop is done (optional) - OS.XtAddCallback(dragContext, OS.XmNdragDropFinishCallback, DragDropFinish.getAddress(), 0); - - // register a call back to tell user what happened (optional) - OS.XtAddCallback(dragContext, OS.XmNdropFinishCallback, DropFinish.getAddress(), 0); - - display.setData(Integer.toString(dragContext), this); - return; -} - -int dragDropFinishCallback(int widget, int client_data, int call_data) { - - // uncomment the following code when we allow users to specify their own source icons - // release the pre set source icon - //int pSourceIcon = OS.XtMalloc(4); - //int[] args = new int[]{OS.XmNsourceCursorIcon, pSourceIcon}; - //OS.XtGetValues(control.handle, args, args.length / 2); - //int[] sourceIcon = new int[1]; - //OS.memmove(sourceIcon, pSourceIcon, 4); - //if (sourceIcon[0] != 0) - //OS.XtDestroyWidget(sourceIcon[0]); - //OS.XtFree(pSourceIcon); - - dragContext = 0; - getDisplay().setData(Integer.toString(dragContext), null); - return 0; -} -int dropFinishCallback(int widget, int client_data, int call_data) { - XmDropFinishCallbackStruct data = new XmDropFinishCallbackStruct(); - OS.memmove(data, call_data, XmDropFinishCallbackStruct.sizeof); - if (data.dropAction != OS.XmDROP || data.dropSiteStatus != OS.XmDROP_SITE_VALID) { - DNDEvent event = new DNDEvent(); - event.widget = this.control; - event.time = data.timeStamp; - event.detail = DND.DROP_NONE; - event.doit = false; - notifyListeners(DND.DragEnd,event); - return 0; - } - DNDEvent event = new DNDEvent(); - event.widget = this.control; - event.time = data.timeStamp; - if (moveRequested) { - event.detail = DND.DROP_MOVE; - } else { - if (data.operation == OS.XmDROP_MOVE) { - event.detail = DND.DROP_NONE; - } else { - event.detail = osOpToOp(data.operation); - } - } - event.doit = (data.completionStatus != 0); - notifyListeners(DND.DragEnd,event); - moveRequested = false; - return 0; -} -/** - * 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 (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; -} -byte opToOsOp(int operation){ - byte osOperation = OS.XmDROP_NOOP; - - if ((operation & DND.DROP_COPY) == DND.DROP_COPY) - osOperation |= OS.XmDROP_COPY; - if ((operation & DND.DROP_MOVE) == DND.DROP_MOVE) - osOperation |= OS.XmDROP_MOVE; - if ((operation & DND.DROP_LINK) == DND.DROP_LINK) - osOperation |= OS.XmDROP_LINK; - - return osOperation; -} -int osOpToOp(byte osOperation){ - int operation = DND.DROP_NONE; - - if ((osOperation & OS.XmDROP_COPY) == OS.XmDROP_COPY) - operation |= DND.DROP_COPY; - if ((osOperation & OS.XmDROP_MOVE) == OS.XmDROP_MOVE) - operation |= DND.DROP_MOVE; - if ((osOperation & OS.XmDROP_LINK) == OS.XmDROP_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){ - this.transferAgents = transferAgents; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/DropTarget.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/DropTarget.java deleted file mode 100755 index 6076d943f1..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/DropTarget.java +++ /dev/null @@ -1,948 +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.widgets.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; - -/** - * - * 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 - Simulate events when the mouse is not moving - long dragOverStart; - Runnable dragOverHeartbeat; - DNDEvent dragOverEvent; - - // workaround - The data required in the transferProc callback is not available - // so store it from the dropProc callback - XmDropProcCallbackStruct droppedEventData; - int dropTransferObject; - - // workaround - The DND operation can time out so temporarily set the - // time out to be very long while the application processes the data and - // restore it to the previous value when done. - int selectionTimeout; - - // workaround - A drop target is still active even when it is not visible. - // This causes problems when the widget is not visible but - // overlaps with a visible widget. Deregister drop target when it is - // not visible. - boolean registered = false; - - int deleteAtom, nullAtom; - - static final String DEFAULT_DROP_TARGET_EFFECT = "DEFAULT_DROP_TARGET_EFFECT"; //$NON-NLS-1$ - static byte [] DELETE = Converter.wcsToMbcs (null, "DELETE", true); //$NON-NLS-1$ - static byte [] NULL = Converter.wcsToMbcs (null, "NULL", true); //$NON-NLS-1$ - static final int DRAGOVER_HYSTERESIS = 50; - - static Callback DropProc; - static Callback DragProc; - static Callback TransferProc; - - static { - DropProc = new Callback(DropTarget.class, "DropProcCallback", 3); //$NON-NLS-1$ - if (DropProc.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - DragProc = new Callback(DropTarget.class, "DragProcCallback", 3); //$NON-NLS-1$ - if (DragProc.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); - TransferProc = new Callback(DropTarget.class, "TransferProcCallback", 7); //$NON-NLS-1$ - if (TransferProc.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 (DropProc == null || DragProc == null || TransferProc == 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); - int xDisplay = Display.getDefault().xDisplay; - deleteAtom = OS.XmInternAtom (xDisplay, DELETE, false); - nullAtom = OS.XmInternAtom (xDisplay, NULL, false); - - controlListener = new Listener () { - public void handleEvent (Event event) { - switch (event.type) { - case SWT.Dispose: { - if (!DropTarget.this.isDisposed()){ - onDispose(); - } - break; - } - case SWT.Show: { - if (!registered) { - registerDropTarget(); - } else { - int[] args = new int[]{OS.XmNdropSiteActivity, OS.XmDROP_SITE_ACTIVE,}; - OS.XmDropSiteUpdate(DropTarget.this.control.handle, args, args.length/2); - if (DropTarget.this.control instanceof Label) { - int formHandle = OS.XtParent (DropTarget.this.control.handle); - OS.XmDropSiteUpdate(formHandle, args, args.length / 2); - } - } - break; - } - case SWT.Hide: { - int[] args = new int[]{OS.XmNdropSiteActivity, OS.XmDROP_SITE_INACTIVE,}; - OS.XmDropSiteUpdate(DropTarget.this.control.handle, args, args.length/2); - if (DropTarget.this.control instanceof Label) { - int formHandle = OS.XtParent (DropTarget.this.control.handle); - OS.XmDropSiteUpdate(formHandle, args, args.length / 2); - } - break; - } - } - } - }; - control.addListener (SWT.Dispose, controlListener); - Control c = control; - while (c != null) { - c.addListener (SWT.Show, controlListener); - c.addListener (SWT.Hide, controlListener); - c = c.getParent(); - } - - this.addListener(SWT.Dispose, new Listener () { - public void handleEvent (Event event) { - if (DropTarget.this.control == null || - DropTarget.this.control.isDisposed()) return; - - unregisterDropTarget(); - 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); - } - - if (control.isVisible()) registerDropTarget(); - - 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 { - 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 = (int)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); - } - notifyListeners(DND.DragOver, event); - - selectedDataType = null; - if (event.dataType != null) { - for (int i = 0; i < allowedTypes.length; i++) { - if (allowedTypes[i].type == event.dataType.type) { - selectedDataType = event.dataType; - break; - } - } - } - - selectedOperation = DND.DROP_NONE; - 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 DragProcCallback(int widget, int client_data, int call_data) { - DropTarget target = FindDropTarget(widget); - if (target != null) { - target.dragProcCallback(widget, client_data, call_data); - } - return 0; -} - -static int DropProcCallback(int widget, int client_data, int call_data) { - DropTarget target = FindDropTarget(widget); - if (target != null) { - target.dropProcCallback(widget, client_data, call_data); - } - return 0; -} - -static DropTarget FindDropTarget(int 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); -} - -static int TransferProcCallback(int widget, int client_data, int pSelection, int pType, int pValue, int pLength, int pFormat) { - DropTarget target = FindDropTarget(client_data); - if (target != null) { - target.transferProcCallback(widget, client_data, pSelection, pType, pValue, pLength, pFormat); - } - return 0; -} -/** - * 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 dragProcCallback(int widget, int client_data, int call_data) { - if (call_data == 0) return; - XmDragProcCallbackStruct callbackData = new XmDragProcCallbackStruct(); - OS.memmove(callbackData, call_data, XmDragProcCallbackStruct.sizeof); - - if (callbackData.reason == OS.XmCR_DROP_SITE_LEAVE_MESSAGE) { - updateDragOverHover(0, null); - - if (callbackData.dropSiteStatus == OS.XmDROP_SITE_INVALID) { - return; - } - - DNDEvent event = new DNDEvent(); - event.widget = this; - event.time = callbackData.timeStamp; - event.detail = DND.DROP_NONE; - notifyListeners(DND.DragLeave, event); - return; - } - - if (callbackData.reason == OS.XmCR_DROP_SITE_ENTER_MESSAGE) { - selectedDataType = null; - selectedOperation = DND.DROP_NONE; - droppedEventData = null; - dropTransferObject = 0; - } - - DNDEvent event = new DNDEvent(); - if (!setEventData(callbackData.operations, callbackData.operation, callbackData.dragContext, callbackData.x, callbackData.y, callbackData.timeStamp, event)) { - callbackData.dropSiteStatus = (byte)OS.XmDROP_SITE_INVALID; - callbackData.operation = opToOsOp(DND.DROP_NONE); - OS.memmove(call_data, callbackData, XmDragProcCallbackStruct.sizeof); - return; - } - - int allowedOperations = event.operations; - TransferData[] allowedDataTypes = new TransferData[event.dataTypes.length]; - System.arraycopy(event.dataTypes, 0, allowedDataTypes, 0, allowedDataTypes.length); - - switch (callbackData.reason) { - case OS.XmCR_DROP_SITE_ENTER_MESSAGE : - event.type = DND.DragEnter; - break; - case OS.XmCR_DROP_SITE_MOTION_MESSAGE : - event.type = DND.DragOver; - event.dataType = selectedDataType; - event.detail = selectedOperation; - break; - case OS.XmCR_OPERATION_CHANGED : - event.type = DND.DragOperationChanged; - event.dataType = selectedDataType; - break; - } - - updateDragOverHover(DRAGOVER_HYSTERESIS, event); - notifyListeners(event.type, event); - if (event.detail == DND.DROP_DEFAULT) { - event.detail = (allowedOperations & DND.DROP_MOVE) != 0 ? DND.DROP_MOVE : DND.DROP_NONE; - } - selectedDataType = null; - if (event.dataType != null) { - for (int i = 0; i < allowedDataTypes.length; i++) { - if (allowedDataTypes[i].type == event.dataType.type) { - selectedDataType = allowedDataTypes[i]; - break; - } - } - } - - selectedOperation = DND.DROP_NONE; - if (selectedDataType != null && (allowedOperations & event.detail) != 0) { - selectedOperation = event.detail; - } - - callbackData.dropSiteStatus = (byte)OS.XmDROP_SITE_VALID; - callbackData.operation = opToOsOp(selectedOperation); - OS.memmove(call_data, callbackData, XmDragProcCallbackStruct.sizeof); - - if (callbackData.reason == OS.XmCR_DROP_SITE_ENTER_MESSAGE) { - dragOverHeartbeat.run(); - } -} - -void dropProcCallback(int widget, int client_data, int call_data) { - if (call_data == 0) return; - droppedEventData = new XmDropProcCallbackStruct(); - OS.memmove(droppedEventData, call_data, XmDropProcCallbackStruct.sizeof); - - if (droppedEventData.dropSiteStatus == OS.XmDROP_SITE_INVALID) { - int[] args = new int[] {OS.XmNtransferStatus, OS.XmTRANSFER_FAILURE, OS.XmNnumDropTransfers, 0}; - dropTransferObject = OS.XmDropTransferStart(droppedEventData.dragContext, args, args.length / 2); - return; - } - - DNDEvent event = new DNDEvent(); - if (!setEventData(droppedEventData.operations, droppedEventData.operation, droppedEventData.dragContext, droppedEventData.x, droppedEventData.y, droppedEventData.timeStamp, event)){ - return; - } - - 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; - notifyListeners(DND.DropAccept,event); - selectedDataType = null; - if (event.dataType != null) { - for (int i = 0; i < allowedDataTypes.length; i++) { - if (allowedDataTypes[i].type == event.dataType.type) { - selectedDataType = allowedDataTypes[i]; - break; - } - } - } - - selectedOperation = DND.DROP_NONE; - if (selectedDataType != null && ((event.detail & allowedOperations) == event.detail)) { - selectedOperation = event.detail; - } - - if (selectedOperation == DND.DROP_NONE) { - // this was not a successful drop - int[] args = new int[] {OS.XmNtransferStatus, OS.XmTRANSFER_FAILURE, OS.XmNnumDropTransfers, 0}; - dropTransferObject = OS.XmDropTransferStart(droppedEventData.dragContext, args, args.length / 2); - return; - } - - // ask drag source for dropped data - int[] transferEntries = new int[2]; - transferEntries[0] = control.handle; // pass control handle as data to locate drop target - transferEntries[1] = selectedDataType.type; - - int pTransferEntries = OS.XtMalloc(transferEntries.length * 4); - OS.memmove(pTransferEntries, transferEntries, transferEntries.length * 4); - - int xtContext = OS.XtDisplayToApplicationContext(getDisplay().xDisplay); - selectionTimeout = OS.XtAppGetSelectionTimeout(xtContext); - OS.XtAppSetSelectionTimeout(xtContext, 0x7fffffff); - - int[] args = new int[] {OS.XmNdropTransfers, pTransferEntries, - OS.XmNnumDropTransfers, transferEntries.length / 2, - OS.XmNtransferProc, TransferProc.getAddress()}; - - dropTransferObject = OS.XmDropTransferStart(droppedEventData.dragContext, args, args.length / 2); - OS.XtFree(pTransferEntries); -} - -/** - * 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; -} - -/** - * 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; - if (controlListener != null) { - Control c = control; - while (c != null) { - c.removeListener (SWT.Show, controlListener); - c.removeListener (SWT.Hide, controlListener); - c = c.getParent(); - } - control.removeListener(SWT.Dispose, controlListener); - } - controlListener = null; - control.setData(DND.DROP_TARGET_KEY, null); - control = null; - transferAgents = null; -} -byte opToOsOp(int operation){ - byte osOperation = OS.XmDROP_NOOP; - - if ((operation & DND.DROP_COPY) == DND.DROP_COPY) - osOperation |= OS.XmDROP_COPY; - if ((operation & DND.DROP_MOVE) == DND.DROP_MOVE) - osOperation |= OS.XmDROP_MOVE; - if ((operation & DND.DROP_LINK) == DND.DROP_LINK) - osOperation |= OS.XmDROP_LINK; - - return osOperation; -} -int osOpToOp(byte osOperation){ - int operation = DND.DROP_NONE; - - if ((osOperation & OS.XmDROP_COPY) == OS.XmDROP_COPY) - operation |= DND.DROP_COPY; - if ((osOperation & OS.XmDROP_MOVE) == OS.XmDROP_MOVE) - operation |= DND.DROP_MOVE; - if ((osOperation & OS.XmDROP_LINK) == OS.XmDROP_LINK) - operation |= DND.DROP_LINK; - - return operation; -} -void registerDropTarget() { - if (control == null || control.isDisposed() || registered) return; - - int[] args = new int[]{ - OS.XmNdropSiteOperations, opToOsOp(getStyle()), - OS.XmNdropSiteActivity, OS.XmDROP_SITE_ACTIVE, - OS.XmNdropProc, DropProc.getAddress(), - OS.XmNdragProc, DragProc.getAddress(), - OS.XmNanimationStyle, OS.XmDRAG_UNDER_NONE, - OS.XmNdropSiteType, OS.XmDROP_SITE_COMPOSITE, - }; - - if (transferAgents != null && transferAgents.length != 0) { - TransferData[] transferData = new TransferData[0]; - for (int i = 0, length = transferAgents.length; i < length; i++){ - Transfer transfer = transferAgents[i]; - if (transfer != null) { - TransferData[] data = transfer.getSupportedTypes(); - TransferData[] newTransferData = new TransferData[transferData.length + data.length]; - System.arraycopy(transferData, 0, newTransferData, 0, transferData.length); - System.arraycopy(data, 0, newTransferData, transferData.length, data.length); - transferData = newTransferData; - } - } - - int[] atoms = new int[transferData.length]; - for (int i = 0, length = transferData.length; i < length; i++){ - atoms[i] = transferData[i].type; - } - - // Copy import targets to global memory - int pImportTargets = OS.XtMalloc(atoms.length * 4); - OS.memmove(pImportTargets, atoms, atoms.length * 4); - - int[] args2 = new int[]{ - OS.XmNimportTargets, pImportTargets, - OS.XmNnumImportTargets, atoms.length - }; - - int[] newArgs = new int[args.length + args2.length]; - System.arraycopy(args, 0, newArgs, 0, args.length); - System.arraycopy(args2, 0, newArgs, args.length, args2.length); - args = newArgs; - } - - OS.XmDropSiteRegister(control.handle, args, args.length / 2); - if (control instanceof Label) { - int formHandle = OS.XtParent (control.handle); - OS.XmDropSiteRegister(formHandle, args, args.length / 2); - } - registered = true; -} - - -/** - * 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 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(byte ops, byte op, int dragContext, short x, short y, int timestamp, DNDEvent event) { - //get allowed operations - int style = getStyle(); - int operations = osOpToOp(ops) & style; - if (operations == DND.DROP_NONE) return false; - - //get current operation - int operation = osOpToOp(op); - int xDisplay = getDisplay().xDisplay; - int xWindow = OS.XDefaultRootWindow (xDisplay); - int [] unused = new int [1]; - int[] mask_return = new int[1]; - OS.XQueryPointer (xDisplay, xWindow, unused, unused, unused, unused, unused, unused, mask_return); - int mask = mask_return[0]; - if ((mask & OS.ShiftMask) == 0 && (mask & OS.ControlMask) == 0) { - operation = DND.DROP_DEFAULT; - } - 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 ppExportTargets = OS.XtMalloc(4); - int pNumExportTargets = OS.XtMalloc(4); - int[] args = new int[]{ - OS.XmNexportTargets, ppExportTargets, - OS.XmNnumExportTargets, pNumExportTargets - }; - - OS.XtGetValues(dragContext, args, args.length / 2); - int[] numExportTargets = new int[1]; - OS.memmove(numExportTargets, pNumExportTargets, 4); - OS.XtFree(pNumExportTargets); - int[] pExportTargets = new int[1]; - OS.memmove(pExportTargets, ppExportTargets, 4); - OS.XtFree(ppExportTargets); - int[] exportTargets = new int[numExportTargets[0]]; - OS.memmove(exportTargets, pExportTargets[0], 4*numExportTargets[0]); - //?OS.XtFree(pExportTargets[0]); - - TransferData[] dataTypes = new TransferData[0]; - for (int i = 0; i < exportTargets.length; i++){ - for (int j = 0; j < transferAgents.length; j++){ - TransferData transferData = new TransferData(); - transferData.type = exportTargets[i]; - Transfer transfer = transferAgents[j]; - if (transfer != null && transfer.isSupportedType(transferData)) { - TransferData[] newDataTypes = new TransferData[dataTypes.length + 1]; - System.arraycopy(dataTypes, 0, newDataTypes, 0, dataTypes.length); - newDataTypes[dataTypes.length] = transferData; - dataTypes = newDataTypes; - break; - } - } - } - if (dataTypes.length == 0) return false; - - short [] root_x = new short [1]; - short [] root_y = new short [1]; - OS.XtTranslateCoords (this.control.handle, x, y, root_x, root_y); - - event.widget = this; - event.x = root_x[0]; - event.y = root_y[0]; - event.time = timestamp; - 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(event.x, event.y); - } - return true; -} - -/** - * 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); - this.transferAgents = transferAgents; - - if (!control.isVisible()) return; - - // register data types - TransferData[] transferData = new TransferData[0]; - for (int i = 0, length = transferAgents.length; i < length; i++){ - Transfer transfer = transferAgents[i]; - if (transfer != null) { - TransferData[] data = transfer.getSupportedTypes(); - TransferData[] newTransferData = new TransferData[transferData.length + data.length]; - System.arraycopy(transferData, 0, newTransferData, 0, transferData.length); - System.arraycopy(data, 0, newTransferData, transferData.length, data.length); - transferData = newTransferData; - } - } - - int[] atoms = new int[transferData.length]; - for (int i = 0, length = transferData.length; i < length; i++){ - atoms[i] = transferData[i].type; - } - - // Copy import targets to global memory - int pImportTargets = OS.XtMalloc(atoms.length * 4); - OS.memmove(pImportTargets, atoms, atoms.length * 4); - - int[] args = new int[]{ - OS.XmNimportTargets, pImportTargets, - OS.XmNnumImportTargets, atoms.length - }; - - OS.XmDropSiteUpdate(control.handle, args, args.length / 2); - if (control instanceof Label) { - int formHandle = OS.XtParent (control.handle); - OS.XmDropSiteUpdate(formHandle, args, args.length / 2); - } - - OS.XtFree(pImportTargets); - -} -void transferProcCallback(int widget, int client_data, int pSelection, int pType, int pValue, int pLength, int pFormat) { - if (pType == 0 || pValue == 0 || pLength == 0 || pFormat == 0) return; - - int[] type = new int[1]; - OS.memmove(type, pType, 4); - if (type[0] == nullAtom) { - return; - } - - DNDEvent event = new DNDEvent(); - if (!setEventData(droppedEventData.operations, droppedEventData.operation, droppedEventData.dragContext, droppedEventData.x, droppedEventData.y, droppedEventData.timeStamp, event)){ - return; - } - - int allowedOperations = event.operations; - - // Get Data in a Java format - Object object = null; - TransferData transferData = new TransferData(); - int[] length = new int[1]; - OS.memmove(length, pLength, 4); - int[] format = new int[1]; - OS.memmove(format, pFormat, 4); - transferData.type = type[0]; - transferData.length = length[0]; - transferData.pValue = pValue; - transferData.format = format[0]; - for (int i = 0; i < transferAgents.length; i++){ - Transfer transfer = transferAgents[i]; - if (transfer != null && transfer.isSupportedType(transferData)){ - object = transfer.nativeToJava(transferData); - break; - } - } - OS.XtFree(pValue); - - if (object == null) { - selectedOperation = DND.DROP_NONE; - } - - event.detail = selectedOperation; - event.dataType = transferData; - event.data = object; - notifyListeners(DND.Drop, event); - selectedOperation = DND.DROP_NONE; - if ((allowedOperations & event.detail) == event.detail) { - selectedOperation = event.detail; - } - - //workaround - restore original timeout - int xtContext = OS.XtDisplayToApplicationContext (getDisplay().xDisplay); - OS.XtAppSetSelectionTimeout (xtContext, selectionTimeout); - - //notify source of action taken - if ((selectedOperation & DND.DROP_MOVE) == DND.DROP_MOVE) { - int[] args = new int[]{control.handle, deleteAtom}; - OS.XmDropTransferAdd(dropTransferObject, args, args.length / 2); - } -} - -void unregisterDropTarget() { - if (control == null || control.isDisposed() || !registered) return; - OS.XmDropSiteUnregister(control.handle); - if (control instanceof Label) { - int formHandle = OS.XtParent(control.handle); - OS.XmDropSiteUnregister(formHandle); - } - - registered = false; -} - -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; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/FileTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/FileTransfer.java deleted file mode 100755 index c9a62703bd..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/FileTransfer.java +++ /dev/null @@ -1,148 +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.motif.*; - -/** - * 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 { - - static FileTransfer _instance = new FileTransfer(); - static final String URI_LIST = "text/uri-list"; //$NON-NLS-1$ - static final int URI_LIST_ID = registerType(URI_LIST); - static final String URI_LIST_PREFIX = "file:"; //$NON-NLS-1$ - static final String URI_LIST_SEPARATOR = "\r"; //$NON-NLS-1$ - -FileTransfer() {/*empty*/} - -/** - * 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); - } - String[] files = (String[])object; - StringBuffer sb = new StringBuffer(); - for (int i = 0, length = files.length; i < length; i++){ - sb.append(URI_LIST_PREFIX); - sb.append(files[i]); - sb.append(URI_LIST_SEPARATOR); - } - byte[] buffer = Converter.wcsToMbcs(null, sb.toString(), true); - int pValue = OS.XtMalloc(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 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) 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); - // parse data and convert string to array of files - int start = string.indexOf(URI_LIST_PREFIX); - if (start == -1) return null; - start += URI_LIST_PREFIX.length(); - String[] fileNames = new String[0]; - while (start < string.length()) { - int end = string.indexOf(URI_LIST_SEPARATOR, start); - if (end == -1) end = string.length() - 1; - String fileName = string.substring(start, end); - String[] newFileNames = new String[fileNames.length + 1]; - System.arraycopy(fileNames, 0, newFileNames, 0, fileNames.length); - newFileNames[fileNames.length] = fileName; - fileNames = newFileNames; - start = string.indexOf(URI_LIST_PREFIX, end); - if (start == -1) break; - start += URI_LIST_PREFIX.length(); - } - return fileNames; -} - -protected int[] getTypeIds(){ - return new int[]{URI_LIST_ID}; -} - -protected String[] getTypeNames(){ - return new String[]{URI_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/motif/org/eclipse/swt/dnd/HTMLTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/HTMLTransfer.java deleted file mode 100644 index 462ccdc395..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/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.motif.*; - -/** - * 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 { - - static HTMLTransfer _instance = new HTMLTransfer(); - static final String TEXT_HTML = "text/html"; //$NON-NLS-1$ - static final int TEXT_HTML_ID = registerType(TEXT_HTML); - static final String TEXT_HTML2 = "TEXT/HTML"; //$NON-NLS-1$ - static final int TEXT_HTML2_ID = registerType(TEXT_HTML2); - -HTMLTransfer() {/*empty*/} - -/** - * 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 pValue = OS.XtMalloc(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/motif/org/eclipse/swt/dnd/ImageTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/ImageTransfer.java deleted file mode 100644 index 3e43800473..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/ImageTransfer.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.SWT; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.widgets.Display; - -/** - * 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 PIXMAP = "PIXMAP"; //$NON-NLS-1$ - private static final int PIXMAP_ID = registerType(PIXMAP); - -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); - } - ImageData imgData = (ImageData)object; - if (imgData == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - Image image = new Image(Display.getCurrent(), imgData); - int pixmap = image.pixmap; - int pValue = OS.XtMalloc(4); - if (pValue == 0) return; - OS.memmove(pValue, new int [] {pixmap}, 4); - transferData.type = PIXMAP_ID; - transferData.format = 32; - transferData.length = 1; - transferData.pValue = pValue; - transferData.result = 1; -} -/** - * 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) { - if (!isSupportedType(transferData) || transferData.pValue == 0) return null; - int length = transferData.length; - if (length == 0) return null; - int [] pixmap = new int [1]; - OS.memmove(pixmap, transferData.pValue, length * 4); - Image image = Image.motif_new(Display.getCurrent(), SWT.BITMAP, pixmap[0], 0); - ImageData imgData = image.getImageData(); - image.dispose(); - return imgData; -} - -protected int[] getTypeIds(){ - return new int[]{PIXMAP_ID}; -} - -protected String[] getTypeNames(){ - return new String[]{PIXMAP}; -} - -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/motif/org/eclipse/swt/dnd/RTFTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/RTFTransfer.java deleted file mode 100755 index 4d6b3e4204..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/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.motif.*; - -/** - * 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 { - - static RTFTransfer _instance = new RTFTransfer(); - static final String TEXT_RTF = "text/rtf"; //$NON-NLS-1$ - static final int TEXT_RTF_ID = registerType(TEXT_RTF); - static final String TEXT_RTF2 = "TEXT/RTF"; //$NON-NLS-1$ - static final int TEXT_RTF2_ID = registerType(TEXT_RTF2); - static final String APPLICATION_RTF = "application/rtf"; //$NON-NLS-1$ - static final int APPLICATION_RTF_ID = registerType(APPLICATION_RTF); - -RTFTransfer() {/*empty*/} - -/** - * 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 pValue = OS.XtMalloc(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/motif/org/eclipse/swt/dnd/TableDragSourceEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TableDragSourceEffect.java deleted file mode 100644 index b7dbda53be..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TableDragSourceEffect.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.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 { - /** - * 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); - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TableDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TableDropTargetEffect.java deleted file mode 100644 index 72a6f563bc..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TableDropTargetEffect.java +++ /dev/null @@ -1,217 +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.events.*; -import org.eclipse.swt.graphics.*; -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 currentEffect = DND.FEEDBACK_NONE; - TableItem currentItem; - - PaintListener paintListener; - TableItem dropSelection = null; - - TableItem scrollItem; - 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; - scrollItem = null; - currentItem = null; - dropSelection = null; - } - - /** - * 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; - if (currentItem != null) { - setDropSelection(table, null); - currentItem = null; - } - scrollBeginTime = 0; - scrollItem = null; - } - - /** - * 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 effect = checkEffect(event.feedback); - TableItem item = (TableItem)getItem(table, event.x, event.y); - - if ((effect & DND.FEEDBACK_SCROLL) == 0) { - scrollBeginTime = 0; - scrollItem = null; - } else { - if (item != null && item.equals(scrollItem) && scrollBeginTime != 0) { - if (System.currentTimeMillis() >= scrollBeginTime) { - Rectangle area = table.getClientArea(); - int headerHeight = table.getHeaderHeight(); - int itemHeight= table.getItemHeight(); - Point pt = new Point(event.x, event.y); - pt = table.getDisplay().map(null, table, pt); - TableItem nextItem = null; - if (pt.y < area.y + headerHeight + 2 * itemHeight) { - int index = Math.max(0, table.indexOf(item)-1); - nextItem = table.getItem(index); - } - if (pt.y > area.y + area.height - 2 * itemHeight) { - int index = Math.min(table.getItemCount()-1, table.indexOf(item)+1); - nextItem = table.getItem(index); - } - if (nextItem != null) table.showItem(nextItem); - scrollBeginTime = 0; - scrollItem = null; - } - } else { - scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS; - scrollItem = item; - } - } - - if ((effect & DND.FEEDBACK_SELECT) != 0) { - if (currentItem != item || (currentEffect & DND.FEEDBACK_SELECT) == 0) { - setDropSelection(table, item); - currentEffect = effect; - currentItem = item; - } - } else { - setDropSelection(table, null); - } - } - - void setDropSelection (Table table, TableItem item) { - if (item == dropSelection) return; - if (dropSelection != null && !dropSelection.isDisposed()) { - Rectangle bounds = dropSelection.getBounds(0); - table.redraw(bounds.x, bounds.y, bounds.width, bounds.height, true); - } - dropSelection = item; - if (dropSelection != null && !dropSelection.isDisposed()) { - Rectangle bounds = dropSelection.getBounds(0); - table.redraw(bounds.x, bounds.y, bounds.width, bounds.height, true); - } - if (dropSelection == null) { - if (paintListener != null) { - table.removePaintListener(paintListener); - paintListener = null; - } - } else { - if (paintListener == null) { - paintListener = new PaintListener() { - public void paintControl(PaintEvent e) { - if (dropSelection == null || dropSelection.isDisposed()) return; - GC gc = e.gc; - boolean xor = gc.getXORMode(); - gc.setXORMode(true); - Rectangle bounds = dropSelection.getBounds(0); - gc.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height); - gc.setXORMode(xor); - } - }; - table.addPaintListener(paintListener); - } - } - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TextTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TextTransfer.java deleted file mode 100755 index da99125db1..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TextTransfer.java +++ /dev/null @@ -1,166 +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.widgets.Display; -import org.eclipse.swt.internal.Converter; -import org.eclipse.swt.internal.motif.OS; -import org.eclipse.swt.internal.motif.XTextProperty; - -/** - * 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 { - - static TextTransfer _instance = new TextTransfer(); - static final String COMPOUND_TEXT = "COMPOUND_TEXT"; //$NON-NLS-1$ - static final String STRING = "STRING"; //$NON-NLS-1$ - static final int COMPOUND_TEXT_ID = registerType(COMPOUND_TEXT); - static final int STRING_ID = registerType(STRING); - -TextTransfer() {/*empty*/} - -/** - * 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[] buffer = Converter.wcsToMbcs (null, string, true); - if (transferData.type == COMPOUND_TEXT_ID) { - Display display = Display.getCurrent(); - if (display == null) return; - int xDisplay = display.xDisplay; - int pBuffer = OS.XtMalloc(buffer.length); - if (pBuffer == 0) return; - try { - OS.memmove(pBuffer, buffer, buffer.length); - int list = OS.XtMalloc(4); - if (list == 0) return; - OS.memmove(list, new int[] {pBuffer}, 4); - XTextProperty text_prop_return = new XTextProperty(); - int result = OS.XmbTextListToTextProperty (xDisplay, list, 1, OS.XCompoundTextStyle, text_prop_return); - OS.XtFree(list); - if (result != 0)return; - transferData.format = text_prop_return.format; - transferData.length = text_prop_return.nitems; - transferData.pValue = text_prop_return.value; - transferData.type = text_prop_return.encoding; - transferData.result = 1; - } finally { - OS.XtFree(pBuffer); - } - } - if (transferData.type == STRING_ID) { - int pValue = OS.XtMalloc(buffer.length); - if (pValue == 0) return; - OS.memmove(pValue, buffer, buffer.length); - transferData.type = STRING_ID; - transferData.format = 8; - transferData.length = buffer.length - 1; - transferData.pValue = pValue; - 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; - byte[] buffer = null; - if (transferData.type == COMPOUND_TEXT_ID) { - Display display = Display.getCurrent(); - if (display == null) return null; - int xDisplay = display.xDisplay; - XTextProperty text_prop = new XTextProperty(); - text_prop.encoding = transferData.type; - text_prop.format = transferData.format; - text_prop.nitems = transferData.length; - text_prop.value = transferData.pValue; - int[] list_return = new int[1]; - int[] count_return = new int[1]; - int result = OS.XmbTextPropertyToTextList (xDisplay, text_prop, list_return, count_return); - if (result != 0 || list_return[0] == 0) return null; - //Note: only handling the first string in list - int[] ptr = new int[1]; - OS.memmove(ptr, list_return[0], 4); - int length = OS.strlen(ptr[0]); - buffer = new byte[length]; - OS.memmove(buffer, ptr[0], length); - OS.XFreeStringList(list_return[0]); - } - if (transferData.type == STRING_ID) { - int size = transferData.format * transferData.length / 8; - if (size == 0) return null; - buffer = new byte[size]; - OS.memmove(buffer, transferData.pValue, size); - } - if (buffer == null) return null; - // convert byte array to a string - char [] unicode = Converter.mbcsToWcs (null, buffer); - String string = new String (unicode); - int end = string.indexOf('\0'); - return (end == -1) ? string : string.substring(0, end); -} - -protected int[] getTypeIds() { - return new int[] {COMPOUND_TEXT_ID, STRING_ID}; -} - -protected String[] getTypeNames() { - return new 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/motif/org/eclipse/swt/dnd/Transfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Transfer.java deleted file mode 100755 index c1572a3449..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/Transfer.java +++ /dev/null @@ -1,157 +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.motif.OS; -import org.eclipse.swt.widgets.Display; - -/** - * <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){ - // Use default display because we don't have a particular widget - int xDisplay = Display.getDefault().xDisplay; - // Use the character encoding for the default locale - byte[] buffer = Converter.wcsToMbcs (null, formatName, true); - return OS.XmInternAtom (xDisplay, 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/motif/org/eclipse/swt/dnd/TransferData.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TransferData.java deleted file mode 100755 index 7985cb865c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/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 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 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/motif/org/eclipse/swt/dnd/TreeDragSourceEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TreeDragSourceEffect.java deleted file mode 100644 index 7a66bebb22..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TreeDragSourceEffect.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.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 { - /** - * 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); - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TreeDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TreeDropTargetEffect.java deleted file mode 100644 index 7a57f9b001..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/TreeDropTargetEffect.java +++ /dev/null @@ -1,283 +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.events.*; -import org.eclipse.swt.graphics.*; -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 currentEffect = DND.FEEDBACK_NONE; - TreeItem currentItem; - - PaintListener paintListener; - TreeItem dropSelection = null; - - TreeItem insertItem = null; - boolean insertBefore = false; - - TreeItem scrollItem; - long scrollBeginTime; - - TreeItem expandItem; - 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) { - insertItem = null; - currentItem = null; - dropSelection = null; - expandBeginTime = 0; - expandItem = null; - scrollBeginTime = 0; - scrollItem = null; - } - - /** - * 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; - if (insertItem != null) { - tree.setInsertMark(null, false); - insertItem = null; - } - if (currentItem != null) { - setDropSelection(tree, null); - currentItem = null; - } - expandBeginTime = 0; - expandItem = null; - scrollBeginTime = 0; - scrollItem = null; - } - - /** - * 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); - - TreeItem item = (TreeItem)getItem(tree, event.x, event.y); - - if ((effect & DND.FEEDBACK_EXPAND) == 0) { - expandBeginTime = 0; - expandItem = null; - } else { - if (item != null && item.equals(expandItem) && expandBeginTime != 0) { - if (System.currentTimeMillis() >= expandBeginTime) { - if (item.getItemCount() > 0 && !item.getExpanded()) { - Event e = new Event(); - e.x = event.x; - e.y = event.y; - e.item = item; - e.time = (int) System.currentTimeMillis(); - tree.notifyListeners(SWT.Expand, e); - if (item.isDisposed()) return; - item.setExpanded(true); - } - expandBeginTime = 0; - expandItem = null; - } - } else { - expandBeginTime = System.currentTimeMillis() + EXPAND_HYSTERESIS; - expandItem = item; - } - } - - if ((effect & DND.FEEDBACK_SCROLL) == 0) { - scrollBeginTime = 0; - scrollItem = null; - } else { - if (item != null && item.equals(scrollItem) && scrollBeginTime != 0) { - if (System.currentTimeMillis() >= scrollBeginTime) { - Rectangle area = tree.getClientArea(); - int headerHeight = tree.getHeaderHeight(); - int itemHeight= tree.getItemHeight(); - Point pt = new Point(event.x, event.y); - pt = tree.getDisplay().map(null, tree, pt); - TreeItem nextItem = null; - if (pt.y < area.y + headerHeight + 2 * itemHeight) { - nextItem = previousItem(tree, item); - } - if (pt.y > area.y + area.height - 2 * itemHeight) { - nextItem = nextItem(tree, item); - } - if (nextItem != null) tree.showItem(nextItem); - scrollBeginTime = 0; - scrollItem = null; - } - } else { - scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS; - scrollItem = item; - } - } - - if ((effect & DND.FEEDBACK_SELECT) != 0) { - if (currentItem != item || (currentEffect & DND.FEEDBACK_SELECT) == 0) { - setDropSelection(tree, item); - currentEffect = effect; - currentItem = item; - } - } else { - setDropSelection(tree, null); - } - - if ((effect & DND.FEEDBACK_INSERT_AFTER) != 0 || - (effect & DND.FEEDBACK_INSERT_BEFORE) != 0) { - if (currentItem != item || - ((effect & DND.FEEDBACK_INSERT_AFTER) != (currentEffect & DND.FEEDBACK_INSERT_AFTER)) || - ((effect & DND.FEEDBACK_INSERT_BEFORE) != (currentEffect & DND.FEEDBACK_INSERT_BEFORE))) { - setInsertMark(tree, item, (effect & DND.FEEDBACK_INSERT_BEFORE) != 0); - currentEffect = effect; - currentItem = item; - } - } else { - setInsertMark(tree, null, false); - } - } - - void setDropSelection (Tree tree, TreeItem item) { - if (item == dropSelection) return; - if (dropSelection != null && !dropSelection.isDisposed()) { - Rectangle bounds = dropSelection.getBounds(); - tree.redraw(bounds.x, bounds.y, bounds.width, bounds.height, true); - } - dropSelection = item; - if (dropSelection != null && !dropSelection.isDisposed()) { - Rectangle bounds = dropSelection.getBounds(); - tree.redraw(bounds.x, bounds.y, bounds.width, bounds.height, true); - } - if (dropSelection == null) { - if (paintListener != null) { - tree.removePaintListener(paintListener); - paintListener = null; - } - } else { - if (paintListener == null) { - paintListener = new PaintListener() { - public void paintControl(PaintEvent e) { - if (dropSelection == null || dropSelection.isDisposed()) return; - GC gc = e.gc; - boolean xor = gc.getXORMode(); - gc.setXORMode(true); - Rectangle bounds = dropSelection.getBounds(); - gc.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height); - gc.setXORMode(xor); - } - }; - tree.addPaintListener(paintListener); - } - } - } - - void setInsertMark(Tree tree, TreeItem item, boolean before) { - if (item == insertItem && before == insertBefore) return; - insertItem = item; - insertBefore = before; - tree.setInsertMark(item, before); - } - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/URLTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/URLTransfer.java deleted file mode 100644 index 9e266354fb..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/motif/org/eclipse/swt/dnd/URLTransfer.java +++ /dev/null @@ -1,116 +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.motif.*; - -/** - * 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(); - - static final String TEXT_UNICODE = "text/unicode"; //$NON-NLS-1$ - private static final String TEXT_XMOZURL = "text/x-moz-url"; //$NON-NLS-1$ - 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 pValue = OS.XtMalloc(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); -} -} |