author | Claus Gittinger <cg@exept.de> |
Wed, 15 Aug 2001 14:52:20 +0200 | |
changeset 1490 | b2e1f907060c |
parent 1487 | 6cefff982779 |
child 1497 | dff682eb74fc |
permissions | -rw-r--r-- |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1 |
" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
2 |
COPYRIGHT (c) 1996 by eXept Software AG / Claus Gittinger |
1166 | 3 |
All Rights Reserved |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
4 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
5 |
This software is furnished under a license and may be used |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
6 |
only in accordance with the terms of that license and with the |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
7 |
inclusion of the above copyright notice. This software may not |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
8 |
be provided or otherwise made available to, or used by, any |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
9 |
other person. No title to or ownership of the software is |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
10 |
hereby transferred. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
11 |
" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
12 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
13 |
|
1397 | 14 |
"{ Package: 'stx:libview2' }" |
15 |
||
341 | 16 |
Object subclass:#DragAndDropManager |
874 | 17 |
instanceVariableNames:'dropContext dragView dropAction dragOffset handler restoreBlock |
18 |
alienCursor enabledCursor disabledCursor canDrop' |
|
1487 | 19 |
classVariableNames:'DragOriginatorQuerySignal DragOffsetQuerySignal |
20 |
ActiveDragAndDropManagers' |
|
628 | 21 |
poolDictionaries:'' |
874 | 22 |
category:'Interface-DragAndDrop' |
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
23 |
! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
24 |
|
341 | 25 |
!DragAndDropManager class methodsFor:'documentation'! |
26 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
27 |
copyright |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
28 |
" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
29 |
COPYRIGHT (c) 1996 by eXept Software AG / Claus Gittinger |
1166 | 30 |
All Rights Reserved |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
31 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
32 |
This software is furnished under a license and may be used |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
33 |
only in accordance with the terms of that license and with the |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
34 |
inclusion of the above copyright notice. This software may not |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
35 |
be provided or otherwise made available to, or used by, any |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
36 |
other person. No title to or ownership of the software is |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
37 |
hereby transferred. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
38 |
" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
39 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
40 |
! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
41 |
|
348 | 42 |
documentation |
43 |
" |
|
44 |
this class provides low-level drag & drop mechanisms. |
|
45 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
46 |
Easy to use interface interfaces: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
47 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
48 |
A drag is usually initiated by a view or its application model, |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
49 |
when a selection is moved (for example, SelectionInListView can |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
50 |
be initializd to do so). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
51 |
There, the view creates a collection of dropObjects from its selection, |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
52 |
and starts the drag operation with: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
53 |
|
1166 | 54 |
DragAndDropManager startDrag:collectionOfDragObjects from:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
55 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
56 |
This easy to use interface starts a drag and also drops the collection |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
57 |
into the target view. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
58 |
While dragging, a thumbsUp cursor is shown, if the view-under-the-drag |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
59 |
can handle a drop, a thumbsDown is shown if not, and a question mark |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
60 |
is shown for alien views (which means: we dont know). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
61 |
Alien view drop is supported (but no 'canDrop' query). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
62 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
63 |
For rubber-band line dragging, two more easy-to-use startup methods are |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
64 |
provided: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
65 |
|
1166 | 66 |
DragAndDropManager |
67 |
startLineDragIn:aView at:position |
|
68 |
atEnd:aFourArgEndBlock |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
69 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
70 |
and: |
1166 | 71 |
DragAndDropManager |
72 |
startArrowDragIn:aView at:position |
|
73 |
atEnd:aFourArgEndBlock |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
74 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
75 |
both of the above expect a 4-arg block to be passed, which will be |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
76 |
evaluated at end-drag, with the target view, its viewID, the drop position |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
77 |
on the screen and within the target view as arguments. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
78 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
79 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
80 |
Expert interface: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
81 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
82 |
More control over the dragging (i.e. the drawing procedure) |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
83 |
can be optained, by passing a dragBlock and an endDrag action: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
84 |
|
1166 | 85 |
aDragAndDropMgr := DragAndDropManager new. |
86 |
aDragAndDropMgr dropObjects:(self collectionOfDragObjects). |
|
87 |
aDragAndDropMgr |
|
88 |
startOpaqueDrag:[:aPoint :aView :dropObjects | |
|
89 |
self |
|
90 |
showDragging:dropObjects |
|
91 |
in:aView |
|
92 |
at:aPoint - (xOffset@0) |
|
93 |
] |
|
94 |
offset:clickOffset |
|
95 |
extent:saveUnderExtent |
|
96 |
in:self |
|
97 |
at:clickPoint |
|
98 |
atEnd:[:v :vId :posScreen :posView | ... ] |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
99 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
100 |
the arguments are: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
101 |
startOpaqueDrag: |
1166 | 102 |
a 3-arg block, which is evaluated by the d&d manager whenever the |
103 |
mouse moves; it is supposed to draw the dropObjects at some position |
|
104 |
in the passed view. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
105 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
106 |
offset: |
1166 | 107 |
a clickOffset; drawing is offset by this amount |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
108 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
109 |
extent: |
1166 | 110 |
a save extent; the size of the screen area that must be saved during |
111 |
the drag operation |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
112 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
113 |
in: |
1166 | 114 |
initiating view |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
115 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
116 |
at: |
1166 | 117 |
position where d&d operation starts |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
118 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
119 |
atEnd: |
1166 | 120 |
a 4-arg block that is evaluated when the d&d is finished. |
121 |
It gets the target view (or nil, for alien views), the targets |
|
122 |
view ID (needed if its an alien view), the screen position and the |
|
123 |
relative position within the target view of the drop as arguments. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
124 |
|
1166 | 125 |
For internal (ST/X) views, the dropBlock should perform |
126 |
a simple canDrop:/doDrop message. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
127 |
|
1166 | 128 |
For alien views, the Displays d&d functions can be used. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
129 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
130 |
|
348 | 131 |
[author:] |
1166 | 132 |
Claus Gittinger |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
133 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
134 |
[see also:] |
1166 | 135 |
DemoView1, DemoView2, ... |
136 |
SelectionInListView FileBrowser - for a concrete example |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
137 |
|
348 | 138 |
" |
139 |
||
140 |
! |
|
141 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
142 |
examples |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
143 |
" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
144 |
a button, which initiates dragging of a file-object |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
145 |
Notice that this can be dropped into the launchers panel, |
549 | 146 |
to open a fileBrowser on that directory ... |
1166 | 147 |
[exBegin] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
148 |
|o top v| |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
149 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
150 |
top := StandardSystemView new. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
151 |
v := Button label:'press for drag' in:top. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
152 |
v pressAction:[ |
1166 | 153 |
|o| |
154 |
o := DropObject newFile:('/etc'). |
|
155 |
DragAndDropManager startDrag:o from:v. |
|
156 |
v turnOff |
|
157 |
]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
158 |
top openWithExtent:200@200 |
1166 | 159 |
[exEnd] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
160 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
161 |
initiate a drag with some offset: |
1166 | 162 |
[exBegin] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
163 |
|o top v| |
341 | 164 |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
165 |
top := StandardSystemView new. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
166 |
v := Button label:'press for drag' in:top. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
167 |
v pressAction:[ |
1166 | 168 |
|o| |
169 |
o := DropObject newFile:('.'). |
|
170 |
DragAndDropManager startDrag:o from:v offset:10@10. |
|
171 |
v turnOff |
|
172 |
]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
173 |
top openWithExtent:200@200 |
1166 | 174 |
[exEnd] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
175 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
176 |
initiate a line drag: |
1166 | 177 |
[exBegin] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
178 |
|o top v endAction| |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
179 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
180 |
endAction := [ :v :vID :sPos :vPos | |
1166 | 181 |
Transcript show:'end drag in '. |
182 |
v isNil ifTrue:[ |
|
183 |
Transcript show:'alien view' |
|
184 |
] ifFalse:[ |
|
185 |
Transcript show:v |
|
186 |
]. |
|
187 |
Transcript show:' at screen: '; show:sPos; |
|
188 |
show:' in view: '; showCR:vPos |
|
189 |
]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
190 |
top := StandardSystemView new. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
191 |
v := Button label:'press for drag' in:top. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
192 |
v pressAction:[ |
1166 | 193 |
DragAndDropManager |
194 |
startLineDragIn:v at:10@10 atEnd:endAction. |
|
195 |
v turnOff |
|
196 |
]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
197 |
top openWithExtent:200@200 |
1166 | 198 |
[exEnd] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
199 |
|
874 | 200 |
more drag & drop; offset, displayObjects, ... |
1166 | 201 |
[exBegin] |
874 | 202 |
|dropObj topView pannel icon buttonAction addButton| |
203 |
||
204 |
topView := StandardSystemView new. |
|
205 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
206 |
pannel horizontalLayout:#fit. |
|
207 |
pannel verticalLayout:#fitSpace. |
|
208 |
||
209 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
210 |
dropObj := DropObject newFile:('.'). |
|
211 |
||
212 |
addButton := [:offset :label :dispObj| |button| |
|
1166 | 213 |
button := Button label:label in:pannel. |
874 | 214 |
|
1166 | 215 |
button pressAction:[ |
216 |
DragAndDropManager startDrag:dropObj from:button offset:offset display:dispObj. |
|
217 |
button turnOff. |
|
218 |
] |
|
874 | 219 |
]. |
220 |
||
881 | 221 |
addButton value:(0@-5) value:'String' value:'String'. |
874 | 222 |
addButton value:#topLeft value:'String' value:'String'. |
223 |
addButton value:#topRight value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
224 |
addButton value:#bottomLeft value:'Icon' value:icon. |
|
225 |
addButton value:#bottomRight value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
226 |
addButton value:#center value:'Mixed' value:(Array with:'String' with:icon). |
|
227 |
||
228 |
topView label:'Drag & Drop'. |
|
229 |
topView openWithExtent:200@200. |
|
1166 | 230 |
[exEnd] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
231 |
" |
341 | 232 |
! ! |
233 |
||
628 | 234 |
!DragAndDropManager class methodsFor:'initialization'! |
235 |
||
236 |
initialize |
|
237 |
DragOriginatorQuerySignal := QuerySignal new. |
|
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
238 |
DragOffsetQuerySignal := QuerySignal new. |
1487 | 239 |
ActiveDragAndDropManagers := IdentityDictionary new. |
628 | 240 |
|
241 |
" |
|
242 |
self initialize |
|
243 |
" |
|
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
244 |
|
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
245 |
"Modified: 11.8.1997 / 00:54:21 / cg" |
1420 | 246 |
! ! |
247 |
||
248 |
!DragAndDropManager class methodsFor:'instance creation'! |
|
874 | 249 |
|
250 |
new |
|
251 |
^ self basicNew initialize |
|
628 | 252 |
! ! |
253 |
||
254 |
!DragAndDropManager class methodsFor:'Signal constants'! |
|
255 |
||
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
256 |
dragOffsetQuerySignal |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
257 |
^ DragOffsetQuerySignal |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
258 |
|
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
259 |
"Created: 11.8.1997 / 00:54:10 / cg" |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
260 |
! |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
261 |
|
628 | 262 |
dragOriginatorQuerySignal |
263 |
^ DragOriginatorQuerySignal |
|
264 |
! ! |
|
265 |
||
1487 | 266 |
!DragAndDropManager class methodsFor:'helpers'! |
267 |
||
268 |
saveDraw:aBlock device:aDevice |
|
269 |
|activeManager| |
|
270 |
||
271 |
activeManager := ActiveDragAndDropManagers at:aDevice ifAbsent:nil. |
|
272 |
activeManager isNil ifTrue:[ |
|
273 |
aBlock value |
|
274 |
] ifFalse:[ |
|
275 |
activeManager saveDraw:aBlock |
|
276 |
]. |
|
277 |
! ! |
|
278 |
||
279 |
!DragAndDropManager class methodsFor:'queries'! |
|
280 |
||
281 |
isDragAndDropActiveOnDevice:aDevice |
|
282 |
^ ActiveDragAndDropManagers includesKey:aDevice |
|
283 |
! ! |
|
284 |
||
874 | 285 |
!DragAndDropManager class methodsFor:'simple start - drop source'! |
286 |
||
287 |
startDragFrom:aView dropSource:aDropSource |
|
288 |
"start a drop at the current pointer position. |
|
289 |
" |
|
290 |
^ (self new) startDragFrom:aView dropSource:aDropSource |
|
291 |
! ! |
|
292 |
||
293 |
!DragAndDropManager class methodsFor:'simple start - generic'! |
|
294 |
||
295 |
startDrag:draggableObjects from:aView |
|
296 |
"start a drop at the current pointer position |
|
297 |
" |
|
298 |
^ self startDrag:draggableObjects |
|
1166 | 299 |
from:aView |
300 |
offset:0@0 |
|
301 |
atEnd:nil |
|
302 |
display:draggableObjects |
|
874 | 303 |
|
304 |
" |
|
305 |
EXAMPLE: |
|
306 |
||
307 |
|button| |
|
308 |
||
309 |
button := (Button label:'press me'). |
|
310 |
||
311 |
button pressAction:[ |
|
1166 | 312 |
DragAndDropManager startDrag:(DropObject newFile:('.')) from:button. |
313 |
button turnOff |
|
874 | 314 |
]. |
315 |
||
316 |
button openAt:100@100 |
|
317 |
" |
|
318 |
! |
|
319 |
||
320 |
startDrag:draggableObjects from:aView atEnd:aFourArgEndBlock |
|
321 |
"start a drop at the current pointer position |
|
322 |
When finished, the endAction is called with four args: |
|
323 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
324 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
325 |
" |
|
326 |
^ self startDrag:draggableObjects |
|
1166 | 327 |
from:aView |
328 |
offset:0@0 |
|
329 |
atEnd:aFourArgEndBlock |
|
330 |
display:draggableObjects |
|
874 | 331 |
|
332 |
" |
|
333 |
EXAMPLE: |
|
334 |
||
335 |
|button| |
|
336 |
||
337 |
button := (Button label:'press me'). |
|
338 |
||
339 |
button pressAction:[ |
|
1166 | 340 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
341 |
from:button |
|
342 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
343 |
Transcript showCR:'target view: ', targetView printString. |
|
344 |
Transcript showCR:'target id: ', targetViewId printString. |
|
345 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
346 |
Transcript showCR:'point target: ', targetPoint printString. |
|
347 |
]. |
|
348 |
button turnOff |
|
874 | 349 |
]. |
350 |
||
351 |
button openAt:100@100 |
|
352 |
" |
|
353 |
||
354 |
! |
|
355 |
||
356 |
startDrag:draggableObjects from:aView atEnd:aFourArgEndBlock display:something |
|
357 |
"start a drop at the current pointer position |
|
358 |
When finished, the endAction is called with four args: |
|
359 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
360 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
361 |
" |
|
362 |
^ self startDrag:draggableObjects |
|
1166 | 363 |
from:aView |
364 |
offset:0@0 |
|
365 |
atEnd:aFourArgEndBlock |
|
366 |
display:something |
|
874 | 367 |
|
368 |
" |
|
369 |
EXAMPLE: |
|
370 |
||
371 |
|button| |
|
372 |
||
373 |
button := (Button label:'press me'). |
|
374 |
||
375 |
button pressAction:[ |
|
1166 | 376 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
377 |
from:button |
|
378 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
379 |
Transcript showCR:'target view: ', targetView printString. |
|
380 |
Transcript showCR:'target id: ', targetViewId printString. |
|
381 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
382 |
Transcript showCR:'point target: ', targetPoint printString. |
|
383 |
] |
|
384 |
display:(Array with:'String' with:(Image fromFile:('xpmBitmaps/QUESTION3.xpm'))). |
|
385 |
button turnOff |
|
874 | 386 |
]. |
387 |
||
388 |
button openAt:100@100 |
|
389 |
" |
|
390 |
! |
|
391 |
||
392 |
startDrag:draggableObjects from:aView display:something |
|
393 |
"start a drop at the current pointer position |
|
394 |
" |
|
395 |
^ self startDrag:draggableObjects |
|
1166 | 396 |
from:aView |
397 |
offset:0@0 |
|
398 |
atEnd:nil |
|
399 |
display:something |
|
874 | 400 |
|
401 |
" |
|
402 |
EXAMPLE: |
|
403 |
||
404 |
|dropObj topView pannel icon buttonAction addButton| |
|
405 |
||
406 |
topView := StandardSystemView new. |
|
407 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
408 |
pannel horizontalLayout:#fit. |
|
409 |
pannel verticalLayout:#fitSpace. |
|
410 |
||
411 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
412 |
dropObj := DropObject newFile:('.'). |
|
413 |
||
414 |
addButton := [:label :dispObj| |button| |
|
1166 | 415 |
button := Button label:label in:pannel. |
874 | 416 |
|
1166 | 417 |
button pressAction:[ |
418 |
DragAndDropManager startDrag:dropObj from:button display:dispObj. |
|
419 |
button turnOff. |
|
420 |
] |
|
874 | 421 |
]. |
422 |
||
423 |
addButton value:'String' value:'String'. |
|
424 |
addButton value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
425 |
addButton value:'Icon' value:icon. |
|
426 |
addButton value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
427 |
addButton value:'Mixed' value:(Array with:'String' with:icon). |
|
428 |
||
429 |
topView label:'Drag & Drop'. |
|
430 |
topView openWithExtent:200@200. |
|
431 |
" |
|
432 |
! |
|
433 |
||
434 |
startDrag:draggableObjects from:aView offset:anOffset |
|
435 |
"start a drop at the current pointer position |
|
436 |
" |
|
437 |
^ self startDrag:draggableObjects |
|
1166 | 438 |
from:aView |
439 |
offset:anOffset |
|
440 |
atEnd:nil |
|
441 |
display:draggableObjects |
|
874 | 442 |
|
443 |
" |
|
444 |
EXAMPLE: |
|
445 |
||
446 |
|button| |
|
447 |
||
448 |
button := (Button label:'press me'). |
|
449 |
||
450 |
button pressAction:[ |
|
1166 | 451 |
DragAndDropManager startDrag:(DropObject newFile:('.')) from:button offset:(-10 @ -10). |
452 |
button turnOff |
|
874 | 453 |
]. |
454 |
||
455 |
button openAt:100@100 |
|
456 |
" |
|
457 |
||
458 |
! |
|
459 |
||
460 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock |
|
461 |
"start a drop at the current pointer position |
|
462 |
When finished, the endAction is called with four args: |
|
463 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
464 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
465 |
" |
|
466 |
^ self startDrag:draggableObjects |
|
1166 | 467 |
from:aView |
468 |
offset:anOffset |
|
469 |
atEnd:aFourArgEndBlock |
|
470 |
display:draggableObjects |
|
874 | 471 |
|
472 |
" |
|
473 |
EXAMPLE: |
|
474 |
||
475 |
|button| |
|
476 |
||
477 |
button := (Button label:'press me'). |
|
478 |
||
479 |
button pressAction:[ |
|
1166 | 480 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
481 |
from:button |
|
482 |
offset:(-10 @ -10) |
|
483 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
484 |
Transcript showCR:'target view: ', targetView printString. |
|
485 |
Transcript showCR:'target id: ', targetViewId printString. |
|
486 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
487 |
Transcript showCR:'point target: ', targetPoint printString. |
|
488 |
]. |
|
489 |
button turnOff |
|
874 | 490 |
]. |
491 |
||
492 |
button openAt:100@100 |
|
493 |
" |
|
494 |
||
495 |
! |
|
496 |
||
497 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock display:something |
|
498 |
"start a drop at the current pointer position |
|
499 |
When finished, the endAction is called with four args: |
|
500 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
501 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
502 |
" |
|
503 |
|manager| |
|
504 |
||
505 |
manager := self new. |
|
506 |
||
507 |
manager startDrag:draggableObjects |
|
1166 | 508 |
from:aView |
509 |
offset:anOffset |
|
510 |
atEnd:aFourArgEndBlock |
|
511 |
display:something. |
|
874 | 512 |
|
513 |
^ manager |
|
514 |
||
515 |
" |
|
516 |
EXAMPLE: |
|
517 |
||
518 |
|button| |
|
519 |
||
520 |
button := (Button label:'press me'). |
|
521 |
||
522 |
button pressAction:[ |
|
1166 | 523 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
524 |
from:button |
|
525 |
offset:(-10 @ -10) |
|
526 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
527 |
Transcript showCR:'target view: ', targetView printString. |
|
528 |
Transcript showCR:'target id: ', targetViewId printString. |
|
529 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
530 |
Transcript showCR:'point target: ', targetPoint printString. |
|
531 |
] |
|
532 |
display:(Array with:'String' with:(Image fromFile:('xpmBitmaps/QUESTION3.xpm'))). |
|
533 |
button turnOff |
|
874 | 534 |
]. |
535 |
||
536 |
button openAt:100@100 |
|
537 |
" |
|
538 |
||
539 |
! |
|
540 |
||
541 |
startDrag:draggableObjects from:aView offset:anOffset display:something |
|
542 |
"start a drop at the current pointer position |
|
543 |
" |
|
544 |
^ self startDrag:draggableObjects |
|
1166 | 545 |
from:aView |
546 |
offset:anOffset |
|
547 |
atEnd:nil |
|
548 |
display:something |
|
874 | 549 |
|
550 |
" |
|
551 |
EXAMPLE: |
|
552 |
||
553 |
|dropObj topView pannel icon buttonAction addButton| |
|
554 |
||
555 |
topView := StandardSystemView new. |
|
556 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
557 |
pannel horizontalLayout:#fit. |
|
558 |
pannel verticalLayout:#fitSpace. |
|
559 |
||
560 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
561 |
dropObj := DropObject newFile:('.'). |
|
562 |
||
563 |
addButton := [:offset :label :dispObj| |button| |
|
1166 | 564 |
button := Button label:label in:pannel. |
874 | 565 |
|
1166 | 566 |
button pressAction:[ |
567 |
DragAndDropManager startDrag:dropObj from:button offset:offset display:dispObj. |
|
568 |
button turnOff. |
|
569 |
] |
|
874 | 570 |
]. |
571 |
||
572 |
addButton value:#topLeft value:'String' value:'String'. |
|
573 |
addButton value:#topRight value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
574 |
addButton value:#bottomLeft value:'Icon' value:icon. |
|
575 |
addButton value:#bottomRight value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
576 |
addButton value:#center value:'Mixed' value:(Array with:'String' with:icon). |
|
577 |
||
578 |
topView label:'Drag & Drop'. |
|
579 |
topView openWithExtent:200@200. |
|
580 |
" |
|
581 |
||
582 |
! ! |
|
583 |
||
584 |
!DragAndDropManager class methodsFor:'simple start - lines'! |
|
397 | 585 |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
586 |
startArrowDragIn:aView at:dragPoint atEnd:aFourArgBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
587 |
"start a rubber-arrow-line dragging in aView at dragPoint. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
588 |
When finished, evaluate the fourArgBlock with targetView, |
874 | 589 |
targetID, screenPosition and targetViewPosition as arguments |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
590 |
" |
874 | 591 |
^ self new startArrowDragIn:aView at:dragPoint atEnd:aFourArgBlock |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
592 |
|
874 | 593 |
" |
594 |
EXAMPLE: |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
595 |
|
874 | 596 |
|button| |
397 | 597 |
|
874 | 598 |
button := (Button label:'press me'). |
861 | 599 |
|
874 | 600 |
button pressAction:[ |
1166 | 601 |
button turnOff. |
861 | 602 |
|
1166 | 603 |
DragAndDropManager startArrowDragIn:button |
604 |
at:(button preferredExtent // 2) |
|
605 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
606 |
targetView isNil ifTrue:[ |
|
607 |
Transcript show:'alien view' |
|
608 |
] ifFalse:[ |
|
609 |
Transcript showCR:'target: ', targetView printString |
|
610 |
]. |
|
611 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
612 |
Transcript showCR:'point target: ', targetPoint printString. |
|
613 |
] |
|
874 | 614 |
]. |
615 |
button openAt:100@100 |
|
616 |
" |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
617 |
! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
618 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
619 |
startLineDragIn:aView at:dragPoint atEnd:aFourArgBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
620 |
"start a rubber-line dragging in aView at dragPoint. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
621 |
When finished, evaluate the fourArgBlock with targetView, |
874 | 622 |
targetID, screenPosition and targetViewPosition as arguments |
623 |
" |
|
624 |
^ self new startLineDragIn:aView at:dragPoint atEnd:aFourArgBlock |
|
625 |
||
626 |
" |
|
627 |
EXAMPLE: |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
628 |
|
874 | 629 |
|button| |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
630 |
|
874 | 631 |
button := (Button label:'press me'). |
632 |
||
633 |
button pressAction:[ |
|
1166 | 634 |
button turnOff. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
635 |
|
1166 | 636 |
DragAndDropManager startLineDragIn:button |
637 |
at:(button preferredExtent // 2) |
|
638 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
639 |
targetView isNil ifTrue:[ |
|
640 |
Transcript show:'alien view' |
|
641 |
] ifFalse:[ |
|
642 |
Transcript showCR:'target: ', targetView printString |
|
643 |
]. |
|
644 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
645 |
Transcript showCR:'point target: ', targetPoint printString. |
|
646 |
] |
|
874 | 647 |
]. |
648 |
button openAt:100@100 |
|
649 |
" |
|
397 | 650 |
! ! |
651 |
||
394 | 652 |
!DragAndDropManager methodsFor:'accessing'! |
653 |
||
861 | 654 |
device |
655 |
"returns the device of the source view |
|
656 |
" |
|
657 |
^ dragView device |
|
658 |
||
659 |
||
660 |
! |
|
661 |
||
874 | 662 |
dropContext |
663 |
"return the current context |
|
664 |
" |
|
665 |
^ dropContext |
|
666 |
! |
|
667 |
||
397 | 668 |
dropObjects |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
669 |
"return the current dropObject collection" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
670 |
|
874 | 671 |
^ dropContext dropObjects |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
672 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
673 |
"Modified: 19.4.1997 / 10:19:06 / cg" |
397 | 674 |
! |
675 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
676 |
dropObjects:aCollectionOfDropObjects |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
677 |
"set the current dropObject collection" |
397 | 678 |
|
874 | 679 |
^ dropContext dropObjects:aCollectionOfDropObjects |
861 | 680 |
! |
681 |
||
682 |
font |
|
683 |
"returns the font of the source view |
|
684 |
" |
|
685 |
^ dragView font |
|
686 |
||
687 |
||
874 | 688 |
! |
689 |
||
690 |
sourceWidget |
|
691 |
^ dragView |
|
692 |
! ! |
|
693 |
||
1397 | 694 |
!DragAndDropManager methodsFor:'accessing-cursor'! |
874 | 695 |
|
696 |
alienCursor:aCursorOrImage |
|
697 |
"set the cursor used for an alien widget; not an ST/X view |
|
698 |
" |
|
699 |
aCursorOrImage isImage ifTrue:[ |
|
1166 | 700 |
alienCursor := Cursor fromImage:aCursorOrImage |
874 | 701 |
] ifFalse:[ |
1166 | 702 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
703 |
alienCursor := aCursorOrImage |
|
704 |
] ifFalse:[ |
|
705 |
"/ |
|
706 |
"/ use disabled cursor |
|
707 |
"/ |
|
708 |
alienCursor := nil |
|
709 |
] |
|
874 | 710 |
] |
711 |
! |
|
712 |
||
713 |
disabledCursor:aCursorOrImage |
|
714 |
"set the cursor for an ST/X view, which can not drop the objects |
|
715 |
" |
|
716 |
aCursorOrImage isImage ifTrue:[ |
|
1166 | 717 |
disabledCursor := Cursor fromImage:aCursorOrImage |
874 | 718 |
] ifFalse:[ |
1166 | 719 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
720 |
disabledCursor := aCursorOrImage |
|
721 |
] |
|
874 | 722 |
] |
723 |
! |
|
724 |
||
725 |
enabledCursor:aCursorOrImage |
|
726 |
"set the cursor for an ST/X view, which can drop the objects |
|
727 |
" |
|
728 |
aCursorOrImage isImage ifTrue:[ |
|
1166 | 729 |
enabledCursor := Cursor fromImage:aCursorOrImage |
874 | 730 |
] ifFalse:[ |
1166 | 731 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
732 |
enabledCursor := aCursorOrImage |
|
733 |
] |
|
874 | 734 |
] |
735 |
||
736 |
! ! |
|
737 |
||
738 |
!DragAndDropManager methodsFor:'dragging - drop source'! |
|
739 |
||
740 |
startDragFrom:aView dropSource:aDropSource |
|
741 |
"start a drop at the current pointer position. |
|
742 |
" |
|
743 |
^ self startDragFrom:aView dropSource:aDropSource offset:#topLeft "/ #center |
|
744 |
! |
|
745 |
||
746 |
startDragFrom:aView dropSource:aDropSource offset:anOffset |
|
747 |
"start a drop at the current pointer position. |
|
748 |
" |
|
749 |
dropContext dropSource:aDropSource. |
|
750 |
||
751 |
^ self startDrag:(aDropSource dropObjects) |
|
1166 | 752 |
from:aView |
753 |
offset:anOffset |
|
754 |
atEnd:nil |
|
755 |
display:(aDropSource displayObjects) |
|
874 | 756 |
! ! |
757 |
||
758 |
!DragAndDropManager methodsFor:'dragging - easy startup'! |
|
759 |
||
760 |
startDrag:draggableObjects from:aView |
|
761 |
"start a drop at the current pointer position |
|
762 |
" |
|
763 |
^ self startDrag:draggableObjects |
|
1166 | 764 |
from:aView |
765 |
offset:0@0 |
|
874 | 766 |
! |
767 |
||
768 |
startDrag:draggableObjects from:aView display:something |
|
769 |
"start a drop at the current pointer position. |
|
770 |
" |
|
771 |
^ self startDrag:draggableObjects |
|
1166 | 772 |
from:aView |
773 |
offset:nil |
|
774 |
atEnd:nil |
|
775 |
display:something |
|
874 | 776 |
! |
777 |
||
778 |
startDrag:draggableObjects from:aView offset:anOffset |
|
779 |
"start a drop at the current pointer position with an offset |
|
780 |
" |
|
781 |
^ self startDrag:draggableObjects |
|
1166 | 782 |
from:aView |
783 |
offset:anOffset |
|
784 |
atEnd:nil |
|
874 | 785 |
! |
786 |
||
787 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock |
|
788 |
"start a drop at the current pointer position. |
|
789 |
When finished, the endAction is called with four args: |
|
790 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
791 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
792 |
" |
|
793 |
^ self startDrag:draggableObjects |
|
1166 | 794 |
from:aView |
795 |
offset:anOffset |
|
796 |
atEnd:aFourArgEndBlock |
|
797 |
display:draggableObjects |
|
874 | 798 |
! |
799 |
||
800 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgBlock display:something |
|
801 |
"start a drop at the current pointer position. |
|
802 |
When finished, the endAction is called with four args: |
|
803 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
804 |
the dropPoint in root-coordinates and the dropPoint within the targetView. |
|
805 |
" |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
806 |
|height width fontWdt offset ascent device dispObjs list space| |
874 | 807 |
|
808 |
self dropObjects:draggableObjects. |
|
809 |
||
810 |
self dropObjects size == 0 ifTrue:[ |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
811 |
^ self |
874 | 812 |
]. |
813 |
||
814 |
device := aView device. |
|
815 |
space := 1. |
|
816 |
height := space negated. |
|
817 |
width := 0. |
|
818 |
fontWdt := aView font width. |
|
819 |
ascent := aView font ascent. |
|
820 |
||
821 |
(list := something) isNil ifTrue:[ |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
822 |
list := self dropObjects |
874 | 823 |
] ifFalse:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
824 |
(list isCollection not or:[list isString]) ifTrue:[ |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
825 |
list := Array with:something |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
826 |
] |
874 | 827 |
]. |
828 |
dispObjs := OrderedCollection new. |
|
829 |
||
830 |
list do:[:el| |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
831 |
|obj asc| |
874 | 832 |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
833 |
obj := self displayObjectFor:el on:device. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
834 |
asc := (obj respondsTo:#string) ifTrue:[ascent] ifFalse:[0]. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
835 |
height := height + space. |
874 | 836 |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
837 |
dispObjs add:(Array with:obj with:(0 @ (height + asc))). |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
838 |
width := width max:(obj widthOn:aView). |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
839 |
height := height + (obj heightOn:aView). |
874 | 840 |
]. |
841 |
||
881 | 842 |
anOffset isSymbol ifTrue:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
843 |
offset := (0@0 extent:(width @ height)) perform:anOffset. |
881 | 844 |
] ifFalse:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
845 |
offset := anOffset ? (0@0). |
881 | 846 |
]. |
847 |
offset := offset rounded. |
|
874 | 848 |
|
849 |
dispObjs do:[:el| el at:2 put:((el at:2) - offset) ]. |
|
850 |
||
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
851 |
self startOpaqueDrag:[:p :v| |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
852 |
|cursor hX hY pDraw| |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
853 |
|
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
854 |
cursor := dragView cursor. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
855 |
hX := cursor hotX. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
856 |
hY := cursor hotY. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
857 |
pDraw := p - (hX@hY) + cursor extent. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
858 |
dispObjs do:[:el| (el at:1) displayOn:v |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
859 |
at:pDraw + (el at:2) |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
860 |
] |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
861 |
] |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
862 |
offset:offset |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
863 |
extent:width @ height |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
864 |
in:aView |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
865 |
at:nil |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
866 |
atEnd:aFourArgBlock |
881 | 867 |
|
868 |
"Modified: / 31.3.1998 / 11:18:04 / cg" |
|
874 | 869 |
! |
870 |
||
871 |
startDrag:draggableObjects from:aView offset:anOffset display:something |
|
872 |
"start a drop at the current pointer position. |
|
873 |
" |
|
874 |
^ self startDrag:draggableObjects |
|
1166 | 875 |
from:aView |
876 |
offset:anOffset |
|
877 |
atEnd:nil |
|
878 |
display:something |
|
394 | 879 |
! ! |
880 |
||
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
881 |
!DragAndDropManager methodsFor:'dragging - generic'! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
882 |
|
348 | 883 |
startGenericDrag:aTwoArgDragBlock in:aView at:p atEnd:aFourArgEndBlock |
884 |
"start a generic (caller-provided drag); |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
885 |
Here, an inverting drag is initiated (i.e. the drawing is undone |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
886 |
by inverting again). See startOpaqueDrag for another variant. |
348 | 887 |
the dragBlock, aTwoArgDragBlock will be called with two args |
888 |
aPoint and a drawingGC, to perform the drawing at some dragPoint. |
|
889 |
The drag starts in aView at point p. |
|
890 |
When finished, the endAction is called with four args: |
|
891 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
874 | 892 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
893 |
" |
|
894 |
^ self startOpaqueDrag:aTwoArgDragBlock |
|
1166 | 895 |
offset:nil |
896 |
extent:nil |
|
897 |
in:aView |
|
898 |
at:nil |
|
899 |
atEnd:aFourArgEndBlock |
|
394 | 900 |
! |
901 |
||
874 | 902 |
startOpaqueDrag:aDragBlock offset:offs extent:anExtent in:aView at:aDummyPoint atEnd:aFourArgEndBlock |
903 |
"start an opaque or generic opaque (caller-provided drag); |
|
394 | 904 |
opaque drag means, that the drawing cannot be undone by two inverting |
905 |
draws, but instead, the area under the dragged object must be saved |
|
874 | 906 |
and restored. The areas size to be saved/restored is passed in anExtent. |
907 |
the dragBlock, aDragBlock will be called with up to three args aPoint, a |
|
908 |
drawingGC and the display objects, to perform the drawing at some dragPoint. |
|
394 | 909 |
The drag starts in aView at point p. |
910 |
When finished, the endAction is called with four args: |
|
911 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
874 | 912 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
913 |
" |
|
914 |
|handler numArgs dragBlock dobjs| |
|
394 | 915 |
|
874 | 916 |
dragOffset := offs ? (Point x:0 y:0). |
917 |
numArgs := aDragBlock numArgs. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
918 |
|
874 | 919 |
numArgs == 3 ifTrue:[ |
1289 | 920 |
dobjs := self dropObjects. |
921 |
dragBlock := [:p :v| aDragBlock value:p value:v value:dobjs ] |
|
874 | 922 |
] ifFalse:[ |
1289 | 923 |
numArgs == 1 ifTrue:[ |
924 |
dragBlock := [:p :v| aDragBlock value:p ] |
|
925 |
] ifFalse:[ |
|
926 |
dragBlock := aDragBlock |
|
927 |
] |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
928 |
]. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
929 |
|
874 | 930 |
anExtent isNil ifTrue:[ |
1289 | 931 |
handler := DragHandler startGenericDrag:dragBlock. |
874 | 932 |
] ifFalse:[ |
1289 | 933 |
handler := DragHandler startOpaqueDrag:dragBlock extent:anExtent offset:dragOffset. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
934 |
]. |
1289 | 935 |
self doStart:handler for:aView atEnd:aFourArgEndBlock. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
936 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
937 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
938 |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
939 |
!DragAndDropManager methodsFor:'dragging - lines'! |
341 | 940 |
|
874 | 941 |
startArrowDragIn:aView at:aStartPoint atEnd:aFourArgEndBlock |
942 |
"start a line-drag of an arrow-line. |
|
943 |
The drag starts in aView at point aStartPoint. |
|
944 |
When finished, the endAction is called with four args: |
|
945 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
946 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
947 |
" |
|
948 |
|p| |
|
341 | 949 |
|
874 | 950 |
p := self translatePointToScreen:aStartPoint from:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
951 |
|
874 | 952 |
self doStart:(DragHandler startArrowDragAt:p) |
1166 | 953 |
for:aView |
954 |
atEnd:aFourArgEndBlock |
|
341 | 955 |
! |
956 |
||
874 | 957 |
startLineDragIn:aView at:aStartPoint atEnd:aFourArgEndBlock |
958 |
"start a line-drag of a normal line. |
|
959 |
The drag starts in aView at point aStartPoint. |
|
348 | 960 |
When finished, the endAction is called with four args: |
961 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
874 | 962 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
963 |
" |
|
964 |
|p| |
|
341 | 965 |
|
874 | 966 |
p := self translatePointToScreen:aStartPoint from:aView. |
348 | 967 |
|
874 | 968 |
self doStart:(DragHandler startLineDragAt:p) |
1166 | 969 |
for:aView |
970 |
atEnd:aFourArgEndBlock |
|
341 | 971 |
! ! |
972 |
||
397 | 973 |
!DragAndDropManager methodsFor:'drawing'! |
974 |
||
874 | 975 |
displayObjectFor:anObject on:aDevice |
976 |
"converts an object to a display object |
|
977 |
" |
|
978 |
|obj icon s1 s2| |
|
979 |
||
980 |
obj := (anObject respondsTo:#displayObject) ifTrue:[anObject displayObject] |
|
1166 | 981 |
ifFalse:[anObject]. |
874 | 982 |
|
983 |
obj isString ifTrue:[ |
|
1166 | 984 |
^ obj |
874 | 985 |
]. |
986 |
||
987 |
obj messageNotUnderstoodSignal handle:[:ex|] do:[ |
|
1166 | 988 |
obj := obj on:aDevice |
874 | 989 |
]. |
990 |
||
991 |
obj isImage ifTrue:[ |
|
1166 | 992 |
^ obj clearMaskedPixels |
874 | 993 |
]. |
994 |
||
995 |
obj class == LabelAndIcon ifTrue:[ |
|
1166 | 996 |
obj image notNil ifTrue:[obj image clearMaskedPixels]. |
997 |
obj icon notNil ifTrue:[obj icon clearMaskedPixels]. |
|
874 | 998 |
^ obj |
999 |
]. |
|
1000 |
||
1001 |
(obj class == MultiColListEntry) ifFalse:[ |
|
1166 | 1002 |
^ obj |
874 | 1003 |
]. |
1004 |
s1 := obj colAt:1. |
|
1005 |
s2 := obj colAt:2. |
|
1006 |
||
1007 |
s1 isImage ifTrue:[ |
|
1166 | 1008 |
s2 isImage ifTrue:[ ^ self displayObjectFor:(LabelAndIcon form:s1 image:s2) on:aDevice ]. |
1009 |
s2 isString ifTrue:[ ^ self displayObjectFor:(LabelAndIcon icon:s1 string:s2) on:aDevice ]. |
|
1010 |
^ (s1 on:aDevice) clearMaskedPixels |
|
874 | 1011 |
]. |
1012 |
||
1013 |
s2 isImage ifTrue:[ |
|
1166 | 1014 |
s1 isString ifTrue:[ ^ self displayObjectFor:(LabelAndIcon icon:s2 string:s1) on:aDevice ]. |
1015 |
^ (s2 on:aDevice) clearMaskedPixels |
|
874 | 1016 |
]. |
1017 |
||
1018 |
s1 isString ifTrue:[^ s1]. |
|
1019 |
s2 isString ifTrue:[^ s2]. |
|
1020 |
^ obj |
|
1021 |
! |
|
1022 |
||
397 | 1023 |
showDragging:items in:aView at:p |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1024 |
"helper for dragging dragObjects: draw them all" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1025 |
|
397 | 1026 |
|offs| |
1027 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1028 |
offs := 0. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1029 |
items do:[:item | |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1030 |
item displayOn:aView at:p + (0@offs). |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1031 |
offs := offs + (item heightOn:self) |
397 | 1032 |
] |
1033 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1034 |
"Modified: 19.4.1997 / 12:41:24 / cg" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1035 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1036 |
|
341 | 1037 |
!DragAndDropManager methodsFor:'event catching'! |
1038 |
||
1484 | 1039 |
buttonMotion:buttonState x:x y:y view:aView |
874 | 1040 |
"handle a button motion event |
1041 |
" |
|
1466
f6a566b26c9e
Use #viewIdFromPoint: to get the drop target.
Stefan Vogel <sv@exept.de>
parents:
1430
diff
changeset
|
1042 |
|oldPt oldTgt oldWg oldId newWg newId newTgt point cursor device isDroppable| |
874 | 1043 |
|
1044 |
device := dragView device. |
|
1045 |
point := self translatePointToScreen:(x @ y) from:dragView. |
|
1046 |
oldWg := dropContext targetWidget. |
|
1047 |
oldId := dropContext targetId. |
|
1048 |
oldPt := dropContext rootPoint. |
|
1049 |
||
1050 |
dropContext rootPoint:point. |
|
1051 |
||
1466
f6a566b26c9e
Use #viewIdFromPoint: to get the drop target.
Stefan Vogel <sv@exept.de>
parents:
1430
diff
changeset
|
1052 |
newId := device viewIdFromPoint:point. |
874 | 1053 |
newWg := device viewFromId:newId. |
1054 |
dropContext targetWidget:newWg id:newId. |
|
1055 |
||
1056 |
handler isInterestedInDropTarget ifFalse:[ |
|
1289 | 1057 |
"/ |
1058 |
"/ line or arrow handler |
|
1059 |
"/ |
|
1060 |
handler dragTo:point. |
|
1061 |
^ self |
|
874 | 1062 |
]. |
1063 |
||
1064 |
oldWg ~~ newWg ifTrue:[ |
|
1289 | 1065 |
"/ |
1066 |
"/ widget has changed: drop target might change |
|
1067 |
"/ |
|
1068 |
oldTgt := dropContext dropTarget. |
|
1069 |
newTgt := self doFindDropTargetIn:newWg at:point. |
|
874 | 1070 |
|
1289 | 1071 |
newTgt ~= oldTgt ifTrue:[ |
1072 |
"/ |
|
1073 |
"/ drop target changed: handler might restore the screen |
|
1074 |
"/ |
|
1075 |
handler dropTargetWillChange. |
|
341 | 1076 |
|
1289 | 1077 |
oldTgt notNil ifTrue:[ |
1078 |
"/ |
|
1079 |
"/ setup old context |
|
1080 |
"/ |
|
1081 |
dropContext targetWidget:oldWg id:oldId. |
|
1082 |
oldTgt leave:dropContext. |
|
1083 |
dropContext targetWidget:newWg id:newId. |
|
1084 |
]. |
|
1085 |
dropContext dropTarget:newTgt. |
|
1086 |
newTgt notNil ifTrue:[ newTgt enter:dropContext ] |
|
1087 |
] ifFalse:[ |
|
1088 |
dropContext dropTarget:newTgt |
|
1089 |
] |
|
874 | 1090 |
] ifFalse:[ |
1289 | 1091 |
(oldPt notNil and:[(oldPt dist:point) < 2 ]) ifTrue:[ |
1092 |
"/ |
|
1093 |
"/ ignore the button motion event; restore old rootPoint |
|
1094 |
"/ |
|
1095 |
dropContext rootPoint:oldPt. |
|
1096 |
^ self |
|
1097 |
]. |
|
1098 |
newTgt := dropContext dropTarget |
|
874 | 1099 |
]. |
1100 |
"/ |
|
1101 |
"/ update the cursor |
|
1102 |
"/ |
|
1103 |
(isDroppable := dropContext canDrop) ifTrue:[ |
|
1289 | 1104 |
cursor := enabledCursor |
874 | 1105 |
] ifFalse:[ |
1289 | 1106 |
cursor := dropContext isAlienView ifFalse:[disabledCursor] |
1107 |
ifTrue:[alienCursor] |
|
874 | 1108 |
]. |
1109 |
dragView cursor:cursor now:true. |
|
1110 |
"/ |
|
1111 |
"/ test if droppable state changed |
|
1112 |
"/ |
|
1113 |
canDrop == isDroppable ifFalse:[ |
|
1289 | 1114 |
"/ |
1115 |
"/ droppable state changed: handler might restore the screen |
|
1116 |
"/ |
|
1117 |
canDrop := isDroppable. |
|
1118 |
handler dropTargetWillChange |
|
874 | 1119 |
]. |
394 | 1120 |
|
874 | 1121 |
newTgt notNil ifTrue:[ newTgt over:dropContext ]. |
1122 |
handler dragTo:point. |
|
1123 |
! |
|
394 | 1124 |
|
874 | 1125 |
buttonMultiPress:button x:x y:y view:aView |
1126 |
"discard each buttonMultiPress event |
|
1127 |
" |
|
1128 |
! |
|
1129 |
||
1130 |
buttonPress:button x:x y:y view:aView |
|
1131 |
"discard each buttonPress event |
|
1132 |
" |
|
341 | 1133 |
! |
1134 |
||
1135 |
buttonRelease:button x:x y:y view:aView |
|
874 | 1136 |
"button released; do the drop |
1137 |
" |
|
1138 |
((button == 2) or:[button == #menu]) ifTrue:[ |
|
1166 | 1139 |
^ self |
874 | 1140 |
]. |
1141 |
"/ |
|
1142 |
"/ update the context |
|
1143 |
"/ |
|
1144 |
self buttonMotion:button x:x y:y view:aView. |
|
1145 |
||
1146 |
"/ |
|
1147 |
"/ restore source view |
|
1148 |
"/ |
|
1149 |
restoreBlock value. |
|
394 | 1150 |
|
874 | 1151 |
"/ |
1152 |
"/ at least do the drop operation |
|
1153 |
"/ |
|
1154 |
dropAction isNil ifTrue:[ |
|
1166 | 1155 |
dropContext doDrop |
874 | 1156 |
] ifFalse:[ |
1166 | 1157 |
"/ |
1158 |
"/ initiator wants to do it himself, manually. |
|
1159 |
"/ Thus, no feedBack operation invoked. |
|
1160 |
"/ |
|
1161 |
dropAction value:(dropContext targetWidget) |
|
1162 |
value:(dropContext targetId) |
|
1163 |
value:(dropContext rootPoint) |
|
1164 |
value:(dropContext targetPoint). |
|
874 | 1165 |
] |
341 | 1166 |
! |
1167 |
||
1289 | 1168 |
delegatesTo:someone |
1169 |
^false |
|
1170 |
! |
|
1171 |
||
341 | 1172 |
handlesButtonMotion:button inView:aView |
1173 |
"query from event processor: am I interested in button-events ? |
|
1174 |
yes I am (to activate the clicked-on field)." |
|
1175 |
||
874 | 1176 |
^ dragView == aView |
1177 |
! |
|
1178 |
||
1179 |
handlesButtonMultiPress:button inView:aView |
|
1180 |
"query from event processor: am I interested in button-events ? |
|
1181 |
yes I am (to activate the clicked-on field)." |
|
341 | 1182 |
|
874 | 1183 |
^ dragView == aView |
1184 |
! |
|
394 | 1185 |
|
874 | 1186 |
handlesButtonPress:button inView:aView |
1187 |
"query from event processor: am I interested in button-events ? |
|
1188 |
yes I am (to activate the clicked-on field)." |
|
1189 |
||
1190 |
^ dragView == aView |
|
341 | 1191 |
! |
1192 |
||
1193 |
handlesButtonRelease:button inView:aView |
|
1194 |
"query from event processor: am I interested in button-events ? |
|
1195 |
yes I am (to activate the clicked-on field)." |
|
1196 |
||
874 | 1197 |
^ dragView == aView |
1198 |
! ! |
|
1199 |
||
1200 |
!DragAndDropManager methodsFor:'initialization'! |
|
341 | 1201 |
|
874 | 1202 |
initialize |
1203 |
super initialize. |
|
394 | 1204 |
|
874 | 1205 |
dragOffset := 0 @ 0. |
1206 |
dropContext := DropContext new. |
|
1207 |
alienCursor := Cursor questionMark. |
|
1208 |
enabledCursor := Cursor thumbsUp. |
|
1209 |
disabledCursor := Cursor thumbsDown. |
|
1210 |
canDrop := false. |
|
341 | 1211 |
! ! |
1212 |
||
1213 |
!DragAndDropManager methodsFor:'private'! |
|
1214 |
||
874 | 1215 |
doDrop:aContext in:aWidget |
1216 |
"old drop mechanism |
|
1217 |
" |
|
1218 |
|point| |
|
628 | 1219 |
|
1220 |
DragOriginatorQuerySignal answer:dragView do:[ |
|
1166 | 1221 |
DragOffsetQuerySignal answer:dragOffset do:[ |
1222 |
aContext targetWidget == aWidget ifTrue:[ |
|
1223 |
point := aContext targetPoint |
|
1224 |
] ifFalse:[ |
|
1225 |
point := 0@0. "/ nil. |
|
1226 |
"/ |
|
1227 |
"/ FeedBack: set the widget which handles the drop |
|
1228 |
"/ |
|
1229 |
aContext targetWidget:aWidget id:(aWidget id). |
|
1230 |
]. |
|
1231 |
aWidget drop:(aContext dropObjects) at:point |
|
1232 |
] |
|
609
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1233 |
]. |
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1234 |
|
1072
be90bc383d83
do not pas nil point to dropDestination
Claus Gittinger <cg@exept.de>
parents:
881
diff
changeset
|
1235 |
"Modified: / 11.9.1998 / 00:53:22 / cg" |
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
1236 |
! |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
1237 |
|
874 | 1238 |
doFindDropTargetIn:aView at:aPoint |
1239 |
"get the drop target for a view and source at a point or nil |
|
411 | 1240 |
" |
874 | 1241 |
|target view dobj| |
628 | 1242 |
|
874 | 1243 |
aView isNil ifTrue:[ ^ nil ]. |
1244 |
"/ |
|
1245 |
"/ new mechanism to get a dropTarget |
|
1246 |
"/ |
|
1247 |
aView messageNotUnderstoodSignal handle:[:ex| |
|
1166 | 1248 |
target := nil. |
874 | 1249 |
] do:[ |
1166 | 1250 |
target := aView dropTarget |
874 | 1251 |
]. |
1252 |
target notNil ifTrue:[ ^ target ]. |
|
1253 |
"/ |
|
1254 |
"/ old mechanism to get a dropTarget |
|
1255 |
"/ |
|
1256 |
view := aView. |
|
1257 |
dobj := dropContext dropObjects. |
|
628 | 1258 |
|
874 | 1259 |
DragOriginatorQuerySignal answer:dragView do:[ |
1166 | 1260 |
DragOffsetQuerySignal answer:dragOffset do:[ |
1261 |
[ (view canDrop:dobj) ifTrue:[ |
|
1262 |
^ DropTarget receiver:self argument:view dropSelector:#doDrop:in:. |
|
1263 |
]. |
|
1264 |
(view := view superView) notNil |
|
628 | 1265 |
|
1166 | 1266 |
] whileTrue. |
1267 |
] |
|
874 | 1268 |
]. |
1269 |
^ nil |
|
1270 |
! |
|
628 | 1271 |
|
874 | 1272 |
doStart:aHandler for:aView atEnd:aFourArgEndBlock |
1273 |
"setup a handler and a restore block |
|
628 | 1274 |
" |
1289 | 1275 |
|savedCursor savedDelegate prevGrab sensor p| |
628 | 1276 |
|
1487 | 1277 |
(ActiveDragAndDropManagers at:aView device ifAbsent:nil) notNil ifTrue:[ |
1278 |
self error:'oops - two dnd managers active'. |
|
1279 |
^ self. |
|
1280 |
]. |
|
1281 |
ActiveDragAndDropManagers at:aView device put:self. |
|
1282 |
||
874 | 1283 |
dropContext sourceWidget:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1284 |
|
874 | 1285 |
dragOffset isNil ifTrue:[ dragOffset := 0 @ 0 ]. |
1286 |
alienCursor isNil ifTrue:[ alienCursor := disabledCursor ]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1287 |
|
874 | 1288 |
dragView := aView. |
1289 |
dropAction := aFourArgEndBlock. |
|
1289 | 1290 |
savedCursor := aView cursor. |
1291 |
savedDelegate := aView delegate. |
|
874 | 1292 |
handler := aHandler. |
609
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1293 |
|
1162
0539b64679ce
set DragHandler in the DropContext
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1294 |
dropContext dragHandler:aHandler. |
0539b64679ce
set DragHandler in the DropContext
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1295 |
|
874 | 1296 |
restoreBlock := [ |
1487 | 1297 |
ActiveDragAndDropManagers removeKey:aView device. |
1289 | 1298 |
aHandler postDragging. |
1299 |
aView delegate:savedDelegate. |
|
1300 |
aView cursor:savedCursor now:true. |
|
1301 |
prevGrab notNil ifTrue:[ |
|
1302 |
aView forceUngrabPointer. |
|
1303 |
prevGrab grabPointer. |
|
1304 |
] ifFalse:[ |
|
1305 |
aView ungrabPointer. |
|
1306 |
]. |
|
874 | 1307 |
]. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1308 |
|
874 | 1309 |
aHandler preDraggingIn:aView. |
1310 |
aView delegate:self. |
|
1289 | 1311 |
prevGrab := aView device activePointerGrab. |
1312 |
aView grabPointer. |
|
1313 |
||
1314 |
"/ must wait for all pending motion events to arrive, and ignore them |
|
1315 |
(sensor := aView sensor) notNil ifTrue:[ |
|
1316 |
aView device sync. |
|
1317 |
sensor flushMotionEventsFor:nil. |
|
1318 |
]. |
|
1319 |
||
1320 |
"/ start with a first draw at the current mouse position |
|
1321 |
p := aView device pointerPosition. |
|
1430
572d486a52b8
use rootWindowId (save a message send)
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
1322 |
p := aView device translatePoint:p from:(aView device rootWindowId) to:(aView id). |
1289 | 1323 |
self buttonMotion:1 x:p x y:p y view:aView |
1487 | 1324 |
! |
1325 |
||
1326 |
saveDraw:aBlock |
|
1327 |
handler postDragging. |
|
1328 |
aBlock value. |
|
1329 |
handler rereadSaveArea. |
|
1330 |
handler restoreFromSaveArea. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1331 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1332 |
|
874 | 1333 |
!DragAndDropManager methodsFor:'translation'! |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1334 |
|
874 | 1335 |
translatePointToScreen:aPoint from:aView |
1336 |
"translate a point to screen |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1337 |
" |
874 | 1338 |
|device trans point offset| |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1339 |
|
874 | 1340 |
device := aView device. |
1341 |
"/ |
|
1342 |
"/ get device coordinates |
|
1343 |
"/ |
|
1344 |
(trans := aView transformation) notNil ifTrue:[ |
|
1430
572d486a52b8
use rootWindowId (save a message send)
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
1345 |
point := trans applyTo:aPoint |
874 | 1346 |
] ifFalse:[ |
1430
572d486a52b8
use rootWindowId (save a message send)
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
1347 |
point := aPoint |
874 | 1348 |
]. |
1349 |
"/ |
|
1350 |
"/ translate to screen |
|
1351 |
"/ |
|
1430
572d486a52b8
use rootWindowId (save a message send)
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
1352 |
offset := device translatePoint:0@0 from:(aView id) to:(device rootWindowId). |
874 | 1353 |
^ offset + point |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1354 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1355 |
|
341 | 1356 |
!DragAndDropManager class methodsFor:'documentation'! |
1357 |
||
1358 |
version |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1359 |
^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.31 2001-08-15 12:52:20 cg Exp $' |
341 | 1360 |
! ! |
628 | 1361 |
DragAndDropManager initialize! |