author | Claus Gittinger <cg@exept.de> |
Tue, 29 Aug 2017 23:16:03 +0200 | |
changeset 4000 | d39d58494281 |
parent 3875 | 7bf6b506ae69 |
child 4394 | 136d5851f5ba |
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 |
||
3875 | 110 |
!DragHandler class methodsFor:'queries'! |
111 |
||
112 |
isAbstract |
|
113 |
"Return if this class is an abstract class. |
|
114 |
True is returned here for myself only; false for subclasses. |
|
115 |
Abstract subclasses must redefine this again." |
|
116 |
||
117 |
^ self == DragHandler. |
|
118 |
! ! |
|
119 |
||
2435
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
120 |
!DragHandler methodsFor:'accessing'! |
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
121 |
|
2438 | 122 |
dropContext |
123 |
^ dropContext |
|
2435
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
124 |
! |
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
125 |
|
2438 | 126 |
dropContext:something |
127 |
dropContext := something. |
|
128 |
! |
|
129 |
||
130 |
targetView |
|
131 |
dropContext isNil ifTrue:[^ nil]. |
|
132 |
^ dropContext targetView |
|
2435
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
133 |
! ! |
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
134 |
|
873 | 135 |
!DragHandler methodsFor:'event dropTarget'! |
136 |
||
137 |
dropTargetWillChange |
|
138 |
"called before the drop target or widget changed. |
|
2078 | 139 |
restore root view ... (optional)" |
873 | 140 |
! |
141 |
||
142 |
isInterestedInDropTarget |
|
143 |
"returns true, if the handler is interested in the underlying |
|
144 |
drop target and the target should be tested to be able to drop |
|
2078 | 145 |
the objects." |
146 |
||
873 | 147 |
^ true |
148 |
! ! |
|
149 |
||
150 |
!DragHandler methodsFor:'protocol'! |
|
151 |
||
152 |
dragTo:aRootPoint |
|
2078 | 153 |
"drag to a root point" |
154 |
||
873 | 155 |
self subclassResponsibility |
156 |
! |
|
157 |
||
2043 | 158 |
flushSaveArea |
159 |
! |
|
160 |
||
873 | 161 |
postDragging |
2078 | 162 |
"after dragging; restore root view ..." |
163 |
||
873 | 164 |
self subclassResponsibility |
165 |
! |
|
166 |
||
167 |
preDraggingIn:aSourceWidget |
|
2078 | 168 |
"called before starting the drag & drop operation" |
169 |
||
873 | 170 |
rootView := aSourceWidget device rootView. |
2043 | 171 |
! |
172 |
||
173 |
rereadSaveArea |
|
873 | 174 |
! ! |
175 |
||
176 |
!DragHandler::Generic class methodsFor:'documentation'! |
|
177 |
||
178 |
documentation |
|
179 |
" |
|
180 |
this class handles a generic drag on the screen. It is not visible to |
|
181 |
the user and is created automatically by the DragAndDropManger. |
|
182 |
||
183 |
[author:] |
|
184 |
Claus Gittinger |
|
185 |
||
186 |
[see also:] |
|
187 |
DragAndDropManager |
|
188 |
" |
|
189 |
||
190 |
||
191 |
! ! |
|
192 |
||
193 |
!DragHandler::Generic methodsFor:'instance creation'! |
|
194 |
||
195 |
dragBlock:aTwoArgBlock |
|
196 |
"the dragBlock will be called with two arguments, aPoint and the drawing GC, |
|
2078 | 197 |
to perform the drawing at some dragPoint." |
198 |
||
873 | 199 |
dragBlock := aTwoArgBlock |
200 |
! ! |
|
201 |
||
202 |
!DragHandler::Generic methodsFor:'protocol'! |
|
203 |
||
204 |
dragTo:aRootPoint |
|
2078 | 205 |
"drag to a root point" |
206 |
||
873 | 207 |
prevPoint notNil ifTrue:[ |
208 |
self postDragging |
|
209 |
]. |
|
210 |
lastPoint := nil. |
|
1487 | 211 |
prevPoint := lastRootPoint := aRootPoint. |
873 | 212 |
self postDragging |
213 |
! |
|
214 |
||
215 |
postDragging |
|
216 |
lastPoint isNil ifTrue:[ |
|
217 |
lastPoint := prevPoint. |
|
218 |
]. |
|
219 |
rootView clippedByChildren:false. |
|
220 |
||
221 |
rootView xoring:[ |
|
222 |
rootView lineWidth:0. |
|
223 |
dragBlock value:lastPoint value:rootView. |
|
224 |
rootView flush |
|
225 |
] |
|
226 |
! ! |
|
227 |
||
228 |
!DragHandler::Line class methodsFor:'documentation'! |
|
229 |
||
230 |
documentation |
|
231 |
" |
|
232 |
this class handles a line or arrow drag on the screen. It is not visible to |
|
233 |
the user and is created automatically by the DragAndDropManger. |
|
234 |
||
235 |
[author:] |
|
236 |
Claus Gittinger |
|
237 |
||
238 |
[see also:] |
|
239 |
DragAndDropManager |
|
240 |
" |
|
241 |
||
242 |
||
243 |
! ! |
|
244 |
||
245 |
!DragHandler::Line methodsFor:'event dropTarget'! |
|
246 |
||
247 |
isInterestedInDropTarget |
|
248 |
^ false |
|
249 |
||
250 |
||
251 |
! ! |
|
252 |
||
253 |
!DragHandler::Line methodsFor:'instance creation'! |
|
254 |
||
255 |
startPoint:aPoint mode:aMode |
|
256 |
||
257 |
lineMode := aMode. |
|
258 |
startPoint := aPoint. |
|
259 |
||
260 |
||
261 |
! ! |
|
262 |
||
263 |
!DragHandler::Line methodsFor:'protocol'! |
|
264 |
||
265 |
dragTo:aRootPoint |
|
2078 | 266 |
"do a line or arrow drag" |
267 |
||
873 | 268 |
self postDragging. |
1487 | 269 |
endPoint := lastRootPoint := aRootPoint. |
873 | 270 |
self postDragging. |
271 |
! |
|
272 |
||
273 |
postDragging |
|
2078 | 274 |
"invert for a line or arrow drag" |
275 |
||
873 | 276 |
|arrow| |
277 |
||
278 |
endPoint isNil ifTrue:[ |
|
279 |
^ self |
|
280 |
]. |
|
281 |
rootView clippedByChildren:false. |
|
282 |
||
283 |
rootView xoring:[ |
|
284 |
rootView lineWidth:0. |
|
285 |
||
286 |
lineMode == #arrow ifTrue:[ |
|
287 |
arrow := Arrow from:startPoint to:endPoint. |
|
288 |
arrow arrowHeadLength:(rootView device horizontalPixelPerMillimeter * 4) rounded. |
|
289 |
arrow displayFilledOn:rootView. |
|
290 |
] ifFalse:[ |
|
291 |
rootView displayLineFrom:startPoint to:endPoint. |
|
292 |
]. |
|
293 |
rootView flush |
|
294 |
] |
|
295 |
! ! |
|
296 |
||
297 |
!DragHandler::Opaque class methodsFor:'constants'! |
|
298 |
||
299 |
additionalSaveSize |
|
300 |
^ 50 @ 50 |
|
301 |
||
302 |
||
303 |
! ! |
|
304 |
||
305 |
!DragHandler::Opaque class methodsFor:'documentation'! |
|
306 |
||
307 |
documentation |
|
308 |
" |
|
309 |
this class handles an generic opaque drag on the screen. It is not visible |
|
310 |
to the user and is created automatically by the DragAndDropManger. |
|
311 |
||
312 |
[author:] |
|
313 |
Claus Gittinger |
|
314 |
||
315 |
[see also:] |
|
316 |
DragAndDropManager |
|
317 |
" |
|
318 |
||
319 |
||
320 |
! ! |
|
321 |
||
322 |
!DragHandler::Opaque methodsFor:'instance creation'! |
|
323 |
||
324 |
dragSize:anExtent dragOffset:anOffset dragBlock:aTwoArgBlock |
|
325 |
"the dragBlock will be called with two arguments, aPoint and the drawing GC, |
|
326 |
to perform the drawing at some dragPoint. |
|
327 |
" |
|
328 |
dragSize := anExtent. |
|
329 |
dragOffset := anOffset. |
|
330 |
dragBlock := aTwoArgBlock |
|
331 |
! ! |
|
332 |
||
333 |
!DragHandler::Opaque methodsFor:'protocol'! |
|
334 |
||
335 |
dragTo:aRootPoint |
|
2078 | 336 |
"drag to a root point" |
337 |
||
3529 | 338 |
|p point area| |
1487 | 339 |
|
1687
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
340 |
(saveArea notNil and:[lastRootPoint notNil]) ifTrue:[ |
2626
762fe84ed4fa
change back the cursor, when escaping;
Claus Gittinger <cg@exept.de>
parents:
2438
diff
changeset
|
341 |
(lastRootPoint = aRootPoint) ifTrue:[ |
1687
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
342 |
"/ nothing changed |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
343 |
^ self |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
344 |
]. |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
345 |
]. |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
346 |
|
1487 | 347 |
lastRootPoint := aRootPoint. |
873 | 348 |
"/ |
349 |
"/ copy from screen to saveUnder |
|
350 |
"/ |
|
351 |
rootView clippedByChildren:false. |
|
352 |
point := aRootPoint - dragOffset. |
|
353 |
||
354 |
saveArea notNil ifTrue:[ |
|
355 |
( (saveArea left <= point x) |
|
356 |
and:[(saveArea top <= point y) |
|
357 |
and:[(saveArea right >= (point x + dragSize x)) |
|
358 |
and:[(saveArea bottom >= (point y + dragSize y))]]] |
|
359 |
) ifFalse:[ |
|
360 |
"/ |
|
361 |
"/ draggable objects no longer contained in saved area; |
|
362 |
"/ thus we have to restore the saved area on the screen. |
|
363 |
"/ |
|
3529 | 364 |
self postDragging. |
873 | 365 |
] |
366 |
]. |
|
367 |
||
368 |
saveArea isNil ifTrue:[ |
|
369 |
"/ |
|
370 |
"/ screen not yet saved; thus we have to save the area |
|
371 |
"/ |
|
372 |
p := point - (self class additionalSaveSize). |
|
373 |
saveUnder copyFrom:rootView |
|
374 |
x:p x |
|
375 |
y:p y |
|
376 |
toX:0 |
|
377 |
y:0 |
|
3529 | 378 |
width:saveUnder width |
379 |
height:saveUnder height. |
|
380 |
saveArea := p extent:saveUnder extent. |
|
873 | 381 |
]. |
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
382 |
area := saveArea. |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
383 |
|
873 | 384 |
"/ |
385 |
"/ draw into the form using the dragAction block |
|
386 |
"/ |
|
387 |
tmpForm copyFrom:saveUnder toX:0 y:0. |
|
388 |
tmpForm paint:Color black. |
|
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
389 |
|
873 | 390 |
dragBlock value:(point - saveArea origin + dragOffset) value:tmpForm. |
391 |
||
3529 | 392 |
"if saveArea changed during dragBlock; lock operation" |
393 |
area == saveArea ifTrue:[ |
|
394 |
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
|
395 |
]. |
873 | 396 |
! |
397 |
||
398 |
dropTargetWillChange |
|
2078 | 399 |
"restore old saveArea" |
400 |
||
873 | 401 |
self postDragging |
402 |
! |
|
403 |
||
2043 | 404 |
flushSaveArea |
405 |
saveArea := nil |
|
406 |
! |
|
407 |
||
873 | 408 |
postDragging |
2078 | 409 |
"restore from saveUnder for a generic opaque drag" |
3529 | 410 |
|
411 |
|area| |
|
2078 | 412 |
|
3160
7aa62ff13f85
fix for redraw problem in tree (d&d) - from ca
Michael Beyl <mb@exept.de>
parents:
2626
diff
changeset
|
413 |
saveArea isNil ifTrue:[ ^ self ]. |
3529 | 414 |
area := saveArea. |
3160
7aa62ff13f85
fix for redraw problem in tree (d&d) - from ca
Michael Beyl <mb@exept.de>
parents:
2626
diff
changeset
|
415 |
saveArea := nil. |
873 | 416 |
|
3160
7aa62ff13f85
fix for redraw problem in tree (d&d) - from ca
Michael Beyl <mb@exept.de>
parents:
2626
diff
changeset
|
417 |
rootView clippedByChildren:false. |
3529 | 418 |
"/ 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
|
419 |
rootView copyFrom:saveUnder |
3529 | 420 |
x:0 |
421 |
y:0 |
|
422 |
toX:area left |
|
423 |
y:area top |
|
424 |
width:saveUnder width |
|
425 |
height:saveUnder height |
|
426 |
async:false. |
|
3533 | 427 |
|
428 |
"Call #D1894600 - redraw artefakte bei drag im tree |
|
429 |
work around copy again back |
|
430 |
- doesn't help for linux |
|
3534 | 431 |
- but helps for windows (native, not needed for windows running in VM)" |
3533 | 432 |
saveUnder copyFrom:rootView |
433 |
x: area left |
|
434 |
y: area top |
|
435 |
width: 1 |
|
436 |
height: 1. |
|
873 | 437 |
! |
438 |
||
439 |
preDraggingIn:aSourceWidget |
|
2078 | 440 |
"setup my default values" |
441 |
||
3624 | 442 |
|depth extent widgetsDevice| |
873 | 443 |
|
444 |
super preDraggingIn:aSourceWidget. |
|
445 |
||
3624 | 446 |
widgetsDevice := aSourceWidget device. |
873 | 447 |
depth := rootView device depth. |
448 |
extent := dragSize + (2 * (self class additionalSaveSize)). |
|
3624 | 449 |
saveUnder := Form extent:extent depth:depth onDevice:widgetsDevice. |
450 |
tmpForm := Form extent:extent depth:depth onDevice:widgetsDevice. |
|
873 | 451 |
|
452 |
saveUnder clippedByChildren:false. |
|
453 |
tmpForm initGC. |
|
454 |
tmpForm font:(aSourceWidget font). |
|
2331 | 455 |
|
456 |
"Modified: / 27-05-2007 / 12:48:28 / cg" |
|
1487 | 457 |
! |
458 |
||
459 |
rereadSaveArea |
|
460 |
saveArea notNil ifTrue:[ |
|
461 |
rootView clippedByChildren:false. |
|
462 |
saveUnder copyFrom:rootView |
|
3529 | 463 |
x:saveArea left |
464 |
y:saveArea top |
|
465 |
toX:0 |
|
466 |
y:0 |
|
467 |
width:saveArea width |
|
468 |
height:saveArea height. |
|
469 |
]. |
|
1487 | 470 |
! |
471 |
||
472 |
restoreFromSaveArea |
|
1639 | 473 |
lastRootPoint notNil ifTrue:[ |
474 |
self dragTo:lastRootPoint |
|
475 |
]. |
|
873 | 476 |
! ! |
477 |
||
478 |
!DragHandler class methodsFor:'documentation'! |
|
479 |
||
480 |
version |
|
3529 | 481 |
^ '$Header$' |
3534 | 482 |
! |
483 |
||
484 |
version_CVS |
|
485 |
^ '$Header$' |
|
873 | 486 |
! ! |
3160
7aa62ff13f85
fix for redraw problem in tree (d&d) - from ca
Michael Beyl <mb@exept.de>
parents:
2626
diff
changeset
|
487 |