author | Claus Gittinger <cg@exept.de> |
Mon, 23 Jan 2017 11:00:34 +0100 | |
changeset 3835 | 98c65815a6d3 |
parent 3624 | e9121eb50ff4 |
child 3875 | 7bf6b506ae69 |
permissions | -rw-r--r-- |
873 | 1 |
" |
2 |
COPYRIGHT (c) 1998 by eXept Software AG / Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
1487 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
3529 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
873 | 16 |
Object subclass:#DragHandler |
2435
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
17 |
instanceVariableNames:'rootView lastRootPoint dropContext' |
873 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
20 |
category:'Interface-DragAndDrop' |
|
21 |
! |
|
22 |
||
23 |
DragHandler subclass:#Generic |
|
24 |
instanceVariableNames:'prevPoint lastPoint dragBlock' |
|
25 |
classVariableNames:'' |
|
26 |
poolDictionaries:'' |
|
27 |
privateIn:DragHandler |
|
28 |
! |
|
29 |
||
30 |
DragHandler subclass:#Line |
|
31 |
instanceVariableNames:'startPoint endPoint lineMode' |
|
32 |
classVariableNames:'' |
|
33 |
poolDictionaries:'' |
|
34 |
privateIn:DragHandler |
|
35 |
! |
|
36 |
||
37 |
DragHandler subclass:#Opaque |
|
38 |
instanceVariableNames:'dragSize dragBlock dragOffset saveUnder saveArea tmpForm' |
|
39 |
classVariableNames:'' |
|
40 |
poolDictionaries:'' |
|
41 |
privateIn:DragHandler |
|
42 |
! |
|
43 |
||
44 |
!DragHandler class methodsFor:'documentation'! |
|
45 |
||
46 |
copyright |
|
47 |
" |
|
48 |
COPYRIGHT (c) 1998 by eXept Software AG / Claus Gittinger |
|
49 |
All Rights Reserved |
|
50 |
||
51 |
This software is furnished under a license and may be used |
|
52 |
only in accordance with the terms of that license and with the |
|
53 |
inclusion of the above copyright notice. This software may not |
|
54 |
be provided or otherwise made available to, or used by, any |
|
55 |
other person. No title to or ownership of the software is |
|
56 |
hereby transferred. |
|
57 |
" |
|
58 |
||
59 |
||
60 |
||
61 |
! |
|
62 |
||
63 |
documentation |
|
64 |
" |
|
65 |
this abstract class describes the protocol common to any DragHandler. |
|
66 |
The DragAndDropManger creates one instance responsible to show the |
|
67 |
dragging objects on the screen. |
|
68 |
||
69 |
[author:] |
|
70 |
Claus Gittinger |
|
71 |
||
72 |
[see also:] |
|
73 |
DragAndDropManager |
|
74 |
" |
|
75 |
||
76 |
||
77 |
||
78 |
! ! |
|
79 |
||
80 |
!DragHandler class methodsFor:'instance creation'! |
|
81 |
||
82 |
startArrowDragAt:aStartPoint |
|
83 |
"creates and returns the drag handler which is responsible |
|
2078 | 84 |
for an arrow drag." |
85 |
||
873 | 86 |
^ Line new startPoint:aStartPoint mode:#arrow |
87 |
! |
|
88 |
||
89 |
startGenericDrag:aTwoArgDragBlock |
|
90 |
"creates and returns the drag handler which is responsible |
|
2078 | 91 |
for a generic drag." |
92 |
||
873 | 93 |
^ Generic new dragBlock:aTwoArgDragBlock |
94 |
! |
|
95 |
||
96 |
startLineDragAt:aStartPoint |
|
97 |
"creates and returns the drag handler which is responsible |
|
2078 | 98 |
for a line drag." |
99 |
||
873 | 100 |
^ Line new startPoint:aStartPoint mode:nil |
101 |
! |
|
102 |
||
103 |
startOpaqueDrag:aTwoArgDragBlock extent:anExtent offset:anOffset |
|
104 |
"creates and returns the drag handler which is responsible |
|
2078 | 105 |
for a generic opaque drag." |
106 |
||
873 | 107 |
^ Opaque new dragSize:anExtent dragOffset:anOffset dragBlock:aTwoArgDragBlock |
108 |
! ! |
|
109 |
||
2435
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
110 |
!DragHandler methodsFor:'accessing'! |
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
111 |
|
2438 | 112 |
dropContext |
113 |
^ dropContext |
|
2435
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
114 |
! |
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
115 |
|
2438 | 116 |
dropContext:something |
117 |
dropContext := something. |
|
118 |
! |
|
119 |
||
120 |
targetView |
|
121 |
dropContext isNil ifTrue:[^ nil]. |
|
122 |
^ dropContext targetView |
|
2435
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
123 |
! ! |
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
124 |
|
873 | 125 |
!DragHandler methodsFor:'event dropTarget'! |
126 |
||
127 |
dropTargetWillChange |
|
128 |
"called before the drop target or widget changed. |
|
2078 | 129 |
restore root view ... (optional)" |
873 | 130 |
! |
131 |
||
132 |
isInterestedInDropTarget |
|
133 |
"returns true, if the handler is interested in the underlying |
|
134 |
drop target and the target should be tested to be able to drop |
|
2078 | 135 |
the objects." |
136 |
||
873 | 137 |
^ true |
138 |
! ! |
|
139 |
||
140 |
!DragHandler methodsFor:'protocol'! |
|
141 |
||
142 |
dragTo:aRootPoint |
|
2078 | 143 |
"drag to a root point" |
144 |
||
873 | 145 |
self subclassResponsibility |
146 |
! |
|
147 |
||
2043 | 148 |
flushSaveArea |
149 |
! |
|
150 |
||
873 | 151 |
postDragging |
2078 | 152 |
"after dragging; restore root view ..." |
153 |
||
873 | 154 |
self subclassResponsibility |
155 |
! |
|
156 |
||
157 |
preDraggingIn:aSourceWidget |
|
2078 | 158 |
"called before starting the drag & drop operation" |
159 |
||
873 | 160 |
rootView := aSourceWidget device rootView. |
2043 | 161 |
! |
162 |
||
163 |
rereadSaveArea |
|
873 | 164 |
! ! |
165 |
||
166 |
!DragHandler::Generic class methodsFor:'documentation'! |
|
167 |
||
168 |
documentation |
|
169 |
" |
|
170 |
this class handles a generic drag on the screen. It is not visible to |
|
171 |
the user and is created automatically by the DragAndDropManger. |
|
172 |
||
173 |
[author:] |
|
174 |
Claus Gittinger |
|
175 |
||
176 |
[see also:] |
|
177 |
DragAndDropManager |
|
178 |
" |
|
179 |
||
180 |
||
181 |
! ! |
|
182 |
||
183 |
!DragHandler::Generic methodsFor:'instance creation'! |
|
184 |
||
185 |
dragBlock:aTwoArgBlock |
|
186 |
"the dragBlock will be called with two arguments, aPoint and the drawing GC, |
|
2078 | 187 |
to perform the drawing at some dragPoint." |
188 |
||
873 | 189 |
dragBlock := aTwoArgBlock |
190 |
! ! |
|
191 |
||
192 |
!DragHandler::Generic methodsFor:'protocol'! |
|
193 |
||
194 |
dragTo:aRootPoint |
|
2078 | 195 |
"drag to a root point" |
196 |
||
873 | 197 |
prevPoint notNil ifTrue:[ |
198 |
self postDragging |
|
199 |
]. |
|
200 |
lastPoint := nil. |
|
1487 | 201 |
prevPoint := lastRootPoint := aRootPoint. |
873 | 202 |
self postDragging |
203 |
! |
|
204 |
||
205 |
postDragging |
|
206 |
lastPoint isNil ifTrue:[ |
|
207 |
lastPoint := prevPoint. |
|
208 |
]. |
|
209 |
rootView clippedByChildren:false. |
|
210 |
||
211 |
rootView xoring:[ |
|
212 |
rootView lineWidth:0. |
|
213 |
dragBlock value:lastPoint value:rootView. |
|
214 |
rootView flush |
|
215 |
] |
|
216 |
! ! |
|
217 |
||
218 |
!DragHandler::Line class methodsFor:'documentation'! |
|
219 |
||
220 |
documentation |
|
221 |
" |
|
222 |
this class handles a line or arrow drag on the screen. It is not visible to |
|
223 |
the user and is created automatically by the DragAndDropManger. |
|
224 |
||
225 |
[author:] |
|
226 |
Claus Gittinger |
|
227 |
||
228 |
[see also:] |
|
229 |
DragAndDropManager |
|
230 |
" |
|
231 |
||
232 |
||
233 |
! ! |
|
234 |
||
235 |
!DragHandler::Line methodsFor:'event dropTarget'! |
|
236 |
||
237 |
isInterestedInDropTarget |
|
238 |
^ false |
|
239 |
||
240 |
||
241 |
! ! |
|
242 |
||
243 |
!DragHandler::Line methodsFor:'instance creation'! |
|
244 |
||
245 |
startPoint:aPoint mode:aMode |
|
246 |
||
247 |
lineMode := aMode. |
|
248 |
startPoint := aPoint. |
|
249 |
||
250 |
||
251 |
! ! |
|
252 |
||
253 |
!DragHandler::Line methodsFor:'protocol'! |
|
254 |
||
255 |
dragTo:aRootPoint |
|
2078 | 256 |
"do a line or arrow drag" |
257 |
||
873 | 258 |
self postDragging. |
1487 | 259 |
endPoint := lastRootPoint := aRootPoint. |
873 | 260 |
self postDragging. |
261 |
! |
|
262 |
||
263 |
postDragging |
|
2078 | 264 |
"invert for a line or arrow drag" |
265 |
||
873 | 266 |
|arrow| |
267 |
||
268 |
endPoint isNil ifTrue:[ |
|
269 |
^ self |
|
270 |
]. |
|
271 |
rootView clippedByChildren:false. |
|
272 |
||
273 |
rootView xoring:[ |
|
274 |
rootView lineWidth:0. |
|
275 |
||
276 |
lineMode == #arrow ifTrue:[ |
|
277 |
arrow := Arrow from:startPoint to:endPoint. |
|
278 |
arrow arrowHeadLength:(rootView device horizontalPixelPerMillimeter * 4) rounded. |
|
279 |
arrow displayFilledOn:rootView. |
|
280 |
] ifFalse:[ |
|
281 |
rootView displayLineFrom:startPoint to:endPoint. |
|
282 |
]. |
|
283 |
rootView flush |
|
284 |
] |
|
285 |
! ! |
|
286 |
||
287 |
!DragHandler::Opaque class methodsFor:'constants'! |
|
288 |
||
289 |
additionalSaveSize |
|
290 |
^ 50 @ 50 |
|
291 |
||
292 |
||
293 |
! ! |
|
294 |
||
295 |
!DragHandler::Opaque class methodsFor:'documentation'! |
|
296 |
||
297 |
documentation |
|
298 |
" |
|
299 |
this class handles an generic opaque drag on the screen. It is not visible |
|
300 |
to the user and is created automatically by the DragAndDropManger. |
|
301 |
||
302 |
[author:] |
|
303 |
Claus Gittinger |
|
304 |
||
305 |
[see also:] |
|
306 |
DragAndDropManager |
|
307 |
" |
|
308 |
||
309 |
||
310 |
! ! |
|
311 |
||
312 |
!DragHandler::Opaque methodsFor:'instance creation'! |
|
313 |
||
314 |
dragSize:anExtent dragOffset:anOffset dragBlock:aTwoArgBlock |
|
315 |
"the dragBlock will be called with two arguments, aPoint and the drawing GC, |
|
316 |
to perform the drawing at some dragPoint. |
|
317 |
" |
|
318 |
dragSize := anExtent. |
|
319 |
dragOffset := anOffset. |
|
320 |
dragBlock := aTwoArgBlock |
|
321 |
! ! |
|
322 |
||
323 |
!DragHandler::Opaque methodsFor:'protocol'! |
|
324 |
||
325 |
dragTo:aRootPoint |
|
2078 | 326 |
"drag to a root point" |
327 |
||
3529 | 328 |
|p point area| |
1487 | 329 |
|
1687
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
330 |
(saveArea notNil and:[lastRootPoint notNil]) ifTrue:[ |
2626
762fe84ed4fa
change back the cursor, when escaping;
Claus Gittinger <cg@exept.de>
parents:
2438
diff
changeset
|
331 |
(lastRootPoint = aRootPoint) ifTrue:[ |
1687
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
332 |
"/ nothing changed |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
333 |
^ self |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
334 |
]. |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
335 |
]. |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
336 |
|
1487 | 337 |
lastRootPoint := aRootPoint. |
873 | 338 |
"/ |
339 |
"/ copy from screen to saveUnder |
|
340 |
"/ |
|
341 |
rootView clippedByChildren:false. |
|
342 |
point := aRootPoint - dragOffset. |
|
343 |
||
344 |
saveArea notNil ifTrue:[ |
|
345 |
( (saveArea left <= point x) |
|
346 |
and:[(saveArea top <= point y) |
|
347 |
and:[(saveArea right >= (point x + dragSize x)) |
|
348 |
and:[(saveArea bottom >= (point y + dragSize y))]]] |
|
349 |
) ifFalse:[ |
|
350 |
"/ |
|
351 |
"/ draggable objects no longer contained in saved area; |
|
352 |
"/ thus we have to restore the saved area on the screen. |
|
353 |
"/ |
|
3529 | 354 |
self postDragging. |
873 | 355 |
] |
356 |
]. |
|
357 |
||
358 |
saveArea isNil ifTrue:[ |
|
359 |
"/ |
|
360 |
"/ screen not yet saved; thus we have to save the area |
|
361 |
"/ |
|
362 |
p := point - (self class additionalSaveSize). |
|
363 |
saveUnder copyFrom:rootView |
|
364 |
x:p x |
|
365 |
y:p y |
|
366 |
toX:0 |
|
367 |
y:0 |
|
3529 | 368 |
width:saveUnder width |
369 |
height:saveUnder height. |
|
370 |
saveArea := p extent:saveUnder extent. |
|
873 | 371 |
]. |
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
372 |
area := saveArea. |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
373 |
|
873 | 374 |
"/ |
375 |
"/ draw into the form using the dragAction block |
|
376 |
"/ |
|
377 |
tmpForm copyFrom:saveUnder toX:0 y:0. |
|
378 |
tmpForm paint:Color black. |
|
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
379 |
|
873 | 380 |
dragBlock value:(point - saveArea origin + dragOffset) value:tmpForm. |
381 |
||
3529 | 382 |
"if saveArea changed during dragBlock; lock operation" |
383 |
area == saveArea ifTrue:[ |
|
384 |
rootView copyFrom:tmpForm toX:area left y:area top. |
|
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
385 |
]. |
873 | 386 |
! |
387 |
||
388 |
dropTargetWillChange |
|
2078 | 389 |
"restore old saveArea" |
390 |
||
873 | 391 |
self postDragging |
392 |
! |
|
393 |
||
2043 | 394 |
flushSaveArea |
395 |
saveArea := nil |
|
396 |
! |
|
397 |
||
873 | 398 |
postDragging |
2078 | 399 |
"restore from saveUnder for a generic opaque drag" |
3529 | 400 |
|
401 |
|area| |
|
2078 | 402 |
|
3160
7aa62ff13f85
fix for redraw problem in tree (d&d) - from ca
Michael Beyl <mb@exept.de>
parents:
2626
diff
changeset
|
403 |
saveArea isNil ifTrue:[ ^ self ]. |
3529 | 404 |
area := saveArea. |
3160
7aa62ff13f85
fix for redraw problem in tree (d&d) - from ca
Michael Beyl <mb@exept.de>
parents:
2626
diff
changeset
|
405 |
saveArea := nil. |
873 | 406 |
|
3160
7aa62ff13f85
fix for redraw problem in tree (d&d) - from ca
Michael Beyl <mb@exept.de>
parents:
2626
diff
changeset
|
407 |
rootView clippedByChildren:false. |
3529 | 408 |
"/ restore screen from saveUnder |
3160
7aa62ff13f85
fix for redraw problem in tree (d&d) - from ca
Michael Beyl <mb@exept.de>
parents:
2626
diff
changeset
|
409 |
rootView copyFrom:saveUnder |
3529 | 410 |
x:0 |
411 |
y:0 |
|
412 |
toX:area left |
|
413 |
y:area top |
|
414 |
width:saveUnder width |
|
415 |
height:saveUnder height |
|
416 |
async:false. |
|
3533 | 417 |
|
418 |
"Call #D1894600 - redraw artefakte bei drag im tree |
|
419 |
work around copy again back |
|
420 |
- doesn't help for linux |
|
3534 | 421 |
- but helps for windows (native, not needed for windows running in VM)" |
3533 | 422 |
saveUnder copyFrom:rootView |
423 |
x: area left |
|
424 |
y: area top |
|
425 |
width: 1 |
|
426 |
height: 1. |
|
873 | 427 |
! |
428 |
||
429 |
preDraggingIn:aSourceWidget |
|
2078 | 430 |
"setup my default values" |
431 |
||
3624 | 432 |
|depth extent widgetsDevice| |
873 | 433 |
|
434 |
super preDraggingIn:aSourceWidget. |
|
435 |
||
3624 | 436 |
widgetsDevice := aSourceWidget device. |
873 | 437 |
depth := rootView device depth. |
438 |
extent := dragSize + (2 * (self class additionalSaveSize)). |
|
3624 | 439 |
saveUnder := Form extent:extent depth:depth onDevice:widgetsDevice. |
440 |
tmpForm := Form extent:extent depth:depth onDevice:widgetsDevice. |
|
873 | 441 |
|
442 |
saveUnder clippedByChildren:false. |
|
443 |
tmpForm initGC. |
|
444 |
tmpForm font:(aSourceWidget font). |
|
2331 | 445 |
|
446 |
"Modified: / 27-05-2007 / 12:48:28 / cg" |
|
1487 | 447 |
! |
448 |
||
449 |
rereadSaveArea |
|
450 |
saveArea notNil ifTrue:[ |
|
451 |
rootView clippedByChildren:false. |
|
452 |
saveUnder copyFrom:rootView |
|
3529 | 453 |
x:saveArea left |
454 |
y:saveArea top |
|
455 |
toX:0 |
|
456 |
y:0 |
|
457 |
width:saveArea width |
|
458 |
height:saveArea height. |
|
459 |
]. |
|
1487 | 460 |
! |
461 |
||
462 |
restoreFromSaveArea |
|
1639 | 463 |
lastRootPoint notNil ifTrue:[ |
464 |
self dragTo:lastRootPoint |
|
465 |
]. |
|
873 | 466 |
! ! |
467 |
||
468 |
!DragHandler class methodsFor:'documentation'! |
|
469 |
||
470 |
version |
|
3529 | 471 |
^ '$Header$' |
3534 | 472 |
! |
473 |
||
474 |
version_CVS |
|
475 |
^ '$Header$' |
|
873 | 476 |
! ! |
3160
7aa62ff13f85
fix for redraw problem in tree (d&d) - from ca
Michael Beyl <mb@exept.de>
parents:
2626
diff
changeset
|
477 |