comparison dwt/dnd/DropTargetEffect.d @ 101:43123e716bda

Ported dwt.dnd.DropTargetEffect
author Jacob Carlborg <doob@me.com>
date Wed, 31 Dec 2008 13:21:58 +0100
parents d8635bb48c7c
children
comparison
equal deleted inserted replaced
100:c2f1ba00473b 101:43123e716bda
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.DropTargetEffect; 14 module dwt.dnd.DropTargetEffect;
12 15
13 import dwt.dwthelper.utils; 16 import dwt.dwthelper.utils;
14 17
19 import dwt.widgets.Table; 22 import dwt.widgets.Table;
20 import dwt.widgets.TableItem; 23 import dwt.widgets.TableItem;
21 import dwt.widgets.Tree; 24 import dwt.widgets.Tree;
22 import dwt.widgets.TreeItem; 25 import dwt.widgets.TreeItem;
23 import dwt.widgets.Widget; 26 import dwt.widgets.Widget;
27
28 import dwt.dnd.DropTargetAdapter;
24 29
25 30
26 /** 31 /**
27 * This class provides a default drag under effect during a drag and drop. 32 * This class provides a default drag under effect during a drag and drop.
28 * The current implementation does not provide any visual feedback. 33 * The current implementation does not provide any visual feedback.
54 * @see DropTargetEvent 59 * @see DropTargetEvent
55 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> 60 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
56 * 61 *
57 * @since 3.3 62 * @since 3.3
58 */ 63 */
59 public class DropTargetEffect extends DropTargetAdapter { 64 public class DropTargetEffect : DropTargetAdapter {
60 Control control; 65 Control control;
61 66
62 /** 67 /**
63 * Creates a new <code>DropTargetEffect</code> to handle the drag under effect on the specified 68 * Creates a new <code>DropTargetEffect</code> to handle the drag under effect on the specified
64 * <code>Control</code>. 69 * <code>Control</code>.
67 * 72 *
68 * @exception IllegalArgumentException <ul> 73 * @exception IllegalArgumentException <ul>
69 * <li>ERROR_NULL_ARGUMENT - if the control is null</li> 74 * <li>ERROR_NULL_ARGUMENT - if the control is null</li>
70 * </ul> 75 * </ul>
71 */ 76 */
72 public DropTargetEffect(Control control) { 77 public this(Control control) {
73 if (control is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 78 if (control is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
74 this.control = control; 79 this.control = control;
75 } 80 }
76 81
77 /** 82 /**
92 * @param x the x coordinate used to locate the item 97 * @param x the x coordinate used to locate the item
93 * @param y the y coordinate used to locate the item 98 * @param y the y coordinate used to locate the item
94 * @return the item at the given x-y coordinate, or null if the coordinate is not in a selectable item 99 * @return the item at the given x-y coordinate, or null if the coordinate is not in a selectable item
95 */ 100 */
96 public Widget getItem(int x, int y) { 101 public Widget getItem(int x, int y) {
97 if (control instanceof Table) { 102 if (cast(Table) control) {
98 return getItem((Table) control, x, y); 103 return getItem(cast(Table) control, x, y);
99 } 104 }
100 if (control instanceof Tree) { 105 if (cast(Tree) control) {
101 return getItem((Tree) control, x, y); 106 return getItem(cast(Tree) control, x, y);
102 } 107 }
103 return null; 108 return null;
104 } 109 }
105 110
106 Widget getItem(Table table, int x, int y) { 111 Widget getItem(Table table, int x, int y) {
165 if (item is null) return null; 170 if (item is null) return null;
166 TreeItem childItem = item; 171 TreeItem childItem = item;
167 TreeItem parentItem = childItem.getParentItem(); 172 TreeItem parentItem = childItem.getParentItem();
168 int index = parentItem is null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); 173 int index = parentItem is null ? tree.indexOf(childItem) : parentItem.indexOf(childItem);
169 if (index is 0) return parentItem; 174 if (index is 0) return parentItem;
170 TreeItem nextItem = parentItem is null ? tree.getItem(index-1) : parentItem.getItem(index-1); 175 TreeItem nextItem_ = parentItem is null ? tree.getItem(index-1) : parentItem.getItem(index-1);
171 int count = nextItem.getItemCount(); 176 int count = nextItem_.getItemCount();
172 while (count > 0 && nextItem.getExpanded()) { 177 while (count > 0 && nextItem_.getExpanded()) {
173 nextItem = nextItem.getItem(count - 1); 178 nextItem_ = nextItem_.getItem(count - 1);
174 count = nextItem.getItemCount(); 179 count = nextItem_.getItemCount();
175 } 180 }
176 return nextItem; 181 return nextItem_;
177 } 182 }
178 } 183 }