| 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 dwt.dnd.DND; |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
import dwt.DWT; |
|---|
| 17 |
import dwt.DWTError; |
|---|
| 18 |
import dwt.DWTException; |
|---|
| 19 |
|
|---|
| 20 |
import tango.util.Convert; |
|---|
| 21 |
import dwt.dwthelper.utils; |
|---|
| 22 |
|
|---|
| 23 |
/** |
|---|
| 24 |
* |
|---|
| 25 |
* Class DND contains all the constants used in defining a |
|---|
| 26 |
* DragSource or a DropTarget. |
|---|
| 27 |
* |
|---|
| 28 |
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
|---|
| 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 mouse button 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 |
/** |
|---|
| 205 |
* DropTarget Key: The string constant for looking up the drop target |
|---|
| 206 |
* for a control using <code>getData(String)</code>. When a drop target |
|---|
| 207 |
* is created for a control, it is stored as a property in the control |
|---|
| 208 |
* using <code>setData(String, Object)</code>. |
|---|
| 209 |
* |
|---|
| 210 |
* @since 3.4 |
|---|
| 211 |
*/ |
|---|
| 212 |
public static final String DROP_TARGET_KEY = "DropTarget"; //$NON-NLS-1$ |
|---|
| 213 |
|
|---|
| 214 |
/** |
|---|
| 215 |
* DragSource Key: The string constant for looking up the drag source |
|---|
| 216 |
* for a control using <code>getData(String)</code>. When a drag source |
|---|
| 217 |
* is created for a control, it is stored as a property in the control |
|---|
| 218 |
* using <code>setData(String, Object)</code>. |
|---|
| 219 |
* |
|---|
| 220 |
* @since 3.4 |
|---|
| 221 |
*/ |
|---|
| 222 |
public static final String DRAG_SOURCE_KEY = "DragSource"; //$NON-NLS-1$ |
|---|
| 223 |
|
|---|
| 224 |
static const String INIT_DRAG_MESSAGE = "Cannot initialize Drag"; //$NON-NLS-1$ |
|---|
| 225 |
static const String INIT_DROP_MESSAGE = "Cannot initialize Drop"; //$NON-NLS-1$ |
|---|
| 226 |
static const String CANNOT_SET_CLIPBOARD_MESSAGE = "Cannot set data in clipboard"; //$NON-NLS-1$ |
|---|
| 227 |
static const String INVALID_DATA_MESSAGE = "Data does not have correct format for type"; //$NON-NLS-1$ |
|---|
| 228 |
|
|---|
| 229 |
/** |
|---|
| 230 |
* Throws an appropriate exception based on the passed in error code. |
|---|
| 231 |
* |
|---|
| 232 |
* @param code the DND error code |
|---|
| 233 |
*/ |
|---|
| 234 |
public static void error (int code) { |
|---|
| 235 |
error (code, 0); |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
/** |
|---|
| 239 |
* Throws an appropriate exception based on the passed in error code. |
|---|
| 240 |
* The <code>hresult</code> argument should be either 0, or the |
|---|
| 241 |
* platform specific error code. |
|---|
| 242 |
* <p> |
|---|
| 243 |
* In DND, errors are reported by throwing one of three exceptions: |
|---|
| 244 |
* <dl> |
|---|
| 245 |
* <dd>java.lang.IllegalArgumentException</dd> |
|---|
| 246 |
* <dt>thrown whenever one of the API methods is invoked with an illegal argument</dt> |
|---|
| 247 |
* <dd>org.eclipse.swt.DWTException (extends java.lang.RuntimeException)</dd> |
|---|
| 248 |
* <dt>thrown whenever a recoverable error happens internally in DWT</dt> |
|---|
| 249 |
* <dd>org.eclipse.swt.DWTError (extends java.lang.Error)</dd> |
|---|
| 250 |
* <dt>thrown whenever a <b>non-recoverable</b> error happens internally in DWT</dt> |
|---|
| 251 |
* </dl> |
|---|
| 252 |
* This method provides the logic which maps between error codes |
|---|
| 253 |
* and one of the above exceptions. |
|---|
| 254 |
* </p> |
|---|
| 255 |
* |
|---|
| 256 |
* @param code the DND error code. |
|---|
| 257 |
* @param hresult the platform specific error code. |
|---|
| 258 |
* |
|---|
| 259 |
* @see DWTError |
|---|
| 260 |
* @see DWTException |
|---|
| 261 |
* @see IllegalArgumentException |
|---|
| 262 |
*/ |
|---|
| 263 |
public static void error (int code, int hresult) { |
|---|
| 264 |
switch (code) { |
|---|
| 265 |
/* OS Failure/Limit (fatal, may occur only on some platforms) */ |
|---|
| 266 |
case DND.ERROR_CANNOT_INIT_DRAG:{ |
|---|
| 267 |
String msg = DND.INIT_DRAG_MESSAGE; |
|---|
| 268 |
if (hresult !is 0) msg ~= " result = "~to!(String)(hresult); //$NON-NLS-1$ |
|---|
| 269 |
throw new DWTError (code, msg); |
|---|
| 270 |
} |
|---|
| 271 |
case DND.ERROR_CANNOT_INIT_DROP:{ |
|---|
| 272 |
String msg = DND.INIT_DROP_MESSAGE; |
|---|
| 273 |
if (hresult !is 0) msg ~= " result = "~to!(String)(hresult); //$NON-NLS-1$ |
|---|
| 274 |
throw new DWTError (code, msg); |
|---|
| 275 |
} |
|---|
| 276 |
case DND.ERROR_CANNOT_SET_CLIPBOARD:{ |
|---|
| 277 |
String msg = DND.CANNOT_SET_CLIPBOARD_MESSAGE; |
|---|
| 278 |
if (hresult !is 0) msg ~= " result = "~to!(String)(hresult); //$NON-NLS-1$ |
|---|
| 279 |
throw new DWTError (code, msg); |
|---|
| 280 |
} |
|---|
| 281 |
case DND.ERROR_INVALID_DATA:{ |
|---|
| 282 |
String msg = DND.INVALID_DATA_MESSAGE; |
|---|
| 283 |
if (hresult !is 0) msg ~= " result = "~to!(String)(hresult); //$NON-NLS-1$ |
|---|
| 284 |
throw new DWTException (code, msg); |
|---|
| 285 |
} |
|---|
| 286 |
default: |
|---|
| 287 |
} |
|---|
| 288 |
|
|---|
| 289 |
/* Unknown/Undefined Error */ |
|---|
| 290 |
DWT.error(code); |
|---|
| 291 |
} |
|---|
| 292 |
|
|---|
| 293 |
} |
|---|