author | Claus Gittinger <cg@exept.de> |
Fri, 01 Mar 1996 19:44:55 +0100 | |
changeset 447 | ed41e1bbd9a1 |
parent 446 | 98f38de97099 |
child 448 | e23465aad9e8 |
permissions | -rw-r--r-- |
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 |
SimpleView subclass:#ScrollBar |
345 | 14 |
instanceVariableNames:'thumb button1 button2 buttonLayout elementSpacing' |
15 |
classVariableNames:'DefaultButtonPositions DefaultLevel DefaultElementSpacing |
|
16 |
DefaultScrollerBordered' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Interactors' |
|
0 | 19 |
! |
20 |
||
38 | 21 |
!ScrollBar class methodsFor:'documentation'! |
0 | 22 |
|
38 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 26 |
All Rights Reserved |
0 | 27 |
|
38 | 28 |
This software is furnished under a license and may be used |
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
this class implements vertical scrollbars with scroller and |
|
40 |
2 step-scroll buttons. when moved or stepped, it performs a |
|
41 |
predefined action. |
|
42 |
||
43 |
The action is specified by: the block to be evaluated for step-up |
|
59 | 44 |
aScrollBar scrollUpAction:aBlock |
45 |
(scrollLeftAction for hor-Scrollbars) |
|
0 | 46 |
|
59 | 47 |
aScrollBar scrollDownAction:aBlock the block to be evaluated for step-down |
48 |
(scrollRightAction for hor-Scrollbars) |
|
38 | 49 |
|
59 | 50 |
aScrollbar scrollAction:aBlock the block to be evaluated for scroll |
51 |
passing percentage as argument. |
|
38 | 52 |
|
53 |
Scrollbars can scroll syncronous (i.e. every movement is notified immediately via the |
|
54 |
scrollAction) or asynchronous (i.e. only one notification takes place at the end of the movement). |
|
55 |
The choice is up to the user of the scrollbar (typically, views which are complicated to redraw, |
|
56 |
will set it to asynchronous.) |
|
57 |
||
58 |
Most often scrollbars are used hidden with ScrollableView or HVScrollableView (i.e. you |
|
59 |
dont have to care for all the details). |
|
128 | 60 |
|
61 |
The scrollBars and scrollers protocols have been made similar enough to |
|
62 |
allow transparent use of either a scroller or a scrollBar in applications. |
|
38 | 63 |
" |
0 | 64 |
! ! |
65 |
||
66 |
!ScrollBar class methodsFor:'style changes'! |
|
67 |
||
59 | 68 |
updateStyleCache |
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
69 |
"extract values from the styleSheet and cache them in class variables" |
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
70 |
|
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
71 |
<resource: #style (#scrollBarButtonPositions #scrollBarLevel |
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
72 |
#scrollBarScrollerBordered #scrollBarElementSpacing)> |
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
73 |
|
59 | 74 |
DefaultButtonPositions := StyleSheet at:'scrollBarButtonPositions' default:#bottom. |
75 |
DefaultLevel := StyleSheet at:'scrollBarLevel'. |
|
76 |
DefaultScrollerBordered := StyleSheet at:'scrollBarScrollerBordered' default:false. |
|
77 |
DefaultElementSpacing := StyleSheet at:'scrollBarElementSpacing' |
|
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
78 |
default:(StyleSheet is3D ifTrue:[1] ifFalse:[0]). |
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
79 |
|
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
345
diff
changeset
|
80 |
"Modified: 1.3.1996 / 13:46:29 / cg" |
0 | 81 |
! ! |
82 |
||
205 | 83 |
!ScrollBar methodsFor:'accessing'! |
0 | 84 |
|
205 | 85 |
thumbColor:aColor |
86 |
"set the thumbs color" |
|
128 | 87 |
|
205 | 88 |
thumb thumbColor:aColor |
0 | 89 |
! |
90 |
||
205 | 91 |
thumbHeight |
92 |
"return height of thumb in percent" |
|
128 | 93 |
|
205 | 94 |
^ thumb thumbHeight |
0 | 95 |
! |
96 |
||
205 | 97 |
thumbHeight:newHeight |
98 |
"set height of thumb in percent" |
|
128 | 99 |
|
205 | 100 |
thumb thumbHeight:newHeight. |
101 |
self enableDisableButtons |
|
102 |
! |
|
103 |
||
104 |
thumbOrigin |
|
105 |
"return position of (top of) thumb in percent" |
|
106 |
||
107 |
^ thumb thumbOrigin |
|
128 | 108 |
! |
109 |
||
205 | 110 |
thumbOrigin:newOrigin |
111 |
"set position of (top of) thumb in percent" |
|
112 |
||
113 |
thumb thumbOrigin:newOrigin. |
|
114 |
self enableDisableButtons |
|
115 |
! |
|
128 | 116 |
|
205 | 117 |
thumbOrigin:newOrigin thumbHeight:newHeight |
118 |
"set origin and height of thumb (both in percent)" |
|
128 | 119 |
|
205 | 120 |
thumb thumbOrigin:newOrigin thumbHeight:newHeight. |
121 |
self enableDisableButtons |
|
122 |
! |
|
128 | 123 |
|
133 | 124 |
upButtonLabel:label1 downButtonLabel:label2 |
446 | 125 |
"set the labels shown in the buttons. |
126 |
Because of the fixed button sizes, this only makes sense with |
|
127 |
single-character strings or small bitmaps." |
|
133 | 128 |
|
129 |
button1 label:label1. |
|
130 |
button2 label:label2. |
|
131 |
self setElementPositions. |
|
132 |
||
446 | 133 |
"not bad: |
133 | 134 |
|v| |
135 |
||
136 |
v := ScrollableView for:EditTextView. |
|
137 |
v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile). |
|
138 |
v scrollBar upButtonLabel:'+' downButtonLabel:'-'. |
|
139 |
v open |
|
140 |
" |
|
446 | 141 |
|
142 |
"also possible : |
|
143 |
|v| |
|
144 |
||
145 |
v := ScrollableView for:EditTextView. |
|
146 |
v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile). |
|
147 |
v scrollBar upButtonLabel:'u' downButtonLabel:'d'. |
|
148 |
v open |
|
149 |
" |
|
150 |
||
151 |
"BAD example: |
|
152 |
|v| |
|
153 |
||
154 |
v := ScrollableView for:EditTextView. |
|
155 |
v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile). |
|
156 |
v scrollBar upButtonLabel:'up' downButtonLabel:'down'. |
|
157 |
v open |
|
158 |
" |
|
159 |
||
160 |
"Modified: 1.3.1996 / 19:06:50 / cg" |
|
205 | 161 |
! ! |
162 |
||
163 |
!ScrollBar methodsFor:'accessing-behavior'! |
|
133 | 164 |
|
205 | 165 |
asynchronousOperation |
166 |
"set asynchronous-mode - scroll action is performed after movement |
|
167 |
of scroller (i.e. when mouse-button is finally released). |
|
128 | 168 |
This is forwarded to the scroller here." |
169 |
||
205 | 170 |
thumb asynchronousOperation |
128 | 171 |
! |
172 |
||
205 | 173 |
scrollAction:aBlock |
174 |
"set the action, aBlock to be performed when the scroller is moved. |
|
128 | 175 |
This is forwarded to the scroller here." |
176 |
||
205 | 177 |
thumb scrollAction:aBlock |
128 | 178 |
! |
179 |
||
205 | 180 |
scrollDownAction:aBlock |
181 |
"set the action, aBlock to be performed when the down-button is pressed." |
|
128 | 182 |
|
205 | 183 |
button2 action:aBlock |
128 | 184 |
! |
185 |
||
205 | 186 |
scrollUpAction:aBlock |
187 |
"set the action, aBlock to be performed when the up-button is pressed." |
|
7 | 188 |
|
205 | 189 |
button1 action:aBlock |
0 | 190 |
! |
191 |
||
205 | 192 |
synchronousOperation |
193 |
"set synchronous-mode - scroll action is performed for every movement |
|
194 |
of scroller. |
|
195 |
This is forwarded to the scroller here." |
|
0 | 196 |
|
205 | 197 |
thumb synchronousOperation |
198 |
! ! |
|
0 | 199 |
|
446 | 200 |
!ScrollBar methodsFor:'accessing-components'! |
201 |
||
202 |
downButton |
|
203 |
"return the down-button |
|
204 |
(Please: only use this direct access for special applications)" |
|
205 |
||
206 |
^ button2 |
|
207 |
||
208 |
" |
|
209 |
|v| |
|
210 |
||
211 |
v := ScrollableView for:EditTextView. |
|
212 |
v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile). |
|
213 |
v scrollBar upButton activeForegroundColor:Color red. |
|
214 |
v scrollBar downButton activeForegroundColor:Color red. |
|
215 |
v open |
|
216 |
" |
|
217 |
||
218 |
"Modified: 1.3.1996 / 19:04:43 / cg" |
|
219 |
! |
|
220 |
||
221 |
thumb |
|
222 |
"return the thumb (i.e. the scroller subview) |
|
223 |
(Please: only use this direct access for special applications)" |
|
224 |
||
225 |
^ thumb |
|
226 |
||
227 |
" |
|
228 |
|v| |
|
229 |
||
230 |
v := ScrollableView for:EditTextView. |
|
231 |
v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile). |
|
232 |
v scrollBar thumb thumbColor:(Color red). |
|
233 |
v open |
|
234 |
" |
|
235 |
||
236 |
"Modified: 1.3.1996 / 19:15:50 / cg" |
|
237 |
! |
|
238 |
||
239 |
upButton |
|
240 |
"return the up-button |
|
241 |
(Please: only use this direct access for special applications)" |
|
242 |
||
243 |
^ button1 |
|
244 |
||
245 |
" |
|
246 |
|v| |
|
247 |
||
248 |
v := ScrollableView for:EditTextView. |
|
249 |
v scrolledView contents:('/etc/passwd' asFilename contentsOfEntireFile). |
|
250 |
v scrollBar upButton foregroundColor:(Color red). |
|
251 |
v scrollBar upButton enteredForegroundColor:(Color red lightened). |
|
252 |
v scrollBar downButton foregroundColor:(Color green). |
|
253 |
v scrollBar downButton enteredForegroundColor:(Color green lightened). |
|
254 |
v open |
|
255 |
" |
|
256 |
||
257 |
"Modified: 1.3.1996 / 19:04:48 / cg" |
|
258 |
! ! |
|
259 |
||
205 | 260 |
!ScrollBar methodsFor:'change & update'! |
0 | 261 |
|
205 | 262 |
update:something with:aParameter from:changedObject |
263 |
changedObject == thumb ifTrue:[ |
|
264 |
self enableDisableButtons |
|
265 |
] |
|
0 | 266 |
! ! |
267 |
||
268 |
!ScrollBar methodsFor:'events'! |
|
269 |
||
270 |
sizeChanged:how |
|
128 | 271 |
"when my size changes, I have to resize/reposition the subviews. |
272 |
Also, if I became too small, hide thumb/buttons." |
|
0 | 273 |
|
59 | 274 |
|upHeight downHeight thumbHeight upAndDownHeight bwn sep2 |
130 | 275 |
thumbWidth w style b1Hidden b2Hidden thumbHidden bY| |
0 | 276 |
|
277 |
button1 isNil ifTrue:[^ self]. |
|
278 |
thumb isNil ifTrue:[^ self]. |
|
279 |
button2 isNil ifTrue:[^ self]. |
|
280 |
||
130 | 281 |
style := styleSheet name. |
128 | 282 |
|
0 | 283 |
upHeight := button1 height + borderWidth. |
284 |
downHeight := button2 height + borderWidth. |
|
285 |
upAndDownHeight := upHeight + downHeight. |
|
3 | 286 |
bwn := borderWidth negated + margin. |
0 | 287 |
|
59 | 288 |
thumbHeight := height - upAndDownHeight - borderWidth - (elementSpacing * 3). |
3 | 289 |
" |
130 | 290 |
((buttonLayout ~~ #top) and:[buttonLayout ~~ #bottom]) ifTrue:[ |
59 | 291 |
thumbHeight := thumbHeight - borderWidth |
0 | 292 |
]. |
3 | 293 |
" |
130 | 294 |
buttonLayout == #around ifTrue:[ |
59 | 295 |
thumbHeight := thumbHeight + borderWidth |
3 | 296 |
]. |
0 | 297 |
|
298 |
"if I become too small, hide buttons and thumb" |
|
299 |
||
130 | 300 |
height < upAndDownHeight ifTrue:[ |
301 |
b1Hidden := b2Hidden := thumbHidden := true. |
|
0 | 302 |
] ifFalse:[ |
130 | 303 |
b1Hidden := b2Hidden := thumbHidden := false. |
0 | 304 |
]. |
305 |
||
306 |
(thumbHeight < 10) ifTrue:[ |
|
130 | 307 |
thumbHidden := true. |
308 |
] ifFalse:[ |
|
309 |
thumbHidden := false. |
|
310 |
]. |
|
311 |
||
312 |
button1 hiddenOnRealize:b1Hidden. |
|
313 |
b1Hidden ifTrue:[ |
|
314 |
button1 unrealize |
|
0 | 315 |
] ifFalse:[ |
130 | 316 |
shown ifTrue:[button1 realize] |
317 |
]. |
|
318 |
button2 hiddenOnRealize:b1Hidden. |
|
319 |
b2Hidden ifTrue:[ |
|
320 |
button2 unrealize |
|
321 |
] ifFalse:[ |
|
322 |
shown ifTrue:[button2 realize] |
|
323 |
]. |
|
324 |
thumb hiddenOnRealize:thumbHidden. |
|
325 |
thumbHidden ifTrue:[ |
|
326 |
thumb unrealize |
|
327 |
] ifFalse:[ |
|
328 |
shown ifTrue:[thumb realize] |
|
0 | 329 |
]. |
330 |
||
331 |
"width of buttons is always my width" |
|
332 |
||
3 | 333 |
w := width - (margin * 2). |
334 |
(w ~~ button1 width) ifTrue:[ |
|
59 | 335 |
button1 width:w. |
336 |
button2 width:w |
|
0 | 337 |
]. |
338 |
||
3 | 339 |
thumbWidth := w. |
128 | 340 |
style == #next ifTrue:[ |
59 | 341 |
thumbWidth := thumbWidth - (thumb borderWidth * 2). |
342 |
thumbHeight := thumbHeight - 1 |
|
0 | 343 |
]. |
128 | 344 |
style == #motif ifTrue:[ |
63 | 345 |
thumbHeight := thumbHeight - margin |
346 |
]. |
|
0 | 347 |
|
38 | 348 |
" |
349 |
a kludge: views with width or height of 0 are illegal |
|
350 |
avoid error from view-creation (it will be hidden anyway) |
|
351 |
" |
|
352 |
thumbHeight <= 0 ifTrue:[ |
|
59 | 353 |
thumbHeight := 1 |
38 | 354 |
]. |
355 |
||
130 | 356 |
(buttonLayout == #top) ifTrue:[ |
59 | 357 |
"buttons at top" |
358 |
thumb extent:(thumbWidth @ thumbHeight). |
|
359 |
^ self |
|
0 | 360 |
]. |
361 |
||
59 | 362 |
sep2 := elementSpacing * 2. |
130 | 363 |
(buttonLayout == #bottom) ifTrue:[ |
59 | 364 |
"buttons at bottom" |
143 | 365 |
"/ |
366 |
"/ XX: I thought, that viewGravity shuld fix things automatically |
|
367 |
"/ XX: it seems not to do it (or I misused it ;-) |
|
368 |
"/ XX: anyway, viewGravity is an X special feature which is probably |
|
369 |
"/ XX: not available with other windowing systems. Therefore, |
|
370 |
"/ XX: the viewGravity depending code below is disabled. |
|
371 |
"/ XX: resize is somewhat slower, though. |
|
372 |
||
59 | 373 |
thumbHeight := thumbHeight + borderWidth. |
143 | 374 |
"/ XX thumbHidden ifTrue:[ |
375 |
"/ XX bY := elementSpacing |
|
376 |
"/ XX ] ifFalse:[ |
|
130 | 377 |
bY := thumbHeight + sep2. |
143 | 378 |
"/ XX ]. |
379 |
"XX" button1 viewGravity:#North. |
|
380 |
"XX" button2 viewGravity:#North. |
|
59 | 381 |
(how == #smaller) ifTrue:[ |
382 |
thumb extent:(thumbWidth @ thumbHeight). |
|
143 | 383 |
"XX" button1 origin:(bwn @ (thumbHeight + sep2)). |
384 |
"XX" button2 origin:(bwn @ (thumbHeight + sep2 + upHeight)) |
|
59 | 385 |
] ifFalse:[ |
130 | 386 |
button1 origin:(bwn @ bY). |
387 |
button2 origin:(bwn @ (bY + upHeight)). |
|
59 | 388 |
thumb extent:(thumbWidth @ thumbHeight) |
389 |
]. |
|
390 |
^ self |
|
0 | 391 |
]. |
392 |
"buttons around thumb" |
|
393 |
||
128 | 394 |
style == #motif ifTrue:[ |
395 |
sep2 := sep2 + 1 |
|
396 |
]. |
|
3 | 397 |
button1 origin:(bwn @ bwn). |
128 | 398 |
|
399 |
style == #os2 ifTrue:[ |
|
400 |
button2 origin:(bwn @ (upHeight + thumbHeight + sep2 - margin "+ borderWidth")). |
|
401 |
thumb extent:(thumbWidth @ (thumbHeight - margin - margin "+ margin - (margin // 2)")). |
|
402 |
thumb origin:(bwn @ (upHeight - borderWidth + elementSpacing + margin)) |
|
403 |
] ifFalse:[ |
|
404 |
button2 origin:(bwn @ (upHeight + thumbHeight + sep2 - (margin // 2) "+ borderWidth")). |
|
405 |
thumb extent:(thumbWidth @ (thumbHeight + margin - (margin // 2))). |
|
406 |
thumb origin:(bwn @ (upHeight - borderWidth + elementSpacing)) |
|
407 |
]. |
|
0 | 408 |
! ! |
110 | 409 |
|
410 |
!ScrollBar methodsFor:'forced scroll'! |
|
411 |
||
205 | 412 |
pageDown |
413 |
"page down/right" |
|
414 |
||
415 |
thumb pageDown |
|
416 |
! |
|
417 |
||
110 | 418 |
pageUp |
419 |
"page up/left" |
|
420 |
||
421 |
thumb pageUp |
|
205 | 422 |
! ! |
423 |
||
424 |
!ScrollBar methodsFor:'initialization'! |
|
425 |
||
426 |
computeInitialExtent |
|
427 |
"compute my extent from sub-components" |
|
428 |
||
429 |
self extent:(self preferredExtent). |
|
430 |
! |
|
431 |
||
432 |
createElements |
|
433 |
button1 := ArrowButton upIn:self. |
|
434 |
button2 := ArrowButton downIn:self. |
|
435 |
thumb := Scroller in:self. |
|
436 |
! |
|
437 |
||
438 |
initStyle |
|
439 |
super initStyle. |
|
440 |
||
441 |
buttonLayout := DefaultButtonPositions. |
|
442 |
DefaultLevel notNil ifTrue:[ |
|
443 |
self level:DefaultLevel |
|
444 |
]. |
|
445 |
elementSpacing := DefaultElementSpacing |
|
446 |
! |
|
447 |
||
448 |
initialize |
|
449 |
"setup; create the 2 buttons and a scroller" |
|
450 |
||
451 |
|clr style| |
|
452 |
||
453 |
super initialize. |
|
454 |
||
455 |
self createElements. |
|
456 |
||
457 |
(styleSheet at:'scrollBarDisableButtons' default:false) ifTrue:[ |
|
345 | 458 |
thumb addDependent:self |
205 | 459 |
]. |
460 |
||
345 | 461 |
button1 autoRepeat:true. |
462 |
button2 autoRepeat:true. |
|
205 | 463 |
|
464 |
self computeInitialExtent. |
|
465 |
||
466 |
button1 borderWidth:borderWidth. |
|
467 |
DefaultScrollerBordered ifFalse:[ |
|
345 | 468 |
thumb borderWidth:borderWidth. |
205 | 469 |
]. |
470 |
button2 borderWidth:borderWidth. |
|
471 |
||
472 |
style := styleSheet name. |
|
473 |
((style = #iris) and:[Display hasGreyscales]) ifTrue:[ |
|
345 | 474 |
"have to change some of Buttons defaults" |
475 |
clr := (Color grey:25) on:device. |
|
476 |
button1 offLevel:2. |
|
477 |
button2 offLevel:2. |
|
478 |
button1 foregroundColor:clr. |
|
479 |
button1 activeForegroundColor:clr. |
|
480 |
button1 enteredForegroundColor:clr. |
|
481 |
button2 foregroundColor:clr. |
|
482 |
button2 activeForegroundColor:clr. |
|
483 |
button2 enteredForegroundColor:clr. |
|
205 | 484 |
]. |
485 |
||
486 |
self setElementPositions. |
|
487 |
||
488 |
style = #motif ifTrue:[ |
|
345 | 489 |
clr := thumb thumbColor. |
490 |
button1 foregroundColor:clr. |
|
491 |
button2 foregroundColor:clr. |
|
205 | 492 |
|
345 | 493 |
clr := thumb viewBackground. |
494 |
button1 viewBackground:clr. |
|
495 |
button2 viewBackground:clr. |
|
496 |
button1 backgroundColor:clr. |
|
497 |
button2 backgroundColor:clr. |
|
498 |
button1 activeBackgroundColor:clr. |
|
499 |
button2 activeBackgroundColor:clr. |
|
500 |
device hasGreyscales ifFalse:[ |
|
501 |
button1 activeForegroundColor:Black. |
|
502 |
button2 activeForegroundColor:Black. |
|
503 |
] |
|
205 | 504 |
] |
345 | 505 |
|
506 |
"Modified: 9.2.1996 / 22:42:16 / cg" |
|
205 | 507 |
! |
508 |
||
509 |
reinitialize |
|
510 |
super reinitialize. |
|
511 |
self setElementPositions. |
|
110 | 512 |
! |
513 |
||
205 | 514 |
setElementPositions |
515 |
"position sub-components" |
|
516 |
||
517 |
|bwn| |
|
518 |
||
519 |
bwn := borderWidth negated + margin. |
|
520 |
||
521 |
(buttonLayout == #top) ifTrue:[ |
|
522 |
button1 origin:(bwn @ bwn). |
|
523 |
button1 viewGravity:#North. |
|
524 |
button2 origin:(bwn @ (button1 height)). |
|
525 |
button2 viewGravity:#North. |
|
526 |
thumb origin:(bwn @ (button1 height |
|
527 |
+ borderWidth |
|
528 |
+ button2 height |
|
529 |
+ elementSpacing |
|
530 |
+ elementSpacing)). |
|
531 |
thumb viewGravity:#North. |
|
532 |
^ self |
|
533 |
]. |
|
534 |
(buttonLayout == #bottom) ifTrue:[ |
|
535 |
device supportsViewGravity ifTrue:[ |
|
536 |
button1 viewGravity:#South. |
|
537 |
button2 viewGravity:#South. |
|
538 |
thumb viewGravity:#North. |
|
539 |
]. |
|
540 |
thumb origin:(bwn @ bwn). |
|
541 |
^ self |
|
542 |
]. |
|
543 |
||
544 |
"buttonLayout == #around" |
|
545 |
button1 origin:(bwn @ bwn). |
|
546 |
button1 viewGravity:#North. |
|
547 |
"/ button2 viewGravity:#North. |
|
548 |
thumb origin:(bwn @ (button1 height + elementSpacing)). |
|
549 |
thumb viewGravity:#North |
|
550 |
! ! |
|
551 |
||
552 |
!ScrollBar methodsFor:'private'! |
|
553 |
||
554 |
enableDisableButtons |
|
555 |
"only used with styles which disable their buttons if the |
|
556 |
thumb is at either end. Check where the thumb is and enable/disable |
|
557 |
as appropriate." |
|
558 |
||
559 |
|e1 e2 th to| |
|
560 |
||
561 |
(styleSheet at:'scrollBarDisableButtons' default:false) ifFalse:[^ self]. |
|
110 | 562 |
|
205 | 563 |
e1 := e2 := true. |
564 |
(th := thumb thumbHeight) notNil ifTrue:[ |
|
565 |
(th >= (thumb stop)) ifTrue:[ |
|
566 |
e1 := false. |
|
567 |
e2 := false |
|
568 |
] |
|
569 |
]. |
|
570 |
((to := thumb thumbOrigin) <= thumb start) ifTrue:[ |
|
571 |
e1 := false |
|
572 |
] ifFalse:[ |
|
573 |
th isNil ifTrue:[th := 0]. |
|
574 |
(to + th) >= thumb stop ifTrue:[ |
|
575 |
e2 := false |
|
576 |
] |
|
577 |
]. |
|
578 |
e1 ifTrue:[button1 enable] ifFalse:[button1 disable]. |
|
579 |
e2 ifTrue:[button2 enable] ifFalse:[button2 disable]. |
|
446 | 580 |
! |
581 |
||
582 |
setThumbHeightFor:aView |
|
583 |
"adjust thumbs height for aViews size & contents. |
|
584 |
This is forwarded to the scroller here." |
|
585 |
||
586 |
thumb setThumbHeightFor:aView. |
|
587 |
self enableDisableButtons |
|
588 |
! ! |
|
589 |
||
590 |
!ScrollBar methodsFor:'private scrollView interface'! |
|
591 |
||
592 |
setThumbFor:aView |
|
593 |
"adjust thumb for aView |
|
594 |
(i.e. adjust thumbs origin & size for views size & views contents). |
|
595 |
This is forwarded to the scroller here." |
|
596 |
||
597 |
thumb setThumbFor:aView. |
|
598 |
self enableDisableButtons |
|
599 |
! |
|
600 |
||
601 |
setThumbOriginFor:aView |
|
602 |
"adjust thumbs origin for aViews size & contents. |
|
603 |
This is forwarded to the scroller here." |
|
604 |
||
605 |
thumb setThumbOriginFor:aView. |
|
606 |
self enableDisableButtons |
|
110 | 607 |
! ! |
205 | 608 |
|
609 |
!ScrollBar methodsFor:'queries'! |
|
610 |
||
611 |
preferredExtent |
|
612 |
"compute my extent from sub-components" |
|
613 |
||
614 |
|w h upForm downForm |
|
615 |
upHeight "{ Class: SmallInteger }" |
|
616 |
downHeight "{ Class: SmallInteger }" |
|
617 |
upWidth downWidth style| |
|
618 |
||
619 |
" |
|
620 |
need fix - this is a kludge; |
|
621 |
the if should not be needed ... |
|
622 |
" |
|
623 |
style := styleSheet name. |
|
624 |
style == #mswindows ifTrue:[ |
|
625 |
w := button1 width max:button2 width. |
|
626 |
h := button1 height + button2 height + (Scroller defaultExtent y). |
|
627 |
] ifFalse:[ |
|
628 |
upForm := ArrowButton upArrowButtonForm:style on:device. |
|
629 |
downForm := ArrowButton downArrowButtonForm:style on:device. |
|
630 |
upForm isNil ifTrue:[ |
|
631 |
upHeight := upWidth := 16. |
|
632 |
] ifFalse:[ |
|
633 |
upHeight := upForm height. |
|
634 |
upWidth := upForm width |
|
635 |
]. |
|
636 |
downForm isNil ifTrue:[ |
|
637 |
downHeight := downWidth := 16 |
|
638 |
] ifFalse:[ |
|
639 |
downHeight := downForm height. |
|
640 |
downWidth := downForm width |
|
641 |
]. |
|
642 |
h := upHeight + downHeight + (1 * 2) + (Scroller defaultExtent y). |
|
643 |
w := upWidth max:downWidth. |
|
644 |
style ~~ #normal ifTrue:[ |
|
645 |
h := h + 4. |
|
646 |
w := w + 4 |
|
647 |
]. |
|
648 |
]. |
|
649 |
||
650 |
^ w @ h. |
|
651 |
! ! |
|
652 |
||
653 |
!ScrollBar class methodsFor:'documentation'! |
|
654 |
||
655 |
version |
|
446 | 656 |
^ '$Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.23 1996-03-01 18:16:26 cg Exp $' |
205 | 657 |
! ! |