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