Mercurial > projects > dwt-linux
annotate dwt/dnd/TableDropTargetEffect.d @ 240:ce446666f5a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 12 May 2008 19:13:01 +0200 |
parents | f2e04420fd6c |
children | c0d810de7093 |
rev | line source |
---|---|
150
f2e04420fd6c
reworked overrides and superclass aliases
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.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 | |
51 * | |
52 * @since 3.3 | |
53 */ | |
54 public class TableDropTargetEffect : DropTargetEffect { | |
55 static const int SCROLL_HYSTERESIS = 150; // milli seconds | |
56 | |
57 int scrollIndex; | |
58 long scrollBeginTime; | |
59 | |
60 /** | |
61 * Creates a new <code>TableDropTargetEffect</code> to handle the drag under effect on the specified | |
62 * <code>Table</code>. | |
63 * | |
64 * @param table the <code>Table</code> over which the user positions the cursor to drop the data | |
65 */ | |
66 public this(Table table) { | |
67 super(table); | |
68 } | |
69 | |
70 int checkEffect(int effect) { | |
71 // Some effects are mutually exclusive. Make sure that only one of the mutually exclusive effects has been specified. | |
72 if ((effect & DND.FEEDBACK_SELECT) !is 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER & ~DND.FEEDBACK_INSERT_BEFORE; | |
73 if ((effect & DND.FEEDBACK_INSERT_BEFORE) !is 0) effect = effect & ~DND.FEEDBACK_INSERT_AFTER; | |
74 return effect; | |
75 } | |
76 | |
77 /** | |
78 * This implementation of <code>dragEnter</code> provides a default drag under effect | |
79 * for the feedback specified in <code>event.feedback</code>. | |
80 * | |
81 * For additional information see <code>DropTargetAdapter.dragEnter</code>. | |
82 * | |
83 * Subclasses that override this method should call <code>super.dragEnter(event)</code> | |
84 * to get the default drag under effect implementation. | |
85 * | |
86 * @param event the information associated with the drag enter event | |
87 * | |
88 * @see DropTargetAdapter | |
89 * @see DropTargetEvent | |
90 */ | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
91 public override void dragEnter(DropTargetEvent event) { |
92 | 92 scrollBeginTime = 0; |
93 scrollIndex = -1; | |
94 } | |
95 | |
96 /** | |
97 * This implementation of <code>dragLeave</code> provides a default drag under effect | |
98 * for the feedback specified in <code>event.feedback</code>. | |
99 * | |
100 * For additional information see <code>DropTargetAdapter.dragLeave</code>. | |
101 * | |
102 * Subclasses that override this method should call <code>super.dragLeave(event)</code> | |
103 * to get the default drag under effect implementation. | |
104 * | |
105 * @param event the information associated with the drag leave event | |
106 * | |
107 * @see DropTargetAdapter | |
108 * @see DropTargetEvent | |
109 */ | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
110 public override void dragLeave(DropTargetEvent event) { |
92 | 111 Table table = cast(Table) control; |
112 auto handle = table.handle; | |
240 | 113 OS.gtk_tree_view_set_drag_dest_row(handle, null, OS.GTK_TREE_VIEW_DROP_BEFORE); |
92 | 114 |
115 scrollBeginTime = 0; | |
116 scrollIndex = -1; | |
117 } | |
118 | |
119 /** | |
120 * This implementation of <code>dragOver</code> provides a default drag under effect | |
121 * for the feedback specified in <code>event.feedback</code>. The class description | |
122 * lists the FEEDBACK constants that are applicable to the class. | |
123 * | |
124 * For additional information see <code>DropTargetAdapter.dragOver</code>. | |
125 * | |
126 * Subclasses that override this method should call <code>super.dragOver(event)</code> | |
127 * to get the default drag under effect implementation. | |
128 * | |
129 * @param event the information associated with the drag over event | |
130 * | |
131 * @see DropTargetAdapter | |
132 * @see DropTargetEvent | |
133 * @see DND#FEEDBACK_SELECT | |
134 * @see DND#FEEDBACK_SCROLL | |
135 */ | |
150
f2e04420fd6c
reworked overrides and superclass aliases
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
136 public override void dragOver(DropTargetEvent event) { |
92 | 137 Table table = cast(Table) control; |
138 auto handle = table.handle; | |
139 int effect = checkEffect(event.feedback); | |
140 Point coordinates = new Point(event.x, event.y); | |
141 coordinates = table.toControl(coordinates); | |
142 void* path; | |
143 OS.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, &path, null, null, null); | |
144 int index = -1; | |
145 if (path !is null) { | |
146 auto indices = OS.gtk_tree_path_get_indices (path); | |
147 if (indices !is null) { | |
148 index = indices[0]; | |
149 } | |
150 } | |
151 if ((effect & DND.FEEDBACK_SCROLL) is 0) { | |
152 scrollBeginTime = 0; | |
153 scrollIndex = -1; | |
154 } else { | |
155 if (index !is -1 && scrollIndex is index && scrollBeginTime !is 0) { | |
156 if (System.currentTimeMillis() >= scrollBeginTime) { | |
157 if (coordinates.y < table.getItemHeight()) { | |
158 OS.gtk_tree_path_prev(path); | |
159 } else { | |
160 OS.gtk_tree_path_next(path); | |
161 } | |
162 if (path !is null) { | |
163 OS.gtk_tree_view_scroll_to_cell(handle, path, null, false, 0, 0); | |
164 OS.gtk_tree_path_free(path); | |
165 path = null; | |
166 OS.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, &path, null, null, null); | |
167 } | |
168 scrollBeginTime = 0; | |
169 scrollIndex = -1; | |
170 } | |
171 } else { | |
172 scrollBeginTime = System.currentTimeMillis() + SCROLL_HYSTERESIS; | |
173 scrollIndex = index; | |
174 } | |
175 } | |
176 if (path !is null) { | |
177 int position = 0; | |
178 if ((effect & DND.FEEDBACK_SELECT) !is 0) position = OS.GTK_TREE_VIEW_DROP_INTO_OR_BEFORE; | |
179 //if ((effect & DND.FEEDBACK_INSERT_BEFORE) !is 0) position = OS.GTK_TREE_VIEW_DROP_BEFORE; | |
180 //if ((effect & DND.FEEDBACK_INSERT_AFTER) !is 0) position = OS.GTK_TREE_VIEW_DROP_AFTER; | |
181 if (position !is 0) { | |
182 OS.gtk_tree_view_set_drag_dest_row(handle, path, OS.GTK_TREE_VIEW_DROP_INTO_OR_BEFORE); | |
183 } else { | |
240 | 184 OS.gtk_tree_view_set_drag_dest_row(handle, null, OS.GTK_TREE_VIEW_DROP_BEFORE); |
92 | 185 } |
186 } else { | |
240 | 187 OS.gtk_tree_view_set_drag_dest_row(handle, null, OS.GTK_TREE_VIEW_DROP_BEFORE); |
92 | 188 } |
189 if (path !is null) OS.gtk_tree_path_free (path ); | |
190 } | |
191 } |