author | Claus Gittinger <cg@exept.de> |
Thu, 05 Jun 2008 17:30:14 +0200 | |
changeset 2493 | 6aa0d6539c5d |
parent 2492 | 5462e31d8af3 |
child 2564 | 10ed9ff5b0fc |
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 |
" |
|
1397 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
873 | 14 |
Object subclass:#DropContext |
15 |
instanceVariableNames:'dropObjects rootPoint dropSource sourceWidget dropTarget |
|
1662 | 16 |
targetWidget targetId hasDropped dragHandler manager dropInfo' |
873 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Interface-DragAndDrop' |
|
20 |
! |
|
21 |
||
22 |
!DropContext class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1998 by eXept Software AG / Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
||
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
instance, which keeps information about the current drag & drop operation. |
|
42 |
||
43 |
dropObjects <Collection> collection of dropObjects. |
|
44 |
rootPoint <Point> the current mouse position on the screen (root view). |
|
45 |
||
46 |
[see also:] |
|
47 |
DragAndDropManager |
|
48 |
DropObject |
|
49 |
DropSource |
|
50 |
DropTarget |
|
51 |
||
52 |
[author:] |
|
53 |
Claus Atzkern |
|
54 |
" |
|
55 |
! ! |
|
56 |
||
57 |
!DropContext methodsFor:'accessing'! |
|
58 |
||
1161
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
59 |
dragHandler |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
60 |
^ dragHandler |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
61 |
|
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
62 |
! |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
63 |
|
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
64 |
dragHandler:aHandler |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
65 |
dragHandler := aHandler |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
66 |
! |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
67 |
|
1662 | 68 |
dropInfo |
69 |
"a hook for additional info" |
|
70 |
||
71 |
dropInfo isNil ifTrue:[ |
|
72 |
dropInfo := IdentityDictionary new |
|
73 |
]. |
|
74 |
^ dropInfo |
|
75 |
! |
|
76 |
||
873 | 77 |
dropObjects |
1824 | 78 |
"returns the collection of dropobjects" |
79 |
||
873 | 80 |
^ dropObjects ? #() |
81 |
! |
|
82 |
||
1618 | 83 |
manager:something |
84 |
manager := something. |
|
85 |
! |
|
86 |
||
873 | 87 |
rootPoint |
1824 | 88 |
"returns the absolute point on the screen (rootPoint)" |
89 |
||
873 | 90 |
^ rootPoint |
91 |
! ! |
|
92 |
||
1397 | 93 |
!DropContext methodsFor:'accessing-source'! |
873 | 94 |
|
95 |
dropSource |
|
1824 | 96 |
"returns the drop source or nil" |
97 |
||
873 | 98 |
^ dropSource |
99 |
! |
|
100 |
||
101 |
sourceWidget |
|
1824 | 102 |
"returns the source widget the drag is started from" |
103 |
||
873 | 104 |
^ sourceWidget |
105 |
! ! |
|
106 |
||
1397 | 107 |
!DropContext methodsFor:'accessing-target'! |
873 | 108 |
|
109 |
dropTarget |
|
1824 | 110 |
"returns the drop target or nil" |
111 |
||
873 | 112 |
^ dropTarget |
113 |
! |
|
114 |
||
115 |
targetId |
|
1824 | 116 |
"returns the id of the target widget" |
117 |
||
873 | 118 |
^ targetId |
119 |
! |
|
120 |
||
121 |
targetPoint |
|
2493
6aa0d6539c5d
targetPoint is in DEVICE coordinates
Claus Gittinger <cg@exept.de>
parents:
2492
diff
changeset
|
122 |
"returns the relative point on the target widget (in DEVICE coordinates)" |
1824 | 123 |
|
2444
3d985b31faf2
targetPoitn was computed wrong for textViews (scrollOffset)
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
124 |
|trn org pnt dev| |
873 | 125 |
|
126 |
dev := sourceWidget device. |
|
1430
572d486a52b8
use rootWindowId (save a message send)
Claus Gittinger <cg@exept.de>
parents:
1397
diff
changeset
|
127 |
pnt := dev translatePoint:rootPoint from:(dev rootWindowId) to:targetId. |
873 | 128 |
|
2492
5462e31d8af3
fix: care for non.existing targetpoint
Claus Gittinger <cg@exept.de>
parents:
2444
diff
changeset
|
129 |
(pnt notNil and:[targetWidget notNil]) ifTrue:[ |
873 | 130 |
(trn := targetWidget transformation) notNil ifTrue:[ |
2444
3d985b31faf2
targetPoitn was computed wrong for textViews (scrollOffset)
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
131 |
^ trn applyInverseTo:pnt. |
3d985b31faf2
targetPoitn was computed wrong for textViews (scrollOffset)
Claus Gittinger <cg@exept.de>
parents:
2260
diff
changeset
|
132 |
]. |
2493
6aa0d6539c5d
targetPoint is in DEVICE coordinates
Claus Gittinger <cg@exept.de>
parents:
2492
diff
changeset
|
133 |
"/ ca: do not translate here - drop is in device coordinates EVERYWHERE |
6aa0d6539c5d
targetPoint is in DEVICE coordinates
Claus Gittinger <cg@exept.de>
parents:
2492
diff
changeset
|
134 |
"/ (org := targetWidget viewOrigin) notNil ifTrue:[ |
6aa0d6539c5d
targetPoint is in DEVICE coordinates
Claus Gittinger <cg@exept.de>
parents:
2492
diff
changeset
|
135 |
"/ ^ pnt + org. |
6aa0d6539c5d
targetPoint is in DEVICE coordinates
Claus Gittinger <cg@exept.de>
parents:
2492
diff
changeset
|
136 |
"/ ]. |
873 | 137 |
]. |
138 |
^ pnt |
|
139 |
! |
|
140 |
||
141 |
targetWidget |
|
1824 | 142 |
"returns the widget assigned to the current dropTarget" |
143 |
||
873 | 144 |
^ targetWidget |
145 |
! ! |
|
146 |
||
147 |
!DropContext methodsFor:'actions'! |
|
148 |
||
149 |
doDrop |
|
1824 | 150 |
"evaluate the drop operation; set the feedBack" |
151 |
||
873 | 152 |
hasDropped := self canDrop. |
153 |
||
154 |
self isAlienView ifFalse:[ |
|
155 |
hasDropped ifTrue:[ |
|
156 |
dropTarget drop:self |
|
157 |
] ifFalse:[ |
|
158 |
"/ |
|
159 |
"/ called to restore the widget in |
|
160 |
"/ case that something has changed |
|
161 |
"/ |
|
162 |
dropTarget notNil ifTrue:[ |
|
163 |
dropTarget leave:self |
|
164 |
] |
|
165 |
] |
|
166 |
] ifTrue:[ |
|
167 |
"/ |
|
168 |
"/ not one of my views |
|
169 |
"/ external clipboard mechanism via display |
|
170 |
"/ |
|
171 |
"/ ?? FEEDBACK ?? hasDropped ?? |
|
172 |
"/ |
|
1732
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
173 |
sourceWidget device |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
174 |
drop:dropObjects |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
175 |
inWindowID:targetId |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
176 |
position:(self targetPoint) |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
177 |
rootPosition:rootPoint. |
873 | 178 |
]. |
179 |
||
180 |
dropSource notNil ifTrue:[ |
|
1732
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
181 |
hasDropped ifTrue:[ "/ could have been cleared in drop-code |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
182 |
dropSource dropFeedBackFrom:self |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
183 |
] |
873 | 184 |
]. |
1618 | 185 |
! |
186 |
||
2091 | 187 |
exchangeDragHandler:aHandler |
188 |
"make the new handler to the active handler" |
|
189 |
||
190 |
(aHandler notNil and:[ aHandler ~~ dragHandler ]) ifTrue:[ |
|
2014 | 191 |
dragHandler postDragging. |
192 |
dragHandler := aHandler. |
|
193 |
manager dragHandler:dragHandler. |
|
194 |
]. |
|
195 |
! |
|
196 |
||
1662 | 197 |
passiveAction:aBlock |
198 |
manager passiveAction:aBlock |
|
199 |
! |
|
200 |
||
1618 | 201 |
saveDraw:aBlock |
202 |
"evaluate aBlock with the drag temporarily being undrawn |
|
203 |
(i.e. restore original picture, evaluate the block, and draw dragged objects again). |
|
204 |
Return blocks value." |
|
205 |
||
206 |
^ manager saveDraw:aBlock |
|
873 | 207 |
! ! |
208 |
||
1161
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
209 |
!DropContext methodsFor:'change & update'! |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
210 |
|
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
211 |
contentsWillChange |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
212 |
"called by the dropTarget-widget if the contents will change during a |
1824 | 213 |
dragAndDrop operation" |
214 |
||
1161
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
215 |
dragHandler notNil ifTrue:[ |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
216 |
dragHandler dropTargetWillChange |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
217 |
] |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
218 |
! ! |
1b0ae7be8de6
keep reference to DragHandler
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
219 |
|
873 | 220 |
!DropContext methodsFor:'drag & drop manager interface'! |
221 |
||
222 |
dropObjects:something |
|
1824 | 223 |
"set the collection of dropobjects" |
224 |
||
873 | 225 |
something notNil ifTrue:[ |
226 |
dropObjects := something isCollection ifTrue:[something] |
|
227 |
ifFalse:[Array with:something] |
|
228 |
] |
|
229 |
! |
|
230 |
||
231 |
dropSource:aDropSource |
|
1824 | 232 |
"set the dropSource" |
233 |
||
873 | 234 |
dropSource := aDropSource. |
235 |
! |
|
236 |
||
237 |
dropTarget:aDropTargetOrNil |
|
1824 | 238 |
"set a new drop target" |
239 |
||
873 | 240 |
dropTarget := aDropTargetOrNil. |
241 |
! |
|
242 |
||
243 |
rootPoint:something |
|
1824 | 244 |
"set the absolute point on the screen (rootPoint); |
245 |
called by the drag and drop manager" |
|
246 |
||
873 | 247 |
rootPoint := something. |
248 |
! |
|
249 |
||
250 |
sourceWidget:aView |
|
1824 | 251 |
"set the source widget the drag is started from" |
252 |
||
873 | 253 |
sourceWidget := aView. |
254 |
! |
|
255 |
||
256 |
targetWidget:aViewOrNil id:anId |
|
1824 | 257 |
"set a new drop widget" |
258 |
||
873 | 259 |
targetWidget := aViewOrNil. |
260 |
targetId := anId. |
|
261 |
! ! |
|
262 |
||
263 |
!DropContext methodsFor:'queries'! |
|
264 |
||
265 |
canDrop |
|
2260 | 266 |
"returns true if the current dropTarget can drop the objects" |
1824 | 267 |
|
2260 | 268 |
^ dropTarget notNil and:[dropTarget canDrop:self] |
269 |
||
270 |
"Modified: / 13-10-2006 / 15:48:02 / cg" |
|
873 | 271 |
! |
272 |
||
1732
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
273 |
clearHasDroppedFlagToSuppressFeedBack |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
274 |
"can be used from within a targets drop code, |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
275 |
to signal that no feedBack should be send to the |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
276 |
dropSource (because the drop did not happen)" |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
277 |
|
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
278 |
hasDropped := false |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
279 |
! |
d31fef80f6e5
feedBackSelector -> dropFeedBackSelector
Claus Gittinger <cg@exept.de>
parents:
1662
diff
changeset
|
280 |
|
873 | 281 |
hasDropped |
282 |
^ hasDropped ? false |
|
283 |
! |
|
284 |
||
285 |
isAlienView |
|
1824 | 286 |
"returns true if current dropTarget is not an ST/X view" |
287 |
||
873 | 288 |
^ targetWidget isNil |
289 |
! |
|
290 |
||
291 |
isRootView |
|
1824 | 292 |
"returns true if the current target widget is the root view (screen)" |
293 |
||
2000 | 294 |
^ targetWidget isNil |
295 |
ifTrue:[false] |
|
296 |
ifFalse:[targetWidget isRootView] |
|
873 | 297 |
! ! |
298 |
||
299 |
!DropContext class methodsFor:'documentation'! |
|
300 |
||
301 |
version |
|
2493
6aa0d6539c5d
targetPoint is in DEVICE coordinates
Claus Gittinger <cg@exept.de>
parents:
2492
diff
changeset
|
302 |
^ '$Header: /cvs/stx/stx/libview2/DropContext.st,v 1.15 2008-06-05 15:30:14 cg Exp $' |
873 | 303 |
! ! |