author | ca |
Mon, 30 Mar 1998 14:02:15 +0200 | |
changeset 874 | 0730cf44f593 |
parent 861 | 10bbb13fcb05 |
child 881 | 981e0791ca36 |
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 |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
3 |
All Rights Reserved |
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 |
|
341 | 14 |
Object subclass:#DragAndDropManager |
874 | 15 |
instanceVariableNames:'dropContext dragView dropAction dragOffset handler restoreBlock |
16 |
alienCursor enabledCursor disabledCursor canDrop' |
|
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
17 |
classVariableNames:'DragOriginatorQuerySignal DragOffsetQuerySignal' |
628 | 18 |
poolDictionaries:'' |
874 | 19 |
category:'Interface-DragAndDrop' |
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
20 |
! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
21 |
|
341 | 22 |
!DragAndDropManager class methodsFor:'documentation'! |
23 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
24 |
copyright |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
25 |
" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
26 |
COPYRIGHT (c) 1996 by eXept Software AG / Claus Gittinger |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
27 |
All Rights Reserved |
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 |
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
|
30 |
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
|
31 |
inclusion of the above copyright notice. This software may not |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
32 |
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
|
33 |
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
|
34 |
hereby transferred. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
35 |
" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
36 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
37 |
! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
38 |
|
348 | 39 |
documentation |
40 |
" |
|
41 |
this class provides low-level drag & drop mechanisms. |
|
42 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
43 |
Easy to use interface interfaces: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
44 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
45 |
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
|
46 |
when a selection is moved (for example, SelectionInListView can |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
47 |
be initializd to do so). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
48 |
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
|
49 |
and starts the drag operation with: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
50 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
51 |
DragAndDropManager startDrag:collectionOfDragObjects from:aView. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
52 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
53 |
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
|
54 |
into the target view. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
55 |
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
|
56 |
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
|
57 |
is shown for alien views (which means: we dont know). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
58 |
Alien view drop is supported (but no 'canDrop' query). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
59 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
60 |
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
|
61 |
provided: |
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 |
DragAndDropManager |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
64 |
startLineDragIn:aView at:position |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
65 |
atEnd:aFourArgEndBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
66 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
67 |
and: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
68 |
DragAndDropManager |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
69 |
startArrowDragIn:aView at:position |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
70 |
atEnd:aFourArgEndBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
71 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
72 |
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
|
73 |
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
|
74 |
on the screen and within the target view as arguments. |
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 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
77 |
Expert interface: |
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 |
More control over the dragging (i.e. the drawing procedure) |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
80 |
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
|
81 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
82 |
aDragAndDropMgr := DragAndDropManager new. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
83 |
aDragAndDropMgr dropObjects:(self collectionOfDragObjects). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
84 |
aDragAndDropMgr |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
85 |
startOpaqueDrag:[:aPoint :aView :dropObjects | |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
86 |
self |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
87 |
showDragging:dropObjects |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
88 |
in:aView |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
89 |
at:aPoint - (xOffset@0) |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
90 |
] |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
91 |
offset:clickOffset |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
92 |
extent:saveUnderExtent |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
93 |
in:self |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
94 |
at:clickPoint |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
95 |
atEnd:[:v :vId :posScreen :posView | ... ] |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
96 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
97 |
the arguments are: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
98 |
startOpaqueDrag: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
99 |
a 3-arg block, which is evaluated by the d&d manager whenever the |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
100 |
mouse moves; it is supposed to draw the dropObjects at some position |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
101 |
in the passed view. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
102 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
103 |
offset: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
104 |
a clickOffset; drawing is offset by this amount |
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 |
extent: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
107 |
a save extent; the size of the screen area that must be saved during |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
108 |
the drag operation |
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 |
in: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
111 |
initiating view |
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 |
at: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
114 |
position where d&d operation starts |
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 |
atEnd: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
117 |
a 4-arg block that is evaluated when the d&d is finished. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
118 |
It gets the target view (or nil, for alien views), the targets |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
119 |
view ID (needed if its an alien view), the screen position and the |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
120 |
relative position within the target view of the drop as arguments. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
121 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
122 |
For internal (ST/X) views, the dropBlock should perform |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
123 |
a simple canDrop:/doDrop message. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
124 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
125 |
For alien views, the Displays d&d functions can be used. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
126 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
127 |
|
348 | 128 |
[author:] |
129 |
Claus Gittinger |
|
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 |
[see also:] |
874 | 132 |
DemoView1, DemoView2, ... |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
133 |
SelectionInListView FileBrowser - for a concrete example |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
134 |
|
348 | 135 |
" |
136 |
||
137 |
! |
|
138 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
139 |
examples |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
140 |
" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
141 |
a button, which initiates dragging of a file-object |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
142 |
Notice that this can be dropped into the launchers panel, |
549 | 143 |
to open a fileBrowser on that directory ... |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
144 |
[exBegin] |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
145 |
|o top v| |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
146 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
147 |
top := StandardSystemView new. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
148 |
v := Button label:'press for drag' in:top. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
149 |
v pressAction:[ |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
150 |
|o| |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
151 |
o := DropObject newFile:('/etc'). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
152 |
DragAndDropManager startDrag:o from:v. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
153 |
v turnOff |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
154 |
]. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
155 |
top openWithExtent:200@200 |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
156 |
[exEnd] |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
157 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
158 |
initiate a drag with some offset: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
159 |
[exBegin] |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
160 |
|o top v| |
341 | 161 |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
162 |
top := StandardSystemView new. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
163 |
v := Button label:'press for drag' in:top. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
164 |
v pressAction:[ |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
165 |
|o| |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
166 |
o := DropObject newFile:('.'). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
167 |
DragAndDropManager startDrag:o from:v offset:10@10. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
168 |
v turnOff |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
169 |
]. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
170 |
top openWithExtent:200@200 |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
171 |
[exEnd] |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
172 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
173 |
initiate a line drag: |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
174 |
[exBegin] |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
175 |
|o top v endAction| |
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 |
endAction := [ :v :vID :sPos :vPos | |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
178 |
Transcript show:'end drag in '. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
179 |
v isNil ifTrue:[ |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
180 |
Transcript show:'alien view' |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
181 |
] ifFalse:[ |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
182 |
Transcript show:v |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
183 |
]. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
184 |
Transcript show:' at screen: '; show:sPos; |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
185 |
show:' in view: '; showCR:vPos |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
186 |
]. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
187 |
top := StandardSystemView new. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
188 |
v := Button label:'press for drag' in:top. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
189 |
v pressAction:[ |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
190 |
DragAndDropManager |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
191 |
startLineDragIn:v at:10@10 atEnd:endAction. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
192 |
v turnOff |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
193 |
]. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
194 |
top openWithExtent:200@200 |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
195 |
[exEnd] |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
196 |
|
874 | 197 |
more drag & drop; offset, displayObjects, ... |
198 |
[exBegin] |
|
199 |
|dropObj topView pannel icon buttonAction addButton| |
|
200 |
||
201 |
topView := StandardSystemView new. |
|
202 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
203 |
pannel horizontalLayout:#fit. |
|
204 |
pannel verticalLayout:#fitSpace. |
|
205 |
||
206 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
207 |
dropObj := DropObject newFile:('.'). |
|
208 |
||
209 |
addButton := [:offset :label :dispObj| |button| |
|
210 |
button := Button label:label in:pannel. |
|
211 |
||
212 |
button pressAction:[ |
|
213 |
DragAndDropManager startDrag:dropObj from:button offset:offset display:dispObj. |
|
214 |
button turnOff. |
|
215 |
] |
|
216 |
]. |
|
217 |
||
218 |
addButton value:#topLeft value:'String' value:'String'. |
|
219 |
addButton value:#topRight value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
220 |
addButton value:#bottomLeft value:'Icon' value:icon. |
|
221 |
addButton value:#bottomRight value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
222 |
addButton value:#center value:'Mixed' value:(Array with:'String' with:icon). |
|
223 |
||
224 |
topView label:'Drag & Drop'. |
|
225 |
topView openWithExtent:200@200. |
|
226 |
[exEnd] |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
227 |
" |
341 | 228 |
! ! |
229 |
||
628 | 230 |
!DragAndDropManager class methodsFor:'initialization'! |
231 |
||
232 |
initialize |
|
233 |
DragOriginatorQuerySignal := QuerySignal new. |
|
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
234 |
DragOffsetQuerySignal := QuerySignal new. |
628 | 235 |
|
236 |
" |
|
237 |
self initialize |
|
238 |
" |
|
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
239 |
|
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
240 |
"Modified: 11.8.1997 / 00:54:21 / cg" |
874 | 241 |
! |
242 |
||
243 |
new |
|
244 |
^ self basicNew initialize |
|
628 | 245 |
! ! |
246 |
||
247 |
!DragAndDropManager class methodsFor:'Signal constants'! |
|
248 |
||
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
249 |
dragOffsetQuerySignal |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
250 |
^ DragOffsetQuerySignal |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
251 |
|
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
252 |
"Created: 11.8.1997 / 00:54:10 / cg" |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
253 |
! |
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
254 |
|
628 | 255 |
dragOriginatorQuerySignal |
256 |
^ DragOriginatorQuerySignal |
|
257 |
! ! |
|
258 |
||
874 | 259 |
!DragAndDropManager class methodsFor:'simple start - drop source'! |
260 |
||
261 |
startDragFrom:aView dropSource:aDropSource |
|
262 |
"start a drop at the current pointer position. |
|
263 |
" |
|
264 |
^ (self new) startDragFrom:aView dropSource:aDropSource |
|
265 |
! ! |
|
266 |
||
267 |
!DragAndDropManager class methodsFor:'simple start - generic'! |
|
268 |
||
269 |
startDrag:draggableObjects from:aView |
|
270 |
"start a drop at the current pointer position |
|
271 |
" |
|
272 |
^ self startDrag:draggableObjects |
|
273 |
from:aView |
|
274 |
offset:0@0 |
|
275 |
atEnd:nil |
|
276 |
display:draggableObjects |
|
277 |
||
278 |
" |
|
279 |
EXAMPLE: |
|
280 |
||
281 |
|button| |
|
282 |
||
283 |
button := (Button label:'press me'). |
|
284 |
||
285 |
button pressAction:[ |
|
286 |
DragAndDropManager startDrag:(DropObject newFile:('.')) from:button. |
|
287 |
button turnOff |
|
288 |
]. |
|
289 |
||
290 |
button openAt:100@100 |
|
291 |
" |
|
292 |
! |
|
293 |
||
294 |
startDrag:draggableObjects from:aView atEnd:aFourArgEndBlock |
|
295 |
"start a drop at the current pointer position |
|
296 |
When finished, the endAction is called with four args: |
|
297 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
298 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
299 |
" |
|
300 |
^ self startDrag:draggableObjects |
|
301 |
from:aView |
|
302 |
offset:0@0 |
|
303 |
atEnd:aFourArgEndBlock |
|
304 |
display:draggableObjects |
|
305 |
||
306 |
" |
|
307 |
EXAMPLE: |
|
308 |
||
309 |
|button| |
|
310 |
||
311 |
button := (Button label:'press me'). |
|
312 |
||
313 |
button pressAction:[ |
|
314 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
|
315 |
from:button |
|
316 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
317 |
Transcript showCR:'target view: ', targetView printString. |
|
318 |
Transcript showCR:'target id: ', targetViewId printString. |
|
319 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
320 |
Transcript showCR:'point target: ', targetPoint printString. |
|
321 |
]. |
|
322 |
button turnOff |
|
323 |
]. |
|
324 |
||
325 |
button openAt:100@100 |
|
326 |
" |
|
327 |
||
328 |
! |
|
329 |
||
330 |
startDrag:draggableObjects from:aView atEnd:aFourArgEndBlock display:something |
|
331 |
"start a drop at the current pointer position |
|
332 |
When finished, the endAction is called with four args: |
|
333 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
334 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
335 |
" |
|
336 |
^ self startDrag:draggableObjects |
|
337 |
from:aView |
|
338 |
offset:0@0 |
|
339 |
atEnd:aFourArgEndBlock |
|
340 |
display:something |
|
341 |
||
342 |
" |
|
343 |
EXAMPLE: |
|
344 |
||
345 |
|button| |
|
346 |
||
347 |
button := (Button label:'press me'). |
|
348 |
||
349 |
button pressAction:[ |
|
350 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
|
351 |
from:button |
|
352 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
353 |
Transcript showCR:'target view: ', targetView printString. |
|
354 |
Transcript showCR:'target id: ', targetViewId printString. |
|
355 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
356 |
Transcript showCR:'point target: ', targetPoint printString. |
|
357 |
] |
|
358 |
display:(Array with:'String' with:(Image fromFile:('xpmBitmaps/QUESTION3.xpm'))). |
|
359 |
button turnOff |
|
360 |
]. |
|
361 |
||
362 |
button openAt:100@100 |
|
363 |
" |
|
364 |
! |
|
365 |
||
366 |
startDrag:draggableObjects from:aView display:something |
|
367 |
"start a drop at the current pointer position |
|
368 |
" |
|
369 |
^ self startDrag:draggableObjects |
|
370 |
from:aView |
|
371 |
offset:0@0 |
|
372 |
atEnd:nil |
|
373 |
display:something |
|
374 |
||
375 |
" |
|
376 |
EXAMPLE: |
|
377 |
||
378 |
|dropObj topView pannel icon buttonAction addButton| |
|
379 |
||
380 |
topView := StandardSystemView new. |
|
381 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
382 |
pannel horizontalLayout:#fit. |
|
383 |
pannel verticalLayout:#fitSpace. |
|
384 |
||
385 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
386 |
dropObj := DropObject newFile:('.'). |
|
387 |
||
388 |
addButton := [:label :dispObj| |button| |
|
389 |
button := Button label:label in:pannel. |
|
390 |
||
391 |
button pressAction:[ |
|
392 |
DragAndDropManager startDrag:dropObj from:button display:dispObj. |
|
393 |
button turnOff. |
|
394 |
] |
|
395 |
]. |
|
396 |
||
397 |
addButton value:'String' value:'String'. |
|
398 |
addButton value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
399 |
addButton value:'Icon' value:icon. |
|
400 |
addButton value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
401 |
addButton value:'Mixed' value:(Array with:'String' with:icon). |
|
402 |
||
403 |
topView label:'Drag & Drop'. |
|
404 |
topView openWithExtent:200@200. |
|
405 |
" |
|
406 |
! |
|
407 |
||
408 |
startDrag:draggableObjects from:aView offset:anOffset |
|
409 |
"start a drop at the current pointer position |
|
410 |
" |
|
411 |
^ self startDrag:draggableObjects |
|
412 |
from:aView |
|
413 |
offset:anOffset |
|
414 |
atEnd:nil |
|
415 |
display:draggableObjects |
|
416 |
||
417 |
" |
|
418 |
EXAMPLE: |
|
419 |
||
420 |
|button| |
|
421 |
||
422 |
button := (Button label:'press me'). |
|
423 |
||
424 |
button pressAction:[ |
|
425 |
DragAndDropManager startDrag:(DropObject newFile:('.')) from:button offset:(-10 @ -10). |
|
426 |
button turnOff |
|
427 |
]. |
|
428 |
||
429 |
button openAt:100@100 |
|
430 |
" |
|
431 |
||
432 |
! |
|
433 |
||
434 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock |
|
435 |
"start a drop at the current pointer position |
|
436 |
When finished, the endAction is called with four args: |
|
437 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
438 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
439 |
" |
|
440 |
^ self startDrag:draggableObjects |
|
441 |
from:aView |
|
442 |
offset:anOffset |
|
443 |
atEnd:aFourArgEndBlock |
|
444 |
display:draggableObjects |
|
445 |
||
446 |
" |
|
447 |
EXAMPLE: |
|
448 |
||
449 |
|button| |
|
450 |
||
451 |
button := (Button label:'press me'). |
|
452 |
||
453 |
button pressAction:[ |
|
454 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
|
455 |
from:button |
|
456 |
offset:(-10 @ -10) |
|
457 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
458 |
Transcript showCR:'target view: ', targetView printString. |
|
459 |
Transcript showCR:'target id: ', targetViewId printString. |
|
460 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
461 |
Transcript showCR:'point target: ', targetPoint printString. |
|
462 |
]. |
|
463 |
button turnOff |
|
464 |
]. |
|
465 |
||
466 |
button openAt:100@100 |
|
467 |
" |
|
468 |
||
469 |
! |
|
470 |
||
471 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock display:something |
|
472 |
"start a drop at the current pointer position |
|
473 |
When finished, the endAction is called with four args: |
|
474 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
475 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
476 |
" |
|
477 |
|manager| |
|
478 |
||
479 |
manager := self new. |
|
480 |
||
481 |
manager startDrag:draggableObjects |
|
482 |
from:aView |
|
483 |
offset:anOffset |
|
484 |
atEnd:aFourArgEndBlock |
|
485 |
display:something. |
|
486 |
||
487 |
^ manager |
|
488 |
||
489 |
" |
|
490 |
EXAMPLE: |
|
491 |
||
492 |
|button| |
|
493 |
||
494 |
button := (Button label:'press me'). |
|
495 |
||
496 |
button pressAction:[ |
|
497 |
DragAndDropManager startDrag:(DropObject newFile:('.')) |
|
498 |
from:button |
|
499 |
offset:(-10 @ -10) |
|
500 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
501 |
Transcript showCR:'target view: ', targetView printString. |
|
502 |
Transcript showCR:'target id: ', targetViewId printString. |
|
503 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
504 |
Transcript showCR:'point target: ', targetPoint printString. |
|
505 |
] |
|
506 |
display:(Array with:'String' with:(Image fromFile:('xpmBitmaps/QUESTION3.xpm'))). |
|
507 |
button turnOff |
|
508 |
]. |
|
509 |
||
510 |
button openAt:100@100 |
|
511 |
" |
|
512 |
||
513 |
! |
|
514 |
||
515 |
startDrag:draggableObjects from:aView offset:anOffset display:something |
|
516 |
"start a drop at the current pointer position |
|
517 |
" |
|
518 |
^ self startDrag:draggableObjects |
|
519 |
from:aView |
|
520 |
offset:anOffset |
|
521 |
atEnd:nil |
|
522 |
display:something |
|
523 |
||
524 |
" |
|
525 |
EXAMPLE: |
|
526 |
||
527 |
|dropObj topView pannel icon buttonAction addButton| |
|
528 |
||
529 |
topView := StandardSystemView new. |
|
530 |
pannel := VerticalPanelView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:topView. |
|
531 |
pannel horizontalLayout:#fit. |
|
532 |
pannel verticalLayout:#fitSpace. |
|
533 |
||
534 |
icon := Image fromFile:('xpmBitmaps/QUESTION3.xpm'). |
|
535 |
dropObj := DropObject newFile:('.'). |
|
536 |
||
537 |
addButton := [:offset :label :dispObj| |button| |
|
538 |
button := Button label:label in:pannel. |
|
539 |
||
540 |
button pressAction:[ |
|
541 |
DragAndDropManager startDrag:dropObj from:button offset:offset display:dispObj. |
|
542 |
button turnOff. |
|
543 |
] |
|
544 |
]. |
|
545 |
||
546 |
addButton value:#topLeft value:'String' value:'String'. |
|
547 |
addButton value:#topRight value:'Text' value:(Text string:'hello' emphasis:#bold). |
|
548 |
addButton value:#bottomLeft value:'Icon' value:icon. |
|
549 |
addButton value:#bottomRight value:'LabelAndIcon' value:(LabelAndIcon icon:icon string:'Label & Icon'). |
|
550 |
addButton value:#center value:'Mixed' value:(Array with:'String' with:icon). |
|
551 |
||
552 |
topView label:'Drag & Drop'. |
|
553 |
topView openWithExtent:200@200. |
|
554 |
" |
|
555 |
||
556 |
! ! |
|
557 |
||
558 |
!DragAndDropManager class methodsFor:'simple start - lines'! |
|
397 | 559 |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
560 |
startArrowDragIn:aView at:dragPoint atEnd:aFourArgBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
561 |
"start a rubber-arrow-line dragging in aView at dragPoint. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
562 |
When finished, evaluate the fourArgBlock with targetView, |
874 | 563 |
targetID, screenPosition and targetViewPosition as arguments |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
564 |
" |
874 | 565 |
^ self new startArrowDragIn:aView at:dragPoint atEnd:aFourArgBlock |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
566 |
|
874 | 567 |
" |
568 |
EXAMPLE: |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
569 |
|
874 | 570 |
|button| |
397 | 571 |
|
874 | 572 |
button := (Button label:'press me'). |
861 | 573 |
|
874 | 574 |
button pressAction:[ |
575 |
button turnOff. |
|
861 | 576 |
|
874 | 577 |
DragAndDropManager startArrowDragIn:button |
578 |
at:(button preferredExtent // 2) |
|
579 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
580 |
targetView isNil ifTrue:[ |
|
581 |
Transcript show:'alien view' |
|
582 |
] ifFalse:[ |
|
583 |
Transcript showCR:'target: ', targetView printString |
|
584 |
]. |
|
585 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
586 |
Transcript showCR:'point target: ', targetPoint printString. |
|
587 |
] |
|
588 |
]. |
|
589 |
button openAt:100@100 |
|
590 |
" |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
591 |
! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
592 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
593 |
startLineDragIn:aView at:dragPoint atEnd:aFourArgBlock |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
594 |
"start a rubber-line dragging in aView at dragPoint. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
595 |
When finished, evaluate the fourArgBlock with targetView, |
874 | 596 |
targetID, screenPosition and targetViewPosition as arguments |
597 |
" |
|
598 |
^ self new startLineDragIn:aView at:dragPoint atEnd:aFourArgBlock |
|
599 |
||
600 |
" |
|
601 |
EXAMPLE: |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
602 |
|
874 | 603 |
|button| |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
604 |
|
874 | 605 |
button := (Button label:'press me'). |
606 |
||
607 |
button pressAction:[ |
|
608 |
button turnOff. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
609 |
|
874 | 610 |
DragAndDropManager startLineDragIn:button |
611 |
at:(button preferredExtent // 2) |
|
612 |
atEnd:[:targetView :targetViewId :screenPoint :targetPoint| |
|
613 |
targetView isNil ifTrue:[ |
|
614 |
Transcript show:'alien view' |
|
615 |
] ifFalse:[ |
|
616 |
Transcript showCR:'target: ', targetView printString |
|
617 |
]. |
|
618 |
Transcript showCR:'point screen: ', screenPoint printString. |
|
619 |
Transcript showCR:'point target: ', targetPoint printString. |
|
620 |
] |
|
621 |
]. |
|
622 |
button openAt:100@100 |
|
623 |
" |
|
397 | 624 |
! ! |
625 |
||
394 | 626 |
!DragAndDropManager methodsFor:'accessing'! |
627 |
||
861 | 628 |
device |
629 |
"returns the device of the source view |
|
630 |
" |
|
631 |
^ dragView device |
|
632 |
||
633 |
||
634 |
! |
|
635 |
||
874 | 636 |
dropContext |
637 |
"return the current context |
|
638 |
" |
|
639 |
^ dropContext |
|
640 |
! |
|
641 |
||
397 | 642 |
dropObjects |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
643 |
"return the current dropObject collection" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
644 |
|
874 | 645 |
^ dropContext dropObjects |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
646 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
647 |
"Modified: 19.4.1997 / 10:19:06 / cg" |
397 | 648 |
! |
649 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
650 |
dropObjects:aCollectionOfDropObjects |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
651 |
"set the current dropObject collection" |
397 | 652 |
|
874 | 653 |
^ dropContext dropObjects:aCollectionOfDropObjects |
861 | 654 |
! |
655 |
||
656 |
font |
|
657 |
"returns the font of the source view |
|
658 |
" |
|
659 |
^ dragView font |
|
660 |
||
661 |
||
874 | 662 |
! |
663 |
||
664 |
sourceWidget |
|
665 |
^ dragView |
|
666 |
! ! |
|
667 |
||
668 |
!DragAndDropManager methodsFor:'accessing cursor'! |
|
669 |
||
670 |
alienCursor:aCursorOrImage |
|
671 |
"set the cursor used for an alien widget; not an ST/X view |
|
672 |
" |
|
673 |
aCursorOrImage isImage ifTrue:[ |
|
674 |
alienCursor := Cursor fromImage:aCursorOrImage |
|
675 |
] ifFalse:[ |
|
676 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
|
677 |
alienCursor := aCursorOrImage |
|
678 |
] ifFalse:[ |
|
679 |
"/ |
|
680 |
"/ use disabled cursor |
|
681 |
"/ |
|
682 |
alienCursor := nil |
|
683 |
] |
|
684 |
] |
|
685 |
! |
|
686 |
||
687 |
disabledCursor:aCursorOrImage |
|
688 |
"set the cursor for an ST/X view, which can not drop the objects |
|
689 |
" |
|
690 |
aCursorOrImage isImage ifTrue:[ |
|
691 |
disabledCursor := Cursor fromImage:aCursorOrImage |
|
692 |
] ifFalse:[ |
|
693 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
|
694 |
disabledCursor := aCursorOrImage |
|
695 |
] |
|
696 |
] |
|
697 |
! |
|
698 |
||
699 |
enabledCursor:aCursorOrImage |
|
700 |
"set the cursor for an ST/X view, which can drop the objects |
|
701 |
" |
|
702 |
aCursorOrImage isImage ifTrue:[ |
|
703 |
enabledCursor := Cursor fromImage:aCursorOrImage |
|
704 |
] ifFalse:[ |
|
705 |
(aCursorOrImage isMemberOf:Cursor) ifTrue:[ |
|
706 |
enabledCursor := aCursorOrImage |
|
707 |
] |
|
708 |
] |
|
709 |
||
710 |
! ! |
|
711 |
||
712 |
!DragAndDropManager methodsFor:'dragging - drop source'! |
|
713 |
||
714 |
startDragFrom:aView dropSource:aDropSource |
|
715 |
"start a drop at the current pointer position. |
|
716 |
" |
|
717 |
^ self startDragFrom:aView dropSource:aDropSource offset:#topLeft "/ #center |
|
718 |
! |
|
719 |
||
720 |
startDragFrom:aView dropSource:aDropSource offset:anOffset |
|
721 |
"start a drop at the current pointer position. |
|
722 |
" |
|
723 |
dropContext dropSource:aDropSource. |
|
724 |
||
725 |
^ self startDrag:(aDropSource dropObjects) |
|
726 |
from:aView |
|
727 |
offset:anOffset |
|
728 |
atEnd:nil |
|
729 |
display:(aDropSource displayObjects) |
|
730 |
! ! |
|
731 |
||
732 |
!DragAndDropManager methodsFor:'dragging - easy startup'! |
|
733 |
||
734 |
startDrag:draggableObjects from:aView |
|
735 |
"start a drop at the current pointer position |
|
736 |
" |
|
737 |
^ self startDrag:draggableObjects |
|
738 |
from:aView |
|
739 |
offset:0@0 |
|
740 |
! |
|
741 |
||
742 |
startDrag:draggableObjects from:aView display:something |
|
743 |
"start a drop at the current pointer position. |
|
744 |
" |
|
745 |
^ self startDrag:draggableObjects |
|
746 |
from:aView |
|
747 |
offset:nil |
|
748 |
atEnd:nil |
|
749 |
display:something |
|
750 |
! |
|
751 |
||
752 |
startDrag:draggableObjects from:aView offset:anOffset |
|
753 |
"start a drop at the current pointer position with an offset |
|
754 |
" |
|
755 |
^ self startDrag:draggableObjects |
|
756 |
from:aView |
|
757 |
offset:anOffset |
|
758 |
atEnd:nil |
|
759 |
! |
|
760 |
||
761 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgEndBlock |
|
762 |
"start a drop at the current pointer position. |
|
763 |
When finished, the endAction is called with four args: |
|
764 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
765 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
766 |
" |
|
767 |
^ self startDrag:draggableObjects |
|
768 |
from:aView |
|
769 |
offset:anOffset |
|
770 |
atEnd:aFourArgEndBlock |
|
771 |
display:draggableObjects |
|
772 |
! |
|
773 |
||
774 |
startDrag:draggableObjects from:aView offset:anOffset atEnd:aFourArgBlock display:something |
|
775 |
"start a drop at the current pointer position. |
|
776 |
When finished, the endAction is called with four args: |
|
777 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
778 |
the dropPoint in root-coordinates and the dropPoint within the targetView. |
|
779 |
" |
|
780 |
|height width fontWdt dispObj offset ascent device dispObjs list space| |
|
781 |
||
782 |
self dropObjects:draggableObjects. |
|
783 |
||
784 |
self dropObjects size == 0 ifTrue:[ |
|
785 |
^ self |
|
786 |
]. |
|
787 |
||
788 |
device := aView device. |
|
789 |
space := 1. |
|
790 |
height := space negated. |
|
791 |
width := 0. |
|
792 |
fontWdt := aView font width. |
|
793 |
ascent := aView font ascent. |
|
794 |
||
795 |
(list := something) isNil ifTrue:[ |
|
796 |
list := self dropObjects |
|
797 |
] ifFalse:[ |
|
798 |
(list isCollection not or:[list isString]) ifTrue:[ |
|
799 |
list := Array with:something |
|
800 |
] |
|
801 |
]. |
|
802 |
dispObjs := OrderedCollection new. |
|
803 |
||
804 |
list do:[:el| |
|
805 |
|obj asc| |
|
806 |
||
807 |
obj := self displayObjectFor:el on:device. |
|
808 |
asc := (obj respondsTo:#string) ifTrue:[ascent] ifFalse:[0]. |
|
809 |
height := height + space. |
|
810 |
||
811 |
dispObjs add:(Array with:obj with:(0 @ (height + asc))). |
|
812 |
width := width max:(obj widthOn:aView). |
|
813 |
height := height + (obj heightOn:aView). |
|
814 |
]. |
|
815 |
||
816 |
offset := self computeOffset:anOffset w:width h:height. |
|
817 |
||
818 |
dispObjs do:[:el| el at:2 put:((el at:2) - offset) ]. |
|
819 |
||
820 |
self startOpaqueDrag:[:p :v| dispObjs do:[:el| (el at:1) displayOn:v at:p + (el at:2)] ] |
|
821 |
offset:offset |
|
822 |
extent:width @ height |
|
823 |
in:aView |
|
824 |
at:nil |
|
825 |
atEnd:aFourArgBlock |
|
826 |
! |
|
827 |
||
828 |
startDrag:draggableObjects from:aView offset:anOffset display:something |
|
829 |
"start a drop at the current pointer position. |
|
830 |
" |
|
831 |
^ self startDrag:draggableObjects |
|
832 |
from:aView |
|
833 |
offset:anOffset |
|
834 |
atEnd:nil |
|
835 |
display:something |
|
394 | 836 |
! ! |
837 |
||
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
838 |
!DragAndDropManager methodsFor:'dragging - generic'! |
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
839 |
|
348 | 840 |
startGenericDrag:aTwoArgDragBlock in:aView at:p atEnd:aFourArgEndBlock |
841 |
"start a generic (caller-provided drag); |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
842 |
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
|
843 |
by inverting again). See startOpaqueDrag for another variant. |
348 | 844 |
the dragBlock, aTwoArgDragBlock will be called with two args |
845 |
aPoint and a drawingGC, to perform the drawing at some dragPoint. |
|
846 |
The drag starts in aView at point p. |
|
847 |
When finished, the endAction is called with four args: |
|
848 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
874 | 849 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
850 |
" |
|
851 |
^ self startOpaqueDrag:aTwoArgDragBlock |
|
852 |
offset:nil |
|
853 |
extent:nil |
|
854 |
in:aView |
|
855 |
at:nil |
|
856 |
atEnd:aFourArgEndBlock |
|
394 | 857 |
! |
858 |
||
874 | 859 |
startOpaqueDrag:aDragBlock offset:offs extent:anExtent in:aView at:aDummyPoint atEnd:aFourArgEndBlock |
860 |
"start an opaque or generic opaque (caller-provided drag); |
|
394 | 861 |
opaque drag means, that the drawing cannot be undone by two inverting |
862 |
draws, but instead, the area under the dragged object must be saved |
|
874 | 863 |
and restored. The areas size to be saved/restored is passed in anExtent. |
864 |
the dragBlock, aDragBlock will be called with up to three args aPoint, a |
|
865 |
drawingGC and the display objects, to perform the drawing at some dragPoint. |
|
394 | 866 |
The drag starts in aView at point p. |
867 |
When finished, the endAction is called with four args: |
|
868 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
874 | 869 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
870 |
" |
|
871 |
|handler numArgs dragBlock dobjs| |
|
394 | 872 |
|
874 | 873 |
dragOffset := offs ? (Point x:0 y:0). |
874 |
numArgs := aDragBlock numArgs. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
875 |
|
874 | 876 |
numArgs == 3 ifTrue:[ |
877 |
dobjs := self dropObjects. |
|
878 |
dragBlock := [:p :v| aDragBlock value:p value:v value:dobjs ] |
|
879 |
] ifFalse:[ |
|
880 |
numArgs == 1 ifTrue:[ |
|
881 |
dragBlock := [:p :v| aDragBlock value:p ] |
|
882 |
] ifFalse:[ |
|
883 |
dragBlock := aDragBlock |
|
884 |
] |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
885 |
]. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
886 |
|
874 | 887 |
anExtent isNil ifTrue:[ |
888 |
handler := DragHandler startGenericDrag:dragBlock. |
|
889 |
] ifFalse:[ |
|
890 |
handler := DragHandler startOpaqueDrag:dragBlock extent:anExtent offset:dragOffset. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
891 |
]. |
874 | 892 |
self doStart:handler for:aView atEnd:aFourArgEndBlock |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
893 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
894 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
895 |
|
342
7563cbf04502
added genericDrag & arrowDrag
Claus Gittinger <cg@exept.de>
parents:
341
diff
changeset
|
896 |
!DragAndDropManager methodsFor:'dragging - lines'! |
341 | 897 |
|
874 | 898 |
startArrowDragIn:aView at:aStartPoint atEnd:aFourArgEndBlock |
899 |
"start a line-drag of an arrow-line. |
|
900 |
The drag starts in aView at point aStartPoint. |
|
901 |
When finished, the endAction is called with four args: |
|
902 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
903 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
|
904 |
" |
|
905 |
|p| |
|
341 | 906 |
|
874 | 907 |
p := self translatePointToScreen:aStartPoint from:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
908 |
|
874 | 909 |
self doStart:(DragHandler startArrowDragAt:p) |
910 |
for:aView |
|
911 |
atEnd:aFourArgEndBlock |
|
341 | 912 |
! |
913 |
||
874 | 914 |
startLineDragIn:aView at:aStartPoint atEnd:aFourArgEndBlock |
915 |
"start a line-drag of a normal line. |
|
916 |
The drag starts in aView at point aStartPoint. |
|
348 | 917 |
When finished, the endAction is called with four args: |
918 |
the targetView, the targetViews windowID (useful, if its an alien view), |
|
874 | 919 |
the dropPoint in root-coordinates and the dropPoint within the targetView |
920 |
" |
|
921 |
|p| |
|
341 | 922 |
|
874 | 923 |
p := self translatePointToScreen:aStartPoint from:aView. |
348 | 924 |
|
874 | 925 |
self doStart:(DragHandler startLineDragAt:p) |
926 |
for:aView |
|
927 |
atEnd:aFourArgEndBlock |
|
341 | 928 |
! ! |
929 |
||
397 | 930 |
!DragAndDropManager methodsFor:'drawing'! |
931 |
||
874 | 932 |
computeOffset:anOffset w:w h:h |
933 |
|p| |
|
934 |
||
935 |
anOffset isSymbol ifFalse:[ |
|
936 |
^ anOffset notNil ifTrue:[anOffset] ifFalse:[0@0] |
|
937 |
]. |
|
938 |
anOffset == #topLeft ifTrue:[ ^ 0 @ 0]. |
|
939 |
anOffset == #topRight ifTrue:[ ^ w @ 0]. |
|
940 |
||
941 |
anOffset == #bottomLeft ifTrue:[ ^ 0 @ h]. |
|
942 |
anOffset == #bottomRight ifTrue:[ ^ w @ h]. |
|
943 |
||
944 |
p := (w @ h) // 2. |
|
945 |
||
946 |
anOffset == #center ifTrue:[ ^ p ]. |
|
947 |
||
948 |
anOffset == #topCenter ifTrue:[ ^ p x @ 0 ]. |
|
949 |
anOffset == #bottomCenter ifTrue:[ ^ p x @ h ]. |
|
950 |
||
951 |
anOffset == #leftCenter ifTrue:[ ^ 0 @ p y ]. |
|
952 |
anOffset == #rightCenter ifTrue:[ ^ w @ p y ]. |
|
953 |
||
954 |
Transcript showCR:'unsupported offset: ', anOffset printString. |
|
955 |
^ 0 @ 0 |
|
956 |
! |
|
957 |
||
958 |
displayObjectFor:anObject on:aDevice |
|
959 |
"converts an object to a display object |
|
960 |
" |
|
961 |
|obj icon s1 s2| |
|
962 |
||
963 |
obj := (anObject respondsTo:#displayObject) ifTrue:[anObject displayObject] |
|
964 |
ifFalse:[anObject]. |
|
965 |
||
966 |
obj isString ifTrue:[ |
|
967 |
^ obj |
|
968 |
]. |
|
969 |
||
970 |
obj messageNotUnderstoodSignal handle:[:ex|] do:[ |
|
971 |
obj := obj on:aDevice |
|
972 |
]. |
|
973 |
||
974 |
obj isImage ifTrue:[ |
|
975 |
^ obj clearMaskedPixels |
|
976 |
]. |
|
977 |
||
978 |
obj class == LabelAndIcon ifTrue:[ |
|
979 |
obj image notNil ifTrue:[obj image clearMaskedPixels]. |
|
980 |
obj icon notNil ifTrue:[obj icon clearMaskedPixels]. |
|
981 |
^ obj |
|
982 |
]. |
|
983 |
||
984 |
(obj class == MultiColListEntry) ifFalse:[ |
|
985 |
^ obj |
|
986 |
]. |
|
987 |
s1 := obj colAt:1. |
|
988 |
s2 := obj colAt:2. |
|
989 |
||
990 |
s1 isImage ifTrue:[ |
|
991 |
s2 isImage ifTrue:[ ^ self displayObjectFor:(LabelAndIcon form:s1 image:s2) on:aDevice ]. |
|
992 |
s2 isString ifTrue:[ ^ self displayObjectFor:(LabelAndIcon icon:s1 string:s2) on:aDevice ]. |
|
993 |
^ (s1 on:aDevice) clearMaskedPixels |
|
994 |
]. |
|
995 |
||
996 |
s2 isImage ifTrue:[ |
|
997 |
s1 isString ifTrue:[ ^ self displayObjectFor:(LabelAndIcon icon:s2 string:s1) on:aDevice ]. |
|
998 |
^ (s2 on:aDevice) clearMaskedPixels |
|
999 |
]. |
|
1000 |
||
1001 |
s1 isString ifTrue:[^ s1]. |
|
1002 |
s2 isString ifTrue:[^ s2]. |
|
1003 |
^ obj |
|
1004 |
! |
|
1005 |
||
397 | 1006 |
showDragging:items in:aView at:p |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1007 |
"helper for dragging dragObjects: draw them all" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1008 |
|
397 | 1009 |
|offs| |
1010 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1011 |
offs := 0. |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1012 |
items do:[:item | |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1013 |
item displayOn:aView at:p + (0@offs). |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1014 |
offs := offs + (item heightOn:self) |
397 | 1015 |
] |
1016 |
||
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1017 |
"Modified: 19.4.1997 / 12:41:24 / cg" |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1018 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1019 |
|
341 | 1020 |
!DragAndDropManager methodsFor:'event catching'! |
1021 |
||
1022 |
buttonMotion:button x:x y:y view:aView |
|
874 | 1023 |
"handle a button motion event |
1024 |
" |
|
1025 |
|oldPt oldTgt oldWg oldId newWg newId newTgt point rootId cursor device isDroppable| |
|
1026 |
||
1027 |
device := dragView device. |
|
1028 |
rootId := device rootView id. |
|
1029 |
point := self translatePointToScreen:(x @ y) from:dragView. |
|
1030 |
oldWg := dropContext targetWidget. |
|
1031 |
oldId := dropContext targetId. |
|
1032 |
oldPt := dropContext rootPoint. |
|
1033 |
||
1034 |
dropContext rootPoint:point. |
|
1035 |
||
1036 |
"/ |
|
1037 |
"/ search view the drop is in |
|
1038 |
"/ |
|
1039 |
[ newId := rootId. |
|
1040 |
(rootId := device viewIdFromPoint:point in:newId) notNil |
|
1041 |
] whileTrue. |
|
1042 |
||
1043 |
newWg := device viewFromId:newId. |
|
1044 |
dropContext targetWidget:newWg id:newId. |
|
1045 |
||
1046 |
handler isInterestedInDropTarget ifFalse:[ |
|
1047 |
"/ |
|
1048 |
"/ line or arrow handler |
|
1049 |
"/ |
|
1050 |
handler dragTo:point. |
|
1051 |
^ self |
|
1052 |
]. |
|
1053 |
||
1054 |
oldWg ~~ newWg ifTrue:[ |
|
1055 |
"/ |
|
1056 |
"/ widget has changed: drop target might change |
|
1057 |
"/ |
|
1058 |
oldTgt := dropContext dropTarget. |
|
1059 |
newTgt := self doFindDropTargetIn:newWg at:point. |
|
1060 |
||
1061 |
newTgt ~= oldTgt ifTrue:[ |
|
1062 |
"/ |
|
1063 |
"/ drop target changed: handler might restore the screen |
|
1064 |
"/ |
|
1065 |
handler dropTargetWillChange. |
|
341 | 1066 |
|
874 | 1067 |
oldTgt notNil ifTrue:[ |
1068 |
"/ |
|
1069 |
"/ setup old context |
|
1070 |
"/ |
|
1071 |
dropContext targetWidget:oldWg id:oldId. |
|
1072 |
oldTgt leave:dropContext. |
|
1073 |
dropContext targetWidget:newWg id:newId. |
|
1074 |
]. |
|
1075 |
dropContext dropTarget:newTgt. |
|
1076 |
newTgt notNil ifTrue:[ newTgt enter:dropContext ] |
|
1077 |
] ifFalse:[ |
|
1078 |
dropContext dropTarget:newTgt |
|
1079 |
] |
|
1080 |
] ifFalse:[ |
|
1081 |
(oldPt notNil and:[(oldPt dist:point) < 2 ]) ifTrue:[ |
|
1082 |
"/ |
|
1083 |
"/ ignorre the button motion event; restore old rootPoint |
|
1084 |
"/ |
|
1085 |
dropContext rootPoint:oldPt. |
|
1086 |
^ self |
|
1087 |
]. |
|
1088 |
newTgt := dropContext dropTarget |
|
1089 |
]. |
|
1090 |
"/ |
|
1091 |
"/ update the cursor |
|
1092 |
"/ |
|
1093 |
(isDroppable := dropContext canDrop) ifTrue:[ |
|
1094 |
cursor := enabledCursor |
|
1095 |
] ifFalse:[ |
|
1096 |
cursor := dropContext isAlienView ifFalse:[disabledCursor] |
|
1097 |
ifTrue:[alienCursor] |
|
1098 |
]. |
|
1099 |
dragView cursor:cursor now:true. |
|
1100 |
"/ |
|
1101 |
"/ test if droppable state changed |
|
1102 |
"/ |
|
1103 |
canDrop == isDroppable ifFalse:[ |
|
1104 |
"/ |
|
1105 |
"/ droppable state changed: handler might restore the screen |
|
1106 |
"/ |
|
1107 |
canDrop := isDroppable. |
|
1108 |
handler dropTargetWillChange |
|
1109 |
]. |
|
394 | 1110 |
|
874 | 1111 |
newTgt notNil ifTrue:[ newTgt over:dropContext ]. |
1112 |
handler dragTo:point. |
|
1113 |
! |
|
394 | 1114 |
|
874 | 1115 |
buttonMultiPress:button x:x y:y view:aView |
1116 |
"discard each buttonMultiPress event |
|
1117 |
" |
|
1118 |
! |
|
1119 |
||
1120 |
buttonPress:button x:x y:y view:aView |
|
1121 |
"discard each buttonPress event |
|
1122 |
" |
|
341 | 1123 |
! |
1124 |
||
1125 |
buttonRelease:button x:x y:y view:aView |
|
874 | 1126 |
"button released; do the drop |
1127 |
" |
|
1128 |
((button == 2) or:[button == #menu]) ifTrue:[ |
|
1129 |
^ self |
|
1130 |
]. |
|
1131 |
"/ |
|
1132 |
"/ update the context |
|
1133 |
"/ |
|
1134 |
self buttonMotion:button x:x y:y view:aView. |
|
1135 |
||
1136 |
"/ |
|
1137 |
"/ restore source view |
|
1138 |
"/ |
|
1139 |
restoreBlock value. |
|
394 | 1140 |
|
874 | 1141 |
"/ |
1142 |
"/ at least do the drop operation |
|
1143 |
"/ |
|
1144 |
dropAction isNil ifTrue:[ |
|
1145 |
dropContext doDrop |
|
1146 |
] ifFalse:[ |
|
1147 |
"/ |
|
1148 |
"/ initiator wants to do it himself, manually. |
|
1149 |
"/ Thus, no feedBack operation invoked. |
|
1150 |
"/ |
|
1151 |
dropAction value:(dropContext targetWidget) |
|
1152 |
value:(dropContext targetId) |
|
1153 |
value:(dropContext rootPoint) |
|
1154 |
value:(dropContext targetPoint). |
|
1155 |
] |
|
341 | 1156 |
! |
1157 |
||
1158 |
handlesButtonMotion:button inView:aView |
|
1159 |
"query from event processor: am I interested in button-events ? |
|
1160 |
yes I am (to activate the clicked-on field)." |
|
1161 |
||
874 | 1162 |
^ dragView == aView |
1163 |
! |
|
1164 |
||
1165 |
handlesButtonMultiPress:button inView:aView |
|
1166 |
"query from event processor: am I interested in button-events ? |
|
1167 |
yes I am (to activate the clicked-on field)." |
|
341 | 1168 |
|
874 | 1169 |
^ dragView == aView |
1170 |
! |
|
394 | 1171 |
|
874 | 1172 |
handlesButtonPress:button inView:aView |
1173 |
"query from event processor: am I interested in button-events ? |
|
1174 |
yes I am (to activate the clicked-on field)." |
|
1175 |
||
1176 |
^ dragView == aView |
|
341 | 1177 |
! |
1178 |
||
1179 |
handlesButtonRelease:button inView:aView |
|
1180 |
"query from event processor: am I interested in button-events ? |
|
1181 |
yes I am (to activate the clicked-on field)." |
|
1182 |
||
874 | 1183 |
^ dragView == aView |
1184 |
! ! |
|
1185 |
||
1186 |
!DragAndDropManager methodsFor:'initialization'! |
|
341 | 1187 |
|
874 | 1188 |
initialize |
1189 |
super initialize. |
|
394 | 1190 |
|
874 | 1191 |
dragOffset := 0 @ 0. |
1192 |
dropContext := DropContext new. |
|
1193 |
alienCursor := Cursor questionMark. |
|
1194 |
enabledCursor := Cursor thumbsUp. |
|
1195 |
disabledCursor := Cursor thumbsDown. |
|
1196 |
canDrop := false. |
|
341 | 1197 |
! ! |
1198 |
||
1199 |
!DragAndDropManager methodsFor:'private'! |
|
1200 |
||
874 | 1201 |
doDrop:aContext in:aWidget |
1202 |
"old drop mechanism |
|
1203 |
" |
|
1204 |
|point| |
|
628 | 1205 |
|
1206 |
DragOriginatorQuerySignal answer:dragView do:[ |
|
680
6157661790fd
keep dragOffset - provide querySignal
Claus Gittinger <cg@exept.de>
parents:
628
diff
changeset
|
1207 |
DragOffsetQuerySignal answer:dragOffset do:[ |
874 | 1208 |
aContext targetWidget == aWidget ifTrue:[ |
1209 |
point := aContext targetPoint |
|
1210 |
] ifFalse:[ |
|
1211 |
point := nil. |
|
1212 |
"/ |
|
1213 |
"/ FeedBack: set the widget which handles the drop |
|
1214 |
"/ |
|
1215 |
aContext targetWidget:aWidget id:(aWidget id). |
|
1216 |
]. |
|
1217 |
aWidget drop:(aContext dropObjects) at:point |
|
609
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1218 |
] |
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1219 |
]. |
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1220 |
|
346
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
1221 |
! |
1612c23d9c5d
pass all dropInfo to an end-action
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
1222 |
|
874 | 1223 |
doFindDropTargetIn:aView at:aPoint |
1224 |
"get the drop target for a view and source at a point or nil |
|
411 | 1225 |
" |
874 | 1226 |
|target view dobj| |
628 | 1227 |
|
874 | 1228 |
aView isNil ifTrue:[ ^ nil ]. |
1229 |
"/ |
|
1230 |
"/ new mechanism to get a dropTarget |
|
1231 |
"/ |
|
1232 |
aView messageNotUnderstoodSignal handle:[:ex| |
|
1233 |
target := nil. |
|
1234 |
] do:[ |
|
1235 |
target := aView dropTarget |
|
1236 |
]. |
|
1237 |
target notNil ifTrue:[ ^ target ]. |
|
1238 |
"/ |
|
1239 |
"/ old mechanism to get a dropTarget |
|
1240 |
"/ |
|
1241 |
view := aView. |
|
1242 |
dobj := dropContext dropObjects. |
|
628 | 1243 |
|
874 | 1244 |
DragOriginatorQuerySignal answer:dragView do:[ |
1245 |
DragOffsetQuerySignal answer:dragOffset do:[ |
|
1246 |
[ (view canDrop:dobj) ifTrue:[ |
|
1247 |
^ DropTarget receiver:self argument:view dropSelector:#doDrop:in:. |
|
1248 |
]. |
|
1249 |
(view := view superView) notNil |
|
628 | 1250 |
|
874 | 1251 |
] whileTrue. |
1252 |
] |
|
1253 |
]. |
|
1254 |
^ nil |
|
1255 |
! |
|
628 | 1256 |
|
874 | 1257 |
doStart:aHandler for:aView atEnd:aFourArgEndBlock |
1258 |
"setup a handler and a restore block |
|
628 | 1259 |
" |
874 | 1260 |
|cursor delegate| |
628 | 1261 |
|
874 | 1262 |
dropContext sourceWidget:aView. |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1263 |
|
874 | 1264 |
dragOffset isNil ifTrue:[ dragOffset := 0 @ 0 ]. |
1265 |
alienCursor isNil ifTrue:[ alienCursor := disabledCursor ]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1266 |
|
874 | 1267 |
dragView := aView. |
1268 |
dropAction := aFourArgEndBlock. |
|
1269 |
cursor := aView cursor. |
|
1270 |
delegate := aView delegate. |
|
1271 |
handler := aHandler. |
|
609
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1272 |
|
874 | 1273 |
restoreBlock := [ |
1274 |
aHandler postDragging. |
|
1275 |
aView delegate:delegate. |
|
1276 |
aView cursor:cursor now:true. |
|
1277 |
aView device ungrabPointer |
|
1278 |
]. |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1279 |
|
874 | 1280 |
aHandler preDraggingIn:aView. |
1281 |
aView delegate:self. |
|
1282 |
aView device grabPointerInView:aView. |
|
609
1343bda17876
pass logical coordinates to dropAction.
Claus Gittinger <cg@exept.de>
parents:
549
diff
changeset
|
1283 |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1284 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1285 |
|
874 | 1286 |
!DragAndDropManager methodsFor:'translation'! |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1287 |
|
874 | 1288 |
translatePointToScreen:aPoint from:aView |
1289 |
"translate a point to screen |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1290 |
" |
874 | 1291 |
|device trans point offset| |
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1292 |
|
874 | 1293 |
device := aView device. |
1294 |
"/ |
|
1295 |
"/ get device coordinates |
|
1296 |
"/ |
|
1297 |
(trans := aView transformation) notNil ifTrue:[ |
|
1298 |
point := trans applyTo:aPoint |
|
1299 |
] ifFalse:[ |
|
1300 |
point := aPoint |
|
1301 |
]. |
|
1302 |
"/ |
|
1303 |
"/ translate to screen |
|
1304 |
"/ |
|
1305 |
offset := device translatePoint:0@0 from:(aView id) to:(device rootView id). |
|
1306 |
^ offset + point |
|
548
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1307 |
|
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1308 |
! ! |
1a81d6be65b4
added comments & docu, examples.
Claus Gittinger <cg@exept.de>
parents:
515
diff
changeset
|
1309 |
|
341 | 1310 |
!DragAndDropManager class methodsFor:'documentation'! |
1311 |
||
1312 |
version |
|
874 | 1313 |
^ '$Header: /cvs/stx/stx/libview2/DragAndDropManager.st,v 1.19 1998-03-30 12:02:15 ca Exp $' |
341 | 1314 |
! ! |
628 | 1315 |
DragAndDropManager initialize! |