author | Claus Gittinger <cg@exept.de> |
Tue, 09 Jul 2019 20:53:39 +0200 | |
changeset 6083 | 7a2c0a30e75c |
parent 5813 | bbfae6ced887 |
permissions | -rw-r--r-- |
5813 | 1 |
"{ Encoding: utf8 }" |
2 |
||
3756 | 3 |
" |
4 |
COPYRIGHT (c) 2008 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
3371 | 14 |
"{ Package: 'stx:libwidg2' }" |
15 |
||
4835
10986fc8bd78
class: HierarchicalDropTargetController
Stefan Vogel <sv@exept.de>
parents:
3868
diff
changeset
|
16 |
"{ NameSpace: Smalltalk }" |
10986fc8bd78
class: HierarchicalDropTargetController
Stefan Vogel <sv@exept.de>
parents:
3868
diff
changeset
|
17 |
|
3371 | 18 |
Object subclass:#HierarchicalDropTargetController |
19 |
instanceVariableNames:'expandBlock highlightMode receiver dropOverLine dropSelector |
|
3379 | 20 |
canDropSelector canExpandSelector' |
3371 | 21 |
classVariableNames:'' |
22 |
poolDictionaries:'' |
|
23 |
category:'Interface-DragAndDrop' |
|
24 |
! |
|
25 |
||
3756 | 26 |
!HierarchicalDropTargetController class methodsFor:'documentation'! |
27 |
||
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 2008 by eXept Software AG |
|
31 |
All Rights Reserved |
|
32 |
||
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
! ! |
|
3371 | 41 |
|
42 |
!HierarchicalDropTargetController class methodsFor:'instance creation'! |
|
43 |
||
44 |
receiver:aReceiver argument:anArgument dropSelector:aDropSelector canDropSelector:aCanDropSelector |
|
3379 | 45 |
|
46 |
^ self |
|
47 |
receiver:aReceiver |
|
48 |
argument:anArgument |
|
49 |
dropSelector:aDropSelector |
|
50 |
canDropSelector:aCanDropSelector |
|
51 |
canExpandSelector:nil |
|
52 |
! |
|
53 |
||
54 |
receiver:aReceiver argument:anArgument dropSelector:aDropSelector canDropSelector:aCanDropSelector canExpandSelector: aCanExpandSelector |
|
3371 | 55 |
|target| |
56 |
||
57 |
target := self new. |
|
3379 | 58 |
|
59 |
^ target |
|
60 |
receiver:aReceiver |
|
61 |
argument:anArgument |
|
62 |
dropSelector:aDropSelector |
|
63 |
canDropSelector:aCanDropSelector |
|
64 |
canExpandSelector:aCanExpandSelector |
|
3371 | 65 |
! |
66 |
||
67 |
receiver:aReceiver dropSelector:aDropSelector canDropSelector:aCanDropSelector |
|
3379 | 68 |
|
69 |
^ self |
|
70 |
receiver:aReceiver |
|
71 |
argument:nil |
|
72 |
dropSelector:aDropSelector |
|
73 |
canDropSelector:aCanDropSelector |
|
74 |
canExpandSelector:nil |
|
75 |
! |
|
76 |
||
77 |
receiver:aReceiver dropSelector:aDropSelector canDropSelector:aCanDropSelector canExpandSelector:aCanExpandSelector |
|
78 |
||
79 |
^ self |
|
80 |
receiver:aReceiver |
|
81 |
argument:nil |
|
82 |
dropSelector:aDropSelector |
|
83 |
canDropSelector:aCanDropSelector |
|
84 |
canExpandSelector:aCanExpandSelector |
|
3371 | 85 |
! ! |
86 |
||
87 |
!HierarchicalDropTargetController class methodsFor:'constants'! |
|
88 |
||
89 |
delayMilliSecondsBeforeExpand |
|
90 |
^ 1000 |
|
91 |
! ! |
|
92 |
||
93 |
!HierarchicalDropTargetController methodsFor:'drop actions'! |
|
94 |
||
95 |
canDrop:aDropContext |
|
96 |
"return true, if the DropContext can be dropped into the list of items" |
|
97 |
||
98 |
dropOverLine isNil ifTrue:[ ^ false ]. "/ never setup by dropEnter: |
|
3434 | 99 |
canDropSelector isNil ifTrue:[ ^ false ]. |
3371 | 100 |
|
3434 | 101 |
^ receiver |
102 |
perform:canDropSelector |
|
103 |
withOptionalArgument:aDropContext and:dropOverLine |
|
3371 | 104 |
! |
105 |
||
106 |
drop:aDropContext |
|
107 |
"drop the dropContext into the hierachical list of items |
|
108 |
" |
|
109 |
|lnNr| |
|
110 |
||
3379 | 111 |
(self canDrop:aDropContext) ifFalse:[ |
112 |
self dropLeave:aDropContext. |
|
113 |
^ false. |
|
114 |
]. |
|
3371 | 115 |
lnNr := dropOverLine. |
116 |
lnNr isNil ifTrue:[^ false ]. "/ never setup by dropEnter: |
|
117 |
||
118 |
self dropLeave:aDropContext. |
|
119 |
||
3379 | 120 |
dropSelector isNil ifTrue:[ ^ false ]. |
3434 | 121 |
|
122 |
^ receiver |
|
123 |
perform:dropSelector |
|
124 |
withOptionalArgument:aDropContext and:lnNr |
|
3371 | 125 |
! |
126 |
||
127 |
dropEnter:aDropContext |
|
128 |
"a drop operation enters my widget; set the highlightMode in the target widget" |
|
129 |
||
130 |
|widget| |
|
131 |
||
132 |
dropOverLine := 0. |
|
133 |
||
134 |
widget := aDropContext targetWidget. |
|
135 |
highlightMode := widget highlightMode. |
|
136 |
||
137 |
highlightMode notNil ifTrue:[ |
|
138 |
aDropContext saveDraw:[ |
|
139 |
widget highlightMode: #dropMode. |
|
140 |
widget windowGroup processExposeEvents. |
|
141 |
]. |
|
142 |
]. |
|
143 |
! |
|
144 |
||
145 |
dropLeave:aDropContext |
|
3868
8e73b46c547c
comment/format in: #dropLeave:
Claus Gittinger <cg@exept.de>
parents:
3756
diff
changeset
|
146 |
"restore drop indications drawn..." |
8e73b46c547c
comment/format in: #dropLeave:
Claus Gittinger <cg@exept.de>
parents:
3756
diff
changeset
|
147 |
|
3371 | 148 |
self changeDropLineTo:nil in:aDropContext. |
149 |
! |
|
150 |
||
151 |
dropOver:aDropContext |
|
152 |
|target lineNr| |
|
153 |
||
154 |
dropOverLine isNil ifTrue:[^ self ]. "/ never setup by dropEnter: |
|
155 |
||
156 |
target := aDropContext targetWidget. |
|
5813 | 157 |
lineNr := target yVisibleToLineNr:(aDropContext targetPointInDeviceCoordinates y). |
3371 | 158 |
|
159 |
lineNr isNil ifTrue:[ lineNr := 0. ]. |
|
160 |
||
161 |
lineNr > target size ifTrue:[ |
|
162 |
lineNr := 0. |
|
163 |
]. |
|
164 |
self changeDropLineTo:lineNr in:aDropContext. |
|
5813 | 165 |
|
166 |
"Modified: / 15-06-2018 / 02:25:37 / Claus Gittinger" |
|
3371 | 167 |
! ! |
168 |
||
169 |
!HierarchicalDropTargetController methodsFor:'instance creation'! |
|
170 |
||
3379 | 171 |
receiver:aReceiver argument:anArgument dropSelector:aDropSelector canDropSelector:aCanDropSelector canExpandSelector:aCanExpandSelector |
3371 | 172 |
|target| |
173 |
||
174 |
receiver := aReceiver. |
|
175 |
dropSelector := aDropSelector. |
|
176 |
canDropSelector := aCanDropSelector. |
|
3379 | 177 |
canExpandSelector := aCanExpandSelector. |
3371 | 178 |
|
179 |
target := DropTarget |
|
180 |
receiver:self |
|
181 |
argument:anArgument |
|
182 |
dropSelector:#drop: |
|
183 |
canDropSelector:#canDrop:. |
|
184 |
||
185 |
target enterSelector:#dropEnter:. |
|
186 |
target leaveSelector:#dropLeave:. |
|
187 |
target overSelector:#dropOver:. |
|
188 |
||
189 |
^ target |
|
190 |
! ! |
|
191 |
||
192 |
!HierarchicalDropTargetController methodsFor:'private'! |
|
193 |
||
194 |
changeDropLineTo:aLineOrNil in:aDropContext |
|
195 |
|x0 y0 y1 view item bgColor fgColor processEvents| |
|
196 |
||
197 |
aLineOrNil == dropOverLine ifTrue:[ ^ self ]. "/ nothing changed |
|
198 |
||
199 |
view := aDropContext targetWidget. |
|
200 |
||
201 |
expandBlock notNil ifTrue:[ |
|
202 |
Processor removeTimedBlock:expandBlock. |
|
5142 | 203 |
expandBlock := nil. |
3371 | 204 |
]. |
4879 | 205 |
processEvents := aLineOrNil isNil. |
3371 | 206 |
aDropContext contentsWillChange. |
207 |
||
208 |
(aLineOrNil isNil and:[highlightMode notNil]) ifTrue:[ |
|
209 |
"/ resore the selection mode |
|
210 |
view highlightMode: highlightMode. |
|
211 |
highlightMode := nil. |
|
212 |
processEvents := true. |
|
213 |
]. |
|
214 |
(dropOverLine notNil and:[dropOverLine ~~ 0]) ifTrue:[ |
|
215 |
"/ invalidate old line |
|
216 |
view invalidateLineAt:dropOverLine. |
|
217 |
processEvents := true. |
|
218 |
]. |
|
219 |
processEvents ifTrue:[ |
|
220 |
view windowGroup processExposeEvents. |
|
221 |
]. |
|
222 |
||
223 |
dropOverLine := aLineOrNil. |
|
224 |
||
225 |
(dropOverLine isNil or:[dropOverLine == 0]) ifTrue:[ |
|
226 |
^ self |
|
227 |
]. |
|
228 |
item := view at:dropOverLine ifAbsent:nil. |
|
229 |
item isNil ifTrue:[ ^ self ]. |
|
230 |
||
231 |
y0 := view yVisibleOfLine:dropOverLine. |
|
232 |
y1 := view yVisibleOfLine:(dropOverLine + 1). |
|
233 |
x0 := view xVisibleOfTextAtLevel:item level. |
|
234 |
||
235 |
bgColor := view hilightBackgroundColor. |
|
236 |
fgColor := view hilightForegroundColor. |
|
237 |
||
238 |
view paint: bgColor. |
|
239 |
view fillRectangle:(Rectangle left:(x0 - 2) top:y0 width:(item widthOn:view) + 4 height:(y1 - y0)). |
|
240 |
||
241 |
view paint:fgColor on:bgColor. |
|
4835
10986fc8bd78
class: HierarchicalDropTargetController
Stefan Vogel <sv@exept.de>
parents:
3868
diff
changeset
|
242 |
item displayOn:view x:x0 y:y0 h:(y1 - y0) isHighlightedAsSelected:false. |
3371 | 243 |
|
4879 | 244 |
view device isX11Platform ifTrue:[ |
245 |
"work around X11 draw problems" |
|
246 |
Delay waitForMilliseconds:20. |
|
247 |
]. |
|
248 |
||
3379 | 249 |
item isExpanded ifTrue:[ ^ self ]. |
250 |
item canExpand ifFalse:[ ^ self ]. |
|
251 |
||
252 |
canExpandSelector notNil ifTrue:[ |
|
3434 | 253 |
(receiver |
254 |
perform:canExpandSelector |
|
255 |
withOptionalArgument:aDropContext and:dropOverLine) |
|
256 |
ifFalse:[ |
|
3379 | 257 |
^ self |
258 |
]. |
|
3371 | 259 |
]. |
5142 | 260 |
expandBlock := [self expandForDrop:aDropContext at:aLineOrNil]. |
3379 | 261 |
Processor |
5142 | 262 |
addTimedBlock:expandBlock |
3379 | 263 |
afterMilliseconds:(self class delayMilliSecondsBeforeExpand). |
3371 | 264 |
! |
265 |
||
266 |
expandForDrop:aDropContext at:aLnNr |
|
267 |
|item view| |
|
268 |
||
269 |
expandBlock := nil. |
|
270 |
aLnNr == dropOverLine ifFalse:[ ^ self]. |
|
271 |
||
272 |
view := aDropContext targetWidget. |
|
273 |
item := view at:aLnNr ifAbsent:nil. |
|
274 |
item isNil ifTrue:[^ self]. |
|
275 |
||
276 |
aDropContext saveDraw:[ |
|
277 |
item expand. |
|
278 |
view windowGroup processExposeEvents. |
|
4879 | 279 |
view device isX11Platform ifTrue:[ |
280 |
"work around X11 draw problems" |
|
281 |
Delay waitForMilliseconds:20. |
|
282 |
]. |
|
3371 | 283 |
]. |
284 |
! ! |
|
285 |
||
286 |
!HierarchicalDropTargetController class methodsFor:'documentation'! |
|
287 |
||
288 |
version |
|
4835
10986fc8bd78
class: HierarchicalDropTargetController
Stefan Vogel <sv@exept.de>
parents:
3868
diff
changeset
|
289 |
^ '$Header$' |
3756 | 290 |
! |
291 |
||
292 |
version_CVS |
|
4835
10986fc8bd78
class: HierarchicalDropTargetController
Stefan Vogel <sv@exept.de>
parents:
3868
diff
changeset
|
293 |
^ '$Header$' |
3371 | 294 |
! ! |
4835
10986fc8bd78
class: HierarchicalDropTargetController
Stefan Vogel <sv@exept.de>
parents:
3868
diff
changeset
|
295 |