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