Mercurial > projects > dwt-linux
annotate dwt/dnd/TableDropTargetEffect.d @ 364:2bcb17ebe0be default tip
fix: thx torhu
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 08 Nov 2009 20:57:46 +0100 |
parents | c0d810de7093 |
children |
rev | line source |
---|---|
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
1 /******************************************************************************* |
259 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
92 | 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.TableDropTargetEffect; | |
14 | |
15 | |
16 import dwt.graphics.Point; | |
17 import dwt.internal.gtk.OS; | |
18 import dwt.widgets.Table; | |
19 import dwt.dnd.DropTargetEffect; | |
20 import dwt.dnd.DropTargetEvent; | |
21 import dwt.dnd.DND; | |
22 | |
23 import dwt.dwthelper.System; | |
24 | |
25 /** | |
26 * This class provides a default drag under effect (eg. select, insert and scroll) | |
27 * when a drag occurs over a <code>Table</code>. | |
28 * | |
29 * <p>Classes that wish to provide their own drag under effect for a <code>Table</code> | |
30 * can extend the <code>TableDropTargetEffect</code> and override any applicable methods | |
31 * in <code>TableDropTargetEffect</code> to display their own drag under effect.</p> | |
32 * | |
33 * Subclasses that override any methods of this class must call the corresponding | |
34 * <code>super</code> method to get the default drag under effect implementation. | |
35 * | |
36 * <p>The feedback value is either one of the FEEDBACK constants defined in | |
37 * class <code>DND</code> which is applicable to instances of this class, | |
38 * or it must be built by <em>bitwise OR</em>'ing together | |
39 * (that is, using the <code>int</code> "|" operator) two or more | |
40 * of those <code>DND</code> effect constants. | |
41 * </p> | |
42 * <p> | |
43 * <dl> | |
44 * <dt><b>Feedback:</b></dt> | |
45 * <dd>FEEDBACK_SELECT, FEEDBACK_SCROLL</dd> | |
46 * </dl> | |
47 * </p> | |
48 * | |
49 * @see DropTargetAdapter | |
50 * @see DropTargetEvent | |
259 | 51 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
92 | 52 * |
53 * @since 3.3 | |
54 */ | |
55 public class TableDropTargetEffect : DropTargetEffect { | |
56 static const int SCROLL_HYSTERESIS = 150; // milli seconds | |
57 | |
58 int scrollIndex; | |
59 long scrollBeginTime; | |
60 | |
61 /** | |
62 * Creates a new <code>TableDropTargetEffect</code> to handle the drag under effect on the specified | |
63 * <code>Table</code>. | |
64 * | |
65 * @param table the <code>Table</code> over which the user positions the cursor to drop the data | |
66 */ | |
67 public this(Table table) { | |
68 super(table); | |
69 } | |
70 | |
71 int checkEffect(int effect) { | |
72 // Some effects are mutually exclusive. Make sure that only one of the mutually exclusive effects has been specified. | |
73 if ((effect & DND.FEEDBACK_SELECT) !is 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER & ~DND.FEEDBACK_INSERT_BEFORE; | |
74 if ((effect & DND.FEEDBACK_INSERT_BEFORE) !is 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER; | |
75 return effect; | |
76 } | |
77 | |
78 /** | |
79 * This implementation of <code>dragEnter</code> provides a default drag under effect | |
80 * for the feedback specified in <code>event.feedback</code>. | |
81 * | |
82 * For additional information see <code>DropTargetAdapter.dragEnter</code>. | |
83 * | |
84 * Subclasses that override this method should call <code>super.dragEnter(event)</code> | |
85 * to get the default drag under effect implementation. | |
86 * | |
87 * @param event the information associated with the drag enter event | |
88 * | |
89 * @see DropTargetAdapter | |
90 * @see DropTargetEvent | |
91 */ | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
92 public override void dragEnter(DropTargetEvent event) { |
92 | 93 scrollBeginTime = 0; |
94 scrollIndex = -1; | |
95 } | |
96 | |
97 /** | |
98 * This implementation of <code>dragLeave</code> provides a default drag under effect | |
99 * for the feedback specified in <code>event.feedback</code>. | |
100 * | |
101 * For additional information see <code>DropTargetAdapter.dragLeave</code>. | |
102 * | |
103 * Subclasses that override this method should call <code>super.dragLeave(event)</code> | |
104 * to get the default drag under effect implementation. | |
105 * | |
106 * @param event the information associated with the drag leave event | |
107 * | |
108 * @see DropTargetAdapter | |
109 * @see DropTargetEvent | |
110 */ | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
111 public override void dragLeave(DropTargetEvent event) { |
92 | 112 Table table = cast(Table) control; |
113 auto handle = table.handle; | |
240 | 114 OS.gtk_tree_view_set_drag_dest_row(handle, null, OS.GTK_TREE_VIEW_DROP_BEFORE); |
92 | 115 |
116 scrollBeginTime = 0; | |
117 scrollIndex = -1; | |
118 } | |
119 | |
120 /** | |
121 * This implementation of <code>dragOver</code> provides a default drag under effect | |
122 * for the feedback specified in <code>event.feedback</code>. The class description | |
123 * lists the FEEDBACK constants that are applicable to the class. | |
124 * | |
125 * For additional information see <code>DropTargetAdapter.dragOver</code>. | |
126 * | |
127 * Subclasses that override this method should call <code>super.dragOver(event)</code> | |
128 * to get the default drag under effect implementation. | |
129 * | |
130 * @param event the information associated with the drag over event | |
131 * | |
132 * @see DropTargetAdapter | |
133 * @see DropTargetEvent | |
134 * @see DND#FEEDBACK_SELECT | |
135 * @see DND#FEEDBACK_SCROLL | |
136 */ | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
137 public override void dragOver(DropTargetEvent event) { |
92 | 138 Table table = cast(Table) control; |
139 auto handle = table.handle; | |
140 int effect = checkEffect(event.feedback); | |
141 Point coordinates = new Point(event.x, event.y); | |
142 coordinates = table.toControl(coordinates); | |
143 void* path; | |
144 OS.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, &path, null, null, null); | |
145 int index = -1; | |
146 if (path !is null) { | |
147 auto indices = OS.gtk_tree_path_get_indices (path); | |
148 if (indices !is null) { | |
149 index = indices[0]; | |
150 } | |
151 } | |
152 if ((effect & DND.FEEDBACK_SCROLL) is 0) { | |
153 scrollBeginTime = 0; | |
154 scrollIndex = -1; | |
155 } else { | |
156 if (index !is -1 && scrollIndex is index && scrollBeginTime !is 0) { | |
157 if (System.currentTimeMillis() >= scrollBeginTime) { | |
158 if (coordinates.y < table.getItemHeight()) { | |
159 OS.gtk_tree_path_prev(path); | |
160 } else { | |
161 OS.gtk_tree_path_next(path); | |
162 } | |
163 if (path !is null) { | |
164 OS.gtk_tree_view_scroll_to_cell(handle, path, null, false, 0, 0); | |
165 OS.gtk_tree_path_free(path); | |
166 path = null; | |
167 OS.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, &path, null, null, null); | |
168 } | |
169 scrollBeginTime = 0; | |
170 scrollIndex = -1; | |
171 } | |
172 } else { | |
173 scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS; | |
174 scrollIndex = index; | |
175 } | |
176 } | |
177 if (path !is null) { | |
178 int position = 0; | |
179 if ((effect & DND.FEEDBACK_SELECT) !is 0) position = OS.GTK_TREE_VIEW_DROP_INTO_OR_BEFORE; | |
180 //if ((effect & DND.FEEDBACK_INSERT_BEFORE) !is 0) position = OS.GTK_TREE_VIEW_DROP_BEFORE; | |
181 //if ((effect & DND.FEEDBACK_INSERT_AFTER) !is 0) position = OS.GTK_TREE_VIEW_DROP_AFTER; | |
182 if (position !is 0) { | |
183 OS.gtk_tree_view_set_drag_dest_row(handle, path, OS.GTK_TREE_VIEW_DROP_INTO_OR_BEFORE); | |
184 } else { | |
240 | 185 OS.gtk_tree_view_set_drag_dest_row(handle, null, OS.GTK_TREE_VIEW_DROP_BEFORE); |
92 | 186 } |
187 } else { | |
240 | 188 OS.gtk_tree_view_set_drag_dest_row(handle, null, OS.GTK_TREE_VIEW_DROP_BEFORE); |
92 | 189 } |
190 if (path !is null) OS.gtk_tree_path_free (path ); | |
191 } | |
192 } |