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 |
|
110
|
13 |
'From Smalltalk/X, Version:2.10.5 on 25-mar-1995 at 1:10:33 am'!
|
|
14 |
|
0
|
15 |
View subclass:#ScrollBar
|
110
|
16 |
instanceVariableNames:'thumb button1 button2 layout elementSpacing'
|
|
17 |
classVariableNames:'DefaultButtonPositions DefaultLevel DefaultElementSpacing
|
|
18 |
DefaultScrollerBordered'
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Views-Interactors'
|
0
|
21 |
!
|
|
22 |
|
|
23 |
ScrollBar comment:'
|
5
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
25 |
All Rights Reserved
|
0
|
26 |
|
110
|
27 |
$Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.11 1995-03-25 22:21:15 claus Exp $
|
0
|
28 |
'!
|
|
29 |
|
38
|
30 |
!ScrollBar class methodsFor:'documentation'!
|
0
|
31 |
|
38
|
32 |
copyright
|
|
33 |
"
|
|
34 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
35 |
All Rights Reserved
|
0
|
36 |
|
38
|
37 |
This software is furnished under a license and may be used
|
|
38 |
only in accordance with the terms of that license and with the
|
|
39 |
inclusion of the above copyright notice. This software may not
|
|
40 |
be provided or otherwise made available to, or used by, any
|
|
41 |
other person. No title to or ownership of the software is
|
|
42 |
hereby transferred.
|
|
43 |
"
|
|
44 |
!
|
|
45 |
|
|
46 |
version
|
|
47 |
"
|
110
|
48 |
$Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.11 1995-03-25 22:21:15 claus Exp $
|
38
|
49 |
"
|
0
|
50 |
!
|
|
51 |
|
38
|
52 |
documentation
|
|
53 |
"
|
|
54 |
this class implements vertical scrollbars with scroller and
|
|
55 |
2 step-scroll buttons. when moved or stepped, it performs a
|
|
56 |
predefined action.
|
|
57 |
|
|
58 |
The action is specified by: the block to be evaluated for step-up
|
59
|
59 |
aScrollBar scrollUpAction:aBlock
|
|
60 |
(scrollLeftAction for hor-Scrollbars)
|
0
|
61 |
|
59
|
62 |
aScrollBar scrollDownAction:aBlock the block to be evaluated for step-down
|
|
63 |
(scrollRightAction for hor-Scrollbars)
|
38
|
64 |
|
59
|
65 |
aScrollbar scrollAction:aBlock the block to be evaluated for scroll
|
|
66 |
passing percentage as argument.
|
38
|
67 |
|
|
68 |
Scrollbars can scroll syncronous (i.e. every movement is notified immediately via the
|
|
69 |
scrollAction) or asynchronous (i.e. only one notification takes place at the end of the movement).
|
|
70 |
The choice is up to the user of the scrollbar (typically, views which are complicated to redraw,
|
|
71 |
will set it to asynchronous.)
|
|
72 |
|
|
73 |
Most often scrollbars are used hidden with ScrollableView or HVScrollableView (i.e. you
|
|
74 |
dont have to care for all the details).
|
|
75 |
"
|
0
|
76 |
! !
|
|
77 |
|
|
78 |
!ScrollBar class methodsFor:'style changes'!
|
|
79 |
|
59
|
80 |
updateStyleCache
|
|
81 |
DefaultButtonPositions := StyleSheet at:'scrollBarButtonPositions' default:#bottom.
|
|
82 |
DefaultLevel := StyleSheet at:'scrollBarLevel'.
|
|
83 |
DefaultScrollerBordered := StyleSheet at:'scrollBarScrollerBordered' default:false.
|
|
84 |
DefaultElementSpacing := StyleSheet at:'scrollBarElementSpacing'
|
|
85 |
default:(StyleSheet is3D ifTrue:[1] ifFalse:[0]).
|
0
|
86 |
! !
|
|
87 |
|
|
88 |
!ScrollBar methodsFor:'initialization'!
|
|
89 |
|
38
|
90 |
setElementPositions
|
|
91 |
"position sub-components"
|
|
92 |
|
59
|
93 |
|bwn|
|
38
|
94 |
|
|
95 |
bwn := borderWidth negated + margin.
|
|
96 |
|
|
97 |
(layout == #top) ifTrue:[
|
59
|
98 |
button1 origin:(bwn @ bwn).
|
|
99 |
button1 viewGravity:#North.
|
|
100 |
button2 origin:(bwn @ (button1 height)).
|
|
101 |
button2 viewGravity:#North.
|
|
102 |
thumb origin:(bwn @ (button1 height
|
|
103 |
+ borderWidth
|
|
104 |
+ button2 height
|
|
105 |
+ elementSpacing
|
|
106 |
+ elementSpacing)).
|
|
107 |
thumb viewGravity:#North.
|
|
108 |
^ self
|
38
|
109 |
].
|
|
110 |
(layout == #bottom) ifTrue:[
|
63
|
111 |
device supportsViewGravity ifTrue:[
|
|
112 |
button1 viewGravity:#South.
|
|
113 |
button2 viewGravity:#South.
|
|
114 |
thumb viewGravity:#North.
|
|
115 |
].
|
59
|
116 |
thumb origin:(bwn @ bwn).
|
|
117 |
^ self
|
38
|
118 |
].
|
|
119 |
|
|
120 |
"layout == #around"
|
|
121 |
button1 origin:(bwn @ bwn).
|
|
122 |
button1 viewGravity:#North.
|
63
|
123 |
"/ button2 viewGravity:#North.
|
59
|
124 |
thumb origin:(bwn @ (button1 height + elementSpacing)).
|
38
|
125 |
thumb viewGravity:#North
|
|
126 |
!
|
|
127 |
|
110
|
128 |
createElements
|
|
129 |
button1 := ArrowButton upIn:self.
|
|
130 |
button2 := ArrowButton downIn:self.
|
|
131 |
thumb := Scroller in:self.
|
|
132 |
!
|
|
133 |
|
|
134 |
initStyle
|
|
135 |
super initStyle.
|
|
136 |
|
|
137 |
layout := DefaultButtonPositions.
|
|
138 |
DefaultLevel notNil ifTrue:[
|
|
139 |
self level:DefaultLevel
|
|
140 |
].
|
|
141 |
elementSpacing := DefaultElementSpacing
|
|
142 |
!
|
|
143 |
|
38
|
144 |
computeInitialExtent
|
|
145 |
"compute my extent from sub-components"
|
|
146 |
|
|
147 |
|w h upForm downForm
|
|
148 |
upHeight "{ Class: SmallInteger }"
|
|
149 |
downHeight "{ Class: SmallInteger }"
|
110
|
150 |
upWidth downWidth style|
|
38
|
151 |
|
|
152 |
"need fix - this is a kludge;
|
|
153 |
the if should not be needed ..."
|
110
|
154 |
style := StyleSheet name.
|
|
155 |
style == #mswindows ifTrue:[
|
|
156 |
w := button1 width max:button2 width.
|
|
157 |
h := button1 height + button2 height + (Scroller defaultExtent y).
|
38
|
158 |
] ifFalse:[
|
110
|
159 |
upForm := ArrowButton upArrowButtonForm:style on:device.
|
|
160 |
downForm := ArrowButton downArrowButtonForm:style on:device.
|
|
161 |
upForm isNil ifTrue:[
|
|
162 |
upHeight := upWidth := 16.
|
|
163 |
] ifFalse:[
|
|
164 |
upHeight := upForm height.
|
|
165 |
upWidth := upForm width
|
|
166 |
].
|
|
167 |
downForm isNil ifTrue:[
|
|
168 |
downHeight := downWidth := 16
|
|
169 |
] ifFalse:[
|
|
170 |
downHeight := downForm height.
|
|
171 |
downWidth := downForm width
|
|
172 |
].
|
|
173 |
h := upHeight + downHeight + (1 * 2) + (Scroller defaultExtent y).
|
|
174 |
w := upWidth max:downWidth.
|
|
175 |
style ~~ #normal ifTrue:[
|
|
176 |
h := h + 4.
|
|
177 |
w := w + 4
|
|
178 |
].
|
38
|
179 |
].
|
|
180 |
|
|
181 |
self extent:w @ h.
|
110
|
182 |
!
|
|
183 |
|
|
184 |
initialize
|
|
185 |
"setup; create the 2 buttons and a scroller"
|
|
186 |
|
|
187 |
|clr style|
|
|
188 |
|
|
189 |
super initialize.
|
|
190 |
|
|
191 |
self createElements.
|
|
192 |
|
|
193 |
button1 autoRepeat.
|
|
194 |
button2 autoRepeat.
|
|
195 |
|
|
196 |
self computeInitialExtent.
|
|
197 |
|
|
198 |
button1 borderWidth:borderWidth.
|
|
199 |
DefaultScrollerBordered ifFalse:[
|
|
200 |
thumb borderWidth:borderWidth.
|
|
201 |
].
|
|
202 |
button2 borderWidth:borderWidth.
|
|
203 |
|
|
204 |
style := StyleSheet name.
|
|
205 |
((style = #iris) and:[Display hasGreyscales]) ifTrue:[
|
|
206 |
"have to change some of Buttons defaults"
|
|
207 |
clr := (Color grey:25) on:device.
|
|
208 |
button1 offLevel:2.
|
|
209 |
button2 offLevel:2.
|
|
210 |
button1 foregroundColor:clr.
|
|
211 |
button1 activeForegroundColor:clr.
|
|
212 |
button1 enteredForegroundColor:clr.
|
|
213 |
button2 foregroundColor:clr.
|
|
214 |
button2 activeForegroundColor:clr.
|
|
215 |
button2 enteredForegroundColor:clr.
|
|
216 |
].
|
|
217 |
|
|
218 |
self setElementPositions.
|
|
219 |
|
|
220 |
style = #motif ifTrue:[
|
|
221 |
clr := thumb thumbColor.
|
|
222 |
button1 foregroundColor:clr.
|
|
223 |
button2 foregroundColor:clr.
|
|
224 |
|
|
225 |
clr := thumb viewBackground.
|
|
226 |
button1 viewBackground:clr.
|
|
227 |
button2 viewBackground:clr.
|
|
228 |
button1 backgroundColor:clr.
|
|
229 |
button2 backgroundColor:clr.
|
|
230 |
button1 activeBackgroundColor:clr.
|
|
231 |
button2 activeBackgroundColor:clr.
|
|
232 |
device hasGreyscales ifFalse:[
|
|
233 |
button1 activeForegroundColor:Black.
|
|
234 |
button2 activeForegroundColor:Black.
|
|
235 |
]
|
|
236 |
]
|
|
237 |
!
|
|
238 |
|
|
239 |
reinitialize
|
|
240 |
super reinitialize.
|
|
241 |
self setElementPositions.
|
0
|
242 |
! !
|
|
243 |
|
|
244 |
!ScrollBar methodsFor:'accessing'!
|
|
245 |
|
110
|
246 |
setThumbFor:aView
|
|
247 |
"adjust thumb for aView"
|
|
248 |
|
|
249 |
thumb setThumbFor:aView
|
|
250 |
!
|
|
251 |
|
|
252 |
setThumbOriginFor:aView
|
|
253 |
"adjust thumbs origin for aView"
|
|
254 |
|
|
255 |
thumb setThumbOriginFor:aView
|
|
256 |
!
|
|
257 |
|
|
258 |
thumbOrigin:newOrigin thumbHeight:newHeight
|
|
259 |
"set origin and height of thumb in percent"
|
|
260 |
|
|
261 |
^ thumb thumbOrigin:newOrigin thumbHeight:newHeight
|
|
262 |
!
|
|
263 |
|
0
|
264 |
scrollAction:aBlock
|
|
265 |
"set the action, aBlock to be performed when the scroller is moved"
|
|
266 |
|
|
267 |
thumb scrollAction:aBlock
|
|
268 |
!
|
|
269 |
|
|
270 |
scrollUpAction:aBlock
|
|
271 |
"set the action, aBlock to be performed when the up-button is pressed"
|
|
272 |
|
|
273 |
button1 action:aBlock
|
|
274 |
!
|
|
275 |
|
|
276 |
scrollDownAction:aBlock
|
|
277 |
"set the action, aBlock to be performed when the down-button is pressed"
|
|
278 |
|
|
279 |
button2 action:aBlock
|
|
280 |
!
|
|
281 |
|
|
282 |
thumbColor:aColor
|
7
|
283 |
"set the thumbs color"
|
|
284 |
|
0
|
285 |
thumb thumbColor:aColor
|
|
286 |
!
|
|
287 |
|
|
288 |
thumbOrigin
|
7
|
289 |
"return position of (top of) thumb in percent"
|
0
|
290 |
|
|
291 |
^ thumb thumbOrigin
|
|
292 |
!
|
|
293 |
|
|
294 |
thumbOrigin:newOrigin
|
|
295 |
"set position of (top of) thumb in percent"
|
|
296 |
|
|
297 |
^ thumb thumbOrigin:newOrigin
|
|
298 |
!
|
|
299 |
|
|
300 |
thumbHeight
|
7
|
301 |
"return height of thumb in percent"
|
0
|
302 |
|
|
303 |
^ thumb thumbHeight
|
|
304 |
!
|
|
305 |
|
|
306 |
thumbHeight:newHeight
|
|
307 |
"set height of thumb in percent"
|
|
308 |
|
|
309 |
^ thumb thumbHeight:newHeight
|
|
310 |
!
|
|
311 |
|
|
312 |
setThumbHeightFor:aView
|
|
313 |
"adjust thumbs height for aView"
|
|
314 |
|
|
315 |
thumb setThumbHeightFor:aView
|
|
316 |
!
|
|
317 |
|
|
318 |
asynchronousOperation
|
|
319 |
"set asynchronous-mode - scroll action is performed after movement
|
|
320 |
of scroller (i.e. when mouse-button is finally released)"
|
|
321 |
|
|
322 |
thumb asynchronousOperation
|
|
323 |
!
|
|
324 |
|
|
325 |
synchronousOperation
|
|
326 |
"set synchronous-mode - scroll action is performed for every movement
|
|
327 |
of scroller"
|
|
328 |
|
|
329 |
thumb synchronousOperation
|
|
330 |
! !
|
|
331 |
|
|
332 |
!ScrollBar methodsFor:'events'!
|
|
333 |
|
|
334 |
sizeChanged:how
|
|
335 |
"when my size changes, I have to resize/reposition the subviews"
|
|
336 |
|
59
|
337 |
|upHeight downHeight thumbHeight upAndDownHeight bwn sep2
|
3
|
338 |
thumbWidth w|
|
0
|
339 |
|
|
340 |
button1 isNil ifTrue:[^ self].
|
|
341 |
thumb isNil ifTrue:[^ self].
|
|
342 |
button2 isNil ifTrue:[^ self].
|
|
343 |
|
|
344 |
upHeight := button1 height + borderWidth.
|
|
345 |
downHeight := button2 height + borderWidth.
|
|
346 |
upAndDownHeight := upHeight + downHeight.
|
3
|
347 |
bwn := borderWidth negated + margin.
|
0
|
348 |
|
59
|
349 |
thumbHeight := height - upAndDownHeight - borderWidth - (elementSpacing * 3).
|
3
|
350 |
"
|
0
|
351 |
((layout ~~ #top) and:[layout ~~ #bottom]) ifTrue:[
|
59
|
352 |
thumbHeight := thumbHeight - borderWidth
|
0
|
353 |
].
|
3
|
354 |
"
|
|
355 |
layout == #around ifTrue:[
|
59
|
356 |
thumbHeight := thumbHeight + borderWidth
|
3
|
357 |
].
|
0
|
358 |
|
|
359 |
"if I become too small, hide buttons and thumb"
|
|
360 |
|
|
361 |
height < (upHeight + downHeight) ifTrue:[
|
59
|
362 |
button1 shown ifTrue:[
|
|
363 |
button1 unrealize.
|
|
364 |
button2 unrealize.
|
|
365 |
thumb unrealize
|
|
366 |
]
|
0
|
367 |
] ifFalse:[
|
59
|
368 |
shown ifTrue:[
|
|
369 |
button1 shown ifFalse:[
|
|
370 |
button1 realize.
|
|
371 |
button2 realize.
|
|
372 |
thumb realize
|
|
373 |
]
|
|
374 |
]
|
0
|
375 |
].
|
|
376 |
|
|
377 |
(thumbHeight < 10) ifTrue:[
|
59
|
378 |
thumb shown ifTrue:[
|
|
379 |
thumb unrealize
|
|
380 |
]
|
0
|
381 |
] ifFalse:[
|
59
|
382 |
thumb shown ifFalse:[
|
|
383 |
button1 shown ifTrue:[
|
|
384 |
thumb realize
|
|
385 |
]
|
|
386 |
]
|
0
|
387 |
].
|
|
388 |
|
|
389 |
"width of buttons is always my width"
|
|
390 |
|
3
|
391 |
w := width - (margin * 2).
|
|
392 |
(w ~~ button1 width) ifTrue:[
|
59
|
393 |
button1 width:w.
|
|
394 |
button2 width:w
|
0
|
395 |
].
|
|
396 |
|
3
|
397 |
thumbWidth := w.
|
77
|
398 |
StyleSheet name == #next ifTrue:[
|
59
|
399 |
thumbWidth := thumbWidth - (thumb borderWidth * 2).
|
|
400 |
thumbHeight := thumbHeight - 1
|
0
|
401 |
].
|
77
|
402 |
StyleSheet name == #motif ifTrue:[
|
63
|
403 |
thumbHeight := thumbHeight - margin
|
|
404 |
].
|
0
|
405 |
|
38
|
406 |
"
|
|
407 |
a kludge: views with width or height of 0 are illegal
|
|
408 |
avoid error from view-creation (it will be hidden anyway)
|
|
409 |
"
|
|
410 |
thumbHeight <= 0 ifTrue:[
|
59
|
411 |
thumbHeight := 1
|
38
|
412 |
].
|
|
413 |
|
0
|
414 |
(layout == #top) ifTrue:[
|
59
|
415 |
"buttons at top"
|
|
416 |
thumb extent:(thumbWidth @ thumbHeight).
|
|
417 |
^ self
|
0
|
418 |
].
|
|
419 |
|
59
|
420 |
sep2 := elementSpacing * 2.
|
0
|
421 |
(layout == #bottom) ifTrue:[
|
59
|
422 |
"buttons at bottom"
|
|
423 |
thumbHeight := thumbHeight + borderWidth.
|
|
424 |
(how == #smaller) ifTrue:[
|
|
425 |
thumb extent:(thumbWidth @ thumbHeight).
|
63
|
426 |
"/ button1 origin:(bwn @ (thumbHeight + sep2)).
|
|
427 |
"/ button2 origin:(bwn @ (thumbHeight + sep2 + upHeight))
|
59
|
428 |
] ifFalse:[
|
|
429 |
button1 origin:(bwn @ (thumbHeight + sep2)).
|
|
430 |
button2 origin:(bwn @ (thumbHeight + sep2 + upHeight)).
|
|
431 |
thumb extent:(thumbWidth @ thumbHeight)
|
|
432 |
].
|
|
433 |
^ self
|
0
|
434 |
].
|
|
435 |
"buttons around thumb"
|
|
436 |
|
77
|
437 |
StyleSheet name == #motif ifTrue:[
|
63
|
438 |
sep2 := sep2 + 1
|
|
439 |
].
|
3
|
440 |
button1 origin:(bwn @ bwn).
|
38
|
441 |
button2 origin:(bwn @ (upHeight + thumbHeight + sep2 - (margin // 2) "+ borderWidth")).
|
|
442 |
thumb extent:(thumbWidth @ (thumbHeight + margin - (margin // 2))).
|
59
|
443 |
thumb origin:(bwn @ (upHeight - borderWidth + elementSpacing))
|
0
|
444 |
! !
|
110
|
445 |
|
|
446 |
!ScrollBar methodsFor:'forced scroll'!
|
|
447 |
|
|
448 |
pageUp
|
|
449 |
"page up/left"
|
|
450 |
|
|
451 |
thumb pageUp
|
|
452 |
!
|
|
453 |
|
|
454 |
pageDown
|
|
455 |
"page down/right"
|
|
456 |
|
|
457 |
thumb pageDown
|
|
458 |
! !
|
|
459 |
|