author | Claus Gittinger <cg@exept.de> |
Fri, 17 Jan 1997 23:24:42 +0100 | |
changeset 958 | b75025112346 |
parent 797 | 2f9cd56f48ee |
child 1007 | a482384cda45 |
permissions | -rw-r--r-- |
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 |
|
585 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Views-Interactors' |
|
0 | 18 |
! |
19 |
||
958 | 20 |
!HorizontalScrollBar class methodsFor:'documentation'! |
38 | 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. |
585 | 41 |
|
42 |
[author:] |
|
43 |
Claus Gittinger |
|
38 | 44 |
" |
0 | 45 |
! ! |
46 |
||
127 | 47 |
!HorizontalScrollBar methodsFor:'accessing-behavior'! |
0 | 48 |
|
38 | 49 |
scrollLeftAction |
60 | 50 |
"return the action which is performed on scroll-left" |
51 |
||
38 | 52 |
^ button1 action |
53 |
! |
|
54 |
||
0 | 55 |
scrollLeftAction:aBlock |
60 | 56 |
"set the action to be performed on scroll-left" |
57 |
||
0 | 58 |
button1 action:aBlock |
59 |
! |
|
60 |
||
38 | 61 |
scrollRightAction |
60 | 62 |
"return the action which is performed on scroll-right" |
63 |
||
38 | 64 |
^ button2 action |
65 |
! |
|
66 |
||
0 | 67 |
scrollRightAction:aBlock |
60 | 68 |
"set the action to be performed on scroll-right" |
69 |
||
0 | 70 |
button2 action:aBlock |
71 |
! ! |
|
72 |
||
70 | 73 |
!HorizontalScrollBar methodsFor:'event handling'! |
0 | 74 |
|
75 |
sizeChanged:how |
|
958 | 76 |
"my size has changed somehow - reposition the components" |
77 |
||
762 | 78 |
<resource: #style (#name)> |
79 |
||
60 | 80 |
"handle changed size - reposition elements" |
81 |
||
59 | 82 |
|leftWidth rightWidth thumbWidth leftAndRightWidth bwn sep2 |
130 | 83 |
thumbHeight h style b1Hidden b2Hidden thumbHidden bX| |
0 | 84 |
|
85 |
button1 isNil ifTrue:[^ self]. |
|
86 |
button2 isNil ifTrue:[^ self]. |
|
87 |
thumb isNil ifTrue:[^ self]. |
|
88 |
||
89 |
leftWidth := button1 width + borderWidth. |
|
90 |
rightWidth := button2 width + borderWidth. |
|
91 |
leftAndRightWidth := leftWidth + rightWidth. |
|
7 | 92 |
bwn := borderWidth negated + margin. |
0 | 93 |
|
59 | 94 |
thumbWidth := width - leftAndRightWidth - borderWidth - (elementSpacing * 3). |
7 | 95 |
" |
130 | 96 |
((buttonLayout ~~ #top) and:[buttonLayout ~~ #bottom]) ifTrue:[ |
612 | 97 |
thumbWidth := thumbWidth - borderWidth |
0 | 98 |
]. |
7 | 99 |
" |
130 | 100 |
buttonLayout == #around ifTrue:[ |
612 | 101 |
thumbWidth := thumbWidth + borderWidth |
7 | 102 |
]. |
0 | 103 |
|
104 |
"if I become too small, hide buttons" |
|
105 |
||
130 | 106 |
width < leftAndRightWidth ifTrue:[ |
612 | 107 |
b1Hidden := b2Hidden := thumbHidden := true. |
0 | 108 |
] ifFalse:[ |
612 | 109 |
b1Hidden := b2Hidden := thumbHidden := false. |
0 | 110 |
]. |
111 |
||
112 |
(thumbWidth < 10) ifTrue:[ |
|
612 | 113 |
thumbHidden := true. |
130 | 114 |
] ifFalse:[ |
612 | 115 |
thumbHidden := false. |
130 | 116 |
]. |
117 |
||
118 |
button1 hiddenOnRealize:b1Hidden. |
|
119 |
b1Hidden ifTrue:[ |
|
612 | 120 |
button1 unmap |
0 | 121 |
] ifFalse:[ |
612 | 122 |
shown ifTrue:[button1 realize] |
130 | 123 |
]. |
124 |
button2 hiddenOnRealize:b1Hidden. |
|
125 |
b2Hidden ifTrue:[ |
|
612 | 126 |
button2 unmap |
130 | 127 |
] ifFalse:[ |
612 | 128 |
shown ifTrue:[button2 realize] |
130 | 129 |
]. |
130 |
thumb hiddenOnRealize:thumbHidden. |
|
131 |
thumbHidden ifTrue:[ |
|
612 | 132 |
thumb unmap |
130 | 133 |
] ifFalse:[ |
612 | 134 |
shown ifTrue:[thumb realize] |
0 | 135 |
]. |
136 |
||
137 |
"height of buttons is always my width" |
|
138 |
||
7 | 139 |
h := height - (margin * 2). |
140 |
||
141 |
(h ~~ button1 height) ifTrue:[ |
|
612 | 142 |
button1 height:h. |
143 |
button2 height:h |
|
0 | 144 |
]. |
145 |
||
7 | 146 |
thumbHeight := h. |
130 | 147 |
style := styleSheet name. |
7 | 148 |
style == #next ifTrue:[ |
612 | 149 |
thumbHeight := thumbHeight - (thumb borderWidth * 2). |
150 |
thumbWidth := thumbWidth - 1 |
|
7 | 151 |
]. |
63 | 152 |
style == #motif ifTrue:[ |
612 | 153 |
thumbWidth := thumbWidth - margin |
63 | 154 |
]. |
0 | 155 |
|
38 | 156 |
" |
157 |
a kludge: views with width or height of 0 are illegal |
|
158 |
avoid error from view-creation (it will be hidden anyway) |
|
159 |
" |
|
160 |
thumbWidth <= 0 ifTrue:[ |
|
612 | 161 |
thumbWidth := 1 |
38 | 162 |
]. |
163 |
||
130 | 164 |
(buttonLayout == #bottom) ifTrue:[ |
612 | 165 |
"buttons at left" |
166 |
thumb extent:(thumbWidth @ thumbHeight). |
|
167 |
^ self |
|
0 | 168 |
]. |
7 | 169 |
|
59 | 170 |
sep2 := elementSpacing * 2. |
130 | 171 |
(buttonLayout == #top) ifTrue:[ |
612 | 172 |
"buttons at right" |
173 |
thumbWidth := thumbWidth + borderWidth. |
|
174 |
thumbHidden ifTrue:[ |
|
175 |
bX := elementSpacing |
|
176 |
] ifFalse:[ |
|
177 |
bX := thumbWidth + sep2. |
|
178 |
]. |
|
179 |
(how == #smaller) ifTrue:[ |
|
180 |
thumb extent:(thumbWidth @ thumbHeight). |
|
181 |
button1 origin:(bX @ bwn). |
|
182 |
button2 origin:((bX + leftWidth) @ bwn) |
|
183 |
] ifFalse:[ |
|
184 |
button1 origin:(bX @ bwn). |
|
185 |
button2 origin:((bX + leftWidth) @ bwn). |
|
186 |
thumb extent:(thumbWidth @ thumbHeight) |
|
187 |
]. |
|
188 |
^ self |
|
0 | 189 |
]. |
190 |
"button around thumb" |
|
191 |
||
128 | 192 |
style == #motif ifTrue:[ |
612 | 193 |
sep2 := sep2 + 1 |
128 | 194 |
]. |
195 |
||
7 | 196 |
button1 origin:(bwn @ bwn). |
128 | 197 |
style == #os2 ifTrue:[ |
612 | 198 |
button2 origin:((leftWidth + thumbWidth + sep2 - margin) @ bwn). |
199 |
thumb extent:((thumbWidth - margin - margin) @ thumbHeight). |
|
200 |
thumb origin:((leftWidth - borderWidth + elementSpacing + margin) @ bwn) |
|
128 | 201 |
] ifFalse:[ |
612 | 202 |
button2 origin:((leftWidth + thumbWidth + sep2 - (margin // 2)) @ bwn). |
203 |
thumb extent:((thumbWidth + margin - (margin // 2)) @ thumbHeight). |
|
204 |
thumb origin:((leftWidth - borderWidth + elementSpacing) @ bwn) |
|
128 | 205 |
]. |
612 | 206 |
|
207 |
"Modified: 3.5.1996 / 23:47:30 / stefan" |
|
958 | 208 |
"Modified: 17.1.1997 / 23:19:15 / cg" |
0 | 209 |
! ! |
205 | 210 |
|
211 |
!HorizontalScrollBar methodsFor:'initialization'! |
|
212 |
||
213 |
createElements |
|
214 |
"private: create my elements" |
|
215 |
||
216 |
button1 := ArrowButton leftIn:self. |
|
217 |
button2 := ArrowButton rightIn:self. |
|
218 |
thumb := HorizontalScroller in:self. |
|
219 |
! |
|
220 |
||
221 |
setElementPositions |
|
222 |
"position sub-components" |
|
223 |
||
224 |
|bwn| |
|
225 |
||
226 |
bwn := borderWidth negated + margin. |
|
227 |
||
228 |
(buttonLayout == #bottom) ifTrue:[ |
|
229 |
"buttons at left" |
|
230 |
button1 origin:(bwn @ bwn). |
|
231 |
button1 viewGravity:#West. |
|
232 |
button2 origin:(button1 width @ bwn). |
|
233 |
button2 viewGravity:#West. |
|
234 |
thumb origin:((button1 width |
|
235 |
+ borderWidth |
|
236 |
+ button2 width |
|
237 |
+ elementSpacing + elementSpacing) @ bwn). |
|
238 |
thumb viewGravity:#West. |
|
239 |
^ self |
|
240 |
]. |
|
241 |
||
242 |
(buttonLayout == #top) ifTrue:[ |
|
243 |
"buttons at right" |
|
244 |
button1 viewGravity:#West. |
|
245 |
button2 viewGravity:#West. |
|
246 |
thumb origin:(bwn @ bwn). |
|
247 |
thumb viewGravity:#West |
|
248 |
]. |
|
249 |
||
250 |
"buttonLayout == #around " |
|
251 |
button1 origin:(bwn @ bwn). |
|
252 |
button1 viewGravity:#West. |
|
253 |
button2 viewGravity:#West. |
|
254 |
thumb origin:((button1 width + elementSpacing) @ bwn). |
|
255 |
thumb viewGravity:#West |
|
256 |
! ! |
|
257 |
||
258 |
!HorizontalScrollBar methodsFor:'queries'! |
|
259 |
||
260 |
preferredExtent |
|
958 | 261 |
"compute my extent from sub-components" |
762 | 262 |
|
958 | 263 |
<resource: #style (#name)> |
205 | 264 |
|
265 |
|w h leftForm rightForm wLeft hLeft wRight hRight style| |
|
266 |
||
797 | 267 |
"/ If I have an explicit preferredExtent .. |
268 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
269 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
270 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
271 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
272 |
|
958 | 273 |
"/ need fix - this is a kludge; |
274 |
"/ the reference to the mswindows style here is bad |
|
205 | 275 |
style := styleSheet name. |
276 |
style == #mswindows ifTrue:[ |
|
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
277 |
h := button1 height max:button2 height. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
278 |
w := button1 width + button2 width + (Scroller defaultExtent x). |
205 | 279 |
] ifFalse:[ |
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
280 |
leftForm := ArrowButton leftArrowButtonForm:style on:device. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
281 |
rightForm := ArrowButton rightArrowButtonForm:style on:device. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
282 |
" |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
283 |
just in case ... |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
284 |
" |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
285 |
leftForm isNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
286 |
wLeft := hLeft := 16 |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
287 |
] ifFalse:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
288 |
wLeft := leftForm width. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
289 |
hLeft := leftForm height |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
290 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
291 |
rightForm isNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
292 |
wRight := hRight := 16 |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
293 |
] ifFalse:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
294 |
wRight := rightForm width. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
295 |
hRight := rightForm height |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
296 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
297 |
w := wLeft + wRight + (1 * 2) + (HorizontalScroller defaultExtent x). |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
298 |
h := hLeft max:hRight. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
299 |
(style ~~ #normal) ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
300 |
h := h + 4. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
301 |
w := w + 4 |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
302 |
]. |
205 | 303 |
]. |
786
8b301af1cdcc
remember and do not recompute the preferredExtent;
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
304 |
preferredExtent := w @ h. |
8b301af1cdcc
remember and do not recompute the preferredExtent;
Claus Gittinger <cg@exept.de>
parents:
762
diff
changeset
|
305 |
^ preferredExtent. |
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
612
diff
changeset
|
306 |
|
958 | 307 |
"Modified: 17.1.1997 / 23:18:48 / cg" |
205 | 308 |
! ! |
309 |
||
958 | 310 |
!HorizontalScrollBar class methodsFor:'documentation'! |
205 | 311 |
|
312 |
version |
|
958 | 313 |
^ '$Header: /cvs/stx/stx/libwidg/HorizontalScrollBar.st,v 1.23 1997-01-17 22:24:42 cg Exp $' |
205 | 314 |
! ! |