author | Claus Gittinger <cg@exept.de> |
Fri, 01 Mar 1996 19:44:55 +0100 | |
changeset 447 | ed41e1bbd9a1 |
parent 444 | ef26eba8c854 |
child 492 | 80950bd2462e |
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 |
||
119 | 13 |
SimpleView subclass:#ScrollableView |
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
14 |
instanceVariableNames:'scrolledView scrollBar helpView innerMargin scrollBarPosition |
248 | 15 |
lockUpdates' |
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
16 |
classVariableNames:'DefaultScrolledViewLevel' |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
17 |
poolDictionaries:'' |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
18 |
category:'Views-Basic' |
0 | 19 |
! |
20 |
||
38 | 21 |
!ScrollableView class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 26 |
All Rights Reserved |
38 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
a view containing a scrollbar and some other (slave-)view. |
|
130 | 40 |
This view wraps scrollbar(s) around the view to be scrolled. |
65 | 41 |
The scrollbars are setup to send scrollUp/scrollDown/scrollVerticalTo |
42 |
and scrollLeft/scrollRight/scrollHorizontalTo- messages whenever moved. |
|
130 | 43 |
The view itself has to implement these (there is a default implementation |
65 | 44 |
in the common View class for this. |
45 |
||
46 |
For the scrollbars to know about the full (maximum) size, the view |
|
47 |
must implement #heightOfContents and/or #widthOfContents. |
|
130 | 48 |
The values returned by these methods are used to compute the fraction |
49 |
which is visible (i.e. the scrollers thumb heights). |
|
65 | 50 |
|
38 | 51 |
There are two ways to create a ScrollableView: |
52 |
if the type of the view to be scrolled is known in advance, |
|
53 |
use: |
|
130 | 54 |
v := ScrollableView for:<ViewClass> |
55 |
or: |
|
56 |
v := ScrollableView for:<ViewClass> in:someSuperView |
|
65 | 57 |
|
38 | 58 |
otherwise, create the scrollableView empty with: |
130 | 59 |
|
60 |
v := ScrollableView new |
|
61 |
or: |
|
62 |
v := ScrollableView in:someSuperView |
|
63 |
||
65 | 64 |
and define the view later with: |
130 | 65 |
|
59 | 66 |
v scrolledView:aViewToBeScrolled |
65 | 67 |
|
130 | 68 |
Finally, if the view to be scrolled has been already created, |
69 |
use: |
|
70 |
||
71 |
v := ScrollableView forView:aViewToBeScrolled |
|
72 |
or: |
|
73 |
v := ScrollableView forView:aViewToBeScrolled in:someSuperView |
|
65 | 74 |
|
130 | 75 |
It is also possible to change the scrolledView later (even multiple times). |
76 |
This may be useful, if different views are needed to display different types |
|
77 |
of data (see example2) and at creation time, it is not known what type |
|
78 |
of view is required (multimedia applications). |
|
79 |
||
80 |
If you want to scroll views (instead of a views contents), you need a |
|
81 |
companion class (ViewScroller). See the documentation there. |
|
65 | 82 |
|
83 |
If you need horizontal scrolling too, use an instance of HVScrollableView. |
|
113 | 84 |
|
85 |
By default, scrollbars are full size scrollbars - for horizontal scrolling |
|
86 |
(which is less often used), scrollableViews can optionally be created with |
|
87 |
miniscrollers which take up less screen space. |
|
130 | 88 |
|
89 |
TODO: |
|
90 |
this is pretty old and needs a rewrite. There are quite some |
|
91 |
historic leftovers found here and things can be done better |
|
92 |
(especially in initializeFor...) |
|
93 |
||
94 |
Also, it should be rewritten into one class which supports both |
|
95 |
Vertical-only, Horizontal-only and HV scrolling. |
|
96 |
Currently, horizontal-only scrolling is not available. |
|
97 |
(you have to write your own class ...) |
|
98 |
||
99 |
Finally, some means to hide scrollbars should be added - this would |
|
100 |
give more screenspace to the view when all is visible |
|
101 |
(and therefore, the scrollbars are not needed, anyway) |
|
102 |
||
103 |
Expect the above things to be fixed in an upcoming version. |
|
63 | 104 |
" |
105 |
! |
|
38 | 106 |
|
63 | 107 |
examples |
108 |
" |
|
65 | 109 |
example1 (simple scrolled text): |
38 | 110 |
|
59 | 111 |
|top scr txt| |
0 | 112 |
|
65 | 113 |
top := StandardSystemView label:'scroll example1'. |
114 |
top extent:200@100. |
|
113 | 115 |
|
59 | 116 |
scr := ScrollableView for:EditTextView in:top. |
117 |
scr origin:0.0@0.0 corner:1.0@1.0. |
|
118 |
txt := scr scrolledView. |
|
38 | 119 |
|
59 | 120 |
txt list:#('line1' |
121 |
'line2' |
|
122 |
'line3' |
|
123 |
'line4' |
|
124 |
'line5' |
|
65 | 125 |
'line7' |
126 |
'line8' |
|
127 |
'line9' |
|
128 |
'line10' |
|
129 |
). |
|
59 | 130 |
top open |
38 | 131 |
|
65 | 132 |
|
133 |
example2 (changing the scrolledView later): |
|
38 | 134 |
|
113 | 135 |
|top scr txtView1 txtView2 browserView| |
38 | 136 |
|
65 | 137 |
top := StandardSystemView label:'scroll example2'. |
113 | 138 |
top extent:300@100. |
139 |
||
59 | 140 |
scr := ScrollableView in:top. |
141 |
scr origin:0.0@0.0 corner:1.0@1.0. |
|
113 | 142 |
|
59 | 143 |
top open. |
0 | 144 |
|
59 | 145 |
(Delay forSeconds:5) wait. |
38 | 146 |
|
65 | 147 |
txtView1 := EditTextView new. |
148 |
txtView1 list:#( |
|
149 |
'wait 5 seconds to see the other text' |
|
150 |
'line2' |
|
151 |
'line3' |
|
152 |
'line4' |
|
153 |
'line5' |
|
154 |
'line7' |
|
155 |
'line8' |
|
156 |
'line9' |
|
157 |
'line10' |
|
158 |
). |
|
159 |
scr scrolledView:txtView1. |
|
38 | 160 |
|
59 | 161 |
(Delay forSeconds:5) wait. |
38 | 162 |
|
65 | 163 |
txtView2 := EditTextView new. |
113 | 164 |
txtView2 list:#('this is the other views text' |
65 | 165 |
'alternative line2' |
166 |
'alternative line3' |
|
167 |
'alternative line4' |
|
168 |
'alternative line5' |
|
169 |
'alternative line6'). |
|
170 |
scr scrolledView:txtView2. |
|
113 | 171 |
|
172 |
||
173 |
||
174 |
||
175 |
||
176 |
example3 (using a miniscroller): |
|
177 |
||
178 |
|top scr txt| |
|
179 |
||
180 |
top := StandardSystemView label:'scroll example3'. |
|
181 |
top extent:200@100. |
|
182 |
||
183 |
scr := ScrollableView for:EditTextView miniScroller:true in:top. |
|
184 |
scr origin:0.0@0.0 corner:1.0@1.0. |
|
185 |
txt := scr scrolledView. |
|
186 |
||
187 |
txt list:#('line1' |
|
188 |
'line2' |
|
189 |
'line3' |
|
190 |
'line4' |
|
191 |
'line5' |
|
192 |
'line7' |
|
193 |
'line8' |
|
194 |
'line9' |
|
195 |
'line10' |
|
196 |
). |
|
197 |
top open |
|
198 |
||
199 |
||
200 |
||
201 |
||
202 |
example4 (scrolling in both directions): |
|
203 |
||
204 |
|top scr txt| |
|
205 |
||
206 |
top := StandardSystemView label:'scroll example4'. |
|
207 |
top extent:200@100. |
|
208 |
||
209 |
scr := HVScrollableView for:EditTextView in:top. |
|
210 |
scr origin:0.0@0.0 corner:1.0@1.0. |
|
211 |
txt := scr scrolledView. |
|
212 |
||
213 |
txt list:#('line1' |
|
214 |
'line2' |
|
215 |
'line3' |
|
216 |
'line4' |
|
217 |
'line5' |
|
218 |
'line7' |
|
219 |
'line8' |
|
220 |
'line9' |
|
221 |
'line10' |
|
222 |
). |
|
223 |
top open |
|
224 |
||
225 |
||
226 |
||
227 |
||
228 |
example5 (using a full scroller vertically, miniscroller horizontally): |
|
229 |
||
230 |
|top scr txt| |
|
231 |
||
232 |
top := StandardSystemView label:'scroll example5'. |
|
233 |
top extent:200@100. |
|
234 |
||
235 |
scr := HVScrollableView for:EditTextView miniScrollerH:true in:top. |
|
236 |
scr origin:0.0@0.0 corner:1.0@1.0. |
|
237 |
txt := scr scrolledView. |
|
238 |
||
239 |
txt list:#('line1' |
|
240 |
'line2' |
|
241 |
'line3' |
|
242 |
'line4' |
|
243 |
'line5' |
|
244 |
'line7' |
|
245 |
'line8' |
|
246 |
'line9' |
|
247 |
'line10' |
|
248 |
). |
|
249 |
top open |
|
250 |
||
251 |
||
252 |
||
253 |
||
254 |
example6 (using miniscrollers for both directions ): |
|
255 |
||
256 |
|top scr txt| |
|
257 |
||
258 |
top := StandardSystemView label:'scroll example6'. |
|
259 |
top extent:200@100. |
|
260 |
||
261 |
scr := HVScrollableView for:EditTextView miniScroller:true in:top. |
|
262 |
scr origin:0.0@0.0 corner:1.0@1.0. |
|
263 |
txt := scr scrolledView. |
|
264 |
||
265 |
txt list:#('line1' |
|
266 |
'line2' |
|
267 |
'line3' |
|
268 |
'line4' |
|
269 |
'line5' |
|
270 |
'line7' |
|
271 |
'line8' |
|
272 |
'line9' |
|
273 |
'line10' |
|
274 |
). |
|
275 |
top open |
|
38 | 276 |
" |
277 |
! ! |
|
0 | 278 |
|
217 | 279 |
!ScrollableView class methodsFor:'instance creation'! |
280 |
||
281 |
for:aViewClass |
|
282 |
"return a new scrolling view scrolling an instance of aViewClass. |
|
283 |
The subview is created here. |
|
284 |
The view will have full scrollbars." |
|
285 |
||
286 |
^ self for:aViewClass miniScrollerH:false miniScrollerV:false in:nil |
|
287 |
! |
|
288 |
||
289 |
for:aViewClass in:aView |
|
290 |
"return a new scrolling view scrolling an instance of aViewClass. |
|
291 |
The subview is created here. |
|
292 |
The view will have full scrollbars." |
|
293 |
||
294 |
^ self for:aViewClass miniScrollerH:false miniScrollerV:false in:aView |
|
295 |
! |
|
296 |
||
297 |
for:aViewClass miniScroller:mini |
|
298 |
"return a new scrolling view scrolling an instance of aViewClass. |
|
299 |
The subview is created here. |
|
300 |
The view will have full scrollbars if mini is false, miniscrollers |
|
301 |
if true." |
|
302 |
||
303 |
^ self for:aViewClass miniScrollerH:mini miniScrollerV:mini in:nil |
|
304 |
! |
|
305 |
||
306 |
for:aViewClass miniScroller:mini in:aView |
|
307 |
"return a new scrolling view scrolling an instance of aViewClass. |
|
308 |
The subview is created here. |
|
309 |
The view will have full scrollbars if mini is false, miniscrollers |
|
310 |
if true." |
|
311 |
||
312 |
^ self for:aViewClass miniScrollerH:mini miniScrollerV:mini in:aView |
|
313 |
! |
|
153 | 314 |
|
217 | 315 |
for:aViewClass miniScrollerH:miniH |
316 |
"return a new scrolling view scrolling an instance of aViewClass. |
|
317 |
The subview is created here. |
|
318 |
The view will have full scrollbars if miniH is false, |
|
319 |
and a horizontal miniscroller if true." |
|
320 |
||
321 |
^ self for:aViewClass miniScrollerH:miniH miniScrollerV:false in:nil |
|
322 |
! |
|
323 |
||
324 |
for:aViewClass miniScrollerH:miniH in:aView |
|
325 |
"return a new scrolling view scrolling an instance of aViewClass. |
|
326 |
The subview is created here. |
|
327 |
The view will have full scrollbars if miniH is false, |
|
328 |
and a horizontal miniscroller if true." |
|
329 |
||
330 |
^ self for:aViewClass miniScrollerH:miniH miniScrollerV:false in:aView |
|
331 |
! |
|
153 | 332 |
|
217 | 333 |
for:aViewClass miniScrollerH:miniH miniScrollerV:miniV |
334 |
"return a new scrolling view scrolling an instance of aViewClass. |
|
335 |
The subview is created here. |
|
336 |
The view will have full scrollbars if the corresponding miniH/miniV |
|
337 |
is false, miniscrollers if true." |
|
338 |
||
339 |
^ self for:aViewClass miniScrollerH:miniH miniScrollerV:miniV in:nil |
|
340 |
! |
|
341 |
||
342 |
for:aViewClass miniScrollerH:miniH miniScrollerV:miniV in:aView |
|
343 |
"return a new scrolling view scrolling an instance of aViewClass. |
|
344 |
The subview is created here. |
|
345 |
The view will have full scrollbars if the corresponding miniH/miniV |
|
346 |
is false, miniscrollers if true." |
|
347 |
||
300 | 348 |
|newView dev| |
217 | 349 |
|
350 |
aView notNil ifTrue:[ |
|
300 | 351 |
dev := aView device |
352 |
] ifFalse:[ |
|
353 |
dev := Screen current |
|
354 |
]. |
|
355 |
newView := self basicNew device:dev. |
|
356 |
newView initializeFor:aViewClass miniScrollerH:miniH miniScrollerV:miniV. |
|
357 |
aView notNil ifTrue:[ |
|
217 | 358 |
aView addSubView:newView |
153 | 359 |
]. |
217 | 360 |
^ newView |
361 |
! |
|
362 |
||
363 |
forView:aView |
|
364 |
"return a new scrolling view scrolling aView. |
|
365 |
The view will have full scrollbars." |
|
366 |
||
367 |
^ self forView:aView miniScrollerH:false miniScrollerV:false in:nil |
|
368 |
! |
|
369 |
||
248 | 370 |
forView:aView miniScrollerH:mini |
371 |
"return a new scrolling view scrolling aView. |
|
372 |
The view will have a full vertical scrollbar and a horizontal |
|
373 |
miniScroller if mini is true." |
|
374 |
||
375 |
^ self forView:aView miniScrollerH:mini miniScrollerV:false in:nil |
|
376 |
||
377 |
"Created: 10.12.1995 / 17:26:16 / cg" |
|
378 |
! |
|
379 |
||
217 | 380 |
forView:scrolledView miniScrollerH:miniH miniScrollerV:miniV in:aView |
381 |
"return a new scrolling view, scrolling aView. |
|
382 |
The view will have full scrollbars if the corresponding miniH/miniV |
|
383 |
is false, miniscrollers if true." |
|
153 | 384 |
|
217 | 385 |
|newView| |
386 |
||
387 |
newView := self for:nil miniScrollerH:miniH miniScrollerV:miniV in:aView. |
|
388 |
newView scrolledView:scrolledView. |
|
389 |
^ newView |
|
390 |
! |
|
153 | 391 |
|
217 | 392 |
in:aView |
393 |
"return a new scrolling view to be contained in aView. |
|
394 |
There is no slave view now - this has to be set later via |
|
395 |
the scrolledView: method. |
|
396 |
The view will have full scrollbars." |
|
397 |
||
398 |
^ self for:nil miniScrollerH:false miniScrollerV:false in:aView |
|
399 |
! |
|
0 | 400 |
|
93 | 401 |
miniScroller:mini |
402 |
"return a new scrolling view. The subview will be created later. |
|
403 |
The view will have full scrollbars if mini is false, |
|
404 |
miniscrollers if true." |
|
405 |
||
406 |
^ self for:nil miniScrollerH:mini miniScrollerV:mini |
|
407 |
! |
|
408 |
||
113 | 409 |
miniScrollerH:miniH |
410 |
"return a new scrolling view. The subview will be created later. |
|
411 |
The view will have full scrollbars if miniH is false, |
|
412 |
and a horizontal miniscroller if true." |
|
413 |
||
414 |
^ self for:nil miniScrollerH:miniH miniScrollerV:false in:nil |
|
415 |
! |
|
416 |
||
93 | 417 |
miniScrollerH:miniH miniScrollerV:miniV |
418 |
"return a new scrolling view. The subview will be created later. |
|
419 |
The view will have full scrollbars if the corresponding miniH/miniV |
|
113 | 420 |
is false, miniscrollers if true." |
93 | 421 |
|
422 |
^ self for:nil miniScrollerH:miniH miniScrollerV:miniV in:nil |
|
217 | 423 |
! ! |
93 | 424 |
|
217 | 425 |
!ScrollableView class methodsFor:'defaults'! |
426 |
||
427 |
updateStyleCache |
|
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
428 |
"extract values from the styleSheet and cache them in class variables" |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
429 |
|
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
430 |
<resource: #style (#scrolledViewLevel)> |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
431 |
|
217 | 432 |
|d| |
38 | 433 |
|
217 | 434 |
StyleSheet name == #st80 ifTrue:[ |
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
435 |
d := 1 |
217 | 436 |
] ifFalse:[ |
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
437 |
StyleSheet is3D ifTrue:[ |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
438 |
d := -1 |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
439 |
] ifFalse:[ |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
440 |
d := 0 |
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
441 |
] |
217 | 442 |
]. |
443 |
DefaultScrolledViewLevel := StyleSheet at:'scrolledViewLevel' default:d. |
|
0 | 444 |
|
217 | 445 |
"Modified: 31.8.1995 / 04:05:55 / claus" |
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
446 |
"Modified: 1.3.1996 / 13:46:39 / cg" |
217 | 447 |
! ! |
448 |
||
449 |
!ScrollableView methodsFor:'accessing'! |
|
119 | 450 |
|
217 | 451 |
scrollBar |
452 |
"return the scrollbar" |
|
453 |
||
454 |
^ scrollBar |
|
119 | 455 |
! |
456 |
||
217 | 457 |
scrolledView |
458 |
"return the scrolled view" |
|
38 | 459 |
|
217 | 460 |
^ scrolledView |
113 | 461 |
! |
462 |
||
217 | 463 |
scrolledView:aView |
464 |
"set the view to scroll" |
|
465 |
||
466 |
|halfMargin twoMargins isOpenwin| |
|
467 |
||
468 |
scrolledView notNil ifTrue:[ |
|
469 |
scrolledView destroy. |
|
470 |
scrolledView := nil. |
|
471 |
]. |
|
472 |
scrolledView := aView. |
|
77 | 473 |
|
217 | 474 |
"/ ((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[ |
475 |
styleSheet is3D ifTrue:[ |
|
476 |
"3D look" |
|
477 |
||
478 |
isOpenwin := styleSheet name = #openwin. |
|
479 |
||
480 |
twoMargins := innerMargin * 2. |
|
481 |
halfMargin := innerMargin // 2. |
|
482 |
||
483 |
isOpenwin ifTrue:[ |
|
484 |
scrolledView level:0. |
|
485 |
scrolledView borderWidth:1 |
|
486 |
] ifFalse:[ |
|
487 |
scrolledView level:DefaultScrolledViewLevel. |
|
488 |
"/ scrolledView level:-1 |
|
489 |
]. |
|
77 | 490 |
|
217 | 491 |
(scrollBarPosition == #right) ifTrue:[ |
492 |
scrolledView |
|
493 |
origin:halfMargin asPoint |
|
494 |
extent:[(width - |
|
495 |
scrollBar width - |
|
496 |
twoMargins) |
|
497 |
@ |
|
498 |
(height - innerMargin) |
|
499 |
]. |
|
500 |
] ifFalse:[ |
|
501 |
scrolledView |
|
502 |
origin:((scrollBar origin x |
|
503 |
+ scrollBar width |
|
504 |
+ innerMargin) |
|
505 |
@ |
|
506 |
halfMargin) |
|
507 |
extent:[(width |
|
508 |
- scrollBar width |
|
509 |
- twoMargins) |
|
510 |
@ |
|
511 |
(height - innerMargin) |
|
512 |
]. |
|
513 |
] |
|
514 |
] ifFalse:[ |
|
515 |
"non 3D look" |
|
516 |
(scrollBarPosition == #right) ifTrue:[ |
|
517 |
scrolledView |
|
518 |
origin:scrolledView borderWidth negated asPoint |
|
519 |
] ifFalse:[ |
|
520 |
scrolledView |
|
521 |
origin:((scrollBar width |
|
522 |
+ scrollBar borderWidth |
|
523 |
- scrolledView borderWidth) |
|
524 |
@ |
|
525 |
scrolledView borderWidth negated) |
|
526 |
]. |
|
527 |
scrolledView |
|
528 |
extent:[ |
|
529 |
(width |
|
530 |
- scrollBar width |
|
531 |
- scrolledView borderWidth) |
|
532 |
@ |
|
533 |
(height + (scrollBar borderWidth)) |
|
534 |
] |
|
535 |
]. |
|
132 | 536 |
|
217 | 537 |
super addSubView:scrolledView. |
538 |
self setScrollActions. |
|
539 |
||
540 |
" |
|
541 |
pass my keyboard input (and other subviews input) |
|
542 |
to the scrolled view ... |
|
543 |
" |
|
544 |
self delegate:(KeyboardForwarder toView:scrolledView). |
|
545 |
||
546 |
realized ifTrue:[ |
|
547 |
self sizeChanged:nil. |
|
548 |
scrolledView realize |
|
549 |
]. |
|
550 |
! ! |
|
551 |
||
552 |
!ScrollableView methodsFor:'changes '! |
|
553 |
||
554 |
update:something with:argument from:changedObject |
|
555 |
"whenever the scrolledView changes its contents, the scroller must |
|
556 |
be updated" |
|
132 | 557 |
|
217 | 558 |
changedObject == scrolledView ifTrue:[ |
559 |
something == #sizeOfContents ifTrue:[ |
|
560 |
scrollBar setThumbFor:scrolledView. |
|
561 |
^ self |
|
562 |
]. |
|
563 |
something == #originOfContents ifTrue:[ |
|
564 |
lockUpdates ifFalse:[ |
|
565 |
scrollBar setThumbOriginFor:scrolledView. |
|
566 |
]. |
|
567 |
^ self |
|
568 |
]. |
|
569 |
]. |
|
570 |
! ! |
|
38 | 571 |
|
217 | 572 |
!ScrollableView methodsFor:'event processing'! |
573 |
||
574 |
keyPress:key x:x y:y |
|
575 |
"a key was pressed - handle page-keys here" |
|
576 |
||
577 |
<resource: #keyboard ( #Prior #Next ) > |
|
578 |
||
579 |
(key == #Prior) ifTrue: [^ self pageUp]. |
|
580 |
(key == #Next) ifTrue: [^ self pageDown]. |
|
581 |
||
582 |
super keyPress:key x:x y:y |
|
38 | 583 |
! |
584 |
||
217 | 585 |
sizeChanged:how |
586 |
super sizeChanged:how. |
|
587 |
scrolledView notNil ifTrue:[ |
|
588 |
scrollBar setThumbFor:scrolledView |
|
589 |
]. |
|
590 |
scrollBar thumbOrigin + scrollBar thumbHeight >= 100 ifTrue:[ |
|
591 |
scrollBar thumbOrigin:(100 - scrollBar thumbHeight). |
|
592 |
scrolledView scrollVerticalToPercent:scrollBar thumbOrigin. |
|
593 |
]. |
|
113 | 594 |
|
217 | 595 |
"Modified: 8.9.1995 / 12:46:36 / claus" |
596 |
! ! |
|
597 |
||
598 |
!ScrollableView methodsFor:'forced scroll'! |
|
599 |
||
600 |
pageDown |
|
601 |
"page down" |
|
602 |
||
603 |
scrollBar pageDown |
|
113 | 604 |
! |
605 |
||
217 | 606 |
pageUp |
607 |
"page up" |
|
0 | 608 |
|
217 | 609 |
scrollBar pageUp |
0 | 610 |
! ! |
611 |
||
612 |
!ScrollableView methodsFor:'initialization'! |
|
613 |
||
217 | 614 |
initStyle |
615 |
super initStyle. |
|
616 |
||
617 |
scrollBarPosition := styleSheet at:'scrollBarPosition' default:#left |
|
618 |
! |
|
619 |
||
0 | 620 |
initialize |
38 | 621 |
"default setup: full scrollers" |
622 |
||
623 |
^ self initializeFor:nil miniScrollerH:false miniScrollerV:false |
|
0 | 624 |
! |
625 |
||
38 | 626 |
initializeFor:aViewClass miniScrollerH:miniH miniScrollerV:miniV |
130 | 627 |
|negativeOffset twoMargins halfMargin cls isST80 isOpenWin is3D lvl extra| |
0 | 628 |
|
629 |
super initialize. |
|
630 |
||
65 | 631 |
lockUpdates := false. |
632 |
||
110 | 633 |
" |
634 |
mhmh - these must go into the stylesheet as well... |
|
635 |
" |
|
130 | 636 |
isST80 := styleSheet name = #st80. |
637 |
isOpenWin := styleSheet name = #openwin. |
|
59 | 638 |
|
110 | 639 |
isOpenWin ifTrue:[self level:0]. |
130 | 640 |
is3D := styleSheet is3D. |
59 | 641 |
|
642 |
isST80 ifTrue:[ |
|
643 |
innerMargin := 0 |
|
38 | 644 |
] ifFalse:[ |
59 | 645 |
is3D ifTrue:[ |
646 |
innerMargin := ViewSpacing. |
|
647 |
] ifFalse:[ |
|
648 |
innerMargin := 0 |
|
649 |
] |
|
38 | 650 |
]. |
0 | 651 |
negativeOffset := borderWidth negated. |
652 |
||
653 |
"create the scrollbar" |
|
654 |
||
59 | 655 |
isST80 ifTrue:[ |
656 |
cls := ScrollBar |
|
657 |
] ifFalse:[ |
|
658 |
cls := miniV ifTrue:[MiniScroller] ifFalse:[ScrollBar]. |
|
659 |
]. |
|
38 | 660 |
|
661 |
scrollBar := cls in:self. |
|
0 | 662 |
scrollBar thumbOrigin:0 thumbHeight:100. |
663 |
||
130 | 664 |
extra := 0. |
665 |
||
0 | 666 |
"create the subview" |
59 | 667 |
is3D ifTrue:[ |
668 |
twoMargins := innerMargin * 2. |
|
669 |
halfMargin := innerMargin // 2. |
|
0 | 670 |
|
59 | 671 |
aViewClass notNil ifTrue:[ |
672 |
scrolledView := aViewClass in:self. |
|
110 | 673 |
isOpenWin ifTrue:[ |
130 | 674 |
lvl := 0. |
675 |
"/ scrolledView level:0. |
|
676 |
scrolledView borderWidth:1. |
|
59 | 677 |
] ifFalse:[ |
153 | 678 |
lvl := DefaultScrolledViewLevel. |
679 |
"/ isST80 ifTrue:[ |
|
680 |
"/ "/ scrolledView level:1. |
|
681 |
"/ lvl := 1. |
|
682 |
"/ ] ifFalse:[ |
|
683 |
"/ "/ scrolledView level:-1 |
|
684 |
"/ lvl := -1 |
|
685 |
"/ ] |
|
59 | 686 |
]. |
130 | 687 |
scrolledView level:lvl. |
688 |
extra := scrolledView borderWidth * 2. |
|
59 | 689 |
]. |
130 | 690 |
|
691 |
scrollBar extent:[scrollBar extent x |
|
692 |
@ |
|
693 |
(height - innerMargin "new:" + extra)]. |
|
694 |
scrolledView notNil ifTrue:[ |
|
695 |
scrolledView |
|
696 |
extent:[(width |
|
697 |
- scrollBar width |
|
698 |
- twoMargins) |
|
699 |
@ |
|
700 |
(height - innerMargin)]. |
|
701 |
]. |
|
702 |
||
59 | 703 |
(scrollBarPosition == #right) ifTrue:[ |
704 |
scrollBar origin:[width - scrollBar extent x |
|
705 |
- (scrollBar borderWidth * 2) |
|
706 |
- halfMargin |
|
707 |
@ |
|
130 | 708 |
halfMargin]. |
38 | 709 |
|
59 | 710 |
scrolledView notNil ifTrue:[ |
711 |
scrolledView origin:halfMargin asPoint |
|
712 |
] |
|
713 |
] ifFalse:[ |
|
130 | 714 |
scrollBar origin:halfMargin asPoint. |
38 | 715 |
|
59 | 716 |
scrolledView notNil ifTrue:[ |
717 |
scrolledView origin:((scrollBar origin x + scrollBar width + innerMargin) |
|
718 |
@ |
|
719 |
halfMargin) |
|
720 |
] |
|
721 |
]. |
|
0 | 722 |
] ifFalse:[ |
59 | 723 |
(scrollBarPosition == #right) ifTrue:[ |
724 |
scrollBar origin:[width - scrollBar extent x |
|
725 |
- scrollBar borderWidth |
|
726 |
@ |
|
727 |
negativeOffset] |
|
728 |
] ifFalse:[ |
|
729 |
scrollBar origin:negativeOffset asPoint |
|
730 |
]. |
|
130 | 731 |
scrollBar extent:[scrollBar extent x |
732 |
@ |
|
733 |
(height "+ (scrollBar borderWidth * 1)")]. |
|
0 | 734 |
|
59 | 735 |
aViewClass notNil ifTrue:[ |
736 |
scrolledView := aViewClass in:self. |
|
737 |
(scrollBarPosition == #right) ifTrue:[ |
|
738 |
scrolledView origin:scrolledView borderWidth negated asPoint |
|
739 |
] ifFalse:[ |
|
740 |
scrolledView origin:((scrollBar width + |
|
741 |
scrollBar borderWidth - |
|
742 |
scrolledView borderWidth) |
|
743 |
@ |
|
744 |
scrolledView borderWidth negated) |
|
745 |
]. |
|
746 |
scrolledView extent:[(width - scrollBar width - scrolledView borderWidth) |
|
747 |
@ |
|
748 |
(height + (scrollBar borderWidth)) |
|
749 |
] |
|
750 |
]. |
|
0 | 751 |
]. |
752 |
scrolledView notNil ifTrue:[ |
|
59 | 753 |
self setScrollActions. |
754 |
" |
|
113 | 755 |
pass my keyboard input (and other subviews input) |
756 |
to the scrolled view ... |
|
59 | 757 |
" |
122 | 758 |
self delegate:(KeyboardForwarder toView:scrolledView). |
0 | 759 |
] |
760 |
! |
|
761 |
||
762 |
realize |
|
763 |
super realize. |
|
38 | 764 |
|
0 | 765 |
"since scrolledview may have done something to its contents |
766 |
during init-time we had no chance yet to catch contents- |
|
767 |
changes; do it now |
|
768 |
" |
|
38 | 769 |
scrolledView notNil ifTrue:[ |
59 | 770 |
scrollBar setThumbFor:scrolledView |
38 | 771 |
] |
0 | 772 |
! ! |
773 |
||
7 | 774 |
!ScrollableView methodsFor:'private'! |
775 |
||
776 |
setScrollActions |
|
777 |
"lock prevents repositioning the scroller to the |
|
778 |
actual (often rounded) position while scrolling, |
|
779 |
and keeps it instead at the pointer position. |
|
780 |
||
781 |
(this avoids run-away scroller when scrolling |
|
782 |
textviews, when the text is aligned line-wise). |
|
38 | 783 |
Consider this as a kludge." |
7 | 784 |
|
65 | 785 |
lockUpdates := false. |
7 | 786 |
|
787 |
scrollBar scrollAction:[:position | |
|
65 | 788 |
lockUpdates := true. |
59 | 789 |
scrolledView scrollVerticalToPercent:position. |
65 | 790 |
lockUpdates := false |
7 | 791 |
]. |
792 |
scrollBar scrollUpAction:[scrolledView scrollUp]. |
|
793 |
scrollBar scrollDownAction:[scrolledView scrollDown]. |
|
794 |
||
65 | 795 |
scrolledView addDependent:self. |
7 | 796 |
! ! |
797 |
||
217 | 798 |
!ScrollableView methodsFor:'queries'! |
38 | 799 |
|
217 | 800 |
preferredExtent |
801 |
scrolledView notNil ifTrue:[ |
|
802 |
| pref | |
|
803 |
pref := scrolledView preferredExtent. |
|
804 |
^ (pref x + scrollBar width + (innerMargin * 2)) @ pref y. |
|
0 | 805 |
]. |
217 | 806 |
^ super preferredExtent. |
0 | 807 |
! ! |
808 |
||
809 |
!ScrollableView methodsFor:'slave-view messages'! |
|
810 |
||
217 | 811 |
doesNotUnderstand:aMessage |
812 |
"this is funny: all message we do not understand, are passed |
|
813 |
on to the scrolledView - so we do not have to care for all |
|
814 |
possible messages ...(thanks to the Message class)" |
|
815 |
||
816 |
scrolledView isNil ifFalse:[ |
|
817 |
^ scrolledView perform:(aMessage selector) |
|
818 |
withArguments:(aMessage arguments) |
|
819 |
] |
|
820 |
! |
|
821 |
||
0 | 822 |
leftButtonMenu |
38 | 823 |
"return scrolledViews leftbuttonmenu" |
824 |
||
825 |
scrolledView isNil ifTrue:[^ nil]. |
|
0 | 826 |
^ scrolledView leftButtonMenu |
827 |
! |
|
828 |
||
829 |
leftButtonMenu:aMenu |
|
830 |
"pass on leftbuttonmenu to scrolledView" |
|
831 |
||
832 |
scrolledView leftButtonMenu:aMenu |
|
833 |
! |
|
834 |
||
835 |
middleButtonMenu |
|
38 | 836 |
"return scrolledViews middlebuttonmenu" |
837 |
||
838 |
scrolledView isNil ifTrue:[^ nil]. |
|
0 | 839 |
^ scrolledView middleButtonMenu |
840 |
! |
|
841 |
||
842 |
middleButtonMenu:aMenu |
|
843 |
"pass on middlebuttonmenu to scrolledView" |
|
844 |
||
845 |
scrolledView middleButtonMenu:aMenu |
|
846 |
! |
|
847 |
||
848 |
rightButtonMenu |
|
38 | 849 |
"return scrolledViews rightbuttonmenu" |
850 |
||
851 |
scrolledView isNil ifTrue:[^ nil]. |
|
0 | 852 |
^ scrolledView rightButtonMenu |
853 |
! |
|
854 |
||
855 |
rightButtonMenu:aMenu |
|
856 |
"pass on rightbuttonmenu to scrolledView" |
|
857 |
||
858 |
scrolledView rightButtonMenu:aMenu |
|
38 | 859 |
! ! |
860 |
||
217 | 861 |
!ScrollableView class methodsFor:'documentation'! |
0 | 862 |
|
217 | 863 |
version |
444
ef26eba8c854
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
300
diff
changeset
|
864 |
^ '$Header: /cvs/stx/stx/libwidg/ScrollableView.st,v 1.25 1996-03-01 13:07:13 cg Exp $' |
0 | 865 |
! ! |