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