ScrollBar.st
changeset 110 eb59f6e31e84
parent 77 565b052f5277
child 119 59758ff5b841
equal deleted inserted replaced
109:0f014b33eba2 110:eb59f6e31e84
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
       
    13 'From Smalltalk/X, Version:2.10.5 on 25-mar-1995 at 1:10:33 am'!
       
    14 
    13 View subclass:#ScrollBar
    15 View subclass:#ScrollBar
    14        instanceVariableNames:'thumb button1 button2 layout elementSpacing'
    16 	 instanceVariableNames:'thumb button1 button2 layout elementSpacing'
    15        classVariableNames:'DefaultButtonPositions DefaultLevel 
    17 	 classVariableNames:'DefaultButtonPositions DefaultLevel DefaultElementSpacing
    16 			   DefaultElementSpacing DefaultScrollerBordered'
    18                 DefaultScrollerBordered'
    17        poolDictionaries:''
    19 	 poolDictionaries:''
    18        category:'Views-Interactors'
    20 	 category:'Views-Interactors'
    19 !
    21 !
    20 
    22 
    21 ScrollBar comment:'
    23 ScrollBar comment:'
    22 COPYRIGHT (c) 1989 by Claus Gittinger
    24 COPYRIGHT (c) 1989 by Claus Gittinger
    23 	      All Rights Reserved
    25 	      All Rights Reserved
    24 
    26 
    25 $Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.10 1995-02-06 00:53:13 claus Exp $
    27 $Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.11 1995-03-25 22:21:15 claus Exp $
    26 '!
    28 '!
    27 
    29 
    28 !ScrollBar class methodsFor:'documentation'!
    30 !ScrollBar class methodsFor:'documentation'!
    29 
    31 
    30 copyright
    32 copyright
    41 "
    43 "
    42 !
    44 !
    43 
    45 
    44 version
    46 version
    45 "
    47 "
    46 $Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.10 1995-02-06 00:53:13 claus Exp $
    48 $Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.11 1995-03-25 22:21:15 claus Exp $
    47 "
    49 "
    48 !
    50 !
    49 
    51 
    50 documentation
    52 documentation
    51 "
    53 "
    82     DefaultElementSpacing := StyleSheet at:'scrollBarElementSpacing' 
    84     DefaultElementSpacing := StyleSheet at:'scrollBarElementSpacing' 
    83 					default:(StyleSheet is3D ifTrue:[1] ifFalse:[0]).
    85 					default:(StyleSheet is3D ifTrue:[1] ifFalse:[0]).
    84 ! !
    86 ! !
    85 
    87 
    86 !ScrollBar methodsFor:'initialization'!
    88 !ScrollBar methodsFor:'initialization'!
    87 
       
    88 initialize
       
    89     "setup; create the 2 buttons and a scroller"
       
    90 
       
    91     |clr|
       
    92 
       
    93     super initialize.
       
    94 
       
    95     self createElements.
       
    96 
       
    97     button1 autoRepeat.
       
    98     button2 autoRepeat.
       
    99 
       
   100     self computeInitialExtent.
       
   101 
       
   102     button1 borderWidth:borderWidth.
       
   103     DefaultScrollerBordered ifFalse:[
       
   104 	thumb borderWidth:borderWidth.
       
   105     ].
       
   106     button2 borderWidth:borderWidth.
       
   107 
       
   108     ((StyleSheet name = #iris) and:[Display hasGreyscales]) ifTrue:[
       
   109 	"have to change some of Buttons defaults"
       
   110 	clr := (Color grey:25) on:device.
       
   111 	button1 offLevel:2.
       
   112 	button2 offLevel:2.
       
   113 	button1 foregroundColor:clr.
       
   114 	button1 activeForegroundColor:clr.
       
   115 	button1 enteredForegroundColor:clr.
       
   116 	button2 foregroundColor:clr.
       
   117 	button2 activeForegroundColor:clr.
       
   118 	button2 enteredForegroundColor:clr.
       
   119     ].
       
   120 
       
   121     self setElementPositions.
       
   122 
       
   123     StyleSheet name = #motif ifTrue:[
       
   124 	clr := thumb thumbColor.
       
   125 	button1 foregroundColor:clr.
       
   126 	button2 foregroundColor:clr.
       
   127 
       
   128 	clr := thumb viewBackground.
       
   129 	button1 viewBackground:clr.
       
   130 	button2 viewBackground:clr.
       
   131 	button1 backgroundColor:clr.
       
   132 	button2 backgroundColor:clr.
       
   133 	button1 activeBackgroundColor:clr.
       
   134 	button2 activeBackgroundColor:clr.
       
   135 	device hasGreyscales ifFalse:[
       
   136 	    button1 activeForegroundColor:Black.
       
   137 	    button2 activeForegroundColor:Black.
       
   138 	]
       
   139     ]
       
   140 !
       
   141 
       
   142 initStyle
       
   143     super initStyle.
       
   144 
       
   145     layout := DefaultButtonPositions.
       
   146     DefaultLevel notNil ifTrue:[
       
   147 	self level:DefaultLevel
       
   148     ].
       
   149     elementSpacing := DefaultElementSpacing
       
   150 !
       
   151 
       
   152 reinitialize
       
   153     super reinitialize.
       
   154     self setElementPositions.
       
   155 !
       
   156 
       
   157 createElements
       
   158     button1 := ArrowButton upIn:self.
       
   159     button2 := ArrowButton downIn:self.
       
   160     thumb := Scroller in:self.
       
   161 !
       
   162 
    89 
   163 setElementPositions
    90 setElementPositions
   164     "position sub-components"
    91     "position sub-components"
   165 
    92 
   166     |bwn|
    93     |bwn|
   196 "/    button2 viewGravity:#North.
   123 "/    button2 viewGravity:#North.
   197     thumb origin:(bwn @ (button1 height + elementSpacing)).
   124     thumb origin:(bwn @ (button1 height + elementSpacing)).
   198     thumb viewGravity:#North
   125     thumb viewGravity:#North
   199 !
   126 !
   200 
   127 
       
   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 
   201 computeInitialExtent
   144 computeInitialExtent
   202     "compute my extent from sub-components"
   145     "compute my extent from sub-components"
   203 
   146 
   204     |w h upForm downForm
   147     |w h upForm downForm
   205      upHeight   "{ Class: SmallInteger }"
   148      upHeight   "{ Class: SmallInteger }"
   206      downHeight "{ Class: SmallInteger }"
   149      downHeight "{ Class: SmallInteger }"
   207      upWidth downWidth|
   150      upWidth downWidth style|
   208 
   151 
   209     "need fix - this is a kludge;
   152     "need fix - this is a kludge;
   210      the if should not be needed ..."
   153      the if should not be needed ..."
   211     StyleSheet name == #mswindows ifTrue:[
   154     style := StyleSheet name.
   212 	w := button1 width max:button2 width.
   155     style == #mswindows ifTrue:[
   213 	h := button1 height + button2 height + (Scroller defaultExtent y).
   156         w := button1 width max:button2 width.
       
   157         h := button1 height + button2 height + (Scroller defaultExtent y).
   214     ] ifFalse:[
   158     ] ifFalse:[
   215 	upForm  := ArrowButton upArrowButtonForm:style on:device.
   159         upForm  := ArrowButton upArrowButtonForm:style on:device.
   216 	downForm := ArrowButton downArrowButtonForm:style on:device.
   160         downForm := ArrowButton downArrowButtonForm:style on:device.
   217 	upForm isNil ifTrue:[
   161         upForm isNil ifTrue:[
   218 	    upHeight := upWidth := 16.
   162             upHeight := upWidth := 16.
   219 	] ifFalse:[
   163         ] ifFalse:[
   220 	    upHeight := upForm height.
   164             upHeight := upForm height.
   221 	    upWidth := upForm width
   165             upWidth := upForm width
   222 	].
   166         ].
   223 	downForm isNil ifTrue:[
   167         downForm isNil ifTrue:[
   224 	    downHeight := downWidth := 16
   168             downHeight := downWidth := 16
   225 	] ifFalse:[
   169         ] ifFalse:[
   226 	    downHeight := downForm height.
   170             downHeight := downForm height.
   227 	    downWidth := downForm width
   171             downWidth := downForm width
   228 	].
   172         ].
   229 	h := upHeight + downHeight + (1 * 2) + (Scroller defaultExtent y).
   173         h := upHeight + downHeight + (1 * 2) + (Scroller defaultExtent y).
   230 	w := upWidth max:downWidth.
   174         w := upWidth max:downWidth.
   231 	StyleSheet name ~~ #normal ifTrue:[
   175         style ~~ #normal ifTrue:[
   232 	    h := h + 4.
   176             h := h + 4.
   233 	    w := w + 4
   177             w := w + 4
   234 	].
   178         ].
   235     ].
   179     ].
   236 
   180 
   237     self extent:w @ h.
   181     self extent:w @ h.
       
   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.
   238 ! !
   242 ! !
   239 
   243 
   240 !ScrollBar methodsFor:'accessing'!
   244 !ScrollBar methodsFor:'accessing'!
       
   245 
       
   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 !
   241 
   263 
   242 scrollAction:aBlock
   264 scrollAction:aBlock
   243     "set the action, aBlock to be performed when the scroller is moved"
   265     "set the action, aBlock to be performed when the scroller is moved"
   244  
   266  
   245     thumb scrollAction:aBlock
   267     thumb scrollAction:aBlock
   285     "set height of thumb in percent"
   307     "set height of thumb in percent"
   286 
   308 
   287     ^ thumb thumbHeight:newHeight
   309     ^ thumb thumbHeight:newHeight
   288 !
   310 !
   289 
   311 
   290 thumbOrigin:newOrigin thumbHeight:newHeight
       
   291     "set origin and height of thumb in percent"
       
   292 
       
   293     ^ thumb thumbOrigin:newOrigin thumbHeight:newHeight
       
   294 !
       
   295 
       
   296 setThumbFor:aView
       
   297     "adjust thumb for aView"
       
   298 
       
   299     thumb setThumbFor:aView
       
   300 !
       
   301 
       
   302 setThumbHeightFor:aView
   312 setThumbHeightFor:aView
   303     "adjust thumbs height for aView"
   313     "adjust thumbs height for aView"
   304 
   314 
   305     thumb setThumbHeightFor:aView
   315     thumb setThumbHeightFor:aView
   306 !
       
   307 
       
   308 setThumbOriginFor:aView
       
   309     "adjust thumbs origin for aView"
       
   310 
       
   311     thumb setThumbOriginFor:aView
       
   312 !
   316 !
   313 
   317 
   314 asynchronousOperation
   318 asynchronousOperation
   315     "set asynchronous-mode - scroll action is performed after movement
   319     "set asynchronous-mode - scroll action is performed after movement
   316      of scroller (i.e. when mouse-button is finally released)"
   320      of scroller (i.e. when mouse-button is finally released)"
   322     "set synchronous-mode - scroll action is performed for every movement
   326     "set synchronous-mode - scroll action is performed for every movement
   323      of scroller"
   327      of scroller"
   324 
   328 
   325     thumb synchronousOperation
   329     thumb synchronousOperation
   326 ! !
   330 ! !
   327 
       
   328 !ScrollBar methodsFor:'forced scroll'!
       
   329 
       
   330 pageUp
       
   331     "page up/left"
       
   332 
       
   333     thumb pageUp
       
   334 !
       
   335 
       
   336 pageDown
       
   337     "page down/right"
       
   338 
       
   339     thumb pageDown
       
   340 ! !
       
   341 
       
   342 
   331 
   343 !ScrollBar methodsFor:'events'!
   332 !ScrollBar methodsFor:'events'!
   344 
   333 
   345 sizeChanged:how
   334 sizeChanged:how
   346     "when my size changes, I have to resize/reposition the subviews"
   335     "when my size changes, I have to resize/reposition the subviews"
   451     button1 origin:(bwn @ bwn).
   440     button1 origin:(bwn @ bwn).
   452     button2 origin:(bwn @ (upHeight + thumbHeight + sep2 - (margin // 2) "+ borderWidth")).
   441     button2 origin:(bwn @ (upHeight + thumbHeight + sep2 - (margin // 2) "+ borderWidth")).
   453     thumb extent:(thumbWidth @ (thumbHeight + margin - (margin // 2))).
   442     thumb extent:(thumbWidth @ (thumbHeight + margin - (margin // 2))).
   454     thumb origin:(bwn @ (upHeight - borderWidth + elementSpacing))
   443     thumb origin:(bwn @ (upHeight - borderWidth + elementSpacing))
   455 ! !
   444 ! !
       
   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