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