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
|
217
|
14 |
instanceVariableNames:'scrolledView scrollBar helpView innerMargin scrollBarPosition
|
248
|
15 |
lockUpdates'
|
217
|
16 |
classVariableNames:'DefaultScrolledViewLevel'
|
|
17 |
poolDictionaries:''
|
|
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 |
|
|
348 |
|newView|
|
|
349 |
|
|
350 |
aView notNil ifTrue:[
|
|
351 |
newView := self basicNew.
|
|
352 |
newView device:(aView device).
|
|
353 |
aView addSubView:newView
|
153
|
354 |
] ifFalse:[
|
217
|
355 |
"create on Display by default"
|
|
356 |
newView := self basicNew device:Display.
|
153
|
357 |
].
|
217
|
358 |
newView initializeFor:aViewClass miniScrollerH:miniH miniScrollerV:miniV.
|
|
359 |
^ newView
|
|
360 |
!
|
|
361 |
|
|
362 |
forView:aView
|
|
363 |
"return a new scrolling view scrolling aView.
|
|
364 |
The view will have full scrollbars."
|
|
365 |
|
|
366 |
^ self forView:aView miniScrollerH:false miniScrollerV:false in:nil
|
|
367 |
!
|
|
368 |
|
248
|
369 |
forView:aView miniScrollerH:mini
|
|
370 |
"return a new scrolling view scrolling aView.
|
|
371 |
The view will have a full vertical scrollbar and a horizontal
|
|
372 |
miniScroller if mini is true."
|
|
373 |
|
|
374 |
^ self forView:aView miniScrollerH:mini miniScrollerV:false in:nil
|
|
375 |
|
|
376 |
"Created: 10.12.1995 / 17:26:16 / cg"
|
|
377 |
!
|
|
378 |
|
217
|
379 |
forView:scrolledView miniScrollerH:miniH miniScrollerV:miniV in:aView
|
|
380 |
"return a new scrolling view, scrolling aView.
|
|
381 |
The view will have full scrollbars if the corresponding miniH/miniV
|
|
382 |
is false, miniscrollers if true."
|
153
|
383 |
|
217
|
384 |
|newView|
|
|
385 |
|
|
386 |
newView := self for:nil miniScrollerH:miniH miniScrollerV:miniV in:aView.
|
|
387 |
newView scrolledView:scrolledView.
|
|
388 |
^ newView
|
|
389 |
!
|
153
|
390 |
|
217
|
391 |
in:aView
|
|
392 |
"return a new scrolling view to be contained in aView.
|
|
393 |
There is no slave view now - this has to be set later via
|
|
394 |
the scrolledView: method.
|
|
395 |
The view will have full scrollbars."
|
|
396 |
|
|
397 |
^ self for:nil miniScrollerH:false miniScrollerV:false in:aView
|
|
398 |
!
|
0
|
399 |
|
93
|
400 |
miniScroller:mini
|
|
401 |
"return a new scrolling view. The subview will be created later.
|
|
402 |
The view will have full scrollbars if mini is false,
|
|
403 |
miniscrollers if true."
|
|
404 |
|
|
405 |
^ self for:nil miniScrollerH:mini miniScrollerV:mini
|
|
406 |
!
|
|
407 |
|
113
|
408 |
miniScrollerH:miniH
|
|
409 |
"return a new scrolling view. The subview will be created later.
|
|
410 |
The view will have full scrollbars if miniH is false,
|
|
411 |
and a horizontal miniscroller if true."
|
|
412 |
|
|
413 |
^ self for:nil miniScrollerH:miniH miniScrollerV:false in:nil
|
|
414 |
!
|
|
415 |
|
93
|
416 |
miniScrollerH:miniH miniScrollerV:miniV
|
|
417 |
"return a new scrolling view. The subview will be created later.
|
|
418 |
The view will have full scrollbars if the corresponding miniH/miniV
|
113
|
419 |
is false, miniscrollers if true."
|
93
|
420 |
|
|
421 |
^ self for:nil miniScrollerH:miniH miniScrollerV:miniV in:nil
|
217
|
422 |
! !
|
93
|
423 |
|
217
|
424 |
!ScrollableView class methodsFor:'defaults'!
|
|
425 |
|
|
426 |
updateStyleCache
|
|
427 |
|d|
|
38
|
428 |
|
217
|
429 |
StyleSheet name == #st80 ifTrue:[
|
|
430 |
d := 1
|
|
431 |
] ifFalse:[
|
|
432 |
StyleSheet is3D ifTrue:[
|
|
433 |
d := -1
|
|
434 |
] ifFalse:[
|
|
435 |
d := 0
|
|
436 |
]
|
|
437 |
].
|
|
438 |
DefaultScrolledViewLevel := StyleSheet at:'scrolledViewLevel' default:d.
|
0
|
439 |
|
217
|
440 |
"Modified: 31.8.1995 / 04:05:55 / claus"
|
|
441 |
! !
|
|
442 |
|
|
443 |
!ScrollableView methodsFor:'accessing'!
|
119
|
444 |
|
217
|
445 |
scrollBar
|
|
446 |
"return the scrollbar"
|
|
447 |
|
|
448 |
^ scrollBar
|
119
|
449 |
!
|
|
450 |
|
217
|
451 |
scrolledView
|
|
452 |
"return the scrolled view"
|
38
|
453 |
|
217
|
454 |
^ scrolledView
|
113
|
455 |
!
|
|
456 |
|
217
|
457 |
scrolledView:aView
|
|
458 |
"set the view to scroll"
|
|
459 |
|
|
460 |
|halfMargin twoMargins isOpenwin|
|
|
461 |
|
|
462 |
scrolledView notNil ifTrue:[
|
|
463 |
scrolledView destroy.
|
|
464 |
scrolledView := nil.
|
|
465 |
].
|
|
466 |
scrolledView := aView.
|
77
|
467 |
|
217
|
468 |
"/ ((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[
|
|
469 |
styleSheet is3D ifTrue:[
|
|
470 |
"3D look"
|
|
471 |
|
|
472 |
isOpenwin := styleSheet name = #openwin.
|
|
473 |
|
|
474 |
twoMargins := innerMargin * 2.
|
|
475 |
halfMargin := innerMargin // 2.
|
|
476 |
|
|
477 |
isOpenwin ifTrue:[
|
|
478 |
scrolledView level:0.
|
|
479 |
scrolledView borderWidth:1
|
|
480 |
] ifFalse:[
|
|
481 |
scrolledView level:DefaultScrolledViewLevel.
|
|
482 |
"/ scrolledView level:-1
|
|
483 |
].
|
77
|
484 |
|
217
|
485 |
(scrollBarPosition == #right) ifTrue:[
|
|
486 |
scrolledView
|
|
487 |
origin:halfMargin asPoint
|
|
488 |
extent:[(width -
|
|
489 |
scrollBar width -
|
|
490 |
twoMargins)
|
|
491 |
@
|
|
492 |
(height - innerMargin)
|
|
493 |
].
|
|
494 |
] ifFalse:[
|
|
495 |
scrolledView
|
|
496 |
origin:((scrollBar origin x
|
|
497 |
+ scrollBar width
|
|
498 |
+ innerMargin)
|
|
499 |
@
|
|
500 |
halfMargin)
|
|
501 |
extent:[(width
|
|
502 |
- scrollBar width
|
|
503 |
- twoMargins)
|
|
504 |
@
|
|
505 |
(height - innerMargin)
|
|
506 |
].
|
|
507 |
]
|
|
508 |
] ifFalse:[
|
|
509 |
"non 3D look"
|
|
510 |
(scrollBarPosition == #right) ifTrue:[
|
|
511 |
scrolledView
|
|
512 |
origin:scrolledView borderWidth negated asPoint
|
|
513 |
] ifFalse:[
|
|
514 |
scrolledView
|
|
515 |
origin:((scrollBar width
|
|
516 |
+ scrollBar borderWidth
|
|
517 |
- scrolledView borderWidth)
|
|
518 |
@
|
|
519 |
scrolledView borderWidth negated)
|
|
520 |
].
|
|
521 |
scrolledView
|
|
522 |
extent:[
|
|
523 |
(width
|
|
524 |
- scrollBar width
|
|
525 |
- scrolledView borderWidth)
|
|
526 |
@
|
|
527 |
(height + (scrollBar borderWidth))
|
|
528 |
]
|
|
529 |
].
|
132
|
530 |
|
217
|
531 |
super addSubView:scrolledView.
|
|
532 |
self setScrollActions.
|
|
533 |
|
|
534 |
"
|
|
535 |
pass my keyboard input (and other subviews input)
|
|
536 |
to the scrolled view ...
|
|
537 |
"
|
|
538 |
self delegate:(KeyboardForwarder toView:scrolledView).
|
|
539 |
|
|
540 |
realized ifTrue:[
|
|
541 |
self sizeChanged:nil.
|
|
542 |
scrolledView realize
|
|
543 |
].
|
|
544 |
! !
|
|
545 |
|
|
546 |
!ScrollableView methodsFor:'changes '!
|
|
547 |
|
|
548 |
update:something with:argument from:changedObject
|
|
549 |
"whenever the scrolledView changes its contents, the scroller must
|
|
550 |
be updated"
|
132
|
551 |
|
217
|
552 |
changedObject == scrolledView ifTrue:[
|
|
553 |
something == #sizeOfContents ifTrue:[
|
|
554 |
scrollBar setThumbFor:scrolledView.
|
|
555 |
^ self
|
|
556 |
].
|
|
557 |
something == #originOfContents ifTrue:[
|
|
558 |
lockUpdates ifFalse:[
|
|
559 |
scrollBar setThumbOriginFor:scrolledView.
|
|
560 |
].
|
|
561 |
^ self
|
|
562 |
].
|
|
563 |
].
|
|
564 |
! !
|
38
|
565 |
|
217
|
566 |
!ScrollableView methodsFor:'event processing'!
|
|
567 |
|
|
568 |
keyPress:key x:x y:y
|
|
569 |
"a key was pressed - handle page-keys here"
|
|
570 |
|
|
571 |
<resource: #keyboard ( #Prior #Next ) >
|
|
572 |
|
|
573 |
(key == #Prior) ifTrue: [^ self pageUp].
|
|
574 |
(key == #Next) ifTrue: [^ self pageDown].
|
|
575 |
|
|
576 |
super keyPress:key x:x y:y
|
38
|
577 |
!
|
|
578 |
|
217
|
579 |
sizeChanged:how
|
|
580 |
super sizeChanged:how.
|
|
581 |
scrolledView notNil ifTrue:[
|
|
582 |
scrollBar setThumbFor:scrolledView
|
|
583 |
].
|
|
584 |
scrollBar thumbOrigin + scrollBar thumbHeight >= 100 ifTrue:[
|
|
585 |
scrollBar thumbOrigin:(100 - scrollBar thumbHeight).
|
|
586 |
scrolledView scrollVerticalToPercent:scrollBar thumbOrigin.
|
|
587 |
].
|
113
|
588 |
|
217
|
589 |
"Modified: 8.9.1995 / 12:46:36 / claus"
|
|
590 |
! !
|
|
591 |
|
|
592 |
!ScrollableView methodsFor:'forced scroll'!
|
|
593 |
|
|
594 |
pageDown
|
|
595 |
"page down"
|
|
596 |
|
|
597 |
scrollBar pageDown
|
113
|
598 |
!
|
|
599 |
|
217
|
600 |
pageUp
|
|
601 |
"page up"
|
0
|
602 |
|
217
|
603 |
scrollBar pageUp
|
0
|
604 |
! !
|
|
605 |
|
|
606 |
!ScrollableView methodsFor:'initialization'!
|
|
607 |
|
217
|
608 |
initStyle
|
|
609 |
super initStyle.
|
|
610 |
|
|
611 |
scrollBarPosition := styleSheet at:'scrollBarPosition' default:#left
|
|
612 |
!
|
|
613 |
|
0
|
614 |
initialize
|
38
|
615 |
"default setup: full scrollers"
|
|
616 |
|
|
617 |
^ self initializeFor:nil miniScrollerH:false miniScrollerV:false
|
0
|
618 |
!
|
|
619 |
|
38
|
620 |
initializeFor:aViewClass miniScrollerH:miniH miniScrollerV:miniV
|
130
|
621 |
|negativeOffset twoMargins halfMargin cls isST80 isOpenWin is3D lvl extra|
|
0
|
622 |
|
|
623 |
super initialize.
|
|
624 |
|
65
|
625 |
lockUpdates := false.
|
|
626 |
|
110
|
627 |
"
|
|
628 |
mhmh - these must go into the stylesheet as well...
|
|
629 |
"
|
130
|
630 |
isST80 := styleSheet name = #st80.
|
|
631 |
isOpenWin := styleSheet name = #openwin.
|
59
|
632 |
|
110
|
633 |
isOpenWin ifTrue:[self level:0].
|
130
|
634 |
is3D := styleSheet is3D.
|
59
|
635 |
|
|
636 |
isST80 ifTrue:[
|
|
637 |
innerMargin := 0
|
38
|
638 |
] ifFalse:[
|
59
|
639 |
is3D ifTrue:[
|
|
640 |
innerMargin := ViewSpacing.
|
|
641 |
] ifFalse:[
|
|
642 |
innerMargin := 0
|
|
643 |
]
|
38
|
644 |
].
|
0
|
645 |
negativeOffset := borderWidth negated.
|
|
646 |
|
|
647 |
"create the scrollbar"
|
|
648 |
|
59
|
649 |
isST80 ifTrue:[
|
|
650 |
cls := ScrollBar
|
|
651 |
] ifFalse:[
|
|
652 |
cls := miniV ifTrue:[MiniScroller] ifFalse:[ScrollBar].
|
|
653 |
].
|
38
|
654 |
|
|
655 |
scrollBar := cls in:self.
|
0
|
656 |
scrollBar thumbOrigin:0 thumbHeight:100.
|
|
657 |
|
130
|
658 |
extra := 0.
|
|
659 |
|
0
|
660 |
"create the subview"
|
59
|
661 |
is3D ifTrue:[
|
|
662 |
twoMargins := innerMargin * 2.
|
|
663 |
halfMargin := innerMargin // 2.
|
0
|
664 |
|
59
|
665 |
aViewClass notNil ifTrue:[
|
|
666 |
scrolledView := aViewClass in:self.
|
110
|
667 |
isOpenWin ifTrue:[
|
130
|
668 |
lvl := 0.
|
|
669 |
"/ scrolledView level:0.
|
|
670 |
scrolledView borderWidth:1.
|
59
|
671 |
] ifFalse:[
|
153
|
672 |
lvl := DefaultScrolledViewLevel.
|
|
673 |
"/ isST80 ifTrue:[
|
|
674 |
"/ "/ scrolledView level:1.
|
|
675 |
"/ lvl := 1.
|
|
676 |
"/ ] ifFalse:[
|
|
677 |
"/ "/ scrolledView level:-1
|
|
678 |
"/ lvl := -1
|
|
679 |
"/ ]
|
59
|
680 |
].
|
130
|
681 |
scrolledView level:lvl.
|
|
682 |
extra := scrolledView borderWidth * 2.
|
59
|
683 |
].
|
130
|
684 |
|
|
685 |
scrollBar extent:[scrollBar extent x
|
|
686 |
@
|
|
687 |
(height - innerMargin "new:" + extra)].
|
|
688 |
scrolledView notNil ifTrue:[
|
|
689 |
scrolledView
|
|
690 |
extent:[(width
|
|
691 |
- scrollBar width
|
|
692 |
- twoMargins)
|
|
693 |
@
|
|
694 |
(height - innerMargin)].
|
|
695 |
].
|
|
696 |
|
59
|
697 |
(scrollBarPosition == #right) ifTrue:[
|
|
698 |
scrollBar origin:[width - scrollBar extent x
|
|
699 |
- (scrollBar borderWidth * 2)
|
|
700 |
- halfMargin
|
|
701 |
@
|
130
|
702 |
halfMargin].
|
38
|
703 |
|
59
|
704 |
scrolledView notNil ifTrue:[
|
|
705 |
scrolledView origin:halfMargin asPoint
|
|
706 |
]
|
|
707 |
] ifFalse:[
|
130
|
708 |
scrollBar origin:halfMargin asPoint.
|
38
|
709 |
|
59
|
710 |
scrolledView notNil ifTrue:[
|
|
711 |
scrolledView origin:((scrollBar origin x + scrollBar width + innerMargin)
|
|
712 |
@
|
|
713 |
halfMargin)
|
|
714 |
]
|
|
715 |
].
|
0
|
716 |
] ifFalse:[
|
59
|
717 |
(scrollBarPosition == #right) ifTrue:[
|
|
718 |
scrollBar origin:[width - scrollBar extent x
|
|
719 |
- scrollBar borderWidth
|
|
720 |
@
|
|
721 |
negativeOffset]
|
|
722 |
] ifFalse:[
|
|
723 |
scrollBar origin:negativeOffset asPoint
|
|
724 |
].
|
130
|
725 |
scrollBar extent:[scrollBar extent x
|
|
726 |
@
|
|
727 |
(height "+ (scrollBar borderWidth * 1)")].
|
0
|
728 |
|
59
|
729 |
aViewClass notNil ifTrue:[
|
|
730 |
scrolledView := aViewClass in:self.
|
|
731 |
(scrollBarPosition == #right) ifTrue:[
|
|
732 |
scrolledView origin:scrolledView borderWidth negated asPoint
|
|
733 |
] ifFalse:[
|
|
734 |
scrolledView origin:((scrollBar width +
|
|
735 |
scrollBar borderWidth -
|
|
736 |
scrolledView borderWidth)
|
|
737 |
@
|
|
738 |
scrolledView borderWidth negated)
|
|
739 |
].
|
|
740 |
scrolledView extent:[(width - scrollBar width - scrolledView borderWidth)
|
|
741 |
@
|
|
742 |
(height + (scrollBar borderWidth))
|
|
743 |
]
|
|
744 |
].
|
0
|
745 |
].
|
|
746 |
scrolledView notNil ifTrue:[
|
59
|
747 |
self setScrollActions.
|
|
748 |
"
|
113
|
749 |
pass my keyboard input (and other subviews input)
|
|
750 |
to the scrolled view ...
|
59
|
751 |
"
|
122
|
752 |
self delegate:(KeyboardForwarder toView:scrolledView).
|
0
|
753 |
]
|
|
754 |
!
|
|
755 |
|
|
756 |
realize
|
|
757 |
super realize.
|
38
|
758 |
|
0
|
759 |
"since scrolledview may have done something to its contents
|
|
760 |
during init-time we had no chance yet to catch contents-
|
|
761 |
changes; do it now
|
|
762 |
"
|
38
|
763 |
scrolledView notNil ifTrue:[
|
59
|
764 |
scrollBar setThumbFor:scrolledView
|
38
|
765 |
]
|
0
|
766 |
! !
|
|
767 |
|
7
|
768 |
!ScrollableView methodsFor:'private'!
|
|
769 |
|
|
770 |
setScrollActions
|
|
771 |
"lock prevents repositioning the scroller to the
|
|
772 |
actual (often rounded) position while scrolling,
|
|
773 |
and keeps it instead at the pointer position.
|
|
774 |
|
|
775 |
(this avoids run-away scroller when scrolling
|
|
776 |
textviews, when the text is aligned line-wise).
|
38
|
777 |
Consider this as a kludge."
|
7
|
778 |
|
65
|
779 |
lockUpdates := false.
|
7
|
780 |
|
|
781 |
scrollBar scrollAction:[:position |
|
65
|
782 |
lockUpdates := true.
|
59
|
783 |
scrolledView scrollVerticalToPercent:position.
|
65
|
784 |
lockUpdates := false
|
7
|
785 |
].
|
|
786 |
scrollBar scrollUpAction:[scrolledView scrollUp].
|
|
787 |
scrollBar scrollDownAction:[scrolledView scrollDown].
|
|
788 |
|
65
|
789 |
scrolledView addDependent:self.
|
7
|
790 |
! !
|
|
791 |
|
217
|
792 |
!ScrollableView methodsFor:'queries'!
|
38
|
793 |
|
217
|
794 |
preferredExtent
|
|
795 |
scrolledView notNil ifTrue:[
|
|
796 |
| pref |
|
|
797 |
pref := scrolledView preferredExtent.
|
|
798 |
^ (pref x + scrollBar width + (innerMargin * 2)) @ pref y.
|
0
|
799 |
].
|
217
|
800 |
^ super preferredExtent.
|
0
|
801 |
! !
|
|
802 |
|
|
803 |
!ScrollableView methodsFor:'slave-view messages'!
|
|
804 |
|
217
|
805 |
doesNotUnderstand:aMessage
|
|
806 |
"this is funny: all message we do not understand, are passed
|
|
807 |
on to the scrolledView - so we do not have to care for all
|
|
808 |
possible messages ...(thanks to the Message class)"
|
|
809 |
|
|
810 |
scrolledView isNil ifFalse:[
|
|
811 |
^ scrolledView perform:(aMessage selector)
|
|
812 |
withArguments:(aMessage arguments)
|
|
813 |
]
|
|
814 |
!
|
|
815 |
|
0
|
816 |
leftButtonMenu
|
38
|
817 |
"return scrolledViews leftbuttonmenu"
|
|
818 |
|
|
819 |
scrolledView isNil ifTrue:[^ nil].
|
0
|
820 |
^ scrolledView leftButtonMenu
|
|
821 |
!
|
|
822 |
|
|
823 |
leftButtonMenu:aMenu
|
|
824 |
"pass on leftbuttonmenu to scrolledView"
|
|
825 |
|
|
826 |
scrolledView leftButtonMenu:aMenu
|
|
827 |
!
|
|
828 |
|
|
829 |
middleButtonMenu
|
38
|
830 |
"return scrolledViews middlebuttonmenu"
|
|
831 |
|
|
832 |
scrolledView isNil ifTrue:[^ nil].
|
0
|
833 |
^ scrolledView middleButtonMenu
|
|
834 |
!
|
|
835 |
|
|
836 |
middleButtonMenu:aMenu
|
|
837 |
"pass on middlebuttonmenu to scrolledView"
|
|
838 |
|
|
839 |
scrolledView middleButtonMenu:aMenu
|
|
840 |
!
|
|
841 |
|
|
842 |
rightButtonMenu
|
38
|
843 |
"return scrolledViews rightbuttonmenu"
|
|
844 |
|
|
845 |
scrolledView isNil ifTrue:[^ nil].
|
0
|
846 |
^ scrolledView rightButtonMenu
|
|
847 |
!
|
|
848 |
|
|
849 |
rightButtonMenu:aMenu
|
|
850 |
"pass on rightbuttonmenu to scrolledView"
|
|
851 |
|
|
852 |
scrolledView rightButtonMenu:aMenu
|
38
|
853 |
! !
|
|
854 |
|
217
|
855 |
!ScrollableView class methodsFor:'documentation'!
|
0
|
856 |
|
217
|
857 |
version
|
248
|
858 |
^ '$Header: /cvs/stx/stx/libwidg/ScrollableView.st,v 1.23 1995-12-10 16:53:46 cg Exp $'
|
0
|
859 |
! !
|