25
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module org.eclipse.swt.dnd.DND;
|
|
14
|
|
15 import java.lang.all;
|
|
16
|
|
17
|
|
18 import org.eclipse.swt.SWT;
|
|
19 import org.eclipse.swt.SWTError;
|
|
20 import org.eclipse.swt.SWTException;
|
|
21
|
48
|
22 version(Tango){
|
25
|
23 import tango.util.Convert;
|
48
|
24 } else { // Phobos
|
|
25 }
|
25
|
26
|
|
27 /**
|
|
28 *
|
|
29 * Class DND contains all the constants used in defining a
|
|
30 * DragSource or a DropTarget.
|
|
31 *
|
|
32 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
|
|
33 */
|
|
34 public class DND {
|
|
35
|
|
36 /**
|
|
37 * The transfer mechanism for data that is being cut
|
|
38 * and then pasted or copied and then pasted (value is 1).
|
|
39 *
|
|
40 * @see Clipboard
|
|
41 *
|
|
42 * @since 3.1
|
|
43 */
|
|
44 public const static int CLIPBOARD = 1 << 0;
|
|
45
|
|
46 /**
|
|
47 * The transfer mechanism for clients that use the selection
|
|
48 * mechanism (value is 2).
|
|
49 *
|
|
50 * @see Clipboard
|
|
51 *
|
|
52 * @since 3.1
|
|
53 */
|
|
54 public const static int SELECTION_CLIPBOARD = 1 << 1;
|
|
55
|
|
56 /**
|
|
57 * Drag and Drop Operation: no drag/drop operation performed
|
|
58 * (value is 0).
|
|
59 */
|
|
60 public const static int DROP_NONE = 0;
|
|
61
|
|
62 /**
|
|
63 * Drag and Drop Operation: a copy of the data in the drag source is
|
|
64 * added to the drop target (value is 1 << 0).
|
|
65 */
|
|
66 public const static int DROP_COPY = 1 << 0;
|
|
67
|
|
68 /**
|
|
69 * Drag and Drop Operation: a copy of the data is added to the drop target and
|
|
70 * the original data is removed from the drag source (value is 1 << 1).
|
|
71 */
|
|
72 public const static int DROP_MOVE = 1 << 1;
|
|
73
|
|
74 /**
|
|
75 * Drag and Drop Operation: the drop target makes a link to the data in
|
|
76 * the drag source (value is 1 << 2).
|
|
77 */
|
|
78 public const static int DROP_LINK = 1 << 2;
|
|
79
|
|
80 /**
|
|
81 * Drag and Drop Operation: the drop target moves the data and the drag source removes
|
|
82 * any references to the data and updates its display. This is not available on all platforms
|
|
83 * and is only used when a non-SWT application is the drop target. In this case, the SWT
|
|
84 * drag source is informed in the dragFinished event that the drop target has moved the data.
|
|
85 * (value is 1 << 3).
|
|
86 *
|
|
87 * @see DragSourceListener#dragFinished
|
|
88 */
|
|
89 public const static int DROP_TARGET_MOVE = 1 << 3;
|
|
90
|
|
91 /**
|
|
92 * Drag and Drop Operation: During a dragEnter event or a dragOperationChanged, if no modifier keys
|
|
93 * are pressed, the operation is set to DROP_DEFAULT. The application can choose what the default
|
|
94 * operation should be by setting a new value in the operation field. If no value is choosen, the
|
|
95 * default operation for the platform will be selected (value is 1 << 4).
|
|
96 *
|
|
97 * @see DropTargetListener#dragEnter
|
|
98 * @see DropTargetListener#dragOperationChanged
|
|
99 * @since 2.0
|
|
100 */
|
|
101 public const static int DROP_DEFAULT = 1 << 4;
|
|
102
|
|
103 /**
|
|
104 * DragSource Event: the drop has successfully completed or has been terminated (such as hitting
|
|
105 * the ESC key); perform cleanup such as removing data on a move operation (value is 2000).
|
|
106 */
|
|
107 public static const int DragEnd = 2000;
|
|
108
|
|
109 /**
|
|
110 * DragSource Event: the data to be dropped is required from the drag source (value is 2001).
|
|
111 */
|
|
112 public static const int DragSetData = 2001;
|
|
113
|
|
114 /**
|
|
115 * DropTarget Event: the cursor has entered the drop target boundaries (value is 2002).
|
|
116 */
|
|
117 public static const int DragEnter = 2002;
|
|
118
|
|
119 /**
|
|
120 * DropTarget Event: the cursor has left the drop target boundaries OR the drop
|
|
121 * operation has been cancelled (such as by hitting ECS) OR the drop is about to
|
|
122 * happen (user has released the mouse button over this target) (value is 2003).
|
|
123 */
|
|
124 public static const int DragLeave = 2003;
|
|
125
|
|
126 /**
|
|
127 * DropTarget Event: the cursor is over the drop target (value is 2004).
|
|
128 */
|
|
129 public static const int DragOver = 2004;
|
|
130
|
|
131 /**
|
|
132 * DropTarget Event: the operation being performed has changed usually due to the user
|
|
133 * changing the selected modifier keys while dragging (value is 2005).
|
|
134 */
|
|
135 public static const int DragOperationChanged = 2005;
|
|
136
|
|
137 /**
|
|
138 * DropTarget Event: the data has been dropped (value is 2006).
|
|
139 */
|
|
140 public static const int Drop = 2006;
|
|
141
|
|
142 /**
|
|
143 * DropTarget Event: the drop target is given a last chance to modify the drop (value is 2007).
|
|
144 */
|
|
145 public static const int DropAccept = 2007;
|
|
146
|
|
147 /**
|
|
148 * DragSource Event: a drag is about to begin (value is 2008).
|
|
149 */
|
|
150 public static const int DragStart = 2008;
|
|
151
|
|
152 /**
|
|
153 * DropTarget drag under effect: No effect is shown (value is 0).
|
|
154 */
|
|
155 public static const int FEEDBACK_NONE = 0;
|
|
156
|
|
157 /**
|
|
158 * DropTarget drag under effect: The item under the cursor is selected; applies to tables
|
|
159 * and trees (value is 1).
|
|
160 */
|
|
161 public static const int FEEDBACK_SELECT = 1;
|
|
162
|
|
163 /**
|
|
164 * DropTarget drag under effect: An insertion mark is shown before the item under the cursor; applies to
|
|
165 * trees (value is 2).
|
|
166 */
|
|
167 public static const int FEEDBACK_INSERT_BEFORE = 2;
|
|
168
|
|
169 /**
|
|
170 * DropTarget drag under effect:An insertion mark is shown after the item under the cursor; applies to
|
|
171 * trees (value is 4).
|
|
172 */
|
|
173 public static const int FEEDBACK_INSERT_AFTER = 4;
|
|
174
|
|
175 /**
|
|
176 * DropTarget drag under effect: The widget is scrolled up or down to allow the user to drop on items that
|
|
177 * are not currently visible; applies to tables and trees (value is 8).
|
|
178 */
|
|
179 public static const int FEEDBACK_SCROLL = 8;
|
|
180
|
|
181 /**
|
|
182 * DropTarget drag under effect: The item currently under the cursor is expanded to allow the user to
|
|
183 * select a drop target from a sub item; applies to trees (value is 16).
|
|
184 */
|
|
185 public static const int FEEDBACK_EXPAND = 16;
|
|
186
|
|
187 /**
|
|
188 * Error code: drag source can not be initialized (value is 2000).
|
|
189 */
|
|
190 public static const int ERROR_CANNOT_INIT_DRAG = 2000;
|
|
191
|
|
192 /**
|
|
193 * Error code: drop target cannot be initialized (value is 2001).
|
|
194 */
|
|
195 public static const int ERROR_CANNOT_INIT_DROP = 2001;
|
|
196
|
|
197 /**
|
|
198 * Error code: Data can not be set on system clipboard (value is 2002).
|
|
199 */
|
|
200 public static const int ERROR_CANNOT_SET_CLIPBOARD = 2002;
|
|
201
|
|
202 /**
|
|
203 * Error code: Data does not have correct format for type (value is 2003).
|
|
204 * @since 3.1
|
|
205 */
|
|
206 public static const int ERROR_INVALID_DATA = 2003;
|
|
207
|
|
208 /**
|
|
209 * DropTarget Key: The string constant for looking up the drop target
|
|
210 * for a control using <code>getData(String)</code>. When a drop target
|
|
211 * is created for a control, it is stored as a property in the control
|
|
212 * using <code>setData(String, Object)</code>.
|
|
213 *
|
|
214 * @since 3.4
|
|
215 */
|
|
216 public static final String DROP_TARGET_KEY = "DropTarget"; //$NON-NLS-1$
|
|
217
|
|
218 /**
|
|
219 * DragSource Key: The string constant for looking up the drag source
|
|
220 * for a control using <code>getData(String)</code>. When a drag source
|
|
221 * is created for a control, it is stored as a property in the control
|
|
222 * using <code>setData(String, Object)</code>.
|
|
223 *
|
|
224 * @since 3.4
|
|
225 */
|
|
226 public static final String DRAG_SOURCE_KEY = "DragSource"; //$NON-NLS-1$
|
|
227
|
|
228 static const String INIT_DRAG_MESSAGE = "Cannot initialize Drag"; //$NON-NLS-1$
|
|
229 static const String INIT_DROP_MESSAGE = "Cannot initialize Drop"; //$NON-NLS-1$
|
|
230 static const String CANNOT_SET_CLIPBOARD_MESSAGE = "Cannot set data in clipboard"; //$NON-NLS-1$
|
|
231 static const String INVALID_DATA_MESSAGE = "Data does not have correct format for type"; //$NON-NLS-1$
|
|
232
|
|
233 /**
|
|
234 * Throws an appropriate exception based on the passed in error code.
|
|
235 *
|
|
236 * @param code the DND error code
|
|
237 */
|
|
238 public static void error (int code) {
|
|
239 error (code, 0);
|
|
240 }
|
|
241
|
|
242 /**
|
|
243 * Throws an appropriate exception based on the passed in error code.
|
|
244 * The <code>hresult</code> argument should be either 0, or the
|
|
245 * platform specific error code.
|
|
246 * <p>
|
|
247 * In DND, errors are reported by throwing one of three exceptions:
|
|
248 * <dl>
|
|
249 * <dd>java.lang.IllegalArgumentException</dd>
|
|
250 * <dt>thrown whenever one of the API methods is invoked with an illegal argument</dt>
|
|
251 * <dd>org.eclipse.swt.SWTException (extends java.lang.RuntimeException)</dd>
|
|
252 * <dt>thrown whenever a recoverable error happens internally in SWT</dt>
|
|
253 * <dd>org.eclipse.swt.SWTError (extends java.lang.Error)</dd>
|
|
254 * <dt>thrown whenever a <b>non-recoverable</b> error happens internally in SWT</dt>
|
|
255 * </dl>
|
|
256 * This method provides the logic which maps between error codes
|
|
257 * and one of the above exceptions.
|
|
258 * </p>
|
|
259 *
|
|
260 * @param code the DND error code.
|
|
261 * @param hresult the platform specific error code.
|
|
262 *
|
|
263 * @see SWTError
|
|
264 * @see SWTException
|
|
265 * @see IllegalArgumentException
|
|
266 */
|
|
267 public static void error (int code, int hresult) {
|
|
268 switch (code) {
|
|
269 /* OS Failure/Limit (fatal, may occur only on some platforms) */
|
|
270 case DND.ERROR_CANNOT_INIT_DRAG:{
|
|
271 String msg = DND.INIT_DRAG_MESSAGE;
|
|
272 if (hresult !is 0) msg ~= " result = "~to!(String)(hresult); //$NON-NLS-1$
|
|
273 throw new SWTError (code, msg);
|
|
274 }
|
|
275 case DND.ERROR_CANNOT_INIT_DROP:{
|
|
276 String msg = DND.INIT_DROP_MESSAGE;
|
|
277 if (hresult !is 0) msg ~= " result = "~to!(String)(hresult); //$NON-NLS-1$
|
|
278 throw new SWTError (code, msg);
|
|
279 }
|
|
280 case DND.ERROR_CANNOT_SET_CLIPBOARD:{
|
|
281 String msg = DND.CANNOT_SET_CLIPBOARD_MESSAGE;
|
|
282 if (hresult !is 0) msg ~= " result = "~to!(String)(hresult); //$NON-NLS-1$
|
|
283 throw new SWTError (code, msg);
|
|
284 }
|
|
285 case DND.ERROR_INVALID_DATA:{
|
|
286 String msg = DND.INVALID_DATA_MESSAGE;
|
|
287 if (hresult !is 0) msg ~= " result = "~to!(String)(hresult); //$NON-NLS-1$
|
|
288 throw new SWTException (code, msg);
|
|
289 }
|
|
290 default:
|
|
291 }
|
|
292
|
|
293 /* Unknown/Undefined Error */
|
|
294 SWT.error(code);
|
|
295 }
|
|
296
|
|
297 }
|