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 |
|
|
16 |
Object subclass:#DragHandler
|
|
17 |
instanceVariableNames:'rootView'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Interface-DragAndDrop'
|
|
21 |
!
|
|
22 |
|
|
23 |
DragHandler subclass:#Generic
|
|
24 |
instanceVariableNames:'prevPoint lastPoint dragBlock'
|
|
25 |
classVariableNames:''
|
|
26 |
poolDictionaries:''
|
|
27 |
privateIn:DragHandler
|
|
28 |
!
|
|
29 |
|
|
30 |
DragHandler subclass:#Line
|
|
31 |
instanceVariableNames:'startPoint endPoint lineMode'
|
|
32 |
classVariableNames:''
|
|
33 |
poolDictionaries:''
|
|
34 |
privateIn:DragHandler
|
|
35 |
!
|
|
36 |
|
|
37 |
DragHandler subclass:#Opaque
|
|
38 |
instanceVariableNames:'dragSize dragBlock dragOffset saveUnder saveArea tmpForm'
|
|
39 |
classVariableNames:''
|
|
40 |
poolDictionaries:''
|
|
41 |
privateIn:DragHandler
|
|
42 |
!
|
|
43 |
|
|
44 |
!DragHandler class methodsFor:'documentation'!
|
|
45 |
|
|
46 |
copyright
|
|
47 |
"
|
|
48 |
COPYRIGHT (c) 1998 by eXept Software AG / Claus Gittinger
|
|
49 |
All Rights Reserved
|
|
50 |
|
|
51 |
This software is furnished under a license and may be used
|
|
52 |
only in accordance with the terms of that license and with the
|
|
53 |
inclusion of the above copyright notice. This software may not
|
|
54 |
be provided or otherwise made available to, or used by, any
|
|
55 |
other person. No title to or ownership of the software is
|
|
56 |
hereby transferred.
|
|
57 |
"
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
!
|
|
62 |
|
|
63 |
documentation
|
|
64 |
"
|
|
65 |
this abstract class describes the protocol common to any DragHandler.
|
|
66 |
The DragAndDropManger creates one instance responsible to show the
|
|
67 |
dragging objects on the screen.
|
|
68 |
|
|
69 |
[author:]
|
|
70 |
Claus Gittinger
|
|
71 |
|
|
72 |
[see also:]
|
|
73 |
DragAndDropManager
|
|
74 |
"
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
! !
|
|
79 |
|
|
80 |
!DragHandler class methodsFor:'instance creation'!
|
|
81 |
|
|
82 |
startArrowDragAt:aStartPoint
|
|
83 |
"creates and returns the drag handler which is responsible
|
|
84 |
for an arrow drag.
|
|
85 |
"
|
|
86 |
^ Line new startPoint:aStartPoint mode:#arrow
|
|
87 |
!
|
|
88 |
|
|
89 |
startGenericDrag:aTwoArgDragBlock
|
|
90 |
"creates and returns the drag handler which is responsible
|
|
91 |
for a generic drag.
|
|
92 |
"
|
|
93 |
^ Generic new dragBlock:aTwoArgDragBlock
|
|
94 |
!
|
|
95 |
|
|
96 |
startLineDragAt:aStartPoint
|
|
97 |
"creates and returns the drag handler which is responsible
|
|
98 |
for a line drag.
|
|
99 |
"
|
|
100 |
^ Line new startPoint:aStartPoint mode:nil
|
|
101 |
!
|
|
102 |
|
|
103 |
startOpaqueDrag:aTwoArgDragBlock extent:anExtent offset:anOffset
|
|
104 |
"creates and returns the drag handler which is responsible
|
|
105 |
for a generic opaque drag.
|
|
106 |
"
|
|
107 |
^ Opaque new dragSize:anExtent dragOffset:anOffset dragBlock:aTwoArgDragBlock
|
|
108 |
! !
|
|
109 |
|
|
110 |
!DragHandler methodsFor:'event dropTarget'!
|
|
111 |
|
|
112 |
dropTargetWillChange
|
|
113 |
"called before the drop target or widget changed.
|
|
114 |
restore root view ... (optional)
|
|
115 |
"
|
|
116 |
|
|
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
|
|
122 |
the objects.
|
|
123 |
"
|
|
124 |
^ true
|
|
125 |
|
|
126 |
|
|
127 |
! !
|
|
128 |
|
|
129 |
!DragHandler methodsFor:'protocol'!
|
|
130 |
|
|
131 |
dragTo:aRootPoint
|
|
132 |
"drag to a root point
|
|
133 |
"
|
|
134 |
self subclassResponsibility
|
|
135 |
|
|
136 |
|
|
137 |
!
|
|
138 |
|
|
139 |
postDragging
|
|
140 |
"after dragging; restore root view ...
|
|
141 |
"
|
|
142 |
self subclassResponsibility
|
|
143 |
|
|
144 |
|
|
145 |
!
|
|
146 |
|
|
147 |
preDraggingIn:aSourceWidget
|
|
148 |
"called before starting the drag & drop operation
|
|
149 |
"
|
|
150 |
rootView := aSourceWidget device rootView.
|
|
151 |
|
|
152 |
! !
|
|
153 |
|
|
154 |
!DragHandler::Generic class methodsFor:'documentation'!
|
|
155 |
|
|
156 |
documentation
|
|
157 |
"
|
|
158 |
this class handles a generic drag on the screen. It is not visible to
|
|
159 |
the user and is created automatically by the DragAndDropManger.
|
|
160 |
|
|
161 |
[author:]
|
|
162 |
Claus Gittinger
|
|
163 |
|
|
164 |
[see also:]
|
|
165 |
DragAndDropManager
|
|
166 |
"
|
|
167 |
|
|
168 |
|
|
169 |
! !
|
|
170 |
|
|
171 |
!DragHandler::Generic methodsFor:'instance creation'!
|
|
172 |
|
|
173 |
dragBlock:aTwoArgBlock
|
|
174 |
"the dragBlock will be called with two arguments, aPoint and the drawing GC,
|
|
175 |
to perform the drawing at some dragPoint.
|
|
176 |
"
|
|
177 |
dragBlock := aTwoArgBlock
|
|
178 |
! !
|
|
179 |
|
|
180 |
!DragHandler::Generic methodsFor:'protocol'!
|
|
181 |
|
|
182 |
dragTo:aRootPoint
|
|
183 |
"drag to a root point
|
|
184 |
"
|
|
185 |
prevPoint notNil ifTrue:[
|
|
186 |
self postDragging
|
|
187 |
].
|
|
188 |
lastPoint := nil.
|
|
189 |
prevPoint := aRootPoint.
|
|
190 |
self postDragging
|
|
191 |
|
|
192 |
|
|
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.
|
|
251 |
endPoint := aRootPoint.
|
|
252 |
self postDragging.
|
|
253 |
|
|
254 |
|
|
255 |
!
|
|
256 |
|
|
257 |
postDragging
|
|
258 |
"invert for a line or arrow drag
|
|
259 |
"
|
|
260 |
|arrow|
|
|
261 |
|
|
262 |
endPoint isNil ifTrue:[
|
|
263 |
^ self
|
|
264 |
].
|
|
265 |
rootView clippedByChildren:false.
|
|
266 |
|
|
267 |
rootView xoring:[
|
|
268 |
rootView lineWidth:0.
|
|
269 |
|
|
270 |
lineMode == #arrow ifTrue:[
|
|
271 |
arrow := Arrow from:startPoint to:endPoint.
|
|
272 |
arrow arrowHeadLength:(rootView device horizontalPixelPerMillimeter * 4) rounded.
|
|
273 |
arrow displayFilledOn:rootView.
|
|
274 |
] ifFalse:[
|
|
275 |
rootView displayLineFrom:startPoint to:endPoint.
|
|
276 |
].
|
|
277 |
rootView flush
|
|
278 |
]
|
|
279 |
|
|
280 |
! !
|
|
281 |
|
|
282 |
!DragHandler::Opaque class methodsFor:'constants'!
|
|
283 |
|
|
284 |
additionalSaveSize
|
|
285 |
^ 50 @ 50
|
|
286 |
|
|
287 |
|
|
288 |
! !
|
|
289 |
|
|
290 |
!DragHandler::Opaque class methodsFor:'documentation'!
|
|
291 |
|
|
292 |
documentation
|
|
293 |
"
|
|
294 |
this class handles an generic opaque drag on the screen. It is not visible
|
|
295 |
to the user and is created automatically by the DragAndDropManger.
|
|
296 |
|
|
297 |
[author:]
|
|
298 |
Claus Gittinger
|
|
299 |
|
|
300 |
[see also:]
|
|
301 |
DragAndDropManager
|
|
302 |
"
|
|
303 |
|
|
304 |
|
|
305 |
! !
|
|
306 |
|
|
307 |
!DragHandler::Opaque methodsFor:'instance creation'!
|
|
308 |
|
|
309 |
dragSize:anExtent dragOffset:anOffset dragBlock:aTwoArgBlock
|
|
310 |
"the dragBlock will be called with two arguments, aPoint and the drawing GC,
|
|
311 |
to perform the drawing at some dragPoint.
|
|
312 |
"
|
|
313 |
dragSize := anExtent.
|
|
314 |
dragOffset := anOffset.
|
|
315 |
dragBlock := aTwoArgBlock
|
|
316 |
! !
|
|
317 |
|
|
318 |
!DragHandler::Opaque methodsFor:'protocol'!
|
|
319 |
|
|
320 |
dragTo:aRootPoint
|
|
321 |
"drag to a root point
|
|
322 |
"
|
|
323 |
|p extent point|
|
|
324 |
"/
|
|
325 |
"/ copy from screen to saveUnder
|
|
326 |
"/
|
|
327 |
rootView clippedByChildren:false.
|
|
328 |
extent := saveUnder extent.
|
|
329 |
point := aRootPoint - dragOffset.
|
|
330 |
|
|
331 |
saveArea notNil ifTrue:[
|
|
332 |
( (saveArea left <= point x)
|
|
333 |
and:[(saveArea top <= point y)
|
|
334 |
and:[(saveArea right >= (point x + dragSize x))
|
|
335 |
and:[(saveArea bottom >= (point y + dragSize y))]]]
|
|
336 |
) ifFalse:[
|
|
337 |
"/
|
|
338 |
"/ draggable objects no longer contained in saved area;
|
|
339 |
"/ thus we have to restore the saved area on the screen.
|
|
340 |
"/
|
|
341 |
self postDragging
|
|
342 |
]
|
|
343 |
].
|
|
344 |
|
|
345 |
saveArea isNil ifTrue:[
|
|
346 |
"/
|
|
347 |
"/ screen not yet saved; thus we have to save the area
|
|
348 |
"/
|
|
349 |
p := point - (self class additionalSaveSize).
|
|
350 |
|
|
351 |
saveUnder copyFrom:rootView
|
|
352 |
x:p x
|
|
353 |
y:p y
|
|
354 |
toX:0
|
|
355 |
y:0
|
|
356 |
width:extent x
|
|
357 |
height:extent y.
|
|
358 |
|
|
359 |
saveArea := p extent:extent.
|
|
360 |
].
|
|
361 |
"/
|
|
362 |
"/ draw into the form using the dragAction block
|
|
363 |
"/
|
|
364 |
tmpForm copyFrom:saveUnder toX:0 y:0.
|
|
365 |
tmpForm paint:Color black.
|
|
366 |
dragBlock value:(point - saveArea origin + dragOffset) value:tmpForm.
|
|
367 |
|
|
368 |
rootView copyFrom:tmpForm
|
|
369 |
x:saveArea origin x
|
|
370 |
y:saveArea origin y
|
|
371 |
width:extent x
|
|
372 |
height:extent y
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
!
|
|
377 |
|
|
378 |
dropTargetWillChange
|
|
379 |
"restore old saveArea
|
|
380 |
"
|
|
381 |
self postDragging
|
|
382 |
|
|
383 |
|
|
384 |
!
|
|
385 |
|
|
386 |
postDragging
|
|
387 |
"restore from saveUnder for a generic opaque drag
|
|
388 |
"
|
|
389 |
saveArea notNil ifTrue:[
|
|
390 |
rootView clippedByChildren:false.
|
|
391 |
"/
|
|
392 |
"/ copy from saveUnder back to screen
|
|
393 |
"/
|
|
394 |
rootView copyFrom:saveUnder
|
|
395 |
x:saveArea origin x
|
|
396 |
y:saveArea origin y
|
|
397 |
width:saveArea extent x
|
|
398 |
height:saveArea extent y.
|
|
399 |
|
|
400 |
saveArea := nil.
|
|
401 |
]
|
|
402 |
|
|
403 |
!
|
|
404 |
|
|
405 |
preDraggingIn:aSourceWidget
|
|
406 |
"setup my default values
|
|
407 |
"
|
|
408 |
|depth extent device|
|
|
409 |
|
|
410 |
super preDraggingIn:aSourceWidget.
|
|
411 |
|
|
412 |
device := aSourceWidget device.
|
|
413 |
depth := rootView device depth.
|
|
414 |
extent := dragSize + (2 * (self class additionalSaveSize)).
|
|
415 |
saveUnder := Form extent:extent depth:depth on:device.
|
|
416 |
tmpForm := Form extent:extent depth:depth on:device.
|
|
417 |
|
|
418 |
saveUnder clippedByChildren:false.
|
|
419 |
tmpForm initGC.
|
|
420 |
tmpForm font:(aSourceWidget font).
|
|
421 |
|
|
422 |
|
|
423 |
! !
|
|
424 |
|
|
425 |
!DragHandler class methodsFor:'documentation'!
|
|
426 |
|
|
427 |
version
|
|
428 |
^ '$Header: /cvs/stx/stx/libview2/DragHandler.st,v 1.1 1998-03-30 12:00:30 ca Exp $'
|
|
429 |
! !
|