0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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 |
|
|
13 |
View subclass:#ScrollableView
|
7
|
14 |
instanceVariableNames:'scrolledView scrollBar helpView innerMargin
|
|
15 |
scrollBarPosition'
|
0
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Basic'
|
|
19 |
!
|
|
20 |
|
|
21 |
ScrollableView comment:'
|
5
|
22 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
23 |
All Rights Reserved
|
38
|
24 |
|
53
|
25 |
$Header: /cvs/stx/stx/libwidg/Attic/ScrView.st,v 1.6 1994-08-23 23:38:46 claus Exp $
|
38
|
26 |
'!
|
|
27 |
|
|
28 |
!ScrollableView class methodsFor:'documentation'!
|
|
29 |
|
|
30 |
copyright
|
|
31 |
"
|
|
32 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
33 |
All Rights Reserved
|
|
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 |
"
|
53
|
46 |
$Header: /cvs/stx/stx/libwidg/Attic/ScrView.st,v 1.6 1994-08-23 23:38:46 claus Exp $
|
38
|
47 |
"
|
|
48 |
!
|
|
49 |
|
|
50 |
documentation
|
|
51 |
"
|
|
52 |
a view containing a scrollbar and some other (slave-)view.
|
|
53 |
There are two ways to create a ScrollableView:
|
|
54 |
if the type of the view to be scrolled is known in advance,
|
|
55 |
use:
|
|
56 |
v := ScrollableView for:<ViewClass> in:someSuperView.
|
|
57 |
otherwise, create the scrollableView empty with:
|
|
58 |
v := ScrollableView in:someSuperView.
|
|
59 |
...
|
|
60 |
v scrolledView:aViewToBeScrolled
|
|
61 |
|
|
62 |
example1:
|
|
63 |
|
|
64 |
|top scr txt|
|
0
|
65 |
|
38
|
66 |
top := StandardSystemView label:'example'.
|
|
67 |
scr := ScrollableView for:EditTextView in:top.
|
|
68 |
scr origin:0.0@0.0 corner:1.0@1.0.
|
|
69 |
txt := scr scrolledView.
|
|
70 |
|
|
71 |
txt list:#('line1'
|
|
72 |
'line2'
|
|
73 |
'line3'
|
|
74 |
'line4'
|
|
75 |
'line5'
|
|
76 |
'line6').
|
|
77 |
top open
|
|
78 |
|
|
79 |
example2:
|
|
80 |
|
|
81 |
|top scr txt1 txt2|
|
|
82 |
|
|
83 |
top := StandardSystemView label:'example'.
|
|
84 |
scr := ScrollableView in:top.
|
|
85 |
scr origin:0.0@0.0 corner:1.0@1.0.
|
|
86 |
top open.
|
0
|
87 |
|
38
|
88 |
(Delay forSeconds:5) wait.
|
|
89 |
|
|
90 |
txt1 := EditTextView new.
|
|
91 |
txt1 list:#('line1'
|
|
92 |
'line2'
|
|
93 |
'line3'
|
|
94 |
'line4'
|
|
95 |
'line5'
|
|
96 |
'line6').
|
|
97 |
scr scrolledView:txt1.
|
|
98 |
|
|
99 |
(Delay forSeconds:5) wait.
|
|
100 |
|
|
101 |
txt2 := EditTextView new.
|
|
102 |
txt2 list:#('alternative line1'
|
|
103 |
'alternative line2'
|
|
104 |
'alternative line3'
|
|
105 |
'alternative line4'
|
|
106 |
'alternative line5'
|
|
107 |
'alternative line6').
|
|
108 |
scr scrolledView:txt2.
|
|
109 |
"
|
|
110 |
! !
|
0
|
111 |
|
|
112 |
!ScrollableView class methodsFor:'instance creation'!
|
|
113 |
|
|
114 |
in:aView
|
38
|
115 |
"return a new scrolling view to be contained in aView.
|
|
116 |
There is no slave view now - this has to be set later via
|
|
117 |
the scrolledView: method.
|
|
118 |
The view will have full scrollbars."
|
|
119 |
|
|
120 |
^ self for:nil miniScrollerH:false miniScrollerV:false in:aView
|
0
|
121 |
!
|
|
122 |
|
|
123 |
for:aViewClass
|
38
|
124 |
"return a new scrolling view scrolling an instance of aViewClass.
|
|
125 |
The subview is created here.
|
|
126 |
The view will have full scrollbars."
|
|
127 |
|
|
128 |
^ self for:aViewClass miniScrollerH:false miniScrollerV:false in:nil
|
0
|
129 |
!
|
|
130 |
|
|
131 |
for:aViewClass in:aView
|
38
|
132 |
"return a new scrolling view scrolling an instance of aViewClass.
|
|
133 |
The subview is created here.
|
|
134 |
The view will have full scrollbars."
|
|
135 |
|
|
136 |
^ self for:aViewClass miniScrollerH:false miniScrollerV:false in:aView
|
|
137 |
!
|
|
138 |
|
|
139 |
for:aViewClass miniScroller:mini in:aView
|
|
140 |
"return a new scrolling view scrolling an instance of aViewClass.
|
|
141 |
The subview is created here.
|
|
142 |
The view will have full scrollbars if mini is false, miniscrollers
|
|
143 |
if true."
|
|
144 |
|
|
145 |
^ self for:aViewClass miniScrollerH:mini miniScrollerV:mini in:aView
|
|
146 |
!
|
|
147 |
|
|
148 |
for:aViewClass miniScrollerH:miniH miniScrollerV:miniV in:aView
|
|
149 |
"return a new scrolling view scrolling an instance of aViewClass.
|
|
150 |
The subview is created here.
|
|
151 |
The view will have full scrollbars if the corresponding miniH/miniV
|
|
152 |
is false, miniscrollers if false."
|
|
153 |
|
0
|
154 |
|newView|
|
|
155 |
|
|
156 |
aView notNil ifTrue:[
|
38
|
157 |
newView := self basicNew.
|
0
|
158 |
newView device:(aView device).
|
|
159 |
aView addSubView:newView
|
|
160 |
] ifFalse:[
|
38
|
161 |
"create on Display by default"
|
|
162 |
newView := self new.
|
0
|
163 |
].
|
38
|
164 |
newView initializeFor:aViewClass miniScrollerH:miniH miniScrollerV:miniV.
|
0
|
165 |
^ newView
|
|
166 |
! !
|
|
167 |
|
|
168 |
!ScrollableView methodsFor:'initialization'!
|
|
169 |
|
|
170 |
initialize
|
38
|
171 |
"default setup: full scrollers"
|
|
172 |
|
|
173 |
^ self initializeFor:nil miniScrollerH:false miniScrollerV:false
|
0
|
174 |
!
|
|
175 |
|
38
|
176 |
initializeFor:aViewClass miniScrollerH:miniH miniScrollerV:miniV
|
|
177 |
|negativeOffset twoMargins halfMargin cls|
|
0
|
178 |
|
|
179 |
super initialize.
|
|
180 |
|
38
|
181 |
style == #openwin ifTrue:[self level:0].
|
|
182 |
style == #st80 ifTrue:[
|
|
183 |
innerMargin := 0
|
|
184 |
] ifFalse:[
|
|
185 |
innerMargin := ViewSpacing.
|
|
186 |
].
|
0
|
187 |
negativeOffset := borderWidth negated.
|
|
188 |
|
|
189 |
"create the scrollbar"
|
|
190 |
|
38
|
191 |
cls := miniV ifTrue:[MiniScroller] ifFalse:[ScrollBar].
|
|
192 |
style == #st80 ifTrue:[cls := ScrollBar].
|
|
193 |
|
|
194 |
scrollBar := cls in:self.
|
0
|
195 |
scrollBar thumbOrigin:0 thumbHeight:100.
|
|
196 |
|
|
197 |
"create the subview"
|
38
|
198 |
((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[
|
0
|
199 |
twoMargins := innerMargin * 2.
|
|
200 |
halfMargin := innerMargin // 2.
|
|
201 |
|
38
|
202 |
aViewClass notNil ifTrue:[
|
|
203 |
scrolledView := aViewClass in:self.
|
|
204 |
style == #openwin ifTrue:[
|
|
205 |
scrolledView level:0.
|
|
206 |
scrolledView borderWidth:1
|
|
207 |
] ifFalse:[
|
|
208 |
style == #st80 ifTrue:[
|
|
209 |
scrolledView level:1.
|
|
210 |
] ifFalse:[
|
|
211 |
scrolledView level:-1
|
|
212 |
]
|
|
213 |
].
|
|
214 |
].
|
7
|
215 |
(scrollBarPosition == #right) ifTrue:[
|
|
216 |
scrollBar origin:[width - scrollBar extent x
|
38
|
217 |
- (scrollBar borderWidth * 2)
|
7
|
218 |
- halfMargin
|
|
219 |
@
|
|
220 |
halfMargin]
|
|
221 |
extent:[scrollBar extent x @ (height - innerMargin)].
|
38
|
222 |
|
|
223 |
scrolledView notNil ifTrue:[
|
|
224 |
scrolledView origin:halfMargin asPoint
|
|
225 |
extent:[(width -
|
|
226 |
scrollBar width -
|
|
227 |
twoMargins)
|
|
228 |
@
|
|
229 |
(height - innerMargin)].
|
|
230 |
]
|
7
|
231 |
] ifFalse:[
|
|
232 |
scrollBar origin:halfMargin asPoint
|
|
233 |
extent:[scrollBar extent x @ (height - innerMargin)].
|
38
|
234 |
|
|
235 |
scrolledView notNil ifTrue:[
|
|
236 |
scrolledView origin:((scrollBar origin x + scrollBar width + innerMargin)
|
|
237 |
@
|
|
238 |
halfMargin)
|
|
239 |
extent:[(width - scrollBar width - twoMargins)
|
|
240 |
@
|
|
241 |
(height - innerMargin)].
|
|
242 |
]
|
7
|
243 |
].
|
0
|
244 |
] ifFalse:[
|
7
|
245 |
(scrollBarPosition == #right) ifTrue:[
|
0
|
246 |
scrollBar origin:[width - scrollBar extent x
|
|
247 |
- scrollBar borderWidth
|
|
248 |
@
|
|
249 |
negativeOffset]
|
|
250 |
] ifFalse:[
|
7
|
251 |
scrollBar origin:negativeOffset asPoint
|
0
|
252 |
].
|
|
253 |
scrollBar extent:[scrollBar extent x @ (height "+ (scrollBar borderWidth * 1)")].
|
|
254 |
|
|
255 |
aViewClass notNil ifTrue:[
|
|
256 |
scrolledView := aViewClass in:self.
|
7
|
257 |
(scrollBarPosition == #right) ifTrue:[
|
|
258 |
scrolledView origin:scrolledView borderWidth negated asPoint
|
0
|
259 |
] ifFalse:[
|
38
|
260 |
scrolledView origin:((scrollBar width +
|
|
261 |
scrollBar borderWidth -
|
|
262 |
scrolledView borderWidth)
|
0
|
263 |
@
|
|
264 |
scrolledView borderWidth negated)
|
|
265 |
].
|
38
|
266 |
scrolledView extent:[(width - scrollBar width - scrolledView borderWidth)
|
0
|
267 |
@
|
|
268 |
(height + (scrollBar borderWidth))
|
|
269 |
]
|
|
270 |
].
|
|
271 |
].
|
|
272 |
scrolledView notNil ifTrue:[
|
38
|
273 |
self setScrollActions.
|
|
274 |
"
|
|
275 |
pass input to myself (and other subviews) to
|
|
276 |
the scrolled view
|
|
277 |
"
|
|
278 |
self keyboardHandler:scrolledView.
|
0
|
279 |
]
|
|
280 |
!
|
|
281 |
|
7
|
282 |
initStyle
|
|
283 |
super initStyle.
|
|
284 |
|
38
|
285 |
((style == #motif)
|
|
286 |
or:[(style == #mswindows)
|
|
287 |
or:[style == #openwin]]) ifTrue:[
|
7
|
288 |
scrollBarPosition := #right
|
38
|
289 |
] ifFalse:[
|
|
290 |
scrollBarPosition := #left.
|
7
|
291 |
].
|
|
292 |
!
|
|
293 |
|
0
|
294 |
realize
|
|
295 |
super realize.
|
38
|
296 |
|
0
|
297 |
"since scrolledview may have done something to its contents
|
|
298 |
during init-time we had no chance yet to catch contents-
|
|
299 |
changes; do it now
|
|
300 |
"
|
38
|
301 |
scrolledView notNil ifTrue:[
|
|
302 |
scrollBar setThumbFor:scrolledView
|
|
303 |
]
|
0
|
304 |
! !
|
|
305 |
|
7
|
306 |
!ScrollableView methodsFor:'private'!
|
|
307 |
|
|
308 |
setScrollActions
|
|
309 |
|lock|
|
|
310 |
|
|
311 |
"lock prevents repositioning the scroller to the
|
|
312 |
actual (often rounded) position while scrolling,
|
|
313 |
and keeps it instead at the pointer position.
|
|
314 |
|
|
315 |
(this avoids run-away scroller when scrolling
|
|
316 |
textviews, when the text is aligned line-wise).
|
38
|
317 |
Consider this as a kludge."
|
7
|
318 |
|
|
319 |
lock := false.
|
|
320 |
|
|
321 |
scrollBar scrollAction:[:position |
|
|
322 |
lock := true.
|
|
323 |
scrolledView scrollVerticalToPercent:position.
|
|
324 |
lock := false
|
|
325 |
].
|
|
326 |
scrollBar scrollUpAction:[scrolledView scrollUp].
|
|
327 |
scrollBar scrollDownAction:[scrolledView scrollDown].
|
|
328 |
|
|
329 |
scrolledView originChangeAction:[:aView |
|
|
330 |
lock ifFalse:[
|
|
331 |
scrollBar setThumbOriginFor:aView.
|
|
332 |
]
|
|
333 |
].
|
|
334 |
scrolledView contentsChangeAction:[:aView |
|
|
335 |
scrollBar setThumbFor:aView.
|
|
336 |
]
|
|
337 |
! !
|
|
338 |
|
0
|
339 |
!ScrollableView methodsFor:'accessing'!
|
|
340 |
|
|
341 |
scrollBar
|
|
342 |
"return the scrollbar"
|
|
343 |
|
|
344 |
^ scrollBar
|
|
345 |
!
|
|
346 |
|
|
347 |
scrolledView
|
|
348 |
"return the scrolled view"
|
|
349 |
|
|
350 |
^ scrolledView
|
|
351 |
!
|
|
352 |
|
|
353 |
scrolledView:aView
|
38
|
354 |
"set the view to scroll"
|
|
355 |
|
|
356 |
|halfMargin twoMargins|
|
0
|
357 |
|
|
358 |
scrolledView notNil ifTrue:[
|
38
|
359 |
scrolledView destroy.
|
|
360 |
scrolledView := nil.
|
0
|
361 |
].
|
|
362 |
scrolledView := aView.
|
|
363 |
|
38
|
364 |
((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[
|
|
365 |
"3D look"
|
|
366 |
|
|
367 |
twoMargins := innerMargin * 2.
|
|
368 |
halfMargin := innerMargin // 2.
|
0
|
369 |
|
38
|
370 |
style == #openwin ifTrue:[
|
|
371 |
scrolledView level:0.
|
|
372 |
scrolledView borderWidth:1
|
|
373 |
] ifFalse:[
|
|
374 |
scrolledView level:-1
|
|
375 |
].
|
|
376 |
|
7
|
377 |
(scrollBarPosition == #right) ifTrue:[
|
38
|
378 |
scrolledView
|
|
379 |
origin:halfMargin asPoint
|
|
380 |
extent:[(width -
|
|
381 |
scrollBar width -
|
|
382 |
twoMargins)
|
|
383 |
@
|
|
384 |
(height - innerMargin)
|
|
385 |
].
|
7
|
386 |
] ifFalse:[
|
38
|
387 |
scrolledView
|
|
388 |
origin:((scrollBar origin x
|
|
389 |
+ scrollBar width
|
|
390 |
+ innerMargin)
|
|
391 |
@
|
|
392 |
halfMargin)
|
|
393 |
extent:[(width
|
|
394 |
- scrollBar width
|
|
395 |
- twoMargins)
|
|
396 |
@
|
|
397 |
(height - innerMargin)
|
|
398 |
].
|
|
399 |
]
|
|
400 |
] ifFalse:[
|
|
401 |
"non 3D look"
|
|
402 |
(scrollBarPosition == #right) ifTrue:[
|
|
403 |
scrolledView
|
|
404 |
origin:scrolledView borderWidth negated asPoint
|
|
405 |
] ifFalse:[
|
|
406 |
scrolledView
|
|
407 |
origin:((scrollBar width
|
|
408 |
+ scrollBar borderWidth
|
|
409 |
- scrolledView borderWidth)
|
|
410 |
@
|
|
411 |
scrolledView borderWidth negated)
|
7
|
412 |
].
|
38
|
413 |
scrolledView
|
|
414 |
extent:[
|
|
415 |
(width
|
|
416 |
- scrollBar width
|
|
417 |
- scrolledView borderWidth)
|
|
418 |
@
|
|
419 |
(height
|
|
420 |
+ (scrollBar borderWidth))
|
|
421 |
]
|
0
|
422 |
].
|
|
423 |
|
38
|
424 |
super addSubView:scrolledView.
|
|
425 |
self setScrollActions.
|
|
426 |
"
|
|
427 |
pass input to myself (and other subviews) to
|
|
428 |
the scrolled view
|
|
429 |
"
|
|
430 |
self keyboardHandler:scrolledView.
|
|
431 |
|
|
432 |
realized ifTrue:[
|
|
433 |
self sizeChanged:nil.
|
|
434 |
scrolledView realize
|
|
435 |
].
|
0
|
436 |
! !
|
|
437 |
|
|
438 |
!ScrollableView methodsFor:'slave-view messages'!
|
|
439 |
|
|
440 |
leftButtonMenu
|
38
|
441 |
"return scrolledViews leftbuttonmenu"
|
|
442 |
|
|
443 |
scrolledView isNil ifTrue:[^ nil].
|
0
|
444 |
^ scrolledView leftButtonMenu
|
|
445 |
!
|
|
446 |
|
|
447 |
leftButtonMenu:aMenu
|
|
448 |
"pass on leftbuttonmenu to scrolledView"
|
|
449 |
|
|
450 |
scrolledView leftButtonMenu:aMenu
|
|
451 |
!
|
|
452 |
|
|
453 |
middleButtonMenu
|
38
|
454 |
"return scrolledViews middlebuttonmenu"
|
|
455 |
|
|
456 |
scrolledView isNil ifTrue:[^ nil].
|
0
|
457 |
^ scrolledView middleButtonMenu
|
|
458 |
!
|
|
459 |
|
|
460 |
middleButtonMenu:aMenu
|
|
461 |
"pass on middlebuttonmenu to scrolledView"
|
|
462 |
|
|
463 |
scrolledView middleButtonMenu:aMenu
|
|
464 |
!
|
|
465 |
|
|
466 |
rightButtonMenu
|
38
|
467 |
"return scrolledViews rightbuttonmenu"
|
|
468 |
|
|
469 |
scrolledView isNil ifTrue:[^ nil].
|
0
|
470 |
^ scrolledView rightButtonMenu
|
|
471 |
!
|
|
472 |
|
|
473 |
rightButtonMenu:aMenu
|
|
474 |
"pass on rightbuttonmenu to scrolledView"
|
|
475 |
|
|
476 |
scrolledView rightButtonMenu:aMenu
|
|
477 |
!
|
|
478 |
|
|
479 |
doesNotUnderstand:aMessage
|
|
480 |
"this is funny: all message we do not understand, are passed
|
|
481 |
on to the scrolledView - so we do not have to care for all
|
|
482 |
possible messages ...(thanks to the Message class)"
|
|
483 |
|
|
484 |
scrolledView isNil ifFalse:[
|
|
485 |
^ scrolledView perform:(aMessage selector)
|
|
486 |
withArguments:(aMessage arguments)
|
|
487 |
]
|
|
488 |
! !
|
|
489 |
|
38
|
490 |
!ScrollableView methodsFor:'forced scroll'!
|
|
491 |
|
|
492 |
pageUp
|
|
493 |
"page up"
|
|
494 |
|
|
495 |
scrollBar pageUp
|
|
496 |
!
|
|
497 |
|
|
498 |
pageDown
|
|
499 |
"page down"
|
|
500 |
|
|
501 |
scrollBar pageDown
|
|
502 |
! !
|
|
503 |
|
0
|
504 |
!ScrollableView methodsFor:'event processing'!
|
|
505 |
|
38
|
506 |
keyPress:key x:x y:y
|
|
507 |
"a key was pressed - handle page-keys here"
|
|
508 |
|
|
509 |
(key == #Prior) ifTrue: [^ self pageUp].
|
|
510 |
(key == #Next) ifTrue: [^ self pageDown].
|
|
511 |
|
|
512 |
super keyPress:key x:x y:y
|
|
513 |
!
|
|
514 |
|
0
|
515 |
sizeChanged:how
|
|
516 |
super sizeChanged:how.
|
38
|
517 |
scrolledView notNil ifTrue:[
|
|
518 |
scrollBar setThumbFor:scrolledView
|
|
519 |
]
|
0
|
520 |
! !
|