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