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