author | ca |
Thu, 18 Oct 2007 14:56:25 +0200 | |
changeset 3249 | 224b457c40fd |
parent 3175 | d82c95049597 |
child 3261 | 7f60ff4c779b |
permissions | -rw-r--r-- |
36 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
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 |
" |
|
2001
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
12 |
"{ Package: 'stx:libwidg2' }" |
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
13 |
|
49 | 14 |
SimpleView subclass:#ViewScroller |
2120 | 15 |
instanceVariableNames:'frame scrolledView keepViewsChannel model verticalScrollStep |
3249
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
16 |
horizontalScrollStep resizeScrolledViewVertical |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
17 |
resizeScrolledViewHorizontal' |
186 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
20 |
category:'Views-Basic' |
|
29 | 21 |
! |
22 |
||
424 | 23 |
!ViewScroller class methodsFor:'documentation'! |
29 | 24 |
|
36 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
187 | 41 |
This wrapper view allows scrolling of views (in contrast to scrolling |
42 |
of contents which can be done by any view). |
|
186 | 43 |
|
187 | 44 |
Normally, scrolling is done by putting a view into a ScrollableView (which |
45 |
simply wraps the scrollbars around) and have the scrollbars send scrollUp:/ |
|
46 |
scrollDown: etc. send to the scrolledView. |
|
47 |
The default implementation of scrolling (in View) modifies the transformation, |
|
48 |
and does a bit-copy of the contents with redraw of the exposed area. |
|
36 | 49 |
|
187 | 50 |
However, there are situations, where you want to scroll a view itself. |
51 |
For example, if you need many buttons in a panel, which do not fit. |
|
36 | 52 |
|
187 | 53 |
This class provides the basic mechanism to implement this. |
54 |
It is a wrapper, which implements scrolling by modifying the origin of its |
|
55 |
single subview when asked to scroll. Thus, it can be put into a ScrollableView |
|
56 |
like any other, but will move its subview when asked to scroll instead. |
|
57 |
(i.e. reimplement all scroll messages by manipulating its subviews origin |
|
58 |
instead of its contents' transformation offset) |
|
36 | 59 |
|
187 | 60 |
The subview should have a constant extent, which will be taken for the |
61 |
scrollbar position/height computation. |
|
62 |
Since the subview is represented directly by the underlying window systems view |
|
63 |
implementation, there may be a limit on the maximum size of that view. For |
|
64 |
example, in X, dimensions may not be larger than 32767 pixels. |
|
65 |
||
2120 | 66 |
[Instance variables:] |
67 |
model <ValueHolder> the model which keeps the current scrolledView. |
|
68 |
||
69 |
keepViewsChannel <ValueHolder> boolean holder; if the value is false (the default), |
|
70 |
the previous scrolled view is destroyed, whenever a |
|
71 |
new scrolled view is set. If true, it is unmapped and |
|
72 |
kept. |
|
73 |
Set this flag, if the application changes the scrolled |
|
74 |
view but wants them to be kept for fast switching. |
|
75 |
||
76 |
horizontalScrollStep <SmallInteger> amount to scroll when stepping left/right in pixels |
|
77 |
verticalScrollStep <SmallInteger> amount to scroll when stepping up/down in pixels |
|
78 |
||
79 |
frame <SimpleView> the one and only container of the visible scrolledView |
|
80 |
and all invisible scrolledViews if existant. |
|
81 |
||
82 |
scrolledView <SimpleView | nil> the current scrolled view or nil |
|
83 |
||
187 | 84 |
[see also:] |
85 |
ScrollableView HVScrollableView |
|
86 |
||
87 |
[author:] |
|
88 |
Claus Gittinger |
|
36 | 89 |
" |
90 |
! |
|
91 |
||
29 | 92 |
examples |
93 |
" |
|
94 |
scroll a panel of buttons: |
|
186 | 95 |
[exBegin] |
29 | 96 |
|top frame vscroller v panel| |
97 |
||
98 |
top := StandardSystemView new. |
|
99 |
top extent:100@400. |
|
100 |
||
101 |
frame := ScrollableView for:ViewScroller in:top. |
|
102 |
frame origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
|
103 |
||
104 |
vscroller := frame scrolledView. |
|
105 |
panel := VerticalPanelView new. |
|
106 |
panel horizontalLayout:#fit. |
|
107 |
1 to:100 do:[:i | |
|
186 | 108 |
Button label:(i printString) in:panel |
29 | 109 |
]. |
110 |
vscroller scrolledView:panel. |
|
111 |
top open. |
|
186 | 112 |
[exEnd] |
29 | 113 |
|
425 | 114 |
same, defining what a scroll step is: |
115 |
[exBegin] |
|
116 |
|top frame vscroller v panel| |
|
117 |
||
118 |
top := StandardSystemView new. |
|
119 |
top extent:100@400. |
|
120 |
||
121 |
frame := ScrollableView for:ViewScroller in:top. |
|
122 |
frame origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
|
123 |
||
124 |
vscroller := frame scrolledView. |
|
125 |
vscroller verticalScrollStep:20. |
|
126 |
panel := VerticalPanelView new. |
|
127 |
panel horizontalLayout:#fit. |
|
128 |
1 to:100 do:[:i | |
|
129 |
Button label:(i printString) in:panel |
|
130 |
]. |
|
131 |
vscroller scrolledView:panel. |
|
132 |
top open. |
|
133 |
[exEnd] |
|
134 |
||
187 | 135 |
|
29 | 136 |
same, horizontally. Also change layout in panel for nicer look |
137 |
and make panel adjust its height: |
|
36 | 138 |
(since the buttons are defined to fill vertically, the vertical |
139 |
scrollbar is useless here - its here as example; not for its function) |
|
186 | 140 |
[exBegin] |
29 | 141 |
|top frame vscroller v panel| |
142 |
||
143 |
top := StandardSystemView new. |
|
144 |
top extent:300@100. |
|
145 |
||
146 |
frame := HVScrollableView for:ViewScroller in:top. |
|
147 |
frame origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
|
148 |
||
149 |
vscroller := frame scrolledView. |
|
150 |
panel := HorizontalPanelView new. |
|
151 |
panel verticalLayout:#fit. |
|
152 |
panel horizontalLayout:#fit. |
|
153 |
1 to:100 do:[:i | |
|
186 | 154 |
Button label:(i printString) in:panel |
29 | 155 |
]. |
156 |
vscroller scrolledView:panel. |
|
157 |
panel height:1.0. |
|
158 |
top open. |
|
186 | 159 |
[exEnd] |
29 | 160 |
|
161 |
||
162 |
scroll a panel of buttons and other views: |
|
163 |
(not good looking, but a demo that it can be done ...) |
|
186 | 164 |
[exBegin] |
29 | 165 |
|top frame vscroller v panel textView1 textView2| |
166 |
||
167 |
top := StandardSystemView new. |
|
168 |
||
169 |
frame := HVScrollableView for:ViewScroller in:top. |
|
170 |
frame origin:0.0 @ 0.0 corner:1.0 @ 1.0. |
|
171 |
||
172 |
vscroller := frame scrolledView. |
|
173 |
||
174 |
panel := VerticalPanelView new. |
|
175 |
panel horizontalLayout:#leftSpace. |
|
176 |
||
177 |
textView1 := ScrollableView for:EditTextView in:panel. |
|
187 | 178 |
textView1 extent:2000 @ 300. |
29 | 179 |
textView1 scrolledView contents:('Makefile' asFilename readStream contents). |
180 |
||
181 |
textView2 := ScrollableView for:EditTextView in:panel. |
|
187 | 182 |
textView2 extent:500 @ 300. |
29 | 183 |
textView2 scrolledView contents:('Make.proto' asFilename readStream contents). |
184 |
||
185 |
1 to:100 do:[:i | |
|
186 | 186 |
Button label:(i printString) in:panel |
29 | 187 |
]. |
188 |
vscroller scrolledView:panel. |
|
189 |
top open. |
|
186 | 190 |
[exEnd] |
29 | 191 |
" |
192 |
! ! |
|
193 |
||
186 | 194 |
!ViewScroller methodsFor:'accessing'! |
195 |
||
2120 | 196 |
destroyAllClientViews |
2957 | 197 |
"destroy all client views" |
198 |
||
2120 | 199 |
frame destroySubViews. |
200 |
||
201 |
scrolledView ifNotNil:[ |
|
202 |
scrolledView := nil. |
|
203 |
self sizeChanged:nil. |
|
204 |
]. |
|
205 |
model value:scrolledView. |
|
206 |
! |
|
425 | 207 |
|
2120 | 208 |
keepViews |
209 |
"returns the value of the boolean channel: keepViewsChannel. |
|
2957 | 210 |
for more information see: #keepViewsChannel" |
211 |
||
2120 | 212 |
^ keepViewsChannel value ? false |
213 |
! |
|
214 |
||
215 |
keepViews:aBool |
|
216 |
"set the value of the boolean channel: keepViewsChannel. |
|
217 |
for more information see: #keepViewsChannel: |
|
218 |
" |
|
219 |
keepViewsChannel value:aBool |
|
2001
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
220 |
! |
425 | 221 |
|
3249
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
222 |
resizeScrolledViewHorizontal |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
223 |
^ resizeScrolledViewHorizontal |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
224 |
! |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
225 |
|
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
226 |
resizeScrolledViewHorizontal:something |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
227 |
resizeScrolledViewHorizontal := something. |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
228 |
! |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
229 |
|
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
230 |
resizeScrolledViewVertical |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
231 |
^ resizeScrolledViewVertical |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
232 |
! |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
233 |
|
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
234 |
resizeScrolledViewVertical:something |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
235 |
resizeScrolledViewVertical := something. |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
236 |
! |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
237 |
|
424 | 238 |
scrolledView |
239 |
"return the view which is scrolled" |
|
240 |
||
241 |
^ scrolledView |
|
242 |
! |
|
243 |
||
186 | 244 |
scrolledView:aView |
2120 | 245 |
"set a new scolled view; dependent on the #keepViewsChannel |
2957 | 246 |
the old scolled view will be destroyed or unmapped." |
247 |
||
2120 | 248 |
scrolledView ~~ aView ifTrue:[ |
249 |
scrolledView ifNotNil:[ |
|
250 |
self keepViews ifTrue:[ scrolledView beInvisible ] |
|
251 |
ifFalse:[ scrolledView destroy ]. |
|
252 |
]. |
|
253 |
scrolledView := aView. |
|
254 |
||
255 |
"test whether new scrolled view not nil and |
|
256 |
not already added to my subViews. |
|
257 |
" |
|
258 |
(scrolledView notNil and:[scrolledView superView ~~ frame]) ifTrue:[ |
|
259 |
|extent| |
|
186 | 260 |
|
2120 | 261 |
scrolledView borderWidth:0; level:0. |
262 |
extent := scrolledView preferredExtent. |
|
263 |
frame addSubView:scrolledView. |
|
264 |
||
265 |
"/ test whether the new view is a scrollWrapper. |
|
266 |
"/ in this case scrolling can be done by this view |
|
267 |
||
268 |
scrolledView isScrollWrapper ifTrue:[ |
|
269 |
scrolledView isHorizontalScrollable ifTrue:[ extent x:1.0 ]. |
|
270 |
scrolledView isVerticalScrollable ifTrue:[ extent y:1.0 ]. |
|
271 |
]. |
|
3249
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
272 |
|
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
273 |
resizeScrolledViewHorizontal ifTrue:[ extent x:1.0 ]. |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
274 |
resizeScrolledViewVertical ifTrue:[ extent y:1.0 ]. |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
275 |
|
2120 | 276 |
scrolledView extent:extent. |
277 |
]. |
|
278 |
||
279 |
realized ifTrue:[ |
|
280 |
scrolledView ifNotNil:[scrolledView beVisible]. |
|
281 |
self sizeChanged:nil. |
|
282 |
]. |
|
186 | 283 |
]. |
2120 | 284 |
model value:scrolledView. |
2124 | 285 |
! |
286 |
||
287 |
scrolledViews |
|
288 |
"Returns the collection of all scrolled views including the current scrolled view |
|
2957 | 289 |
and all unmapped scrolled views." |
290 |
||
2124 | 291 |
|subviews| |
292 |
||
293 |
frame ifNotNil:[ |
|
294 |
subviews := frame subViews. |
|
295 |
subviews ifNotNil:[ ^ subviews ] |
|
296 |
]. |
|
297 |
^ #() |
|
2120 | 298 |
! ! |
299 |
||
300 |
!ViewScroller methodsFor:'accessing-channels'! |
|
301 |
||
302 |
keepViewsChannel |
|
303 |
"boolean holder; if the value is false (the default), the previous scrolled view is |
|
304 |
destroyed, whenever a new scrolled view is set. if true, it is unmapped and kept. |
|
305 |
Set this flag, if the application changes the scrolled view but wants |
|
306 |
them to be kept for fast switching. |
|
307 |
" |
|
308 |
^ keepViewsChannel |
|
309 |
! |
|
310 |
||
311 |
keepViewsChannel:aHolder |
|
312 |
"boolean holder; if the value is false (the default), the previous scrolled view is |
|
313 |
destroyed, whenever a new scrolled view is set. if true, it is unmapped and kept. |
|
314 |
Set this flag, if the application changes the scrolled view but wants |
|
315 |
them to be kept for fast switching. |
|
316 |
" |
|
317 |
|oldValue| |
|
318 |
||
319 |
oldValue := keepViewsChannel value. |
|
320 |
keepViewsChannel removeDependent:self. |
|
321 |
||
3165 | 322 |
(keepViewsChannel := aHolder) isNil ifTrue:[ |
2120 | 323 |
keepViewsChannel := oldValue asValue. |
324 |
]. |
|
325 |
keepViewsChannel addDependent:self. |
|
326 |
self update:nil with:nil from:keepViewsChannel. |
|
327 |
! |
|
328 |
||
329 |
model |
|
330 |
"value holder, which keeps the current scrolledView or nil |
|
331 |
" |
|
332 |
^ model |
|
333 |
! |
|
334 |
||
335 |
model:aHolder |
|
336 |
"value holder, which keeps the current scrolledView or nil |
|
337 |
" |
|
338 |
model removeDependent:self. |
|
339 |
||
340 |
aHolder isNil ifTrue:[ model := nil asValue ] |
|
341 |
ifFalse:[ model := aHolder ]. |
|
342 |
||
343 |
model addDependent:self. |
|
344 |
self update:nil with:nil from:model. |
|
345 |
! ! |
|
346 |
||
347 |
!ViewScroller methodsFor:'accessing-look'! |
|
348 |
||
349 |
horizontalScrollStep:something |
|
350 |
"set the value of the instance variable 'horizontalScrollStep' (automatically generated)" |
|
351 |
||
352 |
horizontalScrollStep := something. |
|
425 | 353 |
! |
354 |
||
355 |
verticalScrollStep:something |
|
356 |
"set the value of the instance variable 'verticalScrollStep' (automatically generated)" |
|
357 |
||
2001
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
358 |
verticalScrollStep := something. |
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
359 |
! ! |
186 | 360 |
|
2120 | 361 |
!ViewScroller methodsFor:'change & update'! |
362 |
||
363 |
update:something with:aParameter from:changedObject |
|
364 |
changedObject == model ifTrue:[ |
|
365 |
self scrolledView:(model value). |
|
2478 | 366 |
^ self |
2120 | 367 |
]. |
368 |
||
369 |
changedObject == keepViewsChannel ifTrue:[ |
|
370 |
self keepViews ifFalse:[ |views| |
|
371 |
"destroy all client views other than the actuel scrolled view |
|
372 |
" |
|
373 |
views := frame subViews. |
|
374 |
views size ~~ 0 ifTrue:[ |
|
2478 | 375 |
views copy do:[:v | v ~~ scrolledView ifTrue:[ v destroy ] ]. |
2120 | 376 |
] |
377 |
]. |
|
378 |
^ self |
|
379 |
]. |
|
380 |
||
381 |
super update:something with:aParameter from:changedObject |
|
382 |
! ! |
|
383 |
||
186 | 384 |
!ViewScroller methodsFor:'event handling'! |
385 |
||
386 |
sizeChanged:how |
|
187 | 387 |
"reposition the scrolledView, if required" |
388 |
||
186 | 389 |
|newOrigin| |
390 |
||
391 |
super sizeChanged:how. |
|
392 |
self changed:#sizeOfContents. "update possible scrollers" |
|
393 |
||
394 |
" |
|
395 |
if we are beyond the end, scroll up a bit |
|
396 |
" |
|
397 |
((self viewOrigin y + self height) > self heightOfContents) ifTrue:[ |
|
398 |
newOrigin := self heightOfContents - self height. |
|
399 |
newOrigin < 0 ifTrue:[ |
|
400 |
newOrigin := 0 |
|
401 |
]. |
|
402 |
self scrollVerticalTo: newOrigin. |
|
403 |
]. |
|
404 |
" |
|
405 |
if we are right of the end, scroll left a bit |
|
406 |
" |
|
407 |
((self viewOrigin x + self width) > self widthOfContents) ifTrue:[ |
|
408 |
newOrigin := self widthOfContents - self width. |
|
409 |
newOrigin < 0 ifTrue:[ |
|
410 |
newOrigin := 0 |
|
411 |
]. |
|
412 |
self scrollHorizontalTo: newOrigin. |
|
413 |
]. |
|
414 |
||
187 | 415 |
"Modified: 24.5.1996 / 17:48:44 / cg" |
186 | 416 |
! ! |
417 |
||
3175 | 418 |
!ViewScroller methodsFor:'focus handling'! |
419 |
||
420 |
canTab |
|
421 |
^ false |
|
422 |
! ! |
|
423 |
||
2120 | 424 |
!ViewScroller methodsFor:'initialization & release'! |
425 |
||
426 |
initialize |
|
2738 | 427 |
"initialize all models of the view" |
428 |
||
2120 | 429 |
super initialize. |
430 |
||
3249
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
431 |
resizeScrolledViewVertical := false. |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
432 |
resizeScrolledViewHorizontal := false. |
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
433 |
|
2120 | 434 |
frame := SimpleView origin:0.0@0.0 corner:1.0@1.0 in:self. |
435 |
frame borderWidth:0; level:0. |
|
436 |
||
437 |
keepViewsChannel := false asValue. |
|
438 |
keepViewsChannel addDependent:self. |
|
439 |
||
440 |
model := nil asValue. |
|
441 |
model addDependent:self. |
|
2156 | 442 |
! |
443 |
||
444 |
release |
|
2738 | 445 |
"release all dependencies" |
446 |
||
2156 | 447 |
keepViewsChannel removeDependent:self. |
448 |
model removeDependent:self. |
|
449 |
||
450 |
super release. |
|
2120 | 451 |
! ! |
452 |
||
29 | 453 |
!ViewScroller methodsFor:'queries-contents'! |
454 |
||
186 | 455 |
heightOfContents |
187 | 456 |
"return my contents' height; this is the scrolledViews height" |
186 | 457 |
|
424 | 458 |
scrolledView isNil ifTrue:[^ super heightOfContents]. |
186 | 459 |
^ scrolledView height |
460 |
||
187 | 461 |
"Modified: 24.5.1996 / 17:34:48 / cg" |
186 | 462 |
! |
463 |
||
29 | 464 |
viewOrigin |
187 | 465 |
"the viewOrigin (for scrollBars) is based upon the scrolledViews origin" |
186 | 466 |
|
424 | 467 |
scrolledView isNil ifTrue:[^ 0@0]. |
29 | 468 |
^ scrolledView origin negated |
186 | 469 |
|
187 | 470 |
"Modified: 24.5.1996 / 17:48:13 / cg" |
29 | 471 |
! |
472 |
||
473 |
widthOfContents |
|
187 | 474 |
"return my contents' width; this is the scrolledViews width" |
29 | 475 |
|
424 | 476 |
scrolledView isNil ifTrue:[^ super widthOfContents]. |
186 | 477 |
^ scrolledView width |
478 |
||
187 | 479 |
"Modified: 24.5.1996 / 17:34:56 / cg" |
29 | 480 |
! ! |
481 |
||
482 |
!ViewScroller methodsFor:'scrolling'! |
|
483 |
||
424 | 484 |
horizontalScrollStep |
485 |
"return the amount by which to step-scroll horizontally" |
|
486 |
||
425 | 487 |
^ horizontalScrollStep ? (self width // 2) |
424 | 488 |
! |
489 |
||
236
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
490 |
scrollTo:aPoint |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
491 |
"change origin of scrolledView to scroll to aPoint" |
29 | 492 |
|
236
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
493 |
|wCont hCont "{ Class:SmallInteger }" |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
494 |
iw ih "{ Class:SmallInteger }" |
2001
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
495 |
viewOrigin orgX orgY newX newY dX dY| |
29 | 496 |
|
424 | 497 |
scrolledView isNil ifTrue:[^ self]. |
498 |
||
29 | 499 |
viewOrigin := scrolledView origin. |
500 |
orgX := viewOrigin x negated. |
|
236
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
501 |
orgY := viewOrigin y negated. |
29 | 502 |
|
236
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
503 |
newX := aPoint x. |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
504 |
newY := aPoint y. |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
505 |
wCont := self widthOfContents. |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
506 |
hCont := self heightOfContents. |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
507 |
iw := self innerWidth. |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
508 |
ih := self innerHeight. |
29 | 509 |
|
236
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
510 |
((newX + iw) > wCont) ifTrue:[ |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
511 |
newX := wCont - iw |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
512 |
]. |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
513 |
(newX < 0) ifTrue:[ |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
514 |
newX := 0 |
29 | 515 |
]. |
236
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
516 |
((newY + ih) > hCont) ifTrue:[ |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
517 |
newY := hCont - ih |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
518 |
]. |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
519 |
(newY < 0) ifTrue:[ |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
520 |
newY := 0 |
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
521 |
]. |
2001
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
522 |
dX := newX-orgX. |
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
523 |
dY := newY-orgY. |
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
524 |
((dX ~= 0) or:[dY ~= 0]) ifTrue:[ |
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
525 |
self originWillChange. |
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
526 |
scrolledView origin:(newX negated @ newY negated). |
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
527 |
self originChanged:(dX negated @ dY negated). |
4fba7c3b5f53
dont scroll if scroll delta is 0
Claus Gittinger <cg@exept.de>
parents:
1466
diff
changeset
|
528 |
] |
42 | 529 |
|
236
20dba8483ad7
Make #scrollTo: the basic scrolling method.
Stefan Vogel <sv@exept.de>
parents:
187
diff
changeset
|
530 |
"Modified: 21.8.1996 / 09:17:49 / stefan" |
424 | 531 |
! |
532 |
||
533 |
verticalScrollStep |
|
534 |
"return the amount by which to step-scroll vertically" |
|
535 |
||
425 | 536 |
^ verticalScrollStep ? (self height // 2) |
42 | 537 |
! ! |
538 |
||
424 | 539 |
!ViewScroller class methodsFor:'documentation'! |
120 | 540 |
|
541 |
version |
|
3249
224b457c40fd
support resizeScrolledViewVertical and resizeScrolledViewHorizontal
ca
parents:
3175
diff
changeset
|
542 |
^ '$Header: /cvs/stx/stx/libwidg2/ViewScroller.st,v 1.24 2007-10-18 12:56:25 ca Exp $' |
120 | 543 |
! ! |