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