Mercurial > projects > dwt-mac
comparison dwt/dnd/DND.d @ 92:370410b7852f
Ported dwt.dnd.DND
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 30 Dec 2008 19:08:20 +0100 |
parents | d8635bb48c7c |
children | 63a09873578e |
comparison
equal
deleted
inserted
replaced
91:a7e41c09df9e | 92:370410b7852f |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <doob@me.com> | |
10 *******************************************************************************/ | 13 *******************************************************************************/ |
11 module dwt.dnd.DND; | 14 module dwt.dnd.DND; |
12 | 15 |
13 import dwt.dwthelper.utils; | 16 import dwt.dwthelper.utils; |
14 | 17 |
32 * | 35 * |
33 * @see Clipboard | 36 * @see Clipboard |
34 * | 37 * |
35 * @since 3.1 | 38 * @since 3.1 |
36 */ | 39 */ |
37 public final static int CLIPBOARD = 1 << 0; | 40 public const static int CLIPBOARD = 1 << 0; |
38 | 41 |
39 /** | 42 /** |
40 * The transfer mechanism for clients that use the selection | 43 * The transfer mechanism for clients that use the selection |
41 * mechanism (value is 2). | 44 * mechanism (value is 2). |
42 * | 45 * |
43 * @see Clipboard | 46 * @see Clipboard |
44 * | 47 * |
45 * @since 3.1 | 48 * @since 3.1 |
46 */ | 49 */ |
47 public final static int SELECTION_CLIPBOARD = 1 << 1; | 50 public const static int SELECTION_CLIPBOARD = 1 << 1; |
48 | 51 |
49 /** | 52 /** |
50 * Drag and Drop Operation: no drag/drop operation performed | 53 * Drag and Drop Operation: no drag/drop operation performed |
51 * (value is 0). | 54 * (value is 0). |
52 */ | 55 */ |
53 public final static int DROP_NONE = 0; | 56 public const static int DROP_NONE = 0; |
54 | 57 |
55 /** | 58 /** |
56 * Drag and Drop Operation: a copy of the data in the drag source is | 59 * Drag and Drop Operation: a copy of the data in the drag source is |
57 * added to the drop target (value is 1 << 0). | 60 * added to the drop target (value is 1 << 0). |
58 */ | 61 */ |
59 public final static int DROP_COPY = 1 << 0; | 62 public const static int DROP_COPY = 1 << 0; |
60 | 63 |
61 /** | 64 /** |
62 * Drag and Drop Operation: a copy of the data is added to the drop target and | 65 * Drag and Drop Operation: a copy of the data is added to the drop target and |
63 * the original data is removed from the drag source (value is 1 << 1). | 66 * the original data is removed from the drag source (value is 1 << 1). |
64 */ | 67 */ |
65 public final static int DROP_MOVE = 1 << 1; | 68 public const static int DROP_MOVE = 1 << 1; |
66 | 69 |
67 /** | 70 /** |
68 * Drag and Drop Operation: the drop target makes a link to the data in | 71 * Drag and Drop Operation: the drop target makes a link to the data in |
69 * the drag source (value is 1 << 2). | 72 * the drag source (value is 1 << 2). |
70 */ | 73 */ |
71 public final static int DROP_LINK = 1 << 2; | 74 public const static int DROP_LINK = 1 << 2; |
72 | 75 |
73 /** | 76 /** |
74 * Drag and Drop Operation: the drop target moves the data and the drag source removes | 77 * Drag and Drop Operation: the drop target moves the data and the drag source removes |
75 * any references to the data and updates its display. This is not available on all platforms | 78 * any references to the data and updates its display. This is not available on all platforms |
76 * and is only used when a non-DWT application is the drop target. In this case, the DWT | 79 * and is only used when a non-DWT application is the drop target. In this case, the DWT |
77 * drag source is informed in the dragFinished event that the drop target has moved the data. | 80 * drag source is informed in the dragFinished event that the drop target has moved the data. |
78 * (value is 1 << 3). | 81 * (value is 1 << 3). |
79 * | 82 * |
80 * @see DragSourceListener#dragFinished | 83 * @see DragSourceListener#dragFinished |
81 */ | 84 */ |
82 public final static int DROP_TARGET_MOVE = 1 << 3; | 85 public const static int DROP_TARGET_MOVE = 1 << 3; |
83 | 86 |
84 /** | 87 /** |
85 * Drag and Drop Operation: During a dragEnter event or a dragOperationChanged, if no modifier keys | 88 * Drag and Drop Operation: During a dragEnter event or a dragOperationChanged, if no modifier keys |
86 * are pressed, the operation is set to DROP_DEFAULT. The application can choose what the default | 89 * are pressed, the operation is set to DROP_DEFAULT. The application can choose what the default |
87 * operation should be by setting a new value in the operation field. If no value is choosen, the | 90 * operation should be by setting a new value in the operation field. If no value is choosen, the |
89 * | 92 * |
90 * @see DropTargetListener#dragEnter | 93 * @see DropTargetListener#dragEnter |
91 * @see DropTargetListener#dragOperationChanged | 94 * @see DropTargetListener#dragOperationChanged |
92 * @since 2.0 | 95 * @since 2.0 |
93 */ | 96 */ |
94 public final static int DROP_DEFAULT = 1 << 4; | 97 public const static int DROP_DEFAULT = 1 << 4; |
95 | 98 |
96 /** | 99 /** |
97 * DragSource Event: the drop has successfully completed or has been terminated (such as hitting | 100 * DragSource Event: the drop has successfully completed or has been terminated (such as hitting |
98 * the ESC key); perform cleanup such as removing data on a move operation (value is 2000). | 101 * the ESC key); perform cleanup such as removing data on a move operation (value is 2000). |
99 */ | 102 */ |
100 public static final int DragEnd = 2000; | 103 public static const int DragEnd = 2000; |
101 | 104 |
102 /** | 105 /** |
103 * DragSource Event: the data to be dropped is required from the drag source (value is 2001). | 106 * DragSource Event: the data to be dropped is required from the drag source (value is 2001). |
104 */ | 107 */ |
105 public static final int DragSetData = 2001; | 108 public static const int DragSetData = 2001; |
106 | 109 |
107 /** | 110 /** |
108 * DropTarget Event: the cursor has entered the drop target boundaries (value is 2002). | 111 * DropTarget Event: the cursor has entered the drop target boundaries (value is 2002). |
109 */ | 112 */ |
110 public static final int DragEnter = 2002; | 113 public static const int DragEnter = 2002; |
111 | 114 |
112 /** | 115 /** |
113 * DropTarget Event: the cursor has left the drop target boundaries OR the drop | 116 * DropTarget Event: the cursor has left the drop target boundaries OR the drop |
114 * operation has been cancelled (such as by hitting ECS) OR the drop is about to | 117 * operation has been cancelled (such as by hitting ECS) OR the drop is about to |
115 * happen (user has released the mouse button over this target) (value is 2003). | 118 * happen (user has released the mouse button over this target) (value is 2003). |
116 */ | 119 */ |
117 public static final int DragLeave = 2003; | 120 public static const int DragLeave = 2003; |
118 | 121 |
119 /** | 122 /** |
120 * DropTarget Event: the cursor is over the drop target (value is 2004). | 123 * DropTarget Event: the cursor is over the drop target (value is 2004). |
121 */ | 124 */ |
122 public static final int DragOver = 2004; | 125 public static const int DragOver = 2004; |
123 | 126 |
124 /** | 127 /** |
125 * DropTarget Event: the operation being performed has changed usually due to the user | 128 * DropTarget Event: the operation being performed has changed usually due to the user |
126 * changing the selected modifier keys while dragging (value is 2005). | 129 * changing the selected modifier keys while dragging (value is 2005). |
127 */ | 130 */ |
128 public static final int DragOperationChanged = 2005; | 131 public static const int DragOperationChanged = 2005; |
129 | 132 |
130 /** | 133 /** |
131 * DropTarget Event: the data has been dropped (value is 2006). | 134 * DropTarget Event: the data has been dropped (value is 2006). |
132 */ | 135 */ |
133 public static final int Drop = 2006; | 136 public static const int Drop = 2006; |
134 | 137 |
135 /** | 138 /** |
136 * DropTarget Event: the drop target is given a last chance to modify the drop (value is 2007). | 139 * DropTarget Event: the drop target is given a last chance to modify the drop (value is 2007). |
137 */ | 140 */ |
138 public static final int DropAccept = 2007; | 141 public static const int DropAccept = 2007; |
139 | 142 |
140 /** | 143 /** |
141 * DragSource Event: a drag is about to begin (value is 2008). | 144 * DragSource Event: a drag is about to begin (value is 2008). |
142 */ | 145 */ |
143 public static final int DragStart = 2008; | 146 public static const int DragStart = 2008; |
144 | 147 |
145 /** | 148 /** |
146 * DropTarget drag under effect: No effect is shown (value is 0). | 149 * DropTarget drag under effect: No effect is shown (value is 0). |
147 */ | 150 */ |
148 public static final int FEEDBACK_NONE = 0; | 151 public static const int FEEDBACK_NONE = 0; |
149 | 152 |
150 /** | 153 /** |
151 * DropTarget drag under effect: The item under the cursor is selected; applies to tables | 154 * DropTarget drag under effect: The item under the cursor is selected; applies to tables |
152 * and trees (value is 1). | 155 * and trees (value is 1). |
153 */ | 156 */ |
154 public static final int FEEDBACK_SELECT = 1; | 157 public static const int FEEDBACK_SELECT = 1; |
155 | 158 |
156 /** | 159 /** |
157 * DropTarget drag under effect: An insertion mark is shown before the item under the cursor; applies to | 160 * DropTarget drag under effect: An insertion mark is shown before the item under the cursor; applies to |
158 * trees (value is 2). | 161 * trees (value is 2). |
159 */ | 162 */ |
160 public static final int FEEDBACK_INSERT_BEFORE = 2; | 163 public static const int FEEDBACK_INSERT_BEFORE = 2; |
161 | 164 |
162 /** | 165 /** |
163 * DropTarget drag under effect:An insertion mark is shown after the item under the cursor; applies to | 166 * DropTarget drag under effect:An insertion mark is shown after the item under the cursor; applies to |
164 * trees (value is 4). | 167 * trees (value is 4). |
165 */ | 168 */ |
166 public static final int FEEDBACK_INSERT_AFTER = 4; | 169 public static const int FEEDBACK_INSERT_AFTER = 4; |
167 | 170 |
168 /** | 171 /** |
169 * DropTarget drag under effect: The widget is scrolled up or down to allow the user to drop on items that | 172 * DropTarget drag under effect: The widget is scrolled up or down to allow the user to drop on items that |
170 * are not currently visible; applies to tables and trees (value is 8). | 173 * are not currently visible; applies to tables and trees (value is 8). |
171 */ | 174 */ |
172 public static final int FEEDBACK_SCROLL = 8; | 175 public static const int FEEDBACK_SCROLL = 8; |
173 | 176 |
174 /** | 177 /** |
175 * DropTarget drag under effect: The item currently under the cursor is expanded to allow the user to | 178 * DropTarget drag under effect: The item currently under the cursor is expanded to allow the user to |
176 * select a drop target from a sub item; applies to trees (value is 16). | 179 * select a drop target from a sub item; applies to trees (value is 16). |
177 */ | 180 */ |
178 public static final int FEEDBACK_EXPAND = 16; | 181 public static const int FEEDBACK_EXPAND = 16; |
179 | 182 |
180 /** | 183 /** |
181 * Error code: drag source can not be initialized (value is 2000). | 184 * Error code: drag source can not be initialized (value is 2000). |
182 */ | 185 */ |
183 public static final int ERROR_CANNOT_INIT_DRAG = 2000; | 186 public static const int ERROR_CANNOT_INIT_DRAG = 2000; |
184 | 187 |
185 /** | 188 /** |
186 * Error code: drop target cannot be initialized (value is 2001). | 189 * Error code: drop target cannot be initialized (value is 2001). |
187 */ | 190 */ |
188 public static final int ERROR_CANNOT_INIT_DROP = 2001; | 191 public static const int ERROR_CANNOT_INIT_DROP = 2001; |
189 | 192 |
190 /** | 193 /** |
191 * Error code: Data can not be set on system clipboard (value is 2002). | 194 * Error code: Data can not be set on system clipboard (value is 2002). |
192 */ | 195 */ |
193 public static final int ERROR_CANNOT_SET_CLIPBOARD = 2002; | 196 public static const int ERROR_CANNOT_SET_CLIPBOARD = 2002; |
194 | 197 |
195 /** | 198 /** |
196 * Error code: Data does not have correct format for type (value is 2003). | 199 * Error code: Data does not have correct format for type (value is 2003). |
197 * @since 3.1 | 200 * @since 3.1 |
198 */ | 201 */ |
199 public static final int ERROR_INVALID_DATA = 2003; | 202 public static const int ERROR_INVALID_DATA = 2003; |
200 | 203 |
201 /** | 204 /** |
202 * DropTarget Key: The string constant for looking up the drop target | 205 * DropTarget Key: The string constant for looking up the drop target |
203 * for a control using <code>getData(String)</code>. When a drop target | 206 * for a control using <code>getData(String)</code>. When a drop target |
204 * is created for a control, it is stored as a property in the control | 207 * is created for a control, it is stored as a property in the control |
205 * using <code>setData(String, Object)</code>. | 208 * using <code>setData(String, Object)</code>. |
206 * | 209 * |
207 * @since 3.4 | 210 * @since 3.4 |
208 */ | 211 */ |
209 public static final String DROP_TARGET_KEY = "DropTarget"; //$NON-NLS-1$ | 212 public static const String DROP_TARGET_KEY = "DropTarget"; //$NON-NLS-1$ |
210 | 213 |
211 /** | 214 /** |
212 * DragSource Key: The string constant for looking up the drag source | 215 * DragSource Key: The string constant for looking up the drag source |
213 * for a control using <code>getData(String)</code>. When a drag source | 216 * for a control using <code>getData(String)</code>. When a drag source |
214 * is created for a control, it is stored as a property in the control | 217 * is created for a control, it is stored as a property in the control |
215 * using <code>setData(String, Object)</code>. | 218 * using <code>setData(String, Object)</code>. |
216 * | 219 * |
217 * @since 3.4 | 220 * @since 3.4 |
218 */ | 221 */ |
219 public static final String DRAG_SOURCE_KEY = "DragSource"; //$NON-NLS-1$ | 222 public static const String DRAG_SOURCE_KEY = "DragSource"; //$NON-NLS-1$ |
220 | 223 |
221 static final String INIT_DRAG_MESSAGE = "Cannot initialize Drag"; //$NON-NLS-1$ | 224 static const String INIT_DRAG_MESSAGE = "Cannot initialize Drag"; //$NON-NLS-1$ |
222 static final String INIT_DROP_MESSAGE = "Cannot initialize Drop"; //$NON-NLS-1$ | 225 static const String INIT_DROP_MESSAGE = "Cannot initialize Drop"; //$NON-NLS-1$ |
223 static final String CANNOT_SET_CLIPBOARD_MESSAGE = "Cannot set data in clipboard"; //$NON-NLS-1$ | 226 static const String CANNOT_SET_CLIPBOARD_MESSAGE = "Cannot set data in clipboard"; //$NON-NLS-1$ |
224 static final String INVALID_DATA_MESSAGE = "Data does not have correct format for type"; //$NON-NLS-1$ | 227 static const String INVALID_DATA_MESSAGE = "Data does not have correct format for type"; //$NON-NLS-1$ |
225 | 228 |
226 /** | 229 /** |
227 * Throws an appropriate exception based on the passed in error code. | 230 * Throws an appropriate exception based on the passed in error code. |
228 * | 231 * |
229 * @param code the DND error code | 232 * @param code the DND error code |
260 public static void error (int code, int hresult) { | 263 public static void error (int code, int hresult) { |
261 switch (code) { | 264 switch (code) { |
262 /* OS Failure/Limit (fatal, may occur only on some platforms) */ | 265 /* OS Failure/Limit (fatal, may occur only on some platforms) */ |
263 case DND.ERROR_CANNOT_INIT_DRAG:{ | 266 case DND.ERROR_CANNOT_INIT_DRAG:{ |
264 String msg = DND.INIT_DRAG_MESSAGE; | 267 String msg = DND.INIT_DRAG_MESSAGE; |
265 if (hresult !is 0) msg += " result = "+hresult; //$NON-NLS-1$ | 268 if (hresult !is 0) msg ~= " result = "~Integer.toString(hresult); //$NON-NLS-1$ |
266 throw new DWTError (code, msg); | 269 throw new DWTError (code, msg); |
267 } | 270 } |
268 case DND.ERROR_CANNOT_INIT_DROP:{ | 271 case DND.ERROR_CANNOT_INIT_DROP:{ |
269 String msg = DND.INIT_DROP_MESSAGE; | 272 String msg = DND.INIT_DROP_MESSAGE; |
270 if (hresult !is 0) msg += " result = "+hresult; //$NON-NLS-1$ | 273 if (hresult !is 0) msg += " result = "~Integer.toString(hresult); //$NON-NLS-1$ |
271 throw new DWTError (code, msg); | 274 throw new DWTError (code, msg); |
272 } | 275 } |
273 case DND.ERROR_CANNOT_SET_CLIPBOARD:{ | 276 case DND.ERROR_CANNOT_SET_CLIPBOARD:{ |
274 String msg = DND.CANNOT_SET_CLIPBOARD_MESSAGE; | 277 String msg = DND.CANNOT_SET_CLIPBOARD_MESSAGE; |
275 if (hresult !is 0) msg += " result = "+hresult; //$NON-NLS-1$ | 278 if (hresult !is 0) msg += " result = "~Integer.toString(hresult); //$NON-NLS-1$ |
276 throw new DWTError (code, msg); | 279 throw new DWTError (code, msg); |
277 } | 280 } |
278 case DND.ERROR_INVALID_DATA:{ | 281 case DND.ERROR_INVALID_DATA:{ |
279 String msg = DND.INVALID_DATA_MESSAGE; | 282 String msg = DND.INVALID_DATA_MESSAGE; |
280 if (hresult !is 0) msg += " result = "+hresult; //$NON-NLS-1$ | 283 if (hresult !is 0) msg += " result = "~Integer.toString(hresult); //$NON-NLS-1$ |
281 throw new DWTException (code, msg); | 284 throw new DWTException (code, msg); |
282 } | 285 } |
286 | |
287 default: | |
283 } | 288 } |
284 | 289 |
285 /* Unknown/Undefined Error */ | 290 /* Unknown/Undefined Error */ |
286 DWT.error(code); | 291 DWT.error(code); |
287 } | 292 } |