author | Claus Gittinger <cg@exept.de> |
Thu, 06 Mar 1997 15:16:03 +0100 | |
changeset 494 | ce8c074d5e6b |
parent 411 | 8b8b0128d129 |
child 513 | 8334721d93bb |
permissions | -rw-r--r-- |
341 | 1 |
Object subclass:#DragAndDropManager |
2 |
instanceVariableNames:'dragView motionAction releaseAction initialPoint previousPoint |
|
394 | 3 |
rememberedDelegate dragBlock lineMode dropAction opaque saveUnder |
397 | 4 |
dragSize dragOffset dropObjects saveCursor lastView' |
341 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
7 |
category:'Interface-Support' |
|
8 |
! |
|
9 |
||
397 | 10 |
View subclass:#DemoView |
11 |
instanceVariableNames:'' |
|
12 |
classVariableNames:'' |
|
13 |
poolDictionaries:'' |
|
14 |
privateIn:DragAndDropManager |
|
15 |
! |
|
16 |
||
343 | 17 |
View subclass:#DemoView2 |
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
18 |
instanceVariableNames:'' |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
19 |
classVariableNames:'' |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
20 |
poolDictionaries:'' |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
21 |
privateIn:DragAndDropManager |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
22 |
! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
23 |
|
345 | 24 |
View subclass:#DemoView3 |
341 | 25 |
instanceVariableNames:'' |
26 |
classVariableNames:'' |
|
27 |
poolDictionaries:'' |
|
28 |
privateIn:DragAndDropManager |
|
29 |
! |
|
30 |
||
31 |
!DragAndDropManager class methodsFor:'documentation'! |
|
32 |
||
348 | 33 |
documentation |
34 |
" |
|
35 |
this class provides low-level drag & drop mechanisms. |
|
36 |
||
37 |
[author:] |
|
38 |
Claus Gittinger |
|
39 |
" |
|
40 |
||
41 |
! |
|
42 |
||
341 | 43 |
history |
44 |
||
45 |
"Created: 26.10.1996 / 15:02:00 / cg" |
|
46 |
"Modified: 26.10.1996 / 15:21:42 / cg" |
|
47 |
! ! |
|
48 |
||
397 | 49 |
!DragAndDropManager class methodsFor:'simple start'! |
50 |
||
51 |
startDrag:anObjectOrCollection from:aView |
|
52 |
"start a drop at the current pointer position" |
|
53 |
||
54 |
(self new) startDrag:anObjectOrCollection from:aView offset:0@0 |
|
55 |
||
56 |
||
57 |
" |
|
58 |
|o v| |
|
59 |
||
60 |
v := (Button label:'press me'). |
|
61 |
v pressAction:[ |
|
62 |
|o| |
|
63 |
o := DropObject newFile:('.'). |
|
64 |
DragAndDropManager startDrag:o from:v. |
|
65 |
v turnOff |
|
66 |
]. |
|
67 |
v openAt:100@100 |
|
68 |
" |
|
69 |
||
70 |
! |
|
71 |
||
72 |
startDrag:anObjectOrCollection from:aView offset:offset |
|
73 |
"start a drop at the current pointer position" |
|
74 |
||
75 |
(self new) startDrag:anObjectOrCollection from:aView offset:offset |
|
76 |
||
77 |
||
78 |
" |
|
79 |
|o v| |
|
80 |
||
81 |
v := (Button label:'press me'). |
|
82 |
v pressAction:[ |
|
83 |
|o| |
|
84 |
o := DropObject newFile:('.'). |
|
85 |
DragAndDropManager startDrag:o from:v offset:10@10. |
|
86 |
v turnOff |
|
87 |
]. |
|
88 |
v openAt:100@100 |
|
89 |
" |
|
90 |
||
91 |
! ! |
|
92 |
||
394 | 93 |
!DragAndDropManager methodsFor:'accessing'! |
94 |
||
397 | 95 |
dropObjects |
96 |
^ dropObjects |
|
97 |
! |
|
98 |
||
99 |
dropObjects:anObjectOrCollection |
|
100 |
||
101 |
anObjectOrCollection isCollection ifTrue:[ |
|
102 |
dropObjects := anObjectOrCollection |
|
103 |
] ifFalse:[ |
|
104 |
dropObjects := Array with:anObjectOrCollection |
|
105 |
]. |
|
394 | 106 |
! ! |
107 |
||
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
108 |
!DragAndDropManager methodsFor:'dragging - generic'! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
109 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
110 |
doGenericDragX:x y:y |
394 | 111 |
|view| |
112 |
||
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
113 |
previousPoint notNil ifTrue:[ |
394 | 114 |
opaque ifTrue:[ |
115 |
self restoreGenericAt:previousPoint |
|
116 |
] ifFalse:[ |
|
117 |
self invertGenericAt:previousPoint |
|
118 |
] |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
119 |
]. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
120 |
previousPoint := x @ y. |
394 | 121 |
|
122 |
view := self destinationViewAt:previousPoint. |
|
123 |
view ~~ lastView ifTrue:[ |
|
397 | 124 |
view isNil ifTrue:[ |
125 |
"/ alien view |
|
126 |
dragView cursor:(Cursor questionMark) now:true |
|
394 | 127 |
] ifFalse:[ |
397 | 128 |
"/ ST/X view |
129 |
(view canDrop:dropObjects) ifTrue:[ |
|
130 |
dragView cursor:(Cursor thumbsUp) now:true. |
|
131 |
] ifFalse:[ |
|
132 |
dragView cursor:(Cursor thumbsDown) now:true |
|
133 |
] |
|
394 | 134 |
]. |
135 |
lastView := view |
|
136 |
]. |
|
137 |
||
138 |
opaque ifTrue:[ |
|
139 |
self drawGenericAt:previousPoint. |
|
140 |
] ifFalse:[ |
|
141 |
self invertGenericAt:previousPoint |
|
142 |
]. |
|
143 |
! |
|
144 |
||
145 |
drawGenericAt:ip |
|
146 |
|t offs p rootView| |
|
147 |
||
148 |
rootView := dragView device rootView. |
|
149 |
||
150 |
p := ip. |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
151 |
|
394 | 152 |
" |
153 |
get device coordinates |
|
154 |
" |
|
155 |
(t := dragView transformation) notNil ifTrue:[ |
|
156 |
p := t applyTo:p. |
|
157 |
]. |
|
158 |
||
159 |
" |
|
160 |
translate to screen |
|
161 |
" |
|
162 |
offs := dragView device |
|
163 |
translatePoint:0@0 |
|
164 |
from:(dragView id) to:(rootView id). |
|
165 |
p := p + offs. |
|
166 |
||
167 |
rootView clippedByChildren:false. |
|
168 |
saveUnder isNil ifTrue:[ |
|
169 |
saveUnder := Form width:dragSize x height:dragSize y depth:rootView device depth on:dragView device. |
|
170 |
saveUnder clippedByChildren:false. |
|
171 |
]. |
|
172 |
saveUnder |
|
173 |
copyFrom:rootView |
|
174 |
x:p x - dragOffset x |
|
175 |
y:p y - dragOffset y |
|
176 |
toX:0 |
|
177 |
y:0 |
|
178 |
width:dragSize x |
|
179 |
height:dragSize y. |
|
180 |
||
181 |
rootView lineWidth:0. |
|
182 |
dragBlock value:p value:rootView. |
|
183 |
rootView flush |
|
184 |
||
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
185 |
! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
186 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
187 |
endGenericDragX:x y:y |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
188 |
previousPoint notNil ifTrue:[ |
394 | 189 |
opaque ifTrue:[ |
190 |
self restoreGenericAt:previousPoint |
|
191 |
] ifFalse:[ |
|
192 |
self invertGenericAt:previousPoint |
|
193 |
] |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
194 |
]. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
195 |
previousPoint := nil. |
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
196 |
self uncatchEvents. |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
197 |
self endDragAt:x @ y |
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
198 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
199 |
"Created: 26.10.1996 / 15:17:20 / cg" |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
200 |
"Modified: 26.10.1996 / 15:22:41 / cg" |
394 | 201 |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
202 |
! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
203 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
204 |
invertGenericAt:ip |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
205 |
|t offs p rootView| |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
206 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
207 |
rootView := dragView device rootView. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
208 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
209 |
p := ip. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
210 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
211 |
" |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
212 |
get device coordinates |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
213 |
" |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
214 |
(t := dragView transformation) notNil ifTrue:[ |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
215 |
p := t applyTo:p. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
216 |
]. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
217 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
218 |
" |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
219 |
translate to screen |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
220 |
" |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
221 |
offs := dragView device |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
222 |
translatePoint:0@0 |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
223 |
from:(dragView id) to:(rootView id). |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
224 |
p := p + offs. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
225 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
226 |
rootView clippedByChildren:false. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
227 |
rootView xoring:[ |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
228 |
rootView lineWidth:0. |
348 | 229 |
dragBlock value:p value:rootView. |
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
230 |
rootView flush |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
231 |
]. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
232 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
233 |
"Created: 26.10.1996 / 15:15:26 / cg" |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
234 |
"Modified: 26.10.1996 / 15:27:09 / cg" |
394 | 235 |
|
236 |
! |
|
237 |
||
238 |
restoreGenericAt:ip |
|
239 |
|t offs p rootView| |
|
240 |
||
241 |
||
242 |
rootView := dragView device rootView. |
|
243 |
p := ip. |
|
244 |
||
245 |
" |
|
246 |
get device coordinates |
|
247 |
" |
|
248 |
(t := dragView transformation) notNil ifTrue:[ |
|
249 |
p := t applyTo:p. |
|
250 |
]. |
|
251 |
||
252 |
" |
|
253 |
translate to screen |
|
254 |
" |
|
255 |
offs := dragView device |
|
256 |
translatePoint:0@0 |
|
257 |
from:(dragView id) to:(rootView id). |
|
258 |
p := p + offs. |
|
259 |
||
260 |
rootView clippedByChildren:false. |
|
261 |
rootView |
|
262 |
copyFrom:saveUnder |
|
263 |
x:0 |
|
264 |
y:0 |
|
265 |
toX:p x - dragOffset x |
|
266 |
y:p y - dragOffset y |
|
267 |
width:dragSize x |
|
268 |
height:dragSize y. |
|
269 |
||
270 |
||
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
271 |
! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
272 |
|
348 | 273 |
startGenericDrag:aTwoArgDragBlock in:aView at:p atEnd:aFourArgEndBlock |
274 |
"start a generic (caller-provided drag); |
|
275 |
the dragBlock, aTwoArgDragBlock will be called with two args |
|
276 |
aPoint and a drawingGC, to perform the drawing at some dragPoint. |
|
277 |
The drag starts in aView at point p. |
|
278 |
When finished, the endAction is called with four args: |
|
279 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
280 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
|
281 |
||
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
282 |
self catchEventsFrom:aView. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
283 |
motionAction := #doGenericDragX:y:. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
284 |
releaseAction := #endGenericDragX:y:. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
285 |
initialPoint := p. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
286 |
previousPoint := nil. |
348 | 287 |
dragBlock := aTwoArgDragBlock. |
288 |
dropAction := aFourArgEndBlock. |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
289 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
290 |
"Modified: 26.10.1996 / 15:09:26 / cg" |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
291 |
"Created: 26.10.1996 / 15:16:13 / cg" |
394 | 292 |
|
293 |
! |
|
294 |
||
295 |
startOpaqueDrag:aTwoArgDragBlock offset:offs extent:ext in:aView at:p atEnd:aFourArgEndBlock |
|
296 |
"start a generic opaque (caller-provided drag); |
|
297 |
opaque drag means, that the drawing cannot be undone by two inverting |
|
298 |
draws, but instead, the area under the dragged object must be saved |
|
299 |
and restored. The areas size to be saved/restored is passed in ext. |
|
300 |
the dragBlock, aTwoArgDragBlock will be called with two args |
|
301 |
aPoint and a drawingGC, to perform the drawing at some dragPoint. |
|
302 |
The drag starts in aView at point p. |
|
303 |
When finished, the endAction is called with four args: |
|
304 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
305 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
|
306 |
||
307 |
self catchEventsFrom:aView. |
|
308 |
motionAction := #doGenericDragX:y:. |
|
309 |
releaseAction := #endGenericDragX:y:. |
|
310 |
initialPoint := p. |
|
311 |
previousPoint := nil. |
|
312 |
dragBlock := aTwoArgDragBlock. |
|
313 |
dropAction := aFourArgEndBlock. |
|
314 |
opaque := true. |
|
315 |
dragSize := ext. |
|
316 |
dragOffset := offs. |
|
317 |
||
318 |
"Modified: 26.10.1996 / 15:09:26 / cg" |
|
319 |
"Created: 26.10.1996 / 15:16:13 / cg" |
|
320 |
||
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
321 |
! ! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
322 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
323 |
!DragAndDropManager methodsFor:'dragging - lines'! |
341 | 324 |
|
325 |
doLineDragX:x y:y |
|
326 |
previousPoint notNil ifTrue:[ |
|
327 |
self invertLineFrom:initialPoint to:previousPoint |
|
328 |
]. |
|
329 |
previousPoint := x @ y. |
|
330 |
self invertLineFrom:initialPoint to:previousPoint |
|
331 |
||
332 |
"Modified: 26.10.1996 / 15:16:59 / cg" |
|
394 | 333 |
|
334 |
||
341 | 335 |
! |
336 |
||
337 |
endLineDragX:x y:y |
|
338 |
previousPoint notNil ifTrue:[ |
|
339 |
self invertLineFrom:initialPoint to:previousPoint |
|
340 |
]. |
|
341 |
previousPoint := nil. |
|
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
342 |
self uncatchEvents. |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
343 |
self endDragAt:x @ y |
341 | 344 |
|
345 |
"Created: 26.10.1996 / 15:17:20 / cg" |
|
346 |
"Modified: 26.10.1996 / 15:22:41 / cg" |
|
394 | 347 |
|
341 | 348 |
! |
349 |
||
350 |
invertLineFrom:ip1 to:ip2 |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
351 |
|t offs p1 p2 rootView a| |
341 | 352 |
|
353 |
rootView := dragView device rootView. |
|
354 |
||
355 |
p1 := ip1. |
|
356 |
p2 := ip2. |
|
357 |
||
358 |
" |
|
359 |
get device coordinates |
|
360 |
" |
|
361 |
(t := dragView transformation) notNil ifTrue:[ |
|
362 |
p1 := t applyTo:p1. |
|
363 |
p2 := t applyTo:p2. |
|
364 |
]. |
|
365 |
||
366 |
" |
|
367 |
translate to screen |
|
368 |
" |
|
369 |
offs := dragView device |
|
370 |
translatePoint:0@0 |
|
371 |
from:(dragView id) to:(rootView id). |
|
372 |
p1 := p1 + offs. |
|
373 |
p2 := p2 + offs. |
|
374 |
||
375 |
rootView clippedByChildren:false. |
|
376 |
rootView xoring:[ |
|
377 |
rootView lineWidth:0. |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
378 |
lineMode == #arrow ifTrue:[ |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
379 |
a := Arrow from:p1 to:p2. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
380 |
a arrowHeadLength:(rootView device horizontalPixelPerMillimeter * 4) rounded. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
381 |
a displayFilledOn:rootView. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
382 |
] ifFalse:[ |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
383 |
rootView displayLineFrom:p1 to:p2. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
384 |
]. |
341 | 385 |
rootView flush |
386 |
]. |
|
387 |
||
388 |
"Created: 26.10.1996 / 15:15:26 / cg" |
|
389 |
"Modified: 26.10.1996 / 15:27:09 / cg" |
|
394 | 390 |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
391 |
! |
341 | 392 |
|
345 | 393 |
startArrowDragIn:aView at:p atEnd:aBlock |
348 | 394 |
"start a line-drag of an arrow-line. |
395 |
The drag starts in aView at point p. |
|
396 |
When finished, the endAction is called with four args: |
|
397 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
398 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
|
399 |
||
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
400 |
self catchEventsFrom:aView. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
401 |
motionAction := #doLineDragX:y:. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
402 |
releaseAction := #endLineDragX:y:. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
403 |
initialPoint := p. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
404 |
previousPoint := nil. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
405 |
dragBlock := nil. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
406 |
lineMode := #arrow. |
345 | 407 |
dropAction := aBlock. |
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
408 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
409 |
"Modified: 26.10.1996 / 15:09:26 / cg" |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
410 |
"Created: 26.10.1996 / 15:16:13 / cg" |
394 | 411 |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
412 |
! |
341 | 413 |
|
348 | 414 |
startLineDragIn:aView at:p atEnd:aFourArgEndBlock |
415 |
"start a line-drag of a normal line. |
|
416 |
The drag starts in aView at point p. |
|
417 |
When finished, the endAction is called with four args: |
|
418 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
419 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
|
420 |
||
341 | 421 |
self catchEventsFrom:aView. |
422 |
motionAction := #doLineDragX:y:. |
|
423 |
releaseAction := #endLineDragX:y:. |
|
424 |
initialPoint := p. |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
425 |
previousPoint := nil. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
426 |
dragBlock := nil. |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
427 |
lineMode := nil. |
348 | 428 |
dropAction := aFourArgEndBlock. |
341 | 429 |
|
430 |
"Modified: 26.10.1996 / 15:09:26 / cg" |
|
431 |
"Created: 26.10.1996 / 15:16:13 / cg" |
|
394 | 432 |
|
341 | 433 |
! ! |
434 |
||
397 | 435 |
!DragAndDropManager methodsFor:'drawing'! |
436 |
||
437 |
showDragging:items in:aView at:p |
|
438 |
|offs| |
|
439 |
||
440 |
items size > 1 ifTrue:[ |
|
441 |
offs := 0. |
|
442 |
items do:[:item | |
|
443 |
item displayOn:aView at:p + (0@offs). |
|
444 |
offs := offs + (item heightOn:self) |
|
445 |
] |
|
446 |
] ifFalse:[ |
|
447 |
items first displayOn:aView at:p. |
|
448 |
] |
|
449 |
||
450 |
"Created: 14.11.1996 / 15:31:31 / cg" |
|
451 |
"Modified: 14.11.1996 / 16:32:00 / cg" |
|
452 |
||
453 |
||
454 |
! ! |
|
455 |
||
456 |
!DragAndDropManager methodsFor:'easy drag & drop'! |
|
457 |
||
458 |
startDrag:anObjectOrCollection from:aView offset:offset |
|
459 |
"start a drop at the current pointer position" |
|
460 |
||
461 |
|pos displayObjects device width height| |
|
462 |
||
463 |
self dropObjects:anObjectOrCollection. |
|
464 |
||
465 |
device := aView device. |
|
466 |
pos := device translatePoint:(device pointerPosition) |
|
467 |
from:(device rootView id) |
|
468 |
to:(aView id). |
|
469 |
||
470 |
displayObjects := dropObjects collect:[:each | each displayObject on:device]. |
|
471 |
height := displayObjects inject:0 into:[:sum :each | sum + (each heightOn:aView)]. |
|
472 |
width := displayObjects inject:0 into:[:max :each | max max:(each widthOn:aView)]. |
|
473 |
||
474 |
self startOpaqueDrag:[:aPoint :aView|self showDragging:displayObjects in:aView at:(aPoint - offset)] |
|
475 |
offset:offset |
|
476 |
extent:(width @ height) |
|
477 |
in:aView |
|
478 |
at:pos |
|
479 |
atEnd:nil. |
|
480 |
! ! |
|
481 |
||
341 | 482 |
!DragAndDropManager methodsFor:'event catching'! |
483 |
||
484 |
buttonMotion:button x:x y:y view:aView |
|
485 |
self perform:motionAction with:x with:y |
|
486 |
||
487 |
"Created: 26.10.1996 / 15:09:00 / cg" |
|
394 | 488 |
|
489 |
||
341 | 490 |
! |
491 |
||
492 |
buttonRelease:button x:x y:y view:aView |
|
493 |
self perform:releaseAction with:x with:y |
|
494 |
||
495 |
"Created: 26.10.1996 / 15:09:14 / cg" |
|
394 | 496 |
|
497 |
! |
|
498 |
||
499 |
drop:something in:targetView at:aPoint from:sourceView ifOk:okAction ifFail:failAction |
|
500 |
"try to drop some object in a targetView; |
|
501 |
if the targetView takes it, okAction is evaluated ; |
|
502 |
if not, failAction is evaluated" |
|
503 |
||
504 |
(targetView canDrop:something) ifFalse:[ |
|
505 |
failAction value. |
|
506 |
^ false |
|
507 |
]. |
|
508 |
targetView drop:something at:aPoint from:sourceView |
|
509 |
with:[:o | okAction. ^ true] |
|
510 |
ifFail:[:o | failAction. ^ false]. |
|
511 |
^ false |
|
512 |
||
513 |
||
514 |
||
515 |
||
516 |
||
341 | 517 |
! |
518 |
||
519 |
handlesButtonMotion:button inView:aView |
|
520 |
"query from event processor: am I interested in button-events ? |
|
521 |
yes I am (to activate the clicked-on field)." |
|
522 |
||
523 |
^ aView == dragView |
|
524 |
||
525 |
"Created: 26.10.1996 / 15:05:36 / cg" |
|
394 | 526 |
|
341 | 527 |
! |
528 |
||
529 |
handlesButtonRelease:button inView:aView |
|
530 |
"query from event processor: am I interested in button-events ? |
|
531 |
yes I am (to activate the clicked-on field)." |
|
532 |
||
533 |
^ aView == dragView |
|
534 |
||
535 |
"Created: 26.10.1996 / 15:05:48 / cg" |
|
394 | 536 |
|
341 | 537 |
! ! |
538 |
||
539 |
!DragAndDropManager methodsFor:'private'! |
|
540 |
||
541 |
catchEventsFrom:aView |
|
394 | 542 |
dragView := aView. |
543 |
saveCursor := dragView cursor. |
|
544 |
||
341 | 545 |
rememberedDelegate := aView delegate. |
394 | 546 |
aView delegate:self. |
341 | 547 |
|
548 |
"Created: 26.10.1996 / 15:03:12 / cg" |
|
549 |
"Modified: 26.10.1996 / 15:21:57 / cg" |
|
394 | 550 |
|
551 |
||
552 |
! |
|
553 |
||
554 |
destinationViewAt:ip |
|
555 |
|rootPoint t viewId offs destinationId lastViewId destinationView |
|
556 |
rootView destinationPoint device| |
|
557 |
||
558 |
device := dragView device. |
|
559 |
rootView := device rootView. |
|
560 |
rootPoint := ip. |
|
561 |
||
562 |
" |
|
563 |
get device coordinates |
|
564 |
" |
|
565 |
(t := dragView transformation) notNil ifTrue:[ |
|
566 |
rootPoint := t applyTo:ip. |
|
567 |
]. |
|
568 |
viewId := rootView id. |
|
569 |
||
570 |
" |
|
571 |
translate to screen |
|
572 |
" |
|
573 |
offs := device translatePoint:0@0 from:(dragView id) to:viewId. |
|
574 |
rootPoint := rootPoint + offs. |
|
575 |
||
576 |
"search view the drop is in" |
|
577 |
||
578 |
[viewId notNil] whileTrue:[ |
|
579 |
destinationId := device viewIdFromPoint:rootPoint in:viewId. |
|
580 |
lastViewId := viewId. |
|
581 |
viewId := destinationId |
|
582 |
]. |
|
583 |
^ device viewFromId:lastViewId |
|
341 | 584 |
! |
585 |
||
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
586 |
endDragAt:ip |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
587 |
|rootPoint t viewId offs destinationId lastViewId destinationView |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
588 |
rootView destinationPoint device| |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
589 |
|
394 | 590 |
dragView cursor:saveCursor now:true. |
591 |
device := dragView device. |
|
592 |
rootView := device rootView. |
|
593 |
rootPoint := ip. |
|
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
594 |
|
394 | 595 |
" |
596 |
get device coordinates |
|
597 |
" |
|
598 |
(t := dragView transformation) notNil ifTrue:[ |
|
599 |
rootPoint := t applyTo:ip. |
|
600 |
]. |
|
601 |
viewId := rootView id. |
|
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
602 |
|
394 | 603 |
" |
604 |
translate to screen |
|
605 |
" |
|
606 |
offs := device translatePoint:0@0 from:(dragView id) to:viewId. |
|
607 |
rootPoint := rootPoint + offs. |
|
608 |
||
609 |
"search view the drop is in" |
|
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
610 |
|
394 | 611 |
[viewId notNil] whileTrue:[ |
612 |
destinationId := device viewIdFromPoint:rootPoint in:viewId. |
|
613 |
lastViewId := viewId. |
|
614 |
viewId := destinationId |
|
615 |
]. |
|
616 |
destinationView := device viewFromId:lastViewId. |
|
617 |
destinationId := lastViewId. |
|
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
618 |
|
394 | 619 |
"into another one" |
620 |
destinationView notNil ifTrue:[ |
|
621 |
destinationPoint := device translatePoint:rootPoint |
|
622 |
from:(rootView id) |
|
623 |
to:(destinationView id). |
|
624 |
destinationView transformation notNil ifTrue:[ |
|
625 |
destinationPoint := destinationView transformation applyInverseTo:destinationPoint |
|
626 |
] |
|
627 |
] ifFalse:[ |
|
628 |
" |
|
629 |
not one of my views |
|
630 |
" |
|
631 |
]. |
|
632 |
||
633 |
dropAction isNil ifTrue:[ |
|
397 | 634 |
"/ XXX add external clipboard mechanism via display |
635 |
(destinationView notNil and:[destinationView canDrop:dropObjects]) ifTrue:[ |
|
401 | 636 |
destinationView drop:dropObjects at:destinationPoint |
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
637 |
]. |
394 | 638 |
^ self |
639 |
]. |
|
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
640 |
|
394 | 641 |
dropAction value:destinationView |
642 |
value:destinationId |
|
643 |
value:rootPoint |
|
644 |
value:destinationPoint |
|
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
645 |
! |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
646 |
|
341 | 647 |
uncatchEvents |
648 |
dragView delegate:rememberedDelegate. |
|
649 |
||
650 |
"Created: 26.10.1996 / 15:22:29 / cg" |
|
394 | 651 |
|
411 | 652 |
" |
653 |
DragAndDropManager allInstancesDo:[:m | |
|
654 |
m uncatchEvents |
|
655 |
] |
|
656 |
" |
|
341 | 657 |
! ! |
658 |
||
397 | 659 |
!DragAndDropManager::DemoView methodsFor:'events'! |
660 |
||
661 |
buttonPress:button x:x y:y |
|
662 |
DragAndDropManager new |
|
663 |
startLineDragIn:self at:(x@y) |
|
664 |
atEnd:[:view |
|
665 |
:viewID |
|
666 |
:rootPoint |
|
667 |
:viewPoint | |
|
668 |
||
669 |
Transcript show:'dropped at '; |
|
670 |
show:viewPoint; |
|
671 |
show:' in '. |
|
672 |
view notNil ifTrue:[ |
|
673 |
Transcript showCR:view |
|
674 |
] ifFalse:[ |
|
675 |
Transcript show:'alien view '; |
|
676 |
showCR:viewID address |
|
677 |
] |
|
678 |
]. |
|
679 |
||
680 |
" |
|
681 |
self new open |
|
682 |
" |
|
683 |
! ! |
|
684 |
||
343 | 685 |
!DragAndDropManager::DemoView2 methodsFor:'events'! |
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
686 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
687 |
buttonPress:button x:x y:y |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
688 |
DragAndDropManager new |
348 | 689 |
startGenericDrag:[:p :v | v displayString:'hello' at:p] |
345 | 690 |
in:self |
691 |
at:(x@y) |
|
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
692 |
atEnd:[:view |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
693 |
:viewID |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
694 |
:rootPoint |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
695 |
:viewPoint | ] |
345 | 696 |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
697 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
698 |
" |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
699 |
self new open |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
700 |
" |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
701 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
702 |
|
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
703 |
! ! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
704 |
|
345 | 705 |
!DragAndDropManager::DemoView3 methodsFor:'events'! |
341 | 706 |
|
707 |
buttonPress:button x:x y:y |
|
708 |
DragAndDropManager new |
|
345 | 709 |
startArrowDragIn:self |
710 |
at:(x@y) |
|
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
711 |
atEnd:[:view |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
712 |
:viewID |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
713 |
:rootPoint |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
714 |
:viewPoint | ] |
341 | 715 |
|
716 |
" |
|
717 |
self new open |
|
718 |
" |
|
719 |
! ! |
|
720 |
||
721 |
!DragAndDropManager class methodsFor:'documentation'! |
|
722 |
||
723 |
version |
|
411 | 724 |
^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.10 1997-02-11 19:09:24 ca Exp $' |
341 | 725 |
! ! |