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