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