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:''
|
21
|
15 |
classVariableNames:'DefaultScrollRightForm
|
|
16 |
DefaultScrollLeftForm'
|
0
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Interactors'
|
|
19 |
!
|
|
20 |
|
|
21 |
HorizontalScrollBar comment:'
|
|
22 |
|
5
|
23 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
24 |
All Rights Reserved
|
|
25 |
|
|
26 |
this class implements horizontal scrollbars with scroller and
|
|
27 |
2 step-scroll buttons. when moved or stepped, it perform a
|
|
28 |
predefined action.
|
|
29 |
|
21
|
30 |
$Header: /cvs/stx/stx/libwidg/HorizontalScrollBar.st,v 1.5 1994-01-08 17:27:18 claus Exp $
|
0
|
31 |
|
|
32 |
written spring/summer 89 by claus
|
|
33 |
'!
|
|
34 |
|
|
35 |
!HorizontalScrollBar class methodsFor:'defaults'!
|
|
36 |
|
|
37 |
scrollLeftButtonForm:style
|
21
|
38 |
DefaultScrollLeftForm isNil ifTrue:[
|
|
39 |
DefaultScrollLeftForm := Form fromFile:(self classResources at:'SCROLL_LEFT_BUTTON_FORM_FILE'
|
0
|
40 |
default:(style == #mswindows
|
|
41 |
ifTrue:['ScrollLt_win.xbm']
|
|
42 |
ifFalse:['ScrollLt.xbm']))
|
|
43 |
resolution:100
|
|
44 |
].
|
21
|
45 |
DefaultScrollLeftForm isNil ifTrue:[
|
|
46 |
DefaultScrollLeftForm :=
|
0
|
47 |
Form width:16 height:16 fromArray:#(2r00000000 2r00000000
|
|
48 |
2r00000001 2r10000000
|
|
49 |
2r00000010 2r10000000
|
|
50 |
2r00000100 2r10000000
|
|
51 |
2r00001000 2r11111110
|
|
52 |
2r00010000 2r00000010
|
|
53 |
2r00100000 2r00000010
|
|
54 |
2r01000000 2r00000010
|
|
55 |
2r01000000 2r00000010
|
|
56 |
2r00100000 2r00000010
|
|
57 |
2r00010000 2r00000010
|
|
58 |
2r00001000 2r11111110
|
|
59 |
2r00000100 2r10000000
|
|
60 |
2r00000010 2r10000000
|
|
61 |
2r00000001 2r10000000
|
|
62 |
2r00000000 2r00000000)
|
|
63 |
].
|
21
|
64 |
^ DefaultScrollLeftForm
|
0
|
65 |
!
|
|
66 |
|
|
67 |
scrollRightButtonForm:style
|
21
|
68 |
DefaultScrollRightForm isNil ifTrue:[
|
|
69 |
DefaultScrollRightForm := Form fromFile:(self classResources at:'SCROLL_RIGHT_BUTTON_FORM_FILE'
|
0
|
70 |
default:(style == #mswindows
|
|
71 |
ifTrue:['ScrollRt_win.xbm']
|
|
72 |
ifFalse:['ScrollRt.xbm']))
|
|
73 |
resolution:100
|
|
74 |
].
|
21
|
75 |
DefaultScrollRightForm isNil ifTrue:[
|
|
76 |
DefaultScrollRightForm :=
|
0
|
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 |
].
|
21
|
94 |
^ DefaultScrollRightForm
|
0
|
95 |
! !
|
|
96 |
|
|
97 |
!HorizontalScrollBar methodsFor:'initialization'!
|
|
98 |
|
|
99 |
initialize
|
7
|
100 |
|bwn sep h w leftForm rightForm c|
|
0
|
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 |
|
7
|
117 |
bwn := borderWidth negated + margin.
|
0
|
118 |
self is3D ifTrue:[
|
|
119 |
sep := 1
|
|
120 |
] ifFalse:[
|
|
121 |
sep := 0
|
|
122 |
].
|
|
123 |
|
7
|
124 |
"poor design - destroy and re-create thumgs"
|
|
125 |
button1 destroy.
|
|
126 |
button2 destroy.
|
|
127 |
thumb destroy.
|
|
128 |
|
3
|
129 |
button1 := ArrowButton leftIn:self.
|
0
|
130 |
button1 name:'LeftButton'.
|
|
131 |
button1 borderWidth:borderWidth.
|
|
132 |
button1 autoRepeat.
|
|
133 |
|
7
|
134 |
thumb := HorizontalScroller in:self.
|
|
135 |
style ~~ #next ifTrue:[
|
|
136 |
thumb borderWidth:borderWidth.
|
|
137 |
].
|
|
138 |
|
3
|
139 |
button2 := ArrowButton rightIn:self.
|
0
|
140 |
button2 name:'RightButton'.
|
|
141 |
button2 borderWidth:borderWidth.
|
|
142 |
button2 autoRepeat.
|
|
143 |
|
7
|
144 |
((style == #iris) and:[Display hasGreyscales])ifTrue:[
|
|
145 |
"have to change some of Buttons defaults"
|
|
146 |
c := (Color grey:25) on:device.
|
|
147 |
button1 offLevel:2.
|
|
148 |
button2 offLevel:2.
|
|
149 |
button1 foregroundColor:c.
|
|
150 |
button1 activeForegroundColor:c.
|
|
151 |
button1 enteredForegroundColor:c.
|
|
152 |
button2 foregroundColor:c.
|
|
153 |
button2 activeForegroundColor:c.
|
|
154 |
button2 enteredForegroundColor:c.
|
|
155 |
].
|
0
|
156 |
|
|
157 |
(layout == #bottom) ifTrue:[
|
|
158 |
"buttons at left"
|
|
159 |
button1 origin:(bwn @ bwn).
|
|
160 |
button1 viewGravity:#West.
|
|
161 |
button2 origin:(button1 width @ bwn).
|
|
162 |
button2 viewGravity:#West.
|
|
163 |
thumb origin:((button1 width + borderWidth + button2 width + sep + sep) @ bwn).
|
|
164 |
thumb viewGravity:#West
|
|
165 |
] ifFalse:[
|
|
166 |
(layout == #top) ifTrue:[
|
|
167 |
"buttons at right"
|
|
168 |
button1 viewGravity:#West.
|
|
169 |
button2 viewGravity:#West.
|
|
170 |
thumb origin:(bwn @ bwn).
|
|
171 |
thumb viewGravity:#West
|
|
172 |
] ifFalse:[
|
|
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 |
! !
|
|
181 |
|
|
182 |
!HorizontalScrollBar methodsFor:'accessing'!
|
|
183 |
|
|
184 |
scrollLeftAction:aBlock
|
|
185 |
button1 action:aBlock
|
|
186 |
!
|
|
187 |
|
|
188 |
scrollRightAction:aBlock
|
|
189 |
button2 action:aBlock
|
|
190 |
! !
|
|
191 |
|
|
192 |
!HorizontalScrollBar methodsFor:'events'!
|
|
193 |
|
|
194 |
sizeChanged:how
|
7
|
195 |
|leftWidth rightWidth thumbWidth leftAndRightWidth bwn sep sep2
|
|
196 |
thumbHeight h|
|
0
|
197 |
|
|
198 |
button1 isNil ifTrue:[^ self].
|
|
199 |
button2 isNil ifTrue:[^ self].
|
|
200 |
thumb isNil ifTrue:[^ self].
|
|
201 |
|
|
202 |
leftWidth := button1 width + borderWidth.
|
|
203 |
rightWidth := button2 width + borderWidth.
|
|
204 |
leftAndRightWidth := leftWidth + rightWidth.
|
7
|
205 |
bwn := borderWidth negated + margin.
|
0
|
206 |
self is3D ifTrue:[
|
|
207 |
sep := 1
|
|
208 |
] ifFalse:[
|
|
209 |
sep := 0
|
|
210 |
].
|
|
211 |
|
|
212 |
thumbWidth := width - leftAndRightWidth - borderWidth - (sep * 3).
|
7
|
213 |
"
|
0
|
214 |
((layout ~~ #top) and:[layout ~~ #bottom]) ifTrue:[
|
|
215 |
thumbWidth := thumbWidth - borderWidth
|
|
216 |
].
|
7
|
217 |
"
|
|
218 |
layout == #around ifTrue:[
|
|
219 |
thumbWidth := thumbWidth + borderWidth
|
|
220 |
].
|
0
|
221 |
|
|
222 |
"if I become too small, hide buttons"
|
|
223 |
|
|
224 |
(width < leftAndRightWidth) ifTrue:[
|
|
225 |
button1 shown ifTrue:[
|
|
226 |
button1 hidden.
|
|
227 |
button2 hidden.
|
|
228 |
thumb hidden
|
|
229 |
]
|
|
230 |
] ifFalse:[
|
|
231 |
shown ifTrue:[
|
|
232 |
button1 shown ifFalse:[
|
|
233 |
button1 show.
|
|
234 |
button2 show.
|
|
235 |
thumb show
|
|
236 |
]
|
|
237 |
]
|
|
238 |
].
|
|
239 |
|
|
240 |
(thumbWidth < 10) ifTrue:[
|
|
241 |
thumb shown ifTrue:[
|
|
242 |
thumb hidden
|
|
243 |
]
|
|
244 |
] ifFalse:[
|
|
245 |
thumb shown ifFalse:[
|
|
246 |
button1 shown ifTrue:[
|
|
247 |
thumb show
|
|
248 |
]
|
|
249 |
]
|
|
250 |
].
|
|
251 |
|
|
252 |
"height of buttons is always my width"
|
|
253 |
|
7
|
254 |
h := height - (margin * 2).
|
|
255 |
|
|
256 |
(h ~~ button1 height) ifTrue:[
|
0
|
257 |
button1 height:height.
|
|
258 |
button2 height:height
|
|
259 |
].
|
|
260 |
|
7
|
261 |
thumbHeight := h.
|
|
262 |
style == #next ifTrue:[
|
|
263 |
thumbHeight := thumbHeight - (thumb borderWidth * 2).
|
|
264 |
thumbWidth := thumbWidth - 1
|
|
265 |
].
|
|
266 |
|
0
|
267 |
|
|
268 |
(layout == #bottom) ifTrue:[
|
|
269 |
"buttons at left"
|
7
|
270 |
thumb extent:(thumbWidth @ thumbHeight).
|
0
|
271 |
^ self
|
|
272 |
].
|
7
|
273 |
|
0
|
274 |
sep2 := sep * 2.
|
|
275 |
(layout == #top) ifTrue:[
|
|
276 |
"buttons at right"
|
|
277 |
(how == #smaller) ifTrue:[
|
7
|
278 |
thumb extent:(thumbWidth @ thumbHeight).
|
0
|
279 |
button1 origin:((thumbWidth + sep2) @ bwn).
|
|
280 |
button2 origin:((thumbWidth + sep2 + leftWidth) @ bwn)
|
|
281 |
] ifFalse:[
|
|
282 |
button1 origin:((thumbWidth + sep2) @ bwn).
|
|
283 |
button2 origin:((thumbWidth + sep2 + leftWidth) @ bwn).
|
7
|
284 |
thumb extent:(thumbWidth @ thumbHeight)
|
0
|
285 |
].
|
|
286 |
^ self
|
|
287 |
].
|
|
288 |
"button around thumb"
|
|
289 |
|
7
|
290 |
button1 origin:(bwn @ bwn).
|
0
|
291 |
button2 origin:((leftWidth + thumbWidth + sep2) @ bwn).
|
7
|
292 |
thumb extent:((thumbWidth + margin) @ thumbHeight).
|
0
|
293 |
thumb origin:((leftWidth - borderWidth + sep) @ bwn)
|
|
294 |
! !
|