author | Claus Gittinger <cg@exept.de> |
Fri, 13 Oct 2006 17:57:55 +0200 | |
changeset 2255 | 074d16551e16 |
parent 2254 | b120e73f9a76 |
child 2259 | 76b190967964 |
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 |
" |
1397 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
341 | 14 |
Object subclass:#DragAndDropManager |
874 | 15 |
instanceVariableNames:'dropContext dragView dropAction dragOffset handler restoreBlock |
1661
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
16 |
alienCursor enabledCursor disabledCursor canDrop escapePressed |
2042
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
17 |
passiveAction autoScrollTask disabledFlag' |
1511 | 18 |
classVariableNames:'DragContextQuerySignal DragOriginatorQuerySignal |
19 |
DragOffsetQuerySignal ActiveDragAndDropManagers' |
|
628 | 20 |
poolDictionaries:'' |
874 | 21 |
category:'Interface-DragAndDrop' |
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
22 |
! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
23 |
|
341 | 24 |
!DragAndDropManager class methodsFor:'documentation'! |
25 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
26 |
copyright |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
27 |
" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
28 |
COPYRIGHT (c) 1996 by eXept Software AG / Claus Gittinger |
1166 | 29 |
All Rights Reserved |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
30 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
inclusion of the above copyright notice. This software may not |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
34 |
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
|
35 |
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
|
36 |
hereby transferred. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
37 |
" |
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 |
|
348 | 41 |
documentation |
42 |
" |
|
43 |
this class provides low-level drag & drop mechanisms. |
|
44 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
45 |
Easy to use interface interfaces: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
46 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
47 |
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
|
48 |
when a selection is moved (for example, SelectionInListView can |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
49 |
be initializd to do so). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
50 |
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
|
51 |
and starts the drag operation with: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
52 |
|
1166 | 53 |
DragAndDropManager startDrag:collectionOfDragObjects from:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
54 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
55 |
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
|
56 |
into the target view. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
is shown for alien views (which means: we dont know). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
60 |
Alien view drop is supported (but no 'canDrop' query). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
61 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
62 |
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
|
63 |
provided: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
64 |
|
1166 | 65 |
DragAndDropManager |
66 |
startLineDragIn:aView at:position |
|
67 |
atEnd:aFourArgEndBlock |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
68 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
69 |
and: |
1166 | 70 |
DragAndDropManager |
71 |
startArrowDragIn:aView at:position |
|
72 |
atEnd:aFourArgEndBlock |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
73 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
on the screen and within the target view as arguments. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
77 |
|
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 |
Expert interface: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
80 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
81 |
More control over the dragging (i.e. the drawing procedure) |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
82 |
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
|
83 |
|
1166 | 84 |
aDragAndDropMgr := DragAndDropManager new. |
85 |
aDragAndDropMgr dropObjects:(self collectionOfDragObjects). |
|
86 |
aDragAndDropMgr |
|
87 |
startOpaqueDrag:[:aPoint :aView :dropObjects | |
|
88 |
self |
|
89 |
showDragging:dropObjects |
|
90 |
in:aView |
|
91 |
at:aPoint - (xOffset@0) |
|
92 |
] |
|
93 |
offset:clickOffset |
|
94 |
extent:saveUnderExtent |
|
95 |
in:self |
|
96 |
at:clickPoint |
|
97 |
atEnd:[:v :vId :posScreen :posView | ... ] |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
98 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
99 |
the arguments are: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
100 |
startOpaqueDrag: |
1166 | 101 |
a 3-arg block, which is evaluated by the d&d manager whenever the |
102 |
mouse moves; it is supposed to draw the dropObjects at some position |
|
103 |
in the passed view. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
104 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
105 |
offset: |
1166 | 106 |
a clickOffset; drawing is offset by this amount |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
107 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
108 |
extent: |
1166 | 109 |
a save extent; the size of the screen area that must be saved during |
110 |
the drag operation |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
111 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
112 |
in: |
1166 | 113 |
initiating view |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
114 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
115 |
at: |
1166 | 116 |
position where d&d operation starts |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
117 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
118 |
atEnd: |
1166 | 119 |
a 4-arg block that is evaluated when the d&d is finished. |
120 |
It gets the target view (or nil, for alien views), the targets |
|
121 |
view ID (needed if its an alien view), the screen position and the |
|
122 |
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
|
123 |
|
1166 | 124 |
For internal (ST/X) views, the dropBlock should perform |
125 |
a simple canDrop:/doDrop message. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
126 |
|
1166 | 127 |
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
|
128 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
129 |
|
348 | 130 |
[author:] |
1166 | 131 |
Claus Gittinger |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
132 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
133 |
[see also:] |
1166 | 134 |
DemoView1, DemoView2, ... |
135 |
SelectionInListView FileBrowser - for a concrete example |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
136 |
|
348 | 137 |
" |
138 |
||
139 |
! |
|
140 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
141 |
examples |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
142 |
" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
143 |
a button, which initiates dragging of a file-object |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
144 |
Notice that this can be dropped into the launchers panel, |
549 | 145 |
to open a fileBrowser on that directory ... |
1166 | 146 |
[exBegin] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
147 |
|o top v| |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
148 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
149 |
top := StandardSystemView new. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
150 |
v := Button label:'press for drag' in:top. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
151 |
v pressAction:[ |
1166 | 152 |
|o| |
153 |
o := DropObject newFile:('/etc'). |
|
154 |
DragAndDropManager startDrag:o from:v. |
|
155 |
v turnOff |
|
156 |
]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
157 |
top openWithExtent:200@200 |
1166 | 158 |
[exEnd] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
159 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
160 |
initiate a drag with some offset: |
1166 | 161 |
[exBegin] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
162 |
|o top v| |
341 | 163 |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
164 |
top := StandardSystemView new. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
165 |
v := Button label:'press for drag' in:top. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
166 |
v pressAction:[ |
1166 | 167 |
|o| |
168 |
o := DropObject newFile:('.'). |
|
169 |
DragAndDropManager startDrag:o from:v offset:10@10. |
|
170 |
v turnOff |
|
171 |
]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
172 |
top openWithExtent:200@200 |
1166 | 173 |
[exEnd] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
174 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
175 |
initiate a line drag: |
1166 | 176 |
[exBegin] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
177 |
|o top v endAction| |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
178 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
179 |
endAction := [ :v :vID :sPos :vPos | |
1166 | 180 |
Transcript show:'end drag in '. |
181 |
v isNil ifTrue:[ |
|
182 |
Transcript show:'alien view' |
|
183 |
] ifFalse:[ |
|
184 |
Transcript show:v |
|
185 |
]. |
|
186 |
Transcript show:' at screen: '; show:sPos; |
|
187 |
show:' in view: '; showCR:vPos |
|
188 |
]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
189 |
top := StandardSystemView new. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
190 |
v := Button label:'press for drag' in:top. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
191 |
v pressAction:[ |
1166 | 192 |
DragAndDropManager |
193 |
startLineDragIn:v at:10@10 atEnd:endAction. |
|
194 |
v turnOff |
|
195 |
]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
196 |
top openWithExtent:200@200 |
1166 | 197 |
[exEnd] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
198 |
|
874 | 199 |
more drag & drop; offset, displayObjects, ... |
1166 | 200 |
[exBegin] |
874 | 201 |
|dropObj topView pannel icon buttonAction addButton| |
202 |
||
203 |
topView := StandardSystemView new. |
|
204 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
205 |
pannel horizontalLayout:#fit. |
|
206 |
pannel verticalLayout:#fitSpace. |
|
207 |
||
208 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
209 |
dropObj := DropObject newFile:('.'). |
|
210 |
||
211 |
addButton := [:offset :label :dispObj| |button| |
|
1166 | 212 |
button := Button label:label in:pannel. |
874 | 213 |
|
1166 | 214 |
button pressAction:[ |
215 |
DragAndDropManager startDrag:dropObj from:button offset:offset display:dispObj. |
|
216 |
button turnOff. |
|
217 |
] |
|
874 | 218 |
]. |
219 |
||
881 | 220 |
addButton value:(0@-5) value:'String' value:'String'. |
874 | 221 |
addButton value:#topLeft value:'String' value:'String'. |
222 |
addButton value:#topRight value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
223 |
addButton value:#bottomLeft value:'Icon' value:icon. |
|
224 |
addButton value:#bottomRight value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
225 |
addButton value:#center value:'Mixed' value:(Array with:'String' with:icon). |
|
226 |
||
227 |
topView label:'Drag & Drop'. |
|
228 |
topView openWithExtent:200@200. |
|
1166 | 229 |
[exEnd] |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
230 |
" |
341 | 231 |
! ! |
232 |
||
628 | 233 |
!DragAndDropManager class methodsFor:'initialization'! |
234 |
||
235 |
initialize |
|
236 |
DragOriginatorQuerySignal := QuerySignal new. |
|
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
237 |
DragOffsetQuerySignal := QuerySignal new. |
1511 | 238 |
DragContextQuerySignal := 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 |
||
1511 | 256 |
dragContextQuerySignal |
257 |
^ DragContextQuerySignal |
|
258 |
! |
|
259 |
||
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
260 |
dragOffsetQuerySignal |
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 |
|
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
263 |
"Created: 11.8.1997 / 00:54:10 / cg" |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
264 |
! |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
265 |
|
628 | 266 |
dragOriginatorQuerySignal |
267 |
^ DragOriginatorQuerySignal |
|
268 |
! ! |
|
269 |
||
1842
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
270 |
!DragAndDropManager class methodsFor:'defaults'! |
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
271 |
|
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
272 |
autoScrollDelayTimeMs |
2078 | 273 |
"time measured in milli-seconds the autoscroll task is delayed" |
274 |
||
1842
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
275 |
^ 200 |
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
276 |
! ! |
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
277 |
|
1487 | 278 |
!DragAndDropManager class methodsFor:'helpers'! |
279 |
||
2042
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
280 |
disabledFlag:aBoolean device:aDevice |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
281 |
|activeManager| |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
282 |
|
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
283 |
activeManager := ActiveDragAndDropManagers at:aDevice ifAbsent:nil. |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
284 |
activeManager notNil ifTrue:[ |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
285 |
activeManager disabledFlag: aBoolean |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
286 |
]. |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
287 |
! |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
288 |
|
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
289 |
postDraggingOnDevice:aDevice |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
290 |
|activeManager| |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
291 |
|
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
292 |
activeManager := ActiveDragAndDropManagers at:aDevice ifAbsent:nil. |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
293 |
activeManager notNil ifTrue:[ |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
294 |
activeManager dragHandler postDragging |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
295 |
]. |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
296 |
! |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
297 |
|
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
298 |
rereadSaveAreaOnDevice:aDevice |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
299 |
|activeManager| |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
300 |
|
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
301 |
activeManager := ActiveDragAndDropManagers at:aDevice ifAbsent:nil. |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
302 |
activeManager notNil ifTrue:[ |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
303 |
activeManager dragHandler flushSaveArea; rereadSaveArea |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
304 |
]. |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
305 |
! |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
306 |
|
1487 | 307 |
saveDraw:aBlock device:aDevice |
308 |
|activeManager| |
|
309 |
||
310 |
activeManager := ActiveDragAndDropManagers at:aDevice ifAbsent:nil. |
|
311 |
activeManager isNil ifTrue:[ |
|
312 |
aBlock value |
|
313 |
] ifFalse:[ |
|
314 |
activeManager saveDraw:aBlock |
|
315 |
]. |
|
316 |
! ! |
|
317 |
||
318 |
!DragAndDropManager class methodsFor:'queries'! |
|
319 |
||
320 |
isDragAndDropActiveOnDevice:aDevice |
|
321 |
^ ActiveDragAndDropManagers includesKey:aDevice |
|
322 |
! ! |
|
323 |
||
1776 | 324 |
!DragAndDropManager class methodsFor:'simple start-drop source'! |
874 | 325 |
|
326 |
startDragFrom:aView dropSource:aDropSource |
|
2078 | 327 |
"start a drop at the current pointer position." |
328 |
||
874 | 329 |
^ (self new) startDragFrom:aView dropSource:aDropSource |
330 |
! ! |
|
331 |
||
1776 | 332 |
!DragAndDropManager class methodsFor:'simple start-generic'! |
874 | 333 |
|
334 |
startDrag:draggableObjects from:aView |
|
2078 | 335 |
"start a drop at the current pointer position" |
336 |
||
874 | 337 |
^ self startDrag:draggableObjects |
2078 | 338 |
from:aView |
339 |
offset:0@0 |
|
340 |
atEnd:nil |
|
341 |
display:draggableObjects |
|
874 | 342 |
|
343 |
" |
|
344 |
EXAMPLE: |
|
345 |
||
346 |
|button| |
|
347 |
||
348 |
button := (Button label:'press me'). |
|
349 |
||
350 |
button pressAction:[ |
|
2078 | 351 |
DragAndDropManager startDrag:(DropObject newFile:('.')) from:button. |
352 |
button turnOff |
|
874 | 353 |
]. |
354 |
||
355 |
button openAt:100@100 |
|
356 |
" |
|
357 |
! |
|
358 |
||
359 |
startDrag:draggableObjects from:aView atEnd:aFourArgEndBlock |
|
360 |
"start a drop at the current pointer position |
|
361 |
When finished, the endAction is called with four args: |
|
362 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
2078 | 363 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
364 |
||
874 | 365 |
^ self startDrag:draggableObjects |
2078 | 366 |
from:aView |
367 |
offset:0@0 |
|
368 |
atEnd:aFourArgEndBlock |
|
369 |
display:draggableObjects |
|
874 | 370 |
|
371 |
" |
|
372 |
EXAMPLE: |
|
373 |
||
374 |
|button| |
|
375 |
||
376 |
button := (Button label:'press me'). |
|
377 |
||
378 |
button pressAction:[ |
|
2078 | 379 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
380 |
from:button |
|
381 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
382 |
Transcript showCR:'target view: ', targetView printString. |
|
383 |
Transcript showCR:'target id: ', targetViewId printString. |
|
384 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
385 |
Transcript showCR:'point target: ', targetPoint printString. |
|
386 |
]. |
|
387 |
button turnOff |
|
874 | 388 |
]. |
389 |
||
390 |
button openAt:100@100 |
|
391 |
" |
|
392 |
! |
|
393 |
||
394 |
startDrag:draggableObjects from:aView atEnd:aFourArgEndBlock display:something |
|
395 |
"start a drop at the current pointer position |
|
396 |
When finished, the endAction is called with four args: |
|
397 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
2078 | 398 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
399 |
||
874 | 400 |
^ self startDrag:draggableObjects |
2078 | 401 |
from:aView |
402 |
offset:0@0 |
|
403 |
atEnd:aFourArgEndBlock |
|
404 |
display:something |
|
874 | 405 |
|
406 |
" |
|
407 |
EXAMPLE: |
|
408 |
||
409 |
|button| |
|
410 |
||
411 |
button := (Button label:'press me'). |
|
412 |
||
413 |
button pressAction:[ |
|
2078 | 414 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
415 |
from:button |
|
416 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
417 |
Transcript showCR:'target view: ', targetView printString. |
|
418 |
Transcript showCR:'target id: ', targetViewId printString. |
|
419 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
420 |
Transcript showCR:'point target: ', targetPoint printString. |
|
421 |
] |
|
422 |
display:(Array with:'String' with:(Image fromFile:('xpmBitmaps/QUESTION3.xpm'))). |
|
423 |
button turnOff |
|
874 | 424 |
]. |
425 |
||
426 |
button openAt:100@100 |
|
427 |
" |
|
428 |
! |
|
429 |
||
430 |
startDrag:draggableObjects from:aView display:something |
|
2078 | 431 |
"start a drop at the current pointer position" |
432 |
||
874 | 433 |
^ self startDrag:draggableObjects |
2078 | 434 |
from:aView |
435 |
offset:0@0 |
|
436 |
atEnd:nil |
|
437 |
display:something |
|
874 | 438 |
|
439 |
" |
|
440 |
EXAMPLE: |
|
441 |
||
442 |
|dropObj topView pannel icon buttonAction addButton| |
|
443 |
||
444 |
topView := StandardSystemView new. |
|
445 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
446 |
pannel horizontalLayout:#fit. |
|
447 |
pannel verticalLayout:#fitSpace. |
|
448 |
||
449 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
450 |
dropObj := DropObject newFile:('.'). |
|
451 |
||
452 |
addButton := [:label :dispObj| |button| |
|
2078 | 453 |
button := Button label:label in:pannel. |
874 | 454 |
|
2078 | 455 |
button pressAction:[ |
456 |
DragAndDropManager startDrag:dropObj from:button display:dispObj. |
|
457 |
button turnOff. |
|
458 |
] |
|
874 | 459 |
]. |
460 |
||
461 |
addButton value:'String' value:'String'. |
|
462 |
addButton value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
463 |
addButton value:'Icon' value:icon. |
|
464 |
addButton value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
465 |
addButton value:'Mixed' value:(Array with:'String' with:icon). |
|
466 |
||
467 |
topView label:'Drag & Drop'. |
|
468 |
topView openWithExtent:200@200. |
|
469 |
" |
|
470 |
! |
|
471 |
||
472 |
startDrag:draggableObjects from:aView offset:anOffset |
|
2078 | 473 |
"start a drop at the current pointer position" |
474 |
||
874 | 475 |
^ self startDrag:draggableObjects |
2078 | 476 |
from:aView |
477 |
offset:anOffset |
|
478 |
atEnd:nil |
|
479 |
display:draggableObjects |
|
874 | 480 |
|
481 |
" |
|
482 |
EXAMPLE: |
|
483 |
||
484 |
|button| |
|
485 |
||
486 |
button := (Button label:'press me'). |
|
487 |
||
488 |
button pressAction:[ |
|
2078 | 489 |
DragAndDropManager startDrag:(DropObject newFile:('.')) from:button offset:(-10 @ -10). |
490 |
button turnOff |
|
874 | 491 |
]. |
492 |
||
493 |
button openAt:100@100 |
|
494 |
" |
|
495 |
! |
|
496 |
||
497 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock |
|
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), |
|
2078 | 501 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
502 |
||
874 | 503 |
^ self startDrag:draggableObjects |
2078 | 504 |
from:aView |
505 |
offset:anOffset |
|
506 |
atEnd:aFourArgEndBlock |
|
507 |
display:draggableObjects |
|
874 | 508 |
|
509 |
" |
|
510 |
EXAMPLE: |
|
511 |
||
512 |
|button| |
|
513 |
||
514 |
button := (Button label:'press me'). |
|
515 |
||
516 |
button pressAction:[ |
|
2078 | 517 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
518 |
from:button |
|
519 |
offset:(-10 @ -10) |
|
520 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
521 |
Transcript showCR:'target view: ', targetView printString. |
|
522 |
Transcript showCR:'target id: ', targetViewId printString. |
|
523 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
524 |
Transcript showCR:'point target: ', targetPoint printString. |
|
525 |
]. |
|
526 |
button turnOff |
|
874 | 527 |
]. |
528 |
||
529 |
button openAt:100@100 |
|
530 |
" |
|
531 |
! |
|
532 |
||
533 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock display:something |
|
534 |
"start a drop at the current pointer position |
|
535 |
When finished, the endAction is called with four args: |
|
536 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
2078 | 537 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
538 |
||
874 | 539 |
|manager| |
540 |
||
541 |
manager := self new. |
|
542 |
||
543 |
manager startDrag:draggableObjects |
|
2078 | 544 |
from:aView |
545 |
offset:anOffset |
|
546 |
atEnd:aFourArgEndBlock |
|
547 |
display:something. |
|
874 | 548 |
|
549 |
^ manager |
|
550 |
||
551 |
" |
|
552 |
EXAMPLE: |
|
553 |
||
554 |
|button| |
|
555 |
||
556 |
button := (Button label:'press me'). |
|
557 |
||
558 |
button pressAction:[ |
|
2078 | 559 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
560 |
from:button |
|
561 |
offset:(-10 @ -10) |
|
562 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
563 |
Transcript showCR:'target view: ', targetView printString. |
|
564 |
Transcript showCR:'target id: ', targetViewId printString. |
|
565 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
566 |
Transcript showCR:'point target: ', targetPoint printString. |
|
567 |
] |
|
568 |
display:(Array with:'String' with:(Image fromFile:('xpmBitmaps/QUESTION3.xpm'))). |
|
569 |
button turnOff |
|
874 | 570 |
]. |
571 |
||
572 |
button openAt:100@100 |
|
573 |
" |
|
574 |
! |
|
575 |
||
576 |
startDrag:draggableObjects from:aView offset:anOffset display:something |
|
2078 | 577 |
"start a drop at the current pointer position" |
578 |
||
874 | 579 |
^ self startDrag:draggableObjects |
2078 | 580 |
from:aView |
581 |
offset:anOffset |
|
582 |
atEnd:nil |
|
583 |
display:something |
|
874 | 584 |
|
585 |
" |
|
586 |
EXAMPLE: |
|
587 |
||
588 |
|dropObj topView pannel icon buttonAction addButton| |
|
589 |
||
590 |
topView := StandardSystemView new. |
|
591 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
592 |
pannel horizontalLayout:#fit. |
|
593 |
pannel verticalLayout:#fitSpace. |
|
594 |
||
595 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
596 |
dropObj := DropObject newFile:('.'). |
|
597 |
||
598 |
addButton := [:offset :label :dispObj| |button| |
|
2078 | 599 |
button := Button label:label in:pannel. |
874 | 600 |
|
2078 | 601 |
button pressAction:[ |
602 |
DragAndDropManager startDrag:dropObj from:button offset:offset display:dispObj. |
|
603 |
button turnOff. |
|
604 |
] |
|
874 | 605 |
]. |
606 |
||
607 |
addButton value:#topLeft value:'String' value:'String'. |
|
608 |
addButton value:#topRight value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
609 |
addButton value:#bottomLeft value:'Icon' value:icon. |
|
610 |
addButton value:#bottomRight value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
611 |
addButton value:#center value:'Mixed' value:(Array with:'String' with:icon). |
|
612 |
||
613 |
topView label:'Drag & Drop'. |
|
614 |
topView openWithExtent:200@200. |
|
615 |
" |
|
616 |
! ! |
|
617 |
||
1776 | 618 |
!DragAndDropManager class methodsFor:'simple start-lines'! |
397 | 619 |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
620 |
startArrowDragIn:aView at:dragPoint atEnd:aFourArgBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
621 |
"start a rubber-arrow-line dragging in aView at dragPoint. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
622 |
When finished, evaluate the fourArgBlock with targetView, |
2078 | 623 |
targetID, screenPosition and targetViewPosition as arguments" |
624 |
||
874 | 625 |
^ self new startArrowDragIn:aView at:dragPoint atEnd:aFourArgBlock |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
626 |
|
874 | 627 |
" |
628 |
EXAMPLE: |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
629 |
|
874 | 630 |
|button| |
397 | 631 |
|
874 | 632 |
button := (Button label:'press me'). |
861 | 633 |
|
874 | 634 |
button pressAction:[ |
2078 | 635 |
button turnOff. |
861 | 636 |
|
2078 | 637 |
DragAndDropManager startArrowDragIn:button |
638 |
at:(button preferredExtent // 2) |
|
639 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
640 |
targetView isNil ifTrue:[ |
|
641 |
Transcript show:'alien view' |
|
642 |
] ifFalse:[ |
|
643 |
Transcript showCR:'target: ', targetView printString |
|
644 |
]. |
|
645 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
646 |
Transcript showCR:'point target: ', targetPoint printString. |
|
647 |
] |
|
874 | 648 |
]. |
649 |
button openAt:100@100 |
|
650 |
" |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
651 |
! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
652 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
653 |
startLineDragIn:aView at:dragPoint atEnd:aFourArgBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
654 |
"start a rubber-line dragging in aView at dragPoint. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
655 |
When finished, evaluate the fourArgBlock with targetView, |
2078 | 656 |
targetID, screenPosition and targetViewPosition as arguments" |
657 |
||
874 | 658 |
^ self new startLineDragIn:aView at:dragPoint atEnd:aFourArgBlock |
659 |
||
660 |
" |
|
661 |
EXAMPLE: |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
662 |
|
874 | 663 |
|button| |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
664 |
|
874 | 665 |
button := (Button label:'press me'). |
666 |
||
667 |
button pressAction:[ |
|
2078 | 668 |
button turnOff. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
669 |
|
2078 | 670 |
DragAndDropManager startLineDragIn:button |
671 |
at:(button preferredExtent // 2) |
|
672 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
673 |
targetView isNil ifTrue:[ |
|
674 |
Transcript show:'alien view' |
|
675 |
] ifFalse:[ |
|
676 |
Transcript showCR:'target: ', targetView printString |
|
677 |
]. |
|
678 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
679 |
Transcript showCR:'point target: ', targetPoint printString. |
|
680 |
] |
|
874 | 681 |
]. |
682 |
button openAt:100@100 |
|
683 |
" |
|
397 | 684 |
! ! |
685 |
||
1511 | 686 |
!DragAndDropManager class methodsFor:'translation'! |
687 |
||
688 |
translatePointFromScreen:aPoint toView:aView |
|
2078 | 689 |
"translate a point from screen- to view coordinates" |
690 |
||
1511 | 691 |
|device trans point offset| |
692 |
||
693 |
device := aView device. |
|
694 |
||
695 |
"/ |
|
696 |
"/ translate to view |
|
697 |
"/ |
|
1517
5f4d38273014
use new #translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
1512
diff
changeset
|
698 |
offset := device translatePoint:0@0 fromView:(device rootView) toView:aView. |
1511 | 699 |
point := aPoint + offset. |
700 |
||
701 |
"/ |
|
702 |
"/ get device coordinates |
|
703 |
"/ |
|
704 |
(trans := aView transformation) notNil ifTrue:[ |
|
705 |
point := trans applyInverseTo:point |
|
706 |
]. |
|
707 |
^ point |
|
708 |
! |
|
709 |
||
710 |
translatePointToScreen:aPoint from:aView |
|
2078 | 711 |
"translate a point from view- to screen coordinates" |
712 |
||
1511 | 713 |
|device trans point offset| |
714 |
||
1686 | 715 |
aView isRootView ifTrue:[^ aPoint]. |
1511 | 716 |
device := aView device. |
717 |
"/ |
|
718 |
"/ get device coordinates |
|
719 |
"/ |
|
720 |
(trans := aView transformation) notNil ifTrue:[ |
|
721 |
point := trans applyTo:aPoint |
|
722 |
] ifFalse:[ |
|
723 |
point := aPoint |
|
724 |
]. |
|
725 |
"/ |
|
726 |
"/ translate to screen |
|
727 |
"/ |
|
1517
5f4d38273014
use new #translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
1512
diff
changeset
|
728 |
offset := device translatePoint:0@0 fromView:aView toView:(device rootView). |
1686 | 729 |
^ offset + point |
1511 | 730 |
! ! |
731 |
||
394 | 732 |
!DragAndDropManager methodsFor:'accessing'! |
733 |
||
2091 | 734 |
buttonMotion:button x:x y:y view:aView |
735 |
|device screenPoint oldWidget oldId oldPoint newId newWidget oldTarget newTarget |
|
736 |
isDroppable cursor| |
|
737 |
||
738 |
self isDisabled ifTrue: [ ^ self ]. |
|
739 |
||
740 |
escapePressed == true ifTrue:[ |
|
741 |
self removePassiveAction. |
|
742 |
^ self |
|
743 |
]. |
|
744 |
||
745 |
(dragView notNil and:[dragView sensor motionEventPending]) ifTrue:[ |
|
746 |
^ self |
|
747 |
]. |
|
748 |
self removePassiveAction. |
|
749 |
||
750 |
device := dragView device. |
|
751 |
oldWidget := dropContext targetWidget. |
|
752 |
oldId := dropContext targetId. |
|
753 |
oldPoint := dropContext rootPoint. |
|
754 |
||
755 |
screenPoint := self class translatePointToScreen:(x @ y) from:aView. |
|
756 |
"/ screenPoint := device pointerPosition. |
|
757 |
dropContext rootPoint:screenPoint. |
|
758 |
||
759 |
newId := device viewIdFromPoint:screenPoint. |
|
760 |
newWidget := device viewFromId:newId. |
|
761 |
||
762 |
dropContext rootPoint:screenPoint. |
|
763 |
dropContext targetWidget:newWidget id:newId. |
|
764 |
||
765 |
handler isInterestedInDropTarget ifFalse:[ |
|
766 |
"/ |
|
767 |
"/ line or arrow handler |
|
768 |
"/ |
|
769 |
handler dragTo:screenPoint. |
|
770 |
^ self |
|
771 |
]. |
|
772 |
||
773 |
oldTarget := dropContext dropTarget. |
|
774 |
newTarget := self doFindDropTargetIn:newWidget at:screenPoint. |
|
775 |
||
776 |
newTarget ~= oldTarget ifTrue:[ |
|
777 |
"/ |
|
778 |
"/ drop target changed: handler might restore the screen |
|
779 |
"/ |
|
780 |
handler dropTargetWillChange. |
|
781 |
||
782 |
oldTarget notNil ifTrue:[ |
|
783 |
"/ |
|
784 |
"/ setup old context |
|
785 |
"/ |
|
786 |
dropContext targetWidget:oldWidget id:oldId. |
|
787 |
oldTarget leave:dropContext. |
|
788 |
dropContext targetWidget:newWidget id:newId. |
|
789 |
]. |
|
790 |
dropContext dropTarget:newTarget. |
|
791 |
newTarget notNil ifTrue:[ newTarget enter:dropContext ] |
|
792 |
] ifFalse:[ |
|
793 |
dropContext dropTarget:newTarget |
|
794 |
]. |
|
795 |
||
796 |
"/ |
|
797 |
"/ update the cursor |
|
798 |
"/ |
|
799 |
(isDroppable := dropContext canDrop) ifTrue:[ |
|
800 |
cursor := enabledCursor |
|
801 |
] ifFalse:[ |
|
802 |
dropContext isAlienView ifFalse:[cursor := disabledCursor] |
|
803 |
ifTrue:[cursor := alienCursor] |
|
804 |
]. |
|
805 |
||
806 |
dragView cursor:cursor now:true. |
|
807 |
"/ |
|
808 |
"/ test if droppable state changed |
|
809 |
"/ |
|
810 |
canDrop == isDroppable ifFalse:[ |
|
811 |
"/ |
|
812 |
"/ droppable state changed: handler might restore the screen |
|
813 |
"/ |
|
814 |
canDrop := isDroppable. |
|
815 |
handler dropTargetWillChange |
|
816 |
]. |
|
817 |
||
818 |
newTarget notNil ifTrue:[ newTarget over:dropContext ]. |
|
819 |
handler dragTo:screenPoint. |
|
820 |
! |
|
821 |
||
861 | 822 |
device |
2078 | 823 |
"returns the device of the source view" |
824 |
||
861 | 825 |
^ dragView device |
826 |
! |
|
827 |
||
2042
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
828 |
disabledFlag |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
829 |
^ disabledFlag ? false |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
830 |
! |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
831 |
|
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
832 |
disabledFlag:something |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
833 |
disabledFlag := something. |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
834 |
! |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
835 |
|
2013 | 836 |
dragHandler |
837 |
"returns the current active handler which is responsible for drawing ..." |
|
838 |
||
839 |
^ handler |
|
840 |
! |
|
841 |
||
842 |
dragHandler:aNewHandler |
|
843 |
"set the active handler which is responsible for drawing ..." |
|
844 |
||
845 |
handler := aNewHandler. |
|
846 |
! |
|
847 |
||
874 | 848 |
dropContext |
2078 | 849 |
"return the current context" |
850 |
||
874 | 851 |
^ dropContext |
852 |
! |
|
853 |
||
397 | 854 |
dropObjects |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
855 |
"return the current dropObject collection" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
856 |
|
874 | 857 |
^ dropContext dropObjects |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
858 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
859 |
"Modified: 19.4.1997 / 10:19:06 / cg" |
397 | 860 |
! |
861 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
862 |
dropObjects:aCollectionOfDropObjects |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
863 |
"set the current dropObject collection" |
397 | 864 |
|
874 | 865 |
^ dropContext dropObjects:aCollectionOfDropObjects |
861 | 866 |
! |
867 |
||
868 |
font |
|
2078 | 869 |
"returns the font of the source view" |
870 |
||
861 | 871 |
^ dragView font |
874 | 872 |
! |
873 |
||
2091 | 874 |
isDisabled |
875 |
^ disabledFlag ? false |
|
876 |
! |
|
877 |
||
1661
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
878 |
passiveAction:aBlockOrNil |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
879 |
self removePassiveAction. |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
880 |
aBlockOrNil notNil ifTrue:[ |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
881 |
passiveAction := Processor addTimedBlock:aBlockOrNil afterMilliseconds:100 |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
882 |
]. |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
883 |
! |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
884 |
|
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
885 |
removePassiveAction |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
886 |
passiveAction notNil ifTrue:[ |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
887 |
Processor removeTimeoutWithID:passiveAction. |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
888 |
passiveAction := nil. |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
889 |
]. |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
890 |
! |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
891 |
|
874 | 892 |
sourceWidget |
893 |
^ dragView |
|
894 |
! ! |
|
895 |
||
1397 | 896 |
!DragAndDropManager methodsFor:'accessing-cursor'! |
874 | 897 |
|
898 |
alienCursor:aCursorOrImage |
|
2078 | 899 |
"set the cursor used for an alien widget; not an ST/X view" |
900 |
||
874 | 901 |
aCursorOrImage isImage ifTrue:[ |
2078 | 902 |
alienCursor := Cursor fromImage:aCursorOrImage |
874 | 903 |
] ifFalse:[ |
2078 | 904 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
905 |
alienCursor := aCursorOrImage |
|
906 |
] ifFalse:[ |
|
907 |
"/ |
|
908 |
"/ use disabled cursor |
|
909 |
"/ |
|
910 |
alienCursor := nil |
|
911 |
] |
|
874 | 912 |
] |
913 |
! |
|
914 |
||
915 |
disabledCursor:aCursorOrImage |
|
2078 | 916 |
"set the cursor for an ST/X view, which can not drop the objects" |
917 |
||
874 | 918 |
aCursorOrImage isImage ifTrue:[ |
2078 | 919 |
disabledCursor := Cursor fromImage:aCursorOrImage |
874 | 920 |
] ifFalse:[ |
2078 | 921 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
922 |
disabledCursor := aCursorOrImage |
|
923 |
] |
|
874 | 924 |
] |
925 |
! |
|
926 |
||
927 |
enabledCursor:aCursorOrImage |
|
2078 | 928 |
"set the cursor for an ST/X view, which can drop the objects" |
929 |
||
874 | 930 |
aCursorOrImage isImage ifTrue:[ |
2078 | 931 |
enabledCursor := Cursor fromImage:aCursorOrImage |
874 | 932 |
] ifFalse:[ |
2078 | 933 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
934 |
enabledCursor := aCursorOrImage |
|
935 |
] |
|
874 | 936 |
] |
937 |
! ! |
|
938 |
||
1678 | 939 |
!DragAndDropManager methodsFor:'dragging-drop source'! |
874 | 940 |
|
941 |
startDragFrom:aView dropSource:aDropSource |
|
2078 | 942 |
"start a drag at the current pointer position." |
943 |
||
874 | 944 |
^ self startDragFrom:aView dropSource:aDropSource offset:#topLeft "/ #center |
945 |
! |
|
946 |
||
947 |
startDragFrom:aView dropSource:aDropSource offset:anOffset |
|
2078 | 948 |
"start a drag at the current pointer position." |
949 |
||
874 | 950 |
dropContext dropSource:aDropSource. |
951 |
||
952 |
^ self startDrag:(aDropSource dropObjects) |
|
1718 | 953 |
from:aView |
954 |
offset:anOffset |
|
955 |
atEnd:nil |
|
956 |
display:(aDropSource displayObjects) |
|
874 | 957 |
! ! |
958 |
||
1678 | 959 |
!DragAndDropManager methodsFor:'dragging-easy startup'! |
874 | 960 |
|
961 |
startDrag:draggableObjects from:aView |
|
2078 | 962 |
"start a drop at the current pointer position" |
963 |
||
874 | 964 |
^ self startDrag:draggableObjects |
2078 | 965 |
from:aView |
966 |
offset:0@0 |
|
874 | 967 |
! |
968 |
||
969 |
startDrag:draggableObjects from:aView display:something |
|
2078 | 970 |
"start a drop at the current pointer position." |
971 |
||
874 | 972 |
^ self startDrag:draggableObjects |
2078 | 973 |
from:aView |
974 |
offset:nil |
|
975 |
atEnd:nil |
|
976 |
display:something |
|
874 | 977 |
! |
978 |
||
979 |
startDrag:draggableObjects from:aView offset:anOffset |
|
2078 | 980 |
"start a drop at the current pointer position with an offset" |
981 |
||
874 | 982 |
^ self startDrag:draggableObjects |
2078 | 983 |
from:aView |
984 |
offset:anOffset |
|
985 |
atEnd:nil |
|
874 | 986 |
! |
987 |
||
988 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock |
|
989 |
"start a drop at the current pointer position. |
|
990 |
When finished, the endAction is called with four args: |
|
991 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
2078 | 992 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
993 |
||
874 | 994 |
^ self startDrag:draggableObjects |
2078 | 995 |
from:aView |
996 |
offset:anOffset |
|
997 |
atEnd:aFourArgEndBlock |
|
998 |
display:draggableObjects |
|
874 | 999 |
! |
1000 |
||
1001 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgBlock display:something |
|
1002 |
"start a drop at the current pointer position. |
|
1003 |
When finished, the endAction is called with four args: |
|
1004 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
2078 | 1005 |
the dropPoint in root-coordinates and the dropPoint within the targetView." |
1006 |
||
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1007 |
|height width fontWdt offset ascent device dispObjs list space| |
874 | 1008 |
|
1009 |
self dropObjects:draggableObjects. |
|
1010 |
||
1011 |
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
|
1012 |
^ self |
874 | 1013 |
]. |
1014 |
||
1015 |
device := aView device. |
|
1016 |
space := 1. |
|
1017 |
height := space negated. |
|
1018 |
width := 0. |
|
1019 |
fontWdt := aView font width. |
|
1020 |
ascent := aView font ascent. |
|
1021 |
||
1022 |
(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
|
1023 |
list := self dropObjects |
874 | 1024 |
] ifFalse:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1025 |
(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
|
1026 |
list := Array with:something |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1027 |
] |
874 | 1028 |
]. |
1029 |
dispObjs := OrderedCollection new. |
|
1030 |
||
1031 |
list do:[:el| |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1032 |
|obj asc| |
874 | 1033 |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1034 |
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
|
1035 |
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
|
1036 |
height := height + space. |
874 | 1037 |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1038 |
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
|
1039 |
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
|
1040 |
height := height + (obj heightOn:aView). |
874 | 1041 |
]. |
1042 |
||
881 | 1043 |
anOffset isSymbol ifTrue:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1044 |
offset := (0@0 extent:(width @ height)) perform:anOffset. |
881 | 1045 |
] ifFalse:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1046 |
offset := anOffset ? (0@0). |
881 | 1047 |
]. |
1048 |
offset := offset rounded. |
|
874 | 1049 |
|
1050 |
dispObjs do:[:el| el at:2 put:((el at:2) - offset) ]. |
|
1051 |
||
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1052 |
self startOpaqueDrag:[:p :v| |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1053 |
|cursor hX hY pDraw| |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1054 |
|
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1055 |
cursor := dragView cursor. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1056 |
hX := cursor hotX. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1057 |
hY := cursor hotY. |
1497
dff682eb74fc
avoid jumping icon while moving
Claus Gittinger <cg@exept.de>
parents:
1490
diff
changeset
|
1058 |
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
|
1059 |
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
|
1060 |
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
|
1061 |
] |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1062 |
] |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1063 |
offset:offset |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1064 |
extent:width @ height |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1065 |
in:aView |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1066 |
at:nil |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1067 |
atEnd:aFourArgBlock |
881 | 1068 |
|
1069 |
"Modified: / 31.3.1998 / 11:18:04 / cg" |
|
874 | 1070 |
! |
1071 |
||
1072 |
startDrag:draggableObjects from:aView offset:anOffset display:something |
|
2078 | 1073 |
"start a drop at the current pointer position." |
1074 |
||
874 | 1075 |
^ self startDrag:draggableObjects |
2078 | 1076 |
from:aView |
1077 |
offset:anOffset |
|
1078 |
atEnd:nil |
|
1079 |
display:something |
|
394 | 1080 |
! ! |
1081 |
||
1678 | 1082 |
!DragAndDropManager methodsFor:'dragging-generic'! |
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
1083 |
|
348 | 1084 |
startGenericDrag:aTwoArgDragBlock in:aView at:p atEnd:aFourArgEndBlock |
1085 |
"start a generic (caller-provided drag); |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1086 |
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
|
1087 |
by inverting again). See startOpaqueDrag for another variant. |
348 | 1088 |
the dragBlock, aTwoArgDragBlock will be called with two args |
1089 |
aPoint and a drawingGC, to perform the drawing at some dragPoint. |
|
1090 |
The drag starts in aView at point p. |
|
1091 |
When finished, the endAction is called with four args: |
|
1092 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
2078 | 1093 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
1094 |
||
874 | 1095 |
^ self startOpaqueDrag:aTwoArgDragBlock |
2078 | 1096 |
offset:nil |
1097 |
extent:nil |
|
1098 |
in:aView |
|
1099 |
at:nil |
|
1100 |
atEnd:aFourArgEndBlock |
|
394 | 1101 |
! |
1102 |
||
874 | 1103 |
startOpaqueDrag:aDragBlock offset:offs extent:anExtent in:aView at:aDummyPoint atEnd:aFourArgEndBlock |
1104 |
"start an opaque or generic opaque (caller-provided drag); |
|
394 | 1105 |
opaque drag means, that the drawing cannot be undone by two inverting |
1106 |
draws, but instead, the area under the dragged object must be saved |
|
874 | 1107 |
and restored. The areas size to be saved/restored is passed in anExtent. |
1108 |
the dragBlock, aDragBlock will be called with up to three args aPoint, a |
|
1109 |
drawingGC and the display objects, to perform the drawing at some dragPoint. |
|
394 | 1110 |
The drag starts in aView at point p. |
1111 |
When finished, the endAction is called with four args: |
|
1112 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
2078 | 1113 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
1114 |
||
874 | 1115 |
|handler numArgs dragBlock dobjs| |
394 | 1116 |
|
874 | 1117 |
dragOffset := offs ? (Point x:0 y:0). |
1118 |
numArgs := aDragBlock numArgs. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1119 |
|
874 | 1120 |
numArgs == 3 ifTrue:[ |
1289 | 1121 |
dobjs := self dropObjects. |
1122 |
dragBlock := [:p :v| aDragBlock value:p value:v value:dobjs ] |
|
874 | 1123 |
] ifFalse:[ |
1289 | 1124 |
numArgs == 1 ifTrue:[ |
1125 |
dragBlock := [:p :v| aDragBlock value:p ] |
|
1126 |
] ifFalse:[ |
|
1127 |
dragBlock := aDragBlock |
|
1128 |
] |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1129 |
]. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1130 |
|
874 | 1131 |
anExtent isNil ifTrue:[ |
1289 | 1132 |
handler := DragHandler startGenericDrag:dragBlock. |
874 | 1133 |
] ifFalse:[ |
1289 | 1134 |
handler := DragHandler startOpaqueDrag:dragBlock extent:anExtent offset:dragOffset. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1135 |
]. |
1289 | 1136 |
self doStart:handler for:aView atEnd:aFourArgEndBlock. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1137 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1138 |
|
1678 | 1139 |
!DragAndDropManager methodsFor:'dragging-lines'! |
341 | 1140 |
|
874 | 1141 |
startArrowDragIn:aView at:aStartPoint atEnd:aFourArgEndBlock |
1142 |
"start a line-drag of an arrow-line. |
|
1143 |
The drag starts in aView at point aStartPoint. |
|
1144 |
When finished, the endAction is called with four args: |
|
1145 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
2078 | 1146 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
1147 |
||
874 | 1148 |
|p| |
341 | 1149 |
|
1511 | 1150 |
p := self class translatePointToScreen:aStartPoint from:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1151 |
|
874 | 1152 |
self doStart:(DragHandler startArrowDragAt:p) |
1511 | 1153 |
for:aView |
1154 |
atEnd:aFourArgEndBlock |
|
341 | 1155 |
! |
1156 |
||
874 | 1157 |
startLineDragIn:aView at:aStartPoint atEnd:aFourArgEndBlock |
1158 |
"start a line-drag of a normal line. |
|
1159 |
The drag starts in aView at point aStartPoint. |
|
348 | 1160 |
When finished, the endAction is called with four args: |
1161 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
2078 | 1162 |
the dropPoint in root-coordinates and the dropPoint within the targetView" |
1163 |
||
874 | 1164 |
|p| |
341 | 1165 |
|
1511 | 1166 |
p := self class translatePointToScreen:aStartPoint from:aView. |
348 | 1167 |
|
874 | 1168 |
self doStart:(DragHandler startLineDragAt:p) |
1511 | 1169 |
for:aView |
1170 |
atEnd:aFourArgEndBlock |
|
341 | 1171 |
! ! |
1172 |
||
397 | 1173 |
!DragAndDropManager methodsFor:'drawing'! |
1174 |
||
874 | 1175 |
displayObjectFor:anObject on:aDevice |
2078 | 1176 |
"converts an object to a display object" |
1177 |
||
1572 | 1178 |
|obj s1 s2| |
874 | 1179 |
|
1180 |
obj := (anObject respondsTo:#displayObject) ifTrue:[anObject displayObject] |
|
1572 | 1181 |
ifFalse:[anObject]. |
874 | 1182 |
|
1183 |
obj isString ifTrue:[ |
|
1572 | 1184 |
^ obj |
874 | 1185 |
]. |
1186 |
||
1582 | 1187 |
MessageNotUnderstood |
1188 |
ignoreNotUnderstoodOf:#'onDevice:' |
|
1189 |
in:[ |
|
1190 |
obj := obj onDevice:aDevice |
|
1191 |
]. |
|
874 | 1192 |
|
1193 |
obj isImage ifTrue:[ |
|
1572 | 1194 |
^ obj clearMaskedPixels |
874 | 1195 |
]. |
1196 |
||
1197 |
obj class == LabelAndIcon ifTrue:[ |
|
1572 | 1198 |
obj image notNil ifTrue:[obj image clearMaskedPixels]. |
1199 |
obj icon notNil ifTrue:[obj icon clearMaskedPixels]. |
|
1823 | 1200 |
^ obj |
874 | 1201 |
]. |
1202 |
||
1203 |
(obj class == MultiColListEntry) ifFalse:[ |
|
1572 | 1204 |
^ obj |
874 | 1205 |
]. |
1206 |
s1 := obj colAt:1. |
|
1207 |
s2 := obj colAt:2. |
|
1208 |
||
1209 |
s1 isImage ifTrue:[ |
|
1572 | 1210 |
s2 isImage ifTrue:[ ^ self displayObjectFor:(LabelAndIcon form:s1 image:s2) on:aDevice ]. |
1211 |
s2 isString ifTrue:[ ^ self displayObjectFor:(LabelAndIcon icon:s1 string:s2) on:aDevice ]. |
|
1212 |
^ (s1 on:aDevice) clearMaskedPixels |
|
874 | 1213 |
]. |
1214 |
||
1215 |
s2 isImage ifTrue:[ |
|
1572 | 1216 |
s1 isString ifTrue:[ ^ self displayObjectFor:(LabelAndIcon icon:s2 string:s1) on:aDevice ]. |
1217 |
^ (s2 on:aDevice) clearMaskedPixels |
|
874 | 1218 |
]. |
1219 |
||
1220 |
s1 isString ifTrue:[^ s1]. |
|
1221 |
s2 isString ifTrue:[^ s2]. |
|
1823 | 1222 |
^ obj |
874 | 1223 |
! |
1224 |
||
397 | 1225 |
showDragging:items in:aView at:p |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1226 |
"helper for dragging dragObjects: draw them all" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1227 |
|
397 | 1228 |
|offs| |
1229 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1230 |
offs := 0. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1231 |
items do:[:item | |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1232 |
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
|
1233 |
offs := offs + (item heightOn:self) |
397 | 1234 |
] |
1235 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1236 |
"Modified: 19.4.1997 / 12:41:24 / cg" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1237 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1238 |
|
341 | 1239 |
!DragAndDropManager methodsFor:'event catching'! |
1240 |
||
1686 | 1241 |
buttonRelease:button x:x y:y view:aView |
2063 | 1242 |
|targetWidget| |
874 | 1243 |
|
1686 | 1244 |
((button == 1) or:[button == #select]) ifFalse:[ |
1619 | 1245 |
^ self |
874 | 1246 |
]. |
1686 | 1247 |
self removePassiveAction. |
1661
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
1248 |
|
1686 | 1249 |
restoreBlock value. "/ restore context before start drag |
394 | 1250 |
|
2061
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1251 |
escapePressed == true ifTrue:[^ self]. |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1252 |
|
2063 | 1253 |
targetWidget := dropContext targetWidget. |
2061
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1254 |
dropAction notNil ifTrue:[ |
1619 | 1255 |
"/ |
2061
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1256 |
"/ initiator wants to do it himself, manually. |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1257 |
"/ Thus, no feedBack operation invoked. |
1619 | 1258 |
"/ |
2063 | 1259 |
dropAction value:(targetWidget) |
2061
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1260 |
value:(dropContext targetId) |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1261 |
value:(dropContext rootPoint) |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1262 |
value:(dropContext targetPoint). |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1263 |
] ifFalse:[ |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1264 |
dropContext doDrop |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1265 |
]. |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1266 |
|
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1267 |
"/ UI feels better, if the focus is assigned to the target view, |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1268 |
"/ if click-for-focus is on. |
2062 | 1269 |
"/ CG: no - do it always |
1270 |
"/ UserPreferences current focusFollowsMouse == false ifTrue:[ |
|
1271 |
"/ dropContext targetWidget wantsFocusWithButtonPress ifTrue:[ |
|
1272 |
"/ dropContext targetWidget requestFocus |
|
1273 |
"/ ]. |
|
1274 |
"/ ]. |
|
2093
d29474de6ab5
care for widget beeing destroyed during drop-action
Claus Gittinger <cg@exept.de>
parents:
2091
diff
changeset
|
1275 |
(targetWidget notNil and:[targetWidget shown]) ifTrue:[ |
2133
0581d9906df0
common behavior for windows and unix:
Stefan Vogel <sv@exept.de>
parents:
2093
diff
changeset
|
1276 |
targetWidget topView raise; activate. |
2063 | 1277 |
targetWidget takeFocus. |
1278 |
]. |
|
1289 | 1279 |
! |
1280 |
||
1685 | 1281 |
escapePressed |
2078 | 1282 |
"handle the escape key" |
1283 |
||
1685 | 1284 |
|dropTarget| |
1285 |
||
1286 |
escapePressed ~~ true ifTrue:[ |
|
1287 |
escapePressed := true. |
|
1288 |
||
1289 |
handler notNil ifTrue:[ |
|
1290 |
"/ restore handler |
|
1291 |
dropTarget := dropContext dropTarget. |
|
1292 |
handler postDragging. |
|
1293 |
||
1294 |
dropTarget notNil ifTrue:[ |
|
1295 |
"/ invoke leave operation |
|
1296 |
dropTarget leave:dropContext. |
|
1297 |
dropContext dropTarget:nil. |
|
1298 |
]. |
|
1299 |
]. |
|
1300 |
]. |
|
1301 |
! |
|
1302 |
||
1686 | 1303 |
keyPress:aKey x:x y:y view:aView |
2069 | 1304 |
"stop the drag operation, when the escape key is pressed" |
874 | 1305 |
|
2070 | 1306 |
<resource: #keyboard (#Escape)> |
1307 |
||
1686 | 1308 |
escapePressed == true ifTrue:[ ^ self ]. "/ ignorred, escaped was pressed |
1629
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1309 |
|
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1310 |
aKey == #Escape ifTrue:[ |
1685 | 1311 |
self escapePressed. |
1619 | 1312 |
]. |
1686 | 1313 |
! |
1314 |
||
1834 | 1315 |
processAutoScroll |
2078 | 1316 |
"process an autoScroll event" |
1317 |
||
1834 | 1318 |
|targetWidget targetPoint| |
1319 |
||
1320 |
self isActive ifFalse:[^ self]. |
|
1321 |
||
1322 |
dropContext isNil ifTrue:[ ^ self ]. |
|
1323 |
||
1324 |
targetWidget := dropContext targetWidget. |
|
1325 |
targetWidget isNil ifTrue:[ ^ self ]. |
|
1835
d6db8466019b
bugfix in scrolling during drag & drop; test for isRootView
ca
parents:
1834
diff
changeset
|
1326 |
targetWidget isRootView ifTrue:[ ^ self ]. |
1834 | 1327 |
|
1328 |
targetPoint := dropContext targetPoint. |
|
1329 |
targetPoint isNil ifTrue:[ ^ self ]. |
|
1330 |
||
1331 |
(targetWidget dragAutoScroll: dropContext) ifFalse:[ |
|
1332 |
^ self |
|
1333 |
]. |
|
1334 |
self buttonMotion:256 x:(targetPoint x) y:(targetPoint y) view:targetWidget. |
|
1335 |
! |
|
1336 |
||
1686 | 1337 |
processEvent:event |
2022 | 1338 |
"filter keyboard events. |
1339 |
Return true, if I have eaten the event" |
|
1340 |
||
1686 | 1341 |
|evView| |
1342 |
||
1343 |
restoreBlock isNil ifTrue:[^ false]. "/ should not happen |
|
1344 |
||
1345 |
evView := event view. |
|
1346 |
evView isNil ifTrue:[^ false]. |
|
1347 |
||
1348 |
event isInputEvent ifFalse:[ |
|
1349 |
^ false |
|
1350 |
]. |
|
1351 |
||
1352 |
event isKeyEvent ifTrue:[ |
|
1353 |
self keyPress:(event key) x:(event x) y:(event y) view:evView. |
|
1354 |
^ true |
|
1355 |
]. |
|
1356 |
||
1357 |
event isButtonMotionEvent ifTrue:[ |
|
1358 |
self buttonMotion:(event state) x:(event x) y:(event y) view:evView. |
|
1359 |
] ifFalse:[ |
|
1360 |
event isButtonReleaseEvent ifTrue:[ |
|
1361 |
self buttonRelease:(event button) x:(event x) y:(event y) view:evView. |
|
1362 |
] |
|
1363 |
]. |
|
1364 |
^ true |
|
874 | 1365 |
! ! |
1366 |
||
1367 |
!DragAndDropManager methodsFor:'initialization'! |
|
341 | 1368 |
|
874 | 1369 |
initialize |
1370 |
super initialize. |
|
394 | 1371 |
|
874 | 1372 |
dragOffset := 0 @ 0. |
1373 |
dropContext := DropContext new. |
|
1618 | 1374 |
dropContext manager:self. |
874 | 1375 |
alienCursor := Cursor questionMark. |
1376 |
enabledCursor := Cursor thumbsUp. |
|
1377 |
disabledCursor := Cursor thumbsDown. |
|
1378 |
canDrop := false. |
|
341 | 1379 |
! ! |
1380 |
||
1381 |
!DragAndDropManager methodsFor:'private'! |
|
1382 |
||
874 | 1383 |
doDrop:aContext in:aWidget |
2078 | 1384 |
"old drop mechanism" |
1385 |
||
874 | 1386 |
|point| |
628 | 1387 |
|
1511 | 1388 |
DragContextQuerySignal answer:aContext do:[ |
1389 |
DragOriginatorQuerySignal answer:dragView do:[ |
|
2255 | 1390 |
DragOffsetQuerySignal answer:dragOffset do:[ |
1391 |
|targetWidget targetPoint| |
|
1392 |
||
2025 | 1393 |
targetWidget := aContext targetWidget. |
1394 |
targetPoint := aContext targetPoint. |
|
1395 |
||
1396 |
targetWidget == aWidget ifTrue:[ |
|
1397 |
point := targetPoint. |
|
1511 | 1398 |
] ifFalse:[ |
2025 | 1399 |
point := targetWidget originRelativeTo:aWidget. |
1400 |
||
1401 |
point isNil ifTrue:[ |
|
1402 |
point := 0@0. |
|
1403 |
] ifFalse:[ |
|
1404 |
point := point + targetPoint. |
|
1405 |
]. |
|
1511 | 1406 |
"/ |
1407 |
"/ FeedBack: set the widget which handles the drop |
|
1408 |
"/ |
|
1409 |
aContext targetWidget:aWidget id:(aWidget id). |
|
1410 |
]. |
|
2254 | 1411 |
aWidget dropObjects:(aContext dropObjects) at:point |
1511 | 1412 |
] |
1413 |
]. |
|
609
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1414 |
]. |
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1415 |
|
2255 | 1416 |
"Modified: / 13-10-2006 / 17:52:56 / cg" |
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
1417 |
! |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
1418 |
|
874 | 1419 |
doFindDropTargetIn:aView at:aPoint |
2078 | 1420 |
"get the drop target for a view and source at a point or nil" |
628 | 1421 |
|
2091 | 1422 |
|target| |
1423 |
||
2133
0581d9906df0
common behavior for windows and unix:
Stefan Vogel <sv@exept.de>
parents:
2093
diff
changeset
|
1424 |
aView isNil ifTrue:[ |
0581d9906df0
common behavior for windows and unix:
Stefan Vogel <sv@exept.de>
parents:
2093
diff
changeset
|
1425 |
^ nil |
0581d9906df0
common behavior for windows and unix:
Stefan Vogel <sv@exept.de>
parents:
2093
diff
changeset
|
1426 |
]. |
1582 | 1427 |
|
2133
0581d9906df0
common behavior for windows and unix:
Stefan Vogel <sv@exept.de>
parents:
2093
diff
changeset
|
1428 |
"new mechanism to get a dropTarget" |
2091 | 1429 |
target := aView dropTarget. |
1430 |
target notNil ifTrue:[ |
|
1431 |
^ target |
|
1432 |
]. |
|
1582 | 1433 |
|
2133
0581d9906df0
common behavior for windows and unix:
Stefan Vogel <sv@exept.de>
parents:
2093
diff
changeset
|
1434 |
"old mechanism to get a dropTarget" |
0581d9906df0
common behavior for windows and unix:
Stefan Vogel <sv@exept.de>
parents:
2093
diff
changeset
|
1435 |
|
2091 | 1436 |
(SignalSet |
1437 |
with:DragContextQuerySignal |
|
1438 |
with:DragOriginatorQuerySignal |
|
1439 |
with:DragOffsetQuerySignal) |
|
1440 |
handle:[:ex | |
|
1441 |
ex signal == DragContextQuerySignal ifTrue:[ ex proceedWith:dropContext]. |
|
1442 |
ex signal == DragOriginatorQuerySignal ifTrue:[ ex proceedWith:dragView]. |
|
1443 |
ex signal == DragOffsetQuerySignal ifTrue:[ ex proceedWith:dragOffset]. |
|
2133
0581d9906df0
common behavior for windows and unix:
Stefan Vogel <sv@exept.de>
parents:
2093
diff
changeset
|
1444 |
self error:'unexpected query'. |
2091 | 1445 |
] do:[ |
1446 |
|view dobj| |
|
1587 | 1447 |
|
2091 | 1448 |
view := aView. |
1449 |
dobj := dropContext dropObjects. |
|
1450 |
[ |
|
2255 | 1451 |
(view canDrop:dropContext "dobj") ifTrue:[ |
2091 | 1452 |
^ DropTarget receiver:self argument:view dropSelector:#doDrop:in:. |
1453 |
]. |
|
1454 |
(view := view superView) notNil |
|
1455 |
] whileTrue. |
|
874 | 1456 |
]. |
1457 |
^ nil |
|
2255 | 1458 |
|
1459 |
"Modified: / 13-10-2006 / 17:50:32 / cg" |
|
874 | 1460 |
! |
628 | 1461 |
|
874 | 1462 |
doStart:aHandler for:aView atEnd:aFourArgEndBlock |
2078 | 1463 |
"setup a handler and a restore block" |
1464 |
||
1749
1f58fbcd4b96
Use SynchronousWindoeSensor if no windowGroup
Stefan Vogel <sv@exept.de>
parents:
1718
diff
changeset
|
1465 |
|device lastActive windowGroup savedCursor screenPoint| |
628 | 1466 |
|
1512 | 1467 |
device := aView device. |
1685 | 1468 |
lastActive := ActiveDragAndDropManagers at:device ifAbsent:nil. |
1469 |
||
1470 |
lastActive notNil ifTrue:[ |
|
1471 |
"/ self error:'oops - two dnd managers active' mayProceed:true. |
|
1472 |
||
1473 |
lastActive forceGiveUp. |
|
1939 | 1474 |
'DragAndDropManager [info]: oops - two dnd managers active' infoPrintCR. |
1487 | 1475 |
]. |
1512 | 1476 |
ActiveDragAndDropManagers at:device put:self. |
1487 | 1477 |
|
874 | 1478 |
dropContext sourceWidget:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1479 |
|
874 | 1480 |
dragOffset isNil ifTrue:[ dragOffset := 0 @ 0 ]. |
1481 |
alienCursor isNil ifTrue:[ alienCursor := disabledCursor ]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1482 |
|
1686 | 1483 |
dragView := aView. |
1484 |
dropAction := aFourArgEndBlock. |
|
2091 | 1485 |
windowGroup := aView windowGroup. |
1619 | 1486 |
handler := aHandler. |
1487 |
escapePressed := false. |
|
609
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1488 |
|
1162
0539b64679ce
set DragHandler in the DropContext
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1489 |
dropContext dragHandler:aHandler. |
1686 | 1490 |
|
1689
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1491 |
savedCursor := dragView cursor. |
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1492 |
windowGroup addPreEventHook:self. |
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1493 |
windowGroup addPostEventHook:self. |
1162
0539b64679ce
set DragHandler in the DropContext
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1494 |
|
874 | 1495 |
restoreBlock := [ |
1686 | 1496 |
restoreBlock := nil. |
1497 |
||
1834 | 1498 |
autoScrollTask notNil ifTrue:[ |
1499 |
autoScrollTask terminate. |
|
1500 |
autoScrollTask := nil. |
|
1501 |
]. |
|
1502 |
||
1512 | 1503 |
ActiveDragAndDropManagers removeKey:device ifAbsent:nil. |
1686 | 1504 |
escapePressed ifFalse:[ aHandler postDragging ]. |
1505 |
||
1689
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1506 |
windowGroup removePreEventHook:self. |
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1507 |
windowGroup removePostEventHook:self. |
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1508 |
dragView cursor:savedCursor. |
874 | 1509 |
]. |
1686 | 1510 |
aHandler preDraggingIn:dragView. |
1289 | 1511 |
|
1512 |
"/ must wait for all pending motion events to arrive, and ignore them |
|
1749
1f58fbcd4b96
Use SynchronousWindoeSensor if no windowGroup
Stefan Vogel <sv@exept.de>
parents:
1718
diff
changeset
|
1513 |
device sync. |
1f58fbcd4b96
Use SynchronousWindoeSensor if no windowGroup
Stefan Vogel <sv@exept.de>
parents:
1718
diff
changeset
|
1514 |
dragView sensor flushMotionEventsFor:nil. |
1289 | 1515 |
|
2091 | 1516 |
autoScrollTask := |
1517 |
[ |
|
1518 |
[ |sensor| |
|
1834 | 1519 |
|
2091 | 1520 |
sensor := windowGroup sensor. |
1834 | 1521 |
|
2091 | 1522 |
[ self isActive ] whileTrue:[ |
1523 |
Delay waitForMilliseconds:(self class autoScrollDelayTimeMs). |
|
1834 | 1524 |
|
2091 | 1525 |
self isActive ifTrue:[ |
1526 |
sensor pushUserEvent:#processAutoScroll for:self. |
|
1527 |
]. |
|
1834 | 1528 |
]. |
2091 | 1529 |
]ensure:[ |
1530 |
autoScrollTask := nil. |
|
1531 |
] |
|
1532 |
] newProcess. |
|
1834 | 1533 |
|
2091 | 1534 |
autoScrollTask priority:(Processor userSchedulingPriority). |
1834 | 1535 |
autoScrollTask name:'Drag-AutoScroll'. |
1536 |
autoScrollTask resume. |
|
1537 |
||
1289 | 1538 |
"/ start with a first draw at the current mouse position |
1686 | 1539 |
screenPoint := device pointerPosition. |
1540 |
self buttonMotion:1 x:(screenPoint x) y:(screenPoint y) view:(device rootView). |
|
1487 | 1541 |
! |
1542 |
||
1685 | 1543 |
forceGiveUp |
1544 |
"called if the DragAndDropManager no longer should be |
|
2078 | 1545 |
active; a second one is started" |
1546 |
||
1685 | 1547 |
self escapePressed. |
1548 |
self removePassiveAction. |
|
1549 |
restoreBlock value. |
|
1550 |
! |
|
1551 |
||
1834 | 1552 |
isActive |
2078 | 1553 |
"returns true if a drag operation is active" |
1554 |
||
1834 | 1555 |
restoreBlock isNil ifTrue:[ ^ false ]. |
1556 |
^ escapePressed ~~ true |
|
1557 |
! |
|
1558 |
||
1487 | 1559 |
saveDraw:aBlock |
1560 |
handler postDragging. |
|
1561 |
aBlock value. |
|
1638 | 1562 |
|
1563 |
escapePressed == true ifFalse:[ |
|
1564 |
"/ reread and show drag items |
|
1565 |
handler rereadSaveArea. |
|
1566 |
handler restoreFromSaveArea. |
|
1567 |
]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1568 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1569 |
|
341 | 1570 |
!DragAndDropManager class methodsFor:'documentation'! |
1571 |
||
1572 |
version |
|
2255 | 1573 |
^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.72 2006-10-13 15:57:55 cg Exp $' |
341 | 1574 |
! ! |
1629
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1575 |
|
628 | 1576 |
DragAndDropManager initialize! |