author | Claus Gittinger <cg@exept.de> |
Thu, 22 Dec 2005 18:41:12 +0100 | |
changeset 2075 | c24b6c2c88a6 |
parent 2070 | 869e370ce441 |
child 2078 | 152102d2d8a0 |
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 |
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
275 |
"time measured in milli-seconds the the autoscroll task is delayed |
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 |
^ 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 |
|
329 |
"start a drop at the current pointer position. |
|
330 |
" |
|
331 |
^ (self new) startDragFrom:aView dropSource:aDropSource |
|
332 |
! ! |
|
333 |
||
1776 | 334 |
!DragAndDropManager class methodsFor:'simple start-generic'! |
874 | 335 |
|
336 |
startDrag:draggableObjects from:aView |
|
337 |
"start a drop at the current pointer position |
|
338 |
" |
|
339 |
^ self startDrag:draggableObjects |
|
1166 | 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:[ |
|
1166 | 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), |
|
365 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
366 |
" |
|
367 |
^ self startDrag:draggableObjects |
|
1166 | 368 |
from:aView |
369 |
offset:0@0 |
|
370 |
atEnd:aFourArgEndBlock |
|
371 |
display:draggableObjects |
|
874 | 372 |
|
373 |
" |
|
374 |
EXAMPLE: |
|
375 |
||
376 |
|button| |
|
377 |
||
378 |
button := (Button label:'press me'). |
|
379 |
||
380 |
button pressAction:[ |
|
1166 | 381 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
382 |
from:button |
|
383 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
384 |
Transcript showCR:'target view: ', targetView printString. |
|
385 |
Transcript showCR:'target id: ', targetViewId printString. |
|
386 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
387 |
Transcript showCR:'point target: ', targetPoint printString. |
|
388 |
]. |
|
389 |
button turnOff |
|
874 | 390 |
]. |
391 |
||
392 |
button openAt:100@100 |
|
393 |
" |
|
394 |
||
395 |
! |
|
396 |
||
397 |
startDrag:draggableObjects from:aView atEnd:aFourArgEndBlock display:something |
|
398 |
"start a drop at the current pointer position |
|
399 |
When finished, the endAction is called with four args: |
|
400 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
401 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
402 |
" |
|
403 |
^ self startDrag:draggableObjects |
|
1166 | 404 |
from:aView |
405 |
offset:0@0 |
|
406 |
atEnd:aFourArgEndBlock |
|
407 |
display:something |
|
874 | 408 |
|
409 |
" |
|
410 |
EXAMPLE: |
|
411 |
||
412 |
|button| |
|
413 |
||
414 |
button := (Button label:'press me'). |
|
415 |
||
416 |
button pressAction:[ |
|
1166 | 417 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
418 |
from:button |
|
419 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
420 |
Transcript showCR:'target view: ', targetView printString. |
|
421 |
Transcript showCR:'target id: ', targetViewId printString. |
|
422 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
423 |
Transcript showCR:'point target: ', targetPoint printString. |
|
424 |
] |
|
425 |
display:(Array with:'String' with:(Image fromFile:('xpmBitmaps/QUESTION3.xpm'))). |
|
426 |
button turnOff |
|
874 | 427 |
]. |
428 |
||
429 |
button openAt:100@100 |
|
430 |
" |
|
431 |
! |
|
432 |
||
433 |
startDrag:draggableObjects from:aView display:something |
|
434 |
"start a drop at the current pointer position |
|
435 |
" |
|
436 |
^ self startDrag:draggableObjects |
|
1166 | 437 |
from:aView |
438 |
offset:0@0 |
|
439 |
atEnd:nil |
|
440 |
display:something |
|
874 | 441 |
|
442 |
" |
|
443 |
EXAMPLE: |
|
444 |
||
445 |
|dropObj topView pannel icon buttonAction addButton| |
|
446 |
||
447 |
topView := StandardSystemView new. |
|
448 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
449 |
pannel horizontalLayout:#fit. |
|
450 |
pannel verticalLayout:#fitSpace. |
|
451 |
||
452 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
453 |
dropObj := DropObject newFile:('.'). |
|
454 |
||
455 |
addButton := [:label :dispObj| |button| |
|
1166 | 456 |
button := Button label:label in:pannel. |
874 | 457 |
|
1166 | 458 |
button pressAction:[ |
459 |
DragAndDropManager startDrag:dropObj from:button display:dispObj. |
|
460 |
button turnOff. |
|
461 |
] |
|
874 | 462 |
]. |
463 |
||
464 |
addButton value:'String' value:'String'. |
|
465 |
addButton value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
466 |
addButton value:'Icon' value:icon. |
|
467 |
addButton value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
468 |
addButton value:'Mixed' value:(Array with:'String' with:icon). |
|
469 |
||
470 |
topView label:'Drag & Drop'. |
|
471 |
topView openWithExtent:200@200. |
|
472 |
" |
|
473 |
! |
|
474 |
||
475 |
startDrag:draggableObjects from:aView offset:anOffset |
|
476 |
"start a drop at the current pointer position |
|
477 |
" |
|
478 |
^ self startDrag:draggableObjects |
|
1166 | 479 |
from:aView |
480 |
offset:anOffset |
|
481 |
atEnd:nil |
|
482 |
display:draggableObjects |
|
874 | 483 |
|
484 |
" |
|
485 |
EXAMPLE: |
|
486 |
||
487 |
|button| |
|
488 |
||
489 |
button := (Button label:'press me'). |
|
490 |
||
491 |
button pressAction:[ |
|
1166 | 492 |
DragAndDropManager startDrag:(DropObject newFile:('.')) from:button offset:(-10 @ -10). |
493 |
button turnOff |
|
874 | 494 |
]. |
495 |
||
496 |
button openAt:100@100 |
|
497 |
" |
|
498 |
||
499 |
! |
|
500 |
||
501 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock |
|
502 |
"start a drop at the current pointer position |
|
503 |
When finished, the endAction is called with four args: |
|
504 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
505 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
506 |
" |
|
507 |
^ self startDrag:draggableObjects |
|
1166 | 508 |
from:aView |
509 |
offset:anOffset |
|
510 |
atEnd:aFourArgEndBlock |
|
511 |
display:draggableObjects |
|
874 | 512 |
|
513 |
" |
|
514 |
EXAMPLE: |
|
515 |
||
516 |
|button| |
|
517 |
||
518 |
button := (Button label:'press me'). |
|
519 |
||
520 |
button pressAction:[ |
|
1166 | 521 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
522 |
from:button |
|
523 |
offset:(-10 @ -10) |
|
524 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
525 |
Transcript showCR:'target view: ', targetView printString. |
|
526 |
Transcript showCR:'target id: ', targetViewId printString. |
|
527 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
528 |
Transcript showCR:'point target: ', targetPoint printString. |
|
529 |
]. |
|
530 |
button turnOff |
|
874 | 531 |
]. |
532 |
||
533 |
button openAt:100@100 |
|
534 |
" |
|
535 |
||
536 |
! |
|
537 |
||
538 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock display:something |
|
539 |
"start a drop at the current pointer position |
|
540 |
When finished, the endAction is called with four args: |
|
541 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
542 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
543 |
" |
|
544 |
|manager| |
|
545 |
||
546 |
manager := self new. |
|
547 |
||
548 |
manager startDrag:draggableObjects |
|
1166 | 549 |
from:aView |
550 |
offset:anOffset |
|
551 |
atEnd:aFourArgEndBlock |
|
552 |
display:something. |
|
874 | 553 |
|
554 |
^ manager |
|
555 |
||
556 |
" |
|
557 |
EXAMPLE: |
|
558 |
||
559 |
|button| |
|
560 |
||
561 |
button := (Button label:'press me'). |
|
562 |
||
563 |
button pressAction:[ |
|
1166 | 564 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
565 |
from:button |
|
566 |
offset:(-10 @ -10) |
|
567 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
568 |
Transcript showCR:'target view: ', targetView printString. |
|
569 |
Transcript showCR:'target id: ', targetViewId printString. |
|
570 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
571 |
Transcript showCR:'point target: ', targetPoint printString. |
|
572 |
] |
|
573 |
display:(Array with:'String' with:(Image fromFile:('xpmBitmaps/QUESTION3.xpm'))). |
|
574 |
button turnOff |
|
874 | 575 |
]. |
576 |
||
577 |
button openAt:100@100 |
|
578 |
" |
|
579 |
||
580 |
! |
|
581 |
||
582 |
startDrag:draggableObjects from:aView offset:anOffset display:something |
|
583 |
"start a drop at the current pointer position |
|
584 |
" |
|
585 |
^ self startDrag:draggableObjects |
|
1166 | 586 |
from:aView |
587 |
offset:anOffset |
|
588 |
atEnd:nil |
|
589 |
display:something |
|
874 | 590 |
|
591 |
" |
|
592 |
EXAMPLE: |
|
593 |
||
594 |
|dropObj topView pannel icon buttonAction addButton| |
|
595 |
||
596 |
topView := StandardSystemView new. |
|
597 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
598 |
pannel horizontalLayout:#fit. |
|
599 |
pannel verticalLayout:#fitSpace. |
|
600 |
||
601 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
602 |
dropObj := DropObject newFile:('.'). |
|
603 |
||
604 |
addButton := [:offset :label :dispObj| |button| |
|
1166 | 605 |
button := Button label:label in:pannel. |
874 | 606 |
|
1166 | 607 |
button pressAction:[ |
608 |
DragAndDropManager startDrag:dropObj from:button offset:offset display:dispObj. |
|
609 |
button turnOff. |
|
610 |
] |
|
874 | 611 |
]. |
612 |
||
613 |
addButton value:#topLeft value:'String' value:'String'. |
|
614 |
addButton value:#topRight value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
615 |
addButton value:#bottomLeft value:'Icon' value:icon. |
|
616 |
addButton value:#bottomRight value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
617 |
addButton value:#center value:'Mixed' value:(Array with:'String' with:icon). |
|
618 |
||
619 |
topView label:'Drag & Drop'. |
|
620 |
topView openWithExtent:200@200. |
|
621 |
" |
|
622 |
||
623 |
! ! |
|
624 |
||
1776 | 625 |
!DragAndDropManager class methodsFor:'simple start-lines'! |
397 | 626 |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
627 |
startArrowDragIn:aView at:dragPoint atEnd:aFourArgBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
628 |
"start a rubber-arrow-line dragging in aView at dragPoint. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
629 |
When finished, evaluate the fourArgBlock with targetView, |
874 | 630 |
targetID, screenPosition and targetViewPosition as arguments |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
631 |
" |
874 | 632 |
^ self new startArrowDragIn:aView at:dragPoint atEnd:aFourArgBlock |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
633 |
|
874 | 634 |
" |
635 |
EXAMPLE: |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
636 |
|
874 | 637 |
|button| |
397 | 638 |
|
874 | 639 |
button := (Button label:'press me'). |
861 | 640 |
|
874 | 641 |
button pressAction:[ |
1166 | 642 |
button turnOff. |
861 | 643 |
|
1166 | 644 |
DragAndDropManager startArrowDragIn:button |
645 |
at:(button preferredExtent // 2) |
|
646 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
647 |
targetView isNil ifTrue:[ |
|
648 |
Transcript show:'alien view' |
|
649 |
] ifFalse:[ |
|
650 |
Transcript showCR:'target: ', targetView printString |
|
651 |
]. |
|
652 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
653 |
Transcript showCR:'point target: ', targetPoint printString. |
|
654 |
] |
|
874 | 655 |
]. |
656 |
button openAt:100@100 |
|
657 |
" |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
658 |
! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
659 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
660 |
startLineDragIn:aView at:dragPoint atEnd:aFourArgBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
661 |
"start a rubber-line dragging in aView at dragPoint. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
662 |
When finished, evaluate the fourArgBlock with targetView, |
874 | 663 |
targetID, screenPosition and targetViewPosition as arguments |
664 |
" |
|
665 |
^ self new startLineDragIn:aView at:dragPoint atEnd:aFourArgBlock |
|
666 |
||
667 |
" |
|
668 |
EXAMPLE: |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
669 |
|
874 | 670 |
|button| |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
671 |
|
874 | 672 |
button := (Button label:'press me'). |
673 |
||
674 |
button pressAction:[ |
|
1166 | 675 |
button turnOff. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
676 |
|
1166 | 677 |
DragAndDropManager startLineDragIn:button |
678 |
at:(button preferredExtent // 2) |
|
679 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
680 |
targetView isNil ifTrue:[ |
|
681 |
Transcript show:'alien view' |
|
682 |
] ifFalse:[ |
|
683 |
Transcript showCR:'target: ', targetView printString |
|
684 |
]. |
|
685 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
686 |
Transcript showCR:'point target: ', targetPoint printString. |
|
687 |
] |
|
874 | 688 |
]. |
689 |
button openAt:100@100 |
|
690 |
" |
|
397 | 691 |
! ! |
692 |
||
1511 | 693 |
!DragAndDropManager class methodsFor:'translation'! |
694 |
||
695 |
translatePointFromScreen:aPoint toView:aView |
|
696 |
"translate a point to screen |
|
697 |
" |
|
698 |
|device trans point offset| |
|
699 |
||
700 |
device := aView device. |
|
701 |
||
702 |
"/ |
|
703 |
"/ translate to view |
|
704 |
"/ |
|
1517
5f4d38273014
use new #translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
1512
diff
changeset
|
705 |
offset := device translatePoint:0@0 fromView:(device rootView) toView:aView. |
1511 | 706 |
point := aPoint + offset. |
707 |
||
708 |
"/ |
|
709 |
"/ get device coordinates |
|
710 |
"/ |
|
711 |
(trans := aView transformation) notNil ifTrue:[ |
|
712 |
point := trans applyInverseTo:point |
|
713 |
]. |
|
714 |
^ point |
|
715 |
! |
|
716 |
||
717 |
translatePointToScreen:aPoint from:aView |
|
718 |
"translate a point to screen |
|
719 |
" |
|
720 |
|device trans point offset| |
|
721 |
||
1686 | 722 |
aView isRootView ifTrue:[^ aPoint]. |
1511 | 723 |
device := aView device. |
724 |
"/ |
|
725 |
"/ get device coordinates |
|
726 |
"/ |
|
727 |
(trans := aView transformation) notNil ifTrue:[ |
|
728 |
point := trans applyTo:aPoint |
|
729 |
] ifFalse:[ |
|
730 |
point := aPoint |
|
731 |
]. |
|
732 |
"/ |
|
733 |
"/ translate to screen |
|
734 |
"/ |
|
1517
5f4d38273014
use new #translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
1512
diff
changeset
|
735 |
offset := device translatePoint:0@0 fromView:aView toView:(device rootView). |
1686 | 736 |
^ offset + point |
1511 | 737 |
! ! |
738 |
||
394 | 739 |
!DragAndDropManager methodsFor:'accessing'! |
740 |
||
861 | 741 |
device |
742 |
"returns the device of the source view |
|
743 |
" |
|
744 |
^ dragView device |
|
745 |
||
746 |
||
747 |
! |
|
748 |
||
2042
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
749 |
disabledFlag |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
750 |
^ disabledFlag ? false |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
751 |
! |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
752 |
|
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
753 |
disabledFlag:something |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
754 |
disabledFlag := something. |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
755 |
! |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
756 |
|
2013 | 757 |
dragHandler |
758 |
"returns the current active handler which is responsible for drawing ..." |
|
759 |
||
760 |
^ handler |
|
761 |
! |
|
762 |
||
763 |
dragHandler:aNewHandler |
|
764 |
"set the active handler which is responsible for drawing ..." |
|
765 |
||
766 |
handler := aNewHandler. |
|
767 |
! |
|
768 |
||
874 | 769 |
dropContext |
770 |
"return the current context |
|
771 |
" |
|
772 |
^ dropContext |
|
773 |
! |
|
774 |
||
397 | 775 |
dropObjects |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
776 |
"return the current dropObject collection" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
777 |
|
874 | 778 |
^ dropContext dropObjects |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
779 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
780 |
"Modified: 19.4.1997 / 10:19:06 / cg" |
397 | 781 |
! |
782 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
783 |
dropObjects:aCollectionOfDropObjects |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
784 |
"set the current dropObject collection" |
397 | 785 |
|
874 | 786 |
^ dropContext dropObjects:aCollectionOfDropObjects |
861 | 787 |
! |
788 |
||
789 |
font |
|
790 |
"returns the font of the source view |
|
791 |
" |
|
792 |
^ dragView font |
|
793 |
||
794 |
||
874 | 795 |
! |
796 |
||
1661
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
797 |
passiveAction:aBlockOrNil |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
798 |
self removePassiveAction. |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
799 |
aBlockOrNil notNil ifTrue:[ |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
800 |
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
|
801 |
]. |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
802 |
! |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
803 |
|
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
804 |
removePassiveAction |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
805 |
passiveAction notNil ifTrue:[ |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
806 |
Processor removeTimeoutWithID:passiveAction. |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
807 |
passiveAction := nil. |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
808 |
]. |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
809 |
! |
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
810 |
|
874 | 811 |
sourceWidget |
812 |
^ dragView |
|
813 |
! ! |
|
814 |
||
1397 | 815 |
!DragAndDropManager methodsFor:'accessing-cursor'! |
874 | 816 |
|
817 |
alienCursor:aCursorOrImage |
|
818 |
"set the cursor used for an alien widget; not an ST/X view |
|
819 |
" |
|
820 |
aCursorOrImage isImage ifTrue:[ |
|
1166 | 821 |
alienCursor := Cursor fromImage:aCursorOrImage |
874 | 822 |
] ifFalse:[ |
1166 | 823 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
824 |
alienCursor := aCursorOrImage |
|
825 |
] ifFalse:[ |
|
826 |
"/ |
|
827 |
"/ use disabled cursor |
|
828 |
"/ |
|
829 |
alienCursor := nil |
|
830 |
] |
|
874 | 831 |
] |
832 |
! |
|
833 |
||
834 |
disabledCursor:aCursorOrImage |
|
835 |
"set the cursor for an ST/X view, which can not drop the objects |
|
836 |
" |
|
837 |
aCursorOrImage isImage ifTrue:[ |
|
1166 | 838 |
disabledCursor := Cursor fromImage:aCursorOrImage |
874 | 839 |
] ifFalse:[ |
1166 | 840 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
841 |
disabledCursor := aCursorOrImage |
|
842 |
] |
|
874 | 843 |
] |
844 |
! |
|
845 |
||
846 |
enabledCursor:aCursorOrImage |
|
847 |
"set the cursor for an ST/X view, which can drop the objects |
|
848 |
" |
|
849 |
aCursorOrImage isImage ifTrue:[ |
|
1166 | 850 |
enabledCursor := Cursor fromImage:aCursorOrImage |
874 | 851 |
] ifFalse:[ |
1166 | 852 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
853 |
enabledCursor := aCursorOrImage |
|
854 |
] |
|
874 | 855 |
] |
856 |
||
857 |
! ! |
|
858 |
||
1678 | 859 |
!DragAndDropManager methodsFor:'dragging-drop source'! |
874 | 860 |
|
861 |
startDragFrom:aView dropSource:aDropSource |
|
1718 | 862 |
"start a drag at the current pointer position. |
874 | 863 |
" |
864 |
^ self startDragFrom:aView dropSource:aDropSource offset:#topLeft "/ #center |
|
865 |
! |
|
866 |
||
867 |
startDragFrom:aView dropSource:aDropSource offset:anOffset |
|
1718 | 868 |
"start a drag at the current pointer position. |
874 | 869 |
" |
870 |
dropContext dropSource:aDropSource. |
|
871 |
||
872 |
^ self startDrag:(aDropSource dropObjects) |
|
1718 | 873 |
from:aView |
874 |
offset:anOffset |
|
875 |
atEnd:nil |
|
876 |
display:(aDropSource displayObjects) |
|
874 | 877 |
! ! |
878 |
||
1678 | 879 |
!DragAndDropManager methodsFor:'dragging-easy startup'! |
874 | 880 |
|
881 |
startDrag:draggableObjects from:aView |
|
882 |
"start a drop at the current pointer position |
|
883 |
" |
|
884 |
^ self startDrag:draggableObjects |
|
1166 | 885 |
from:aView |
886 |
offset:0@0 |
|
874 | 887 |
! |
888 |
||
889 |
startDrag:draggableObjects from:aView display:something |
|
890 |
"start a drop at the current pointer position. |
|
891 |
" |
|
892 |
^ self startDrag:draggableObjects |
|
1166 | 893 |
from:aView |
894 |
offset:nil |
|
895 |
atEnd:nil |
|
896 |
display:something |
|
874 | 897 |
! |
898 |
||
899 |
startDrag:draggableObjects from:aView offset:anOffset |
|
900 |
"start a drop at the current pointer position with an offset |
|
901 |
" |
|
902 |
^ self startDrag:draggableObjects |
|
1166 | 903 |
from:aView |
904 |
offset:anOffset |
|
905 |
atEnd:nil |
|
874 | 906 |
! |
907 |
||
908 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock |
|
909 |
"start a drop at the current pointer position. |
|
910 |
When finished, the endAction is called with four args: |
|
911 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
912 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
913 |
" |
|
914 |
^ self startDrag:draggableObjects |
|
1166 | 915 |
from:aView |
916 |
offset:anOffset |
|
917 |
atEnd:aFourArgEndBlock |
|
918 |
display:draggableObjects |
|
874 | 919 |
! |
920 |
||
921 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgBlock display:something |
|
922 |
"start a drop at the current pointer position. |
|
923 |
When finished, the endAction is called with four args: |
|
924 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
925 |
the dropPoint in root-coordinates and the dropPoint within the targetView. |
|
926 |
" |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
927 |
|height width fontWdt offset ascent device dispObjs list space| |
874 | 928 |
|
929 |
self dropObjects:draggableObjects. |
|
930 |
||
931 |
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
|
932 |
^ self |
874 | 933 |
]. |
934 |
||
935 |
device := aView device. |
|
936 |
space := 1. |
|
937 |
height := space negated. |
|
938 |
width := 0. |
|
939 |
fontWdt := aView font width. |
|
940 |
ascent := aView font ascent. |
|
941 |
||
942 |
(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
|
943 |
list := self dropObjects |
874 | 944 |
] ifFalse:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
945 |
(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
|
946 |
list := Array with:something |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
947 |
] |
874 | 948 |
]. |
949 |
dispObjs := OrderedCollection new. |
|
950 |
||
951 |
list do:[:el| |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
952 |
|obj asc| |
874 | 953 |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
954 |
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
|
955 |
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
|
956 |
height := height + space. |
874 | 957 |
|
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
958 |
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
|
959 |
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
|
960 |
height := height + (obj heightOn:aView). |
874 | 961 |
]. |
962 |
||
881 | 963 |
anOffset isSymbol ifTrue:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
964 |
offset := (0@0 extent:(width @ height)) perform:anOffset. |
881 | 965 |
] ifFalse:[ |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
966 |
offset := anOffset ? (0@0). |
881 | 967 |
]. |
968 |
offset := offset rounded. |
|
874 | 969 |
|
970 |
dispObjs do:[:el| el at:2 put:((el at:2) - offset) ]. |
|
971 |
||
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
972 |
self startOpaqueDrag:[:p :v| |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
973 |
|cursor hX hY pDraw| |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
974 |
|
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
975 |
cursor := dragView cursor. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
976 |
hX := cursor hotX. |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
977 |
hY := cursor hotY. |
1497
dff682eb74fc
avoid jumping icon while moving
Claus Gittinger <cg@exept.de>
parents:
1490
diff
changeset
|
978 |
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
|
979 |
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
|
980 |
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
|
981 |
] |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
982 |
] |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
983 |
offset:offset |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
984 |
extent:width @ height |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
985 |
in:aView |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
986 |
at:nil |
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
987 |
atEnd:aFourArgBlock |
881 | 988 |
|
989 |
"Modified: / 31.3.1998 / 11:18:04 / cg" |
|
874 | 990 |
! |
991 |
||
992 |
startDrag:draggableObjects from:aView offset:anOffset display:something |
|
993 |
"start a drop at the current pointer position. |
|
994 |
" |
|
995 |
^ self startDrag:draggableObjects |
|
1166 | 996 |
from:aView |
997 |
offset:anOffset |
|
998 |
atEnd:nil |
|
999 |
display:something |
|
394 | 1000 |
! ! |
1001 |
||
1678 | 1002 |
!DragAndDropManager methodsFor:'dragging-generic'! |
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
1003 |
|
348 | 1004 |
startGenericDrag:aTwoArgDragBlock in:aView at:p atEnd:aFourArgEndBlock |
1005 |
"start a generic (caller-provided drag); |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1006 |
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
|
1007 |
by inverting again). See startOpaqueDrag for another variant. |
348 | 1008 |
the dragBlock, aTwoArgDragBlock will be called with two args |
1009 |
aPoint and a drawingGC, to perform the drawing at some dragPoint. |
|
1010 |
The drag starts in aView at point p. |
|
1011 |
When finished, the endAction is called with four args: |
|
1012 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
874 | 1013 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
1014 |
" |
|
1015 |
^ self startOpaqueDrag:aTwoArgDragBlock |
|
1166 | 1016 |
offset:nil |
1017 |
extent:nil |
|
1018 |
in:aView |
|
1019 |
at:nil |
|
1020 |
atEnd:aFourArgEndBlock |
|
394 | 1021 |
! |
1022 |
||
874 | 1023 |
startOpaqueDrag:aDragBlock offset:offs extent:anExtent in:aView at:aDummyPoint atEnd:aFourArgEndBlock |
1024 |
"start an opaque or generic opaque (caller-provided drag); |
|
394 | 1025 |
opaque drag means, that the drawing cannot be undone by two inverting |
1026 |
draws, but instead, the area under the dragged object must be saved |
|
874 | 1027 |
and restored. The areas size to be saved/restored is passed in anExtent. |
1028 |
the dragBlock, aDragBlock will be called with up to three args aPoint, a |
|
1029 |
drawingGC and the display objects, to perform the drawing at some dragPoint. |
|
394 | 1030 |
The drag starts in aView at point p. |
1031 |
When finished, the endAction is called with four args: |
|
1032 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
874 | 1033 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
1034 |
" |
|
1035 |
|handler numArgs dragBlock dobjs| |
|
394 | 1036 |
|
874 | 1037 |
dragOffset := offs ? (Point x:0 y:0). |
1038 |
numArgs := aDragBlock numArgs. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1039 |
|
874 | 1040 |
numArgs == 3 ifTrue:[ |
1289 | 1041 |
dobjs := self dropObjects. |
1042 |
dragBlock := [:p :v| aDragBlock value:p value:v value:dobjs ] |
|
874 | 1043 |
] ifFalse:[ |
1289 | 1044 |
numArgs == 1 ifTrue:[ |
1045 |
dragBlock := [:p :v| aDragBlock value:p ] |
|
1046 |
] ifFalse:[ |
|
1047 |
dragBlock := aDragBlock |
|
1048 |
] |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1049 |
]. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1050 |
|
874 | 1051 |
anExtent isNil ifTrue:[ |
1289 | 1052 |
handler := DragHandler startGenericDrag:dragBlock. |
874 | 1053 |
] ifFalse:[ |
1289 | 1054 |
handler := DragHandler startOpaqueDrag:dragBlock extent:anExtent offset:dragOffset. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1055 |
]. |
1289 | 1056 |
self doStart:handler for:aView atEnd:aFourArgEndBlock. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1057 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1058 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1059 |
|
1678 | 1060 |
!DragAndDropManager methodsFor:'dragging-lines'! |
341 | 1061 |
|
874 | 1062 |
startArrowDragIn:aView at:aStartPoint atEnd:aFourArgEndBlock |
1063 |
"start a line-drag of an arrow-line. |
|
1064 |
The drag starts in aView at point aStartPoint. |
|
1065 |
When finished, the endAction is called with four args: |
|
1066 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
1067 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
1068 |
" |
|
1069 |
|p| |
|
341 | 1070 |
|
1511 | 1071 |
p := self class translatePointToScreen:aStartPoint from:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1072 |
|
874 | 1073 |
self doStart:(DragHandler startArrowDragAt:p) |
1511 | 1074 |
for:aView |
1075 |
atEnd:aFourArgEndBlock |
|
341 | 1076 |
! |
1077 |
||
874 | 1078 |
startLineDragIn:aView at:aStartPoint atEnd:aFourArgEndBlock |
1079 |
"start a line-drag of a normal line. |
|
1080 |
The drag starts in aView at point aStartPoint. |
|
348 | 1081 |
When finished, the endAction is called with four args: |
1082 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
874 | 1083 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
1084 |
" |
|
1085 |
|p| |
|
341 | 1086 |
|
1511 | 1087 |
p := self class translatePointToScreen:aStartPoint from:aView. |
348 | 1088 |
|
874 | 1089 |
self doStart:(DragHandler startLineDragAt:p) |
1511 | 1090 |
for:aView |
1091 |
atEnd:aFourArgEndBlock |
|
341 | 1092 |
! ! |
1093 |
||
397 | 1094 |
!DragAndDropManager methodsFor:'drawing'! |
1095 |
||
874 | 1096 |
displayObjectFor:anObject on:aDevice |
1097 |
"converts an object to a display object |
|
1098 |
" |
|
1572 | 1099 |
|obj s1 s2| |
874 | 1100 |
|
1101 |
obj := (anObject respondsTo:#displayObject) ifTrue:[anObject displayObject] |
|
1572 | 1102 |
ifFalse:[anObject]. |
874 | 1103 |
|
1104 |
obj isString ifTrue:[ |
|
1572 | 1105 |
^ obj |
874 | 1106 |
]. |
1107 |
||
1582 | 1108 |
MessageNotUnderstood |
1109 |
ignoreNotUnderstoodOf:#'onDevice:' |
|
1110 |
in:[ |
|
1111 |
obj := obj onDevice:aDevice |
|
1112 |
]. |
|
874 | 1113 |
|
1114 |
obj isImage ifTrue:[ |
|
1572 | 1115 |
^ obj clearMaskedPixels |
874 | 1116 |
]. |
1117 |
||
1118 |
obj class == LabelAndIcon ifTrue:[ |
|
1572 | 1119 |
obj image notNil ifTrue:[obj image clearMaskedPixels]. |
1120 |
obj icon notNil ifTrue:[obj icon clearMaskedPixels]. |
|
1823 | 1121 |
^ obj |
874 | 1122 |
]. |
1123 |
||
1124 |
(obj class == MultiColListEntry) ifFalse:[ |
|
1572 | 1125 |
^ obj |
874 | 1126 |
]. |
1127 |
s1 := obj colAt:1. |
|
1128 |
s2 := obj colAt:2. |
|
1129 |
||
1130 |
s1 isImage ifTrue:[ |
|
1572 | 1131 |
s2 isImage ifTrue:[ ^ self displayObjectFor:(LabelAndIcon form:s1 image:s2) on:aDevice ]. |
1132 |
s2 isString ifTrue:[ ^ self displayObjectFor:(LabelAndIcon icon:s1 string:s2) on:aDevice ]. |
|
1133 |
^ (s1 on:aDevice) clearMaskedPixels |
|
874 | 1134 |
]. |
1135 |
||
1136 |
s2 isImage ifTrue:[ |
|
1572 | 1137 |
s1 isString ifTrue:[ ^ self displayObjectFor:(LabelAndIcon icon:s2 string:s1) on:aDevice ]. |
1138 |
^ (s2 on:aDevice) clearMaskedPixels |
|
874 | 1139 |
]. |
1140 |
||
1141 |
s1 isString ifTrue:[^ s1]. |
|
1142 |
s2 isString ifTrue:[^ s2]. |
|
1823 | 1143 |
^ obj |
874 | 1144 |
! |
1145 |
||
397 | 1146 |
showDragging:items in:aView at:p |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1147 |
"helper for dragging dragObjects: draw them all" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1148 |
|
397 | 1149 |
|offs| |
1150 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1151 |
offs := 0. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1152 |
items do:[:item | |
1490
b2e1f907060c
care for cursor when drawing dragObjects (avoid overdrawing the cursor)
Claus Gittinger <cg@exept.de>
parents:
1487
diff
changeset
|
1153 |
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
|
1154 |
offs := offs + (item heightOn:self) |
397 | 1155 |
] |
1156 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1157 |
"Modified: 19.4.1997 / 12:41:24 / cg" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1158 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1159 |
|
341 | 1160 |
!DragAndDropManager methodsFor:'event catching'! |
1161 |
||
1686 | 1162 |
buttonMotion:button x:x y:y view:aView |
1163 |
|device screenPoint oldWg oldId oldPt newId newWg oldTgt newTgt isDroppable cursor| |
|
874 | 1164 |
|
2042
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
1165 |
self disabledFlag ifTrue: [ |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
1166 |
^ self |
00fd3e50afdd
Add disabled flag. If enabled (=true) the handling of button motion
ab
parents:
2025
diff
changeset
|
1167 |
]. |
1842
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
1168 |
escapePressed == true ifTrue:[ |
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
1169 |
self removePassiveAction. |
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
1170 |
^ self |
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
1171 |
]. |
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
1172 |
|
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
1173 |
(dragView notNil and:[dragView sensor motionEventPending]) ifTrue:[ |
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
1174 |
^ self |
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
1175 |
]. |
1661
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
1176 |
self removePassiveAction. |
1619 | 1177 |
|
874 | 1178 |
device := dragView device. |
1179 |
oldWg := dropContext targetWidget. |
|
1180 |
oldId := dropContext targetId. |
|
1181 |
oldPt := dropContext rootPoint. |
|
1182 |
||
1686 | 1183 |
screenPoint := self class translatePointToScreen:(x @ y) from:aView. |
1184 |
"/ screenPoint := device pointerPosition. |
|
1511 | 1185 |
dropContext rootPoint:screenPoint. |
874 | 1186 |
|
1511 | 1187 |
newId := device viewIdFromPoint:screenPoint. |
874 | 1188 |
newWg := device viewFromId:newId. |
1686 | 1189 |
|
1190 |
dropContext rootPoint:screenPoint. |
|
874 | 1191 |
dropContext targetWidget:newWg id:newId. |
1192 |
||
1193 |
handler isInterestedInDropTarget ifFalse:[ |
|
1289 | 1194 |
"/ |
1195 |
"/ line or arrow handler |
|
1196 |
"/ |
|
1511 | 1197 |
handler dragTo:screenPoint. |
1289 | 1198 |
^ self |
874 | 1199 |
]. |
1686 | 1200 |
oldTgt := dropContext dropTarget. |
1201 |
newTgt := self doFindDropTargetIn:newWg at:screenPoint. |
|
874 | 1202 |
|
1686 | 1203 |
newTgt ~= oldTgt ifTrue:[ |
1289 | 1204 |
"/ |
1686 | 1205 |
"/ drop target changed: handler might restore the screen |
1206 |
"/ |
|
1207 |
handler dropTargetWillChange. |
|
341 | 1208 |
|
1686 | 1209 |
oldTgt notNil ifTrue:[ |
1210 |
"/ |
|
1211 |
"/ setup old context |
|
1212 |
"/ |
|
1213 |
dropContext targetWidget:oldWg id:oldId. |
|
1214 |
oldTgt leave:dropContext. |
|
1215 |
dropContext targetWidget:newWg id:newId. |
|
1216 |
]. |
|
1217 |
dropContext dropTarget:newTgt. |
|
1218 |
newTgt notNil ifTrue:[ newTgt enter:dropContext ] |
|
874 | 1219 |
] ifFalse:[ |
1686 | 1220 |
dropContext dropTarget:newTgt |
874 | 1221 |
]. |
1686 | 1222 |
|
874 | 1223 |
"/ |
1224 |
"/ update the cursor |
|
1225 |
"/ |
|
1686 | 1226 |
|
874 | 1227 |
(isDroppable := dropContext canDrop) ifTrue:[ |
1289 | 1228 |
cursor := enabledCursor |
874 | 1229 |
] ifFalse:[ |
1686 | 1230 |
dropContext isAlienView ifFalse:[cursor := disabledCursor] |
1231 |
ifTrue:[cursor := alienCursor] |
|
874 | 1232 |
]. |
1233 |
dragView cursor:cursor now:true. |
|
1234 |
"/ |
|
1235 |
"/ test if droppable state changed |
|
1236 |
"/ |
|
1237 |
canDrop == isDroppable ifFalse:[ |
|
1289 | 1238 |
"/ |
1239 |
"/ droppable state changed: handler might restore the screen |
|
1240 |
"/ |
|
1241 |
canDrop := isDroppable. |
|
1242 |
handler dropTargetWillChange |
|
874 | 1243 |
]. |
394 | 1244 |
|
874 | 1245 |
newTgt notNil ifTrue:[ newTgt over:dropContext ]. |
1511 | 1246 |
handler dragTo:screenPoint. |
874 | 1247 |
! |
394 | 1248 |
|
1686 | 1249 |
buttonRelease:button x:x y:y view:aView |
2063 | 1250 |
|targetWidget| |
874 | 1251 |
|
1686 | 1252 |
((button == 1) or:[button == #select]) ifFalse:[ |
1619 | 1253 |
^ self |
874 | 1254 |
]. |
1686 | 1255 |
self removePassiveAction. |
1661
3092c6bac88e
added passiveAction: invoked if staying over a dropItem for a while
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
1256 |
|
1686 | 1257 |
restoreBlock value. "/ restore context before start drag |
394 | 1258 |
|
2061
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1259 |
escapePressed == true ifTrue:[^ self]. |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1260 |
|
2063 | 1261 |
targetWidget := dropContext targetWidget. |
2061
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1262 |
dropAction notNil ifTrue:[ |
1619 | 1263 |
"/ |
2061
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1264 |
"/ 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
|
1265 |
"/ Thus, no feedBack operation invoked. |
1619 | 1266 |
"/ |
2063 | 1267 |
dropAction value:(targetWidget) |
2061
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1268 |
value:(dropContext targetId) |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1269 |
value:(dropContext rootPoint) |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1270 |
value:(dropContext targetPoint). |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1271 |
] ifFalse:[ |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1272 |
dropContext doDrop |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1273 |
]. |
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1274 |
|
f847cebf016f
focus behavior when \"click-for-focus\" is on.
Claus Gittinger <cg@exept.de>
parents:
2046
diff
changeset
|
1275 |
"/ 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
|
1276 |
"/ if click-for-focus is on. |
2062 | 1277 |
"/ CG: no - do it always |
1278 |
"/ UserPreferences current focusFollowsMouse == false ifTrue:[ |
|
1279 |
"/ dropContext targetWidget wantsFocusWithButtonPress ifTrue:[ |
|
1280 |
"/ dropContext targetWidget requestFocus |
|
1281 |
"/ ]. |
|
1282 |
"/ ]. |
|
2063 | 1283 |
targetWidget notNil ifTrue:[ |
1284 |
targetWidget topView setForegroundWindow; activate. |
|
1285 |
targetWidget takeFocus. |
|
1286 |
]. |
|
1289 | 1287 |
! |
1288 |
||
1685 | 1289 |
escapePressed |
1290 |
"handle key escape |
|
1291 |
" |
|
1292 |
|dropTarget| |
|
1293 |
||
1294 |
escapePressed ~~ true ifTrue:[ |
|
1295 |
escapePressed := true. |
|
1296 |
||
1297 |
handler notNil ifTrue:[ |
|
1298 |
"/ restore handler |
|
1299 |
dropTarget := dropContext dropTarget. |
|
1300 |
handler postDragging. |
|
1301 |
||
1302 |
dropTarget notNil ifTrue:[ |
|
1303 |
"/ invoke leave operation |
|
1304 |
dropTarget leave:dropContext. |
|
1305 |
dropContext dropTarget:nil. |
|
1306 |
]. |
|
1307 |
]. |
|
1308 |
]. |
|
1309 |
! |
|
1310 |
||
1686 | 1311 |
keyPress:aKey x:x y:y view:aView |
2069 | 1312 |
"stop the drag operation, when the escape key is pressed" |
874 | 1313 |
|
2070 | 1314 |
<resource: #keyboard (#Escape)> |
1315 |
||
1686 | 1316 |
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
|
1317 |
|
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1318 |
aKey == #Escape ifTrue:[ |
1685 | 1319 |
self escapePressed. |
1619 | 1320 |
]. |
1686 | 1321 |
! |
1322 |
||
1834 | 1323 |
processAutoScroll |
1324 |
"process an autoScroll event |
|
1325 |
" |
|
1326 |
|targetWidget targetPoint| |
|
1327 |
||
1328 |
self isActive ifFalse:[^ self]. |
|
1329 |
||
1330 |
dropContext isNil ifTrue:[ ^ self ]. |
|
1331 |
||
1332 |
targetWidget := dropContext targetWidget. |
|
1333 |
targetWidget isNil ifTrue:[ ^ self ]. |
|
1835
d6db8466019b
bugfix in scrolling during drag & drop; test for isRootView
ca
parents:
1834
diff
changeset
|
1334 |
targetWidget isRootView ifTrue:[ ^ self ]. |
1834 | 1335 |
|
1336 |
targetPoint := dropContext targetPoint. |
|
1337 |
targetPoint isNil ifTrue:[ ^ self ]. |
|
1338 |
||
1339 |
(targetWidget dragAutoScroll: dropContext) ifFalse:[ |
|
1340 |
^ self |
|
1341 |
]. |
|
1342 |
self buttonMotion:256 x:(targetPoint x) y:(targetPoint y) view:targetWidget. |
|
1343 |
! |
|
1344 |
||
1686 | 1345 |
processEvent:event |
2022 | 1346 |
"filter keyboard events. |
1347 |
Return true, if I have eaten the event" |
|
1348 |
||
1686 | 1349 |
|evView| |
1350 |
||
1351 |
restoreBlock isNil ifTrue:[^ false]. "/ should not happen |
|
1352 |
||
1353 |
evView := event view. |
|
1354 |
evView isNil ifTrue:[^ false]. |
|
1355 |
||
1356 |
event isInputEvent ifFalse:[ |
|
1357 |
^ false |
|
1358 |
]. |
|
1359 |
||
1360 |
event isKeyEvent ifTrue:[ |
|
1361 |
self keyPress:(event key) x:(event x) y:(event y) view:evView. |
|
1362 |
^ true |
|
1363 |
]. |
|
1364 |
||
1365 |
event isButtonMotionEvent ifTrue:[ |
|
1366 |
self buttonMotion:(event state) x:(event x) y:(event y) view:evView. |
|
1367 |
] ifFalse:[ |
|
1368 |
event isButtonReleaseEvent ifTrue:[ |
|
1369 |
self buttonRelease:(event button) x:(event x) y:(event y) view:evView. |
|
1370 |
] |
|
1371 |
]. |
|
1372 |
^ true |
|
874 | 1373 |
! ! |
1374 |
||
1375 |
!DragAndDropManager methodsFor:'initialization'! |
|
341 | 1376 |
|
874 | 1377 |
initialize |
1378 |
super initialize. |
|
394 | 1379 |
|
874 | 1380 |
dragOffset := 0 @ 0. |
1381 |
dropContext := DropContext new. |
|
1618 | 1382 |
dropContext manager:self. |
874 | 1383 |
alienCursor := Cursor questionMark. |
1384 |
enabledCursor := Cursor thumbsUp. |
|
1385 |
disabledCursor := Cursor thumbsDown. |
|
1386 |
canDrop := false. |
|
341 | 1387 |
! ! |
1388 |
||
1389 |
!DragAndDropManager methodsFor:'private'! |
|
1390 |
||
874 | 1391 |
doDrop:aContext in:aWidget |
1392 |
"old drop mechanism |
|
1393 |
" |
|
1394 |
|point| |
|
628 | 1395 |
|
1511 | 1396 |
DragContextQuerySignal answer:aContext do:[ |
1397 |
DragOriginatorQuerySignal answer:dragView do:[ |
|
2025 | 1398 |
DragOffsetQuerySignal answer:dragOffset do:[ |targetWidget targetPoint| |
1399 |
targetWidget := aContext targetWidget. |
|
1400 |
targetPoint := aContext targetPoint. |
|
1401 |
||
1402 |
targetWidget == aWidget ifTrue:[ |
|
1403 |
point := targetPoint. |
|
1511 | 1404 |
] ifFalse:[ |
2025 | 1405 |
point := targetWidget originRelativeTo:aWidget. |
1406 |
||
1407 |
point isNil ifTrue:[ |
|
1408 |
point := 0@0. |
|
1409 |
] ifFalse:[ |
|
1410 |
point := point + targetPoint. |
|
1411 |
]. |
|
1511 | 1412 |
"/ |
1413 |
"/ FeedBack: set the widget which handles the drop |
|
1414 |
"/ |
|
1415 |
aContext targetWidget:aWidget id:(aWidget id). |
|
1416 |
]. |
|
1417 |
aWidget drop:(aContext dropObjects) at:point |
|
1418 |
] |
|
1419 |
]. |
|
609
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1420 |
]. |
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1421 |
|
1072
be90bc383d83
do not pas nil point to dropDestination
Claus Gittinger <cg@exept.de>
parents:
881
diff
changeset
|
1422 |
"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
|
1423 |
! |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
1424 |
|
874 | 1425 |
doFindDropTargetIn:aView at:aPoint |
1426 |
"get the drop target for a view and source at a point or nil |
|
411 | 1427 |
" |
628 | 1428 |
|
874 | 1429 |
aView isNil ifTrue:[ ^ nil ]. |
1582 | 1430 |
|
874 | 1431 |
"/ |
1432 |
"/ new mechanism to get a dropTarget |
|
1433 |
"/ |
|
1587 | 1434 |
|
1582 | 1435 |
MessageNotUnderstood |
1436 |
ignoreNotUnderstoodOf:#dropTarget |
|
1587 | 1437 |
in:[ |target| |
1582 | 1438 |
target := aView dropTarget. |
1587 | 1439 |
target notNil ifTrue:[ ^ target ]. |
1582 | 1440 |
]. |
1441 |
||
874 | 1442 |
"/ |
1443 |
"/ old mechanism to get a dropTarget |
|
1444 |
"/ |
|
628 | 1445 |
|
1511 | 1446 |
DragContextQuerySignal answer:dropContext do:[ |
1447 |
DragOriginatorQuerySignal answer:dragView do:[ |
|
1448 |
DragOffsetQuerySignal answer:dragOffset do:[ |
|
1587 | 1449 |
|view dobj| |
1450 |
||
1451 |
view := aView. |
|
1452 |
dobj := dropContext dropObjects. |
|
1453 |
[ |
|
1454 |
(view canDrop:dobj) ifTrue:[ |
|
1511 | 1455 |
^ DropTarget receiver:self argument:view dropSelector:#doDrop:in:. |
1456 |
]. |
|
1457 |
(view := view superView) notNil |
|
1458 |
] whileTrue. |
|
1459 |
] |
|
1460 |
]. |
|
874 | 1461 |
]. |
1462 |
^ nil |
|
1463 |
! |
|
628 | 1464 |
|
874 | 1465 |
doStart:aHandler for:aView atEnd:aFourArgEndBlock |
1466 |
"setup a handler and a restore block |
|
628 | 1467 |
" |
1749
1f58fbcd4b96
Use SynchronousWindoeSensor if no windowGroup
Stefan Vogel <sv@exept.de>
parents:
1718
diff
changeset
|
1468 |
|device lastActive windowGroup savedCursor screenPoint| |
628 | 1469 |
|
1512 | 1470 |
device := aView device. |
1685 | 1471 |
lastActive := ActiveDragAndDropManagers at:device ifAbsent:nil. |
1472 |
||
1473 |
lastActive notNil ifTrue:[ |
|
1474 |
"/ self error:'oops - two dnd managers active' mayProceed:true. |
|
1475 |
||
1476 |
lastActive forceGiveUp. |
|
1939 | 1477 |
'DragAndDropManager [info]: oops - two dnd managers active' infoPrintCR. |
1487 | 1478 |
]. |
1512 | 1479 |
ActiveDragAndDropManagers at:device put:self. |
1487 | 1480 |
|
874 | 1481 |
dropContext sourceWidget:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1482 |
|
874 | 1483 |
dragOffset isNil ifTrue:[ dragOffset := 0 @ 0 ]. |
1484 |
alienCursor isNil ifTrue:[ alienCursor := disabledCursor ]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1485 |
|
1686 | 1486 |
dragView := aView. |
1487 |
dropAction := aFourArgEndBlock. |
|
1488 |
windowGroup := aView windowGroup. |
|
1619 | 1489 |
handler := aHandler. |
1490 |
escapePressed := false. |
|
609
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1491 |
|
1162
0539b64679ce
set DragHandler in the DropContext
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1492 |
dropContext dragHandler:aHandler. |
1686 | 1493 |
|
1689
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1494 |
savedCursor := dragView cursor. |
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1495 |
windowGroup addPreEventHook:self. |
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1496 |
windowGroup addPostEventHook:self. |
1162
0539b64679ce
set DragHandler in the DropContext
Claus Gittinger <cg@exept.de>
parents:
1072
diff
changeset
|
1497 |
|
874 | 1498 |
restoreBlock := [ |
1686 | 1499 |
restoreBlock := nil. |
1500 |
||
1834 | 1501 |
autoScrollTask notNil ifTrue:[ |
1502 |
autoScrollTask terminate. |
|
1503 |
autoScrollTask := nil. |
|
1504 |
]. |
|
1505 |
||
1512 | 1506 |
ActiveDragAndDropManagers removeKey:device ifAbsent:nil. |
1686 | 1507 |
escapePressed ifFalse:[ aHandler postDragging ]. |
1508 |
||
1689
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1509 |
windowGroup removePreEventHook:self. |
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1510 |
windowGroup removePostEventHook:self. |
5aae4c617ffd
obsoleted preEventHook and postEventHook in windowGroup
Claus Gittinger <cg@exept.de>
parents:
1686
diff
changeset
|
1511 |
dragView cursor:savedCursor. |
874 | 1512 |
]. |
1686 | 1513 |
aHandler preDraggingIn:dragView. |
1289 | 1514 |
|
1515 |
"/ 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
|
1516 |
device sync. |
1f58fbcd4b96
Use SynchronousWindoeSensor if no windowGroup
Stefan Vogel <sv@exept.de>
parents:
1718
diff
changeset
|
1517 |
dragView sensor flushMotionEventsFor:nil. |
1289 | 1518 |
|
1834 | 1519 |
autoScrollTask := Process for:[ |
1520 |
[ |sensor| |
|
1521 |
||
1522 |
sensor := windowGroup sensor. |
|
1523 |
||
1524 |
[ self isActive ] whileTrue:[ |
|
1842
f033c7b344de
compress buttonMotion events handling (look for outstanding events)
ca
parents:
1835
diff
changeset
|
1525 |
Delay waitForMilliseconds:(self class autoScrollDelayTimeMs). |
1834 | 1526 |
|
1527 |
self isActive ifTrue:[ |
|
1528 |
sensor pushUserEvent:#processAutoScroll for:self. |
|
1529 |
]. |
|
1530 |
]. |
|
1531 |
]ensure:[ |
|
1532 |
autoScrollTask := nil. |
|
1533 |
] |
|
1534 |
] priority:(Processor userSchedulingPriority). |
|
1535 |
||
1536 |
autoScrollTask name:'Drag-AutoScroll'. |
|
1537 |
autoScrollTask resume. |
|
1538 |
||
1289 | 1539 |
"/ start with a first draw at the current mouse position |
1686 | 1540 |
screenPoint := device pointerPosition. |
1541 |
self buttonMotion:1 x:(screenPoint x) y:(screenPoint y) view:(device rootView). |
|
1487 | 1542 |
! |
1543 |
||
1685 | 1544 |
forceGiveUp |
1545 |
"called if the DragAndDropManager no longer should be |
|
1546 |
active; a second one is started |
|
1547 |
" |
|
1548 |
self escapePressed. |
|
1549 |
self removePassiveAction. |
|
1550 |
restoreBlock value. |
|
1551 |
! |
|
1552 |
||
1834 | 1553 |
isActive |
1554 |
"returns true if a drag operation is active |
|
1555 |
" |
|
1556 |
restoreBlock isNil ifTrue:[ ^ false ]. |
|
1557 |
^ escapePressed ~~ true |
|
1558 |
! |
|
1559 |
||
1487 | 1560 |
saveDraw:aBlock |
1561 |
handler postDragging. |
|
1562 |
aBlock value. |
|
1638 | 1563 |
|
1564 |
escapePressed == true ifFalse:[ |
|
1565 |
"/ reread and show drag items |
|
1566 |
handler rereadSaveArea. |
|
1567 |
handler restoreFromSaveArea. |
|
1568 |
]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1569 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1570 |
|
341 | 1571 |
!DragAndDropManager class methodsFor:'documentation'! |
1572 |
||
1573 |
version |
|
2070 | 1574 |
^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.66 2005-12-21 11:36:08 cg Exp $' |
341 | 1575 |
! ! |
1629
9b0f45e63e24
bug fix if operation cancled by #Escape, must invoke #leave
ca
parents:
1619
diff
changeset
|
1576 |
|
628 | 1577 |
DragAndDropManager initialize! |