author | ca |
Fri, 04 Oct 2002 07:26:48 +0200 | |
changeset 1629 | 9b0f45e63e24 |
parent 1619 | 545b8fcc868e |
child 1638 | 67a340f6249f |
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 |
1619 | 18 |
alienCursor enabledCursor disabledCursor canDrop escapePressed' |
1511 | 19 |
classVariableNames:'DragContextQuerySignal DragOriginatorQuerySignal |
20 |
DragOffsetQuerySignal 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. |
1511 | 239 |
DragContextQuerySignal := QuerySignal new. |
1487 | 240 |
ActiveDragAndDropManagers := IdentityDictionary new. |
628 | 241 |
|
242 |
" |
|
243 |
self initialize |
|
244 |
" |
|
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
245 |
|
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
246 |
"Modified: 11.8.1997 / 00:54:21 / cg" |
1420 | 247 |
! ! |
248 |
||
249 |
!DragAndDropManager class methodsFor:'instance creation'! |
|
874 | 250 |
|
251 |
new |
|
252 |
^ self basicNew initialize |
|
628 | 253 |
! ! |
254 |
||
255 |
!DragAndDropManager class methodsFor:'Signal constants'! |
|
256 |
||
1511 | 257 |
dragContextQuerySignal |
258 |
^ DragContextQuerySignal |
|
259 |
! |
|
260 |
||
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
261 |
dragOffsetQuerySignal |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
262 |
^ DragOffsetQuerySignal |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
263 |
|
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
264 |
"Created: 11.8.1997 / 00:54:10 / cg" |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
265 |
! |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
266 |
|
628 | 267 |
dragOriginatorQuerySignal |
268 |
^ DragOriginatorQuerySignal |
|
269 |
! ! |
|
270 |
||
1487 | 271 |
!DragAndDropManager class methodsFor:'helpers'! |
272 |
||
273 |
saveDraw:aBlock device:aDevice |
|
274 |
|activeManager| |
|
275 |
||
276 |
activeManager := ActiveDragAndDropManagers at:aDevice ifAbsent:nil. |
|
277 |
activeManager isNil ifTrue:[ |
|
278 |
aBlock value |
|
279 |
] ifFalse:[ |
|
280 |
activeManager saveDraw:aBlock |
|
281 |
]. |
|
282 |
! ! |
|
283 |
||
284 |
!DragAndDropManager class methodsFor:'queries'! |
|
285 |
||
286 |
isDragAndDropActiveOnDevice:aDevice |
|
287 |
^ ActiveDragAndDropManagers includesKey:aDevice |
|
288 |
! ! |
|
289 |
||
874 | 290 |
!DragAndDropManager class methodsFor:'simple start - drop source'! |
291 |
||
292 |
startDragFrom:aView dropSource:aDropSource |
|
293 |
"start a drop at the current pointer position. |
|
294 |
" |
|
295 |
^ (self new) startDragFrom:aView dropSource:aDropSource |
|
296 |
! ! |
|
297 |
||
298 |
!DragAndDropManager class methodsFor:'simple start - generic'! |
|
299 |
||
300 |
startDrag:draggableObjects from:aView |
|
301 |
"start a drop at the current pointer position |
|
302 |
" |
|
303 |
^ self startDrag:draggableObjects |
|
1166 | 304 |
from:aView |
305 |
offset:0@0 |
|
306 |
atEnd:nil |
|
307 |
display:draggableObjects |
|
874 | 308 |
|
309 |
" |
|
310 |
EXAMPLE: |
|
311 |
||
312 |
|button| |
|
313 |
||
314 |
button := (Button label:'press me'). |
|
315 |
||
316 |
button pressAction:[ |
|
1166 | 317 |
DragAndDropManager startDrag:(DropObject newFile:('.')) from:button. |
318 |
button turnOff |
|
874 | 319 |
]. |
320 |
||
321 |
button openAt:100@100 |
|
322 |
" |
|
323 |
! |
|
324 |
||
325 |
startDrag:draggableObjects from:aView atEnd:aFourArgEndBlock |
|
326 |
"start a drop at the current pointer position |
|
327 |
When finished, the endAction is called with four args: |
|
328 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
329 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
330 |
" |
|
331 |
^ self startDrag:draggableObjects |
|
1166 | 332 |
from:aView |
333 |
offset:0@0 |
|
334 |
atEnd:aFourArgEndBlock |
|
335 |
display:draggableObjects |
|
874 | 336 |
|
337 |
" |
|
338 |
EXAMPLE: |
|
339 |
||
340 |
|button| |
|
341 |
||
342 |
button := (Button label:'press me'). |
|
343 |
||
344 |
button pressAction:[ |
|
1166 | 345 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
346 |
from:button |
|
347 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
348 |
Transcript showCR:'target view: ', targetView printString. |
|
349 |
Transcript showCR:'target id: ', targetViewId printString. |
|
350 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
351 |
Transcript showCR:'point target: ', targetPoint printString. |
|
352 |
]. |
|
353 |
button turnOff |
|
874 | 354 |
]. |
355 |
||
356 |
button openAt:100@100 |
|
357 |
" |
|
358 |
||
359 |
! |
|
360 |
||
361 |
startDrag:draggableObjects from:aView atEnd:aFourArgEndBlock display:something |
|
362 |
"start a drop at the current pointer position |
|
363 |
When finished, the endAction is called with four args: |
|
364 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
365 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
366 |
" |
|
367 |
^ self startDrag:draggableObjects |
|
1166 | 368 |
from:aView |
369 |
offset:0@0 |
|
370 |
atEnd:aFourArgEndBlock |
|
371 |
display:something |
|
874 | 372 |
|
373 |
" |
|
374 |
EXAMPLE: |
|
375 |
||
376 |
|button| |
|
377 |
||
378 |
button := (Button label:'press me'). |
|
379 |
||
380 |
button pressAction:[ |
|
1166 | 381 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
382 |
from:button |
|
383 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
384 |
Transcript showCR:'target view: ', targetView printString. |
|
385 |
Transcript showCR:'target id: ', targetViewId printString. |
|
386 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
387 |
Transcript showCR:'point target: ', targetPoint printString. |
|
388 |
] |
|
389 |
display:(Array with:'String' with:(Image fromFile:('xpmBitmaps/QUESTION3.xpm'))). |
|
390 |
button turnOff |
|
874 | 391 |
]. |
392 |
||
393 |
button openAt:100@100 |
|
394 |
" |
|
395 |
! |
|
396 |
||
397 |
startDrag:draggableObjects from:aView display:something |
|
398 |
"start a drop at the current pointer position |
|
399 |
" |
|
400 |
^ self startDrag:draggableObjects |
|
1166 | 401 |
from:aView |
402 |
offset:0@0 |
|
403 |
atEnd:nil |
|
404 |
display:something |
|
874 | 405 |
|
406 |
" |
|
407 |
EXAMPLE: |
|
408 |
||
409 |
|dropObj topView pannel icon buttonAction addButton| |
|
410 |
||
411 |
topView := StandardSystemView new. |
|
412 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
413 |
pannel horizontalLayout:#fit. |
|
414 |
pannel verticalLayout:#fitSpace. |
|
415 |
||
416 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
417 |
dropObj := DropObject newFile:('.'). |
|
418 |
||
419 |
addButton := [:label :dispObj| |button| |
|
1166 | 420 |
button := Button label:label in:pannel. |
874 | 421 |
|
1166 | 422 |
button pressAction:[ |
423 |
DragAndDropManager startDrag:dropObj from:button display:dispObj. |
|
424 |
button turnOff. |
|
425 |
] |
|
874 | 426 |
]. |
427 |
||
428 |
addButton value:'String' value:'String'. |
|
429 |
addButton value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
430 |
addButton value:'Icon' value:icon. |
|
431 |
addButton value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
432 |
addButton value:'Mixed' value:(Array with:'String' with:icon). |
|
433 |
||
434 |
topView label:'Drag & Drop'. |
|
435 |
topView openWithExtent:200@200. |
|
436 |
" |
|
437 |
! |
|
438 |
||
439 |
startDrag:draggableObjects from:aView offset:anOffset |
|
440 |
"start a drop at the current pointer position |
|
441 |
" |
|
442 |
^ self startDrag:draggableObjects |
|
1166 | 443 |
from:aView |
444 |
offset:anOffset |
|
445 |
atEnd:nil |
|
446 |
display:draggableObjects |
|
874 | 447 |
|
448 |
" |
|
449 |
EXAMPLE: |
|
450 |
||
451 |
|button| |
|
452 |
||
453 |
button := (Button label:'press me'). |
|
454 |
||
455 |
button pressAction:[ |
|
1166 | 456 |
DragAndDropManager startDrag:(DropObject newFile:('.')) from:button offset:(-10 @ -10). |
457 |
button turnOff |
|
874 | 458 |
]. |
459 |
||
460 |
button openAt:100@100 |
|
461 |
" |
|
462 |
||
463 |
! |
|
464 |
||
465 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock |
|
466 |
"start a drop at the current pointer position |
|
467 |
When finished, the endAction is called with four args: |
|
468 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
469 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
470 |
" |
|
471 |
^ self startDrag:draggableObjects |
|
1166 | 472 |
from:aView |
473 |
offset:anOffset |
|
474 |
atEnd:aFourArgEndBlock |
|
475 |
display:draggableObjects |
|
874 | 476 |
|
477 |
" |
|
478 |
EXAMPLE: |
|
479 |
||
480 |
|button| |
|
481 |
||
482 |
button := (Button label:'press me'). |
|
483 |
||
484 |
button pressAction:[ |
|
1166 | 485 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
486 |
from:button |
|
487 |
offset:(-10 @ -10) |
|
488 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
489 |
Transcript showCR:'target view: ', targetView printString. |
|
490 |
Transcript showCR:'target id: ', targetViewId printString. |
|
491 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
492 |
Transcript showCR:'point target: ', targetPoint printString. |
|
493 |
]. |
|
494 |
button turnOff |
|
874 | 495 |
]. |
496 |
||
497 |
button openAt:100@100 |
|
498 |
" |
|
499 |
||
500 |
! |
|
501 |
||
502 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock display:something |
|
503 |
"start a drop at the current pointer position |
|
504 |
When finished, the endAction is called with four args: |
|
505 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
506 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
507 |
" |
|
508 |
|manager| |
|
509 |
||
510 |
manager := self new. |
|
511 |
||
512 |
manager startDrag:draggableObjects |
|
1166 | 513 |
from:aView |
514 |
offset:anOffset |
|
515 |
atEnd:aFourArgEndBlock |
|
516 |
display:something. |
|
874 | 517 |
|
518 |
^ manager |
|
519 |
||
520 |
" |
|
521 |
EXAMPLE: |
|
522 |
||
523 |
|button| |
|
524 |
||
525 |
button := (Button label:'press me'). |
|
526 |
||
527 |
button pressAction:[ |
|
1166 | 528 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
529 |
from:button |
|
530 |
offset:(-10 @ -10) |
|
531 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
532 |
Transcript showCR:'target view: ', targetView printString. |
|
533 |
Transcript showCR:'target id: ', targetViewId printString. |
|
534 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
535 |
Transcript showCR:'point target: ', targetPoint printString. |
|
536 |
] |
|
537 |
display:(Array with:'String' with:(Image fromFile:('xpmBitmaps/QUESTION3.xpm'))). |
|
538 |
button turnOff |
|
874 | 539 |
]. |
540 |
||
541 |
button openAt:100@100 |
|
542 |
" |
|
543 |
||
544 |
! |
|
545 |
||
546 |
startDrag:draggableObjects from:aView offset:anOffset display:something |
|
547 |
"start a drop at the current pointer position |
|
548 |
" |
|
549 |
^ self startDrag:draggableObjects |
|
1166 | 550 |
from:aView |
551 |
offset:anOffset |
|
552 |
atEnd:nil |
|
553 |
display:something |
|
874 | 554 |
|
555 |
" |
|
556 |
EXAMPLE: |
|
557 |
||
558 |
|dropObj topView pannel icon buttonAction addButton| |
|
559 |
||
560 |
topView := StandardSystemView new. |
|
561 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
562 |
pannel horizontalLayout:#fit. |
|
563 |
pannel verticalLayout:#fitSpace. |
|
564 |
||
565 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
566 |
dropObj := DropObject newFile:('.'). |
|
567 |
||
568 |
addButton := [:offset :label :dispObj| |button| |
|
1166 | 569 |
button := Button label:label in:pannel. |
874 | 570 |
|
1166 | 571 |
button pressAction:[ |
572 |
DragAndDropManager startDrag:dropObj from:button offset:offset display:dispObj. |
|
573 |
button turnOff. |
|
574 |
] |
|
874 | 575 |
]. |
576 |
||
577 |
addButton value:#topLeft value:'String' value:'String'. |
|
578 |
addButton value:#topRight value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
579 |
addButton value:#bottomLeft value:'Icon' value:icon. |
|
580 |
addButton value:#bottomRight value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
581 |
addButton value:#center value:'Mixed' value:(Array with:'String' with:icon). |
|
582 |
||
583 |
topView label:'Drag & Drop'. |
|
584 |
topView openWithExtent:200@200. |
|
585 |
" |
|
586 |
||
587 |
! ! |
|
588 |
||
589 |
!DragAndDropManager class methodsFor:'simple start - lines'! |
|
397 | 590 |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
591 |
startArrowDragIn:aView at:dragPoint atEnd:aFourArgBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
592 |
"start a rubber-arrow-line dragging in aView at dragPoint. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
593 |
When finished, evaluate the fourArgBlock with targetView, |
874 | 594 |
targetID, screenPosition and targetViewPosition as arguments |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
595 |
" |
874 | 596 |
^ self new startArrowDragIn:aView at:dragPoint atEnd:aFourArgBlock |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
597 |
|
874 | 598 |
" |
599 |
EXAMPLE: |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
600 |
|
874 | 601 |
|button| |
397 | 602 |
|
874 | 603 |
button := (Button label:'press me'). |
861 | 604 |
|
874 | 605 |
button pressAction:[ |
1166 | 606 |
button turnOff. |
861 | 607 |
|
1166 | 608 |
DragAndDropManager startArrowDragIn:button |
609 |
at:(button preferredExtent // 2) |
|
610 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
611 |
targetView isNil ifTrue:[ |
|
612 |
Transcript show:'alien view' |
|
613 |
] ifFalse:[ |
|
614 |
Transcript showCR:'target: ', targetView printString |
|
615 |
]. |
|
616 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
617 |
Transcript showCR:'point target: ', targetPoint printString. |
|
618 |
] |
|
874 | 619 |
]. |
620 |
button openAt:100@100 |
|
621 |
" |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
622 |
! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
623 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
624 |
startLineDragIn:aView at:dragPoint atEnd:aFourArgBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
625 |
"start a rubber-line dragging in aView at dragPoint. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
626 |
When finished, evaluate the fourArgBlock with targetView, |
874 | 627 |
targetID, screenPosition and targetViewPosition as arguments |
628 |
" |
|
629 |
^ self new startLineDragIn:aView at:dragPoint atEnd:aFourArgBlock |
|
630 |
||
631 |
" |
|
632 |
EXAMPLE: |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
633 |
|
874 | 634 |
|button| |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
635 |
|
874 | 636 |
button := (Button label:'press me'). |
637 |
||
638 |
button pressAction:[ |
|
1166 | 639 |
button turnOff. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
640 |
|
1166 | 641 |
DragAndDropManager startLineDragIn:button |
642 |
at:(button preferredExtent // 2) |
|
643 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
644 |
targetView isNil ifTrue:[ |
|
645 |
Transcript show:'alien view' |
|
646 |
] ifFalse:[ |
|
647 |
Transcript showCR:'target: ', targetView printString |
|
648 |
]. |
|
649 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
650 |
Transcript showCR:'point target: ', targetPoint printString. |
|
651 |
] |
|
874 | 652 |
]. |
653 |
button openAt:100@100 |
|
654 |
" |
|
397 | 655 |
! ! |
656 |
||
1511 | 657 |
!DragAndDropManager class methodsFor:'translation'! |
658 |
||
659 |
translatePointFromScreen:aPoint toView:aView |
|
660 |
"translate a point to screen |
|
661 |
" |
|
662 |
|device trans point offset| |
|
663 |
||
664 |
device := aView device. |
|
665 |
||
666 |
"/ |
|
667 |
"/ translate to view |
|
668 |
"/ |
|
1517
5f4d38273014
use new #translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
1512
diff
changeset
|
669 |
offset := device translatePoint:0@0 fromView:(device rootView) toView:aView. |
1511 | 670 |
point := aPoint + offset. |
671 |
||
672 |
"/ |
|
673 |
"/ get device coordinates |
|
674 |
"/ |
|
675 |
(trans := aView transformation) notNil ifTrue:[ |
|
676 |
point := trans applyInverseTo:point |
|
677 |
]. |
|
678 |
^ point |
|
679 |
! |
|
680 |
||
681 |
translatePointToScreen:aPoint from:aView |
|
682 |
"translate a point to screen |
|
683 |
" |
|
684 |
|device trans point offset| |
|
685 |
||
686 |
device := aView device. |
|
687 |
"/ |
|
688 |
"/ get device coordinates |
|
689 |
"/ |
|
690 |
(trans := aView transformation) notNil ifTrue:[ |
|
691 |
point := trans applyTo:aPoint |
|
692 |
] ifFalse:[ |
|
693 |
point := aPoint |
|
694 |
]. |
|
695 |
"/ |
|
696 |
"/ translate to screen |
|
697 |
"/ |
|
1517
5f4d38273014
use new #translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
1512
diff
changeset
|
698 |
offset := device translatePoint:0@0 fromView:aView toView:(device rootView). |
1511 | 699 |
^ offset + point |
700 |
! ! |
|
701 |
||
394 | 702 |
!DragAndDropManager methodsFor:'accessing'! |
703 |
||
861 | 704 |
device |
705 |
"returns the device of the source view |
|
706 |
" |
|
707 |
^ dragView device |
|
708 |
||
709 |
||
710 |
! |
|
711 |
||
874 | 712 |
dropContext |
713 |
"return the current context |
|
714 |
" |
|
715 |
^ dropContext |
|
716 |
! |
|
717 |
||
397 | 718 |
dropObjects |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
719 |
"return the current dropObject collection" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
720 |
|
874 | 721 |
^ dropContext dropObjects |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
722 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
723 |
"Modified: 19.4.1997 / 10:19:06 / cg" |
397 | 724 |
! |
725 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
726 |
dropObjects:aCollectionOfDropObjects |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
727 |
"set the current dropObject collection" |
397 | 728 |
|
874 | 729 |
^ dropContext dropObjects:aCollectionOfDropObjects |
861 | 730 |
! |
731 |
||
732 |
font |
|
733 |
"returns the font of the source view |
|
734 |
" |
|
735 |
^ dragView font |
|
736 |
||
737 |
||
874 | 738 |
! |
739 |
||
740 |
sourceWidget |
|
741 |
^ dragView |
|
742 |
! ! |
|
743 |
||
1397 | 744 |
!DragAndDropManager methodsFor:'accessing-cursor'! |
874 | 745 |
|
746 |
alienCursor:aCursorOrImage |
|
747 |
"set the cursor used for an alien widget; not an ST/X view |
|
748 |
" |
|
749 |
aCursorOrImage isImage ifTrue:[ |
|
1166 | 750 |
alienCursor := Cursor fromImage:aCursorOrImage |
874 | 751 |
] ifFalse:[ |
1166 | 752 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
753 |
alienCursor := aCursorOrImage |
|
754 |
] ifFalse:[ |
|
755 |
"/ |
|
756 |
"/ use disabled cursor |
|
757 |
"/ |
|
758 |
alienCursor := nil |
|
759 |
] |
|
874 | 760 |
] |
761 |
! |
|
762 |
||
763 |
disabledCursor:aCursorOrImage |
|
764 |
"set the cursor for an ST/X view, which can not drop the objects |
|
765 |
" |
|
766 |
aCursorOrImage isImage ifTrue:[ |
|
1166 | 767 |
disabledCursor := Cursor fromImage:aCursorOrImage |
874 | 768 |
] ifFalse:[ |
1166 | 769 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
770 |
disabledCursor := aCursorOrImage |
|
771 |
] |
|
874 | 772 |
] |
773 |
! |
|
774 |
||
775 |
enabledCursor:aCursorOrImage |
|
776 |
"set the cursor for an ST/X view, which can drop the objects |
|
777 |
" |
|
778 |
aCursorOrImage isImage ifTrue:[ |
|
1166 | 779 |
enabledCursor := Cursor fromImage:aCursorOrImage |
874 | 780 |
] ifFalse:[ |
1166 | 781 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
782 |
enabledCursor := aCursorOrImage |
|
783 |
] |
|
874 | 784 |
] |
785 |
||
786 |
! ! |
|
787 |
||
788 |
!DragAndDropManager methodsFor:'dragging - drop source'! |
|
789 |
||
790 |
startDragFrom:aView dropSource:aDropSource |
|
791 |
"start a drop at the current pointer position. |
|
792 |
" |
|
793 |
^ self startDragFrom:aView dropSource:aDropSource offset:#topLeft "/ #center |
|
794 |
! |
|
795 |
||
796 |
startDragFrom:aView dropSource:aDropSource offset:anOffset |
|
797 |
"start a drop at the current pointer position. |
|
798 |
" |
|
799 |
dropContext dropSource:aDropSource. |
|
800 |
||
801 |
^ self startDrag:(aDropSource dropObjects) |
|
1166 | 802 |
from:aView |
803 |
offset:anOffset |
|
804 |
atEnd:nil |
|
805 |
display:(aDropSource displayObjects) |
|
874 | 806 |
! ! |
807 |
||
808 |
!DragAndDropManager methodsFor:'dragging - easy startup'! |
|
809 |
||
810 |
startDrag:draggableObjects from:aView |
|
811 |
"start a drop at the current pointer position |
|
812 |
" |
|
813 |
^ self startDrag:draggableObjects |
|
1166 | 814 |
from:aView |
815 |
offset:0@0 |
|
874 | 816 |
! |
817 |
||
818 |
startDrag:draggableObjects from:aView display:something |
|
819 |
"start a drop at the current pointer position. |
|
820 |
" |
|
821 |
^ self startDrag:draggableObjects |
|
1166 | 822 |
from:aView |
823 |
offset:nil |
|
824 |
atEnd:nil |
|
825 |
display:something |
|
874 | 826 |
! |
827 |
||
828 |
startDrag:draggableObjects from:aView offset:anOffset |
|
829 |
"start a drop at the current pointer position with an offset |
|
830 |
" |
|
831 |
^ self startDrag:draggableObjects |
|
1166 | 832 |
from:aView |
833 |
offset:anOffset |
|
834 |
atEnd:nil |
|
874 | 835 |
! |
836 |
||
837 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock |
|
838 |
"start a drop at the current pointer position. |
|
839 |
When finished, the endAction is called with four args: |
|
840 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
841 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
842 |
" |
|
843 |
^ self startDrag:draggableObjects |
|
1166 | 844 |
from:aView |
845 |
offset:anOffset |
|
846 |
atEnd:aFourArgEndBlock |
|
847 |
display:draggableObjects |
|
874 | 848 |
! |
849 |
||
850 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgBlock display:something |
|
851 |
"start a drop at the current pointer position. |
|
852 |
When finished, the endAction is called with four args: |
|
853 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
854 |
the dropPoint in root-coordinates and the dropPoint within the targetView. |
|
855 |
" |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
856 |
|height width fontWdt offset ascent device dispObjs list space| |
874 | 857 |
|
858 |
self dropObjects:draggableObjects. |
|
859 |
||
860 |
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
|
861 |
^ self |
874 | 862 |
]. |
863 |
||
864 |
device := aView device. |
|
865 |
space := 1. |
|
866 |
height := space negated. |
|
867 |
width := 0. |
|
868 |
fontWdt := aView font width. |
|
869 |
ascent := aView font ascent. |
|
870 |
||
871 |
(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
|
872 |
list := self dropObjects |
874 | 873 |
] ifFalse:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
874 |
(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
|
875 |
list := Array with:something |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
876 |
] |
874 | 877 |
]. |
878 |
dispObjs := OrderedCollection new. |
|
879 |
||
880 |
list do:[:el| |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
881 |
|obj asc| |
874 | 882 |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
883 |
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
|
884 |
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
|
885 |
height := height + space. |
874 | 886 |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
887 |
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
|
888 |
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
|
889 |
height := height + (obj heightOn:aView). |
874 | 890 |
]. |
891 |
||
881 | 892 |
anOffset isSymbol ifTrue:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
893 |
offset := (0@0 extent:(width @ height)) perform:anOffset. |
881 | 894 |
] ifFalse:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
895 |
offset := anOffset ? (0@0). |
881 | 896 |
]. |
897 |
offset := offset rounded. |
|
874 | 898 |
|
899 |
dispObjs do:[:el| el at:2 put:((el at:2) - offset) ]. |
|
900 |
||
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
901 |
self startOpaqueDrag:[:p :v| |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
902 |
|cursor hX hY pDraw| |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
903 |
|
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
904 |
cursor := dragView cursor. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
905 |
hX := cursor hotX. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
906 |
hY := cursor hotY. |
1497
dff682eb74fc
avoid jumping icon while moving
Claus Gittinger <cg@exept.de>
parents:
1490
diff
changeset
|
907 |
pDraw := p "- (hX@hY) + cursor extent". |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
908 |
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
|
909 |
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
|
910 |
] |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
911 |
] |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
912 |
offset:offset |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
913 |
extent:width @ height |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
914 |
in:aView |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
915 |
at:nil |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
916 |
atEnd:aFourArgBlock |
881 | 917 |
|
918 |
"Modified: / 31.3.1998 / 11:18:04 / cg" |
|
874 | 919 |
! |
920 |
||
921 |
startDrag:draggableObjects from:aView offset:anOffset display:something |
|
922 |
"start a drop at the current pointer position. |
|
923 |
" |
|
924 |
^ self startDrag:draggableObjects |
|
1166 | 925 |
from:aView |
926 |
offset:anOffset |
|
927 |
atEnd:nil |
|
928 |
display:something |
|
394 | 929 |
! ! |
930 |
||
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
931 |
!DragAndDropManager methodsFor:'dragging - generic'! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
932 |
|
348 | 933 |
startGenericDrag:aTwoArgDragBlock in:aView at:p atEnd:aFourArgEndBlock |
934 |
"start a generic (caller-provided drag); |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
935 |
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
|
936 |
by inverting again). See startOpaqueDrag for another variant. |
348 | 937 |
the dragBlock, aTwoArgDragBlock will be called with two args |
938 |
aPoint and a drawingGC, to perform the drawing at some dragPoint. |
|
939 |
The drag starts in aView at point p. |
|
940 |
When finished, the endAction is called with four args: |
|
941 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
874 | 942 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
943 |
" |
|
944 |
^ self startOpaqueDrag:aTwoArgDragBlock |
|
1166 | 945 |
offset:nil |
946 |
extent:nil |
|
947 |
in:aView |
|
948 |
at:nil |
|
949 |
atEnd:aFourArgEndBlock |
|
394 | 950 |
! |
951 |
||
874 | 952 |
startOpaqueDrag:aDragBlock offset:offs extent:anExtent in:aView at:aDummyPoint atEnd:aFourArgEndBlock |
953 |
"start an opaque or generic opaque (caller-provided drag); |
|
394 | 954 |
opaque drag means, that the drawing cannot be undone by two inverting |
955 |
draws, but instead, the area under the dragged object must be saved |
|
874 | 956 |
and restored. The areas size to be saved/restored is passed in anExtent. |
957 |
the dragBlock, aDragBlock will be called with up to three args aPoint, a |
|
958 |
drawingGC and the display objects, to perform the drawing at some dragPoint. |
|
394 | 959 |
The drag starts in aView at point p. |
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 |
|handler numArgs dragBlock dobjs| |
|
394 | 965 |
|
874 | 966 |
dragOffset := offs ? (Point x:0 y:0). |
967 |
numArgs := aDragBlock numArgs. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
968 |
|
874 | 969 |
numArgs == 3 ifTrue:[ |
1289 | 970 |
dobjs := self dropObjects. |
971 |
dragBlock := [:p :v| aDragBlock value:p value:v value:dobjs ] |
|
874 | 972 |
] ifFalse:[ |
1289 | 973 |
numArgs == 1 ifTrue:[ |
974 |
dragBlock := [:p :v| aDragBlock value:p ] |
|
975 |
] ifFalse:[ |
|
976 |
dragBlock := aDragBlock |
|
977 |
] |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
978 |
]. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
979 |
|
874 | 980 |
anExtent isNil ifTrue:[ |
1289 | 981 |
handler := DragHandler startGenericDrag:dragBlock. |
874 | 982 |
] ifFalse:[ |
1289 | 983 |
handler := DragHandler startOpaqueDrag:dragBlock extent:anExtent offset:dragOffset. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
984 |
]. |
1289 | 985 |
self doStart:handler for:aView atEnd:aFourArgEndBlock. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
986 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
987 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
988 |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
989 |
!DragAndDropManager methodsFor:'dragging - lines'! |
341 | 990 |
|
874 | 991 |
startArrowDragIn:aView at:aStartPoint atEnd:aFourArgEndBlock |
992 |
"start a line-drag of an arrow-line. |
|
993 |
The drag starts in aView at point aStartPoint. |
|
994 |
When finished, the endAction is called with four args: |
|
995 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
996 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
997 |
" |
|
998 |
|p| |
|
341 | 999 |
|
1511 | 1000 |
p := self class translatePointToScreen:aStartPoint from:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1001 |
|
874 | 1002 |
self doStart:(DragHandler startArrowDragAt:p) |
1511 | 1003 |
for:aView |
1004 |
atEnd:aFourArgEndBlock |
|
341 | 1005 |
! |
1006 |
||
874 | 1007 |
startLineDragIn:aView at:aStartPoint atEnd:aFourArgEndBlock |
1008 |
"start a line-drag of a normal line. |
|
1009 |
The drag starts in aView at point aStartPoint. |
|
348 | 1010 |
When finished, the endAction is called with four args: |
1011 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
874 | 1012 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
1013 |
" |
|
1014 |
|p| |
|
341 | 1015 |
|
1511 | 1016 |
p := self class translatePointToScreen:aStartPoint from:aView. |
348 | 1017 |
|
874 | 1018 |
self doStart:(DragHandler startLineDragAt:p) |
1511 | 1019 |
for:aView |
1020 |
atEnd:aFourArgEndBlock |
|
341 | 1021 |
! ! |
1022 |
||
397 | 1023 |
!DragAndDropManager methodsFor:'drawing'! |
1024 |
||
874 | 1025 |
displayObjectFor:anObject on:aDevice |
1026 |
"converts an object to a display object |
|
1027 |
" |
|
1572 | 1028 |
|obj s1 s2| |
874 | 1029 |
|
1030 |
obj := (anObject respondsTo:#displayObject) ifTrue:[anObject displayObject] |
|
1572 | 1031 |
ifFalse:[anObject]. |
874 | 1032 |
|
1033 |
obj isString ifTrue:[ |
|
1572 | 1034 |
^ obj |
874 | 1035 |
]. |
1036 |
||
1582 | 1037 |
MessageNotUnderstood |
1038 |
ignoreNotUnderstoodOf:#'onDevice:' |
|
1039 |
in:[ |
|
1040 |
obj := obj onDevice:aDevice |
|
1041 |
]. |
|
874 | 1042 |
|
1043 |
obj isImage ifTrue:[ |
|
1572 | 1044 |
^ obj clearMaskedPixels |
874 | 1045 |
]. |
1046 |
||
1047 |
obj class == LabelAndIcon ifTrue:[ |
|
1572 | 1048 |
obj image notNil ifTrue:[obj image clearMaskedPixels]. |
1049 |
obj icon notNil ifTrue:[obj icon clearMaskedPixels]. |
|
874 | 1050 |
^ obj |
1051 |
]. |
|
1052 |
||
1053 |
(obj class == MultiColListEntry) ifFalse:[ |
|
1572 | 1054 |
^ obj |
874 | 1055 |
]. |
1056 |
s1 := obj colAt:1. |
|
1057 |
s2 := obj colAt:2. |
|
1058 |
||
1059 |
s1 isImage ifTrue:[ |
|
1572 | 1060 |
s2 isImage ifTrue:[ ^ self displayObjectFor:(LabelAndIcon form:s1 image:s2) on:aDevice ]. |
1061 |
s2 isString ifTrue:[ ^ self displayObjectFor:(LabelAndIcon icon:s1 string:s2) on:aDevice ]. |
|
1062 |
^ (s1 on:aDevice) clearMaskedPixels |
|
874 | 1063 |
]. |
1064 |
||
1065 |
s2 isImage ifTrue:[ |
|
1572 | 1066 |
s1 isString ifTrue:[ ^ self displayObjectFor:(LabelAndIcon icon:s2 string:s1) on:aDevice ]. |
1067 |
^ (s2 on:aDevice) clearMaskedPixels |
|
874 | 1068 |
]. |
1069 |
||
1070 |
s1 isString ifTrue:[^ s1]. |
|
1071 |
s2 isString ifTrue:[^ s2]. |
|
1072 |
^ obj |
|
1073 |
! |
|
1074 |
||
397 | 1075 |
showDragging:items in:aView at:p |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1076 |
"helper for dragging dragObjects: draw them all" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1077 |
|
397 | 1078 |
|offs| |
1079 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1080 |
offs := 0. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1081 |
items do:[:item | |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1082 |
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
|
1083 |
offs := offs + (item heightOn:self) |
397 | 1084 |
] |
1085 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1086 |
"Modified: 19.4.1997 / 12:41:24 / cg" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1087 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1088 |
|
341 | 1089 |
!DragAndDropManager methodsFor:'event catching'! |
1090 |
||
1484 | 1091 |
buttonMotion:buttonState x:x y:y view:aView |
874 | 1092 |
"handle a button motion event |
1093 |
" |
|
1511 | 1094 |
|oldPt oldTgt oldWg oldId newWg newId newTgt screenPoint cursor device isDroppable| |
874 | 1095 |
|
1619 | 1096 |
escapePressed == true ifTrue:[^ self]. |
1097 |
||
874 | 1098 |
device := dragView device. |
1511 | 1099 |
screenPoint := self class translatePointToScreen:(x @ y) from:dragView. |
1497
dff682eb74fc
avoid jumping icon while moving
Claus Gittinger <cg@exept.de>
parents:
1490
diff
changeset
|
1100 |
"/ cursor := dragView cursor. |
1511 | 1101 |
"/ screenPoint := screenPoint + (cursor hotX @ cursor hotY). |
1497
dff682eb74fc
avoid jumping icon while moving
Claus Gittinger <cg@exept.de>
parents:
1490
diff
changeset
|
1102 |
|
874 | 1103 |
oldWg := dropContext targetWidget. |
1104 |
oldId := dropContext targetId. |
|
1105 |
oldPt := dropContext rootPoint. |
|
1106 |
||
1511 | 1107 |
dropContext rootPoint:screenPoint. |
874 | 1108 |
|
1511 | 1109 |
newId := device viewIdFromPoint:screenPoint. |
874 | 1110 |
newWg := device viewFromId:newId. |
1111 |
dropContext targetWidget:newWg id:newId. |
|
1112 |
||
1113 |
handler isInterestedInDropTarget ifFalse:[ |
|
1289 | 1114 |
"/ |
1115 |
"/ line or arrow handler |
|
1116 |
"/ |
|
1511 | 1117 |
handler dragTo:screenPoint. |
1289 | 1118 |
^ self |
874 | 1119 |
]. |
1120 |
||
1511 | 1121 |
true "oldWg ~~ newWg" ifTrue:[ |
1289 | 1122 |
"/ |
1123 |
"/ widget has changed: drop target might change |
|
1124 |
"/ |
|
1125 |
oldTgt := dropContext dropTarget. |
|
1511 | 1126 |
newTgt := self doFindDropTargetIn:newWg at:screenPoint. |
874 | 1127 |
|
1289 | 1128 |
newTgt ~= oldTgt ifTrue:[ |
1129 |
"/ |
|
1130 |
"/ drop target changed: handler might restore the screen |
|
1131 |
"/ |
|
1132 |
handler dropTargetWillChange. |
|
341 | 1133 |
|
1289 | 1134 |
oldTgt notNil ifTrue:[ |
1135 |
"/ |
|
1136 |
"/ setup old context |
|
1137 |
"/ |
|
1138 |
dropContext targetWidget:oldWg id:oldId. |
|
1139 |
oldTgt leave:dropContext. |
|
1140 |
dropContext targetWidget:newWg id:newId. |
|
1141 |
]. |
|
1142 |
dropContext dropTarget:newTgt. |
|
1143 |
newTgt notNil ifTrue:[ newTgt enter:dropContext ] |
|
1144 |
] ifFalse:[ |
|
1145 |
dropContext dropTarget:newTgt |
|
1146 |
] |
|
874 | 1147 |
] ifFalse:[ |
1511 | 1148 |
(oldPt notNil and:[(oldPt dist:screenPoint) < 2 ]) ifTrue:[ |
1289 | 1149 |
"/ |
1150 |
"/ ignore the button motion event; restore old rootPoint |
|
1151 |
"/ |
|
1152 |
dropContext rootPoint:oldPt. |
|
1153 |
^ self |
|
1154 |
]. |
|
1155 |
newTgt := dropContext dropTarget |
|
874 | 1156 |
]. |
1157 |
"/ |
|
1158 |
"/ update the cursor |
|
1159 |
"/ |
|
1160 |
(isDroppable := dropContext canDrop) ifTrue:[ |
|
1289 | 1161 |
cursor := enabledCursor |
874 | 1162 |
] ifFalse:[ |
1289 | 1163 |
cursor := dropContext isAlienView ifFalse:[disabledCursor] |
1164 |
ifTrue:[alienCursor] |
|
874 | 1165 |
]. |
1166 |
dragView cursor:cursor now:true. |
|
1167 |
"/ |
|
1168 |
"/ test if droppable state changed |
|
1169 |
"/ |
|
1170 |
canDrop == isDroppable ifFalse:[ |
|
1289 | 1171 |
"/ |
1172 |
"/ droppable state changed: handler might restore the screen |
|
1173 |
"/ |
|
1174 |
canDrop := isDroppable. |
|
1175 |
handler dropTargetWillChange |
|
874 | 1176 |
]. |
394 | 1177 |
|
874 | 1178 |
newTgt notNil ifTrue:[ newTgt over:dropContext ]. |
1511 | 1179 |
handler dragTo:screenPoint. |
874 | 1180 |
! |
394 | 1181 |
|
874 | 1182 |
buttonMultiPress:button x:x y:y view:aView |
1183 |
"discard each buttonMultiPress event |
|
1184 |
" |
|
1185 |
! |
|
1186 |
||
1187 |
buttonPress:button x:x y:y view:aView |
|
1188 |
"discard each buttonPress event |
|
1189 |
" |
|
341 | 1190 |
! |
1191 |
||
1192 |
buttonRelease:button x:x y:y view:aView |
|
874 | 1193 |
"button released; do the drop |
1194 |
" |
|
1195 |
((button == 2) or:[button == #menu]) ifTrue:[ |
|
1619 | 1196 |
^ self |
874 | 1197 |
]. |
1198 |
"/ |
|
1199 |
"/ update the context |
|
1200 |
"/ |
|
1201 |
self buttonMotion:button x:x y:y view:aView. |
|
1202 |
||
1203 |
"/ |
|
1204 |
"/ restore source view |
|
1205 |
"/ |
|
1206 |
restoreBlock value. |
|
1619 | 1207 |
escapePressed == true ifTrue:[^ self]. |
394 | 1208 |
|
874 | 1209 |
"/ |
1210 |
"/ at least do the drop operation |
|
1211 |
"/ |
|
1212 |
dropAction isNil ifTrue:[ |
|
1619 | 1213 |
dropContext doDrop |
874 | 1214 |
] ifFalse:[ |
1619 | 1215 |
"/ |
1216 |
"/ initiator wants to do it himself, manually. |
|
1217 |
"/ Thus, no feedBack operation invoked. |
|
1218 |
"/ |
|
1219 |
dropAction value:(dropContext targetWidget) |
|
1220 |
value:(dropContext targetId) |
|
1221 |
value:(dropContext rootPoint) |
|
1222 |
value:(dropContext targetPoint). |
|
874 | 1223 |
] |
341 | 1224 |
! |
1225 |
||
1289 | 1226 |
delegatesTo:someone |
1227 |
^false |
|
1228 |
! |
|
1229 |
||
341 | 1230 |
handlesButtonMotion:button inView:aView |
1231 |
"query from event processor: am I interested in button-events ? |
|
1232 |
yes I am (to activate the clicked-on field)." |
|
1233 |
||
874 | 1234 |
^ dragView == aView |
1235 |
! |
|
1236 |
||
1237 |
handlesButtonMultiPress:button inView:aView |
|
1238 |
"query from event processor: am I interested in button-events ? |
|
1239 |
yes I am (to activate the clicked-on field)." |
|
341 | 1240 |
|
874 | 1241 |
^ dragView == aView |
1242 |
! |
|
394 | 1243 |
|
874 | 1244 |
handlesButtonPress:button inView:aView |
1245 |
"query from event processor: am I interested in button-events ? |
|
1246 |
yes I am (to activate the clicked-on field)." |
|
1247 |
||
1248 |
^ dragView == aView |
|
341 | 1249 |
! |
1250 |
||
1251 |
handlesButtonRelease:button inView:aView |
|
1252 |
"query from event processor: am I interested in button-events ? |
|
1253 |
yes I am (to activate the clicked-on field)." |
|
1254 |
||
874 | 1255 |
^ dragView == aView |
1619 | 1256 |
! |
1257 |
||
1258 |
handlesKeyPress:aKey inView:aView |
|
1259 |
"query from event processor: am I interested in key-events ? |
|
1260 |
yes I am (to activate the clicked-on field)." |
|
1261 |
||
1262 |
^ dragView == aView |
|
1263 |
! |
|
1264 |
||
1265 |
keyPress:aKey x:x y:y view:aView |
|
1629
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1266 |
"any key is pressed: |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1267 |
#Escape cancel drag & drop operation |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1268 |
" |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1269 |
|dropTarget| |
1619 | 1270 |
|
1629
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1271 |
escapePressed == true ifTrue:[^ self ]. "/ already canceled |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1272 |
|
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1273 |
aKey == #Escape ifTrue:[ |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1274 |
"/ cancel drag & drop operation |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1275 |
escapePressed := true. |
1619 | 1276 |
|
1629
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1277 |
handler ifNotNil:[ |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1278 |
"/ restore handler |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1279 |
dropTarget := dropContext dropTarget. |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1280 |
handler postDragging. |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1281 |
|
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1282 |
dropTarget ifNotNil:[ |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1283 |
"/ invoke leave operation |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1284 |
dropTarget leave:dropContext. |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1285 |
dropContext dropTarget:nil. |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1286 |
]. |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1287 |
]. |
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1288 |
^ self |
1619 | 1289 |
]. |
874 | 1290 |
! ! |
1291 |
||
1292 |
!DragAndDropManager methodsFor:'initialization'! |
|
341 | 1293 |
|
874 | 1294 |
initialize |
1295 |
super initialize. |
|
394 | 1296 |
|
874 | 1297 |
dragOffset := 0 @ 0. |
1298 |
dropContext := DropContext new. |
|
1618 | 1299 |
dropContext manager:self. |
874 | 1300 |
alienCursor := Cursor questionMark. |
1301 |
enabledCursor := Cursor thumbsUp. |
|
1302 |
disabledCursor := Cursor thumbsDown. |
|
1303 |
canDrop := false. |
|
341 | 1304 |
! ! |
1305 |
||
1306 |
!DragAndDropManager methodsFor:'private'! |
|
1307 |
||
874 | 1308 |
doDrop:aContext in:aWidget |
1309 |
"old drop mechanism |
|
1310 |
" |
|
1311 |
|point| |
|
628 | 1312 |
|
1511 | 1313 |
DragContextQuerySignal answer:aContext do:[ |
1314 |
DragOriginatorQuerySignal answer:dragView do:[ |
|
1315 |
DragOffsetQuerySignal answer:dragOffset do:[ |
|
1316 |
aContext targetWidget == aWidget ifTrue:[ |
|
1317 |
point := aContext targetPoint |
|
1318 |
] ifFalse:[ |
|
1319 |
point := 0@0. "/ nil. |
|
1320 |
"/ |
|
1321 |
"/ FeedBack: set the widget which handles the drop |
|
1322 |
"/ |
|
1323 |
aContext targetWidget:aWidget id:(aWidget id). |
|
1324 |
]. |
|
1325 |
aWidget drop:(aContext dropObjects) at:point |
|
1326 |
] |
|
1327 |
]. |
|
609
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1328 |
]. |
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1329 |
|
1072
be90bc383d83
do not pas nil point to dropDestination
Claus Gittinger <cg@exept.de>
parents:
881
diff
changeset
|
1330 |
"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
|
1331 |
! |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
1332 |
|
874 | 1333 |
doFindDropTargetIn:aView at:aPoint |
1334 |
"get the drop target for a view and source at a point or nil |
|
411 | 1335 |
" |
628 | 1336 |
|
874 | 1337 |
aView isNil ifTrue:[ ^ nil ]. |
1582 | 1338 |
|
874 | 1339 |
"/ |
1340 |
"/ new mechanism to get a dropTarget |
|
1341 |
"/ |
|
1587 | 1342 |
|
1582 | 1343 |
MessageNotUnderstood |
1344 |
ignoreNotUnderstoodOf:#dropTarget |
|
1587 | 1345 |
in:[ |target| |
1582 | 1346 |
target := aView dropTarget. |
1587 | 1347 |
target notNil ifTrue:[ ^ target ]. |
1582 | 1348 |
]. |
1349 |
||
874 | 1350 |
"/ |
1351 |
"/ old mechanism to get a dropTarget |
|
1352 |
"/ |
|
628 | 1353 |
|
1511 | 1354 |
DragContextQuerySignal answer:dropContext do:[ |
1355 |
DragOriginatorQuerySignal answer:dragView do:[ |
|
1356 |
DragOffsetQuerySignal answer:dragOffset do:[ |
|
1587 | 1357 |
|view dobj| |
1358 |
||
1359 |
view := aView. |
|
1360 |
dobj := dropContext dropObjects. |
|
1361 |
[ |
|
1362 |
(view canDrop:dobj) ifTrue:[ |
|
1511 | 1363 |
^ DropTarget receiver:self argument:view dropSelector:#doDrop:in:. |
1364 |
]. |
|
1365 |
(view := view superView) notNil |
|
1366 |
] whileTrue. |
|
1367 |
] |
|
1368 |
]. |
|
874 | 1369 |
]. |
1370 |
^ nil |
|
1371 |
! |
|
628 | 1372 |
|
874 | 1373 |
doStart:aHandler for:aView atEnd:aFourArgEndBlock |
1374 |
"setup a handler and a restore block |
|
628 | 1375 |
" |
1619 | 1376 |
|device savedCursor savedDelegate prevGrab prevKeyb sensor p| |
628 | 1377 |
|
1512 | 1378 |
device := aView device. |
1379 |
(ActiveDragAndDropManagers at:device ifAbsent:nil) notNil ifTrue:[ |
|
1380 |
self error:'oops - two dnd managers active' mayProceed:true. |
|
1487 | 1381 |
]. |
1512 | 1382 |
ActiveDragAndDropManagers at:device put:self. |
1487 | 1383 |
|
874 | 1384 |
dropContext sourceWidget:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1385 |
|
874 | 1386 |
dragOffset isNil ifTrue:[ dragOffset := 0 @ 0 ]. |
1387 |
alienCursor isNil ifTrue:[ alienCursor := disabledCursor ]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1388 |
|
874 | 1389 |
dragView := aView. |
1390 |
dropAction := aFourArgEndBlock. |
|
1289 | 1391 |
savedCursor := aView cursor. |
1392 |
savedDelegate := aView delegate. |
|
1619 | 1393 |
handler := aHandler. |
1394 |
escapePressed := false. |
|
1395 |
prevGrab := prevKeyb := nil. |
|
609
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1396 |
|
1162
0539b64679ce
set DragHandler in the DropContext
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1397 |
dropContext dragHandler:aHandler. |
0539b64679ce
set DragHandler in the DropContext
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1398 |
|
874 | 1399 |
restoreBlock := [ |
1512 | 1400 |
ActiveDragAndDropManagers removeKey:device ifAbsent:nil. |
1619 | 1401 |
escapePressed ifFalse:[ |
1402 |
aHandler postDragging |
|
1403 |
]. |
|
1289 | 1404 |
aView delegate:savedDelegate. |
1405 |
aView cursor:savedCursor now:true. |
|
1406 |
prevGrab notNil ifTrue:[ |
|
1407 |
aView forceUngrabPointer. |
|
1408 |
prevGrab grabPointer. |
|
1409 |
] ifFalse:[ |
|
1410 |
aView ungrabPointer. |
|
1411 |
]. |
|
1619 | 1412 |
prevKeyb notNil ifTrue:[ |
1413 |
aView forceUngrabKeyboard. |
|
1414 |
prevKeyb grabKeyboard. |
|
1415 |
] ifFalse:[ |
|
1416 |
aView ungrabKeyboard. |
|
1417 |
]. |
|
874 | 1418 |
]. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1419 |
|
874 | 1420 |
aHandler preDraggingIn:aView. |
1421 |
aView delegate:self. |
|
1512 | 1422 |
prevGrab := device activePointerGrab. |
1619 | 1423 |
prevKeyb := device activeKeyboardGrab. |
1289 | 1424 |
aView grabPointer. |
1619 | 1425 |
aView grabKeyboard. |
1289 | 1426 |
|
1427 |
"/ must wait for all pending motion events to arrive, and ignore them |
|
1428 |
(sensor := aView sensor) notNil ifTrue:[ |
|
1512 | 1429 |
device sync. |
1289 | 1430 |
sensor flushMotionEventsFor:nil. |
1431 |
]. |
|
1432 |
||
1433 |
"/ start with a first draw at the current mouse position |
|
1512 | 1434 |
p := device pointerPosition. |
1517
5f4d38273014
use new #translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
1512
diff
changeset
|
1435 |
p := device translatePoint:p fromView:nil toView:aView. |
1289 | 1436 |
self buttonMotion:1 x:p x y:p y view:aView |
1517
5f4d38273014
use new #translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
1512
diff
changeset
|
1437 |
|
5f4d38273014
use new #translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
1512
diff
changeset
|
1438 |
"Modified: / 10.10.2001 / 14:45:22 / cg" |
1487 | 1439 |
! |
1440 |
||
1441 |
saveDraw:aBlock |
|
1442 |
handler postDragging. |
|
1443 |
aBlock value. |
|
1444 |
handler rereadSaveArea. |
|
1445 |
handler restoreFromSaveArea. |
|
1587 | 1446 |
! |
1447 |
||
1448 |
xx |
|
1449 |
||
1450 |
Transcript showCR:([-3] on:Error do:[0]). |
|
1451 |
Transcript showCR:([5 printString. 7] on:Error do:[]) |
|
1452 |
||
1453 |
" |
|
1454 |
self new xx |
|
1455 |
" |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1456 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1457 |
|
341 | 1458 |
!DragAndDropManager class methodsFor:'documentation'! |
1459 |
||
1460 |
version |
|
1629
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1461 |
^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.42 2002-10-04 05:26:48 ca Exp $' |
341 | 1462 |
! ! |
1629
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1463 |
|
628 | 1464 |
DragAndDropManager initialize! |