author | Claus Gittinger <cg@exept.de> |
Tue, 10 Jan 2006 10:47:40 +0100 | |
changeset 2078 | 152102d2d8a0 |
parent 2045 | d284fd4ef3d7 |
child 2331 | a49dabbc2695 |
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 |
" |
|
12 |
||
13 |
||
14 |
||
15 |
||
1487 | 16 |
"{ Package: 'stx:libview2' }" |
17 |
||
873 | 18 |
Object subclass:#DragHandler |
1487 | 19 |
instanceVariableNames:'rootView lastRootPoint' |
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 |
||
112 |
!DragHandler methodsFor:'event dropTarget'! |
|
113 |
||
114 |
dropTargetWillChange |
|
115 |
"called before the drop target or widget changed. |
|
2078 | 116 |
restore root view ... (optional)" |
873 | 117 |
! |
118 |
||
119 |
isInterestedInDropTarget |
|
120 |
"returns true, if the handler is interested in the underlying |
|
121 |
drop target and the target should be tested to be able to drop |
|
2078 | 122 |
the objects." |
123 |
||
873 | 124 |
^ true |
125 |
! ! |
|
126 |
||
127 |
!DragHandler methodsFor:'protocol'! |
|
128 |
||
129 |
dragTo:aRootPoint |
|
2078 | 130 |
"drag to a root point" |
131 |
||
873 | 132 |
self subclassResponsibility |
133 |
! |
|
134 |
||
2043 | 135 |
flushSaveArea |
136 |
! |
|
137 |
||
873 | 138 |
postDragging |
2078 | 139 |
"after dragging; restore root view ..." |
140 |
||
873 | 141 |
self subclassResponsibility |
142 |
! |
|
143 |
||
144 |
preDraggingIn:aSourceWidget |
|
2078 | 145 |
"called before starting the drag & drop operation" |
146 |
||
873 | 147 |
rootView := aSourceWidget device rootView. |
2043 | 148 |
! |
149 |
||
150 |
rereadSaveArea |
|
873 | 151 |
! ! |
152 |
||
153 |
!DragHandler::Generic class methodsFor:'documentation'! |
|
154 |
||
155 |
documentation |
|
156 |
" |
|
157 |
this class handles a generic drag on the screen. It is not visible to |
|
158 |
the user and is created automatically by the DragAndDropManger. |
|
159 |
||
160 |
[author:] |
|
161 |
Claus Gittinger |
|
162 |
||
163 |
[see also:] |
|
164 |
DragAndDropManager |
|
165 |
" |
|
166 |
||
167 |
||
168 |
! ! |
|
169 |
||
170 |
!DragHandler::Generic methodsFor:'instance creation'! |
|
171 |
||
172 |
dragBlock:aTwoArgBlock |
|
173 |
"the dragBlock will be called with two arguments, aPoint and the drawing GC, |
|
2078 | 174 |
to perform the drawing at some dragPoint." |
175 |
||
873 | 176 |
dragBlock := aTwoArgBlock |
177 |
! ! |
|
178 |
||
179 |
!DragHandler::Generic methodsFor:'protocol'! |
|
180 |
||
181 |
dragTo:aRootPoint |
|
2078 | 182 |
"drag to a root point" |
183 |
||
873 | 184 |
prevPoint notNil ifTrue:[ |
185 |
self postDragging |
|
186 |
]. |
|
187 |
lastPoint := nil. |
|
1487 | 188 |
prevPoint := lastRootPoint := aRootPoint. |
873 | 189 |
self postDragging |
190 |
! |
|
191 |
||
192 |
postDragging |
|
193 |
lastPoint isNil ifTrue:[ |
|
194 |
lastPoint := prevPoint. |
|
195 |
]. |
|
196 |
rootView clippedByChildren:false. |
|
197 |
||
198 |
rootView xoring:[ |
|
199 |
rootView lineWidth:0. |
|
200 |
dragBlock value:lastPoint value:rootView. |
|
201 |
rootView flush |
|
202 |
] |
|
203 |
! ! |
|
204 |
||
205 |
!DragHandler::Line class methodsFor:'documentation'! |
|
206 |
||
207 |
documentation |
|
208 |
" |
|
209 |
this class handles a line or arrow drag on the screen. It is not visible to |
|
210 |
the user and is created automatically by the DragAndDropManger. |
|
211 |
||
212 |
[author:] |
|
213 |
Claus Gittinger |
|
214 |
||
215 |
[see also:] |
|
216 |
DragAndDropManager |
|
217 |
" |
|
218 |
||
219 |
||
220 |
! ! |
|
221 |
||
222 |
!DragHandler::Line methodsFor:'event dropTarget'! |
|
223 |
||
224 |
isInterestedInDropTarget |
|
225 |
^ false |
|
226 |
||
227 |
||
228 |
! ! |
|
229 |
||
230 |
!DragHandler::Line methodsFor:'instance creation'! |
|
231 |
||
232 |
startPoint:aPoint mode:aMode |
|
233 |
||
234 |
lineMode := aMode. |
|
235 |
startPoint := aPoint. |
|
236 |
||
237 |
||
238 |
! ! |
|
239 |
||
240 |
!DragHandler::Line methodsFor:'protocol'! |
|
241 |
||
242 |
dragTo:aRootPoint |
|
2078 | 243 |
"do a line or arrow drag" |
244 |
||
873 | 245 |
self postDragging. |
1487 | 246 |
endPoint := lastRootPoint := aRootPoint. |
873 | 247 |
self postDragging. |
248 |
! |
|
249 |
||
250 |
postDragging |
|
2078 | 251 |
"invert for a line or arrow drag" |
252 |
||
873 | 253 |
|arrow| |
254 |
||
255 |
endPoint isNil ifTrue:[ |
|
256 |
^ self |
|
257 |
]. |
|
258 |
rootView clippedByChildren:false. |
|
259 |
||
260 |
rootView xoring:[ |
|
261 |
rootView lineWidth:0. |
|
262 |
||
263 |
lineMode == #arrow ifTrue:[ |
|
264 |
arrow := Arrow from:startPoint to:endPoint. |
|
265 |
arrow arrowHeadLength:(rootView device horizontalPixelPerMillimeter * 4) rounded. |
|
266 |
arrow displayFilledOn:rootView. |
|
267 |
] ifFalse:[ |
|
268 |
rootView displayLineFrom:startPoint to:endPoint. |
|
269 |
]. |
|
270 |
rootView flush |
|
271 |
] |
|
272 |
! ! |
|
273 |
||
274 |
!DragHandler::Opaque class methodsFor:'constants'! |
|
275 |
||
276 |
additionalSaveSize |
|
277 |
^ 50 @ 50 |
|
278 |
||
279 |
||
280 |
! ! |
|
281 |
||
282 |
!DragHandler::Opaque class methodsFor:'documentation'! |
|
283 |
||
284 |
documentation |
|
285 |
" |
|
286 |
this class handles an generic opaque drag on the screen. It is not visible |
|
287 |
to the user and is created automatically by the DragAndDropManger. |
|
288 |
||
289 |
[author:] |
|
290 |
Claus Gittinger |
|
291 |
||
292 |
[see also:] |
|
293 |
DragAndDropManager |
|
294 |
" |
|
295 |
||
296 |
||
297 |
! ! |
|
298 |
||
299 |
!DragHandler::Opaque methodsFor:'instance creation'! |
|
300 |
||
301 |
dragSize:anExtent dragOffset:anOffset dragBlock:aTwoArgBlock |
|
302 |
"the dragBlock will be called with two arguments, aPoint and the drawing GC, |
|
303 |
to perform the drawing at some dragPoint. |
|
304 |
" |
|
305 |
dragSize := anExtent. |
|
306 |
dragOffset := anOffset. |
|
307 |
dragBlock := aTwoArgBlock |
|
308 |
! ! |
|
309 |
||
310 |
!DragHandler::Opaque methodsFor:'protocol'! |
|
311 |
||
312 |
dragTo:aRootPoint |
|
2078 | 313 |
"drag to a root point" |
314 |
||
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
315 |
|p extent point area| |
1487 | 316 |
|
1687
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
317 |
(saveArea notNil and:[lastRootPoint notNil]) ifTrue:[ |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
318 |
( lastRootPoint x == aRootPoint x |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
319 |
and:[lastRootPoint y == aRootPoint y] |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
320 |
) ifTrue:[ |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
321 |
"/ nothing changed |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
322 |
^ self |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
323 |
]. |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
324 |
]. |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
325 |
|
1487 | 326 |
lastRootPoint := aRootPoint. |
873 | 327 |
"/ |
328 |
"/ copy from screen to saveUnder |
|
329 |
"/ |
|
330 |
rootView clippedByChildren:false. |
|
331 |
extent := saveUnder extent. |
|
332 |
point := aRootPoint - dragOffset. |
|
333 |
||
334 |
saveArea notNil ifTrue:[ |
|
335 |
( (saveArea left <= point x) |
|
336 |
and:[(saveArea top <= point y) |
|
337 |
and:[(saveArea right >= (point x + dragSize x)) |
|
338 |
and:[(saveArea bottom >= (point y + dragSize y))]]] |
|
339 |
) ifFalse:[ |
|
340 |
"/ |
|
341 |
"/ draggable objects no longer contained in saved area; |
|
342 |
"/ thus we have to restore the saved area on the screen. |
|
343 |
"/ |
|
344 |
self postDragging |
|
345 |
] |
|
346 |
]. |
|
347 |
||
348 |
saveArea isNil ifTrue:[ |
|
349 |
"/ |
|
350 |
"/ screen not yet saved; thus we have to save the area |
|
351 |
"/ |
|
352 |
p := point - (self class additionalSaveSize). |
|
353 |
||
354 |
saveUnder copyFrom:rootView |
|
355 |
x:p x |
|
356 |
y:p y |
|
357 |
toX:0 |
|
358 |
y:0 |
|
359 |
width:extent x |
|
360 |
height:extent y. |
|
361 |
saveArea := p extent:extent. |
|
362 |
]. |
|
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
363 |
area := saveArea. |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
364 |
|
873 | 365 |
"/ |
366 |
"/ draw into the form using the dragAction block |
|
367 |
"/ |
|
368 |
tmpForm copyFrom:saveUnder toX:0 y:0. |
|
369 |
tmpForm paint:Color black. |
|
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
370 |
|
873 | 371 |
dragBlock value:(point - saveArea origin + dragOffset) value:tmpForm. |
372 |
||
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
373 |
area == saveArea ifFalse:[ |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
374 |
"saveArea changed during dragB;lock operation" |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
375 |
^ self |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
376 |
]. |
2044 | 377 |
|
873 | 378 |
rootView copyFrom:tmpForm |
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
379 |
x:area origin x |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
380 |
y:area origin y |
873 | 381 |
width:extent x |
382 |
height:extent y |
|
383 |
! |
|
384 |
||
385 |
dropTargetWillChange |
|
2078 | 386 |
"restore old saveArea" |
387 |
||
873 | 388 |
self postDragging |
389 |
! |
|
390 |
||
2043 | 391 |
flushSaveArea |
392 |
saveArea := nil |
|
393 |
! |
|
394 |
||
873 | 395 |
postDragging |
2078 | 396 |
"restore from saveUnder for a generic opaque drag" |
397 |
||
873 | 398 |
saveArea notNil ifTrue:[ |
399 |
rootView clippedByChildren:false. |
|
400 |
"/ |
|
401 |
"/ copy from saveUnder back to screen |
|
402 |
"/ |
|
403 |
rootView copyFrom:saveUnder |
|
404 |
x:saveArea origin x |
|
405 |
y:saveArea origin y |
|
406 |
width:saveArea extent x |
|
407 |
height:saveArea extent y. |
|
408 |
||
409 |
saveArea := nil. |
|
410 |
] |
|
411 |
! |
|
412 |
||
413 |
preDraggingIn:aSourceWidget |
|
2078 | 414 |
"setup my default values" |
415 |
||
873 | 416 |
|depth extent device| |
417 |
||
418 |
super preDraggingIn:aSourceWidget. |
|
419 |
||
420 |
device := aSourceWidget device. |
|
421 |
depth := rootView device depth. |
|
422 |
extent := dragSize + (2 * (self class additionalSaveSize)). |
|
423 |
saveUnder := Form extent:extent depth:depth on:device. |
|
424 |
tmpForm := Form extent:extent depth:depth on:device. |
|
425 |
||
426 |
saveUnder clippedByChildren:false. |
|
427 |
tmpForm initGC. |
|
428 |
tmpForm font:(aSourceWidget font). |
|
1487 | 429 |
! |
430 |
||
431 |
rereadSaveArea |
|
432 |
saveArea notNil ifTrue:[ |
|
433 |
rootView clippedByChildren:false. |
|
434 |
"/ |
|
435 |
"/ copy from saveUnder back to screen |
|
436 |
"/ |
|
437 |
saveUnder copyFrom:rootView |
|
438 |
x:saveArea origin x |
|
439 |
y:saveArea origin y |
|
440 |
width:saveArea extent x |
|
441 |
height:saveArea extent y. |
|
442 |
] |
|
443 |
! |
|
444 |
||
445 |
restoreFromSaveArea |
|
1639 | 446 |
lastRootPoint notNil ifTrue:[ |
447 |
self dragTo:lastRootPoint |
|
448 |
]. |
|
873 | 449 |
! ! |
450 |
||
451 |
!DragHandler class methodsFor:'documentation'! |
|
452 |
||
453 |
version |
|
2078 | 454 |
^ '$Header: /cvs/stx/stx/libview2/DragHandler.st,v 1.9 2006-01-10 09:47:37 cg Exp $' |
873 | 455 |
! ! |