author | Claus Gittinger <cg@exept.de> |
Fri, 01 May 2009 19:36:50 +0200 | |
changeset 2626 | 762fe84ed4fa |
parent 2438 | 27171b77ab40 |
child 3160 | 7aa62ff13f85 |
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 |
2435
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
15 |
instanceVariableNames:'rootView lastRootPoint dropContext' |
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 |
||
2435
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
108 |
!DragHandler methodsFor:'accessing'! |
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
109 |
|
2438 | 110 |
dropContext |
111 |
^ dropContext |
|
2435
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
112 |
! |
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
113 |
|
2438 | 114 |
dropContext:something |
115 |
dropContext := something. |
|
116 |
! |
|
117 |
||
118 |
targetView |
|
119 |
dropContext isNil ifTrue:[^ nil]. |
|
120 |
^ dropContext targetView |
|
2435
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
121 |
! ! |
081b5c1b73c8
pass dropContext in dragHandler
Claus Gittinger <cg@exept.de>
parents:
2331
diff
changeset
|
122 |
|
873 | 123 |
!DragHandler methodsFor:'event dropTarget'! |
124 |
||
125 |
dropTargetWillChange |
|
126 |
"called before the drop target or widget changed. |
|
2078 | 127 |
restore root view ... (optional)" |
873 | 128 |
! |
129 |
||
130 |
isInterestedInDropTarget |
|
131 |
"returns true, if the handler is interested in the underlying |
|
132 |
drop target and the target should be tested to be able to drop |
|
2078 | 133 |
the objects." |
134 |
||
873 | 135 |
^ true |
136 |
! ! |
|
137 |
||
138 |
!DragHandler methodsFor:'protocol'! |
|
139 |
||
140 |
dragTo:aRootPoint |
|
2078 | 141 |
"drag to a root point" |
142 |
||
873 | 143 |
self subclassResponsibility |
144 |
! |
|
145 |
||
2043 | 146 |
flushSaveArea |
147 |
! |
|
148 |
||
873 | 149 |
postDragging |
2078 | 150 |
"after dragging; restore root view ..." |
151 |
||
873 | 152 |
self subclassResponsibility |
153 |
! |
|
154 |
||
155 |
preDraggingIn:aSourceWidget |
|
2078 | 156 |
"called before starting the drag & drop operation" |
157 |
||
873 | 158 |
rootView := aSourceWidget device rootView. |
2043 | 159 |
! |
160 |
||
161 |
rereadSaveArea |
|
873 | 162 |
! ! |
163 |
||
164 |
!DragHandler::Generic class methodsFor:'documentation'! |
|
165 |
||
166 |
documentation |
|
167 |
" |
|
168 |
this class handles a generic drag on the screen. It is not visible to |
|
169 |
the user and is created automatically by the DragAndDropManger. |
|
170 |
||
171 |
[author:] |
|
172 |
Claus Gittinger |
|
173 |
||
174 |
[see also:] |
|
175 |
DragAndDropManager |
|
176 |
" |
|
177 |
||
178 |
||
179 |
! ! |
|
180 |
||
181 |
!DragHandler::Generic methodsFor:'instance creation'! |
|
182 |
||
183 |
dragBlock:aTwoArgBlock |
|
184 |
"the dragBlock will be called with two arguments, aPoint and the drawing GC, |
|
2078 | 185 |
to perform the drawing at some dragPoint." |
186 |
||
873 | 187 |
dragBlock := aTwoArgBlock |
188 |
! ! |
|
189 |
||
190 |
!DragHandler::Generic methodsFor:'protocol'! |
|
191 |
||
192 |
dragTo:aRootPoint |
|
2078 | 193 |
"drag to a root point" |
194 |
||
873 | 195 |
prevPoint notNil ifTrue:[ |
196 |
self postDragging |
|
197 |
]. |
|
198 |
lastPoint := nil. |
|
1487 | 199 |
prevPoint := lastRootPoint := aRootPoint. |
873 | 200 |
self postDragging |
201 |
! |
|
202 |
||
203 |
postDragging |
|
204 |
lastPoint isNil ifTrue:[ |
|
205 |
lastPoint := prevPoint. |
|
206 |
]. |
|
207 |
rootView clippedByChildren:false. |
|
208 |
||
209 |
rootView xoring:[ |
|
210 |
rootView lineWidth:0. |
|
211 |
dragBlock value:lastPoint value:rootView. |
|
212 |
rootView flush |
|
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 |
|
2078 | 254 |
"do a line or arrow drag" |
255 |
||
873 | 256 |
self postDragging. |
1487 | 257 |
endPoint := lastRootPoint := aRootPoint. |
873 | 258 |
self postDragging. |
259 |
! |
|
260 |
||
261 |
postDragging |
|
2078 | 262 |
"invert for a line or arrow drag" |
263 |
||
873 | 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 |
!DragHandler::Opaque class methodsFor:'constants'! |
|
286 |
||
287 |
additionalSaveSize |
|
288 |
^ 50 @ 50 |
|
289 |
||
290 |
||
291 |
! ! |
|
292 |
||
293 |
!DragHandler::Opaque class methodsFor:'documentation'! |
|
294 |
||
295 |
documentation |
|
296 |
" |
|
297 |
this class handles an generic opaque drag on the screen. It is not visible |
|
298 |
to the user and is created automatically by the DragAndDropManger. |
|
299 |
||
300 |
[author:] |
|
301 |
Claus Gittinger |
|
302 |
||
303 |
[see also:] |
|
304 |
DragAndDropManager |
|
305 |
" |
|
306 |
||
307 |
||
308 |
! ! |
|
309 |
||
310 |
!DragHandler::Opaque methodsFor:'instance creation'! |
|
311 |
||
312 |
dragSize:anExtent dragOffset:anOffset dragBlock:aTwoArgBlock |
|
313 |
"the dragBlock will be called with two arguments, aPoint and the drawing GC, |
|
314 |
to perform the drawing at some dragPoint. |
|
315 |
" |
|
316 |
dragSize := anExtent. |
|
317 |
dragOffset := anOffset. |
|
318 |
dragBlock := aTwoArgBlock |
|
319 |
! ! |
|
320 |
||
321 |
!DragHandler::Opaque methodsFor:'protocol'! |
|
322 |
||
323 |
dragTo:aRootPoint |
|
2078 | 324 |
"drag to a root point" |
325 |
||
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
326 |
|p extent point area| |
1487 | 327 |
|
1687
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
328 |
(saveArea notNil and:[lastRootPoint notNil]) ifTrue:[ |
2626
762fe84ed4fa
change back the cursor, when escaping;
Claus Gittinger <cg@exept.de>
parents:
2438
diff
changeset
|
329 |
(lastRootPoint = aRootPoint) ifTrue:[ |
1687
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
330 |
"/ nothing changed |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
331 |
^ self |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
332 |
]. |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
333 |
]. |
1ad29040b257
#dragTo: test whether clickPoint changed to the last clickPoint
ca
parents:
1639
diff
changeset
|
334 |
|
1487 | 335 |
lastRootPoint := aRootPoint. |
873 | 336 |
"/ |
337 |
"/ copy from screen to saveUnder |
|
338 |
"/ |
|
339 |
rootView clippedByChildren:false. |
|
340 |
extent := saveUnder extent. |
|
341 |
point := aRootPoint - dragOffset. |
|
342 |
||
343 |
saveArea notNil ifTrue:[ |
|
344 |
( (saveArea left <= point x) |
|
345 |
and:[(saveArea top <= point y) |
|
346 |
and:[(saveArea right >= (point x + dragSize x)) |
|
347 |
and:[(saveArea bottom >= (point y + dragSize y))]]] |
|
348 |
) ifFalse:[ |
|
349 |
"/ |
|
350 |
"/ draggable objects no longer contained in saved area; |
|
351 |
"/ thus we have to restore the saved area on the screen. |
|
352 |
"/ |
|
353 |
self postDragging |
|
354 |
] |
|
355 |
]. |
|
356 |
||
357 |
saveArea isNil ifTrue:[ |
|
358 |
"/ |
|
359 |
"/ screen not yet saved; thus we have to save the area |
|
360 |
"/ |
|
361 |
p := point - (self class additionalSaveSize). |
|
362 |
||
363 |
saveUnder copyFrom:rootView |
|
364 |
x:p x |
|
365 |
y:p y |
|
366 |
toX:0 |
|
367 |
y:0 |
|
368 |
width:extent x |
|
369 |
height:extent y. |
|
370 |
saveArea := p extent:extent. |
|
371 |
]. |
|
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
372 |
area := saveArea. |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
373 |
|
873 | 374 |
"/ |
375 |
"/ draw into the form using the dragAction block |
|
376 |
"/ |
|
377 |
tmpForm copyFrom:saveUnder toX:0 y:0. |
|
378 |
tmpForm paint:Color black. |
|
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
379 |
|
873 | 380 |
dragBlock value:(point - saveArea origin + dragOffset) value:tmpForm. |
381 |
||
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
382 |
area == saveArea ifFalse:[ |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
383 |
"saveArea changed during dragB;lock operation" |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
384 |
^ self |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
385 |
]. |
2044 | 386 |
|
873 | 387 |
rootView copyFrom:tmpForm |
1836
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
388 |
x:area origin x |
c1e0cf991a4d
bugfix in dragTo: test whether saveArea changed dur to async task
ca
parents:
1687
diff
changeset
|
389 |
y:area origin y |
873 | 390 |
width:extent x |
391 |
height:extent y |
|
392 |
! |
|
393 |
||
394 |
dropTargetWillChange |
|
2078 | 395 |
"restore old saveArea" |
396 |
||
873 | 397 |
self postDragging |
398 |
! |
|
399 |
||
2043 | 400 |
flushSaveArea |
401 |
saveArea := nil |
|
402 |
! |
|
403 |
||
873 | 404 |
postDragging |
2078 | 405 |
"restore from saveUnder for a generic opaque drag" |
406 |
||
873 | 407 |
saveArea notNil ifTrue:[ |
408 |
rootView clippedByChildren:false. |
|
409 |
"/ |
|
410 |
"/ copy from saveUnder back to screen |
|
411 |
"/ |
|
412 |
rootView copyFrom:saveUnder |
|
413 |
x:saveArea origin x |
|
414 |
y:saveArea origin y |
|
415 |
width:saveArea extent x |
|
416 |
height:saveArea extent y. |
|
417 |
||
418 |
saveArea := nil. |
|
419 |
] |
|
420 |
! |
|
421 |
||
422 |
preDraggingIn:aSourceWidget |
|
2078 | 423 |
"setup my default values" |
424 |
||
873 | 425 |
|depth extent device| |
426 |
||
427 |
super preDraggingIn:aSourceWidget. |
|
428 |
||
429 |
device := aSourceWidget device. |
|
430 |
depth := rootView device depth. |
|
431 |
extent := dragSize + (2 * (self class additionalSaveSize)). |
|
2331 | 432 |
saveUnder := Form extent:extent depth:depth onDevice:device. |
433 |
tmpForm := Form extent:extent depth:depth onDevice:device. |
|
873 | 434 |
|
435 |
saveUnder clippedByChildren:false. |
|
436 |
tmpForm initGC. |
|
437 |
tmpForm font:(aSourceWidget font). |
|
2331 | 438 |
|
439 |
"Modified: / 27-05-2007 / 12:48:28 / cg" |
|
1487 | 440 |
! |
441 |
||
442 |
rereadSaveArea |
|
443 |
saveArea notNil ifTrue:[ |
|
444 |
rootView clippedByChildren:false. |
|
445 |
"/ |
|
446 |
"/ copy from saveUnder back to screen |
|
447 |
"/ |
|
448 |
saveUnder copyFrom:rootView |
|
449 |
x:saveArea origin x |
|
450 |
y:saveArea origin y |
|
451 |
width:saveArea extent x |
|
452 |
height:saveArea extent y. |
|
453 |
] |
|
454 |
! |
|
455 |
||
456 |
restoreFromSaveArea |
|
1639 | 457 |
lastRootPoint notNil ifTrue:[ |
458 |
self dragTo:lastRootPoint |
|
459 |
]. |
|
873 | 460 |
! ! |
461 |
||
462 |
!DragHandler class methodsFor:'documentation'! |
|
463 |
||
464 |
version |
|
2626
762fe84ed4fa
change back the cursor, when escaping;
Claus Gittinger <cg@exept.de>
parents:
2438
diff
changeset
|
465 |
^ '$Header: /cvs/stx/stx/libview2/DragHandler.st,v 1.13 2009-05-01 17:36:50 cg Exp $' |
873 | 466 |
! ! |