0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
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 |
"
|
|
12 |
|
|
13 |
View subclass:#Scroller
|
|
14 |
instanceVariableNames:'thumbOrigin thumbHeight thumbColor thumbFrameColor
|
|
15 |
realThumbHeight
|
|
16 |
scrollAction moveDirection
|
|
17 |
thumbFrame thumbLevel
|
|
18 |
scrolling pressOffset
|
|
19 |
synchronousOperation
|
|
20 |
shadowForm lightForm inset noColor
|
|
21 |
thumbShadowColor thumbLightColor
|
|
22 |
thumbSoftEdge
|
|
23 |
thumbHalfShadowColor thumbHalfLightColor'
|
|
24 |
classVariableNames: 'handleShadowForm handleLightForm
|
|
25 |
hand'
|
|
26 |
poolDictionaries:''
|
|
27 |
category:'Views-Interactors'
|
|
28 |
!
|
|
29 |
|
|
30 |
Scroller comment:'
|
|
31 |
|
|
32 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
33 |
All Rights Reserved
|
|
34 |
|
3
|
35 |
$Header: /cvs/stx/stx/libwidg/Scroller.st,v 1.2 1993-10-13 01:03:36 claus Exp $
|
|
36 |
|
|
37 |
written spring/summer 89 by claus
|
|
38 |
'!
|
|
39 |
|
|
40 |
!Scroller class methodsFor:'documentation'!
|
|
41 |
|
|
42 |
documentation
|
|
43 |
"
|
0
|
44 |
this class implements the scroller for scrollbars.
|
|
45 |
it can also be used by itself for scrollbars without step-buttons.
|
|
46 |
when moved, a predefined action is performed.
|
|
47 |
|
|
48 |
Instance variables:
|
|
49 |
|
|
50 |
thumbOrigin <Number> origin of thumb (in percent)
|
|
51 |
thumbHeight <Number> height of thumb (in percent)
|
|
52 |
thumbColor <Color> color of thumb
|
|
53 |
scrollAction <Block> 1 arg block to be evaluated when scrolled
|
|
54 |
(arg is position in percent)
|
|
55 |
moveDirection <Symbol> #x or #y
|
|
56 |
thumbFrame <Rectangle> frame of thumb in pixels
|
|
57 |
thumbLevel <Number> level of thumb if 3d
|
|
58 |
scrolling <Boolean> true during scroll
|
|
59 |
pressOffset <Number> temporary
|
|
60 |
synchronousOperation <Boolean> true if synchronous
|
|
61 |
shadowForm <Form> bitmap of knob (shadow part)
|
|
62 |
lightForm <Form> bitmap of knob (light part)
|
3
|
63 |
"
|
|
64 |
! !
|
0
|
65 |
|
|
66 |
!Scroller class methodsFor:'defaults'!
|
|
67 |
|
|
68 |
handleShadowFormOn:aDisplay
|
|
69 |
"answer the form used for the handles shadow area;
|
|
70 |
cache the one for Display for the next round"
|
|
71 |
|
|
72 |
|f|
|
|
73 |
|
|
74 |
((aDisplay == Display) and:[handleShadowForm notNil]) ifTrue:[
|
|
75 |
^ handleShadowForm
|
|
76 |
].
|
|
77 |
f := Form fromFile:'HandleShadow.xbm' resolution:100 on:aDisplay.
|
|
78 |
f isNil ifTrue:[
|
|
79 |
f := Form width:8 height:8 fromArray:#(2r00111100
|
|
80 |
2r01100000
|
|
81 |
2r11000000
|
|
82 |
2r11000000
|
|
83 |
2r11000000
|
|
84 |
2r11000000
|
|
85 |
2r01000000
|
|
86 |
2r00000000)
|
|
87 |
on:aDisplay
|
|
88 |
].
|
|
89 |
(aDisplay == Display) ifTrue:[
|
|
90 |
handleShadowForm := f
|
|
91 |
].
|
|
92 |
^ f
|
|
93 |
!
|
|
94 |
|
|
95 |
handleLightFormOn:aDisplay
|
|
96 |
"answer the form used for the handles light area;
|
|
97 |
cache the one for Display for the next round"
|
|
98 |
|
|
99 |
|f|
|
|
100 |
|
|
101 |
((aDisplay == Display) and:[handleLightForm notNil]) ifTrue:[
|
|
102 |
^ handleLightForm
|
|
103 |
].
|
|
104 |
f := Form fromFile:'HandleLight.xbm' resolution:100 on:aDisplay.
|
|
105 |
f isNil ifTrue:[
|
|
106 |
f := Form width:8 height:8 fromArray:#(2r00000000
|
|
107 |
2r00000010
|
|
108 |
2r00000011
|
|
109 |
2r00000011
|
|
110 |
2r00000011
|
|
111 |
2r00000011
|
|
112 |
2r00000110
|
|
113 |
2r00111100)
|
|
114 |
on:aDisplay
|
|
115 |
].
|
|
116 |
(aDisplay == Display) ifTrue:[
|
|
117 |
handleLightForm := f
|
|
118 |
].
|
|
119 |
^ f
|
|
120 |
! !
|
|
121 |
|
|
122 |
!Scroller methodsFor:'initialization'!
|
|
123 |
|
|
124 |
initialize
|
|
125 |
"initialize - setup instvars from defaults"
|
|
126 |
|
|
127 |
super initialize.
|
|
128 |
moveDirection := #y.
|
|
129 |
|
|
130 |
scrolling := false.
|
|
131 |
synchronousOperation := true.
|
|
132 |
|
|
133 |
noColor := Color noColor.
|
|
134 |
thumbOrigin := 0.
|
|
135 |
thumbHeight := 100.
|
|
136 |
|
|
137 |
inset := 1.
|
|
138 |
|
|
139 |
self initStyle.
|
|
140 |
self computeThumbFrame
|
|
141 |
!
|
|
142 |
|
|
143 |
initStyle
|
|
144 |
"initialize style dep. stuff"
|
|
145 |
|
|
146 |
super initStyle.
|
|
147 |
|
|
148 |
viewBackground := Color grey.
|
|
149 |
thumbLevel := 0.
|
|
150 |
|
|
151 |
self is3D ifTrue:[
|
|
152 |
thumbSoftEdge := false.
|
|
153 |
inset := 0.
|
|
154 |
|
|
155 |
style == #next ifTrue:[
|
|
156 |
self level:0.
|
|
157 |
self borderWidth:1.
|
|
158 |
inset := 1.
|
|
159 |
thumbSoftEdge := true.
|
|
160 |
thumbLevel := 2.
|
|
161 |
thumbColor := Color lightGrey
|
|
162 |
] ifFalse:[
|
3
|
163 |
style == #motif ifTrue:[
|
|
164 |
self level:0.
|
|
165 |
inset := 1.
|
|
166 |
thumbLevel := 2.
|
|
167 |
viewBackground := Color lightGrey.
|
|
168 |
thumbColor := viewBackground.
|
0
|
169 |
] ifFalse:[
|
3
|
170 |
style == #iris ifTrue:[
|
|
171 |
self level:-1.
|
|
172 |
thumbLevel := 3.
|
0
|
173 |
thumbSoftEdge := true.
|
3
|
174 |
thumbColor := viewBackground
|
0
|
175 |
] ifFalse:[
|
3
|
176 |
style == #mswindows ifTrue:[
|
|
177 |
self level:0.
|
|
178 |
self borderWidth:1.
|
|
179 |
thumbLevel := 2.
|
|
180 |
thumbColor := Color lightGrey.
|
|
181 |
thumbSoftEdge := true.
|
|
182 |
viewBackground := Color grey:80.
|
|
183 |
] ifFalse:[
|
|
184 |
self level:-1.
|
|
185 |
thumbLevel := 2.
|
|
186 |
thumbColor := Color lightGrey
|
|
187 |
]
|
0
|
188 |
]
|
|
189 |
]
|
|
190 |
]
|
|
191 |
] ifFalse:[
|
|
192 |
thumbColor := White.
|
|
193 |
inset := 1
|
|
194 |
].
|
|
195 |
|
|
196 |
thumbShadowColor := shadowColor.
|
|
197 |
thumbLightColor := lightColor.
|
|
198 |
thumbSoftEdge ifTrue:[
|
|
199 |
device hasGreyscales ifTrue:[
|
|
200 |
thumbHalfShadowColor := halfShadowColor.
|
|
201 |
thumbHalfLightColor := halfLightColor
|
|
202 |
] ifFalse:[
|
|
203 |
thumbHalfShadowColor := Color darkGrey "halfShadowColor".
|
|
204 |
thumbHalfLightColor := White
|
|
205 |
]
|
|
206 |
].
|
|
207 |
device hasGreyscales ifFalse:[
|
|
208 |
thumbShadowColor := Black.
|
|
209 |
thumbLightColor := White.
|
|
210 |
viewBackground := Color veryLightGrey "White"
|
|
211 |
].
|
|
212 |
|
|
213 |
thumbFrameColor := Black.
|
|
214 |
|
|
215 |
style == #next ifTrue:[
|
|
216 |
shadowForm := self class handleShadowFormOn:device.
|
|
217 |
lightForm := self class handleLightFormOn:device
|
|
218 |
].
|
|
219 |
|
|
220 |
drawableId notNil ifTrue:[
|
|
221 |
self computeThumbFrame
|
|
222 |
]
|
|
223 |
!
|
|
224 |
|
|
225 |
initCursor
|
|
226 |
"set the cursor - a hand"
|
|
227 |
|
|
228 |
cursor := Cursor hand
|
|
229 |
!
|
|
230 |
|
|
231 |
initEvents
|
|
232 |
self enableButtonEvents.
|
|
233 |
self enableButtonMotionEvents
|
|
234 |
! !
|
|
235 |
|
|
236 |
!Scroller methodsFor:'accessing'!
|
|
237 |
|
|
238 |
is3D
|
|
239 |
style == #mswindows ifTrue:[^ true].
|
|
240 |
^ super is3D
|
|
241 |
!
|
|
242 |
|
|
243 |
asynchronousOperation
|
|
244 |
"set scroll-mode to be asynchronous - scroll action is performed after
|
|
245 |
scrolling, when mouse-button is finally released"
|
|
246 |
|
|
247 |
synchronousOperation := false
|
|
248 |
!
|
|
249 |
|
|
250 |
synchronousOperation
|
|
251 |
"set scroll-mode to be synchronous - scroll action is performed for
|
|
252 |
every movement of thumb"
|
|
253 |
|
|
254 |
synchronousOperation := true
|
|
255 |
!
|
|
256 |
|
|
257 |
scrollAction:aBlock
|
|
258 |
"set the scroll action, aBlock which is evaluated when scrolled"
|
|
259 |
|
|
260 |
scrollAction := aBlock
|
|
261 |
!
|
|
262 |
|
|
263 |
scrollAction
|
|
264 |
"answer the scroll action block"
|
|
265 |
|
|
266 |
^ scrollAction
|
|
267 |
!
|
|
268 |
|
|
269 |
thumbOrigin
|
|
270 |
"answer the thumbs origin (in percent)"
|
|
271 |
|
|
272 |
^ thumbOrigin
|
|
273 |
!
|
|
274 |
|
|
275 |
thumbOrigin:newOrigin
|
|
276 |
"set the thumbs origin (in percent)"
|
|
277 |
|
|
278 |
|realNewOrigin oldFrame oldTop oldBot thumbTop thumbBot
|
|
279 |
tH "{ Class: SmallInteger }"
|
|
280 |
tW delta left|
|
|
281 |
|
|
282 |
((newOrigin + thumbHeight) > 100) ifTrue:[
|
|
283 |
realNewOrigin := 100 - thumbHeight
|
|
284 |
] ifFalse: [
|
|
285 |
realNewOrigin := newOrigin
|
|
286 |
].
|
|
287 |
(realNewOrigin > 100) ifTrue:[
|
|
288 |
realNewOrigin := 100
|
|
289 |
] ifFalse: [
|
|
290 |
(realNewOrigin < 0) ifTrue:[
|
|
291 |
realNewOrigin := 0
|
|
292 |
]
|
|
293 |
].
|
|
294 |
(realNewOrigin = thumbOrigin) ifFalse:[
|
|
295 |
oldFrame := thumbFrame.
|
|
296 |
thumbOrigin := realNewOrigin.
|
|
297 |
self computeThumbFrame.
|
|
298 |
(thumbHeight = 100) ifTrue:[^ self].
|
|
299 |
|
|
300 |
shown ifTrue:[
|
|
301 |
(thumbFrame ~~ oldFrame) ifTrue:[
|
|
302 |
tH := thumbFrame height.
|
|
303 |
tW := thumbFrame width.
|
|
304 |
oldTop := oldFrame top.
|
|
305 |
oldBot := oldTop + tH.
|
|
306 |
|
|
307 |
thumbTop := thumbFrame top.
|
|
308 |
thumbBot := thumbTop + tH.
|
|
309 |
|
|
310 |
left := thumbFrame left.
|
|
311 |
|
|
312 |
(oldBot >= height) ifTrue:[
|
|
313 |
"cannot copy - thumb was below end"
|
|
314 |
self drawThumbBackgroundInX:left y:oldTop
|
|
315 |
width:tW height:(height - oldTop).
|
|
316 |
self drawThumb.
|
|
317 |
^ self
|
|
318 |
].
|
|
319 |
|
|
320 |
self copyFrom:self x:left y:oldTop
|
|
321 |
toX:left y:thumbTop
|
|
322 |
width:tW height:tH.
|
|
323 |
|
|
324 |
oldTop > thumbTop ifTrue:[
|
|
325 |
delta := oldTop - thumbTop.
|
|
326 |
oldTop > thumbBot ifTrue:[
|
|
327 |
self drawThumbBackgroundInX:left y:oldTop
|
|
328 |
width:tW height:(tH + 1)
|
|
329 |
] ifFalse:[
|
|
330 |
self drawThumbBackgroundInX:left y:thumbBot
|
|
331 |
width:tW height:delta
|
|
332 |
]
|
|
333 |
] ifFalse:[
|
|
334 |
delta := thumbTop - oldTop.
|
|
335 |
oldBot < thumbTop ifTrue:[
|
|
336 |
self drawThumbBackgroundInX:left y:oldTop
|
|
337 |
width:tW height:(tH + 1)
|
|
338 |
] ifFalse:[
|
|
339 |
self drawThumbBackgroundInX:left y:oldTop
|
|
340 |
width:tW height:delta
|
|
341 |
]
|
|
342 |
].
|
|
343 |
"self is3D ifTrue:[ "
|
|
344 |
self waitForExpose
|
|
345 |
"] "
|
|
346 |
]
|
|
347 |
]
|
|
348 |
]
|
|
349 |
!
|
|
350 |
|
|
351 |
thumbHeight
|
|
352 |
"answer the thumbs height (in percent)"
|
|
353 |
|
|
354 |
^ thumbHeight
|
|
355 |
!
|
|
356 |
|
|
357 |
thumbHeight:newHeight
|
|
358 |
"set the thumbs height (in percent)"
|
|
359 |
|
|
360 |
|realNewHeight oldFrame|
|
|
361 |
|
|
362 |
(newHeight > 100) ifTrue:[
|
|
363 |
realNewHeight := 100
|
|
364 |
] ifFalse:[
|
|
365 |
realNewHeight := newHeight
|
|
366 |
].
|
|
367 |
(realNewHeight = thumbHeight) ifFalse:[
|
|
368 |
oldFrame := thumbFrame.
|
|
369 |
thumbHeight := realNewHeight.
|
|
370 |
self computeThumbFrame.
|
|
371 |
shown ifTrue:[
|
|
372 |
(oldFrame ~~ thumbFrame) ifTrue:[
|
|
373 |
self drawThumbBackgroundInX:(oldFrame left)
|
|
374 |
y:(oldFrame top)
|
|
375 |
width:(oldFrame width)
|
|
376 |
height:(oldFrame height).
|
|
377 |
self drawThumb
|
|
378 |
]
|
|
379 |
]
|
|
380 |
]
|
|
381 |
!
|
|
382 |
|
|
383 |
thumbOrigin:newOrigin thumbHeight:newHeight
|
|
384 |
"set both thumbs height and origin (in percent)"
|
|
385 |
|
|
386 |
|realNewOrigin realNewHeight old new same|
|
|
387 |
|
|
388 |
(newHeight > 100) ifTrue:[
|
|
389 |
realNewHeight := 100
|
|
390 |
] ifFalse:[
|
|
391 |
realNewHeight := newHeight
|
|
392 |
].
|
|
393 |
((newOrigin + realNewHeight) > 100) ifTrue:[
|
|
394 |
realNewOrigin := 100 - realNewHeight
|
|
395 |
] ifFalse: [
|
|
396 |
realNewOrigin := newOrigin
|
|
397 |
].
|
|
398 |
(realNewOrigin < 0) ifTrue: [
|
|
399 |
realNewOrigin := 0
|
|
400 |
].
|
|
401 |
|
|
402 |
same := (realNewHeight = thumbHeight).
|
|
403 |
same ifTrue:[
|
|
404 |
same := (realNewOrigin = thumbOrigin)
|
|
405 |
].
|
|
406 |
|
|
407 |
same ifFalse:[
|
|
408 |
old := self absFromPercent:thumbOrigin.
|
|
409 |
new := self absFromPercent:realNewOrigin.
|
|
410 |
(old == new) ifTrue:[
|
|
411 |
old := self absFromPercent:thumbHeight.
|
|
412 |
new := self absFromPercent:realNewHeight.
|
|
413 |
(old == new) ifTrue:[^ self]
|
|
414 |
].
|
|
415 |
|
|
416 |
shown ifTrue:[
|
|
417 |
self drawThumbBackgroundInX:(thumbFrame left)
|
|
418 |
y:(thumbFrame top)
|
|
419 |
width:(thumbFrame width)
|
|
420 |
height:(thumbFrame height).
|
|
421 |
].
|
|
422 |
thumbOrigin := realNewOrigin.
|
|
423 |
thumbHeight := realNewHeight.
|
|
424 |
self computeThumbFrame.
|
|
425 |
shown ifTrue:[
|
|
426 |
self drawThumb
|
|
427 |
]
|
|
428 |
]
|
|
429 |
!
|
|
430 |
|
|
431 |
setThumbFor:aView
|
|
432 |
"get contents and size info from aView and adjust thumb"
|
|
433 |
|
|
434 |
|percentSize percentOrigin totalHeight|
|
|
435 |
|
|
436 |
aView isNil ifTrue:[
|
|
437 |
totalHeight := 0
|
|
438 |
] ifFalse:[
|
|
439 |
totalHeight := aView heightOfContents
|
|
440 |
].
|
|
441 |
(totalHeight = 0) ifTrue:[
|
|
442 |
percentSize := 100.
|
|
443 |
percentOrigin := 100
|
|
444 |
] ifFalse:[
|
|
445 |
percentSize := (aView innerHeight) * 100.0 / totalHeight.
|
|
446 |
percentOrigin := (aView yOriginOfContents) * 100.0 / totalHeight
|
|
447 |
].
|
|
448 |
(percentSize = thumbHeight) ifTrue:[
|
|
449 |
self thumbOrigin:percentOrigin
|
|
450 |
] ifFalse:[
|
|
451 |
(percentOrigin = thumbOrigin) ifTrue:[
|
|
452 |
self thumbHeight:percentSize
|
|
453 |
] ifFalse:[
|
|
454 |
self thumbOrigin:percentOrigin thumbHeight:percentSize
|
|
455 |
]
|
|
456 |
]
|
|
457 |
!
|
|
458 |
|
|
459 |
setThumbHeightFor:aView
|
|
460 |
"get contents and size info from aView and adjust thumb height"
|
|
461 |
|
|
462 |
|percent totalHeight|
|
|
463 |
|
|
464 |
totalHeight := aView heightOfContents.
|
|
465 |
(totalHeight = 0) ifTrue:[
|
|
466 |
percent := 100
|
|
467 |
] ifFalse:[
|
|
468 |
percent := (aView innerHeight) * 100.0 / totalHeight
|
|
469 |
].
|
|
470 |
self thumbHeight:percent
|
|
471 |
!
|
|
472 |
|
|
473 |
setThumbOriginFor:aView
|
|
474 |
"get contents and size info from aView and adjust thumb origin"
|
|
475 |
|
|
476 |
|percent totalHeight|
|
|
477 |
|
|
478 |
totalHeight := aView heightOfContents.
|
|
479 |
(totalHeight = 0) ifTrue:[
|
|
480 |
percent := 100
|
|
481 |
] ifFalse:[
|
|
482 |
percent := (aView yOriginOfContents) * 100.0 / totalHeight
|
|
483 |
].
|
|
484 |
self thumbOrigin:percent
|
|
485 |
!
|
|
486 |
|
|
487 |
thumbColor:aColor
|
|
488 |
"change the color of the thumb"
|
|
489 |
|
|
490 |
thumbColor := aColor on:device.
|
|
491 |
self is3D ifTrue:[
|
|
492 |
thumbShadowColor := aColor darkened on:device.
|
|
493 |
thumbLightColor := aColor lightened on:device
|
|
494 |
].
|
|
495 |
shown ifTrue:[
|
|
496 |
self redraw
|
|
497 |
]
|
|
498 |
!
|
|
499 |
|
|
500 |
thumbFrame
|
|
501 |
"return the area used by the thumbFrame (in device coordinates).
|
|
502 |
Allows access toi the thumbs physical screen position, for
|
|
503 |
example to position a label below (see Slider-Examples)"
|
|
504 |
|
|
505 |
^ thumbFrame
|
|
506 |
! !
|
|
507 |
|
|
508 |
!Scroller methodsFor:'private'!
|
|
509 |
|
|
510 |
absFromPercent:percent
|
|
511 |
"given a percentage, compute number of pixels"
|
|
512 |
|
|
513 |
|fullSize|
|
|
514 |
|
|
515 |
(moveDirection == #y) ifTrue:[
|
|
516 |
fullSize := height
|
|
517 |
] ifFalse:[
|
|
518 |
fullSize := width
|
|
519 |
].
|
|
520 |
^ ((percent * (fullSize - (margin * 2))) / 100) rounded
|
|
521 |
!
|
|
522 |
|
|
523 |
percentFromAbs:absValue
|
|
524 |
"given a number of pixels, compute percentage"
|
|
525 |
|
|
526 |
|fullSize val|
|
|
527 |
|
|
528 |
(moveDirection == #y) ifTrue:[
|
|
529 |
fullSize := height
|
|
530 |
] ifFalse:[
|
|
531 |
fullSize := width
|
|
532 |
].
|
|
533 |
|
|
534 |
val := absValue / (fullSize - (margin * 2)) * 100.
|
|
535 |
val < 0 ifTrue:[^ 0].
|
|
536 |
val > 100 ifTrue:[^ 100].
|
|
537 |
^ val
|
|
538 |
!
|
|
539 |
|
|
540 |
computeThumbFrame
|
|
541 |
"compute the thumbs frame (a rectangle) whenever thumb is moved, changed
|
|
542 |
height or the scrollers size has changed"
|
|
543 |
|
|
544 |
|np1 np2 ns1 ns2 nh nw ny nx t diff sz1 sz2|
|
|
545 |
|
|
546 |
np1 := (self absFromPercent:thumbOrigin) + margin.
|
|
547 |
ns1 := self absFromPercent:thumbHeight.
|
|
548 |
diff := 0.
|
|
549 |
(moveDirection == #y) ifTrue:[
|
|
550 |
sz1 := height.
|
|
551 |
sz2 := width
|
|
552 |
] ifFalse:[
|
|
553 |
sz1 := width.
|
|
554 |
sz2 := height
|
|
555 |
].
|
|
556 |
self is3D ifTrue:[
|
|
557 |
np2 := margin + inset.
|
|
558 |
ns2 := sz2 - (margin * 2) - (inset * 2).
|
|
559 |
"
|
|
560 |
do not make thumb too small (for handle)
|
|
561 |
"
|
|
562 |
(ns1 < (10 + (2 * thumbLevel))) ifTrue:[
|
|
563 |
t := ns1.
|
|
564 |
ns1 := 10 + (2 * thumbLevel).
|
|
565 |
diff := ns1 - t
|
|
566 |
]
|
|
567 |
] ifFalse:[
|
|
568 |
np2 := inset.
|
|
569 |
ns2 := sz2 - (inset * 2).
|
|
570 |
|
|
571 |
"
|
|
572 |
do not make thumb too small (uncatchable)
|
|
573 |
"
|
|
574 |
(ns1 < 4) ifTrue:[
|
|
575 |
t := ns1.
|
|
576 |
ns1 := 4.
|
|
577 |
diff := ns1 - t
|
|
578 |
]
|
|
579 |
].
|
|
580 |
"
|
|
581 |
oops - if height has been increased, we have to adjust
|
|
582 |
the origin
|
|
583 |
"
|
|
584 |
(diff == 0) ifFalse:[
|
|
585 |
np1 := ((thumbOrigin * (sz1 - diff - (margin * 2))) / 100) rounded
|
|
586 |
+ margin
|
|
587 |
].
|
|
588 |
|
|
589 |
(moveDirection == #y) ifTrue:[
|
|
590 |
ny := np1.
|
|
591 |
nx := np2.
|
|
592 |
nh := ns1.
|
|
593 |
nw := ns2.
|
|
594 |
ny + nh + margin > height ifTrue:[
|
|
595 |
ny := height - margin - nh
|
|
596 |
]
|
|
597 |
] ifFalse:[
|
|
598 |
nx := np1.
|
|
599 |
ny := np2.
|
|
600 |
nw := ns1.
|
|
601 |
nh := ns2.
|
|
602 |
nx + nw + margin > width ifTrue:[
|
|
603 |
nx := width - margin - nw
|
|
604 |
]
|
|
605 |
].
|
|
606 |
|
|
607 |
"
|
|
608 |
do not create new Rectangle if its the same anyway
|
|
609 |
"
|
|
610 |
thumbFrame notNil ifTrue:[
|
|
611 |
(ny == thumbFrame top) ifTrue:[
|
|
612 |
(nx == thumbFrame left) ifTrue:[
|
|
613 |
(nh == thumbFrame height) ifTrue:[
|
|
614 |
(nw == thumbFrame width) ifTrue:[ ^ self]
|
|
615 |
]
|
|
616 |
]
|
|
617 |
]
|
|
618 |
].
|
|
619 |
thumbFrame := Rectangle left:nx top:ny width:nw height:nh
|
|
620 |
! !
|
|
621 |
|
|
622 |
!Scroller methodsFor:'drawing'!
|
|
623 |
|
|
624 |
drawHandleFormAtX:x y:y
|
|
625 |
|oldFg oldBg oldFun|
|
|
626 |
|
|
627 |
oldFg := foreground.
|
|
628 |
oldBg := background.
|
|
629 |
oldFun := function.
|
|
630 |
|
3
|
631 |
thumbShadowColor := thumbShadowColor on:device.
|
|
632 |
thumbLightColor := thumbLightColor on:device.
|
|
633 |
thumbColor := thumbColor on:device.
|
|
634 |
|
0
|
635 |
"kludge for now"
|
|
636 |
((thumbShadowColor colorId notNil)
|
|
637 |
and:[(thumbLightColor colorId notNil)
|
|
638 |
and:[thumbColor colorId notNil]])
|
|
639 |
ifTrue:[
|
|
640 |
self foreground:thumbColor background:noColor function:#xor.
|
|
641 |
self drawOpaqueForm:shadowForm x:x y:y.
|
|
642 |
self foreground:thumbShadowColor function:#or.
|
|
643 |
self drawOpaqueForm:shadowForm x:x y:y.
|
|
644 |
self foreground:thumbColor function:#xor.
|
|
645 |
self drawOpaqueForm:lightForm x:x y:y.
|
|
646 |
self foreground:thumbLightColor function:#or.
|
|
647 |
self drawOpaqueForm:lightForm x:x y:y.
|
|
648 |
self foreground:oldFg background:oldBg function:#copy
|
|
649 |
] ifFalse:[
|
|
650 |
false ifTrue:[
|
|
651 |
"turn off shadow bits"
|
|
652 |
self foreground:noColor background:(Color allColor) function:#and.
|
|
653 |
|
|
654 |
self drawOpaqueForm:shadowForm x:x y:y.
|
|
655 |
"turn off light bits"
|
|
656 |
self drawOpaqueForm:lightForm x:x y:y.
|
|
657 |
|
|
658 |
"draw shadow bits"
|
|
659 |
self paint:shadowColor.
|
|
660 |
self function:#or.
|
|
661 |
self drawOpaqueForm:shadowForm x:x y:y.
|
|
662 |
|
|
663 |
"draw light bits"
|
|
664 |
self paint:lightColor.
|
|
665 |
self drawOpaqueForm:lightForm x:x y:y.
|
|
666 |
self foreground:oldFg background:oldBg function:oldFun
|
|
667 |
]
|
|
668 |
]
|
|
669 |
!
|
|
670 |
|
|
671 |
drawThumbBackgroundInX:x y:y width:w height:h
|
|
672 |
"draw part of the thumbs background; defined as a separate
|
|
673 |
method, to allow drawing of arbitrary patterns under thumb."
|
|
674 |
|
|
675 |
self clearRectangleX:x y:y width:w height:h.
|
|
676 |
!
|
|
677 |
|
|
678 |
drawThumb
|
|
679 |
"draw the thumb"
|
|
680 |
|
|
681 |
|handleX handleY l t
|
|
682 |
w "{ Class: SmallInteger }"
|
|
683 |
h "{ Class: SmallInteger }"
|
|
684 |
x "{ Class: SmallInteger }"
|
|
685 |
y "{ Class: SmallInteger }"
|
|
686 |
mm xL xR yT yB|
|
|
687 |
|
|
688 |
((thumbHeight >= 100) or:[thumbFrame height >= height]) ifTrue:[^ self].
|
|
689 |
|
|
690 |
l := thumbFrame left.
|
|
691 |
t := thumbFrame top.
|
|
692 |
w := thumbFrame width.
|
|
693 |
h := thumbFrame height.
|
|
694 |
self paint:thumbColor.
|
|
695 |
self fillRectangleX:l y:t width:w height:h.
|
|
696 |
|
|
697 |
self is3D ifFalse:[
|
|
698 |
self paint:thumbFrameColor.
|
|
699 |
self drawRectangle:thumbFrame.
|
|
700 |
^ self
|
|
701 |
].
|
|
702 |
|
|
703 |
thumbSoftEdge ifTrue:[
|
|
704 |
softEdge := true
|
|
705 |
].
|
|
706 |
self drawEdgesForX:l y:t width:w height:h level:thumbLevel
|
|
707 |
shadow:thumbShadowColor light:thumbLightColor
|
|
708 |
halfShadow:thumbHalfShadowColor halfLight:thumbHalfLightColor.
|
|
709 |
softEdge := false.
|
|
710 |
|
|
711 |
style == #iris ifFalse:[
|
|
712 |
shadowForm notNil ifTrue:[
|
|
713 |
handleX := l + ((w - 8) // 2).
|
|
714 |
handleY := t + ((h - 8) // 2).
|
|
715 |
self drawHandleFormAtX:handleX y:handleY
|
|
716 |
].
|
|
717 |
^ self
|
|
718 |
].
|
|
719 |
|
|
720 |
(moveDirection == #y) ifTrue:[
|
|
721 |
self paint:shadowColor.
|
|
722 |
y := t + (h // 2) - 1.
|
|
723 |
xL := l + thumbLevel - 1.
|
|
724 |
xR := l + w - thumbLevel + 1.
|
|
725 |
self displayLineFromX:xL y:y toX:xR y:y.
|
|
726 |
y := y + 1.
|
|
727 |
self paint:lightColor.
|
|
728 |
self displayLineFromX:xL y:y toX:xR y:y.
|
|
729 |
|
|
730 |
mm := device verticalPixelPerMillimeter rounded.
|
|
731 |
h > (mm * 6) ifTrue:[
|
|
732 |
y := y - 1 - mm.
|
|
733 |
self paint:shadowColor.
|
|
734 |
self displayLineFromX:xL y:y toX:xR y:y.
|
|
735 |
y := y + 1.
|
|
736 |
self paint:lightColor.
|
|
737 |
self displayLineFromX:xL y:y toX:xR y:y.
|
|
738 |
|
|
739 |
y := y - 1 + mm + mm.
|
|
740 |
self paint:shadowColor.
|
|
741 |
self displayLineFromX:xL y:y toX:xR y:y.
|
|
742 |
y := y + 1.
|
|
743 |
self paint:lightColor.
|
|
744 |
self displayLineFromX:xL y:y toX:xR y:y
|
|
745 |
|
|
746 |
]
|
|
747 |
] ifFalse:[
|
|
748 |
x := l + (w // 2) - 1.
|
|
749 |
yT := t + thumbLevel - 1.
|
|
750 |
yB := t + h - thumbLevel + 1.
|
|
751 |
self paint:shadowColor.
|
|
752 |
self displayLineFromX:x y:yT toX:x y:yB.
|
|
753 |
self paint:lightColor.
|
|
754 |
x := x + 1.
|
|
755 |
self displayLineFromX:x y:yT toX:x y:yB.
|
|
756 |
|
|
757 |
mm := device horizontalPixelPerMillimeter rounded.
|
|
758 |
w > (mm * 6) ifTrue:[
|
|
759 |
x := x - 1 - mm.
|
|
760 |
self paint:shadowColor.
|
|
761 |
self displayLineFromX:x y:yT toX:x y:yB.
|
|
762 |
x := x + 1.
|
|
763 |
self paint:lightColor.
|
|
764 |
self displayLineFromX:x y:yT toX:x y:yB.
|
|
765 |
|
|
766 |
x := x - 1 + mm + mm.
|
|
767 |
self paint:shadowColor.
|
|
768 |
self displayLineFromX:x y:yT toX:x y:yB.
|
|
769 |
x := x + 1.
|
|
770 |
self paint:lightColor.
|
|
771 |
self displayLineFromX:x y:yT toX:x y:yB
|
|
772 |
]
|
|
773 |
]
|
|
774 |
! !
|
|
775 |
|
|
776 |
!Scroller methodsFor:'events'!
|
|
777 |
|
|
778 |
redrawX:x y:y width:w height:h
|
|
779 |
(y > thumbFrame bottom) ifTrue:[
|
|
780 |
self drawThumbBackgroundInX:x y:y width:w height:h.
|
|
781 |
^ self
|
|
782 |
].
|
|
783 |
((y + h) < thumbFrame top) ifTrue:[
|
|
784 |
self drawThumbBackgroundInX:x y:y width:w height:h.
|
|
785 |
^ self
|
|
786 |
].
|
|
787 |
self drawThumbBackgroundInX:0 y:0 width:width height:height.
|
|
788 |
self drawThumb
|
|
789 |
!
|
|
790 |
|
|
791 |
redraw
|
|
792 |
"redraw"
|
|
793 |
|
|
794 |
shown ifTrue:[
|
|
795 |
self drawThumbBackgroundInX:0 y:0 width:width height:height.
|
|
796 |
self drawThumb
|
|
797 |
]
|
|
798 |
!
|
|
799 |
|
|
800 |
sizeChanged:how
|
|
801 |
"size of scroller changed - recompute thumbs frame and redraw it"
|
|
802 |
|
|
803 |
self computeThumbFrame.
|
|
804 |
self redraw
|
|
805 |
!
|
|
806 |
|
|
807 |
buttonPress:button x:x y:y
|
|
808 |
"button was pressed - if above thumb, page up; if below thumb, page down;
|
|
809 |
otherwise start scrolling"
|
|
810 |
|
|
811 |
|curr limit1 limit2|
|
|
812 |
|
|
813 |
(moveDirection == #y) ifTrue:[
|
|
814 |
curr := y.
|
|
815 |
limit1 := thumbFrame top.
|
|
816 |
limit2 := thumbFrame bottom
|
|
817 |
] ifFalse:[
|
|
818 |
curr := x.
|
|
819 |
limit1 := thumbFrame left.
|
|
820 |
limit2 := thumbFrame right
|
|
821 |
].
|
|
822 |
|
|
823 |
(curr < limit1) ifTrue:[
|
|
824 |
"page up/left"
|
|
825 |
self thumbOrigin:(thumbOrigin - thumbHeight).
|
|
826 |
scrollAction notNil ifTrue:[
|
|
827 |
scrollAction value:thumbOrigin
|
|
828 |
]
|
|
829 |
] ifFalse:[
|
|
830 |
(curr > limit2) ifTrue:[
|
|
831 |
"page down/right"
|
|
832 |
self thumbOrigin:(thumbOrigin + thumbHeight).
|
|
833 |
scrollAction notNil ifTrue:[
|
|
834 |
scrollAction value:thumbOrigin
|
|
835 |
]
|
|
836 |
] ifFalse:[
|
|
837 |
pressOffset := curr - limit1.
|
|
838 |
scrolling := true
|
|
839 |
]
|
|
840 |
]
|
|
841 |
!
|
|
842 |
|
|
843 |
buttonMultiPress:button x:x y:y
|
|
844 |
^ self buttonPress:button x:x y:y
|
|
845 |
!
|
|
846 |
|
|
847 |
buttonShiftPress:button x:x y:y
|
|
848 |
"mouse-click with shift - jump to position"
|
|
849 |
|
|
850 |
|pos newThumbOrigin curr limit org|
|
|
851 |
|
|
852 |
(moveDirection == #y) ifTrue:[
|
|
853 |
curr := y.
|
|
854 |
limit := height.
|
|
855 |
org := thumbFrame top
|
|
856 |
] ifFalse:[
|
|
857 |
curr := x.
|
|
858 |
limit := width.
|
|
859 |
org := thumbFrame left
|
|
860 |
].
|
|
861 |
|
|
862 |
(curr < 0) ifTrue:[ "check against limits"
|
|
863 |
pos := 0
|
|
864 |
] ifFalse:[
|
|
865 |
(curr > limit) ifTrue:[
|
|
866 |
pos := limit
|
|
867 |
] ifFalse:[
|
|
868 |
pos := curr
|
|
869 |
]
|
|
870 |
].
|
|
871 |
|
|
872 |
newThumbOrigin := self percentFromAbs:pos.
|
|
873 |
self thumbOrigin:newThumbOrigin.
|
|
874 |
scrollAction notNil ifTrue:[
|
|
875 |
scrollAction value:thumbOrigin
|
|
876 |
].
|
|
877 |
pressOffset := curr - org.
|
|
878 |
scrolling := true
|
|
879 |
!
|
|
880 |
|
|
881 |
buttonMotion:button x:x y:y
|
|
882 |
"mouse-button was moved while pressed;
|
|
883 |
redraw thumb at its new position and, if scroll-mode is asynchronous,
|
|
884 |
the scroll action is performed"
|
|
885 |
|
|
886 |
|pos newThumbOrigin curr limit|
|
|
887 |
|
|
888 |
scrolling ifFalse: [ ^ self ]. "should not happen"
|
|
889 |
|
|
890 |
(moveDirection == #y) ifTrue:[
|
|
891 |
curr := y.
|
|
892 |
limit := height
|
|
893 |
] ifFalse:[
|
|
894 |
curr := x.
|
|
895 |
limit := width
|
|
896 |
].
|
|
897 |
|
|
898 |
(curr < 0) ifTrue:[ "check against limits"
|
|
899 |
pos := 0
|
|
900 |
] ifFalse:[
|
|
901 |
(curr > limit) ifTrue:[
|
|
902 |
pos := limit
|
|
903 |
] ifFalse:[
|
|
904 |
pos := curr
|
|
905 |
]
|
|
906 |
].
|
|
907 |
|
|
908 |
newThumbOrigin := self percentFromAbs:(pos - pressOffset).
|
|
909 |
|
|
910 |
self thumbOrigin:newThumbOrigin.
|
|
911 |
synchronousOperation ifTrue: [
|
|
912 |
scrollAction notNil ifTrue:[
|
|
913 |
scrollAction value:thumbOrigin
|
|
914 |
]
|
|
915 |
]
|
|
916 |
!
|
|
917 |
|
|
918 |
buttonRelease:button x:x y:y
|
|
919 |
"mouse-button was released - if scroll-mode is asynchronous, the scroll
|
|
920 |
action is now performed"
|
|
921 |
|
|
922 |
scrolling ifTrue:[
|
|
923 |
scrolling := false.
|
|
924 |
synchronousOperation ifFalse: [
|
|
925 |
scrollAction notNil ifTrue:[
|
|
926 |
scrollAction value:thumbOrigin
|
|
927 |
]
|
|
928 |
]
|
|
929 |
]
|
|
930 |
! !
|