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