1 /*******************************************************************************
2 * Copyright (c) 2000, 2013 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.dnd;
17 import org.eclipse.swt.*;
20 * Class DND contains all the constants used in defining a
21 * DragSource or a DropTarget.
23 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
28 * The transfer mechanism for data that is being cut
29 * and then pasted or copied and then pasted (value is 1).
35 public final static int CLIPBOARD = 1 << 0;
38 * The transfer mechanism for clients that use the selection
39 * mechanism (value is 2).
45 public final static int SELECTION_CLIPBOARD = 1 << 1;
48 * Drag and Drop Operation: no drag/drop operation performed
51 public final static int DROP_NONE = 0;
54 * Drag and Drop Operation: a copy of the data in the drag source is
55 * added to the drop target (value is 1 << 0).
57 public final static int DROP_COPY = 1 << 0;
60 * Drag and Drop Operation: a copy of the data is added to the drop target and
61 * the drag source removes the original data and any references to the data,
62 * and updates its display (value is 1 << 1).
64 * <b>Warning:</b> Some applications (most notably Firefox, Thunderbird, and Safari) return
65 * {@link DND#DROP_MOVE} even if they just open a dropped file and don't copy
66 * anything, see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=30543">bug 30543</a>.
69 * <b>To avoid data loss</b>, you may want to not remove the original data
70 * when you handle a {@link DND#DragEnd} for a {@link FileTransfer} whose
71 * {@link org.eclipse.swt.widgets.Event#detail} is {@link #DROP_MOVE}.
74 public final static int DROP_MOVE = 1 << 1;
77 * Drag and Drop Operation: the drop target makes a link to the data in
78 * the drag source (value is 1 << 2).
80 public final static int DROP_LINK = 1 << 2;
83 * Drag and Drop Operation: the drop target moves the data and the drag source removes
84 * any references to the data and updates its display. This is not available on all platforms
85 * and is only used when a non-SWT application is the drop target. In this case, the SWT
86 * drag source is informed in the dragFinished event that the drop target has moved the data.
87 * (value is 1 << 3).
89 * @see DragSourceListener#dragFinished
91 public final static int DROP_TARGET_MOVE = 1 << 3;
94 * Drag and Drop Operation: During a dragEnter event or a dragOperationChanged, if no modifier keys
95 * are pressed, the operation is set to DROP_DEFAULT. The application can choose what the default
96 * operation should be by setting a new value in the operation field. If no value is choosen, the
97 * default operation for the platform will be selected (value is 1 << 4).
99 * @see DropTargetListener#dragEnter
100 * @see DropTargetListener#dragOperationChanged
103 public final static int DROP_DEFAULT = 1 << 4;
106 * DragSource Event: the drop has successfully completed or has been terminated (such as hitting
107 * the ESC key); perform cleanup such as removing data on a move operation (value is 2000).
109 public static final int DragEnd = 2000;
112 * DragSource Event: the data to be dropped is required from the drag source (value is 2001).
114 public static final int DragSetData = 2001;
117 * DropTarget Event: the cursor has entered the drop target boundaries (value is 2002).
119 public static final int DragEnter = 2002;
122 * DropTarget Event: the cursor has left the drop target boundaries OR the drop
123 * operation has been cancelled (such as by hitting ECS) OR the drop is about to
124 * happen (user has released the mouse button over this target) (value is 2003).
126 public static final int DragLeave = 2003;
129 * DropTarget Event: the cursor is over the drop target (value is 2004).
131 public static final int DragOver = 2004;
134 * DropTarget Event: the operation being performed has changed usually due to the user
135 * changing the selected modifier keys while dragging (value is 2005).
137 public static final int DragOperationChanged = 2005;
140 * DropTarget Event: the data has been dropped (value is 2006).
142 public static final int Drop = 2006;
145 * DropTarget Event: the drop target is given a last chance to modify the drop (value is 2007).
147 public static final int DropAccept = 2007;
150 * DragSource Event: a drag is about to begin (value is 2008).
152 public static final int DragStart = 2008;
155 * DropTarget drag under effect: No effect is shown (value is 0).
157 public static final int FEEDBACK_NONE = 0;
160 * DropTarget drag under effect: The item under the cursor is selected; applies to tables
161 * and trees (value is 1).
163 public static final int FEEDBACK_SELECT = 1;
166 * DropTarget drag under effect: An insertion mark is shown before the item under the cursor; applies to
167 * tables and trees (value is 2).
169 public static final int FEEDBACK_INSERT_BEFORE = 2;
172 * DropTarget drag under effect: An insertion mark is shown after the item under the cursor; applies to
173 * tables and trees (value is 4).
175 public static final int FEEDBACK_INSERT_AFTER = 4;
178 * DropTarget drag under effect: The widget is scrolled up or down to allow the user to drop on items that
179 * are not currently visible; applies to tables and trees (value is 8).
181 public static final int FEEDBACK_SCROLL = 8;
184 * DropTarget drag under effect: The item currently under the cursor is expanded to allow the user to
185 * select a drop target from a sub item; applies to trees (value is 16).
187 public static final int FEEDBACK_EXPAND = 16;
190 * Error code: drag source can not be initialized (value is 2000).
192 public static final int ERROR_CANNOT_INIT_DRAG = 2000;
195 * Error code: drop target cannot be initialized (value is 2001).
197 public static final int ERROR_CANNOT_INIT_DROP = 2001;
200 * Error code: Data can not be set on system clipboard (value is 2002).
202 public static final int ERROR_CANNOT_SET_CLIPBOARD = 2002;
205 * Error code: Data does not have correct format for type (value is 2003).
208 public static final int ERROR_INVALID_DATA = 2003;
211 * DropTarget Key: The string constant for looking up the drop target
212 * for a control using <code>getData(String)</code>. When a drop target
213 * is created for a control, it is stored as a property in the control
214 * using <code>setData(String, Object)</code>.
218 public static final String DROP_TARGET_KEY = "DropTarget"; //$NON-NLS-1$
221 * DragSource Key: The string constant for looking up the drag source
222 * for a control using <code>getData(String)</code>. When a drag source
223 * is created for a control, it is stored as a property in the control
224 * using <code>setData(String, Object)</code>.
228 public static final String DRAG_SOURCE_KEY = "DragSource"; //$NON-NLS-1$
230 static final String INIT_DRAG_MESSAGE = "Cannot initialize Drag"; //$NON-NLS-1$
231 static final String INIT_DROP_MESSAGE = "Cannot initialize Drop"; //$NON-NLS-1$
232 static final String CANNOT_SET_CLIPBOARD_MESSAGE = "Cannot set data in clipboard"; //$NON-NLS-1$
233 static final String INVALID_DATA_MESSAGE = "Data does not have correct format for type"; //$NON-NLS-1$
236 * Throws an appropriate exception based on the passed in error code.
238 * @param code the DND error code
240 public static void error (int code) {
245 * Throws an appropriate exception based on the passed in error code.
246 * The <code>hresult</code> argument should be either 0, or the
247 * platform specific error code.
249 * In DND, errors are reported by throwing one of three exceptions:</p>
251 * <dd>java.lang.IllegalArgumentException</dd>
252 * <dt>thrown whenever one of the API methods is invoked with an illegal argument</dt>
253 * <dd>org.eclipse.swt.SWTException (extends java.lang.RuntimeException)</dd>
254 * <dt>thrown whenever a recoverable error happens internally in SWT</dt>
255 * <dd>org.eclipse.swt.SWTError (extends java.lang.Error)</dd>
256 * <dt>thrown whenever a <b>non-recoverable</b> error happens internally in SWT</dt>
259 * This method provides the logic which maps between error codes
260 * and one of the above exceptions.
263 * @param code the DND error code.
264 * @param hresult the platform specific error code.
268 * @see IllegalArgumentException
270 public static void error (int code, int hresult) {
272 /* OS Failure/Limit (fatal, may occur only on some platforms) */
273 case DND.ERROR_CANNOT_INIT_DRAG:{
274 String msg = DND.INIT_DRAG_MESSAGE;
275 if (hresult != 0) msg += " result = "+hresult; //$NON-NLS-1$
276 throw new SWTError (code, msg);
278 case DND.ERROR_CANNOT_INIT_DROP:{
279 String msg = DND.INIT_DROP_MESSAGE;
280 if (hresult != 0) msg += " result = "+hresult; //$NON-NLS-1$
281 throw new SWTError (code, msg);
283 case DND.ERROR_CANNOT_SET_CLIPBOARD:{
284 String msg = DND.CANNOT_SET_CLIPBOARD_MESSAGE;
285 if (hresult != 0) msg += " result = "+hresult; //$NON-NLS-1$
286 throw new SWTError (code, msg);
288 case DND.ERROR_INVALID_DATA:{
289 String msg = DND.INVALID_DATA_MESSAGE;
290 if (hresult != 0) msg += " result = "+hresult; //$NON-NLS-1$
291 throw new SWTException (code, msg);
295 /* Unknown/Undefined Error */