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
|
205
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Interactors'
|
0
|
18 |
!
|
|
19 |
|
38
|
20 |
!HorizontalScrollBar class methodsFor:'documentation'!
|
|
21 |
|
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
25 |
All Rights Reserved
|
0
|
26 |
|
38
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
0
|
34 |
!
|
|
35 |
|
38
|
36 |
documentation
|
|
37 |
"
|
|
38 |
this class implements horizontal scrollbars with scroller and
|
116
|
39 |
2 step-scroll buttons. When moved or stepped, it performs a
|
38
|
40 |
predefined action.
|
|
41 |
"
|
0
|
42 |
! !
|
|
43 |
|
127
|
44 |
!HorizontalScrollBar methodsFor:'accessing-behavior'!
|
0
|
45 |
|
38
|
46 |
scrollLeftAction
|
60
|
47 |
"return the action which is performed on scroll-left"
|
|
48 |
|
38
|
49 |
^ button1 action
|
|
50 |
!
|
|
51 |
|
0
|
52 |
scrollLeftAction:aBlock
|
60
|
53 |
"set the action to be performed on scroll-left"
|
|
54 |
|
0
|
55 |
button1 action:aBlock
|
|
56 |
!
|
|
57 |
|
38
|
58 |
scrollRightAction
|
60
|
59 |
"return the action which is performed on scroll-right"
|
|
60 |
|
38
|
61 |
^ button2 action
|
|
62 |
!
|
|
63 |
|
0
|
64 |
scrollRightAction:aBlock
|
60
|
65 |
"set the action to be performed on scroll-right"
|
|
66 |
|
0
|
67 |
button2 action:aBlock
|
|
68 |
! !
|
|
69 |
|
70
|
70 |
!HorizontalScrollBar methodsFor:'event handling'!
|
0
|
71 |
|
|
72 |
sizeChanged:how
|
60
|
73 |
"handle changed size - reposition elements"
|
|
74 |
|
59
|
75 |
|leftWidth rightWidth thumbWidth leftAndRightWidth bwn sep2
|
130
|
76 |
thumbHeight h style b1Hidden b2Hidden thumbHidden bX|
|
0
|
77 |
|
|
78 |
button1 isNil ifTrue:[^ self].
|
|
79 |
button2 isNil ifTrue:[^ self].
|
|
80 |
thumb isNil ifTrue:[^ self].
|
|
81 |
|
|
82 |
leftWidth := button1 width + borderWidth.
|
|
83 |
rightWidth := button2 width + borderWidth.
|
|
84 |
leftAndRightWidth := leftWidth + rightWidth.
|
7
|
85 |
bwn := borderWidth negated + margin.
|
0
|
86 |
|
59
|
87 |
thumbWidth := width - leftAndRightWidth - borderWidth - (elementSpacing * 3).
|
7
|
88 |
"
|
130
|
89 |
((buttonLayout ~~ #top) and:[buttonLayout ~~ #bottom]) ifTrue:[
|
59
|
90 |
thumbWidth := thumbWidth - borderWidth
|
0
|
91 |
].
|
7
|
92 |
"
|
130
|
93 |
buttonLayout == #around ifTrue:[
|
59
|
94 |
thumbWidth := thumbWidth + borderWidth
|
7
|
95 |
].
|
0
|
96 |
|
|
97 |
"if I become too small, hide buttons"
|
|
98 |
|
130
|
99 |
width < leftAndRightWidth ifTrue:[
|
|
100 |
b1Hidden := b2Hidden := thumbHidden := true.
|
0
|
101 |
] ifFalse:[
|
130
|
102 |
b1Hidden := b2Hidden := thumbHidden := false.
|
0
|
103 |
].
|
|
104 |
|
|
105 |
(thumbWidth < 10) ifTrue:[
|
130
|
106 |
thumbHidden := true.
|
|
107 |
] ifFalse:[
|
|
108 |
thumbHidden := false.
|
|
109 |
].
|
|
110 |
|
|
111 |
button1 hiddenOnRealize:b1Hidden.
|
|
112 |
b1Hidden ifTrue:[
|
|
113 |
button1 unrealize
|
0
|
114 |
] ifFalse:[
|
130
|
115 |
shown ifTrue:[button1 realize]
|
|
116 |
].
|
|
117 |
button2 hiddenOnRealize:b1Hidden.
|
|
118 |
b2Hidden ifTrue:[
|
|
119 |
button2 unrealize
|
|
120 |
] ifFalse:[
|
|
121 |
shown ifTrue:[button2 realize]
|
|
122 |
].
|
|
123 |
thumb hiddenOnRealize:thumbHidden.
|
|
124 |
thumbHidden ifTrue:[
|
|
125 |
thumb unrealize
|
|
126 |
] ifFalse:[
|
|
127 |
shown ifTrue:[thumb realize]
|
0
|
128 |
].
|
|
129 |
|
|
130 |
"height of buttons is always my width"
|
|
131 |
|
7
|
132 |
h := height - (margin * 2).
|
|
133 |
|
|
134 |
(h ~~ button1 height) ifTrue:[
|
59
|
135 |
button1 height:h.
|
|
136 |
button2 height:h
|
0
|
137 |
].
|
|
138 |
|
7
|
139 |
thumbHeight := h.
|
130
|
140 |
style := styleSheet name.
|
7
|
141 |
style == #next ifTrue:[
|
59
|
142 |
thumbHeight := thumbHeight - (thumb borderWidth * 2).
|
|
143 |
thumbWidth := thumbWidth - 1
|
7
|
144 |
].
|
63
|
145 |
style == #motif ifTrue:[
|
|
146 |
thumbWidth := thumbWidth - margin
|
|
147 |
].
|
0
|
148 |
|
38
|
149 |
"
|
|
150 |
a kludge: views with width or height of 0 are illegal
|
|
151 |
avoid error from view-creation (it will be hidden anyway)
|
|
152 |
"
|
|
153 |
thumbWidth <= 0 ifTrue:[
|
59
|
154 |
thumbWidth := 1
|
38
|
155 |
].
|
|
156 |
|
130
|
157 |
(buttonLayout == #bottom) ifTrue:[
|
59
|
158 |
"buttons at left"
|
|
159 |
thumb extent:(thumbWidth @ thumbHeight).
|
|
160 |
^ self
|
0
|
161 |
].
|
7
|
162 |
|
59
|
163 |
sep2 := elementSpacing * 2.
|
130
|
164 |
(buttonLayout == #top) ifTrue:[
|
59
|
165 |
"buttons at right"
|
|
166 |
thumbWidth := thumbWidth + borderWidth.
|
130
|
167 |
thumbHidden ifTrue:[
|
|
168 |
bX := elementSpacing
|
|
169 |
] ifFalse:[
|
|
170 |
bX := thumbWidth + sep2.
|
|
171 |
].
|
59
|
172 |
(how == #smaller) ifTrue:[
|
|
173 |
thumb extent:(thumbWidth @ thumbHeight).
|
130
|
174 |
button1 origin:(bX @ bwn).
|
|
175 |
button2 origin:((bX + leftWidth) @ bwn)
|
59
|
176 |
] ifFalse:[
|
130
|
177 |
button1 origin:(bX @ bwn).
|
|
178 |
button2 origin:((bX + leftWidth) @ bwn).
|
59
|
179 |
thumb extent:(thumbWidth @ thumbHeight)
|
|
180 |
].
|
|
181 |
^ self
|
0
|
182 |
].
|
|
183 |
"button around thumb"
|
|
184 |
|
128
|
185 |
style == #motif ifTrue:[
|
|
186 |
sep2 := sep2 + 1
|
|
187 |
].
|
|
188 |
|
7
|
189 |
button1 origin:(bwn @ bwn).
|
128
|
190 |
style == #os2 ifTrue:[
|
|
191 |
button2 origin:((leftWidth + thumbWidth + sep2 - margin) @ bwn).
|
|
192 |
thumb extent:((thumbWidth - margin - margin) @ thumbHeight).
|
|
193 |
thumb origin:((leftWidth - borderWidth + elementSpacing + margin) @ bwn)
|
|
194 |
] ifFalse:[
|
|
195 |
button2 origin:((leftWidth + thumbWidth + sep2 - (margin // 2)) @ bwn).
|
|
196 |
thumb extent:((thumbWidth + margin - (margin // 2)) @ thumbHeight).
|
|
197 |
thumb origin:((leftWidth - borderWidth + elementSpacing) @ bwn)
|
|
198 |
].
|
0
|
199 |
! !
|
205
|
200 |
|
|
201 |
!HorizontalScrollBar methodsFor:'initialization'!
|
|
202 |
|
|
203 |
createElements
|
|
204 |
"private: create my elements"
|
|
205 |
|
|
206 |
button1 := ArrowButton leftIn:self.
|
|
207 |
button2 := ArrowButton rightIn:self.
|
|
208 |
thumb := HorizontalScroller in:self.
|
|
209 |
!
|
|
210 |
|
|
211 |
setElementPositions
|
|
212 |
"position sub-components"
|
|
213 |
|
|
214 |
|bwn|
|
|
215 |
|
|
216 |
bwn := borderWidth negated + margin.
|
|
217 |
|
|
218 |
(buttonLayout == #bottom) ifTrue:[
|
|
219 |
"buttons at left"
|
|
220 |
button1 origin:(bwn @ bwn).
|
|
221 |
button1 viewGravity:#West.
|
|
222 |
button2 origin:(button1 width @ bwn).
|
|
223 |
button2 viewGravity:#West.
|
|
224 |
thumb origin:((button1 width
|
|
225 |
+ borderWidth
|
|
226 |
+ button2 width
|
|
227 |
+ elementSpacing + elementSpacing) @ bwn).
|
|
228 |
thumb viewGravity:#West.
|
|
229 |
^ self
|
|
230 |
].
|
|
231 |
|
|
232 |
(buttonLayout == #top) ifTrue:[
|
|
233 |
"buttons at right"
|
|
234 |
button1 viewGravity:#West.
|
|
235 |
button2 viewGravity:#West.
|
|
236 |
thumb origin:(bwn @ bwn).
|
|
237 |
thumb viewGravity:#West
|
|
238 |
].
|
|
239 |
|
|
240 |
"buttonLayout == #around "
|
|
241 |
button1 origin:(bwn @ bwn).
|
|
242 |
button1 viewGravity:#West.
|
|
243 |
button2 viewGravity:#West.
|
|
244 |
thumb origin:((button1 width + elementSpacing) @ bwn).
|
|
245 |
thumb viewGravity:#West
|
|
246 |
! !
|
|
247 |
|
|
248 |
!HorizontalScrollBar methodsFor:'queries'!
|
|
249 |
|
|
250 |
preferredExtent
|
|
251 |
"compute my extent from sub-components"
|
|
252 |
|
|
253 |
|w h leftForm rightForm wLeft hLeft wRight hRight style|
|
|
254 |
|
|
255 |
"need fix - this is a kludge;
|
|
256 |
the if should not be needed ..."
|
|
257 |
style := styleSheet name.
|
|
258 |
style == #mswindows ifTrue:[
|
|
259 |
h := button1 height max:button2 height.
|
|
260 |
w := button1 width + button2 width + (Scroller defaultExtent x).
|
|
261 |
] ifFalse:[
|
|
262 |
leftForm := ArrowButton leftArrowButtonForm:style on:device.
|
|
263 |
rightForm := ArrowButton rightArrowButtonForm:style on:device.
|
|
264 |
"
|
|
265 |
just in case ...
|
|
266 |
"
|
|
267 |
leftForm isNil ifTrue:[
|
|
268 |
wLeft := hLeft := 16
|
|
269 |
] ifFalse:[
|
|
270 |
wLeft := leftForm width.
|
|
271 |
hLeft := leftForm height
|
|
272 |
].
|
|
273 |
rightForm isNil ifTrue:[
|
|
274 |
wRight := hRight := 16
|
|
275 |
] ifFalse:[
|
|
276 |
wRight := rightForm width.
|
|
277 |
hRight := rightForm height
|
|
278 |
].
|
|
279 |
w := wLeft + wRight + (1 * 2) + (HorizontalScroller defaultExtent x).
|
|
280 |
h := hLeft max:hRight.
|
|
281 |
(style ~~ #normal) ifTrue:[
|
|
282 |
h := h + 4.
|
|
283 |
w := w + 4
|
|
284 |
].
|
|
285 |
].
|
|
286 |
^ w @ h.
|
|
287 |
! !
|
|
288 |
|
|
289 |
!HorizontalScrollBar class methodsFor:'documentation'!
|
|
290 |
|
|
291 |
version
|
|
292 |
^ '$Header: /cvs/stx/stx/libwidg/HorizontalScrollBar.st,v 1.16 1995-11-23 18:18:49 cg Exp $'
|
|
293 |
! !
|