0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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 |
|
|
13 |
ScrollBar subclass:#HorizontalScrollBar
|
|
14 |
instanceVariableNames:''
|
38
|
15 |
classVariableNames:''
|
0
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Interactors'
|
|
18 |
!
|
|
19 |
|
|
20 |
HorizontalScrollBar comment:'
|
5
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
22 |
All Rights Reserved
|
|
23 |
|
38
|
24 |
$Header: /cvs/stx/stx/libwidg/HorizontalScrollBar.st,v 1.6 1994-08-07 13:22:35 claus Exp $
|
0
|
25 |
'!
|
|
26 |
|
38
|
27 |
!HorizontalScrollBar class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
0
|
33 |
|
38
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
0
|
41 |
!
|
|
42 |
|
38
|
43 |
version
|
|
44 |
"
|
|
45 |
$Header: /cvs/stx/stx/libwidg/HorizontalScrollBar.st,v 1.6 1994-08-07 13:22:35 claus Exp $
|
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
this class implements horizontal scrollbars with scroller and
|
|
52 |
2 step-scroll buttons. when moved or stepped, it perform a
|
|
53 |
predefined action.
|
|
54 |
"
|
0
|
55 |
! !
|
|
56 |
|
|
57 |
!HorizontalScrollBar methodsFor:'initialization'!
|
|
58 |
|
38
|
59 |
createElements
|
|
60 |
button1 := ArrowButton leftIn:self.
|
|
61 |
button1 name:'LeftButton'.
|
|
62 |
button2 := ArrowButton rightIn:self.
|
|
63 |
button2 name:'RightButton'.
|
|
64 |
thumb := HorizontalScroller in:self.
|
|
65 |
!
|
0
|
66 |
|
38
|
67 |
computeInitialExtent
|
0
|
68 |
"compute my extent from sub-components"
|
38
|
69 |
|
|
70 |
|w h leftForm rightForm|
|
|
71 |
|
|
72 |
"need fix - this is a kludge;
|
|
73 |
the if should not be needed ..."
|
|
74 |
style == #mswindows ifTrue:[
|
|
75 |
h := button1 height max:button2 height.
|
|
76 |
w := button1 width + button2 width + (Scroller defaultExtent x).
|
|
77 |
] ifFalse:[
|
|
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 |
].
|
0
|
86 |
].
|
|
87 |
self extent:w @ h.
|
38
|
88 |
!
|
|
89 |
|
|
90 |
setElementPositions
|
|
91 |
"position sub-components"
|
|
92 |
|
|
93 |
|bwn sep|
|
0
|
94 |
|
7
|
95 |
bwn := borderWidth negated + margin.
|
38
|
96 |
sep := self spaceBetweenElements.
|
0
|
97 |
|
|
98 |
(layout == #bottom) ifTrue:[
|
|
99 |
"buttons at left"
|
|
100 |
button1 origin:(bwn @ bwn).
|
|
101 |
button1 viewGravity:#West.
|
|
102 |
button2 origin:(button1 width @ bwn).
|
|
103 |
button2 viewGravity:#West.
|
|
104 |
thumb origin:((button1 width + borderWidth + button2 width + sep + sep) @ bwn).
|
38
|
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).
|
0
|
114 |
thumb viewGravity:#West
|
38
|
115 |
].
|
|
116 |
|
|
117 |
"layout == #around "
|
|
118 |
button1 origin:(bwn @ bwn).
|
|
119 |
button1 viewGravity:#West.
|
|
120 |
button2 viewGravity:#West.
|
|
121 |
thumb origin:((button1 width + sep) @ bwn).
|
|
122 |
thumb viewGravity:#West
|
0
|
123 |
! !
|
|
124 |
|
|
125 |
!HorizontalScrollBar methodsFor:'accessing'!
|
|
126 |
|
38
|
127 |
scrollLeftAction
|
|
128 |
^ button1 action
|
|
129 |
!
|
|
130 |
|
0
|
131 |
scrollLeftAction:aBlock
|
|
132 |
button1 action:aBlock
|
|
133 |
!
|
|
134 |
|
38
|
135 |
scrollRightAction
|
|
136 |
^ button2 action
|
|
137 |
!
|
|
138 |
|
0
|
139 |
scrollRightAction:aBlock
|
|
140 |
button2 action:aBlock
|
|
141 |
! !
|
|
142 |
|
|
143 |
!HorizontalScrollBar methodsFor:'events'!
|
|
144 |
|
|
145 |
sizeChanged:how
|
7
|
146 |
|leftWidth rightWidth thumbWidth leftAndRightWidth bwn sep sep2
|
|
147 |
thumbHeight h|
|
0
|
148 |
|
|
149 |
button1 isNil ifTrue:[^ self].
|
|
150 |
button2 isNil ifTrue:[^ self].
|
|
151 |
thumb isNil ifTrue:[^ self].
|
|
152 |
|
|
153 |
leftWidth := button1 width + borderWidth.
|
|
154 |
rightWidth := button2 width + borderWidth.
|
|
155 |
leftAndRightWidth := leftWidth + rightWidth.
|
7
|
156 |
bwn := borderWidth negated + margin.
|
38
|
157 |
sep := self spaceBetweenElements.
|
0
|
158 |
|
|
159 |
thumbWidth := width - leftAndRightWidth - borderWidth - (sep * 3).
|
7
|
160 |
"
|
0
|
161 |
((layout ~~ #top) and:[layout ~~ #bottom]) ifTrue:[
|
|
162 |
thumbWidth := thumbWidth - borderWidth
|
|
163 |
].
|
7
|
164 |
"
|
|
165 |
layout == #around ifTrue:[
|
|
166 |
thumbWidth := thumbWidth + borderWidth
|
|
167 |
].
|
0
|
168 |
|
|
169 |
"if I become too small, hide buttons"
|
|
170 |
|
|
171 |
(width < leftAndRightWidth) ifTrue:[
|
|
172 |
button1 shown ifTrue:[
|
|
173 |
button1 hidden.
|
|
174 |
button2 hidden.
|
|
175 |
thumb hidden
|
|
176 |
]
|
|
177 |
] ifFalse:[
|
|
178 |
shown ifTrue:[
|
|
179 |
button1 shown ifFalse:[
|
|
180 |
button1 show.
|
|
181 |
button2 show.
|
|
182 |
thumb show
|
|
183 |
]
|
|
184 |
]
|
|
185 |
].
|
|
186 |
|
|
187 |
(thumbWidth < 10) ifTrue:[
|
|
188 |
thumb shown ifTrue:[
|
|
189 |
thumb hidden
|
|
190 |
]
|
|
191 |
] ifFalse:[
|
|
192 |
thumb shown ifFalse:[
|
|
193 |
button1 shown ifTrue:[
|
|
194 |
thumb show
|
|
195 |
]
|
|
196 |
]
|
|
197 |
].
|
|
198 |
|
|
199 |
"height of buttons is always my width"
|
|
200 |
|
7
|
201 |
h := height - (margin * 2).
|
|
202 |
|
|
203 |
(h ~~ button1 height) ifTrue:[
|
38
|
204 |
button1 height:h.
|
|
205 |
button2 height:h
|
0
|
206 |
].
|
|
207 |
|
7
|
208 |
thumbHeight := h.
|
|
209 |
style == #next ifTrue:[
|
|
210 |
thumbHeight := thumbHeight - (thumb borderWidth * 2).
|
|
211 |
thumbWidth := thumbWidth - 1
|
|
212 |
].
|
|
213 |
|
0
|
214 |
|
38
|
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 |
|
0
|
223 |
(layout == #bottom) ifTrue:[
|
|
224 |
"buttons at left"
|
7
|
225 |
thumb extent:(thumbWidth @ thumbHeight).
|
0
|
226 |
^ self
|
|
227 |
].
|
7
|
228 |
|
0
|
229 |
sep2 := sep * 2.
|
|
230 |
(layout == #top) ifTrue:[
|
|
231 |
"buttons at right"
|
38
|
232 |
thumbWidth := thumbWidth + borderWidth.
|
0
|
233 |
(how == #smaller) ifTrue:[
|
7
|
234 |
thumb extent:(thumbWidth @ thumbHeight).
|
0
|
235 |
button1 origin:((thumbWidth + sep2) @ bwn).
|
|
236 |
button2 origin:((thumbWidth + sep2 + leftWidth) @ bwn)
|
|
237 |
] ifFalse:[
|
|
238 |
button1 origin:((thumbWidth + sep2) @ bwn).
|
|
239 |
button2 origin:((thumbWidth + sep2 + leftWidth) @ bwn).
|
7
|
240 |
thumb extent:(thumbWidth @ thumbHeight)
|
0
|
241 |
].
|
|
242 |
^ self
|
|
243 |
].
|
|
244 |
"button around thumb"
|
|
245 |
|
7
|
246 |
button1 origin:(bwn @ bwn).
|
38
|
247 |
button2 origin:((leftWidth + thumbWidth + sep2 - (margin // 2)) @ bwn).
|
|
248 |
thumb extent:((thumbWidth + margin - (margin // 2)) @ thumbHeight).
|
0
|
249 |
thumb origin:((leftWidth - borderWidth + sep) @ bwn)
|
|
250 |
! !
|