0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
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
|
59
|
22 |
All Rights Reserved
|
0
|
23 |
|
70
|
24 |
$Header: /cvs/stx/stx/libwidg/HorizontalScrollBar.st,v 1.10 1994-11-28 21:05:01 claus Exp $
|
0
|
25 |
'!
|
|
26 |
|
38
|
27 |
!HorizontalScrollBar class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
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 |
"
|
70
|
45 |
$Header: /cvs/stx/stx/libwidg/HorizontalScrollBar.st,v 1.10 1994-11-28 21:05:01 claus Exp $
|
38
|
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
|
60 |
"private: create my elements"
|
|
61 |
|
38
|
62 |
button1 := ArrowButton leftIn:self.
|
|
63 |
button2 := ArrowButton rightIn:self.
|
|
64 |
thumb := HorizontalScroller in:self.
|
|
65 |
!
|
0
|
66 |
|
38
|
67 |
computeInitialExtent
|
0
|
68 |
"compute my extent from sub-components"
|
38
|
69 |
|
59
|
70 |
|w h leftForm rightForm wLeft hLeft wRight hRight|
|
38
|
71 |
|
|
72 |
"need fix - this is a kludge;
|
|
73 |
the if should not be needed ..."
|
|
74 |
style == #mswindows ifTrue:[
|
59
|
75 |
h := button1 height max:button2 height.
|
|
76 |
w := button1 width + button2 width + (Scroller defaultExtent x).
|
38
|
77 |
] ifFalse:[
|
59
|
78 |
leftForm := ArrowButton leftArrowButtonForm:style on:device.
|
|
79 |
rightForm := ArrowButton rightArrowButtonForm:style on:device.
|
|
80 |
"
|
|
81 |
just in case ...
|
|
82 |
"
|
|
83 |
leftForm isNil ifTrue:[
|
|
84 |
wLeft := hLeft := 16
|
|
85 |
] ifFalse:[
|
|
86 |
wLeft := leftForm width.
|
|
87 |
hLeft := leftForm height
|
|
88 |
].
|
|
89 |
rightForm isNil ifTrue:[
|
|
90 |
wRight := hRight := 16
|
|
91 |
] ifFalse:[
|
|
92 |
wRight := rightForm width.
|
|
93 |
hRight := rightForm height
|
|
94 |
].
|
|
95 |
w := wLeft + wRight + (1 * 2) + (HorizontalScroller defaultExtent x).
|
|
96 |
h := hLeft max:hRight.
|
|
97 |
(style ~~ #normal) ifTrue:[
|
|
98 |
h := h + 4.
|
|
99 |
w := w + 4
|
|
100 |
].
|
0
|
101 |
].
|
|
102 |
self extent:w @ h.
|
38
|
103 |
!
|
|
104 |
|
|
105 |
setElementPositions
|
|
106 |
"position sub-components"
|
|
107 |
|
59
|
108 |
|bwn|
|
0
|
109 |
|
7
|
110 |
bwn := borderWidth negated + margin.
|
0
|
111 |
|
|
112 |
(layout == #bottom) ifTrue:[
|
59
|
113 |
"buttons at left"
|
|
114 |
button1 origin:(bwn @ bwn).
|
|
115 |
button1 viewGravity:#West.
|
|
116 |
button2 origin:(button1 width @ bwn).
|
|
117 |
button2 viewGravity:#West.
|
|
118 |
thumb origin:((button1 width
|
|
119 |
+ borderWidth
|
|
120 |
+ button2 width
|
|
121 |
+ elementSpacing + elementSpacing) @ bwn).
|
|
122 |
thumb viewGravity:#West.
|
|
123 |
^ self
|
38
|
124 |
].
|
|
125 |
|
|
126 |
(layout == #top) ifTrue:[
|
59
|
127 |
"buttons at right"
|
|
128 |
button1 viewGravity:#West.
|
|
129 |
button2 viewGravity:#West.
|
|
130 |
thumb origin:(bwn @ bwn).
|
|
131 |
thumb viewGravity:#West
|
38
|
132 |
].
|
|
133 |
|
|
134 |
"layout == #around "
|
|
135 |
button1 origin:(bwn @ bwn).
|
|
136 |
button1 viewGravity:#West.
|
|
137 |
button2 viewGravity:#West.
|
59
|
138 |
thumb origin:((button1 width + elementSpacing) @ bwn).
|
38
|
139 |
thumb viewGravity:#West
|
0
|
140 |
! !
|
|
141 |
|
|
142 |
!HorizontalScrollBar methodsFor:'accessing'!
|
|
143 |
|
38
|
144 |
scrollLeftAction
|
60
|
145 |
"return the action which is performed on scroll-left"
|
|
146 |
|
38
|
147 |
^ button1 action
|
|
148 |
!
|
|
149 |
|
0
|
150 |
scrollLeftAction:aBlock
|
60
|
151 |
"set the action to be performed on scroll-left"
|
|
152 |
|
0
|
153 |
button1 action:aBlock
|
|
154 |
!
|
|
155 |
|
38
|
156 |
scrollRightAction
|
60
|
157 |
"return the action which is performed on scroll-right"
|
|
158 |
|
38
|
159 |
^ button2 action
|
|
160 |
!
|
|
161 |
|
0
|
162 |
scrollRightAction:aBlock
|
60
|
163 |
"set the action to be performed on scroll-right"
|
|
164 |
|
0
|
165 |
button2 action:aBlock
|
|
166 |
! !
|
|
167 |
|
70
|
168 |
!HorizontalScrollBar methodsFor:'event handling'!
|
0
|
169 |
|
|
170 |
sizeChanged:how
|
60
|
171 |
"handle changed size - reposition elements"
|
|
172 |
|
59
|
173 |
|leftWidth rightWidth thumbWidth leftAndRightWidth bwn sep2
|
7
|
174 |
thumbHeight h|
|
0
|
175 |
|
|
176 |
button1 isNil ifTrue:[^ self].
|
|
177 |
button2 isNil ifTrue:[^ self].
|
|
178 |
thumb isNil ifTrue:[^ self].
|
|
179 |
|
|
180 |
leftWidth := button1 width + borderWidth.
|
|
181 |
rightWidth := button2 width + borderWidth.
|
|
182 |
leftAndRightWidth := leftWidth + rightWidth.
|
7
|
183 |
bwn := borderWidth negated + margin.
|
0
|
184 |
|
59
|
185 |
thumbWidth := width - leftAndRightWidth - borderWidth - (elementSpacing * 3).
|
7
|
186 |
"
|
0
|
187 |
((layout ~~ #top) and:[layout ~~ #bottom]) ifTrue:[
|
59
|
188 |
thumbWidth := thumbWidth - borderWidth
|
0
|
189 |
].
|
7
|
190 |
"
|
|
191 |
layout == #around ifTrue:[
|
59
|
192 |
thumbWidth := thumbWidth + borderWidth
|
7
|
193 |
].
|
0
|
194 |
|
|
195 |
"if I become too small, hide buttons"
|
|
196 |
|
|
197 |
(width < leftAndRightWidth) ifTrue:[
|
59
|
198 |
button1 shown ifTrue:[
|
|
199 |
button1 hidden.
|
|
200 |
button2 hidden.
|
|
201 |
thumb hidden
|
|
202 |
]
|
0
|
203 |
] ifFalse:[
|
59
|
204 |
shown ifTrue:[
|
|
205 |
button1 shown ifFalse:[
|
|
206 |
button1 show.
|
|
207 |
button2 show.
|
|
208 |
thumb show
|
|
209 |
]
|
|
210 |
]
|
0
|
211 |
].
|
|
212 |
|
|
213 |
(thumbWidth < 10) ifTrue:[
|
59
|
214 |
thumb shown ifTrue:[
|
|
215 |
thumb hidden
|
|
216 |
]
|
0
|
217 |
] ifFalse:[
|
59
|
218 |
thumb shown ifFalse:[
|
|
219 |
button1 shown ifTrue:[
|
|
220 |
thumb show
|
|
221 |
]
|
|
222 |
]
|
0
|
223 |
].
|
|
224 |
|
|
225 |
"height of buttons is always my width"
|
|
226 |
|
7
|
227 |
h := height - (margin * 2).
|
|
228 |
|
|
229 |
(h ~~ button1 height) ifTrue:[
|
59
|
230 |
button1 height:h.
|
|
231 |
button2 height:h
|
0
|
232 |
].
|
|
233 |
|
7
|
234 |
thumbHeight := h.
|
|
235 |
style == #next ifTrue:[
|
59
|
236 |
thumbHeight := thumbHeight - (thumb borderWidth * 2).
|
|
237 |
thumbWidth := thumbWidth - 1
|
7
|
238 |
].
|
63
|
239 |
style == #motif ifTrue:[
|
|
240 |
thumbWidth := thumbWidth - margin
|
|
241 |
].
|
0
|
242 |
|
38
|
243 |
"
|
|
244 |
a kludge: views with width or height of 0 are illegal
|
|
245 |
avoid error from view-creation (it will be hidden anyway)
|
|
246 |
"
|
|
247 |
thumbWidth <= 0 ifTrue:[
|
59
|
248 |
thumbWidth := 1
|
38
|
249 |
].
|
|
250 |
|
0
|
251 |
(layout == #bottom) ifTrue:[
|
59
|
252 |
"buttons at left"
|
|
253 |
thumb extent:(thumbWidth @ thumbHeight).
|
|
254 |
^ self
|
0
|
255 |
].
|
7
|
256 |
|
59
|
257 |
sep2 := elementSpacing * 2.
|
0
|
258 |
(layout == #top) ifTrue:[
|
59
|
259 |
"buttons at right"
|
|
260 |
thumbWidth := thumbWidth + borderWidth.
|
|
261 |
(how == #smaller) ifTrue:[
|
|
262 |
thumb extent:(thumbWidth @ thumbHeight).
|
|
263 |
button1 origin:((thumbWidth + sep2) @ bwn).
|
|
264 |
button2 origin:((thumbWidth + sep2 + leftWidth) @ bwn)
|
|
265 |
] ifFalse:[
|
|
266 |
button1 origin:((thumbWidth + sep2) @ bwn).
|
|
267 |
button2 origin:((thumbWidth + sep2 + leftWidth) @ bwn).
|
|
268 |
thumb extent:(thumbWidth @ thumbHeight)
|
|
269 |
].
|
|
270 |
^ self
|
0
|
271 |
].
|
|
272 |
"button around thumb"
|
|
273 |
|
63
|
274 |
style == #motif ifTrue:[
|
|
275 |
sep2 := sep2 + 1
|
|
276 |
].
|
7
|
277 |
button1 origin:(bwn @ bwn).
|
38
|
278 |
button2 origin:((leftWidth + thumbWidth + sep2 - (margin // 2)) @ bwn).
|
|
279 |
thumb extent:((thumbWidth + margin - (margin // 2)) @ thumbHeight).
|
59
|
280 |
thumb origin:((leftWidth - borderWidth + elementSpacing) @ bwn)
|
0
|
281 |
! !
|