0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
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:''
|
|
15 |
classVariableNames:'defaultScrollRightForm
|
|
16 |
defaultScrollLeftForm'
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Interactors'
|
|
19 |
!
|
|
20 |
|
|
21 |
HorizontalScrollBar comment:'
|
|
22 |
|
|
23 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
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 |
|
|
30 |
%W% %E%
|
|
31 |
|
|
32 |
written spring/summer 89 by claus
|
|
33 |
'!
|
|
34 |
|
|
35 |
!HorizontalScrollBar class methodsFor:'defaults'!
|
|
36 |
|
|
37 |
scrollLeftButtonForm:style
|
|
38 |
defaultScrollLeftForm isNil ifTrue:[
|
|
39 |
defaultScrollLeftForm := Form fromFile:(Resources at:'LEFT_BUTTON_FORM_FILE'
|
|
40 |
default:(style == #mswindows
|
|
41 |
ifTrue:['ScrollLt_win.xbm']
|
|
42 |
ifFalse:['ScrollLt.xbm']))
|
|
43 |
resolution:100
|
|
44 |
].
|
|
45 |
defaultScrollLeftForm isNil ifTrue:[
|
|
46 |
defaultScrollLeftForm :=
|
|
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 |
].
|
|
64 |
^ defaultScrollLeftForm
|
|
65 |
!
|
|
66 |
|
|
67 |
scrollRightButtonForm:style
|
|
68 |
defaultScrollRightForm isNil ifTrue:[
|
|
69 |
defaultScrollRightForm := Form fromFile:(Resources at:'RIGHT_BUTTON_FORM_FILE'
|
|
70 |
default:(style == #mswindows
|
|
71 |
ifTrue:['ScrollRt_win.xbm']
|
|
72 |
ifFalse:['ScrollRt.xbm']))
|
|
73 |
resolution:100
|
|
74 |
].
|
|
75 |
defaultScrollRightForm isNil ifTrue:[
|
|
76 |
defaultScrollRightForm :=
|
|
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 |
].
|
|
94 |
^ defaultScrollRightForm
|
|
95 |
! !
|
|
96 |
|
|
97 |
!HorizontalScrollBar methodsFor:'initialization'!
|
|
98 |
|
|
99 |
initialize
|
|
100 |
|bwn sep h w leftForm rightForm|
|
|
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 |
|
|
117 |
style == #mswindows ifTrue:[
|
|
118 |
layout := #around
|
|
119 |
] ifFalse:[
|
|
120 |
layout := defaultLayout
|
|
121 |
].
|
|
122 |
|
|
123 |
bwn := borderWidth negated.
|
|
124 |
self is3D ifTrue:[
|
|
125 |
sep := 1
|
|
126 |
] ifFalse:[
|
|
127 |
sep := 0
|
|
128 |
].
|
|
129 |
|
|
130 |
button1 form:(self class scrollLeftButtonForm:style).
|
|
131 |
button1 name:'LeftButton'.
|
|
132 |
button1 borderWidth:borderWidth.
|
|
133 |
button1 autoRepeat.
|
|
134 |
|
|
135 |
button2 form:(self class scrollRightButtonForm:style).
|
|
136 |
button2 name:'RightButton'.
|
|
137 |
button2 borderWidth:borderWidth.
|
|
138 |
button2 autoRepeat.
|
|
139 |
|
|
140 |
"poor design - destroy thumb and re-create a HScroller for it"
|
|
141 |
|
|
142 |
thumb destroy.
|
|
143 |
thumb := HorizontalScroller in:self.
|
|
144 |
thumb borderWidth:borderWidth.
|
|
145 |
|
|
146 |
(layout == #bottom) ifTrue:[
|
|
147 |
"buttons at left"
|
|
148 |
button1 origin:(bwn @ bwn).
|
|
149 |
button1 viewGravity:#West.
|
|
150 |
button2 origin:(button1 width @ bwn).
|
|
151 |
button2 viewGravity:#West.
|
|
152 |
thumb origin:((button1 width + borderWidth + button2 width + sep + sep) @ bwn).
|
|
153 |
thumb viewGravity:#West
|
|
154 |
] ifFalse:[
|
|
155 |
(layout == #top) ifTrue:[
|
|
156 |
"buttons at right"
|
|
157 |
button1 viewGravity:#West.
|
|
158 |
button2 viewGravity:#West.
|
|
159 |
thumb origin:(bwn @ bwn).
|
|
160 |
thumb viewGravity:#West
|
|
161 |
] ifFalse:[
|
|
162 |
button1 origin:(bwn @ bwn).
|
|
163 |
button1 viewGravity:#West.
|
|
164 |
button2 viewGravity:#West.
|
|
165 |
thumb origin:((button1 width + sep) @ bwn).
|
|
166 |
thumb viewGravity:#West
|
|
167 |
]
|
|
168 |
]
|
|
169 |
! !
|
|
170 |
|
|
171 |
!HorizontalScrollBar methodsFor:'accessing'!
|
|
172 |
|
|
173 |
scrollLeftAction:aBlock
|
|
174 |
button1 action:aBlock
|
|
175 |
!
|
|
176 |
|
|
177 |
scrollRightAction:aBlock
|
|
178 |
button2 action:aBlock
|
|
179 |
! !
|
|
180 |
|
|
181 |
!HorizontalScrollBar methodsFor:'events'!
|
|
182 |
|
|
183 |
sizeChanged:how
|
|
184 |
|leftWidth rightWidth thumbWidth leftAndRightWidth bwn sep sep2|
|
|
185 |
|
|
186 |
button1 isNil ifTrue:[^ self].
|
|
187 |
button2 isNil ifTrue:[^ self].
|
|
188 |
thumb isNil ifTrue:[^ self].
|
|
189 |
|
|
190 |
leftWidth := button1 width + borderWidth.
|
|
191 |
rightWidth := button2 width + borderWidth.
|
|
192 |
leftAndRightWidth := leftWidth + rightWidth.
|
|
193 |
bwn := borderWidth negated.
|
|
194 |
self is3D ifTrue:[
|
|
195 |
sep := 1
|
|
196 |
] ifFalse:[
|
|
197 |
sep := 0
|
|
198 |
].
|
|
199 |
|
|
200 |
thumbWidth := width - leftAndRightWidth - borderWidth - (sep * 3).
|
|
201 |
((layout ~~ #top) and:[layout ~~ #bottom]) ifTrue:[
|
|
202 |
thumbWidth := thumbWidth - borderWidth
|
|
203 |
].
|
|
204 |
|
|
205 |
"if I become too small, hide buttons"
|
|
206 |
|
|
207 |
(width < leftAndRightWidth) ifTrue:[
|
|
208 |
button1 shown ifTrue:[
|
|
209 |
button1 hidden.
|
|
210 |
button2 hidden.
|
|
211 |
thumb hidden
|
|
212 |
]
|
|
213 |
] ifFalse:[
|
|
214 |
shown ifTrue:[
|
|
215 |
button1 shown ifFalse:[
|
|
216 |
button1 show.
|
|
217 |
button2 show.
|
|
218 |
thumb show
|
|
219 |
]
|
|
220 |
]
|
|
221 |
].
|
|
222 |
|
|
223 |
(thumbWidth < 10) ifTrue:[
|
|
224 |
thumb shown ifTrue:[
|
|
225 |
thumb hidden
|
|
226 |
]
|
|
227 |
] ifFalse:[
|
|
228 |
thumb shown ifFalse:[
|
|
229 |
button1 shown ifTrue:[
|
|
230 |
thumb show
|
|
231 |
]
|
|
232 |
]
|
|
233 |
].
|
|
234 |
|
|
235 |
"height of buttons is always my width"
|
|
236 |
|
|
237 |
(height ~~ button1 height) ifTrue:[
|
|
238 |
button1 height:height.
|
|
239 |
button2 height:height
|
|
240 |
].
|
|
241 |
|
|
242 |
"thumb height:height. "
|
|
243 |
|
|
244 |
(layout == #bottom) ifTrue:[
|
|
245 |
"buttons at left"
|
|
246 |
thumb extent:(thumbWidth @ height).
|
|
247 |
^ self
|
|
248 |
].
|
|
249 |
sep2 := sep * 2.
|
|
250 |
(layout == #top) ifTrue:[
|
|
251 |
"buttons at right"
|
|
252 |
(how == #smaller) ifTrue:[
|
|
253 |
thumb extent:(thumbWidth @ height).
|
|
254 |
button1 origin:((thumbWidth + sep2) @ bwn).
|
|
255 |
button2 origin:((thumbWidth + sep2 + leftWidth) @ bwn)
|
|
256 |
] ifFalse:[
|
|
257 |
button1 origin:((thumbWidth + sep2) @ bwn).
|
|
258 |
button2 origin:((thumbWidth + sep2 + leftWidth) @ bwn).
|
|
259 |
thumb extent:(thumbWidth @ height)
|
|
260 |
].
|
|
261 |
^ self
|
|
262 |
].
|
|
263 |
"button around thumb"
|
|
264 |
|
|
265 |
button2 origin:((leftWidth + thumbWidth + sep2) @ bwn).
|
|
266 |
thumb extent:(thumbWidth @ height).
|
|
267 |
thumb origin:((leftWidth - borderWidth + sep) @ bwn)
|
|
268 |
! !
|