HorizontalScrollBar.st
changeset 38 4b9b70b2cc87
parent 21 9ef599238fea
child 59 450ce95a72a4
equal deleted inserted replaced
37:8dd71a2e79cd 38:4b9b70b2cc87
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 ScrollBar subclass:#HorizontalScrollBar
    13 ScrollBar subclass:#HorizontalScrollBar
    14        instanceVariableNames:''
    14        instanceVariableNames:''
    15        classVariableNames:'DefaultScrollRightForm
    15        classVariableNames:''
    16                            DefaultScrollLeftForm'
       
    17        poolDictionaries:''
    16        poolDictionaries:''
    18        category:'Views-Interactors'
    17        category:'Views-Interactors'
    19 !
    18 !
    20 
    19 
    21 HorizontalScrollBar comment:'
    20 HorizontalScrollBar comment:'
    22 
       
    23 COPYRIGHT (c) 1989 by Claus Gittinger
    21 COPYRIGHT (c) 1989 by Claus Gittinger
    24               All Rights Reserved
    22               All Rights Reserved
    25 
    23 
    26 this class implements horizontal scrollbars with scroller and
    24 $Header: /cvs/stx/stx/libwidg/HorizontalScrollBar.st,v 1.6 1994-08-07 13:22:35 claus Exp $
    27 2 step-scroll buttons. when moved or stepped, it perform a
       
    28 predefined action.
       
    29 
       
    30 $Header: /cvs/stx/stx/libwidg/HorizontalScrollBar.st,v 1.5 1994-01-08 17:27:18 claus Exp $
       
    31 
       
    32 written spring/summer 89 by claus
       
    33 '!
    25 '!
    34 
    26 
    35 !HorizontalScrollBar class methodsFor:'defaults'!
    27 !HorizontalScrollBar class methodsFor:'documentation'!
    36 
    28 
    37 scrollLeftButtonForm:style
    29 copyright
    38     DefaultScrollLeftForm isNil ifTrue:[
    30 "
    39         DefaultScrollLeftForm := Form fromFile:(self classResources at:'SCROLL_LEFT_BUTTON_FORM_FILE'
    31  COPYRIGHT (c) 1989 by Claus Gittinger
    40                                                      default:(style == #mswindows
    32               All Rights Reserved
    41                                                                  ifTrue:['ScrollLt_win.xbm']
    33 
    42                                                                  ifFalse:['ScrollLt.xbm']))
    34  This software is furnished under a license and may be used
    43                                     resolution:100
    35  only in accordance with the terms of that license and with the
    44     ].
    36  inclusion of the above copyright notice.   This software may not
    45     DefaultScrollLeftForm isNil ifTrue:[
    37  be provided or otherwise made available to, or used by, any
    46         DefaultScrollLeftForm :=
    38  other person.  No title to or ownership of the software is
    47             Form width:16 height:16 fromArray:#(2r00000000 2r00000000
    39  hereby transferred.
    48                                                 2r00000001 2r10000000
    40 "
    49                                                 2r00000010 2r10000000
    41 !
    50                                                 2r00000100 2r10000000
    42 
    51                                                 2r00001000 2r11111110
    43 version
    52                                                 2r00010000 2r00000010
    44 "
    53                                                 2r00100000 2r00000010
    45 $Header: /cvs/stx/stx/libwidg/HorizontalScrollBar.st,v 1.6 1994-08-07 13:22:35 claus Exp $
    54                                                 2r01000000 2r00000010
    46 "
    55                                                 2r01000000 2r00000010
    47 !
    56                                                 2r00100000 2r00000010
    48 
    57                                                 2r00010000 2r00000010
    49 documentation
    58                                                 2r00001000 2r11111110
    50 "
    59                                                 2r00000100 2r10000000
    51     this class implements horizontal scrollbars with scroller and
    60                                                 2r00000010 2r10000000
    52     2 step-scroll buttons. when moved or stepped, it perform a
    61                                                 2r00000001 2r10000000
    53     predefined action.
    62                                                 2r00000000 2r00000000)
    54 "
    63     ].
       
    64     ^ DefaultScrollLeftForm
       
    65 !
       
    66 
       
    67 scrollRightButtonForm:style
       
    68     DefaultScrollRightForm isNil ifTrue:[
       
    69         DefaultScrollRightForm := Form fromFile:(self classResources at:'SCROLL_RIGHT_BUTTON_FORM_FILE'
       
    70                                                       default:(style == #mswindows
       
    71                                                                  ifTrue:['ScrollRt_win.xbm']
       
    72                                                                  ifFalse:['ScrollRt.xbm']))
       
    73                                      resolution:100
       
    74     ].
       
    75     DefaultScrollRightForm isNil ifTrue:[
       
    76         DefaultScrollRightForm :=
       
    77             Form width:16 height:16 fromArray:#(2r00000000 2r00000000
       
    78                                                 2r00000001 2r10000000
       
    79                                                 2r00000001 2r01000000
       
    80                                                 2r00000001 2r00100000
       
    81                                                 2r01111111 2r00010000
       
    82                                                 2r01000000 2r00001000
       
    83                                                 2r01000000 2r00000100
       
    84                                                 2r01000000 2r00000010
       
    85                                                 2r01000000 2r00000010
       
    86                                                 2r01000000 2r00000100
       
    87                                                 2r01000000 2r00001000
       
    88                                                 2r01111111 2r00010000
       
    89                                                 2r00000001 2r00100000
       
    90                                                 2r00000001 2r01000000
       
    91                                                 2r00000001 2r10000000
       
    92                                                 2r00000000 2r00000000)
       
    93     ].
       
    94     ^ DefaultScrollRightForm
       
    95 ! !
    55 ! !
    96 
    56 
    97 !HorizontalScrollBar methodsFor:'initialization'!
    57 !HorizontalScrollBar methodsFor:'initialization'!
    98 
    58 
    99 initialize
    59 createElements
   100     |bwn sep h w leftForm rightForm c|
       
   101 
       
   102     super initialize.
       
   103 
       
   104     "compute my extent from sub-components"
       
   105     leftForm  := self class scrollLeftButtonForm:style.
       
   106     rightForm := self class scrollRightButtonForm:style.
       
   107     w := leftForm width + rightForm width 
       
   108          + (1 "self defaultBorderWidth" * 2) 
       
   109          + (HorizontalScroller defaultExtent x).
       
   110     h := (leftForm height) max:(rightForm height).
       
   111     self is3D ifTrue:[
       
   112         h := h + 4.
       
   113         w := w + 4
       
   114     ].
       
   115     self extent:w @ h.
       
   116 
       
   117     bwn := borderWidth negated + margin.
       
   118     self is3D ifTrue:[
       
   119         sep := 1
       
   120     ] ifFalse:[
       
   121         sep := 0
       
   122     ].
       
   123 
       
   124     "poor design - destroy and re-create thumgs"
       
   125     button1 destroy.
       
   126     button2 destroy.
       
   127     thumb destroy.
       
   128 
       
   129     button1 := ArrowButton leftIn:self.
    60     button1 := ArrowButton leftIn:self.
   130     button1 name:'LeftButton'.
    61     button1 name:'LeftButton'.
   131     button1 borderWidth:borderWidth.
       
   132     button1 autoRepeat.
       
   133 
       
   134     thumb := HorizontalScroller in:self.
       
   135     style ~~ #next ifTrue:[
       
   136         thumb borderWidth:borderWidth.
       
   137     ].
       
   138 
       
   139     button2 := ArrowButton rightIn:self.
    62     button2 := ArrowButton rightIn:self.
   140     button2 name:'RightButton'.
    63     button2 name:'RightButton'.
   141     button2 borderWidth:borderWidth.
    64     thumb := HorizontalScroller in:self.
   142     button2 autoRepeat.
    65 !
   143 
    66 
   144     ((style == #iris) and:[Display hasGreyscales])ifTrue:[
    67 computeInitialExtent
   145         "have to change some of Buttons defaults"
    68     "compute my extent from sub-components"
   146         c := (Color grey:25) on:device.
    69 
   147         button1 offLevel:2.
    70     |w h leftForm rightForm|
   148         button2 offLevel:2.
    71 
   149         button1 foregroundColor:c.
    72     "need fix - this is a kludge;
   150         button1 activeForegroundColor:c.
    73      the if should not be needed ..."
   151         button1 enteredForegroundColor:c.
    74     style == #mswindows ifTrue:[
   152         button2 foregroundColor:c.
    75         h := button1 height max:button2 height.
   153         button2 activeForegroundColor:c.
    76         w := button1 width + button2 width + (Scroller defaultExtent x).
   154         button2 enteredForegroundColor:c.
    77     ] ifFalse:[
   155     ].
    78         leftForm  := ArrowButton leftArrowButtonForm:style on:device.
       
    79         rightForm := ArrowButton rightArrowButtonForm:style on:device.
       
    80         w := leftForm width + rightForm width + (1 * 2) + (HorizontalScroller defaultExtent x).
       
    81         h := (leftForm height) max:(rightForm height).
       
    82         (style ~~ #normal) ifTrue:[
       
    83             h := h + 4.
       
    84             w := w + 4
       
    85         ].
       
    86     ].
       
    87     self extent:w @ h.
       
    88 !
       
    89 
       
    90 setElementPositions
       
    91     "position sub-components"
       
    92 
       
    93     |bwn sep|
       
    94 
       
    95     bwn := borderWidth negated + margin.
       
    96     sep := self spaceBetweenElements.
   156 
    97 
   157     (layout == #bottom) ifTrue:[
    98     (layout == #bottom) ifTrue:[
   158         "buttons at left"
    99         "buttons at left"
   159         button1 origin:(bwn @ bwn).
   100         button1 origin:(bwn @ bwn).
   160         button1 viewGravity:#West.
   101         button1 viewGravity:#West.
   161         button2 origin:(button1 width @ bwn).
   102         button2 origin:(button1 width @ bwn).
   162         button2 viewGravity:#West.
   103         button2 viewGravity:#West.
   163         thumb origin:((button1 width + borderWidth + button2 width + sep + sep) @ bwn).
   104         thumb origin:((button1 width + borderWidth + button2 width + sep + sep) @ bwn).
       
   105         thumb viewGravity:#West.
       
   106         ^ self
       
   107     ].
       
   108 
       
   109     (layout == #top) ifTrue:[
       
   110         "buttons at right"
       
   111         button1 viewGravity:#West.
       
   112         button2 viewGravity:#West.
       
   113         thumb origin:(bwn @ bwn).
   164         thumb viewGravity:#West
   114         thumb viewGravity:#West
   165     ] ifFalse:[
   115     ].
   166         (layout == #top) ifTrue:[
   116 
   167             "buttons at right"
   117     "layout == #around "
   168             button1 viewGravity:#West.
   118     button1 origin:(bwn @ bwn).
   169             button2 viewGravity:#West.
   119     button1 viewGravity:#West.
   170             thumb origin:(bwn @ bwn).
   120     button2 viewGravity:#West.
   171             thumb viewGravity:#West
   121     thumb origin:((button1 width + sep) @ bwn).
   172         ] ifFalse:[
   122     thumb viewGravity:#West
   173             button1 origin:(bwn @ bwn).
       
   174             button1 viewGravity:#West.
       
   175             button2 viewGravity:#West.
       
   176             thumb origin:((button1 width + sep) @ bwn).
       
   177             thumb viewGravity:#West
       
   178         ]
       
   179     ]
       
   180 ! !
   123 ! !
   181 
   124 
   182 !HorizontalScrollBar methodsFor:'accessing'!
   125 !HorizontalScrollBar methodsFor:'accessing'!
       
   126 
       
   127 scrollLeftAction
       
   128     ^ button1 action
       
   129 !
   183 
   130 
   184 scrollLeftAction:aBlock
   131 scrollLeftAction:aBlock
   185     button1 action:aBlock
   132     button1 action:aBlock
       
   133 !
       
   134 
       
   135 scrollRightAction
       
   136     ^ button2 action
   186 !
   137 !
   187 
   138 
   188 scrollRightAction:aBlock
   139 scrollRightAction:aBlock
   189     button2 action:aBlock
   140     button2 action:aBlock
   190 ! !
   141 ! !
   201 
   152 
   202     leftWidth := button1 width + borderWidth.
   153     leftWidth := button1 width + borderWidth.
   203     rightWidth := button2 width + borderWidth.
   154     rightWidth := button2 width + borderWidth.
   204     leftAndRightWidth := leftWidth + rightWidth.
   155     leftAndRightWidth := leftWidth + rightWidth.
   205     bwn := borderWidth negated + margin.
   156     bwn := borderWidth negated + margin.
   206     self is3D ifTrue:[
   157     sep := self spaceBetweenElements.
   207         sep := 1
       
   208     ] ifFalse:[
       
   209         sep := 0
       
   210     ].
       
   211 
   158 
   212     thumbWidth := width - leftAndRightWidth - borderWidth - (sep * 3).
   159     thumbWidth := width - leftAndRightWidth - borderWidth - (sep * 3).
   213 "
   160 "
   214     ((layout ~~ #top) and:[layout ~~ #bottom]) ifTrue:[
   161     ((layout ~~ #top) and:[layout ~~ #bottom]) ifTrue:[
   215         thumbWidth := thumbWidth - borderWidth
   162         thumbWidth := thumbWidth - borderWidth
   252     "height of buttons is always my width"
   199     "height of buttons is always my width"
   253 
   200 
   254     h := height - (margin * 2).
   201     h := height - (margin * 2).
   255 
   202 
   256     (h ~~ button1 height) ifTrue:[
   203     (h ~~ button1 height) ifTrue:[
   257         button1 height:height.
   204         button1 height:h.
   258         button2 height:height
   205         button2 height:h
   259     ].
   206     ].
   260 
   207 
   261     thumbHeight := h.
   208     thumbHeight := h.
   262     style == #next ifTrue:[
   209     style == #next ifTrue:[
   263         thumbHeight := thumbHeight - (thumb borderWidth * 2).
   210         thumbHeight := thumbHeight - (thumb borderWidth * 2).
   264         thumbWidth := thumbWidth - 1
   211         thumbWidth := thumbWidth - 1
   265     ].
   212     ].
   266 
   213 
   267 
   214 
       
   215     "
       
   216      a kludge: views with width or height of 0 are illegal
       
   217      avoid error from view-creation (it will be hidden anyway)
       
   218     "
       
   219     thumbWidth <= 0 ifTrue:[
       
   220         thumbWidth := 1
       
   221     ].
       
   222 
   268     (layout == #bottom) ifTrue:[
   223     (layout == #bottom) ifTrue:[
   269         "buttons at left"
   224         "buttons at left"
   270         thumb extent:(thumbWidth @ thumbHeight).
   225         thumb extent:(thumbWidth @ thumbHeight).
   271         ^ self
   226         ^ self
   272     ].
   227     ].
   273 
   228 
   274     sep2 := sep * 2.
   229     sep2 := sep * 2.
   275     (layout == #top) ifTrue:[
   230     (layout == #top) ifTrue:[
   276         "buttons at right"
   231         "buttons at right"
       
   232         thumbWidth := thumbWidth + borderWidth.
   277         (how == #smaller) ifTrue:[
   233         (how == #smaller) ifTrue:[
   278             thumb extent:(thumbWidth @ thumbHeight).
   234             thumb extent:(thumbWidth @ thumbHeight).
   279             button1 origin:((thumbWidth + sep2) @ bwn).
   235             button1 origin:((thumbWidth + sep2) @ bwn).
   280             button2 origin:((thumbWidth + sep2 + leftWidth) @ bwn)
   236             button2 origin:((thumbWidth + sep2 + leftWidth) @ bwn)
   281         ] ifFalse:[
   237         ] ifFalse:[
   286         ^ self
   242         ^ self
   287     ].
   243     ].
   288     "button around thumb"
   244     "button around thumb"
   289 
   245 
   290     button1 origin:(bwn @ bwn).
   246     button1 origin:(bwn @ bwn).
   291     button2 origin:((leftWidth + thumbWidth + sep2) @ bwn).
   247     button2 origin:((leftWidth + thumbWidth + sep2 - (margin // 2)) @ bwn).
   292     thumb extent:((thumbWidth + margin) @ thumbHeight).
   248     thumb extent:((thumbWidth + margin - (margin // 2)) @ thumbHeight).
   293     thumb origin:((leftWidth - borderWidth + sep) @ bwn)
   249     thumb origin:((leftWidth - borderWidth + sep) @ bwn)
   294 ! !
   250 ! !