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