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