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