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