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