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