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 |
View subclass:#ScrollBar
|
|
14 |
instanceVariableNames:'thumb button1 button2 layout'
|
21
|
15 |
classVariableNames:'DefaultScrollUpForm
|
|
16 |
DefaultScrollDownForm'
|
0
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Interactors'
|
|
19 |
!
|
|
20 |
|
|
21 |
ScrollBar comment:'
|
|
22 |
|
5
|
23 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
24 |
All Rights Reserved
|
|
25 |
|
|
26 |
this class implements vertical scrollbars with scroller and
|
|
27 |
2 step-scroll buttons. when moved or stepped, it performs a
|
|
28 |
predefined action.
|
|
29 |
|
21
|
30 |
$Header: /cvs/stx/stx/libwidg/ScrollBar.st,v 1.5 1994-01-08 17:27:56 claus Exp $
|
0
|
31 |
|
|
32 |
written spring/summer 89 by claus
|
|
33 |
'!
|
|
34 |
|
|
35 |
!ScrollBar class methodsFor:'defaults'!
|
|
36 |
|
|
37 |
scrollUpButtonForm:style
|
7
|
38 |
"return the form used for the scrollUp Button"
|
0
|
39 |
|
21
|
40 |
DefaultScrollUpForm isNil ifTrue:[
|
|
41 |
DefaultScrollUpForm := Form fromFile:(self classResources at:'SCROLL_UP_BUTTON_FORM_FILE'
|
0
|
42 |
default:(style == #mswindows
|
|
43 |
ifTrue:['ScrollUp_win.xbm']
|
|
44 |
ifFalse:['ScrollUp.xbm'])
|
|
45 |
)
|
|
46 |
resolution:100
|
|
47 |
].
|
21
|
48 |
DefaultScrollUpForm isNil ifTrue:[
|
|
49 |
DefaultScrollUpForm := Form width:16 height:16
|
0
|
50 |
fromArray:#(2r00000000 2r00000000
|
|
51 |
2r00000001 2r10000000
|
|
52 |
2r00000010 2r01000000
|
|
53 |
2r00000100 2r00100000
|
|
54 |
2r00001000 2r00010000
|
|
55 |
2r00010000 2r00001000
|
|
56 |
2r00100000 2r00000100
|
|
57 |
2r01000000 2r00000010
|
|
58 |
2r01111000 2r00011110
|
|
59 |
2r00001000 2r00010000
|
|
60 |
2r00001000 2r00010000
|
|
61 |
2r00001000 2r00010000
|
|
62 |
2r00001000 2r00010000
|
|
63 |
2r00001000 2r00010000
|
|
64 |
2r00001111 2r11110000
|
|
65 |
2r00000000 2r00000000)
|
|
66 |
].
|
21
|
67 |
^ DefaultScrollUpForm
|
0
|
68 |
!
|
|
69 |
|
|
70 |
scrollDownButtonForm:style
|
|
71 |
"retun the form used for the scrollDown Button"
|
|
72 |
|
21
|
73 |
DefaultScrollDownForm isNil ifTrue:[
|
|
74 |
DefaultScrollDownForm := Form fromFile:(self classResources at:'SCROLL_DOWN_BUTTON_FORM_FILE'
|
0
|
75 |
default:(style == #mswindows
|
|
76 |
ifTrue:['ScrollDn_win.xbm']
|
|
77 |
ifFalse:['ScrollDn.xbm'])
|
|
78 |
)
|
|
79 |
resolution:100
|
|
80 |
].
|
21
|
81 |
DefaultScrollDownForm isNil ifTrue:[
|
|
82 |
DefaultScrollDownForm := Form width:16 height:16
|
0
|
83 |
fromArray:#(2r00000000 2r00000000
|
|
84 |
2r00001111 2r11110000
|
|
85 |
2r00001000 2r00010000
|
|
86 |
2r00001000 2r00010000
|
|
87 |
2r00001000 2r00010000
|
|
88 |
2r00001000 2r00010000
|
|
89 |
2r00001000 2r00010000
|
|
90 |
2r01111000 2r00011110
|
|
91 |
2r01000000 2r00000010
|
|
92 |
2r00100000 2r00000100
|
|
93 |
2r00010000 2r00001000
|
|
94 |
2r00001000 2r00010000
|
|
95 |
2r00000100 2r00100000
|
|
96 |
2r00000010 2r01000000
|
|
97 |
2r00000001 2r10000000
|
|
98 |
2r00000000 2r00000000)
|
|
99 |
].
|
21
|
100 |
^ DefaultScrollDownForm
|
0
|
101 |
! !
|
|
102 |
|
|
103 |
!ScrollBar class methodsFor:'style changes'!
|
|
104 |
|
|
105 |
styleChange
|
21
|
106 |
DefaultScrollUpForm := nil.
|
|
107 |
DefaultScrollDownForm := nil
|
0
|
108 |
|
|
109 |
"ScrollBar styleChange"
|
|
110 |
! !
|
|
111 |
|
|
112 |
!ScrollBar methodsFor:'initialization'!
|
|
113 |
|
|
114 |
initialize
|
|
115 |
"setup; create the 2 buttons and a scroller"
|
|
116 |
|
7
|
117 |
|bwn sep w h upForm downForm clr|
|
0
|
118 |
|
|
119 |
super initialize.
|
21
|
120 |
button1 := ArrowButton upIn:self.
|
|
121 |
button1 name:'UpButton'.
|
|
122 |
button1 autoRepeat.
|
|
123 |
|
|
124 |
button2 := ArrowButton downIn:self.
|
|
125 |
button2 name:'DownButton'.
|
|
126 |
button2 autoRepeat.
|
|
127 |
|
|
128 |
thumb := Scroller in:self.
|
0
|
129 |
|
|
130 |
"compute my extent from sub-components"
|
3
|
131 |
|
0
|
132 |
upForm := self class scrollUpButtonForm:style.
|
|
133 |
downForm := self class scrollDownButtonForm:style.
|
3
|
134 |
|
0
|
135 |
h := upForm height + downForm height +
|
|
136 |
(1 "self defaultBorderWidth" * 2) + (Scroller defaultExtent y).
|
|
137 |
w := (upForm width) max:(downForm width).
|
|
138 |
self is3D ifTrue:[
|
|
139 |
h := h + 4.
|
|
140 |
w := w + 4
|
|
141 |
].
|
|
142 |
self extent:w @ h.
|
|
143 |
|
3
|
144 |
bwn := borderWidth negated + margin.
|
0
|
145 |
self is3D ifTrue:[
|
|
146 |
sep := 1
|
|
147 |
] ifFalse:[
|
|
148 |
sep := 0
|
|
149 |
].
|
|
150 |
|
|
151 |
button1 borderWidth:borderWidth.
|
|
152 |
|
|
153 |
style ~~ #next ifTrue:[
|
|
154 |
thumb borderWidth:borderWidth.
|
|
155 |
].
|
|
156 |
|
|
157 |
button2 borderWidth:borderWidth.
|
|
158 |
|
|
159 |
((style == #iris) and:[Display hasGreyscales])ifTrue:[
|
|
160 |
"have to change some of Buttons defaults"
|
7
|
161 |
clr := (Color grey:25) on:device.
|
0
|
162 |
button1 offLevel:2.
|
|
163 |
button2 offLevel:2.
|
7
|
164 |
button1 foregroundColor:clr.
|
|
165 |
button1 activeForegroundColor:clr.
|
|
166 |
button1 enteredForegroundColor:clr.
|
|
167 |
button2 foregroundColor:clr.
|
|
168 |
button2 activeForegroundColor:clr.
|
|
169 |
button2 enteredForegroundColor:clr.
|
0
|
170 |
].
|
|
171 |
|
|
172 |
(layout == #top) ifTrue:[
|
|
173 |
button1 origin:(bwn @ bwn).
|
|
174 |
button1 viewGravity:#North.
|
|
175 |
button2 origin:(bwn @ (button1 height)).
|
|
176 |
button2 viewGravity:#North.
|
|
177 |
thumb origin:(bwn @ (button1 height + borderWidth + button2 height + sep + sep)).
|
|
178 |
thumb viewGravity:#North
|
|
179 |
] ifFalse:[
|
|
180 |
(layout == #bottom) ifTrue:[
|
|
181 |
button1 viewGravity:#North.
|
|
182 |
button2 viewGravity:#North.
|
|
183 |
thumb origin:(bwn @ bwn).
|
|
184 |
thumb viewGravity:#North
|
|
185 |
] ifFalse:[
|
|
186 |
button1 origin:(bwn @ bwn).
|
|
187 |
button1 viewGravity:#North.
|
|
188 |
button2 viewGravity:#North.
|
|
189 |
thumb origin:(bwn @ (button1 height + sep)).
|
|
190 |
thumb viewGravity:#North
|
|
191 |
]
|
|
192 |
]
|
3
|
193 |
!
|
|
194 |
|
|
195 |
initStyle
|
7
|
196 |
|default|
|
3
|
197 |
|
|
198 |
super initStyle.
|
|
199 |
|
|
200 |
default := #bottom.
|
|
201 |
((style == #mswindows) or:[style == #motif]) ifTrue:[
|
|
202 |
default := #around.
|
|
203 |
style == #motif ifTrue:[
|
7
|
204 |
self level:-2
|
3
|
205 |
]
|
|
206 |
].
|
|
207 |
|
|
208 |
layout := resources at:'SCROLLBAR_LAYOUT' default:default.
|
0
|
209 |
! !
|
|
210 |
|
|
211 |
!ScrollBar methodsFor:'accessing'!
|
|
212 |
|
|
213 |
scrollAction:aBlock
|
|
214 |
"set the action, aBlock to be performed when the scroller is moved"
|
|
215 |
|
|
216 |
thumb scrollAction:aBlock
|
|
217 |
!
|
|
218 |
|
|
219 |
scrollUpAction:aBlock
|
|
220 |
"set the action, aBlock to be performed when the up-button is pressed"
|
|
221 |
|
|
222 |
button1 action:aBlock
|
|
223 |
!
|
|
224 |
|
|
225 |
scrollDownAction:aBlock
|
|
226 |
"set the action, aBlock to be performed when the down-button is pressed"
|
|
227 |
|
|
228 |
button2 action:aBlock
|
|
229 |
!
|
|
230 |
|
|
231 |
thumbColor:aColor
|
7
|
232 |
"set the thumbs color"
|
|
233 |
|
0
|
234 |
thumb thumbColor:aColor
|
|
235 |
!
|
|
236 |
|
|
237 |
thumbOrigin
|
7
|
238 |
"return position of (top of) thumb in percent"
|
0
|
239 |
|
|
240 |
^ thumb thumbOrigin
|
|
241 |
!
|
|
242 |
|
|
243 |
thumbOrigin:newOrigin
|
|
244 |
"set position of (top of) thumb in percent"
|
|
245 |
|
|
246 |
^ thumb thumbOrigin:newOrigin
|
|
247 |
!
|
|
248 |
|
|
249 |
thumbHeight
|
7
|
250 |
"return height of thumb in percent"
|
0
|
251 |
|
|
252 |
^ thumb thumbHeight
|
|
253 |
!
|
|
254 |
|
|
255 |
thumbHeight:newHeight
|
|
256 |
"set height of thumb in percent"
|
|
257 |
|
|
258 |
^ thumb thumbHeight:newHeight
|
|
259 |
!
|
|
260 |
|
|
261 |
thumbOrigin:newOrigin thumbHeight:newHeight
|
|
262 |
"set origin and height of thumb in percent"
|
|
263 |
|
|
264 |
^ thumb thumbOrigin:newOrigin thumbHeight:newHeight
|
|
265 |
!
|
|
266 |
|
|
267 |
setThumbFor:aView
|
|
268 |
"adjust thumb for aView"
|
|
269 |
|
|
270 |
thumb setThumbFor:aView
|
|
271 |
!
|
|
272 |
|
|
273 |
setThumbHeightFor:aView
|
|
274 |
"adjust thumbs height for aView"
|
|
275 |
|
|
276 |
thumb setThumbHeightFor:aView
|
|
277 |
!
|
|
278 |
|
|
279 |
setThumbOriginFor:aView
|
|
280 |
"adjust thumbs origin for aView"
|
|
281 |
|
|
282 |
thumb setThumbOriginFor:aView
|
|
283 |
!
|
|
284 |
|
|
285 |
asynchronousOperation
|
|
286 |
"set asynchronous-mode - scroll action is performed after movement
|
|
287 |
of scroller (i.e. when mouse-button is finally released)"
|
|
288 |
|
|
289 |
thumb asynchronousOperation
|
|
290 |
!
|
|
291 |
|
|
292 |
synchronousOperation
|
|
293 |
"set synchronous-mode - scroll action is performed for every movement
|
|
294 |
of scroller"
|
|
295 |
|
|
296 |
thumb synchronousOperation
|
|
297 |
! !
|
|
298 |
|
|
299 |
!ScrollBar methodsFor:'events'!
|
|
300 |
|
|
301 |
sizeChanged:how
|
|
302 |
"when my size changes, I have to resize/reposition the subviews"
|
|
303 |
|
|
304 |
|upHeight downHeight thumbHeight upAndDownHeight bwn sep sep2
|
3
|
305 |
thumbWidth w|
|
0
|
306 |
|
|
307 |
button1 isNil ifTrue:[^ self].
|
|
308 |
thumb isNil ifTrue:[^ self].
|
|
309 |
button2 isNil ifTrue:[^ self].
|
|
310 |
|
|
311 |
upHeight := button1 height + borderWidth.
|
|
312 |
downHeight := button2 height + borderWidth.
|
|
313 |
upAndDownHeight := upHeight + downHeight.
|
3
|
314 |
bwn := borderWidth negated + margin.
|
0
|
315 |
self is3D ifTrue:[
|
|
316 |
sep := 1
|
|
317 |
] ifFalse:[
|
|
318 |
sep := 0
|
|
319 |
].
|
|
320 |
|
|
321 |
thumbHeight := height - upAndDownHeight - borderWidth - (sep * 3).
|
3
|
322 |
"
|
0
|
323 |
((layout ~~ #top) and:[layout ~~ #bottom]) ifTrue:[
|
|
324 |
thumbHeight := thumbHeight - borderWidth
|
|
325 |
].
|
3
|
326 |
"
|
|
327 |
layout == #around ifTrue:[
|
|
328 |
thumbHeight := thumbHeight + borderWidth
|
|
329 |
].
|
0
|
330 |
|
|
331 |
"if I become too small, hide buttons and thumb"
|
|
332 |
|
|
333 |
height < (upHeight + downHeight) ifTrue:[
|
|
334 |
button1 shown ifTrue:[
|
|
335 |
button1 hidden.
|
|
336 |
button2 hidden.
|
|
337 |
thumb hidden
|
|
338 |
]
|
|
339 |
] ifFalse:[
|
|
340 |
shown ifTrue:[
|
|
341 |
button1 shown ifFalse:[
|
|
342 |
button1 show.
|
|
343 |
button2 show.
|
|
344 |
thumb show
|
|
345 |
]
|
|
346 |
]
|
|
347 |
].
|
|
348 |
|
|
349 |
(thumbHeight < 10) ifTrue:[
|
|
350 |
thumb shown ifTrue:[
|
|
351 |
thumb hidden
|
|
352 |
]
|
|
353 |
] ifFalse:[
|
|
354 |
thumb shown ifFalse:[
|
|
355 |
button1 shown ifTrue:[
|
|
356 |
thumb show
|
|
357 |
]
|
|
358 |
]
|
|
359 |
].
|
|
360 |
|
|
361 |
"width of buttons is always my width"
|
|
362 |
|
3
|
363 |
w := width - (margin * 2).
|
|
364 |
(w ~~ button1 width) ifTrue:[
|
|
365 |
button1 width:w.
|
|
366 |
button2 width:w
|
0
|
367 |
].
|
|
368 |
|
3
|
369 |
thumbWidth := w.
|
0
|
370 |
style == #next ifTrue:[
|
|
371 |
thumbWidth := thumbWidth - (thumb borderWidth * 2).
|
|
372 |
thumbHeight := thumbHeight - 1
|
|
373 |
].
|
|
374 |
|
|
375 |
(layout == #top) ifTrue:[
|
|
376 |
"buttons at top"
|
|
377 |
thumb extent:(thumbWidth @ thumbHeight).
|
|
378 |
^ self
|
|
379 |
].
|
|
380 |
|
|
381 |
sep2 := sep * 2.
|
|
382 |
(layout == #bottom) ifTrue:[
|
|
383 |
"buttons at bottom"
|
|
384 |
thumbHeight := thumbHeight + borderWidth.
|
|
385 |
(how == #smaller) ifTrue:[
|
|
386 |
thumb extent:(thumbWidth @ thumbHeight).
|
|
387 |
button1 origin:(bwn @ (thumbHeight + sep2)).
|
|
388 |
button2 origin:(bwn @ (thumbHeight + sep2 + upHeight))
|
|
389 |
] ifFalse:[
|
|
390 |
button1 origin:(bwn @ (thumbHeight + sep2)).
|
|
391 |
button2 origin:(bwn @ (thumbHeight + sep2 + upHeight)).
|
|
392 |
thumb extent:(thumbWidth @ thumbHeight)
|
|
393 |
].
|
|
394 |
^ self
|
|
395 |
].
|
|
396 |
"buttons around thumb"
|
|
397 |
|
3
|
398 |
button1 origin:(bwn @ bwn).
|
|
399 |
button2 origin:(bwn @ (upHeight + thumbHeight + sep2 "+ borderWidth")).
|
|
400 |
thumb extent:(thumbWidth @ (thumbHeight + margin)).
|
0
|
401 |
thumb origin:(bwn @ (upHeight - borderWidth + sep))
|
|
402 |
! !
|