0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
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 |
|
119
|
13 |
'From Smalltalk/X, Version:2.10.5 on 30-apr-1995 at 1:46:03 am'!
|
105
|
14 |
|
0
|
15 |
View subclass:#Scroller
|
105
|
16 |
instanceVariableNames:'thumbOrigin thumbHeight thumbColor thumbFrameColor scrollAction
|
119
|
17 |
orientation thumbFrame thumbLevel scrolling pressOffset
|
105
|
18 |
synchronousOperation shadowForm lightForm inset thumbShadowColor
|
|
19 |
thumbLightColor thumbEdgeStyle thumbHalfShadowColor
|
|
20 |
thumbHalfLightColor thumbFrameSizeDifference tallyLevel
|
|
21 |
tallyMarks fixThumbHeight frameBeforeMove ghostColor
|
117
|
22 |
ghostFrameColor ghostLevel rangeStart rangeEnd rangeStep'
|
105
|
23 |
classVariableNames:'HandleShadowForm HandleLightForm DefaultViewBackground
|
|
24 |
DefaultShadowColor DefaultLightColor DefaultThumbColor
|
|
25 |
DefaultThumbShadowColor DefaultThumbLightColor
|
|
26 |
DefaultThumbHalfShadowColor DefaultThumbHalfLightColor
|
|
27 |
DefaultHalfShadowColor DefaultHalfLightColor DefaultTallyMarks
|
|
28 |
DefaultTallyLevel DefaultLevel DefaultBorderWidth
|
|
29 |
DefaultThumbLevel DefaultInset DefaultThumbFrameColor
|
|
30 |
DefaultGhostColor DefaultGhostFrameColor DefaultGhostLevel
|
|
31 |
DefaultFixThumbHeight DefaultEdgeStyle'
|
|
32 |
poolDictionaries:''
|
|
33 |
category:'Views-Interactors'
|
0
|
34 |
!
|
|
35 |
|
|
36 |
Scroller comment:'
|
5
|
37 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
38 |
All Rights Reserved
|
0
|
39 |
|
120
|
40 |
$Header: /cvs/stx/stx/libwidg/Scroller.st,v 1.21 1995-05-03 16:30:22 claus Exp $
|
3
|
41 |
'!
|
|
42 |
|
|
43 |
!Scroller class methodsFor:'documentation'!
|
|
44 |
|
38
|
45 |
copyright
|
|
46 |
"
|
|
47 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
48 |
All Rights Reserved
|
38
|
49 |
|
|
50 |
This software is furnished under a license and may be used
|
|
51 |
only in accordance with the terms of that license and with the
|
|
52 |
inclusion of the above copyright notice. This software may not
|
|
53 |
be provided or otherwise made available to, or used by, any
|
|
54 |
other person. No title to or ownership of the software is
|
|
55 |
hereby transferred.
|
|
56 |
"
|
|
57 |
!
|
|
58 |
|
|
59 |
version
|
|
60 |
"
|
120
|
61 |
$Header: /cvs/stx/stx/libwidg/Scroller.st,v 1.21 1995-05-03 16:30:22 claus Exp $
|
38
|
62 |
"
|
|
63 |
!
|
|
64 |
|
3
|
65 |
documentation
|
|
66 |
"
|
38
|
67 |
this class implements the scroller for scrollbars.
|
|
68 |
it can also be used by itself for scrollbars without step-buttons.
|
63
|
69 |
When moved, either a predefined action is performed (scrollAction),
|
119
|
70 |
or a model is informed via the changeMsg (which is #value: by default).
|
63
|
71 |
|
38
|
72 |
Beside the obvious 3D rectangle, a scroller may draw a know-form
|
|
73 |
(as in NeXT) or little tally marks (as on SGI) in itself.
|
|
74 |
These are controlled by the shadowForm, lightForm, tallyLevel and tallyMarks
|
|
75 |
instance variables.
|
63
|
76 |
|
38
|
77 |
The scroller can work synchronous (i.e. every move leads to an immediate evaluation
|
|
78 |
of the action, or asynchronous (i.e. perform action on end-of move).
|
63
|
79 |
By default, scrollers are synchronous. Asynchronous operation makes sense,
|
|
80 |
if the scroll operation (redraw) is expensive and takes a long time.
|
0
|
81 |
|
63
|
82 |
Instance variables:
|
0
|
83 |
|
38
|
84 |
thumbOrigin <Number> origin of thumb (in percent)
|
|
85 |
thumbHeight <Number> height of thumb (in percent)
|
|
86 |
thumbColor <Color> color of thumb
|
|
87 |
thumbFrameColor <Color> color of the frame around the thumb
|
|
88 |
scrollAction <Block> 1 arg block to be evaluated when scrolled
|
59
|
89 |
(arg is position in percent)
|
119
|
90 |
orientation <Symbol> #horizontal or #vertical
|
38
|
91 |
thumbFrame <Rectangle> frame of thumb in pixels (cached)
|
|
92 |
thumbLevel <Number> level of thumb if 3d
|
|
93 |
scrolling <Boolean> true during scroll
|
|
94 |
pressOffset <Number> temporary (offset into frame when move started)
|
|
95 |
synchronousOperation <Boolean> true if synchronous (i.e. dont wait till release
|
59
|
96 |
to perform action)
|
38
|
97 |
shadowForm <Form> bitmap of knob if any (shadow part)
|
|
98 |
lightForm <Form> bitmap of knob if any (light part)
|
|
99 |
inset <Integer> number of pixels to inset thumb from view borders
|
|
100 |
thumbShadowColor <Color> color do draw dark parts of thumb
|
|
101 |
thumblightColor <Color> color to draw light parts of thumb
|
63
|
102 |
thumbEdgeStyle <SymbolOrNil> #soft or nil
|
38
|
103 |
thumbHalfShadowColor <Color> used to draw smooth edges
|
|
104 |
thumbHalfLightColor <Color> used to draw smooth edges
|
|
105 |
thumbFrameSizeDifference <Integer> number of pixels the thumb is larger than
|
59
|
106 |
it should be (can be negative for mswin-style)
|
38
|
107 |
tallyLevel <Integer> if not zero, specifies if tally-marks should
|
59
|
108 |
go into or out of the display (actually only <0/>0 is checked)
|
|
109 |
I dont know of a better word for these ...
|
38
|
110 |
tallyMarks <Integer> number of tally marks
|
|
111 |
fixThumbHeight <Boolean> perform 'wrong' height computation a la mswindows
|
117
|
112 |
rangeStart <Number> the range of the scroller
|
|
113 |
rangeEnd (defaults to 0..100)
|
119
|
114 |
rangeStep not currently implemented
|
63
|
115 |
|
|
116 |
style settings:
|
|
117 |
|
|
118 |
scrollerLevel <Integer> the level of the scroller w.r.t. its enclosing view
|
|
119 |
scrollerBorderWidth <Integer> the borderWidth (ignored for 3D styles)
|
|
120 |
|
|
121 |
scrollerViewBackground <Color> the viewBackground (color or image)
|
|
122 |
scrollerShadowColor <Color> the color of 3D shadowed edges (ignored in 2D styles)
|
|
123 |
scrollerLightColor <Color> the color of 3D lighted edges (ignored in 2D styles)
|
|
124 |
|
|
125 |
scrollerThumbColor <Color> the thumbs color (color or image)
|
|
126 |
scrollerThumbShadowColor <Color> the color of the thumbs shadowed edges (ignored in 2D styles)
|
|
127 |
scrollerThumbLightColor <Color> the color of the thumbs shadowed edges (ignored in 2D styles)
|
|
128 |
scrollerThumbEdgeStyle <Symbol> the edge style for the thumb (#soft or nil)
|
|
129 |
scrollerThumbLevel <Integer> the 3D height of the thumb
|
|
130 |
scrollerThumbHalfShadowColor<Color> the halfShadow for soft edged thumbs
|
|
131 |
scrollerThumbHalfLightColor <Color> the halfLight for soft edged thumbs
|
|
132 |
scrollerThumbFrameColor <Color> if non-nil, a rectangle is drawn around the thumb is this color
|
|
133 |
scrollerThumbInset <Integer> inset of thumb from the scrollers boundary
|
|
134 |
scrollerThumbFixHeight <Boolean> if true, use a fix thumb height (as in mswindows)
|
|
135 |
scrollerGhostColor <Color> the color in which a ghost-rectangle is drawn
|
|
136 |
scrollerGhostFrameColor <Color> if non-nil, a rectangle is drawn around the ghost is this color
|
|
137 |
scrollerGhostLevel <Color> the 3D level of the ghost rectangle
|
|
138 |
scrollerNTallyMarks <Integer> number of tally-marks to draw on the thumb
|
|
139 |
scrollerTallyLevel. <Integer> the 3D level of any tally marks
|
|
140 |
|
38
|
141 |
notice: for mswindows style, we force a WRONG thumb-frame
|
|
142 |
computation, to make the thumb have constant size;
|
63
|
143 |
if you dont like that (I do not :-), set scrollerThumbFixHeight to false (in the StyleSheet).
|
3
|
144 |
"
|
117
|
145 |
!
|
|
146 |
|
|
147 |
examples
|
|
148 |
"
|
|
149 |
a scroller with action block (ST/X style):
|
|
150 |
|
|
151 |
|top s|
|
|
152 |
|
|
153 |
top := StandardSystemView new extent:200@200.
|
|
154 |
s := Scroller in:top.
|
|
155 |
s origin:(0.0@0.0) corner:(20@1.0).
|
|
156 |
s thumbHeight:10. 'percent'.
|
|
157 |
s scrollAction:[:percent | Transcript show:'moved to: '; showCr:percent asFloat].
|
|
158 |
top open
|
|
159 |
|
|
160 |
|
|
161 |
using a model (ST-80 style):
|
|
162 |
|
|
163 |
|top s m|
|
|
164 |
|
|
165 |
m := 0 asValue.
|
|
166 |
m inspect. 'look at value'.
|
|
167 |
top := StandardSystemView new extent:200@200.
|
|
168 |
s := Scroller in:top.
|
|
169 |
s origin:(0.0@0.0) corner:(20@1.0).
|
|
170 |
s thumbHeight:10. 'percent'.
|
|
171 |
s model:m.
|
|
172 |
top open
|
|
173 |
|
119
|
174 |
|
117
|
175 |
using a different changeSelector:
|
|
176 |
|
|
177 |
|top s1 s2 m|
|
|
178 |
|
|
179 |
m := Plug new.
|
|
180 |
m respondTo:#value1: with:[:v | Transcript show:'scroller 1 moved to: '; showCr:v].
|
|
181 |
m respondTo:#value2: with:[:v | Transcript show:'scroller 2 moved to: '; showCr:v].
|
|
182 |
|
|
183 |
top := StandardSystemView new extent:200@200.
|
|
184 |
s1 := Scroller in:top.
|
|
185 |
s1 origin:(0.0@0.0) corner:(20@1.0).
|
|
186 |
s1 thumbHeight:10. 'percent'.
|
|
187 |
s1 model:m; change:#value1:.
|
|
188 |
|
|
189 |
s2 := Scroller in:top.
|
|
190 |
s2 origin:(30@0.0) corner:(50@1.0).
|
|
191 |
s2 thumbHeight:10. 'percent'.
|
|
192 |
s2 model:m; change:#value2:.
|
|
193 |
top open
|
|
194 |
"
|
3
|
195 |
! !
|
0
|
196 |
|
|
197 |
!Scroller class methodsFor:'defaults'!
|
|
198 |
|
59
|
199 |
updateStyleCache
|
60
|
200 |
DefaultViewBackground := StyleSheet colorAt:'scrollerViewBackground'.
|
|
201 |
DefaultThumbColor := StyleSheet colorAt:'scrollerThumbColor'.
|
63
|
202 |
DefaultShadowColor := StyleSheet colorAt:'scrollerShadowColor'.
|
|
203 |
DefaultLightColor := StyleSheet colorAt:'scrollerLightColor'.
|
|
204 |
DefaultThumbShadowColor := StyleSheet colorAt:'scrollerThumbShadowColor'.
|
|
205 |
DefaultThumbLightColor := StyleSheet colorAt:'scrollerThumbLightColor'.
|
|
206 |
DefaultThumbHalfShadowColor := StyleSheet colorAt:'scrollerThumbHalfShadowColor'.
|
|
207 |
DefaultThumbHalfLightColor := StyleSheet colorAt:'scrollerThumbHalfLightColor'.
|
60
|
208 |
DefaultThumbFrameColor := StyleSheet colorAt:'scrollerThumbFrameColor'.
|
63
|
209 |
DefaultGhostColor := StyleSheet colorAt:'scrollerGhostColor' default:nil.
|
|
210 |
DefaultGhostFrameColor := StyleSheet colorAt:'scrollerGhostFrameColor' default:nil.
|
|
211 |
DefaultGhostLevel := StyleSheet at:'scrollerGhostLevel' default:0.
|
59
|
212 |
DefaultTallyMarks := StyleSheet at:'scrollerNTallyMarks' default:0.
|
|
213 |
DefaultTallyLevel := 0.
|
|
214 |
DefaultTallyMarks ~~ 0 ifTrue:[
|
|
215 |
DefaultTallyLevel := StyleSheet at:'scrollerTallyLevel' default:1.
|
|
216 |
].
|
|
217 |
DefaultLevel := StyleSheet at:'scrollerLevel' default:0.
|
|
218 |
DefaultBorderWidth := StyleSheet at:'scrollerBorderWidth' default:(StyleSheet at:'borderWidth').
|
|
219 |
DefaultThumbLevel := StyleSheet at:'scrollerThumbLevel' default:0.
|
|
220 |
DefaultInset := StyleSheet at:'scrollerThumbInset' default:0.
|
|
221 |
DefaultFixThumbHeight := StyleSheet at:'scrollerThumbFixHeight' default:false.
|
63
|
222 |
DefaultEdgeStyle := StyleSheet at:'scrollerThumbEdgeStyle'.
|
59
|
223 |
!
|
|
224 |
|
0
|
225 |
handleShadowFormOn:aDisplay
|
|
226 |
"answer the form used for the handles shadow area;
|
|
227 |
cache the one for Display for the next round"
|
|
228 |
|
|
229 |
|f|
|
|
230 |
|
22
|
231 |
((aDisplay == Display) and:[HandleShadowForm notNil]) ifTrue:[
|
59
|
232 |
^ HandleShadowForm
|
0
|
233 |
].
|
|
234 |
f := Form fromFile:'HandleShadow.xbm' resolution:100 on:aDisplay.
|
|
235 |
f isNil ifTrue:[
|
59
|
236 |
f := Form width:8 height:8 fromArray:#[2r00111100
|
|
237 |
2r01100000
|
|
238 |
2r11000000
|
|
239 |
2r11000000
|
|
240 |
2r11000000
|
|
241 |
2r11000000
|
|
242 |
2r01000000
|
|
243 |
2r00000000]
|
|
244 |
on:aDisplay
|
0
|
245 |
].
|
|
246 |
(aDisplay == Display) ifTrue:[
|
59
|
247 |
HandleShadowForm := f
|
0
|
248 |
].
|
|
249 |
^ f
|
|
250 |
!
|
|
251 |
|
|
252 |
handleLightFormOn:aDisplay
|
|
253 |
"answer the form used for the handles light area;
|
|
254 |
cache the one for Display for the next round"
|
|
255 |
|
|
256 |
|f|
|
|
257 |
|
22
|
258 |
((aDisplay == Display) and:[HandleLightForm notNil]) ifTrue:[
|
59
|
259 |
^ HandleLightForm
|
0
|
260 |
].
|
|
261 |
f := Form fromFile:'HandleLight.xbm' resolution:100 on:aDisplay.
|
|
262 |
f isNil ifTrue:[
|
59
|
263 |
f := Form width:8 height:8 fromArray:#[2r00000000
|
|
264 |
2r00000010
|
|
265 |
2r00000011
|
|
266 |
2r00000011
|
|
267 |
2r00000011
|
|
268 |
2r00000011
|
|
269 |
2r00000110
|
|
270 |
2r00111100]
|
|
271 |
on:aDisplay
|
0
|
272 |
].
|
|
273 |
(aDisplay == Display) ifTrue:[
|
59
|
274 |
HandleLightForm := f
|
0
|
275 |
].
|
|
276 |
^ f
|
|
277 |
! !
|
|
278 |
|
119
|
279 |
!Scroller methodsFor:'private'!
|
|
280 |
|
|
281 |
absFromPercent:percent
|
|
282 |
"given a percentage, compute number of pixels"
|
|
283 |
|
|
284 |
|fullSize|
|
|
285 |
|
|
286 |
(orientation == #vertical) ifTrue:[
|
|
287 |
fullSize := height
|
|
288 |
] ifFalse:[
|
|
289 |
fullSize := width
|
|
290 |
].
|
|
291 |
"/ ^ ((percent * (fullSize - (margin * 2))) / 100) rounded
|
|
292 |
"/ 20-apr-94
|
|
293 |
^ ((percent * (fullSize - thumbFrameSizeDifference- (margin * 2))) / 100) rounded
|
|
294 |
!
|
|
295 |
|
|
296 |
computeThumbFrame
|
|
297 |
"compute the thumbs frame (a rectangle) whenever thumb is moved,
|
|
298 |
changed height or the scrollers size has changed.
|
|
299 |
We take care, that the thumb will not become too small (i.e.
|
|
300 |
invisible or uncatchable).
|
|
301 |
Also, for mswindows style, its height/width is constant."
|
|
302 |
|
|
303 |
|newPos1 newPos2 newSize1 newSize2 nh nw ny nx
|
|
304 |
computedSize minSz sz1 sz2|
|
|
305 |
|
|
306 |
"compute position & size"
|
|
307 |
newPos1 := (self absFromPercent:thumbOrigin) + margin.
|
|
308 |
newSize1 := computedSize := self absFromPercent:thumbHeight.
|
|
309 |
(orientation == #vertical) ifTrue:[
|
|
310 |
sz1 := height.
|
|
311 |
sz2 := width
|
|
312 |
] ifFalse:[
|
|
313 |
sz1 := width.
|
|
314 |
sz2 := height
|
|
315 |
].
|
|
316 |
|
|
317 |
"
|
|
318 |
do we have to adjust the computed size ?
|
|
319 |
"
|
|
320 |
newPos2 := margin + inset.
|
|
321 |
newSize2 := sz2 - (2 * newPos2).
|
|
322 |
"/ (style ~~ #normal) ifTrue:[
|
|
323 |
thumbLevel ~~ 0 ifTrue:[
|
|
324 |
"
|
|
325 |
do not make thumb too small (for handle & to be catchable)
|
|
326 |
"
|
|
327 |
minSz := 10 + (2 * thumbLevel)
|
|
328 |
] ifFalse:[
|
|
329 |
"
|
|
330 |
do not make thumb too small (uncatchable)
|
|
331 |
"
|
|
332 |
minSz := 4
|
|
333 |
].
|
|
334 |
|
|
335 |
(newSize1 < minSz) ifTrue:[
|
|
336 |
newSize1 := minSz.
|
|
337 |
thumbFrameSizeDifference := newSize1 - computedSize
|
|
338 |
] ifFalse:[
|
|
339 |
thumbFrameSizeDifference := 0.
|
|
340 |
].
|
|
341 |
|
|
342 |
fixThumbHeight ifTrue:[
|
|
343 |
"have a fix-size thumb (i.e. mswindows style)"
|
|
344 |
|
|
345 |
newSize1 := sz2 - (2 * inset). "make it square"
|
|
346 |
thumbFrameSizeDifference := newSize1 - computedSize.
|
|
347 |
].
|
|
348 |
|
|
349 |
"
|
|
350 |
oops - if height does not relect real visibible area, we have to adjust the origin
|
|
351 |
"
|
|
352 |
(thumbFrameSizeDifference == 0) ifFalse:[
|
|
353 |
newPos1 := (self absFromPercent:thumbOrigin) + margin.
|
|
354 |
"/ newPos1 := ((thumbOrigin * (sz1 - thumbFrameSizeDifference - (margin * 2))) / 100) rounded + margin
|
|
355 |
].
|
|
356 |
|
|
357 |
(orientation == #vertical) ifTrue:[
|
|
358 |
ny := newPos1.
|
|
359 |
nx := newPos2.
|
|
360 |
nh := newSize1.
|
|
361 |
nw := newSize2.
|
|
362 |
ny + nh + margin > height ifTrue:[
|
|
363 |
ny := height - margin - nh
|
|
364 |
]
|
|
365 |
] ifFalse:[
|
|
366 |
nx := newPos1.
|
|
367 |
ny := newPos2.
|
|
368 |
nw := newSize1.
|
|
369 |
nh := newSize2.
|
|
370 |
nx + nw + margin > width ifTrue:[
|
|
371 |
nx := width - margin - nw
|
|
372 |
]
|
|
373 |
].
|
|
374 |
|
|
375 |
"
|
|
376 |
do not create new Rectangle if its the same anyway
|
|
377 |
"
|
|
378 |
thumbFrame notNil ifTrue:[
|
|
379 |
(ny == thumbFrame top) ifTrue:[
|
|
380 |
(nx == thumbFrame left) ifTrue:[
|
|
381 |
(nh == thumbFrame height) ifTrue:[
|
|
382 |
(nw == thumbFrame width) ifTrue:[ ^ self]
|
|
383 |
]
|
|
384 |
]
|
|
385 |
]
|
|
386 |
].
|
|
387 |
thumbFrame := Rectangle left:nx top:ny width:nw height:nh
|
|
388 |
!
|
|
389 |
|
|
390 |
percentFromAbs:absValue
|
|
391 |
"given a number of pixels, compute percentage"
|
|
392 |
|
|
393 |
|fullSize val|
|
|
394 |
|
|
395 |
(orientation == #vertical) ifTrue:[
|
|
396 |
fullSize := height
|
|
397 |
] ifFalse:[
|
|
398 |
fullSize := width
|
|
399 |
].
|
|
400 |
|
|
401 |
val := absValue / (fullSize - thumbFrameSizeDifference - (margin * 2)) * (rangeEnd - rangeStart).
|
|
402 |
val := val + rangeStart.
|
|
403 |
val < rangeStart ifTrue:[^ rangeStart].
|
|
404 |
val > rangeEnd ifTrue:[^ rangeEnd].
|
|
405 |
^ val
|
|
406 |
|
|
407 |
! !
|
|
408 |
|
0
|
409 |
!Scroller methodsFor:'drawing'!
|
|
410 |
|
119
|
411 |
drawThumbBackgroundInX:x y:y width:w height:h
|
|
412 |
"draw part of the thumbs background; defined as a separate
|
|
413 |
method, to allow drawing of arbitrary patterns under thumb
|
|
414 |
(see ColorSlider)."
|
|
415 |
|
|
416 |
shown ifTrue:[
|
|
417 |
self clearRectangleX:x y:y width:w height:h.
|
|
418 |
frameBeforeMove notNil ifTrue:[
|
|
419 |
self clippedTo:(Rectangle left:x top:y width:w height:h) do:[
|
|
420 |
|gX gY gW gH|
|
|
421 |
|
|
422 |
gX := frameBeforeMove left.
|
|
423 |
gY := frameBeforeMove top.
|
|
424 |
gW := frameBeforeMove width.
|
|
425 |
gH := frameBeforeMove height.
|
|
426 |
|
|
427 |
self fillRectangle:frameBeforeMove with:ghostColor.
|
|
428 |
(ghostLevel ~~ 0) ifTrue:[
|
|
429 |
self drawEdgesForX:gX y:gY width:gW height:gH level:ghostLevel
|
|
430 |
].
|
|
431 |
ghostFrameColor notNil ifTrue:[
|
|
432 |
self paint:ghostFrameColor.
|
|
433 |
self displayRectangleX:gX y:gY width:gW height:gH
|
|
434 |
]
|
|
435 |
]
|
|
436 |
]
|
|
437 |
]
|
|
438 |
!
|
|
439 |
|
0
|
440 |
drawThumb
|
|
441 |
"draw the thumb"
|
|
442 |
|
|
443 |
|handleX handleY l t
|
|
444 |
w "{ Class: SmallInteger }"
|
|
445 |
h "{ Class: SmallInteger }"
|
|
446 |
x "{ Class: SmallInteger }"
|
|
447 |
y "{ Class: SmallInteger }"
|
63
|
448 |
mm xL xR yT yB color1 color2|
|
0
|
449 |
|
38
|
450 |
(thumbHeight >= 100) ifTrue:[^ self].
|
119
|
451 |
orientation == #vertical ifTrue:[
|
59
|
452 |
thumbFrame height >= height ifTrue:[^ self].
|
38
|
453 |
] ifFalse:[
|
59
|
454 |
thumbFrame width >= width ifTrue:[^ self].
|
38
|
455 |
].
|
0
|
456 |
|
|
457 |
l := thumbFrame left.
|
|
458 |
t := thumbFrame top.
|
|
459 |
w := thumbFrame width.
|
|
460 |
h := thumbFrame height.
|
|
461 |
self paint:thumbColor.
|
38
|
462 |
self fillRectangleX:l y:t width:w-1 height:h.
|
0
|
463 |
|
59
|
464 |
thumbLevel == 0 ifTrue:[
|
|
465 |
thumbFrameColor notNil ifTrue:[
|
|
466 |
self paint:thumbFrameColor.
|
|
467 |
self displayRectangle:thumbFrame.
|
|
468 |
].
|
|
469 |
^ self
|
0
|
470 |
].
|
|
471 |
|
22
|
472 |
"what a kludge - must be a parameter to drawEdge..."
|
0
|
473 |
self drawEdgesForX:l y:t width:w height:h level:thumbLevel
|
59
|
474 |
shadow:thumbShadowColor light:thumbLightColor
|
63
|
475 |
halfShadow:thumbHalfShadowColor halfLight:thumbHalfLightColor
|
|
476 |
style:thumbEdgeStyle.
|
0
|
477 |
|
59
|
478 |
thumbFrameColor notNil ifTrue:[
|
|
479 |
self paint:thumbFrameColor.
|
119
|
480 |
orientation == #vertical ifTrue:[
|
59
|
481 |
self displayRectangleX:l y:t width:w"-1" height:h.
|
|
482 |
] ifFalse:[
|
|
483 |
self displayRectangleX:l y:t width:w height:h"-1".
|
|
484 |
]
|
38
|
485 |
].
|
|
486 |
|
22
|
487 |
(tallyLevel == 0 or:[tallyMarks == 0]) ifTrue:[
|
59
|
488 |
shadowForm notNil ifTrue:[
|
|
489 |
handleX := l + ((w - 8) // 2).
|
|
490 |
handleY := t + ((h - 8) // 2).
|
|
491 |
self drawHandleFormAtX:handleX y:handleY
|
|
492 |
].
|
|
493 |
^ self
|
0
|
494 |
].
|
|
495 |
|
22
|
496 |
"iris style - draw tallys"
|
|
497 |
|
|
498 |
tallyLevel > 0 ifTrue:[
|
59
|
499 |
color1 := thumbLightColor.
|
|
500 |
color2 := thumbShadowColor.
|
22
|
501 |
] ifFalse:[
|
59
|
502 |
color1 := thumbShadowColor.
|
|
503 |
color2 := thumbLightColor.
|
22
|
504 |
].
|
|
505 |
|
|
506 |
"draw tally marks"
|
|
507 |
|
119
|
508 |
(orientation == #vertical) ifTrue:[
|
59
|
509 |
self paint:color1.
|
|
510 |
y := t + (h // 2) - 1.
|
|
511 |
xL := l + thumbLevel - 1.
|
|
512 |
xR := l + w - thumbLevel "+ 1".
|
|
513 |
self displayLineFromX:xL y:y toX:xR y:y.
|
|
514 |
y := y + 1.
|
|
515 |
self paint:color2.
|
|
516 |
self displayLineFromX:xL y:y toX:xR y:y.
|
0
|
517 |
|
59
|
518 |
tallyMarks > 1 ifTrue:[
|
|
519 |
"dont draw other marks if there is not enough space"
|
0
|
520 |
|
59
|
521 |
mm := device verticalPixelPerMillimeter rounded.
|
|
522 |
h > (mm * (tallyMarks * 2)) ifTrue:[
|
|
523 |
y := y - 1 - mm.
|
|
524 |
self paint:color1.
|
|
525 |
self displayLineFromX:xL y:y toX:xR y:y.
|
|
526 |
y := y + 1.
|
|
527 |
self paint:color2.
|
|
528 |
self displayLineFromX:xL y:y toX:xR y:y.
|
0
|
529 |
|
59
|
530 |
y := y - 1 + mm + mm.
|
|
531 |
self paint:color1.
|
|
532 |
self displayLineFromX:xL y:y toX:xR y:y.
|
|
533 |
y := y + 1.
|
|
534 |
self paint:color2.
|
|
535 |
self displayLineFromX:xL y:y toX:xR y:y
|
|
536 |
]
|
|
537 |
]
|
0
|
538 |
] ifFalse:[
|
59
|
539 |
x := l + (w // 2) - 1.
|
|
540 |
yT := t + thumbLevel - 1.
|
|
541 |
yB := t + h - thumbLevel "+ 1".
|
|
542 |
self paint:color1.
|
|
543 |
self displayLineFromX:x y:yT toX:x y:yB.
|
|
544 |
self paint:color2.
|
|
545 |
x := x + 1.
|
|
546 |
self displayLineFromX:x y:yT toX:x y:yB.
|
0
|
547 |
|
59
|
548 |
tallyMarks > 1 ifTrue:[
|
|
549 |
"dont draw other marks if there is not enough space"
|
0
|
550 |
|
59
|
551 |
mm := device horizontalPixelPerMillimeter rounded.
|
|
552 |
w > (mm * (tallyMarks * 2)) ifTrue:[
|
|
553 |
x := x - 1 - mm.
|
|
554 |
self paint:color1.
|
|
555 |
self displayLineFromX:x y:yT toX:x y:yB.
|
|
556 |
x := x + 1.
|
|
557 |
self paint:color2.
|
|
558 |
self displayLineFromX:x y:yT toX:x y:yB.
|
22
|
559 |
|
59
|
560 |
x := x - 1 + mm + mm.
|
|
561 |
self paint:color1.
|
|
562 |
self displayLineFromX:x y:yT toX:x y:yB.
|
|
563 |
x := x + 1.
|
|
564 |
self paint:color2.
|
|
565 |
self displayLineFromX:x y:yT toX:x y:yB
|
|
566 |
]
|
|
567 |
]
|
0
|
568 |
]
|
105
|
569 |
!
|
|
570 |
|
|
571 |
drawHandleFormAtX:x y:y
|
|
572 |
thumbShadowColor := thumbShadowColor on:device.
|
|
573 |
thumbLightColor := thumbLightColor on:device.
|
|
574 |
|
|
575 |
self paint:thumbShadowColor.
|
|
576 |
self displayForm:shadowForm x:x y:y.
|
|
577 |
self paint:thumbLightColor.
|
|
578 |
self displayForm:lightForm x:x y:y.
|
0
|
579 |
! !
|
|
580 |
|
119
|
581 |
!Scroller methodsFor:'event handling'!
|
|
582 |
|
|
583 |
redrawX:x y:y width:w height:h
|
|
584 |
shown ifTrue:[
|
|
585 |
thumbFrame isNil ifTrue:[self computeThumbFrame].
|
|
586 |
self drawThumbBackgroundInX:x y:y width:w height:h.
|
|
587 |
(y > thumbFrame bottom) ifTrue:[
|
|
588 |
^ self
|
|
589 |
].
|
|
590 |
((y + h) < thumbFrame top) ifTrue:[
|
|
591 |
^ self
|
|
592 |
].
|
|
593 |
self drawThumb
|
|
594 |
]
|
|
595 |
!
|
|
596 |
|
|
597 |
buttonPress:button x:x y:y
|
|
598 |
"button was pressed - if above thumb, page up; if below thumb, page down;
|
|
599 |
otherwise start scrolling"
|
|
600 |
|
|
601 |
|curr limit1 limit2|
|
|
602 |
|
120
|
603 |
shown ifFalse:[^ self].
|
|
604 |
|
119
|
605 |
(orientation == #vertical) ifTrue:[
|
|
606 |
curr := y.
|
|
607 |
limit1 := thumbFrame top.
|
|
608 |
limit2 := thumbFrame bottom
|
|
609 |
] ifFalse:[
|
|
610 |
curr := x.
|
|
611 |
limit1 := thumbFrame left.
|
|
612 |
limit2 := thumbFrame right
|
|
613 |
].
|
|
614 |
|
|
615 |
(curr < limit1) ifTrue:[
|
|
616 |
"page up/left"
|
|
617 |
self pageUp
|
|
618 |
] ifFalse:[
|
|
619 |
(curr > limit2) ifTrue:[
|
|
620 |
"page down/right"
|
|
621 |
self pageDown
|
|
622 |
] ifFalse:[
|
|
623 |
pressOffset := curr - limit1.
|
|
624 |
scrolling := true
|
|
625 |
]
|
|
626 |
]
|
|
627 |
!
|
|
628 |
|
|
629 |
buttonRelease:button x:x y:y
|
|
630 |
"mouse-button was released - if scroll-mode is asynchronous, the scroll
|
|
631 |
action is now performed"
|
|
632 |
|
|
633 |
|rect|
|
|
634 |
|
|
635 |
scrolling ifTrue:[
|
|
636 |
frameBeforeMove notNil ifTrue:[
|
|
637 |
rect := frameBeforeMove.
|
|
638 |
frameBeforeMove := nil.
|
|
639 |
self drawThumbBackgroundInX:rect left
|
|
640 |
y:rect top
|
|
641 |
width:rect width
|
|
642 |
height:rect height.
|
|
643 |
(rect intersects:thumbFrame) ifTrue:[
|
|
644 |
self drawThumb
|
|
645 |
]
|
|
646 |
].
|
|
647 |
|
|
648 |
scrolling := false.
|
|
649 |
synchronousOperation ifFalse: [
|
|
650 |
self tellOthers.
|
|
651 |
]
|
|
652 |
]
|
|
653 |
!
|
|
654 |
|
|
655 |
buttonMotion:button x:x y:y
|
|
656 |
"mouse-button was moved while pressed;
|
|
657 |
redraw thumb at its new position and, if scroll-mode is asynchronous,
|
|
658 |
the scroll action is performed"
|
|
659 |
|
|
660 |
|pos curr limit prevOrigin newOrigin|
|
|
661 |
|
|
662 |
scrolling ifFalse: [^ self]. "should not happen"
|
|
663 |
|
|
664 |
frameBeforeMove isNil ifTrue:[
|
|
665 |
ghostColor notNil ifTrue:[
|
|
666 |
frameBeforeMove := thumbFrame insetBy:1@1
|
|
667 |
]
|
|
668 |
].
|
|
669 |
|
|
670 |
(orientation == #vertical) ifTrue:[
|
|
671 |
curr := y.
|
|
672 |
limit := height
|
|
673 |
] ifFalse:[
|
|
674 |
curr := x.
|
|
675 |
limit := width
|
|
676 |
].
|
|
677 |
|
|
678 |
(curr < 0) ifTrue:[ "check against limits"
|
|
679 |
pos := 0
|
|
680 |
] ifFalse:[
|
|
681 |
(curr > limit) ifTrue:[
|
|
682 |
pos := limit
|
|
683 |
] ifFalse:[
|
|
684 |
pos := curr
|
|
685 |
]
|
|
686 |
].
|
|
687 |
|
|
688 |
prevOrigin := self thumbOrigin.
|
|
689 |
newOrigin := self percentFromAbs:(pos - pressOffset).
|
|
690 |
prevOrigin ~= newOrigin ifTrue:[
|
|
691 |
self thumbOrigin:newOrigin.
|
|
692 |
|
|
693 |
synchronousOperation ifTrue: [
|
|
694 |
self tellOthers.
|
|
695 |
]
|
|
696 |
]
|
|
697 |
!
|
|
698 |
|
|
699 |
sizeChanged:how
|
|
700 |
"size of scroller changed - recompute thumbs frame and redraw it"
|
|
701 |
|
|
702 |
shown ifTrue:[
|
|
703 |
self computeThumbFrame.
|
|
704 |
self redraw
|
|
705 |
]
|
|
706 |
!
|
|
707 |
|
|
708 |
update:something with:aParameter from:changedObject
|
|
709 |
"handle update from a model (if any)"
|
|
710 |
|
|
711 |
(changedObject == model
|
|
712 |
"and:[something == aspectMsg]") ifTrue:[
|
|
713 |
self thumbOrigin:(model value).
|
|
714 |
^ self
|
|
715 |
].
|
|
716 |
super update:something with:aParameter from:changedObject
|
|
717 |
!
|
|
718 |
|
|
719 |
redraw
|
|
720 |
"redraw"
|
|
721 |
|
|
722 |
shown ifTrue:[
|
|
723 |
thumbFrame isNil ifTrue:[self computeThumbFrame].
|
|
724 |
self drawThumbBackgroundInX:0 y:0 width:width height:height.
|
|
725 |
self drawThumb
|
|
726 |
]
|
|
727 |
!
|
|
728 |
|
|
729 |
buttonMultiPress:button x:x y:y
|
|
730 |
^ self buttonPress:button x:x y:y
|
|
731 |
!
|
|
732 |
|
|
733 |
buttonShiftPress:button x:x y:y
|
|
734 |
"mouse-click with shift - jump to position"
|
|
735 |
|
|
736 |
|pos curr curr2 limit1 limit2 org|
|
|
737 |
|
|
738 |
(orientation == #vertical) ifTrue:[
|
|
739 |
curr := y.
|
|
740 |
curr2 := y - (thumbFrame height // 2).
|
|
741 |
limit1 := height.
|
|
742 |
limit2 := thumbFrame top
|
|
743 |
] ifFalse:[
|
|
744 |
curr := x.
|
|
745 |
curr2 := x - (thumbFrame width // 2).
|
|
746 |
limit1 := width.
|
|
747 |
limit2 := thumbFrame left
|
|
748 |
].
|
|
749 |
|
|
750 |
(curr2 < 0) ifTrue:[ "check against limits"
|
|
751 |
pos := 0
|
|
752 |
] ifFalse:[
|
|
753 |
(curr2 > limit1) ifTrue:[
|
|
754 |
pos := limit1
|
|
755 |
] ifFalse:[
|
|
756 |
pos := curr2
|
|
757 |
]
|
|
758 |
].
|
|
759 |
|
|
760 |
frameBeforeMove := thumbFrame insetBy:1@1.
|
|
761 |
|
|
762 |
self thumbOrigin:(self percentFromAbs:pos).
|
|
763 |
self tellOthers.
|
|
764 |
|
|
765 |
(orientation == #vertical) ifTrue:[
|
|
766 |
limit2 := thumbFrame top
|
|
767 |
] ifFalse:[
|
|
768 |
limit2 := thumbFrame left
|
|
769 |
].
|
|
770 |
pressOffset := curr - limit2.
|
|
771 |
scrolling := true
|
|
772 |
! !
|
|
773 |
|
105
|
774 |
!Scroller methodsFor:'accessing'!
|
|
775 |
|
119
|
776 |
thumbHeight:aNumber
|
|
777 |
"set the thumbs height (in percent by default)"
|
|
778 |
|
|
779 |
|newHeight realNewHeight oldFrame|
|
|
780 |
|
|
781 |
newHeight := aNumber / (rangeEnd - rangeStart / 100).
|
|
782 |
|
|
783 |
(newHeight > 100) ifTrue:[
|
|
784 |
realNewHeight := 100
|
|
785 |
] ifFalse:[
|
|
786 |
realNewHeight := newHeight
|
|
787 |
].
|
|
788 |
((realNewHeight ~= thumbHeight) or:[thumbFrame isNil]) ifTrue:[
|
|
789 |
thumbHeight := realNewHeight.
|
|
790 |
shown ifTrue:[
|
|
791 |
oldFrame := thumbFrame.
|
|
792 |
self computeThumbFrame.
|
|
793 |
(fixThumbHeight or:[oldFrame ~~ thumbFrame]) ifTrue:[
|
|
794 |
oldFrame notNil ifTrue:[
|
|
795 |
self drawThumbBackgroundInX:(oldFrame left)
|
|
796 |
y:(oldFrame top)
|
|
797 |
width:(oldFrame width)
|
|
798 |
height:(oldFrame height).
|
|
799 |
].
|
|
800 |
self drawThumb
|
|
801 |
]
|
|
802 |
] ifFalse:[
|
|
803 |
thumbFrame := nil
|
|
804 |
]
|
|
805 |
]
|
|
806 |
!
|
|
807 |
|
117
|
808 |
thumbOrigin:aNumber
|
|
809 |
"set the thumbs origin (in percent by default)"
|
105
|
810 |
|
119
|
811 |
|newOrigin realNewOrigin
|
|
812 |
oldFrame oldTop oldBot oldLeft oldRight
|
|
813 |
thumbTop thumbBot thumbLeft thumbRight
|
105
|
814 |
tH "{ Class: SmallInteger }"
|
119
|
815 |
tW
|
|
816 |
delta left needFullDraw
|
|
817 |
bgLeft bgTop bgWidth bgHeight|
|
105
|
818 |
|
117
|
819 |
newOrigin := aNumber / (rangeEnd - rangeStart / 100) - rangeStart.
|
|
820 |
|
105
|
821 |
((newOrigin + thumbHeight) > 100) ifTrue:[
|
|
822 |
realNewOrigin := 100 - thumbHeight
|
|
823 |
] ifFalse: [
|
|
824 |
realNewOrigin := newOrigin
|
|
825 |
].
|
|
826 |
(realNewOrigin > 100) ifTrue:[
|
|
827 |
realNewOrigin := 100
|
|
828 |
] ifFalse: [
|
|
829 |
(realNewOrigin < 0) ifTrue:[
|
|
830 |
realNewOrigin := 0
|
|
831 |
]
|
|
832 |
].
|
|
833 |
((realNewOrigin ~= thumbOrigin) or:[thumbFrame isNil]) ifTrue:[
|
|
834 |
thumbOrigin := realNewOrigin.
|
|
835 |
|
|
836 |
shown ifTrue:[
|
|
837 |
oldFrame := thumbFrame.
|
|
838 |
self computeThumbFrame.
|
117
|
839 |
(thumbHeight = 100) ifTrue:[
|
|
840 |
"/ full: don't draw
|
|
841 |
^ self
|
|
842 |
].
|
105
|
843 |
|
|
844 |
(thumbFrame ~~ oldFrame) ifTrue:[
|
|
845 |
oldFrame isNil ifTrue:[
|
|
846 |
self drawThumb.
|
|
847 |
^ self
|
|
848 |
].
|
|
849 |
tH := thumbFrame height.
|
|
850 |
tW := thumbFrame width.
|
119
|
851 |
|
105
|
852 |
oldTop := oldFrame top.
|
|
853 |
oldBot := oldTop + tH.
|
119
|
854 |
oldLeft := oldFrame left.
|
|
855 |
oldRight := oldLeft + tW.
|
105
|
856 |
|
|
857 |
thumbTop := thumbFrame top.
|
|
858 |
thumbBot := thumbTop + tH.
|
119
|
859 |
thumbLeft := thumbFrame left.
|
|
860 |
thumbRight := thumbLeft + tW.
|
105
|
861 |
|
119
|
862 |
needFullDraw := self exposeEventPending
|
|
863 |
or:[((orientation == #vertical) and:[oldBot >= height])
|
|
864 |
or:[((orientation ~~ #vertical) and:[oldRight >= width])]].
|
105
|
865 |
|
119
|
866 |
needFullDraw ifTrue:[
|
|
867 |
"
|
|
868 |
cannot copy since thumb was below the end
|
|
869 |
or may be not available for the copy
|
|
870 |
"
|
|
871 |
(orientation == #vertical) ifTrue:[
|
|
872 |
self drawThumbBackgroundInX:thumbLeft y:oldTop
|
|
873 |
width:tW height:(height - oldTop).
|
|
874 |
] ifFalse:[
|
|
875 |
self drawThumbBackgroundInX:oldLeft y:thumbTop
|
|
876 |
width:(width - oldLeft) height:tH.
|
|
877 |
].
|
105
|
878 |
self drawThumb.
|
|
879 |
^ self
|
|
880 |
].
|
|
881 |
|
|
882 |
self catchExpose.
|
119
|
883 |
"
|
|
884 |
copy the thumbs pixels
|
|
885 |
"
|
|
886 |
(orientation == #vertical) ifTrue:[
|
|
887 |
self copyFrom:self x:thumbLeft y:oldTop
|
|
888 |
toX:thumbLeft y:thumbTop
|
|
889 |
width:tW height:tH.
|
|
890 |
] ifFalse:[
|
|
891 |
self copyFrom:self x:oldLeft y:thumbTop
|
|
892 |
toX:thumbLeft y:thumbTop
|
|
893 |
width:tW height:tH.
|
|
894 |
].
|
105
|
895 |
|
119
|
896 |
"
|
|
897 |
clear some of the previous thumbs area to background
|
|
898 |
"
|
|
899 |
(orientation == #vertical) ifTrue:[
|
|
900 |
bgLeft := thumbLeft.
|
|
901 |
bgWidth := tW.
|
|
902 |
oldTop > thumbTop ifTrue:[
|
|
903 |
delta := oldTop - thumbTop.
|
|
904 |
oldTop > thumbBot ifTrue:[
|
|
905 |
bgTop := oldTop.
|
|
906 |
bgHeight := tH + 1
|
|
907 |
] ifFalse:[
|
|
908 |
bgTop := thumbBot.
|
|
909 |
bgHeight := delta
|
|
910 |
]
|
105
|
911 |
] ifFalse:[
|
119
|
912 |
delta := thumbTop - oldTop.
|
|
913 |
oldBot < thumbTop ifTrue:[
|
|
914 |
bgTop := oldTop.
|
|
915 |
bgHeight := tH + 1
|
|
916 |
] ifFalse:[
|
|
917 |
bgTop := oldTop.
|
|
918 |
bgHeight := delta
|
|
919 |
]
|
|
920 |
].
|
105
|
921 |
] ifFalse:[
|
119
|
922 |
bgTop := thumbTop.
|
|
923 |
bgHeight := tH.
|
|
924 |
oldLeft > thumbLeft ifTrue:[
|
|
925 |
delta := oldLeft - thumbLeft.
|
|
926 |
oldLeft > thumbRight ifTrue:[
|
|
927 |
bgLeft := oldLeft.
|
|
928 |
bgWidth := tW + 1.
|
|
929 |
] ifFalse:[
|
|
930 |
bgLeft := thumbRight.
|
|
931 |
bgWidth := delta.
|
|
932 |
]
|
105
|
933 |
] ifFalse:[
|
119
|
934 |
delta := thumbLeft - oldLeft.
|
|
935 |
oldRight < thumbLeft ifTrue:[
|
|
936 |
bgLeft := oldLeft.
|
|
937 |
bgWidth := tW + 1.
|
|
938 |
] ifFalse:[
|
|
939 |
bgLeft := oldLeft.
|
|
940 |
bgWidth := delta.
|
|
941 |
]
|
|
942 |
].
|
105
|
943 |
].
|
119
|
944 |
self drawThumbBackgroundInX:bgLeft y:bgTop width:bgWidth height:bgHeight.
|
105
|
945 |
self waitForExpose
|
|
946 |
]
|
|
947 |
] ifFalse:[
|
|
948 |
thumbFrame := nil
|
|
949 |
]
|
|
950 |
]
|
|
951 |
!
|
|
952 |
|
117
|
953 |
thumbOrigin:originNumber thumbHeight:heightNumber
|
|
954 |
"set both thumbs height and origin (in percent by default)"
|
105
|
955 |
|
117
|
956 |
|newHeight newOrigin realNewOrigin realNewHeight old new changed|
|
|
957 |
|
|
958 |
newOrigin := originNumber / (rangeEnd - rangeStart / 100) - rangeStart.
|
|
959 |
newHeight := heightNumber / (rangeEnd - rangeStart / 100).
|
105
|
960 |
|
|
961 |
(newHeight > 100) ifTrue:[
|
|
962 |
realNewHeight := 100
|
|
963 |
] ifFalse:[
|
|
964 |
realNewHeight := newHeight
|
|
965 |
].
|
|
966 |
((newOrigin + realNewHeight) > 100) ifTrue:[
|
|
967 |
realNewOrigin := 100 - realNewHeight
|
|
968 |
] ifFalse: [
|
|
969 |
realNewOrigin := newOrigin
|
|
970 |
].
|
|
971 |
(realNewOrigin < 0) ifTrue: [
|
|
972 |
realNewOrigin := 0
|
|
973 |
].
|
38
|
974 |
|
105
|
975 |
changed := (realNewHeight ~= thumbHeight) or:[realNewOrigin ~= thumbOrigin].
|
|
976 |
(changed or:[thumbFrame isNil]) ifTrue:[
|
|
977 |
old := self absFromPercent:thumbOrigin.
|
|
978 |
new := self absFromPercent:realNewOrigin.
|
|
979 |
changed := old ~~ new.
|
|
980 |
changed ifFalse:[
|
|
981 |
old := self absFromPercent:thumbHeight.
|
|
982 |
new := self absFromPercent:realNewHeight.
|
|
983 |
changed := (old ~~ new)
|
|
984 |
].
|
|
985 |
(changed or:[thumbFrame isNil]) ifTrue:[
|
|
986 |
thumbOrigin := realNewOrigin.
|
|
987 |
thumbHeight := realNewHeight.
|
|
988 |
shown ifTrue:[
|
|
989 |
thumbFrame notNil ifTrue:[
|
|
990 |
self drawThumbBackgroundInX:(thumbFrame left)
|
|
991 |
y:(thumbFrame top)
|
|
992 |
width:(thumbFrame width)
|
|
993 |
height:(thumbFrame height).
|
|
994 |
].
|
|
995 |
self computeThumbFrame.
|
|
996 |
self drawThumb
|
|
997 |
] ifFalse:[
|
|
998 |
thumbFrame := nil
|
|
999 |
]
|
|
1000 |
]
|
|
1001 |
]
|
|
1002 |
!
|
|
1003 |
|
119
|
1004 |
is3D
|
|
1005 |
StyleSheet name = #mswindows ifTrue:[^ true].
|
|
1006 |
^ super is3D
|
|
1007 |
!
|
|
1008 |
|
105
|
1009 |
setThumbOriginFor:aView
|
|
1010 |
"get contents and size info from aView and adjust thumb origin"
|
|
1011 |
|
|
1012 |
|percent total contentsPosition|
|
|
1013 |
|
119
|
1014 |
(orientation == #vertical) ifTrue:[
|
105
|
1015 |
total := aView heightOfContents.
|
|
1016 |
aView transformation notNil ifTrue:[
|
|
1017 |
total := aView transformation applyScaleY:total.
|
|
1018 |
].
|
|
1019 |
] ifFalse:[
|
|
1020 |
total := aView widthOfContents.
|
|
1021 |
aView transformation notNil ifTrue:[
|
|
1022 |
total := aView transformation applyScaleX:total.
|
|
1023 |
].
|
|
1024 |
].
|
|
1025 |
(total = 0) ifTrue:[
|
|
1026 |
percent := 100
|
|
1027 |
] ifFalse:[
|
119
|
1028 |
contentsPosition := (orientation == #vertical) ifTrue:[aView yOriginOfContents]
|
105
|
1029 |
ifFalse:[aView xOriginOfContents].
|
|
1030 |
percent := contentsPosition * 100.0 / total
|
|
1031 |
].
|
|
1032 |
self thumbOrigin:percent
|
|
1033 |
!
|
|
1034 |
|
119
|
1035 |
thumbOrigin
|
|
1036 |
"answer the thumbs origin (in percent by default)"
|
|
1037 |
|
|
1038 |
^ thumbOrigin * (rangeEnd - rangeStart) / 100 + rangeStart
|
|
1039 |
!
|
|
1040 |
|
|
1041 |
scrollAction:aBlock
|
|
1042 |
"set the scroll action, aBlock which is evaluated when scrolled"
|
|
1043 |
|
|
1044 |
scrollAction := aBlock
|
|
1045 |
!
|
|
1046 |
|
|
1047 |
setThumbFor:aView
|
|
1048 |
"get contents and size info from aView and adjust thumb"
|
|
1049 |
|
|
1050 |
|percentSize percentOrigin contentsSize contentsPosition viewsSize|
|
|
1051 |
|
|
1052 |
"
|
|
1053 |
get the content's size
|
|
1054 |
"
|
|
1055 |
aView isNil ifTrue:[
|
|
1056 |
contentsSize := 0
|
|
1057 |
] ifFalse:[
|
|
1058 |
orientation == #vertical ifTrue:[
|
|
1059 |
contentsSize := aView heightOfContents.
|
|
1060 |
aView transformation notNil ifTrue:[
|
|
1061 |
contentsSize := aView transformation applyScaleY:contentsSize.
|
|
1062 |
].
|
|
1063 |
] ifFalse:[
|
|
1064 |
contentsSize := aView widthOfContents.
|
|
1065 |
aView transformation notNil ifTrue:[
|
|
1066 |
contentsSize := aView transformation applyScaleX:contentsSize.
|
|
1067 |
].
|
|
1068 |
]
|
|
1069 |
].
|
|
1070 |
|
|
1071 |
(contentsSize = 0) ifTrue:[
|
|
1072 |
percentSize := 100.
|
|
1073 |
percentOrigin := 100
|
|
1074 |
] ifFalse:[
|
|
1075 |
(orientation == #vertical) ifTrue:[
|
|
1076 |
viewsSize := aView innerHeight.
|
|
1077 |
contentsPosition := aView yOriginOfContents.
|
|
1078 |
] ifFalse:[
|
|
1079 |
viewsSize := aView innerWidth.
|
|
1080 |
contentsPosition := aView xOriginOfContents
|
|
1081 |
].
|
|
1082 |
|
|
1083 |
percentSize := viewsSize * 100.0 / contentsSize.
|
|
1084 |
percentOrigin := contentsPosition * 100.0 / contentsSize.
|
|
1085 |
percentOrigin + percentSize > 100.0 ifTrue:[
|
|
1086 |
"actually showing stuff below contents of view"
|
|
1087 |
"
|
|
1088 |
contentsSize := contentsPosition + aView innerHeight.
|
|
1089 |
percentSize := viewsSize * 100.0 / contentsSize.
|
|
1090 |
percentOrigin := contentsPosition * 100.0 / contentsSize
|
|
1091 |
"
|
|
1092 |
]
|
|
1093 |
].
|
|
1094 |
(percentSize = thumbHeight) ifTrue:[
|
|
1095 |
self thumbOrigin:percentOrigin
|
|
1096 |
] ifFalse:[
|
|
1097 |
(percentOrigin = thumbOrigin) ifTrue:[
|
|
1098 |
self thumbHeight:percentSize
|
|
1099 |
] ifFalse:[
|
|
1100 |
self thumbOrigin:percentOrigin thumbHeight:percentSize
|
|
1101 |
]
|
|
1102 |
]
|
|
1103 |
!
|
|
1104 |
|
117
|
1105 |
setThumbHeightFor:aView
|
|
1106 |
"get contents and size info from aView and adjust thumb height"
|
|
1107 |
|
|
1108 |
|percent total viewsSize|
|
|
1109 |
|
119
|
1110 |
(orientation == #vertical) ifTrue:[
|
117
|
1111 |
total := aView heightOfContents.
|
|
1112 |
aView transformation notNil ifTrue:[
|
|
1113 |
total := aView transformation applyScaleY:total.
|
|
1114 |
].
|
|
1115 |
] ifFalse:[
|
|
1116 |
total := aView widthOfContents.
|
|
1117 |
aView transformation notNil ifTrue:[
|
|
1118 |
total := aView transformation applyScaleX:total.
|
|
1119 |
].
|
|
1120 |
].
|
|
1121 |
(total = 0) ifTrue:[
|
|
1122 |
percent := 100
|
|
1123 |
] ifFalse:[
|
119
|
1124 |
viewsSize := (orientation == #vertical) ifTrue:[aView innerHeight]
|
117
|
1125 |
ifFalse:[aView innerWidth].
|
|
1126 |
percent := viewsSize * 100.0 / total
|
|
1127 |
].
|
|
1128 |
self thumbHeight:percent
|
|
1129 |
!
|
|
1130 |
|
|
1131 |
action:aBlock
|
|
1132 |
"for protocol compatibility; same as scrollAction:"
|
|
1133 |
|
|
1134 |
self scrollAction:aBlock
|
|
1135 |
!
|
|
1136 |
|
105
|
1137 |
asynchronousOperation
|
|
1138 |
"set scroll-mode to be asynchronous - scroll action is performed after
|
|
1139 |
scrolling, when mouse-button is finally released"
|
|
1140 |
|
|
1141 |
synchronousOperation := false
|
|
1142 |
!
|
|
1143 |
|
|
1144 |
synchronousOperation
|
|
1145 |
"set scroll-mode to be synchronous - scroll action is performed for
|
|
1146 |
every movement of thumb"
|
|
1147 |
|
|
1148 |
synchronousOperation := true
|
|
1149 |
!
|
|
1150 |
|
|
1151 |
scrollAction
|
|
1152 |
"answer the scroll action block"
|
|
1153 |
|
|
1154 |
^ scrollAction
|
|
1155 |
!
|
|
1156 |
|
|
1157 |
scrollDownAction:aBlock
|
|
1158 |
"ignored -
|
|
1159 |
but implemented, so that scroller can be used in place of a scrollbar"
|
|
1160 |
!
|
|
1161 |
|
|
1162 |
scrollUpAction:aBlock
|
|
1163 |
"ignored -
|
|
1164 |
but implemented, so that scroller can be used in place of a scrollbar"
|
|
1165 |
!
|
|
1166 |
|
|
1167 |
thumbHeight
|
119
|
1168 |
"answer the thumbs height (in percent by default)"
|
105
|
1169 |
|
117
|
1170 |
^ thumbHeight * (rangeEnd - rangeStart) / 100
|
105
|
1171 |
!
|
|
1172 |
|
|
1173 |
thumbColor:aColor
|
|
1174 |
"change the color of the thumb"
|
|
1175 |
|
|
1176 |
thumbColor := aColor on:device.
|
|
1177 |
(StyleSheet name ~~ #normal) ifTrue:[
|
|
1178 |
thumbShadowColor := aColor darkened on:device.
|
|
1179 |
thumbLightColor := aColor lightened on:device.
|
|
1180 |
thumbHalfShadowColor := thumbShadowColor darkened on:device.
|
|
1181 |
thumbHalfLightColor := thumbLightColor lightened on:device.
|
|
1182 |
].
|
|
1183 |
shown ifTrue:[
|
|
1184 |
self redraw
|
|
1185 |
]
|
|
1186 |
!
|
|
1187 |
|
|
1188 |
thumbColor
|
|
1189 |
"return the thumbs color"
|
|
1190 |
|
|
1191 |
^ thumbColor
|
|
1192 |
!
|
|
1193 |
|
|
1194 |
thumbFrame
|
|
1195 |
"return the area used by the thumbFrame (in device coordinates).
|
|
1196 |
Allows access to the thumbs physical screen position, for
|
|
1197 |
example to position a label below (see Slider-Examples)"
|
|
1198 |
|
|
1199 |
thumbFrame isNil ifTrue:[ self computeThumbFrame].
|
|
1200 |
^ thumbFrame
|
|
1201 |
!
|
|
1202 |
|
119
|
1203 |
start:start stop:stop
|
|
1204 |
rangeStart := start.
|
|
1205 |
rangeEnd := stop
|
105
|
1206 |
! !
|
|
1207 |
|
|
1208 |
!Scroller methodsFor:'initialization'!
|
|
1209 |
|
119
|
1210 |
initCursor
|
|
1211 |
"set the cursor - a hand"
|
105
|
1212 |
|
119
|
1213 |
cursor := Cursor hand
|
105
|
1214 |
!
|
|
1215 |
|
|
1216 |
initStyle
|
|
1217 |
"initialize style dep. stuff"
|
|
1218 |
|
|
1219 |
super initStyle.
|
|
1220 |
|
|
1221 |
DefaultViewBackground notNil ifTrue:[
|
|
1222 |
viewBackground := DefaultViewBackground on:device.
|
|
1223 |
].
|
|
1224 |
DefaultShadowColor notNil ifTrue:[
|
|
1225 |
shadowColor := DefaultShadowColor on:device.
|
|
1226 |
].
|
|
1227 |
DefaultLightColor notNil ifTrue:[
|
|
1228 |
lightColor := DefaultLightColor on:device.
|
|
1229 |
].
|
|
1230 |
|
|
1231 |
tallyMarks := DefaultTallyMarks.
|
|
1232 |
tallyLevel := DefaultTallyLevel.
|
|
1233 |
DefaultLevel ~~ level ifTrue:[
|
|
1234 |
self level:DefaultLevel.
|
|
1235 |
].
|
|
1236 |
DefaultBorderWidth ~~ borderWidth ifTrue:[
|
|
1237 |
self borderWidth:DefaultBorderWidth.
|
86
|
1238 |
].
|
105
|
1239 |
thumbLevel := DefaultThumbLevel.
|
|
1240 |
inset := DefaultInset.
|
|
1241 |
fixThumbHeight := DefaultFixThumbHeight.
|
|
1242 |
thumbEdgeStyle := DefaultEdgeStyle.
|
|
1243 |
|
|
1244 |
DefaultGhostColor notNil ifTrue:[
|
|
1245 |
ghostColor := DefaultGhostColor on:device.
|
|
1246 |
].
|
|
1247 |
DefaultGhostFrameColor notNil ifTrue:[
|
|
1248 |
ghostFrameColor := DefaultGhostFrameColor on:device.
|
|
1249 |
].
|
|
1250 |
ghostLevel := DefaultGhostLevel.
|
|
1251 |
|
|
1252 |
DefaultThumbFrameColor notNil ifTrue:[
|
|
1253 |
thumbFrameColor := DefaultThumbFrameColor on:device.
|
|
1254 |
].
|
|
1255 |
DefaultThumbShadowColor notNil ifTrue:[
|
|
1256 |
thumbShadowColor := DefaultThumbShadowColor
|
|
1257 |
] ifFalse:[
|
|
1258 |
thumbShadowColor := shadowColor.
|
|
1259 |
].
|
|
1260 |
DefaultThumbLightColor notNil ifTrue:[
|
|
1261 |
thumbLightColor := DefaultThumbLightColor
|
|
1262 |
] ifFalse:[
|
|
1263 |
thumbLightColor := lightColor.
|
|
1264 |
].
|
|
1265 |
|
|
1266 |
thumbEdgeStyle notNil ifTrue:[
|
|
1267 |
DefaultThumbHalfShadowColor notNil ifTrue:[
|
|
1268 |
thumbHalfShadowColor := DefaultThumbHalfShadowColor
|
|
1269 |
].
|
|
1270 |
DefaultThumbHalfLightColor notNil ifTrue:[
|
|
1271 |
thumbHalfLightColor := DefaultThumbHalfLightColor
|
|
1272 |
].
|
|
1273 |
].
|
|
1274 |
|
|
1275 |
device hasGreyscales ifFalse:[
|
|
1276 |
thumbEdgeStyle notNil ifTrue:[
|
|
1277 |
thumbHalfShadowColor := Color darkGrey.
|
|
1278 |
thumbHalfLightColor := White
|
|
1279 |
].
|
|
1280 |
|
|
1281 |
thumbShadowColor := Black.
|
|
1282 |
"/ thumbLightColor := White.
|
|
1283 |
|
|
1284 |
StyleSheet name = #motif ifTrue:[
|
|
1285 |
DefaultThumbColor isNil ifTrue:[
|
|
1286 |
thumbColor := White .
|
|
1287 |
].
|
|
1288 |
]
|
|
1289 |
].
|
|
1290 |
|
|
1291 |
DefaultThumbColor notNil ifTrue:[
|
|
1292 |
thumbColor := DefaultThumbColor on:device
|
|
1293 |
] ifFalse:[
|
|
1294 |
thumbColor := White.
|
|
1295 |
StyleSheet name ~= #normal ifTrue:[
|
|
1296 |
device hasGreyscales ifFalse:[
|
|
1297 |
thumbColor := Color grey
|
|
1298 |
].
|
|
1299 |
].
|
|
1300 |
].
|
|
1301 |
|
|
1302 |
thumbColor := thumbColor on:device.
|
|
1303 |
thumbShadowColor notNil ifTrue:[
|
|
1304 |
thumbShadowColor := thumbShadowColor on:device.
|
|
1305 |
].
|
|
1306 |
thumbLightColor notNil ifTrue:[
|
|
1307 |
thumbLightColor := thumbLightColor on:device.
|
|
1308 |
].
|
|
1309 |
thumbHalfShadowColor notNil ifTrue:[
|
|
1310 |
thumbHalfShadowColor := thumbHalfShadowColor on:device.
|
|
1311 |
].
|
|
1312 |
thumbHalfLightColor notNil ifTrue:[
|
|
1313 |
thumbHalfLightColor := thumbHalfLightColor on:device.
|
|
1314 |
].
|
|
1315 |
thumbEdgeStyle notNil ifTrue:[
|
|
1316 |
thumbHalfShadowColor isNil ifTrue:[
|
|
1317 |
thumbHalfShadowColor := thumbShadowColor lightened on:device
|
|
1318 |
]
|
|
1319 |
].
|
|
1320 |
|
|
1321 |
StyleSheet name = #next ifTrue:[
|
|
1322 |
shadowForm := self class handleShadowFormOn:device.
|
|
1323 |
lightForm := self class handleLightFormOn:device
|
|
1324 |
] ifFalse:[
|
|
1325 |
shadowForm := lightForm := nil
|
|
1326 |
].
|
|
1327 |
|
|
1328 |
drawableId notNil ifTrue:[
|
|
1329 |
self computeThumbFrame
|
|
1330 |
]
|
|
1331 |
!
|
|
1332 |
|
|
1333 |
computeInitialExtent
|
|
1334 |
^ self
|
|
1335 |
!
|
|
1336 |
|
119
|
1337 |
initialize
|
|
1338 |
"initialize - setup instvars from defaults"
|
0
|
1339 |
|
119
|
1340 |
super initialize.
|
|
1341 |
self computeInitialExtent.
|
|
1342 |
orientation := #vertical.
|
0
|
1343 |
|
119
|
1344 |
scrolling := false.
|
|
1345 |
synchronousOperation := true.
|
0
|
1346 |
|
119
|
1347 |
thumbOrigin := 0.
|
|
1348 |
thumbHeight := 100.
|
|
1349 |
thumbFrameSizeDifference := 0.
|
0
|
1350 |
|
119
|
1351 |
rangeStart := 0.
|
|
1352 |
rangeEnd := 100.
|
|
1353 |
rangeStep := nil. "/ meaning: arbitrary precision
|
|
1354 |
"/ inset := 1.
|
105
|
1355 |
|
119
|
1356 |
"/ self computeThumbFrame
|
105
|
1357 |
! !
|
|
1358 |
|
|
1359 |
!Scroller methodsFor:'forwarding changed origin'!
|
63
|
1360 |
|
105
|
1361 |
tellOthers
|
117
|
1362 |
|org|
|
|
1363 |
|
|
1364 |
org := self thumbOrigin.
|
105
|
1365 |
"
|
|
1366 |
the ST/X way of notifying scrolls
|
|
1367 |
"
|
|
1368 |
scrollAction notNil ifTrue:[
|
117
|
1369 |
scrollAction value:org
|
105
|
1370 |
].
|
|
1371 |
"
|
|
1372 |
the ST-80 way of notifying scrolls
|
|
1373 |
"
|
117
|
1374 |
self sendChangeMessageWith:org.
|
105
|
1375 |
self changed:#scrollerPosition.
|
0
|
1376 |
! !
|
105
|
1377 |
|
|
1378 |
!Scroller methodsFor:'forced scroll'!
|
|
1379 |
|
119
|
1380 |
pageDown
|
|
1381 |
"page down/right"
|
|
1382 |
|
|
1383 |
self thumbOrigin:(thumbOrigin + thumbHeight).
|
|
1384 |
self tellOthers
|
|
1385 |
!
|
|
1386 |
|
105
|
1387 |
pageUp
|
|
1388 |
"page up/left"
|
|
1389 |
|
|
1390 |
self thumbOrigin:(thumbOrigin - thumbHeight).
|
|
1391 |
self tellOthers
|
|
1392 |
! !
|